Commit bfe03350d28664f847271eb1d3107e5aad1c156b

Authored by totoro
1 parent 6fd7717b

[+] add an image button with dialog confirmation

os_tools/linux/config/network_interface_file.anubis
1   -/*
2   - * Created by PyramIDE.
3   - * User: Alexis & Totoro
4   - * Date: 03/09/2012
5   - * Time: 16:05
6   - *
7   - * To change this template use Tools | Options | Coding | Edit Standard Headers.
8   - */
9   -
10   -read system/logger.anubis
11   -read system/string.anubis
12   -read tools/basis.anubis
13   -read tools/streams.anubis
14   -read types/network_types.anubis
15   -read config/dns_config.anubis
16   -read tools/os.anubis
17   -
18   -delete_entry
19   -find_entry
20   -replace_entry = ok
21   -add_entry
22   -
23   -
24   -public type Network_Parameter:
25   - comment(String),
26   - conf_nv(String name, String value),
27   - conf_nvc(String name, String value, String comment).
28   -
29   -
30   -public type Network_type:
31   - iface(String name, Network_Parameter param).
32   -
33   -public type Network_entry:
34   - blank,
35   - comment(String comment),
36   - section(Network_type net_type, List(Network_Parameter) params).
37   -
38   -
39   -define Maybe(Network_Parameter)
40   - _update_param
41   - (
42   - Network_Parameter param,
43   - String entry_name,
44   - String value
45   - )=
46   - if param is
47   - {
48   - comment(_) then failure,
49   - conf_nv(name,_) then
50   - if name = entry_name then success(conf_nv(name, value))
51   - else failure,
52   - conf_nvc(name,_,c) then
53   - if name = entry_name then success(conf_nvc(name, value,c))
54   - else
55   - failure,
56   - }
57   - .
58   -define List(Network_Parameter)
59   - _update_entry
60   - (
61   - List(Network_Parameter) params,
62   - String entry_name,
63   - String value,
64   - List(Network_Parameter) so_far,
65   - Bool add, //mean add the value if not found
66   - Bool found //
67   - )=
68   - if params is
69   - {
70   - [] then if add & found = false then
71   - reverse([conf_nv(entry_name, value) . so_far])
72   - else
73   - reverse(so_far),
74   -
75   - [ h . t ] then
76   - with result = _update_param(h,entry_name,value),
77   - if result is
78   - {
79   - failure then _update_entry(t, entry_name, value, [h . so_far], add, found),
80   - success(entry) then _update_entry(t, entry_name, value, [entry . so_far], add, true),
81   - }
82   -
83   - }.
84   -
85   -define Network_entry
86   - _update_entry_type
87   - (
88   - Network_type net_type,
89   - List(Network_Parameter) params,
90   - String name_port, // i.e eth0,br0
91   - String entry_name,
92   - String value,
93   - List(Network_Parameter) so_far,
94   - Bool add
95   - )=
96   - if name_port = net_type.name then
97   - if _update_param(net_type.param,entry_name,value) is
98   - {
99   - failure then section(net_type,_update_entry(params,entry_name,value,so_far, add, false)),
100   - success(param) then section(iface(name_port,param),params) //if the value changed is network_type
101   - }
102   - else section(net_type,params)
103   - .
104   -
105   -define List(Network_entry)
106   - update_entry
107   - (
108   - List(Network_entry) entries,
109   - String name_port, // i.e eth0,br0
110   - String entry_name,
111   - String value,
112   - List(Network_entry) so_far,
113   - Bool add //for add an entry or not
114   - )=
115   - if entries is
116   - {
117   - [] then reverse(so_far),
118   - [h . t] then
119   - if h is
120   - {
121   - blank then update_entry(t, name_port, entry_name, value, [h . so_far], add),
122   - comment(_) then update_entry(t, name_port, entry_name, value, [h . so_far], add),
123   - section(net_type,params) then update_entry(t, name_port, entry_name, value,
124   - [_update_entry_type(net_type, params, name_port, entry_name, value, [], add) . so_far], add)
125   - }
126   - }
127   - .
128   -
129   -define String
130   - to_String
131   - (
132   - Network_Parameter i_entry,
133   - )=
134   - if i_entry is
135   - {
136   - comment(s) then s,
137   - conf_nv(n,v) then n +" "+v,
138   - conf_nvc(n,v,c) then n+" "+v+" "+c
139   - }.
140   -
141   -define String
142   - to_String
143   - (
144   - Network_type n_type
145   - )=
146   - if n_type is
147   - {
148   - iface(name, param) then "iface "+name+" "+to_String(param)
149   - }
150   - .
151   -
152   -define String
153   - _to_String
154   - (
155   - List(Network_Parameter) interface_entries,
156   - String so_far //this is so far of the section, not the general file
157   - )=
158   - if interface_entries is
159   - {
160   - [] then so_far,
161   - [h . t] then
162   - _to_String(t, so_far + "\t"+to_String(h)+"\n")
163   - }.
164   -
165   -public define String
166   - to_String
167   - (
168   - List(Network_entry) network_entries,
169   - String so_far
170   - )=
171   - if network_entries is
172   - {
173   - [] then so_far,
174   - [h . t] then
175   - if h is
176   - {
177   - blank then to_String(t, so_far+"\n"),
178   - comment(comment) then to_String(t, so_far + comment),
179   - section(net_type, params) then to_String(t, so_far+"auto "+net_type.name+"\n"+
180   - to_String(net_type)+"\n"+
181   - _to_String( params, ""))
182   - }
183   - }.
184   -
185   -
186   -define Maybe(Network_Parameter)
187   - extract_value
188   - (
189   - String name,
190   - String left_line
191   - )=
192   - //println(" Extract value for name ["+name+"] in ["+left_line+"]");
193   - if find_char(left_line, '#', 0) is
194   - {
195   - failure then success(conf_nv(name, left_line)),
196   - success(idx) then
197   - if sub_string(left_line, 0, idx) is
198   - {
199   - failure then failure,
200   - success(value) then
201   - if sub_string(left_line, idx+1, (length(left_line) - (idx+1))) is
202   - {
203   - failure then success(conf_nv(name, value)),
204   - //println("conf_nv found name="+name+" value="+value);
205   - success(comment) then success(conf_nvc(name, value, comment))
206   - //println("conf_nvc found name="+name+" value="+value+" comment="+comment);
207   -
208   - }
209   - }
210   - }.
211   -
212   -define Maybe(Network_Parameter)
213   - get_network_parameter
214   - (
215   - List(String) params
216   - )=
217   - if params is
218   - {
219   - [] then failure,
220   - [ name . t] then
221   - //println("Get network parameter for ["+name+"]");
222   - if nth((Int)0, name) is
223   - {
224   - failure then failure,
225   - success(c) then
226   - if c = '#' then
227   - success(comment(join(" ",params)))
228   - else
229   - extract_value(name, join(" ",t))
230   - }
231   - }.
232   -
233   -define Maybe(Network_type)
234   - get_type
235   - (
236   - String line,
237   - String name
238   - )=
239   - if split_by_token(line, ' ') is
240   - {
241   - [ ] then failure,
242   - [type . t] then
243   - if type = "iface" then
244   - if t is
245   - {
246   - [] then
247   - //println("WARNING unamed iface section ["+name+"]");
248   - failure,
249   - [h . t] then
250   - //check if auto name is equal to iface name
251   - if h = name then
252   - if get_network_parameter(t) is
253   - {
254   - failure then failure,
255   - success(net_param) then success(iface(name, net_param))
256   - }
257   - else
258   - failure
259   - }
260   - else failure
261   - }.
262   -
263   -define List(Network_Parameter)
264   - parse_section_body
265   - (
266   - Stream s,
267   - List(Network_Parameter) so_far
268   - )=
269   - if read_line(s) is
270   - {
271   - failure then reverse(so_far),
272   - success(line) then println(line);
273   - if nth((Int)0, line) is
274   - {
275   - failure then reverse(so_far),
276   - success(c) then
277   - if c = ' ' | c='\t' then
278   - //it seem to be a a real section body entry we try it
279   - //println("parse section line ["+trim(line)+"]");
280   - if get_network_parameter(split_by_token(trim(line), ' ')) is
281   - {
282   - failure then reverse(so_far),
283   - success(param) then parse_section_body(s,[param . so_far])
284   - }
285   - else
286   - // itsn't part of section body, so we stop here and unput the line read
287   - //and return the found Network_Parameter
288   - //println("Not body part ["+trim(line)+"]");
289   - unput_line(s, line);
290   - reverse(so_far)
291   - }
292   - }.
293   -
294   -define Network_entry
295   - parse_section
296   - (
297   - Stream s,
298   - String line
299   - ) =
300   - if split_by_token(line, ' ') is
301   - {
302   - [ ] then blank,
303   - [h . t] then
304   - if h = "auto" then
305   - if t is
306   - {
307   - [] then blank,
308   - //println("WARNING unamed section ["+h+"]");
309   - [ name . t ] then
310   - //println("auto found with name ["+name+"]");
311   - //read the second line of the section where the type is located i.e. iface
312   - if read_line(s) is
313   - {
314   - failure then blank,
315   - success(type_line) then
316   - //println("get type line for "+name+"["+trim(type_line)+"]");
317   - if get_type(trim(type_line), name) is
318   - {
319   - failure then
320   - //println("type not found for "+name);
321   - blank,
322   - success(type_entry) then
323   - //println("type found, parse for section");
324   - section(type_entry, parse_section_body(s,[]))
325   - }
326   - }
327   - }
328   - else
329   - blank
330   - }.
331   -
332   -
333   -define Network_entry
334   - read_interface_entry
335   - (
336   - Stream s,
337   - String line
338   - )=
339   - //check for comment
340   - if nth((Int)0,line) is
341   - {
342   - failure then blank,
343   - success(c) then
344   - if c = '#' then
345   - comment(line)
346   - else
347   - parse_section(s, trim(line))
348   - }.
349   -
350   -define List(Network_entry)
351   - read_interface_entries
352   - (
353   - Stream s,
354   - List(Network_entry) so_far
355   - )=
356   - if read_line(s) is
357   - {
358   - failure then reverse(so_far),
359   - success(line) then
360   - //println("["+line+"]");
361   - read_interface_entries(s, [read_interface_entry(s, line) . so_far])
362   - }.
363   -
364   -public define List(Network_entry)
365   - read_interface
366   - (
367   - String interface_file
368   - ) =
369   - if (Maybe(RStream))file(interface_file, read) is
370   - {
371   - failure then [], //nothing to read
372   - success(f) then //parse file for each entry
373   - read_interface_entries(make_stream(f), [])
374   - }.
375   -
376   -public define String
377   - dump_interface_file
378   - =
379   - to_String(read_interface("/calexium/interfaces"),"").
380   -
381   -public define Maybe(One)
382   - write_interface
383   - (
384   - String file_name,
385   - List(Network_entry) entries
386   - )=
387   - if (Maybe(RWStream))file(file_name, new) is
388   - {
389   - failure then failure,
390   - success(f) then success(forget(reliable_write(f, to_byte_array(to_String(entries, "")))))
391   - }.
392   -
393   -//ipconfig(String ip,
394   -// String mask,
395   -// String gateway,
396   -// List(String) dns).
397   -
398   -
399   -define One
400   - write_ip_config_linux
401   - (
402   - IpConfig ip_config,
403   - ) =
404   - with file_name = "/etc/network/interfaces",
405   - interfaces_file = read_interface(file_name),
406   - interfaces_file = update_entry(interfaces_file, "br0", "address",ip_config.ip,[], false),
407   - interfaces_file = update_entry(interfaces_file, "br0", "netmask",ip_config.mask,[], false),
408   - interfaces_file = update_entry(interfaces_file, "br0","gateway",ip_config.gateway,[], false),
409   - forget(write_interface(file_name, interfaces_file))
410   - .
411   -
412   -
413   -
414   -public define Maybe(One)
415   - write_network_config_linux
416   - (
417   - IpConfig wan_config
418   - ) =
419   -
420   - write_ip_config_linux(wan_config);
421   - write_dns_list(wan_config.dns);
422   - sync_fs;
423   - success(unique).
424   -
425   -
426   -
427   - /** here tool for testing
428   - * anbexec parse_interface <given_file>
429   - * will produce a dump of given_file into file named as original with ".dump" as an extension
430   - */
431   -
432   -global define One
433   - parse_interface
434   - (
435   - List(String) args
436   - )=
437   - if args is
438   - {
439   - [] then print("usage : parse_interface <file>"),
440   - [ file_name . t ] then
441   - write_ip_config_linux(ipconfig("192.168.4.0","255.255.0.255","0.0.0.0",[]))
442   - }
443   - .
444   -
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: Alexis & Totoro
  4 + * Date: 03/09/2012
  5 + * Time: 16:05
  6 + *
  7 + */
  8 +
  9 +read system/logger.anubis
  10 +read system/string.anubis
  11 +read tools/basis.anubis
  12 +read tools/streams.anubis
  13 +read types/network_types.anubis
  14 +read config/dns_config.anubis
  15 +read tools/os.anubis
  16 +
  17 +delete_entry
  18 +find_entry
  19 +replace_entry = ok
  20 +add_entry
  21 +
  22 +
  23 +public type Network_Parameter:
  24 + comment(String),
  25 + conf_nv(String name, String value),
  26 + conf_nvc(String name, String value, String comment).
  27 +
  28 +
  29 +public type Network_type:
  30 + iface(String name, Network_Parameter param).
  31 +
  32 +public type Network_entry:
  33 + blank,
  34 + comment(String comment),
  35 + section(Network_type net_type, List(Network_Parameter) params).
  36 +
  37 +
  38 +define Maybe(Network_Parameter)
  39 + _update_param
  40 + (
  41 + Network_Parameter param,
  42 + String entry_name,
  43 + String value
  44 + )=
  45 + if param is
  46 + {
  47 + comment(_) then failure,
  48 + conf_nv(name,_) then
  49 + if name = entry_name then success(conf_nv(name, value))
  50 + else failure,
  51 + conf_nvc(name,_,c) then
  52 + if name = entry_name then success(conf_nvc(name, value,c))
  53 + else
  54 + failure,
  55 + }
  56 + .
  57 +define List(Network_Parameter)
  58 + _update_entry
  59 + (
  60 + List(Network_Parameter) params,
  61 + String entry_name,
  62 + String value,
  63 + List(Network_Parameter) so_far,
  64 + Bool add, //means add the value if not found
  65 + Bool found //
  66 + )=
  67 + if params is
  68 + {
  69 + [] then if add & found = false then
  70 + reverse([conf_nv(entry_name, value) . so_far])
  71 + else
  72 + reverse(so_far),
  73 +
  74 + [ h . t ] then
  75 + with result = _update_param(h,entry_name,value),
  76 + if result is
  77 + {
  78 + failure then _update_entry(t, entry_name, value, [h . so_far], add, found),
  79 + success(entry) then _update_entry(t, entry_name, value, [entry . so_far], add, true),
  80 + }
  81 +
  82 + }.
  83 +
  84 +define Network_entry
  85 + _update_entry_type
  86 + (
  87 + Network_type net_type,
  88 + List(Network_Parameter) params,
  89 + String name_port, // i.e eth0,br0
  90 + String entry_name,
  91 + String value,
  92 + List(Network_Parameter) so_far,
  93 + Bool add
  94 + )=
  95 + if name_port = net_type.name then
  96 + if _update_param(net_type.param,entry_name,value) is
  97 + {
  98 + failure then section(net_type,_update_entry(params,entry_name,value,so_far, add, false)),
  99 + success(param) then section(iface(name_port,param),params) //if the value changed is network_type
  100 + }
  101 + else section(net_type,params)
  102 + .
  103 +
  104 +define List(Network_entry)
  105 + update_entry
  106 + (
  107 + List(Network_entry) entries,
  108 + String name_port, // i.e eth0,br0
  109 + String entry_name,
  110 + String value,
  111 + List(Network_entry) so_far,
  112 + Bool add //for add an entry or not
  113 + )=
  114 + if entries is
  115 + {
  116 + [] then reverse(so_far),
  117 + [h . t] then
  118 + if h is
  119 + {
  120 + blank then update_entry(t, name_port, entry_name, value, [h . so_far], add),
  121 + comment(_) then update_entry(t, name_port, entry_name, value, [h . so_far], add),
  122 + section(net_type,params) then update_entry(t, name_port, entry_name, value,
  123 + [_update_entry_type(net_type, params, name_port, entry_name, value, [], add) . so_far], add)
  124 + }
  125 + }
  126 + .
  127 +
  128 +define String
  129 + to_String
  130 + (
  131 + Network_Parameter i_entry,
  132 + )=
  133 + if i_entry is
  134 + {
  135 + comment(s) then s,
  136 + conf_nv(n,v) then n +" "+v,
  137 + conf_nvc(n,v,c) then n+" "+v+" "+c
  138 + }.
  139 +
  140 +define String
  141 + to_String
  142 + (
  143 + Network_type n_type
  144 + )=
  145 + if n_type is
  146 + {
  147 + iface(name, param) then "iface "+name+" "+to_String(param)
  148 + }
  149 + .
  150 +
  151 +define String
  152 + _to_String
  153 + (
  154 + List(Network_Parameter) interface_entries,
  155 + String so_far //this is so far of the section, not the general file
  156 + )=
  157 + if interface_entries is
  158 + {
  159 + [] then so_far,
  160 + [h . t] then
  161 + _to_String(t, so_far + "\t"+to_String(h)+"\n")
  162 + }.
  163 +
  164 +public define String
  165 + to_String
  166 + (
  167 + List(Network_entry) network_entries,
  168 + String so_far
  169 + )=
  170 + if network_entries is
  171 + {
  172 + [] then so_far,
  173 + [h . t] then
  174 + if h is
  175 + {
  176 + blank then to_String(t, so_far+"\n"),
  177 + comment(comment) then to_String(t, so_far + comment),
  178 + section(net_type, params) then to_String(t, so_far+"auto "+net_type.name+"\n"+
  179 + to_String(net_type)+"\n"+
  180 + _to_String( params, ""))
  181 + }
  182 + }.
  183 +
  184 +
  185 +define Maybe(Network_Parameter)
  186 + extract_value
  187 + (
  188 + String name,
  189 + String left_line
  190 + )=
  191 + //println(" Extract value for name ["+name+"] in ["+left_line+"]");
  192 + if find_char(left_line, '#', 0) is
  193 + {
  194 + failure then success(conf_nv(name, left_line)),
  195 + success(idx) then
  196 + if sub_string(left_line, 0, idx) is
  197 + {
  198 + failure then failure,
  199 + success(value) then
  200 + if sub_string(left_line, idx+1, (length(left_line) - (idx+1))) is
  201 + {
  202 + failure then success(conf_nv(name, value)),
  203 + //println("conf_nv found name="+name+" value="+value);
  204 + success(comment) then success(conf_nvc(name, value, comment))
  205 + //println("conf_nvc found name="+name+" value="+value+" comment="+comment);
  206 +
  207 + }
  208 + }
  209 + }.
  210 +
  211 +define Maybe(Network_Parameter)
  212 + get_network_parameter
  213 + (
  214 + List(String) params
  215 + )=
  216 + if params is
  217 + {
  218 + [] then failure,
  219 + [ name . t] then
  220 + //println("Get network parameter for ["+name+"]");
  221 + if nth((Int)0, name) is
  222 + {
  223 + failure then failure,
  224 + success(c) then
  225 + if c = '#' then
  226 + success(comment(join(" ",params)))
  227 + else
  228 + extract_value(name, join(" ",t))
  229 + }
  230 + }.
  231 +
  232 +define Maybe(Network_type)
  233 + get_type
  234 + (
  235 + String line,
  236 + String name
  237 + )=
  238 + if split_by_token(line, ' ') is
  239 + {
  240 + [ ] then failure,
  241 + [type . t] then
  242 + if type = "iface" then
  243 + if t is
  244 + {
  245 + [] then
  246 + //println("WARNING unamed iface section ["+name+"]");
  247 + failure,
  248 + [h . t] then
  249 + //check if auto name is equal to iface name
  250 + if h = name then
  251 + if get_network_parameter(t) is
  252 + {
  253 + failure then failure,
  254 + success(net_param) then success(iface(name, net_param))
  255 + }
  256 + else
  257 + failure
  258 + }
  259 + else failure
  260 + }.
  261 +
  262 +define List(Network_Parameter)
  263 + parse_section_body
  264 + (
  265 + Stream s,
  266 + List(Network_Parameter) so_far
  267 + )=
  268 + if read_line(s) is
  269 + {
  270 + failure then reverse(so_far),
  271 + success(line) then println(line);
  272 + if nth((Int)0, line) is
  273 + {
  274 + failure then reverse(so_far),
  275 + success(c) then
  276 + if c = ' ' | c='\t' then
  277 + //it seem to be a a real section body entry we try it
  278 + //println("parse section line ["+trim(line)+"]");
  279 + if get_network_parameter(split_by_token(trim(line), ' ')) is
  280 + {
  281 + failure then reverse(so_far),
  282 + success(param) then parse_section_body(s,[param . so_far])
  283 + }
  284 + else
  285 + // itsn't part of section body, so we stop here and unput the line read
  286 + //and return the found Network_Parameter
  287 + //println("Not body part ["+trim(line)+"]");
  288 + unput_line(s, line);
  289 + reverse(so_far)
  290 + }
  291 + }.
  292 +
  293 +define Network_entry
  294 + parse_section
  295 + (
  296 + Stream s,
  297 + String line
  298 + ) =
  299 + if split_by_token(line, ' ') is
  300 + {
  301 + [ ] then blank,
  302 + [h . t] then
  303 + if h = "auto" then
  304 + if t is
  305 + {
  306 + [] then blank,
  307 + //println("WARNING unamed section ["+h+"]");
  308 + [ name . t ] then
  309 + //println("auto found with name ["+name+"]");
  310 + //read the second line of the section where the type is located i.e. iface
  311 + if read_line(s) is
  312 + {
  313 + failure then blank,
  314 + success(type_line) then
  315 + //println("get type line for "+name+"["+trim(type_line)+"]");
  316 + if get_type(trim(type_line), name) is
  317 + {
  318 + failure then
  319 + //println("type not found for "+name);
  320 + blank,
  321 + success(type_entry) then
  322 + //println("type found, parse for section");
  323 + section(type_entry, parse_section_body(s,[]))
  324 + }
  325 + }
  326 + }
  327 + else
  328 + blank
  329 + }.
  330 +
  331 +
  332 +define Network_entry
  333 + read_interface_entry
  334 + (
  335 + Stream s,
  336 + String line
  337 + )=
  338 + //check for comment
  339 + if nth((Int)0,line) is
  340 + {
  341 + failure then blank,
  342 + success(c) then
  343 + if c = '#' then
  344 + comment(line)
  345 + else
  346 + parse_section(s, trim(line))
  347 + }.
  348 +
  349 +define List(Network_entry)
  350 + read_interface_entries
  351 + (
  352 + Stream s,
  353 + List(Network_entry) so_far
  354 + )=
  355 + if read_line(s) is
  356 + {
  357 + failure then reverse(so_far),
  358 + success(line) then
  359 + //println("["+line+"]");
  360 + read_interface_entries(s, [read_interface_entry(s, line) . so_far])
  361 + }.
  362 +
  363 +public define List(Network_entry)
  364 + read_interface
  365 + (
  366 + String interface_file
  367 + ) =
  368 + if (Maybe(RStream))file(interface_file, read) is
  369 + {
  370 + failure then [], //nothing to read
  371 + success(f) then //parse file for each entry
  372 + read_interface_entries(make_stream(f), [])
  373 + }.
  374 +
  375 +public define String
  376 + dump_interface_file
  377 + =
  378 + to_String(read_interface("/calexium/interfaces"),"").
  379 +
  380 +public define Maybe(One)
  381 + write_interface
  382 + (
  383 + String file_name,
  384 + List(Network_entry) entries
  385 + )=
  386 + if (Maybe(RWStream))file(file_name, new) is
  387 + {
  388 + failure then failure,
  389 + success(f) then success(forget(reliable_write(f, to_byte_array(to_String(entries, "")))))
  390 + }.
  391 +
  392 +//ipconfig(String ip,
  393 +// String mask,
  394 +// String gateway,
  395 +// List(String) dns).
  396 +
  397 +
  398 +define One
  399 + write_ip_config_linux
  400 + (
  401 + IpConfig ip_config,
  402 + ) =
  403 + with file_name = "/etc/network/interfaces",
  404 + interfaces_file = read_interface(file_name),
  405 + interfaces_file = update_entry(interfaces_file, "br0", "address",ip_config.ip,[], false),
  406 + interfaces_file = update_entry(interfaces_file, "br0", "netmask",ip_config.mask,[], false),
  407 + interfaces_file = update_entry(interfaces_file, "br0","gateway",ip_config.gateway,[], false),
  408 + forget(write_interface(file_name, interfaces_file))
  409 + .
  410 +
  411 +
  412 +
  413 +public define Maybe(One)
  414 + write_network_config_linux
  415 + (
  416 + IpConfig wan_config
  417 + ) =
  418 +
  419 + write_ip_config_linux(wan_config);
  420 + write_dns_list(wan_config.dns);
  421 + sync_fs;
  422 + success(unique).
  423 +
  424 +
  425 +
  426 + /** here tool for testing
  427 + * anbexec parse_interface <given_file>
  428 + * will produce a dump of given_file into file named as original with ".dump" as an extension
  429 + */
  430 +
  431 +global define One
  432 + parse_interface
  433 + (
  434 + List(String) args
  435 + )=
  436 + if args is
  437 + {
  438 + [] then print("usage : parse_interface <file>"),
  439 + [ file_name . t ] then
  440 + write_ip_config_linux(ipconfig("192.168.4.0","255.255.0.255","0.0.0.0",[]))
  441 + }
  442 + .
  443 +
... ...
web/CXM_making_a_web_site.anubis
... ... @@ -3496,7 +3496,7 @@ define Printable_tree
3496 3496 text,
3497 3497 "</a>"
3498 3498 ],
3499   - img_link(img,alt_text) then
  3499 + img_link(img, alt_text) then
3500 3500 [
3501 3501 "<a href=\"", full_url ,"\"><img src=\"", img,
3502 3502 "\" alt=\"" + alt_text + "\" border=\"0\"></a>"
... ...
web/js_tools.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ
  4 + * Date: 18/04/2015
  5 + * Time: 23:21
  6 + * © Calexium
  7 + */
  8 +
  9 +define List(Word8)
  10 + make_js_string
  11 + (
  12 + List(Word8) current,
  13 + List(Word8) so_far
  14 + )
  15 + =
  16 + if current is
  17 + {
  18 + [ ] then reverse(so_far),
  19 + [h . t] then
  20 + make_js_string(t,
  21 + if h = '\'' then
  22 + [h . ['\\' . so_far]]
  23 + else
  24 + [h . so_far]
  25 + )
  26 + }.
  27 +
  28 +/**
  29 + * Convert a string into certified javascript string (I hope)
  30 + */
  31 +public define String
  32 + make_js_string
  33 + (
  34 + String str
  35 + )
  36 + =
  37 + implode(make_js_string(explode(str), [])).
... ...
web/widgets/button.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ & Juju
  4 + * Date: 18/04/2015
  5 + * Time: 20:46
  6 + * © Calexium
  7 + */
  8 +
  9 +read calexium_lib/web/CXM_making_a_web_site.anubis
  10 +
  11 +public define HTML_Partial_Content
  12 + img_button
  13 + (
  14 + String img_path,
  15 + String url,
  16 + List((String, String)) extra_ops
  17 + )=
  18 + partial_content(actioner(same, same, img_link(img_path, ""), url, extra_ops)).
  19 +
  20 +public define HTML_Partial_Content
  21 + img_button
  22 + (
  23 + String img_path,
  24 + String url
  25 + )=
  26 + img_button(img_path, url, []).
  27 +
  28 +public define HTML_Partial_Content
  29 + img_button_confirm
  30 + (
  31 + String img_path,
  32 + String dlg_title,
  33 + String dlg_text,
  34 + String dlg_ok,
  35 + String dlg_cancel,
  36 + String url,
  37 + List((String, String)) extra_ops
  38 + )=
  39 + partial_content([js(js_file("js/cxm/cxm.js"))],
  40 + image([style("cursor: pointer"), event(onclick, "CalexiumToolBox.make_confirm_dialog('" + dlg_title + "',
  41 + '" + dlg_text + "',
  42 + '" + dlg_ok + "',
  43 + '" + dlg_cancel + "',
  44 + '/?a=" + url + format_extra_operands(extra_ops)+"');")], img_path, "")).
  45 +
  46 +public define HTML_Partial_Content
  47 + img_button_confirm
  48 + (
  49 + String img_path,
  50 + String dlg_title,
  51 + String dlg_text,
  52 + String dlg_ok,
  53 + String dlg_cancel,
  54 + String url
  55 + )=
  56 + img_button_confirm(img_path, dlg_title, dlg_text, dlg_ok, dlg_cancel, url, []).
  57 +
... ...