BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/usr/bin/badvpn-ncd
2  
3 process main {
4 getargs() args;
5 value(args) args;
6  
7 num_different(args.length, "0") bad_args;
8 If (bad_args) {
9 println("Usage: list-port-forwardings");
10 exit("1");
11 };
12  
13 var("0") exit_status;
14  
15 sys.request_client({"unix", "/run/ncd-control.socket"}) client;
16  
17 var({"list-port-forwardings"}) request_data;
18  
19 client->request(request_data, "reply_handler", "finished_handler", {});
20 }
21  
22 template reply_handler {
23 value(_reply.data) reply_data;
24 reply_data->get("0") status;
25 reply_data->get("1") arg;
26  
27 val_equal(status, "ok") is_ok;
28 If (is_ok) {
29 println("Protocol Start End Destination");
30 Foreach (arg As entry) {
31 value(entry) entry;
32 entry->get("0") protocol;
33 entry->get("1") port_start;
34 entry->get("2") port_end;
35 entry->get("3") dest_addr;
36 call("append_spaces", {port_start, "5"}) fixed_start;
37 call("append_spaces", {port_end, "5"}) fixed_end;
38 println(protocol, " ", fixed_start.result, " ", fixed_end.result, " ", dest_addr);
39 };
40 } Else {
41 _caller.exit_status->set("1");
42 println("Error: ", arg);
43 };
44 }
45  
46 template finished_handler {
47 exit(_caller.exit_status);
48 }
49  
50 template append_spaces {
51 alias("_arg0") input;
52 alias("_arg1") min_length;
53  
54 value(input) result;
55 backtrack_point() point;
56 num_lesser(result.length, min_length) more;
57 If (more) {
58 result->append(" ");
59 point->go();
60 };
61 }