BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | process main { |
2 | call("make_igmpproxy_config", {"br0", "eth1", "./igmpproxy.conf.template", "./igmpproxy.conf"}); |
||
3 | |||
4 | println("Done."); |
||
5 | exit("0"); |
||
6 | } |
||
7 | |||
8 | template make_igmpproxy_config { |
||
9 | alias("_arg0") upstream_iface; |
||
10 | alias("_arg1") downstream_iface; |
||
11 | alias("_arg2") template_file; |
||
12 | alias("_arg3") output_file; |
||
13 | |||
14 | # Make a list of interfaces to add as disabled (upstream and downstream will not be disabled). |
||
15 | var({ |
||
16 | "eth0", "eth1", "eth2", "eth3", "eth4", "eth5", "eth6", "eth7", "eth8", "eth9", |
||
17 | "wlan0", "wlan1", "wlan2", "wlan3", "wlan4", "wlan5", "wlan6", "wlan7", "wlan8", "wlan9", |
||
18 | "tap0", "tap1", "tap2", "tap3", "tap4", "tap5", "tap6", "tap7", "tap8", "tap9", |
||
19 | "br0", "br1", "br2", "br3", "br4", "br5", "br6", "br7", "br8", "br9" |
||
20 | }) disabled_ifaces; |
||
21 | |||
22 | # Build replacements for template config. |
||
23 | var({"<UPSTREAM_IFACE>", "<DOWNSTREAM_IFACE>"}) regex; |
||
24 | var({upstream_iface, downstream_iface}) replace; |
||
25 | |||
26 | # Read template config. |
||
27 | file_read(template_file) template_data; |
||
28 | |||
29 | # Perform replacements. |
||
30 | regex_replace(template_data, regex, replace) replaced_data; |
||
31 | |||
32 | # Build string value from replaced_data, to which we will append |
||
33 | # configuration for disabled interfaces. |
||
34 | value(replaced_data) output_data; |
||
35 | |||
36 | # Build disabled strings. |
||
37 | Foreach (disabled_ifaces As iface) { |
||
38 | # Determine if the interface is disabled. |
||
39 | val_equal(iface, upstream_iface) is_up; |
||
40 | val_equal(iface, downstream_iface) is_down; |
||
41 | or(is_up, is_down) is_not_disabled; |
||
42 | not(is_not_disabled) is_disabled; |
||
43 | |||
44 | # If it's disabled, append to the configuration file. |
||
45 | If (is_disabled) { |
||
46 | concat("phyint ", iface, " disabled\n") str; |
||
47 | output_data->append(str); |
||
48 | }; |
||
49 | }; |
||
50 | |||
51 | # Write config. |
||
52 | file_write(output_file, output_data); |
||
53 | } |