From bfe03350d28664f847271eb1d3107e5aad1c156b Mon Sep 17 00:00:00 2001 From: totoro Date: Sun, 19 Apr 2015 03:03:53 +0200 Subject: [PATCH] [+] add an image button with dialog confirmation --- os_tools/linux/config/network_interface_file.anubis | 887 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ web/CXM_making_a_web_site.anubis | 2 +- web/js_tools.anubis | 37 +++++++++++++++++++++++++++++++++++++ web/widgets/button.anubis | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 538 insertions(+), 445 deletions(-) create mode 100644 web/js_tools.anubis create mode 100644 web/widgets/button.anubis diff --git a/os_tools/linux/config/network_interface_file.anubis b/os_tools/linux/config/network_interface_file.anubis index abc8077..ade93e1 100644 --- a/os_tools/linux/config/network_interface_file.anubis +++ b/os_tools/linux/config/network_interface_file.anubis @@ -1,444 +1,443 @@ -/* - * Created by PyramIDE. - * User: Alexis & Totoro - * Date: 03/09/2012 - * Time: 16:05 - * - * To change this template use Tools | Options | Coding | Edit Standard Headers. - */ - -read system/logger.anubis -read system/string.anubis -read tools/basis.anubis -read tools/streams.anubis -read types/network_types.anubis -read config/dns_config.anubis -read tools/os.anubis - -delete_entry -find_entry -replace_entry = ok -add_entry - - -public type Network_Parameter: - comment(String), - conf_nv(String name, String value), - conf_nvc(String name, String value, String comment). - - -public type Network_type: - iface(String name, Network_Parameter param). - -public type Network_entry: - blank, - comment(String comment), - section(Network_type net_type, List(Network_Parameter) params). - - -define Maybe(Network_Parameter) - _update_param - ( - Network_Parameter param, - String entry_name, - String value - )= - if param is - { - comment(_) then failure, - conf_nv(name,_) then - if name = entry_name then success(conf_nv(name, value)) - else failure, - conf_nvc(name,_,c) then - if name = entry_name then success(conf_nvc(name, value,c)) - else - failure, - } - . -define List(Network_Parameter) - _update_entry - ( - List(Network_Parameter) params, - String entry_name, - String value, - List(Network_Parameter) so_far, - Bool add, //mean add the value if not found - Bool found // - )= - if params is - { - [] then if add & found = false then - reverse([conf_nv(entry_name, value) . so_far]) - else - reverse(so_far), - - [ h . t ] then - with result = _update_param(h,entry_name,value), - if result is - { - failure then _update_entry(t, entry_name, value, [h . so_far], add, found), - success(entry) then _update_entry(t, entry_name, value, [entry . so_far], add, true), - } - - }. - -define Network_entry - _update_entry_type - ( - Network_type net_type, - List(Network_Parameter) params, - String name_port, // i.e eth0,br0 - String entry_name, - String value, - List(Network_Parameter) so_far, - Bool add - )= - if name_port = net_type.name then - if _update_param(net_type.param,entry_name,value) is - { - failure then section(net_type,_update_entry(params,entry_name,value,so_far, add, false)), - success(param) then section(iface(name_port,param),params) //if the value changed is network_type - } - else section(net_type,params) - . - -define List(Network_entry) - update_entry - ( - List(Network_entry) entries, - String name_port, // i.e eth0,br0 - String entry_name, - String value, - List(Network_entry) so_far, - Bool add //for add an entry or not - )= - if entries is - { - [] then reverse(so_far), - [h . t] then - if h is - { - blank then update_entry(t, name_port, entry_name, value, [h . so_far], add), - comment(_) then update_entry(t, name_port, entry_name, value, [h . so_far], add), - section(net_type,params) then update_entry(t, name_port, entry_name, value, - [_update_entry_type(net_type, params, name_port, entry_name, value, [], add) . so_far], add) - } - } - . - -define String - to_String - ( - Network_Parameter i_entry, - )= - if i_entry is - { - comment(s) then s, - conf_nv(n,v) then n +" "+v, - conf_nvc(n,v,c) then n+" "+v+" "+c - }. - -define String - to_String - ( - Network_type n_type - )= - if n_type is - { - iface(name, param) then "iface "+name+" "+to_String(param) - } - . - -define String - _to_String - ( - List(Network_Parameter) interface_entries, - String so_far //this is so far of the section, not the general file - )= - if interface_entries is - { - [] then so_far, - [h . t] then - _to_String(t, so_far + "\t"+to_String(h)+"\n") - }. - -public define String - to_String - ( - List(Network_entry) network_entries, - String so_far - )= - if network_entries is - { - [] then so_far, - [h . t] then - if h is - { - blank then to_String(t, so_far+"\n"), - comment(comment) then to_String(t, so_far + comment), - section(net_type, params) then to_String(t, so_far+"auto "+net_type.name+"\n"+ - to_String(net_type)+"\n"+ - _to_String( params, "")) - } - }. - - -define Maybe(Network_Parameter) - extract_value - ( - String name, - String left_line - )= - //println(" Extract value for name ["+name+"] in ["+left_line+"]"); - if find_char(left_line, '#', 0) is - { - failure then success(conf_nv(name, left_line)), - success(idx) then - if sub_string(left_line, 0, idx) is - { - failure then failure, - success(value) then - if sub_string(left_line, idx+1, (length(left_line) - (idx+1))) is - { - failure then success(conf_nv(name, value)), - //println("conf_nv found name="+name+" value="+value); - success(comment) then success(conf_nvc(name, value, comment)) - //println("conf_nvc found name="+name+" value="+value+" comment="+comment); - - } - } - }. - -define Maybe(Network_Parameter) - get_network_parameter - ( - List(String) params - )= - if params is - { - [] then failure, - [ name . t] then - //println("Get network parameter for ["+name+"]"); - if nth((Int)0, name) is - { - failure then failure, - success(c) then - if c = '#' then - success(comment(join(" ",params))) - else - extract_value(name, join(" ",t)) - } - }. - -define Maybe(Network_type) - get_type - ( - String line, - String name - )= - if split_by_token(line, ' ') is - { - [ ] then failure, - [type . t] then - if type = "iface" then - if t is - { - [] then - //println("WARNING unamed iface section ["+name+"]"); - failure, - [h . t] then - //check if auto name is equal to iface name - if h = name then - if get_network_parameter(t) is - { - failure then failure, - success(net_param) then success(iface(name, net_param)) - } - else - failure - } - else failure - }. - -define List(Network_Parameter) - parse_section_body - ( - Stream s, - List(Network_Parameter) so_far - )= - if read_line(s) is - { - failure then reverse(so_far), - success(line) then println(line); - if nth((Int)0, line) is - { - failure then reverse(so_far), - success(c) then - if c = ' ' | c='\t' then - //it seem to be a a real section body entry we try it - //println("parse section line ["+trim(line)+"]"); - if get_network_parameter(split_by_token(trim(line), ' ')) is - { - failure then reverse(so_far), - success(param) then parse_section_body(s,[param . so_far]) - } - else - // itsn't part of section body, so we stop here and unput the line read - //and return the found Network_Parameter - //println("Not body part ["+trim(line)+"]"); - unput_line(s, line); - reverse(so_far) - } - }. - -define Network_entry - parse_section - ( - Stream s, - String line - ) = - if split_by_token(line, ' ') is - { - [ ] then blank, - [h . t] then - if h = "auto" then - if t is - { - [] then blank, - //println("WARNING unamed section ["+h+"]"); - [ name . t ] then - //println("auto found with name ["+name+"]"); - //read the second line of the section where the type is located i.e. iface - if read_line(s) is - { - failure then blank, - success(type_line) then - //println("get type line for "+name+"["+trim(type_line)+"]"); - if get_type(trim(type_line), name) is - { - failure then - //println("type not found for "+name); - blank, - success(type_entry) then - //println("type found, parse for section"); - section(type_entry, parse_section_body(s,[])) - } - } - } - else - blank - }. - - -define Network_entry - read_interface_entry - ( - Stream s, - String line - )= - //check for comment - if nth((Int)0,line) is - { - failure then blank, - success(c) then - if c = '#' then - comment(line) - else - parse_section(s, trim(line)) - }. - -define List(Network_entry) - read_interface_entries - ( - Stream s, - List(Network_entry) so_far - )= - if read_line(s) is - { - failure then reverse(so_far), - success(line) then - //println("["+line+"]"); - read_interface_entries(s, [read_interface_entry(s, line) . so_far]) - }. - -public define List(Network_entry) - read_interface - ( - String interface_file - ) = - if (Maybe(RStream))file(interface_file, read) is - { - failure then [], //nothing to read - success(f) then //parse file for each entry - read_interface_entries(make_stream(f), []) - }. - -public define String - dump_interface_file - = - to_String(read_interface("/calexium/interfaces"),""). - -public define Maybe(One) - write_interface - ( - String file_name, - List(Network_entry) entries - )= - if (Maybe(RWStream))file(file_name, new) is - { - failure then failure, - success(f) then success(forget(reliable_write(f, to_byte_array(to_String(entries, ""))))) - }. - -//ipconfig(String ip, -// String mask, -// String gateway, -// List(String) dns). - - -define One - write_ip_config_linux - ( - IpConfig ip_config, - ) = - with file_name = "/etc/network/interfaces", - interfaces_file = read_interface(file_name), - interfaces_file = update_entry(interfaces_file, "br0", "address",ip_config.ip,[], false), - interfaces_file = update_entry(interfaces_file, "br0", "netmask",ip_config.mask,[], false), - interfaces_file = update_entry(interfaces_file, "br0","gateway",ip_config.gateway,[], false), - forget(write_interface(file_name, interfaces_file)) - . - - - -public define Maybe(One) - write_network_config_linux - ( - IpConfig wan_config - ) = - - write_ip_config_linux(wan_config); - write_dns_list(wan_config.dns); - sync_fs; - success(unique). - - - - /** here tool for testing - * anbexec parse_interface - * will produce a dump of given_file into file named as original with ".dump" as an extension - */ - -global define One - parse_interface - ( - List(String) args - )= - if args is - { - [] then print("usage : parse_interface "), - [ file_name . t ] then - write_ip_config_linux(ipconfig("192.168.4.0","255.255.0.255","0.0.0.0",[])) - } - . - +/* + * Created by PyramIDE. + * User: Alexis & Totoro + * Date: 03/09/2012 + * Time: 16:05 + * + */ + +read system/logger.anubis +read system/string.anubis +read tools/basis.anubis +read tools/streams.anubis +read types/network_types.anubis +read config/dns_config.anubis +read tools/os.anubis + +delete_entry +find_entry +replace_entry = ok +add_entry + + +public type Network_Parameter: + comment(String), + conf_nv(String name, String value), + conf_nvc(String name, String value, String comment). + + +public type Network_type: + iface(String name, Network_Parameter param). + +public type Network_entry: + blank, + comment(String comment), + section(Network_type net_type, List(Network_Parameter) params). + + +define Maybe(Network_Parameter) + _update_param + ( + Network_Parameter param, + String entry_name, + String value + )= + if param is + { + comment(_) then failure, + conf_nv(name,_) then + if name = entry_name then success(conf_nv(name, value)) + else failure, + conf_nvc(name,_,c) then + if name = entry_name then success(conf_nvc(name, value,c)) + else + failure, + } + . +define List(Network_Parameter) + _update_entry + ( + List(Network_Parameter) params, + String entry_name, + String value, + List(Network_Parameter) so_far, + Bool add, //means add the value if not found + Bool found // + )= + if params is + { + [] then if add & found = false then + reverse([conf_nv(entry_name, value) . so_far]) + else + reverse(so_far), + + [ h . t ] then + with result = _update_param(h,entry_name,value), + if result is + { + failure then _update_entry(t, entry_name, value, [h . so_far], add, found), + success(entry) then _update_entry(t, entry_name, value, [entry . so_far], add, true), + } + + }. + +define Network_entry + _update_entry_type + ( + Network_type net_type, + List(Network_Parameter) params, + String name_port, // i.e eth0,br0 + String entry_name, + String value, + List(Network_Parameter) so_far, + Bool add + )= + if name_port = net_type.name then + if _update_param(net_type.param,entry_name,value) is + { + failure then section(net_type,_update_entry(params,entry_name,value,so_far, add, false)), + success(param) then section(iface(name_port,param),params) //if the value changed is network_type + } + else section(net_type,params) + . + +define List(Network_entry) + update_entry + ( + List(Network_entry) entries, + String name_port, // i.e eth0,br0 + String entry_name, + String value, + List(Network_entry) so_far, + Bool add //for add an entry or not + )= + if entries is + { + [] then reverse(so_far), + [h . t] then + if h is + { + blank then update_entry(t, name_port, entry_name, value, [h . so_far], add), + comment(_) then update_entry(t, name_port, entry_name, value, [h . so_far], add), + section(net_type,params) then update_entry(t, name_port, entry_name, value, + [_update_entry_type(net_type, params, name_port, entry_name, value, [], add) . so_far], add) + } + } + . + +define String + to_String + ( + Network_Parameter i_entry, + )= + if i_entry is + { + comment(s) then s, + conf_nv(n,v) then n +" "+v, + conf_nvc(n,v,c) then n+" "+v+" "+c + }. + +define String + to_String + ( + Network_type n_type + )= + if n_type is + { + iface(name, param) then "iface "+name+" "+to_String(param) + } + . + +define String + _to_String + ( + List(Network_Parameter) interface_entries, + String so_far //this is so far of the section, not the general file + )= + if interface_entries is + { + [] then so_far, + [h . t] then + _to_String(t, so_far + "\t"+to_String(h)+"\n") + }. + +public define String + to_String + ( + List(Network_entry) network_entries, + String so_far + )= + if network_entries is + { + [] then so_far, + [h . t] then + if h is + { + blank then to_String(t, so_far+"\n"), + comment(comment) then to_String(t, so_far + comment), + section(net_type, params) then to_String(t, so_far+"auto "+net_type.name+"\n"+ + to_String(net_type)+"\n"+ + _to_String( params, "")) + } + }. + + +define Maybe(Network_Parameter) + extract_value + ( + String name, + String left_line + )= + //println(" Extract value for name ["+name+"] in ["+left_line+"]"); + if find_char(left_line, '#', 0) is + { + failure then success(conf_nv(name, left_line)), + success(idx) then + if sub_string(left_line, 0, idx) is + { + failure then failure, + success(value) then + if sub_string(left_line, idx+1, (length(left_line) - (idx+1))) is + { + failure then success(conf_nv(name, value)), + //println("conf_nv found name="+name+" value="+value); + success(comment) then success(conf_nvc(name, value, comment)) + //println("conf_nvc found name="+name+" value="+value+" comment="+comment); + + } + } + }. + +define Maybe(Network_Parameter) + get_network_parameter + ( + List(String) params + )= + if params is + { + [] then failure, + [ name . t] then + //println("Get network parameter for ["+name+"]"); + if nth((Int)0, name) is + { + failure then failure, + success(c) then + if c = '#' then + success(comment(join(" ",params))) + else + extract_value(name, join(" ",t)) + } + }. + +define Maybe(Network_type) + get_type + ( + String line, + String name + )= + if split_by_token(line, ' ') is + { + [ ] then failure, + [type . t] then + if type = "iface" then + if t is + { + [] then + //println("WARNING unamed iface section ["+name+"]"); + failure, + [h . t] then + //check if auto name is equal to iface name + if h = name then + if get_network_parameter(t) is + { + failure then failure, + success(net_param) then success(iface(name, net_param)) + } + else + failure + } + else failure + }. + +define List(Network_Parameter) + parse_section_body + ( + Stream s, + List(Network_Parameter) so_far + )= + if read_line(s) is + { + failure then reverse(so_far), + success(line) then println(line); + if nth((Int)0, line) is + { + failure then reverse(so_far), + success(c) then + if c = ' ' | c='\t' then + //it seem to be a a real section body entry we try it + //println("parse section line ["+trim(line)+"]"); + if get_network_parameter(split_by_token(trim(line), ' ')) is + { + failure then reverse(so_far), + success(param) then parse_section_body(s,[param . so_far]) + } + else + // itsn't part of section body, so we stop here and unput the line read + //and return the found Network_Parameter + //println("Not body part ["+trim(line)+"]"); + unput_line(s, line); + reverse(so_far) + } + }. + +define Network_entry + parse_section + ( + Stream s, + String line + ) = + if split_by_token(line, ' ') is + { + [ ] then blank, + [h . t] then + if h = "auto" then + if t is + { + [] then blank, + //println("WARNING unamed section ["+h+"]"); + [ name . t ] then + //println("auto found with name ["+name+"]"); + //read the second line of the section where the type is located i.e. iface + if read_line(s) is + { + failure then blank, + success(type_line) then + //println("get type line for "+name+"["+trim(type_line)+"]"); + if get_type(trim(type_line), name) is + { + failure then + //println("type not found for "+name); + blank, + success(type_entry) then + //println("type found, parse for section"); + section(type_entry, parse_section_body(s,[])) + } + } + } + else + blank + }. + + +define Network_entry + read_interface_entry + ( + Stream s, + String line + )= + //check for comment + if nth((Int)0,line) is + { + failure then blank, + success(c) then + if c = '#' then + comment(line) + else + parse_section(s, trim(line)) + }. + +define List(Network_entry) + read_interface_entries + ( + Stream s, + List(Network_entry) so_far + )= + if read_line(s) is + { + failure then reverse(so_far), + success(line) then + //println("["+line+"]"); + read_interface_entries(s, [read_interface_entry(s, line) . so_far]) + }. + +public define List(Network_entry) + read_interface + ( + String interface_file + ) = + if (Maybe(RStream))file(interface_file, read) is + { + failure then [], //nothing to read + success(f) then //parse file for each entry + read_interface_entries(make_stream(f), []) + }. + +public define String + dump_interface_file + = + to_String(read_interface("/calexium/interfaces"),""). + +public define Maybe(One) + write_interface + ( + String file_name, + List(Network_entry) entries + )= + if (Maybe(RWStream))file(file_name, new) is + { + failure then failure, + success(f) then success(forget(reliable_write(f, to_byte_array(to_String(entries, ""))))) + }. + +//ipconfig(String ip, +// String mask, +// String gateway, +// List(String) dns). + + +define One + write_ip_config_linux + ( + IpConfig ip_config, + ) = + with file_name = "/etc/network/interfaces", + interfaces_file = read_interface(file_name), + interfaces_file = update_entry(interfaces_file, "br0", "address",ip_config.ip,[], false), + interfaces_file = update_entry(interfaces_file, "br0", "netmask",ip_config.mask,[], false), + interfaces_file = update_entry(interfaces_file, "br0","gateway",ip_config.gateway,[], false), + forget(write_interface(file_name, interfaces_file)) + . + + + +public define Maybe(One) + write_network_config_linux + ( + IpConfig wan_config + ) = + + write_ip_config_linux(wan_config); + write_dns_list(wan_config.dns); + sync_fs; + success(unique). + + + + /** here tool for testing + * anbexec parse_interface + * will produce a dump of given_file into file named as original with ".dump" as an extension + */ + +global define One + parse_interface + ( + List(String) args + )= + if args is + { + [] then print("usage : parse_interface "), + [ file_name . t ] then + write_ip_config_linux(ipconfig("192.168.4.0","255.255.0.255","0.0.0.0",[])) + } + . + diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index 2fba0b1..2a42491 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -3496,7 +3496,7 @@ define Printable_tree text, "" ], - img_link(img,alt_text) then + img_link(img, alt_text) then [ "\""" diff --git a/web/js_tools.anubis b/web/js_tools.anubis new file mode 100644 index 0000000..99ad31b --- /dev/null +++ b/web/js_tools.anubis @@ -0,0 +1,37 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ + * Date: 18/04/2015 + * Time: 23:21 + * © Calexium + */ + +define List(Word8) + make_js_string + ( + List(Word8) current, + List(Word8) so_far + ) + = + if current is + { + [ ] then reverse(so_far), + [h . t] then + make_js_string(t, + if h = '\'' then + [h . ['\\' . so_far]] + else + [h . so_far] + ) + }. + +/** + * Convert a string into certified javascript string (I hope) + */ +public define String + make_js_string + ( + String str + ) + = + implode(make_js_string(explode(str), [])). diff --git a/web/widgets/button.anubis b/web/widgets/button.anubis new file mode 100644 index 0000000..6982de2 --- /dev/null +++ b/web/widgets/button.anubis @@ -0,0 +1,57 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ & Juju + * Date: 18/04/2015 + * Time: 20:46 + * © Calexium + */ + +read calexium_lib/web/CXM_making_a_web_site.anubis + +public define HTML_Partial_Content + img_button + ( + String img_path, + String url, + List((String, String)) extra_ops + )= + partial_content(actioner(same, same, img_link(img_path, ""), url, extra_ops)). + +public define HTML_Partial_Content + img_button + ( + String img_path, + String url + )= + img_button(img_path, url, []). + +public define HTML_Partial_Content + img_button_confirm + ( + String img_path, + String dlg_title, + String dlg_text, + String dlg_ok, + String dlg_cancel, + String url, + List((String, String)) extra_ops + )= + partial_content([js(js_file("js/cxm/cxm.js"))], + image([style("cursor: pointer"), event(onclick, "CalexiumToolBox.make_confirm_dialog('" + dlg_title + "', + '" + dlg_text + "', + '" + dlg_ok + "', + '" + dlg_cancel + "', + '/?a=" + url + format_extra_operands(extra_ops)+"');")], img_path, "")). + +public define HTML_Partial_Content + img_button_confirm + ( + String img_path, + String dlg_title, + String dlg_text, + String dlg_ok, + String dlg_cancel, + String url + )= + img_button_confirm(img_path, dlg_title, dlg_text, dlg_ok, dlg_cancel, url, []). + -- libgit2 0.21.4