home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd2.bin / suse / inst-sys / lib / YaST2 / clients / dialup.ycp < prev    next >
Encoding:
Text File  |  2000-03-30  |  73.5 KB  |  1,876 lines

  1. /* 
  2.  *
  3.  * Dial-Up Internet Connection YaST2 module
  4.  *
  5.  * Author:   Petr Hrbek <hrbek@suse.cz>
  6.  *
  7.  * Purpose: 
  8.  * This module executes wvdialconf program, which tries autodetection of modem
  9.  * and it tries autodetection of ISDN device (libhd library).
  10.  * If modem or ISDN device  was found it offers Predefined ISPs and shows it's
  11.  * specification (phone, username, password) with two extra profiles (Current 
  12.  * settings and Generic). You can modify specification by hand. 
  13.  *
  14.  * Second screen is Modem/ISDN configuration. Next step writes your configuration 
  15.  * into config files.
  16.  *
  17.  * Accessed Config files:
  18.  * /etc/wvdial.conf  
  19.  * /etc/rc.config.d/i4l_hardware.rc.config (only ISDN)
  20.  * /etc/rc.config.d/i4l.rc.config  (only ISDN)
  21.  * /etc/rc.config (only ISDN)
  22.  * /etc/ppp/pap-secrets (only ISDN)
  23.  * /etc/ppp/chap-secrets (only ISDN)
  24.  * /etc/ppp/options.ippp0 (only ISDN)
  25.  * 
  26.  * Needed external programs:
  27.  * wvdialconf
  28.  */ 
  29.  
  30. {
  31.  
  32. // Menuentry for the YaST2 menu
  33. if (Args() == [ "get_menuentry" ]) 
  34.     return [ "dialup", $[
  35.                     `menuentry    : UI(_("Network/Modem+ISDN")),
  36.                     `arguments    : [ ],
  37.                     `widget       : `RichText(
  38.                                                UI(_("Choose this item to configure your modem or ISDN-card for the connection to your ISP."))
  39.                                                  +
  40.                                                  UI(_("<P><P>You need to be logged in as <I>root</I>."))),
  41.                     `codefragment : nil ]
  42.   ];
  43.  
  44.  
  45.   // get full name of device from .probe device map
  46.   define name_of_device (map device) ``{
  47.     string sub_vendor = lookup (device, "sub_vendor", "");
  48.     string sub_device = lookup (device, "sub_device", "");
  49.     if ((sub_vendor != "") && (sub_device != ""))
  50.    return (sub_vendor + " " + sub_device);
  51.     else
  52.    return (lookup (device, "vendor", "") + " " + lookup (device, "device", ""));
  53.   };
  54.  
  55. // Any agent for reading rc.config file
  56. SCR(``{
  57.    MountAgent (`anyagent(
  58.       ``Description (
  59.          ``File("/etc/rc.config"),   // real file name
  60.             "#\n",         // Comment
  61.             false,         // read-only
  62.             ``List(
  63.                Tuple(
  64.                   Optional(String(" ")),
  65.                   `key (String("^ =")),
  66.                   Separator ("= "),
  67.                   Optional(`value (String("^\n")))
  68.                ),
  69.                "\n"
  70.             )
  71.    )), .etc.rc_config);
  72. });
  73.  
  74. SCR(``{
  75.    MountAgent (`anyagent(
  76.       ``Description (
  77.          ``File("/etc/route.conf"),   // real file name
  78.             "#\n",         // Comment
  79.             true,         // read-only
  80.             ``List(
  81.                Tuple(
  82.                   `key (String("^ ")),
  83.                   Separator (" "),
  84.                   Optional(`value (String("^\n")))
  85.                ),
  86.                "\n"
  87.             )
  88.    )), .etc.route_conf);
  89. });
  90.    void|map predefined_providers = ReadY2("providers.ycp");
  91.  
  92.  
  93. // ISDN protocols structure
  94.    map isdn_prot = $[
  95. // Type of ISDN protocol (1TR6, Euro-ISDN Leased line)
  96.       1   :   UI(_("1TR6")),
  97.       2   :   UI(_("Euro-ISDN (EDSS1)")),
  98.       3   :   UI(_("Leased line"))
  99.    ];
  100.    
  101.    list valid_bauds = [1200,2400,4800,9600,19200,38400,57600,115200,230400,460800];
  102.    list def_IPs = ["30.0.0.","20.0.0.","12.0.0.","10.0.0.","192.168.0."];
  103.  
  104.  
  105. // Was ISDN/modem device detected?
  106.    boolean isdn_det = false;
  107.    boolean modem_det = false;
  108.  
  109. // Entries of /etc/wvdial.conf
  110.    string init1 = "";
  111.    string init2 = "";
  112.    string init3 = "";
  113.    string prefix = "";
  114.    void|boolean tone_dial = nil;
  115.    boolean pbx = false;
  116.    void|boolean verbose = nil;
  117.    string tel_no = ""; 
  118.    string username = ""; 
  119.    string pass = ""; 
  120.    boolean stupid = true;
  121.    boolean compuserve = false;
  122.    map providers = $[];
  123.    if (predefined_providers != nil)
  124.       providers = predefined_providers;
  125.    map providers_names = $[];
  126.    list sbox_entry = [];
  127.    string wvdial_write_section = "/usr/bin/wvdial-write-section";
  128.    boolean usb = false;
  129.  
  130.    string isdn4all = "no";        // only root may dial-out (ISDN4ALL="false" in rc.config)
  131.  
  132.    void|string selected_provider = nil;
  133.    string  sec = "";
  134.    list keys = [];
  135.    map entries = $[]; 
  136.    string kname = "";
  137.    string kvalue = "";
  138.  
  139.    void|list modem_probe = [];
  140.    list ISDN_probe = [];
  141.    
  142.  
  143. // ISDN AnyAgent structures and vars
  144.    list pap_secrets = [];
  145.    list chap_secrets = [];
  146.    list i4l_rc_config = [];
  147.    list i4l_hardware = [];
  148.    list rc_config = [];
  149.    list ippp_options = [];
  150.    string msn = "";
  151.    string dial_mode = "";
  152.    void|string dev_num = nil;
  153.    void|string card_num = nil;
  154.    string if_config = "";
  155.    boolean dynamic = true; 
  156.    boolean dynDNS = true; 
  157.    boolean boot = true; 
  158.    string IP_local = "";
  159.    string IP_rem = "";
  160.    string net_dev = "";
  161.    string location = "";
  162.    integer protocol = 0;
  163.    string callback_mode = "";
  164.    string type = "";
  165.    string subtype = "";
  166.    string baud = "";
  167.    void|string io = "";
  168.    void|string io0 = "";
  169.    void|string io1 = "";
  170.    void|string io2 = "";
  171.    map card_values = $[
  172.          "I4L_TYPE_" : "",
  173.          "I4L_SUBTYPE_" : "",
  174.          "I4L_IRQ_" : "",
  175.          "I4L_IO_" : "",
  176.          "I4L_IO0_" : "",
  177.          "I4L_IO1_" : "",
  178.          "I4L_IO2_" : "",
  179.          "I4L_MEMBASE_" : ""
  180.    ];
  181.    void|string membase = "";
  182.    void|string irq = "";
  183.    map active = $[];
  184.    map active_pcmcia = $[];
  185.    map net_devs = $[];
  186.    map if_configs = $[];   
  187.    void|string ISDN_desc = nil;
  188.    boolean isdn_pcmcia = false;
  189.    boolean route = true;
  190.  
  191. // Trasformation Anyagent structures to simplier form 
  192.    void|list wvdial_cfg = [];
  193.    map i4l_rc_config_entries = $[];
  194.    map i4l_hardware_entries = $[];
  195.    any tmp = [];
  196.    any tmp2 = [];
  197.    map pap_secrets_int = $[];
  198.    map chap_secrets_int = $[];
  199.    map ippp_options_int = $[];
  200.  
  201.  
  202. // ######################### Taken from lan.ycp script #############################
  203.  
  204. /*
  205.  * Split long string by characters in separator string into list of strings
  206.  *
  207.  *   split("addr:127.0.0.1  Mask:255.0.0.0", ": .") ->
  208.  *   -> ["addr", "127", "0", "0", "1", "Mask", "255", "0", "0", "0"]
  209.  *
  210.  */
  211.    define split(string s, string sep) ``{
  212.       list chars = [];
  213.       integer|void  i = size(sep) - 1;
  214.       while (i >= 0) {   
  215.          chars = add(chars, substring(sep, i, 1));
  216.          i = i - 1;
  217.       }
  218.       chars = add(chars, "");
  219.       list l = [];
  220.       string ch = "";
  221.       i = findfirstnotof(s, sep);
  222.       while (i != nil) {
  223.          s = substring(s, i, size(s) - i);
  224.          i = 0;
  225.          ch = substring(s, 0, 1);
  226.             while (!contains(chars, ch)) {
  227.                i = i + 1;
  228.                ch = substring(s, i, 1);
  229.             } 
  230.          l = add (l, substring(s, 0, i));
  231.          s = substring(s, i, size(s) - i);
  232.          i = findfirstnotof(s, sep);
  233.       }
  234.       return l;
  235.    };
  236.  
  237.  
  238. /*
  239.  * Convert ip address string into list of four integer
  240.  * Return [] in case of syntax error
  241.  *
  242.  * strtoaddr("127.0.0.0") -> [127, 0, 0, 0]
  243.  *
  244.  */
  245.    define strtoaddr(string str) ``{
  246.       integer i = 0;
  247.       integer j = 4;
  248.       integer x = 0;
  249.       list ip = [];
  250.       str =  str + ".";
  251.       while (j > 0) {
  252.          i = findfirstnotof (str, "1234567890");
  253.          if ((substring (str, i, 1) == ".") && (i != 0)) {
  254.             x = tointeger(str);
  255.             if (x > 256) return [];
  256.             ip = add(ip, x);
  257.             str = substring (str, i + 1);
  258.          } else {
  259.             return [];
  260.          }
  261.          j = j - 1;
  262.       }
  263.       if (size(str) > 0) return [];
  264.       return ip;
  265.    };
  266.  
  267. /*
  268.  * Convert integer into list of eight boolean
  269.  *
  270.  */
  271.    define inttobyte(integer i) ``{
  272.       if ((i < 0) || (i > 255)) return [0];
  273.       list y = [];
  274.       do {
  275.          y = add(y, i%2 == 1);
  276.          i = i / 2;
  277.       } while (i > 0);
  278.       return y;
  279.    };
  280.  
  281. /*
  282.  * Convert list of boolean to integer 
  283.  *
  284.  */
  285.    define bytetoint(list a) ``{
  286.       integer i = size(a) - 1;
  287.       integer x = 0;
  288.       while (i >= 0) {
  289.          x = x * 2;
  290.          if (select(a, i)) x = x + 1;
  291.          i = i - 1;
  292.       }
  293.       return x;
  294.    }; 
  295. /*
  296.  * Logical 'and' on boolean elements of lists
  297.  *
  298.  */
  299.    define and(list a, list b) ``{
  300.       list c = [];
  301.       integer no = 0;
  302.       integer i = 0;
  303.       if (size(a) < size(b)) no = size(a);
  304.       else no = size(b);
  305.       while (i < no) {   
  306.          c = add (c, select (a, i) && select(b, i));
  307.          i = i + 1;
  308.       }
  309.       return c;
  310.    };
  311.  
  312. /*
  313.  * Compute network address  from ip and mask
  314.  *
  315.  */
  316.    define getnet (list ip, list mask) ``{
  317.       integer i = 0;
  318.       list net = [];
  319.       while (i < 4) {
  320.          net = add(
  321.             net, 
  322.             bytetoint(
  323.                and(
  324.                   inttobyte(select(ip, i)),
  325.                   inttobyte(select(mask, i))
  326.                )
  327.             )
  328.          );
  329.          i = i + 1;
  330.       }
  331.       return net;
  332.    };
  333.  
  334. // ######################### Taken from lan.ycp script #############################
  335.  
  336.  
  337. // Returns haxadecimal value of input number
  338. // Parameters:      i - number to be converted
  339. // Return Value:   hexadecimal representation of i
  340.    define tohex(integer i) ``{
  341.       integer mod = 0;
  342.       string out = "";
  343.       do {
  344.          mod = i % 16;
  345.          if (mod < 10)
  346.             out = sformat("%1",mod) + out;
  347.          else if (mod == 10)
  348.             out = "A" + out;
  349.          else if (mod == 11)
  350.             out = "B" + out;
  351.          else if (mod == 12)
  352.             out = "C" + out;
  353.          else if (mod == 13)
  354.             out = "D" + out;
  355.          else if (mod == 14)
  356.             out = "E" + out;
  357.          else if (mod == 15)
  358.             out = "F" + out;
  359.          i = i / 16;               
  360.       } while (i > 0);
  361.       out = "0x" + out;
  362.       return out;
  363.    };
  364.  
  365.  
  366.  
  367. // Returns input string without leading and trailing quote
  368. // Parameters:    s - string to unqoute   
  369. // Return Value:   unquoted input string    
  370.    define unquote(string s) ``{
  371.       if (substring(s,0,1) == "\"") {
  372.          s = substring(s,1,(size(s)-1));
  373.          if (substring(s,size(s)-1,1) == "\"") 
  374.             s = substring(s,0,(size(s)-1));
  375.       }
  376.       return s;
  377.    };
  378.  
  379.  
  380.  
  381.  
  382. // Reads modem configuration file (/etc/wvdial.conf) and convert it to simplier form
  383. // Parameters: location (string) - selected group of C-b-C providers       
  384. //               rebuild_providers - completely rebuild providers structure (speed)
  385. // Return Value:       
  386.    define read_cfg_modem(string location, boolean rebuild_providers) ``{
  387.       providers_names = $[];
  388.       if (rebuild_providers) {
  389.          wvdial_cfg = SCR(`Read(.etc.wvdialconf)); 
  390.          providers = $[];
  391.          if (predefined_providers != nil)
  392.             providers = predefined_providers;
  393.          if (wvdial_cfg != nil)
  394.             tmp = maplist(`entry, wvdial_cfg, ``{
  395.                entries = $[];
  396.                sec = lookup (entry, "section","");
  397.                keys = lookup (entry, "contents","");
  398.    
  399.                tmp2 = maplist(`keys_entry, keys, ``{
  400.                   kname = lookup (keys_entry, "keyname","");
  401.                   kvalue = lookup (keys_entry,"keyvalue","");
  402.                   entries = add(entries,kname,kvalue);
  403.                });
  404.                providers = add(providers,sec,entries);
  405.             });     
  406.       }
  407.  
  408.       string description = "";
  409.  
  410. // Creates providers_names map for SelectionBox
  411.       tmp = maplist(`ISP_name, `ISP_data, providers, ``{ 
  412.          if ((((location == "`ger")&&(lookup(ISP_data,"Country","") == "Germany"))
  413.              ||((location == "`UK")&&(lookup(ISP_data,"Country","") == "UK"))
  414.             ||((location == "`USA")&&(lookup(ISP_data,"Country","") == "USA"))
  415.             ||(ISP_name == "Dialer Defaults"))&&(((isdn_det)&&(lookup(ISP_data,"ISDN supported","") == "1"))||(modem_det))) {
  416.             if ((ISP_name == "Dialer Defaults")&&(modem_det))
  417.                description = "Edit";
  418.             else if ((lookup(ISP_data,"Connection name","") == "") && (lookup(ISP_data,"Provider","") == ""))
  419.                description = ISP_name;
  420.             else if (lookup(ISP_data,"Provider","") == "")
  421.                description = ISP_name;
  422.             else {
  423.                description = lookup(ISP_data,"Provider", "");
  424.                description = description + " ("+lookup(ISP_data,"Product", "")+")";
  425.             }
  426.             providers_names = add(providers_names,ISP_name,description);
  427.          }
  428.       });
  429.    };
  430.  
  431.  
  432. // Gets free device number of network devices
  433. // Parameters:
  434. // Return Value:  
  435.    define get_dev_num() ``{
  436.       rc_config = SCR(`Read(.etc.rc_config));
  437.       dev_num = nil;
  438.       integer i = 0;
  439.       while(i <= 3) {
  440.          active = $[];
  441.          active_pcmcia = $[];
  442.          tmp = maplist (`entry, rc_config, ``{
  443.             if (lookup(entry,"key","") == sformat("NETDEV_%1",i)) 
  444.                net_devs = add(net_devs,i,unquote(lookup(entry,"value","")));
  445.             if (lookup(entry,"key","") == sformat("IFCONFIG_%1",i)) 
  446.                if_configs = add(if_configs,i,unquote(lookup(entry,"value","")));
  447.             if (lookup(entry,"key","") == "IP_DYNIP") 
  448.                if (unquote(lookup(entry,"value","")) == "no")
  449.                   dynamic = false;
  450.                else
  451.                   dynamic = true;
  452.             if (lookup(entry,"key","") == "I4L_START") 
  453.                if (unquote(lookup(entry,"value")) == "yes")
  454.                   boot = true;
  455.                else
  456.                   boot = false;
  457.             if (lookup(entry,"key","") == "NETCONFIG")
  458.                tmp2 = maplist(`entry2, split(unquote(lookup(entry,"value",""))," "), ``{
  459.                   active = add(active,tointeger(filterchars(entry2,"0123")),"1");   
  460.                });
  461.             if (lookup(entry,"key","") == "NETCONFIG_PCMCIA")
  462.                tmp2 = maplist(`entry2, split(unquote(lookup(entry,"value",""))," "), ``{
  463.                   active_pcmcia = add(active_pcmcia, tointeger(filterchars(entry2,"0123")),"1");   
  464.                });
  465.          });
  466.  
  467.          if ((dev_num == nil)&&((lookup(net_devs,i,"") == "")||(lookup(net_devs,i,"") == "isdn0")||(lookup(net_devs,i,"") == "ippp0"))) {
  468.             dev_num = sformat("%1",i);
  469.             net_dev = lookup(net_devs,i,"");
  470.          }
  471.          i=i+1;
  472.       }   
  473.       if (dev_num != nil) {
  474.          if_config = lookup(if_configs,tointeger(dev_num),"");
  475.          if (if_config != "") {
  476.             IP_local = select(split(if_config," "),0);
  477.             IP_rem = select(split(if_config," "),3);
  478.          }
  479.       }
  480.    };
  481.  
  482.  
  483.  
  484. // Reads ISDN configuration files and convert it to simplier form
  485. // Parameters:       
  486. // Return Value:       
  487.    define read_cfg_ISDN() ``{
  488.       
  489.       get_dev_num();
  490.       card_num = "1";      
  491.       any key = nil;
  492.       any value = nil;
  493.       any ret = nil;
  494.  
  495.       pap_secrets = SCR(`Read(.etc.ppp.pap_secrets)); 
  496.       chap_secrets = SCR(`Read(.etc.ppp.chap_secrets));
  497.       ret = Shell("if test ! -f /etc/ppp/options.ippp0 ; then cp /etc/ppp/ioptions.YaST /etc/ppp/options.ippp0; fi;");
  498.       ippp_options = SCR(`Read(.etc.ppp.ioptions)); 
  499.       i4l_rc_config = SCR(`Read(.etc.i4l)); 
  500.       i4l_hardware = SCR(`Read(.etc.i4l_hw)); 
  501.       tmp = maplist (`entry, pap_secrets, ``{
  502.          pap_secrets_int = add(pap_secrets_int,lookup(entry,"client",""),$["server":lookup(entry,"server",""), "secret":lookup(entry,"secret","")]);
  503.       }); 
  504.       tmp = maplist (`entry, chap_secrets, ``{
  505.          chap_secrets_int = add(chap_secrets_int,lookup(entry,"client",""),$["server":lookup(entry,"server",""), "secret":lookup(entry,"secret","")]);
  506.       }); 
  507.  
  508.       tmp = maplist(`entry, i4l_rc_config, ``{
  509.          key = lookup (entry, "key","");
  510.          value = lookup (entry, "value","");
  511.          i4l_rc_config_entries = add(i4l_rc_config_entries,key,unquote(value));
  512.       });     
  513.       tmp = maplist(`entry, i4l_hardware, ``{
  514.          key = lookup (entry, "key","");
  515.          value = lookup (entry, "value","");
  516.          i4l_hardware_entries = add(i4l_hardware_entries,key,unquote(value));
  517.       });     
  518.       tmp = maplist(`entry, ippp_options, ``{
  519.          key = lookup (entry, "key","");
  520.          value = lookup (entry, "value","");
  521.          if (value == nil)
  522.             value = "";
  523.          ippp_options_int = add(ippp_options_int,key,unquote(value));
  524.       });     
  525.       if (lookup(ippp_options_int,"ms-get-dns","") == nil)
  526.          dynDNS = false;
  527.       providers_names = add(providers_names,"Dialer Defaults",UI(_("Edit")));
  528.       providers = add(providers,"Dialer Defaults",$["Phone":filterchars(lookup(i4l_rc_config_entries,"I4L_REMOTE_OUT_"+dev_num,""),"1234567890 ,*#-"),"Username":lookup(ippp_options_int,"user",""),"Password":lookup((lookup(pap_secrets_int,lookup(ippp_options_int,"user",""),lookup(pap_secrets_int,"\""+lookup(ippp_options_int,"user")+"\""))),"secret")]);
  529.    };
  530.  
  531. // Check function for valid Phone number and Area Code
  532. // Parameters:         caller - function from which was is_valid called
  533. //                     field - TextEntry name for error message 
  534. //                     s - checked string
  535. //                     op - needed operation ("v" - validation for phone strings,
  536. //                                          "e" - string can't be empty,
  537. //                                          "i" - string is valid IP)
  538. //                                          "b" - baud rate validation)
  539. // Return Value:      caller (if there are invalid chars)
  540.    define is_valid(any caller, string field, string s, string op) ``{
  541.       string help = "";
  542.       void|term contents = nil;
  543.       
  544.       if ((s != filterchars(s,"1234567890,*#- "))&&(filterchars(op,"v") == "v")) {
  545. // Invalid characters in various fields of dialogs (almost telephone numbers) 
  546.           help = sformat(UI(_("<P>You entered invalid characters in field \"%1\".</P><P>Valid characters 
  547. are <B>numbers</B>, <B>*</B>, <B>#</B>, <B>SPACE</B>, <B>-</B> and 
  548. <B>,</B>.</P>
  549. ")),field);
  550.           contents = 
  551.             `HSquash(`VBox(
  552. // Label for error screen if invalid characters were writen 
  553.                `Label(sformat(UI(_("Invalid characters in field \"%1\"!")),field)),`Empty()));
  554.  
  555. // Title for screen if invalid characters were writen 
  556.       }
  557.  
  558.       if (filterchars(op,"b") == "b") {
  559.          boolean err = true;
  560.          string valid_rates = "";
  561.          tmp = maplist(`entry, valid_bauds, ``{
  562.             if (s == sformat("%1",entry))
  563.                err = false;
  564.                valid_rates = valid_rates + entry + ", ";
  565.          });  
  566.          valid_rates = substring(valid_rates,0,size(valid_rates)-2);
  567.          if (err) {
  568. // Invalid baudrate heltext 
  569.           help = sformat(UI(_("<P>Please choose a valid <B>baud rate</B>.</P><P>Possible values are %1.</P>")),valid_rates);
  570.           contents = 
  571.             `HSquash(`VBox(
  572. // Label for error screen if invalid baudrate writen 
  573.                `Label(UI(_("Invalid baud rate"))),`Empty()));
  574.          }   
  575.  
  576. // Title for screen if invalid characters were writen 
  577.       }
  578.  
  579.       if (filterchars(op,"i") == "i") {
  580.          list parts = split(s,".");
  581.          boolean err = false;
  582.          tmp = maplist(`entry, parts, ``{
  583.             if (entry != nil)
  584.                if ((tointeger(entry) < 0)||(tointeger(entry) > 255)||(filterchars(entry,"1234567890") != entry)) 
  585.                   err = true;
  586.          });  
  587.          if ((err)||((size(parts) != 4)&&(s != ""))) 
  588. // Invalid IP address inserted 
  589.           help = sformat(UI(_("Please enter a valid IP address in the field \"%1\".")),field);
  590.           contents = 
  591.             `HSquash(`VBox(
  592. // Label for error screen if invalid characters were writen 
  593.                `Label(sformat(UI(_("Invalid IP address format in field \"%1\"")),field)),`Empty()));
  594.  
  595. // Title for screen if invalid characters were writen 
  596.       }
  597.  
  598.       if ((s == "")&&(filterchars(op,"e") == "e")) {
  599. // Empty value of field where is value needed) 
  600.           help = sformat(UI(_("<P>The field \"%1\" must not be empty.</P><P>Please enter a value.</P>")),field);
  601.          contents = 
  602.             `HSquash(`VBox(
  603. // Label for error screen if invalid characters were writen 
  604.                `Label(sformat(UI(_("The field \"%1\" must not be empty")),field)),`Empty()));
  605.  
  606. // Title for screen if invalid characters were writen 
  607.       }
  608.       if (help != "") {
  609.          any ret = UI(`ShowPage(_("Input error"),contents,help,true,true));
  610.          return caller;
  611.       }
  612.    };
  613.  
  614.  
  615.  
  616. // Modem and ISDN device detection function
  617. // Parameters:       
  618. // Return Value:      `check_devices
  619.    define modem_detection() ``{
  620. // Deletes Modem entry from /etc/wvdial.conf 
  621.       tel_no = "";
  622.       username = "";
  623.       pass = "";
  624.       location = "";
  625.       modem_det = false;
  626.       isdn_det = false;
  627.       read_cfg_modem("",true);
  628.       if (save_cfg_modem(true) == `back)
  629.          return back;   
  630.  
  631.       UI(``{
  632. // Help text for autodetection screen. It dissapears automaticaly when autodetection is done
  633.          ChangeWidget(`id(`help), `Value, _("<P>An attempt to find external modems and internal modems will be made.<P>If 
  634. you are using an <I>ISA-PnP or PCI-Modem</I>, please refer to the 
  635. manual.</P><P><B>Please wait...</B></P>
  636. "));
  637.          ChangeWidget(`id(`title), `Value, _("Modem and ISDN autodetection"));
  638.          ChangeWidget(`id(`back), `Enabled, false);
  639.          ChangeWidget(`id(`next), `Enabled, false);
  640.          ChangeWidget(`id(`next), `Label, _("&Next"));
  641.          ReplaceWidget(`id(`contents), 
  642.          `HSquash(`VBox(
  643. // Autodetection is running
  644.             `Label(_("Modem device detection in progress...")),`Empty()))
  645.          );
  646.       });
  647. // Runs wvdialconf which detect modem and writes device, bauds and init string into cfg file 
  648.       any ret = Shell("wvdialconf /etc/wvdial.conf");
  649.       UI(`ChangeWidget(`id(`next), `Enabled, true));
  650.       modem_probe = SCR(`Read(.probe.byclass.modem));   
  651.       ISDN_probe = SCR(`Read(.probe.byclass.isdn));   
  652.       
  653.       return `check_devices;
  654.    };
  655.  
  656. // Check if modem or ISDN was detected by modem_detection function
  657. // Parameters:       
  658. // Return Value:      `ISP_sel if modem was detected or `back if not
  659.    define check_devices() ``{
  660.       providers = $[];
  661.       read_cfg_modem("",true);
  662.       void|term contents = nil;
  663.       string help = "";
  664.       any ret = nil;
  665.       list tmp = [];
  666.       map isdn_map = $[];
  667.       map isdn_para = $[];
  668.       any modem_desc = nil;
  669.       string|void modem_dev = lookup(lookup(providers,"Dialer Defaults",""),"Modem","");
  670.       if (size(filterchars(modem_dev,"USBACM")) > 1)
  671.          usb = true; 
  672.       if ((modem_dev != nil) && (modem_dev != "")) 
  673.          modem_det = true;
  674.       if (size(ISDN_probe) > 0)
  675.          isdn_det = true;
  676.       if (isdn_det) {
  677.          io = nil;
  678.          irq = nil;
  679.          membase = nil;
  680.          type = "";
  681.          subtype = "";
  682.             
  683.          tmp = maplist(`entry, ISDN_probe, ``{
  684.             isdn_map = lookup(entry, "isdn","");
  685.             ISDN_desc = lookup(isdn_map, "name","");
  686.             type = sformat("%1",lookup(isdn_map,"type"));
  687.             subtype = sformat("%1",lookup(isdn_map,"subtype",""));
  688.             isdn_para = lookup(isdn_map, "parameter","");
  689.             card_values = add(card_values, "I4L_TYPE_", type); 
  690.             card_values = add(card_values, "I4L_SUBTYPE_", subtype); 
  691.             if (size(isdn_para) > 0) {
  692.                foreach(`k, `v, isdn_para, ``{
  693.                   if (k == "IRQ") {
  694.                      irq = sformat("%1", select(v, 0));
  695.                      card_values = add(card_values, "I4L_IRQ_", irq); 
  696.                   }
  697.                   if (k == "IO") {
  698.                      io = sformat("%1", select(v, 0));
  699.                      card_values = add(card_values, "I4L_IO_",
  700.                         tohex(tointeger(io))); 
  701.                   }
  702.                   if (k == "IO0") {
  703.                      io0 = sformat("%1", select(v, 0));
  704.                      card_values = add(card_values, "I4L_IO0_",
  705.                         tohex(tointeger(io0))); 
  706.                   }
  707.                   if (k == "IO1") {
  708.                      io1 = sformat("%1", select(v, 0));
  709.                      card_values = add(card_values, "I4L_IO1_", 
  710.                         tohex(tointeger(io1))); 
  711.                   }
  712.                   if (k == "IO2") {
  713.                      io2 = sformat("%1", select(v, 0));
  714.                      card_values = add(card_values, "I4L_IO2_",
  715.                         tohex(tointeger(io2))); 
  716.                   }
  717.                   if (k == "MEMBASE") {
  718.                      mem = sformat("%1", select(v, 0));
  719.                      card_values = add(card_values, "I4L_MEMBASE_",
  720.                         tohex(tointeger(mem))); 
  721.                   }
  722.                });
  723.             }
  724.          });
  725.       }      
  726. // Get modem description from libhd structure
  727.       if (modem_det) {
  728.          if (modem_dev != "/dev/modem")
  729.             Shell("/bin/ln -sf "+modem_dev+" /dev/modem");          
  730.          tmp = maplist(`entry, modem_probe, ``{
  731.               if (lookup(lookup(entry,"attached_to",""),"dev_name") == modem_dev)
  732.                  modem_desc = name_of_device(entry);
  733.          });
  734.          if (modem_desc == nil) 
  735.             modem_desc = lookup(lookup(providers,"Dialer Defaults"),"Modem Name",nil);
  736.          if (modem_desc == nil)
  737.             modem_desc = UI(_("Unknown"));
  738. // Generates screen with information about detected devices 
  739.  
  740.          if (isdn_det) {
  741. // If there are more detected devices, user has to select which of them will be configured
  742.             help = UI(_("<P>Both an <B>ISDN card</B> and a <B>modem</B> were detected.</P>"));
  743.             help = help + UI(_("<P>Please select the one that will be used for the internet connection.</P>
  744. "));
  745. //            help = help + UI(_("<P>Note: there are other names for serial ports in Linux (/dev/ttyS0 = COM1, /dev/ttyS1 = COM2...)</P>"));
  746.             contents = 
  747.                `HSquash(`VBox(
  748.                      `Left(`Label(_("Hardware probing found several devices for internet connection"))),
  749.                      `Left(`Label(_("Please choose which one to configure:"))),
  750.                      `RadioButtonGroup(`id(`dev),
  751.                         `VBox(
  752. // Description of detected ISDN device
  753.                            `Left(`RadioButton(`id(`ISDN), sformat(UI(_("&ISDN card %1")),ISDN_desc),true)),            
  754. // Description of detected modem 
  755.                            `Left(`RadioButton(`id(`modem), sformat(UI(_("&Modem %1 on %2")),modem_desc, modem_dev)))            
  756.                         )
  757.                      )
  758.                ));
  759.             ret = UI(`ShowPage(_("Internet configuration"),contents,help,true,true));
  760.             if (ret == `next) {
  761.                isdn_det = UI(`QueryWidget(`id(`ISDN), `Value));
  762.                modem_det = UI(`QueryWidget(`id(`modem), `Value));
  763.                return `ISP_sel;
  764.             }
  765.             else if (ret == `cancel)
  766.                return `cancel;
  767.             else
  768.                return `back;
  769.          }
  770.          else {
  771. // There was only one device (modem) detected and in next dialogs it'll be configured
  772.               help = UI(_("<P>A <B>modem</B> was detected.</P><P>Please continue with the configuration 
  773. of your connection to your ISP.</P>
  774. "));
  775.               help = help + UI(_("<P>Note: Serial ports in Linux are named differently than in DOS, e.g., 
  776. /dev/ttyS0 = COM1, /dev/ttyS1 = COM2...</P>
  777. "));
  778.             contents = 
  779.                `HSquash(`VBox(
  780. // Description of detected modem
  781.                      `Label(sformat(UI(_("A modem\n\n     %1\n\n was detected on %2 and will be configured\nfor internet access")), modem_desc, modem_dev)),`Empty()));
  782.             ret = UI(`ShowPage(_("Internet configuration"),contents,help,true,true));
  783.             if (ret == `next)
  784.                return `ISP_sel;
  785.             else if (ret == `cancel)
  786.                return `cancel;
  787.             else
  788.                return `back;
  789.          }
  790.       }
  791.       else {
  792.          if (isdn_det) {
  793. // There was only one device (ISDN card) detected and in next dialogs it'll be configured
  794.             help = UI(_("<P>An <B>ISDN card</B> was detected.</P><P>Please continue with the 
  795. configuration of the connection to your ISP.</P>
  796. "));
  797.             contents = 
  798.                `HSquash(`VBox(
  799. // Description of detected ISDN card
  800.                   `Label(sformat(UI(_("An ISDN card\n\n     %1\n\n was detected and will be configured for internet access")),ISDN_desc)),`Empty()));
  801.             ret = UI(`ShowPage(_("Internet configuration"),contents,help,true,true));
  802.             if (ret == `next)
  803.                return `ISP_sel;
  804.             else if (ret == `cancel)
  805.                return `cancel;
  806.             else
  807.                return `back;
  808.          }
  809.          else {
  810. // No configurable device found
  811. // html-format / help start
  812.             help = UI(_("<p>Neither an ISDN card nor a modem was found.</p>"));
  813. // html-format / help 2
  814.             help = help + UI(_("\
  815. <p>
  816. If you are using a <b>PCI-Modem</b> run <i>lspci -v</i> and determine the IRQ and PORT.
  817. Then execute <i>setserial /dev/modem port PORT irq IRQ</i> and try again.</p>
  818. <p>
  819. <b>ISA-PnP card</b>: run <i>pnpdump -c > /etc/isapnp.conf</i> and
  820. <i>isapnp /etc/isapnp.conf</i>.<br>
  821. Determine the IRQ and PORT. Then execute <i>setserial /dev/modem port PORT irq IRQ</i>
  822. and try again.</p>
  823. "));
  824. // html-format / help 3
  825.             help = help + UI(_("\
  826. <p>
  827. Further Information can be found in the manual.</p>
  828. <p>
  829. If you are able to connect to the internet on another machine, have a look at
  830. the support database 'http://sdb.suse.de/sdb/en/html' and the modem trouble shooting
  831. tool 'http://sdb.suse.de/sdb/en/html/hoe_wvcheck.html'.</p>
  832. "));
  833.             contents = 
  834.                `HSquash(`VBox(
  835.                   `Label(_("Sorry, neither a modem nor an ISDN device was found")),
  836.                   `HBox(
  837. //Try again autodetection of ISDN device
  838.                   `PushButton(`id(`try), _("&Try again")),
  839. //Manual ISDN card configuration (if no ISDN card found)
  840.                   `PushButton(`id(`ISDN_man), _("&Manual ISDN device configuration"))
  841. )));
  842.             ret = UI(`ShowPage(_("Internet access"),contents,help,true,false));
  843.             if (ret == `try)
  844.                return `modem_detection;
  845.             if (ret == `ISDN_man)
  846.                return `ISDN_man;
  847.             else if (ret == `cancel)
  848.                return `cancel;
  849.             else
  850.                return `back;
  851.          }
  852.       }
  853.    };
  854.  
  855.  
  856. //Manual ISDN device configuration
  857. //Parameters:         -
  858. //Return value:       `dev_cfg (if NEXT was pressed) or `modem_detection (BACK)
  859.    define ISDN_man() ``{
  860. //Manual selection of ISDN card (if autodetection fails) 
  861.       string help = UI(_("You need to select the type of your <B>ISDN</B> card and enter the required parameters manually (possible values of the parameters are shown)"));
  862.       list ISDN_devices = SCR(`Read(.probe.ihw_data));
  863.       list card_list = [];
  864.       map IO_ISDN = $[];
  865.       map IRQ_ISDN = $[];
  866.       map MEM_ISDN = $[];
  867.       map TYPES_ISDN = $[];
  868.       map SUBTYPES_ISDN = $[];
  869.       map CLASS_ISDN = $[];
  870.       map DESC_ISDN = $[];
  871.       list IO_list = [];
  872.       list IRQ_list = [];
  873.       list MEM_list = [];
  874.  
  875.       integer i = 0;
  876.       integer j = 0;
  877.       integer cl = 0;
  878.       boolean initsel = false;
  879.       string old_type = "";
  880.       string old_subtype = "";
  881.  
  882.       // Read current settings
  883.       read_cfg_ISDN();
  884.       old_type = lookup(i4l_hardware_entries, "I4L_TYPE_1", "0");
  885.       old_subtype = lookup(i4l_hardware_entries, "I4L_SUBTYPE_1", "0");
  886.       // Get information for manual selection 
  887.       tmp = maplist(`entry, ISDN_devices, ``{
  888.          cl = lookup(entry,"class");
  889.      // only legal ISA PCMCIA and parallel port devices are allowed
  890.      if ((cl == 3) || (cl == 4) || (cl == 6)) {
  891.             DESC_ISDN = add(DESC_ISDN, i, lookup(entry,"name"));
  892.             type = sformat("%1",(lookup(entry,"type")));
  893.             subtype = sformat("%1",(lookup(entry,"subtype")));
  894.             TYPES_ISDN = add(TYPES_ISDN, i, (lookup(entry,"type")));
  895.             SUBTYPES_ISDN = add(SUBTYPES_ISDN,i,(lookup(entry,"subtype","")));
  896.             CLASS_ISDN = add(CLASS_ISDN, i, cl);
  897.             if ((old_type == type) && (old_subtype == subtype))
  898.                initsel = true;
  899.             else
  900.                initsel = false;
  901.             card_list = add(card_list,`item(`id(i),(lookup(entry,"name")),initsel));
  902.          if (lookup(entry,"parameter") != nil) {
  903.             if ((lookup(lookup(entry,"parameter"),"IO")) != nil)
  904.                IO_ISDN = add(IO_ISDN,i,lookup(lookup(entry,"parameter",[]),"IO",[]));
  905.             else
  906.                IO_ISDN = add(IO_ISDN,i,[]);
  907.             if ((lookup(lookup(entry,"parameter"),"IRQ")) != nil)
  908.                IRQ_ISDN = add(IRQ_ISDN,i,lookup(lookup(entry,"parameter",[]),"IRQ",[]));
  909.             else
  910.                IRQ_ISDN = add(IRQ_ISDN,i,[]);
  911.             if ((lookup(lookup(entry,"parameter"),"MEMBASE")) != nil)
  912.                MEM_ISDN = add(MEM_ISDN,i,lookup(lookup(entry,"parameter",[]),"MEMBASE",[]));
  913.             else
  914.                 MEM_ISDN = add(MEM_ISDN,i,[]);
  915.             } else {
  916.             IO_ISDN = add(IO_ISDN,i,[]);
  917.             IRQ_ISDN = add(IRQ_ISDN,i,[]);
  918.             MEM_ISDN = add(MEM_ISDN,i,[]);
  919.          }   
  920.             if (initsel) {
  921.                IO_list = [];
  922.                IRQ_list = [];
  923.                MEM_list = [];
  924.                j = 0;
  925.                tmp = maplist(`entry, lookup(IO_ISDN,i), ``{
  926.                   if ((j > 0)||(size(lookup(IO_ISDN,i)) == 1))
  927.                   IO_list = add(IO_list,`item(`id(entry),tohex(entry),(tohex(entry) == lookup(i4l_hardware_entries, "I4L_IO_1"))));
  928.                   j=j+1;
  929.                });
  930.                j = 0;
  931.                tmp = maplist(`entry, lookup(IRQ_ISDN,i), ``{
  932.                   if ((j > 0)||(size(lookup(IRQ_ISDN,i)) == 1))
  933.                   IRQ_list = add(IRQ_list,`item(`id(entry),sformat("%1",entry),(sformat("%1",entry)==lookup(i4l_hardware_entries, "I4L_IRQ_1"))));
  934.                   j=j+1;
  935.                });
  936.                j = 0;
  937.                tmp = maplist(`entry, lookup(MEM_ISDN,i), ``{
  938.                   if ((j > 0)||(size(lookup(MEM_ISDN,i)) == 1))
  939.                   MEM_list = add(MEM_list,`item(`id(entry),tohex(entry), (tohex(entry) == lookup(i4l_hardware_entries, "I4L_MEMBASE_1"))));
  940.                   j=j+1;
  941.                });
  942.             }
  943.          i=i+1;
  944.          }
  945.       });
  946.  
  947.       term contents = 
  948.          `HSquash(`VBox(
  949.                `SelectionBox(`id(`sel_card),`opt(`notify), 
  950.                   _("Select your ISDN card: "), card_list), 
  951.                `HBox(
  952.                   `ReplacePoint(`id(`io_repl),`SelectionBox(`id(`io),_("IO address"),IO_list)),
  953.                   `ReplacePoint(`id(`irq_repl),`SelectionBox(`id(`irq),_("IRQ"),IRQ_list)),
  954.                   `ReplacePoint(`id(`mem_repl),`SelectionBox(`id(`mem),_("MemBase"),MEM_list))
  955.                )
  956.          ));
  957.       any ret = UI(`ShowPage(_("Manual ISDN selection and configuration"),contents,help,true,true));
  958.       while (ret != `next && ret != `back && ret != `cancel) {
  959.     //If there was change in SelectionBox parameters are updated
  960.             if (ret == `sel_card) {
  961.                i = UI(`QueryWidget(`id(`sel_card), `CurrentItem));
  962.                IO_list = [];
  963.                IRQ_list = [];
  964.                MEM_list = [];
  965.                j = 0;
  966.                tmp = maplist(`entry, lookup(IO_ISDN,i,""), ``{
  967.                   if ((j > 0)||(size(lookup(IO_ISDN,i,"")) == 1))
  968.                   IO_list = add(IO_list,`item(`id(entry),tohex(entry),(entry == select(lookup(IO_ISDN,i,""),0))));
  969.                   j=j+1;
  970.                });
  971.                j = 0;
  972.                tmp = maplist(`entry, lookup(IRQ_ISDN,i,""), ``{
  973.                   if ((j > 0)||(size(lookup(IRQ_ISDN,i,"")) == 1))
  974.                   IRQ_list = add(IRQ_list,`item(`id(entry),sformat("%1",entry),(entry == select(lookup(IRQ_ISDN,i,""),0))));
  975.                   j=j+1;
  976.                });
  977.                j = 0;
  978.                tmp = maplist(`entry, lookup(MEM_ISDN,i,""), ``{
  979.                   if ((j > 0)||(size(lookup(MEM_ISDN,i,"")) == 1))
  980.                   MEM_list = add(MEM_list,`item(`id(entry),tohex(entry),(entry == select(lookup(MEM_ISDN,i,""),0))));
  981.                   j=j+1;
  982.                });
  983.                UI(`ReplaceWidget(`id(`io_repl), `SelectionBox(`id(`io),_("IO address (PORT)"), IO_list)));
  984.                UI(`ReplaceWidget(`id(`irq_repl), `SelectionBox(`id(`irq),_("IRQ"), IRQ_list)));
  985.                UI(`ReplaceWidget(`id(`mem_repl), `SelectionBox(`id(`mem),_("MemBase"), MEM_list)));
  986.             }
  987.             ret = UI(`UserInput());
  988.       } 
  989. // If you click on NEXT button, contents of widgets are stored into YaST2 variables 
  990.       if (ret == `next) 
  991.          if (UI(`QueryWidget(`id(`sel_card), `CurrentItem)) == nil)
  992.             return `modem_detection;
  993.          else {    
  994.             if (UI(`QueryWidget(`id(`io), `CurrentItem)) != nil) {
  995.                io = sformat("%1",UI(`QueryWidget(`id(`io), `CurrentItem)));
  996.                card_values = add(card_values, "I4L_IO_",
  997.                   tohex(tointeger(io))); 
  998.             }
  999.             if (UI(`QueryWidget(`id(`irq), `CurrentItem)) != nil)  {
  1000.                irq = sformat("%1",UI(`QueryWidget(`id(`irq), `CurrentItem)));
  1001.                card_values = add(card_values, "I4L_IRQ_",
  1002.                   irq); 
  1003.             }
  1004.             if (UI(`QueryWidget(`id(`mem), `CurrentItem)) != nil)  {
  1005.                membase = sformat("%1",UI(`QueryWidget(`id(`mem), `CurrentItem)));
  1006.                card_values = add(card_values, "I4L_MEMBASE_",
  1007.                   tohex(tointeger(membase))); 
  1008.             }
  1009.             if (lookup(TYPES_ISDN,UI(`QueryWidget(`id(`sel_card), `CurrentItem))) != nil) {
  1010.                type = sformat("%1",lookup(TYPES_ISDN,UI(`QueryWidget(`id(`sel_card), `CurrentItem))));
  1011.                card_values = add(card_values, "I4L_TYPE_", type); 
  1012.             }
  1013.             if (lookup(SUBTYPES_ISDN,UI(`QueryWidget(`id(`sel_card), `CurrentItem))) != nil) {
  1014.                subtype = sformat("%1",lookup(SUBTYPES_ISDN,UI(`QueryWidget(`id(`sel_card), `CurrentItem))));
  1015.                card_values = add(card_values, "I4L_SUBTYPE_", subtype); 
  1016.             }
  1017.             // Filter PCMCIA devices for NETCONFIG_PCMCIA
  1018.             if (lookup(CLASS_ISDN,UI(`QueryWidget(`id(`sel_card), `CurrentItem))) != nil) {
  1019.                cl = lookup(CLASS_ISDN,UI(`QueryWidget(`id(`sel_card), `CurrentItem)));
  1020.                if (cl == 4)
  1021.                   isdn_pcmcia = true;
  1022.             }
  1023.             ISDN_desc = lookup(DESC_ISDN,(UI(`QueryWidget(`id(`sel_card), `CurrentItem))),"");
  1024.             isdn_det = true;
  1025.             return `ISP_sel;
  1026.          }
  1027.       else if (ret == `back)
  1028.          return `modem_detection;
  1029.       else if (ret == `cancel)
  1030.          return `cancel;
  1031.    };
  1032.  
  1033.  
  1034.  
  1035. //ISP selection screen for modem and ISDN device
  1036. //Parameters:         -
  1037. //Return value:       `device_cfg (if NEXT was pressed) or `modem_detection (BACK)
  1038.    define ISP_sel() ``{
  1039.       string help = "";
  1040.       read_cfg_modem(location,true);
  1041.       if (isdn_det) 
  1042.          read_cfg_ISDN();
  1043.       sbox_entry = [];
  1044. // Making content of SelectionBox with ISPs (stored as sbox_entry list)
  1045.       tmp = maplist(`key, `value, providers_names, ``{
  1046.          if (key == selected_provider)
  1047.             sbox_entry = add(sbox_entry,`item(`id(key),value, true));
  1048.          else  
  1049.             sbox_entry = add(sbox_entry,`item(`id(key),value, false));
  1050.       });
  1051. // "Generic" ISP added (if there wasn't any ISP selected, this entry is default
  1052.       if ((selected_provider == "") || (selected_provider == nil))
  1053. // "Empty" ISP 
  1054.          sbox_entry = flatten([ [`item(`id(""),_("New"),true)], sbox_entry]);
  1055.       else
  1056.          sbox_entry = flatten([ [`item(`id(""),_("New"),false)], sbox_entry]);
  1057.       term contents = 
  1058.          `HSquash(`VBox(
  1059. //Location of Call-by-Call providers (UK, Germany and USA) filter
  1060.                `Frame(_("Provider location"),`RadioButtonGroup(`id(`loc),
  1061.                   `HBox(
  1062.                      `RadioButton(`id(`ger),`opt(`notify),_("Germany"), (location == "`ger")),
  1063.                      `RadioButton(`id(`UK),`opt(`notify),_("UK"), (location == "`UK")),
  1064.                      `RadioButton(`id(`USA),`opt(`notify),_("USA"), (location == "`USA"))
  1065.                ,`HStretch()))),
  1066.                `ReplacePoint(`id(`prov),`SelectionBox(`id(`cbc),`opt(`notify), 
  1067.                   _("Select a provider: "), sbox_entry)), 
  1068.                   `HBox(
  1069.                      `HWeight(20,`TextEntry(`id(`tel_no),_("Phone number"),tel_no)),
  1070.                      `HWeight(80,`HStretch())),
  1071.                   `HBox(
  1072.                      `HWeight(40,`TextEntry(`id(`username),_("User ID"),username)),
  1073.                      `HWeight(40,`Password(`id(`pass),_("Password"),pass))
  1074.                )
  1075.          ));
  1076.       string current_provider = ""; 
  1077. //Predefined provider's selection (for these providers Tel. No, Username and Password values are set
  1078.       help = UI(_("<P>Please choose:<UL><LI> <I>new</I> and enter the <I>tel. no., login</I> and <I>password,</I></LI><LI>or select a predefined Call-by-Call provider from the list for your country,</LI><LI>or edit the current settings, please choose the item <I>edit</I>.</LI></UL></P>"));
  1079.       any ret = UI(`ShowPage(_("Internet access - Provider configuration"),contents,help,true,true));
  1080.       repeat {
  1081. //If there was change in SelectionBox phone, username and password are updated
  1082.          if (ret == `cbc) {
  1083.             current_provider = UI(`QueryWidget(`id(`cbc), `CurrentItem));
  1084.             if (current_provider != "") {
  1085.                tel_no = lookup(lookup(providers, current_provider,""), "Phone", "");
  1086.                username = lookup(lookup(providers, current_provider, ""), "Username", "");
  1087.                pass = lookup(lookup(providers, current_provider, ""), "Password", "");
  1088.                if (lookup(lookup(providers,current_provider,""),"Compuserve","") == "1")
  1089.                   compuserve = true;
  1090.                else
  1091.                   compuserve = false;
  1092.                if (lookup(lookup(providers,current_provider,""),"Stupid Mode","") != "1")
  1093.                   stupid = false;
  1094.                else
  1095.                   stupid = true;
  1096.               }
  1097.             else {
  1098.                tel_no = "";
  1099.                username = "";
  1100.                pass = "";
  1101.                compuserve = false;
  1102.                stupid = true;
  1103.             }
  1104.             UI(`ChangeWidget(`id(`tel_no), `Value, tel_no));
  1105.             UI(`ChangeWidget(`id(`username), `Value, username));
  1106.             UI(`ChangeWidget(`id(`pass), `Value, pass));
  1107.             ret = UI(`UserInput());
  1108.          }
  1109.          else if ((ret == `ger)||(ret == `UK)||(ret == `USA)) {
  1110.             location = sformat("%1",ret);
  1111.             read_cfg_modem(location,false);
  1112.             if (isdn_det)
  1113.                read_cfg_ISDN();
  1114.             sbox_entry = [];
  1115.             tmp = maplist(`key, `value, providers_names, ``{
  1116.                if (key == selected_provider)
  1117.                   sbox_entry = add(sbox_entry,`item(`id(key),value, true));
  1118.                else  
  1119.                   sbox_entry = add(sbox_entry,`item(`id(key),value, false));
  1120.             });
  1121.             if ((selected_provider == "") || (selected_provider == nil))
  1122.                sbox_entry = flatten([ [`item(`id(""),_("New"),true)], sbox_entry]);
  1123.             else
  1124.                sbox_entry = flatten([ [`item(`id(""),_("New"),false)], sbox_entry]);
  1125.          
  1126. //Let user to select provider
  1127.             UI(`ReplaceWidget(`id(`prov),`SelectionBox(`id(`cbc),`opt(`notify),_("Select a provider"), sbox_entry))); 
  1128.             UI(`ChangeWidget(`id(`tel_no), `Value, ""));
  1129.             UI(`ChangeWidget(`id(`username), `Value, ""));
  1130.             UI(`ChangeWidget(`id(`pass), `Value, ""));
  1131.             tel_no = "";
  1132.             username = "";
  1133.             pass = "";
  1134.             ret = UI(`UserInput());
  1135.          }
  1136.    
  1137.          
  1138.       } until (ret == `next || ret == `back || ret == `cancel);
  1139. // If you click on NEXT button, contents of widgets are stored into YaST2 variables 
  1140.       if (ret == `next) {
  1141.          selected_provider = UI(`QueryWidget(`id(`cbc), `CurrentItem));
  1142.          username = UI(`QueryWidget(`id(`username), `Value));
  1143.          pass = UI(`QueryWidget(`id(`pass), `Value));
  1144.          tel_no = UI(`QueryWidget(`id(`tel_no), `Value));
  1145.          if (is_valid(`ISP_sel,UI(_("Telephone number")),tel_no,"ve") != `ISP_sel) 
  1146.             return `device_cfg;
  1147.          else
  1148.             return `ISP_sel;
  1149.       }
  1150.       else if (ret == `back)
  1151.          return `modem_detection;
  1152.       else if (ret == `cancel)
  1153.          return `cancel;
  1154.    };
  1155.  
  1156. //ISDN configuration screen
  1157. //Parameters:         -
  1158. //Return value:      `ISP_sel (BACK) or `ISDN_net_cfg (NEXT)
  1159.    define ISDN_cfg() ``{
  1160.       string help = UI(_("<P>Please enter the parameters for your internet connection.</P>"));
  1161. // If this screen wasn't already shown, defaults from cfg file are used
  1162.       if (msn == "")
  1163.          msn = lookup(i4l_rc_config_entries,"I4L_LOCALMSN_"+dev_num,"0");
  1164.       if (protocol == 0) {
  1165.          if (lookup(i4l_hardware_entries,"I4L_PROTOCOL_"+card_num,"") == "1")
  1166.             protocol = 1;
  1167.          else if (lookup(i4l_hardware_entries,"I4L_PROTOCOL_"+card_num,"") == "3")
  1168.             protocol = 3;
  1169.          else 
  1170.             protocol = 2;
  1171.       }
  1172.       if (callback_mode == "") 
  1173.          if (lookup(i4l_rc_config_entries,"I4L_CALLBACK_"+dev_num,"") != nil)
  1174.             callback_mode = lookup(i4l_rc_config_entries,"I4L_CALLBACK_"+dev_num,"");
  1175.  
  1176.       if (dial_mode == "")
  1177.          if (lookup(i4l_rc_config_entries,"I4L_DIALMODE_"+dev_num,"") != nil)
  1178.             dial_mode = lookup(i4l_rc_config_entries,"I4L_DIALMODE_"+dev_num,"");
  1179.  
  1180.       term contents = 
  1181.             `HSquash(`VBox(
  1182.                   `TextEntry(`id(`msn), _("Local number (MSN)"),msn), `HStretch(), 
  1183.                   `HBox(
  1184. //Type of ISDN protocol
  1185.                      `Frame(_("ISDN protocol"),`RadioButtonGroup(`id(`protocol),
  1186.                                 `VBox(
  1187.                                  `Left(`RadioButton(`id(`prot_1),lookup(isdn_prot,1),(protocol == 1))),
  1188.                                  `Left(`RadioButton(`id(`prot_2),lookup(isdn_prot,2),((protocol == 0)||(protocol == 2)))),
  1189.                                  `Left(`RadioButton(`id(`prot_3),lookup(isdn_prot,3),(protocol == 3)))
  1190.                      ))),
  1191. //ISDN callback mode selection
  1192.                      `Frame(_("ISDN Callback configuration"),`RadioButtonGroup(`id(`callback),
  1193.                                 `VBox(
  1194.                                  `Left(`RadioButton(`id(`in),_("Callback Server"),(callback_mode == "in"))),
  1195.                                  `Left(`RadioButton(`id(`out),_("Callback Client"),(callback_mode == "out"))),
  1196.                                  `Left(`RadioButton(`id(`off),_("Callback Off"),(callback_mode == "off")||(callback_mode == "")))
  1197.                      )))),
  1198.                   `HBox(
  1199. //Type of device (isdn0/ippp0) selection
  1200.                      `Frame(_("Network device type"),`RadioButtonGroup(`id(`netdev),
  1201.                                 `VBox(
  1202.                                  `Left(`RadioButton(`id(`ippp0),_("ISDN SyncPPP"),((net_dev == "ippp0")||(net_dev == "")))),
  1203.                                  `Left(`RadioButton(`id(`isdn0),_("ISDN Raw IP"),(net_dev == "isdn0")))
  1204.                      ))),
  1205. //Dial mode selection
  1206.                      `Frame(_("Dial mode"),`RadioButtonGroup(`id(`dial),
  1207.                                 `VBox(
  1208. //Automatic dial mode
  1209.                                  `Left(`RadioButton(`id(`auto),_("Automatic"),((dial_mode == "auto")||(dial_mode == "")))),
  1210. //Manual dial mode
  1211.                                  `Left(`RadioButton(`id(`manual),_("Manual"),(dial_mode == "manual"))),
  1212. //Dial mode off
  1213.                                  `Left(`RadioButton(`id(`off),_("Off"),(dial_mode == "off")))
  1214.                   )))),
  1215.         `CheckBox(`id(`only_root), _("ISDN access for 'root' only"), (isdn4all == "no"))
  1216.             ));
  1217.       any ret = UI(`ShowPage(_("Internet access - ISDN configuration"),contents,help,true,true));
  1218. // Data from form are stored 
  1219.       msn  = UI(`QueryWidget(`id(`msn), `Value));   
  1220.       if (UI(`QueryWidget(`id(`only_root), `Value))) {
  1221.     isdn4all = "no";
  1222.       }
  1223.       else {
  1224.     isdn4all = "yes";
  1225.       }
  1226.       if (UI(`QueryWidget(`id(`prot_1), `Value)))
  1227.          protocol = 1;
  1228.       else if (UI(`QueryWidget(`id(`prot_2), `Value)))
  1229.          protocol = 2;
  1230.       else if (UI(`QueryWidget(`id(`prot_3), `Value)))
  1231.          protocol = 3;
  1232.  
  1233.       if (UI(`QueryWidget(`id(`in), `Value)))
  1234.          callback_mode = "in";
  1235.       else if (UI(`QueryWidget(`id(`out), `Value)))
  1236.          callback_mode = "out";
  1237.       else if (UI(`QueryWidget(`id(`off), `Value)))
  1238.          callback_mode = "off";
  1239.  
  1240.       if (UI(`QueryWidget(`id(`ippp0), `Value)))
  1241.          net_dev = "ippp0";
  1242.       else if (UI(`QueryWidget(`id(`isdn0), `Value)))
  1243.          net_dev = "isdn0";
  1244.  
  1245.       if (UI(`QueryWidget(`id(`auto), `Value)))
  1246.          dial_mode = "auto";
  1247.       else if (UI(`QueryWidget(`id(`manual), `Value)))
  1248.          dial_mode = "manual";
  1249.       else if (UI(`QueryWidget(`id(`off), `Value)))
  1250.          dial_mode = "off";
  1251.          
  1252.       
  1253.       if (ret == `next) {
  1254.          if (is_valid(`device_cfg,UI(_("Local number (MSN)")),msn,"ve") != `device_cfg) 
  1255.             return `ISDN_net_cfg;   
  1256.          else
  1257.             return `device_cfg;
  1258.       }
  1259.       else if (ret == `back)    
  1260.          return `ISP_sel;
  1261.       else if (ret == `cancel)
  1262.          return `cancel;
  1263.    };
  1264.  
  1265. //ISDN network configuration screen
  1266. //Parameters:         -
  1267. //Return value:      `ISP_sel (BACK) or `save_cfg (NEXT)
  1268.    define ISDN_net_cfg() ``{
  1269. //Configuration of local IP address and remote IP address for Peer-to-Peer internet connection
  1270. // html-format
  1271.       string help = UI(_("<P>You need to enter a local IP address and a 
  1272. remote IP address for your ISP.</P> 
  1273. "));
  1274.       help = help + UI(_("<P>If your provider supports dynamic DNS assignment, you can choose the appropriate checkbox. All major ISPs support this feature.</P>"));
  1275.       integer i = 0;
  1276. //Select default address for IP_local
  1277.       if (IP_local == "")
  1278.          tmp = maplist(`IP_entry, def_IPs, ``{
  1279.             while (i <= 3) {
  1280.                if ((i != tointeger(dev_num)) && (lookup(if_configs,i,"") != "")
  1281.                  && ((lookup(active,i,"") == "1")
  1282.                  || (lookup(active_pcmcia,i,"") == "1"))) {
  1283.                   if_conf = split(lookup(if_configs,i,"")," ");
  1284.                   IP = [];
  1285.                   netmask = [];
  1286.                   net = false;
  1287.                   IP = strtoaddr(select(if_conf,0));
  1288.                   tmp = maplist (`entry, if_conf, ``{
  1289.                      if (net) {
  1290.                         netmask = strtoaddr(entry);
  1291.                         net = false;
  1292.                      }
  1293.                      if (entry == "netmask") 
  1294.                         net = true;
  1295.                   }); 
  1296.                   if ((netmask != [])&&(IP != [])&&(IP_entry+"99" != ""))
  1297.                      if (getnet(IP,netmask) == getnet(strtoaddr(IP_entry+"99"),netmask)) {
  1298.                         IP_local = IP_entry+"99";
  1299.                         break;
  1300.                      }
  1301.                }
  1302.                i = i+1;
  1303.             }
  1304.             if ((0 == size(active)) && (0 == size(active_pcmcia)))
  1305.                IP_local = IP_entry+"99";
  1306.          });
  1307.       i = 0;
  1308. //Select default address for IP_rem
  1309.       if (IP_rem == "")
  1310.          tmp = maplist(`IP_entry, def_IPs, ``{
  1311.             while (i <= 3) {
  1312.                if ((i != tointeger(dev_num)) && (lookup(if_configs,i,"") != "")
  1313.                  && ((lookup(active,i,"") == "1")
  1314.                  || (lookup(active_pcmcia,i,"") == "1"))) {
  1315.                   if_conf = split(lookup(if_configs,i,"")," ");
  1316.                   IP = [];
  1317.                   netmask = [];
  1318.                   net = false;
  1319.                   IP = strtoaddr(select(if_conf,0));
  1320.                   tmp = maplist (`entry, if_conf, ``{
  1321.                      if (net) {
  1322.                         netmask = strtoaddr(entry);
  1323.                         net = false;
  1324.                      }
  1325.                      if (entry == "netmask") 
  1326.                         net = true;
  1327.                   }); 
  1328.                   if ((netmask != [])&&(IP != [])&&(IP_entry+"1" != ""))
  1329.                      if (getnet(IP,netmask) == getnet(strtoaddr(IP_entry+"1"),netmask)) {
  1330.                         IP_rem = IP_entry+"1";
  1331.                         break;
  1332.                      }
  1333.                }
  1334.                i = i+1;
  1335.             }   
  1336.             if ((0 == size(active)) && (0 == size(active_pcmcia)))
  1337.                IP_rem = IP_entry+"1";
  1338.          });
  1339.       term contents = 
  1340.             `HSquash(`VBox(
  1341.                   `Left(`TextEntry(`id(`IP_local), _("Local IP address of your machine"),IP_local)),
  1342. //IP address of Peer for Point-to-Point connection
  1343.                   `Left(`TextEntry(`id(`IP_rem), _("Remote IP address"),IP_rem)),
  1344.                   `Left(`CheckBox(`id(`dynamic), _("Dynamic IP address"),dynamic)),
  1345.                   `Left(`CheckBox(`id(`dynDNS), _("Dynamic DNS assignment"),dynDNS)),
  1346.                   `Left(`CheckBox(`id(`boot), _("Start ISDN during system boot"),boot))
  1347.             ));
  1348.       any ret = UI(`ShowPage(_("Internet access - ISDN network configuration"),contents,help,true,true));
  1349. // Data from form are stored 
  1350.       IP_local = UI(`QueryWidget(`id(`IP_local), `Value));
  1351.       dynamic = UI(`QueryWidget(`id(`dynamic), `Value));
  1352.       IP_rem = UI(`QueryWidget(`id(`IP_rem), `Value));
  1353.       dynDNS = UI(`QueryWidget(`id(`dynDNS), `Value));
  1354.       boot = UI(`QueryWidget(`id(`boot), `Value));
  1355.       if (ret == `next) {
  1356.          i = 0;                  
  1357.          list if_conf = [];
  1358.          list IP = [];
  1359.          list netmask = [];
  1360.          boolean net = false;
  1361.          string conflict = ""; 
  1362.          string conflict_adr = "";
  1363.          while (i <= 3) {
  1364.             if ((i != tointeger(dev_num)) && (lookup(if_configs,i,"") != "")
  1365.               && ((lookup(active,i,"") == "1")
  1366.               || (lookup(active_pcmcia,i,"") == "1"))) {
  1367.                if_conf = split(lookup(if_configs,i,"")," ");
  1368.                IP = [];
  1369.                netmask = [];
  1370.                net = false;
  1371.                IP = strtoaddr(select(if_conf,0));
  1372.                tmp = maplist (`entry, if_conf, ``{
  1373.                   if (net) {
  1374.                      netmask = strtoaddr(entry);
  1375.                      net = false;
  1376.                   }
  1377.                   if (entry == "netmask") 
  1378.                      net = true;
  1379.                }); 
  1380.                if ((netmask != [])&&(IP != [])&&(IP_local != ""))
  1381.                   if (getnet(IP,netmask) == getnet(strtoaddr(IP_local),netmask)) {
  1382.                      conflict_adr = UL(_("Local"));
  1383.                      conflict = lookup(net_devs,0,""); 
  1384.                      break;
  1385.                   }
  1386.                if ((netmask != [])&&(IP != [])&&(IP_rem != ""))
  1387.                   if (getnet(IP,netmask) == getnet(strtoaddr(IP_rem),netmask)) {
  1388.                      conflict_adr = UI(_("Remote"));
  1389.                      conflict = lookup(net_devs,0,""); 
  1390.                      break;
  1391.                   }
  1392.             }
  1393.             i = i+1;
  1394.          }   
  1395.          if (conflict != "") {
  1396. //If input Local IP address conflicts which existing network user is needed to set it again
  1397.             help = sformat(UI(_("You can't use this <B>IP address (%1)</B>, because it is part of an existing, already configured network. Please choose another address ...")),conflict_adr);
  1398.             contents = 
  1399.                `HSquash(`VBox(
  1400.                      `Label(sformat(UI(_("ISDN network conflicts with %1 network device")),conflict)),
  1401.                      `Label(sformat(_("Please set your %1 address again")))));
  1402.             ret = UI(`ShowPage(_("Network device conflict"),contents,help,true,true));
  1403.             return `ISDN_net_cfg;
  1404.          }
  1405.          else {
  1406.             if ((is_valid(`ISDN_net_cfg,UI(_("Local IP address of your machine")),IP_local,"ie") != `ISDN_net_cfg) 
  1407.                &&(is_valid(`ISDN_net_cfg,UI(_("Remote IP address of the P-t-P partner")),IP_rem,"ie") != `ISDN_net_cfg)) 
  1408.                return `save_cfg;   
  1409.             else
  1410.                return `ISDN_net_cfg;
  1411.          }
  1412.       }
  1413.       else     
  1414.          return `device_cfg;
  1415.    };
  1416. //modem configuration screen
  1417. //Parameters:         -
  1418. //Return value:      `ISP_sel (BACK) or `save_cfg (NEXT)
  1419.    define modem_cfg() ``{
  1420. // If this screen wasn't already shown, defaults from cfg file are used
  1421.       string help = "";
  1422. //Setting of Modem specific parameters
  1423.       help = UI(_("<P>If you are on a PBX, you probably have to enter a <B>dial prefix</B>. 
  1424. Often this is <I>9</I>.</P><P> Most of the telephone companies use <I>tone 
  1425. dial</I> as the <B>dial method</B>.</P>
  1426. "));
  1427.       help = help + UI(_("<P>You can adjust the INIT strings for your device. This could be neccessary 
  1428. if you are using a terminal adapter or some special modems.</P>
  1429. "));
  1430.       if (prefix == "")
  1431.          prefix = lookup(lookup(providers,"Dialer Defaults",""),"Area Code","");
  1432.       if (baud == "")
  1433.          baud = lookup(lookup(providers,"Dialer Defaults",""),"Baud","");
  1434.       if (init1 == "")
  1435.          init1 = lookup(lookup(providers,"Dialer Defaults",""),"Init1","");
  1436.       if (init2 == "")
  1437.          init2 = lookup(lookup(providers,"Dialer Defaults",""),"Init2","");
  1438.       if (init3 == "")
  1439.          init3 = lookup(lookup(providers,"Dialer Defaults",""),"Init3","");
  1440.       if (verbose == nil)
  1441.       if (lookup(lookup(providers,"Dialer Defaults",""),"Init9","") == "ATM0")
  1442.          verbose = false;
  1443.       else
  1444.          verbose = true;
  1445.       if (lookup(lookup(providers,"Dialer Defaults",""),"Area Code","") == "")
  1446.          pbx = true;
  1447.       else
  1448.          pbx = false;
  1449.       if (tone_dial == nil)
  1450.          if(filterchars(lookup(lookup(providers,"Dialer Defaults",""),"Dial Command",""),"P") == "P")
  1451.             tone_dial = false;   
  1452.          else
  1453.             tone_dial = true;   
  1454.  
  1455.       term contents = 
  1456.          `HSquash(`VBox(
  1457.                `HBox(
  1458. //Area Code prefix 
  1459.                `TextEntry(`id(`prefix), _("Dial prefix(if needed)"),prefix),  
  1460. //Modem BaudRate
  1461.                `TextEntry(`id(`baud), _("BaudRate"), baud)),
  1462.             `Frame(_("Modem initialization strings"),`VBox(
  1463.             `TextEntry(`id(`init1), _("Init 1"), init1),
  1464.             `TextEntry(`id(`init2), _("Init 2"), init2),
  1465.             `TextEntry(`id(`init3), _("Init 3"), init3)
  1466.             )),
  1467.             `HBox(
  1468. //Modem baudrate 
  1469.                `Frame(_("Dial mode"),`RadioButtonGroup(`id(`dial),
  1470.                           `VBox(`Left(`RadioButton(`id(`tone),_("Tone dialing"),tone_dial)),
  1471.                         `Left(`RadioButton(`id(`pulse),_("Pulse dialing"),!tone_dial))      
  1472.                      ))
  1473.                ),
  1474. //Set modem to be loud
  1475.                   `CheckBox(`id(`verbose), _("Turn on modem speaker"),verbose)
  1476.             )
  1477.          )
  1478.       );
  1479.       any ret = UI(`ShowPage(_("Internet access - Modem configuration"),contents,help,true,true));
  1480. // Data from form are stored 
  1481.       baud = UI(`QueryWidget(`id(`baud), `Value));   
  1482.       init1 = UI(`QueryWidget(`id(`init1), `Value));   
  1483.       init2 = UI(`QueryWidget(`id(`init2), `Value));   
  1484.       init3 = UI(`QueryWidget(`id(`init3), `Value));   
  1485.       prefix = UI(`QueryWidget(`id(`prefix), `Value));   
  1486.       tone_dial = UI(`QueryWidget(`id(`tone), `Value));   
  1487.       verbose = UI(`QueryWidget(`id(`verbose), `Value));   
  1488.       if (prefix != "")
  1489.          pbx = true;
  1490.       else
  1491.          pbx = false;   
  1492.    
  1493.       if (ret == `next) {
  1494.          if ((is_valid(`device_cfg,UI(_("Dial Prefix")),prefix,"v") != `device_cfg) 
  1495.              &&(is_valid(`device_cfg,UI(_("Baud Rate")),baud,"b") != `device_cfg)) 
  1496.             return `save_cfg;   
  1497.          else
  1498.             return `device_cfg;
  1499.       }
  1500.       else if (ret == `back)    
  1501.          return `ISP_sel;
  1502.       else if (ret == `cancel)
  1503.          return `cancel;
  1504.    };
  1505.  
  1506. //Save configuration into /etc/wvdial.conf
  1507. //Parameters:         res_modem (may MODEM entry be deleted? - before autodetection) 
  1508. //Retrun value:      - 
  1509.    define save_cfg_modem (boolean res_modem) ``{
  1510.  
  1511.       list cont = [];
  1512.       list rev_cfg = [];
  1513.       string dial_str = "AT";
  1514.       string help = "";
  1515.       any ret = nil;
  1516.  
  1517. //Finish of modem internet connection configuration
  1518.       help = UI(_("<P><B>Congratulations!!!</B></P><P>Internet connection configuration is finished.</P>"));
  1519.       tmp = maplist(`isp, `keys, providers, ``{
  1520. // Update defaults section of cfg file from user's inputs and convert
  1521. // YaST2 cfg structure back into the AnyAgent structure
  1522.          if (isp == "Dialer Defaults") {
  1523.             if (res_modem)
  1524.                ret = Shell(wvdial_write_section+" 'Modem='");  
  1525.             else {
  1526.                ret = Shell(wvdial_write_section+" 'Baud="+baud+"'");  
  1527.                if (ret == 0)
  1528.                   ret = Shell(wvdial_write_section+" 'Phone="+tel_no+"'");  
  1529.                if (ret == 0)
  1530.                   ret = Shell(wvdial_write_section+" 'Username="+username+"'");  
  1531.                if (ret == 0)
  1532.                   ret = Shell(wvdial_write_section+" 'Password="+pass+"'");  
  1533.                if (ret == 0)
  1534.                   ret = Shell(wvdial_write_section+" 'Init1="+init1+"'");  
  1535.                if (ret == 0)
  1536.                   ret = Shell(wvdial_write_section+" 'Init2="+init2+"'");  
  1537.                if (ret == 0)
  1538.                   ret = Shell(wvdial_write_section+" 'Init3="+init3+"'");  
  1539.                if (ret == 0)
  1540.                   ret = Shell(wvdial_write_section+" 'Area Code="+prefix+"'");  
  1541.                if (ret == 0) {
  1542.                   if (compuserve)
  1543.                      ret = Shell(wvdial_write_section+" 'Compuserve=1'");  
  1544.                   else
  1545.                      ret = Shell(wvdial_write_section+" 'Compuserve=0'");  
  1546.                }
  1547.                if (ret == 0) {
  1548.                   if (stupid)
  1549.                      ret = Shell(wvdial_write_section+" 'Stupid Mode=1'");  
  1550.                   else
  1551.                      ret = Shell(wvdial_write_section+" 'Stupid=0'");  
  1552.                }
  1553.                if (ret == 0) {
  1554.                   if (verbose)
  1555.                      ret = Shell(wvdial_write_section+" 'Init9='");  
  1556.                   else
  1557.                      ret = Shell(wvdial_write_section+" 'Init9=ATM0'");  
  1558.                }
  1559.                if (pbx)
  1560.                   dial_str = dial_str + "X3";
  1561.                if (tone_dial)
  1562.                   dial_str = dial_str + "DT";
  1563.                else
  1564.                   dial_str = dial_str + "DP";
  1565.                if (ret == 0) 
  1566.                ret = Shell(wvdial_write_section+" 'Dial Command="+dial_str+"'");  
  1567.                if (ret == 0) 
  1568.                ret = Shell(wvdial_write_section+" 'Auto DNS=1'");  
  1569.             }
  1570.          }
  1571.       });  
  1572.       if (ret != 0) {
  1573.          help = UI(_("<P>Configuration failed due to configuration writing error.</P><P>You must run configuration as <B>root</B> user!</P>"));
  1574.          term contents = 
  1575.             `HSquash(`VBox(
  1576.                `Label(_("Configuration failed")),
  1577.                `Label(_("I wasn't able to write your configuration to /etc/wvdial.conf")))); 
  1578.          ret = UI(`ShowPage(_("Internet access configuration"),contents,help,true,false));
  1579.          if ((ret == `next)&&(!res_modem))
  1580.             return `next;
  1581.          else if (ret == `cancel)
  1582.             return `cancel;
  1583.          else 
  1584.             return `back;
  1585.       }
  1586.       else if (!res_modem) {
  1587.          term contents = 
  1588.             `HSquash(`VBox(
  1589.                `Label(_("Configuration completed")),
  1590.                `Left(`Label(_("To dial into the internet, type wvdial in a terminal window or on the console."))),
  1591.                `Left(`Label(_("The first connection must be established as user root."))))); 
  1592.          ret = UI(`ShowPage(_("Internet access configuration"),contents,help,true,false));
  1593.          if (ret == `back)
  1594.             return `device_cfg;
  1595.          else if (ret == `cancel)
  1596.               return `cancel;
  1597.          else 
  1598.             return `next;
  1599.       }
  1600.    };
  1601.  
  1602. //Save configuration for ISDN
  1603. //Parameters:         -
  1604. //Return value:      - 
  1605.    define save_cfg_ISDN () ``{
  1606.       string help = "";
  1607.       any fillup = nil;
  1608.       any en_k = nil;
  1609.       any en_v = nil;
  1610.       void|term contents = nil;
  1611.       help = UI(_("<P><B>Congratulations!!!</B></P><P>ISDN Internet connection configuration is finished.</P>"));
  1612.       
  1613.       pap_secrets = [];
  1614.       chap_secrets = [];
  1615.       list ippp_options_new = [];
  1616.       list i4l_rc_config_new = [];
  1617.       list i4l_hardware_new = [];
  1618.  
  1619.       pap_secrets_int = add(pap_secrets_int,"\""+unquote(username)+"\"", $["server" : "*", "secret" : "\""+unquote(pass)+"\""]);
  1620.       chap_secrets_int = add(chap_secrets_int,"\""+unquote(username)+"\"", $["server" : "*", "secret" : "\""+unquote(pass)+"\""]);
  1621.       ippp_options_int = add(ippp_options_int,"user","\""+unquote(username)+"\"");
  1622.       ippp_options_int = add(ippp_options_int,"name","\""+unquote(username)+"\"");
  1623.  
  1624.       if (msn != nil)
  1625.          i4l_rc_config_entries = add (i4l_rc_config_entries,"I4L_LOCALMSN_"+dev_num,msn);
  1626.       if ((tel_no != nil)&&(tel_no != ""))
  1627.       i4l_rc_config_entries = add (i4l_rc_config_entries,"I4L_REMOTE_OUT_"+dev_num,tel_no);
  1628.       if (net_dev == "isdn0")
  1629.          i4l_rc_config_entries = add (i4l_rc_config_entries,"I4L_ENCAP_"+dev_num,"rawip");
  1630.       else
  1631.          i4l_rc_config_entries = add (i4l_rc_config_entries,"I4L_ENCAP_"+dev_num,"syncppp");
  1632.       if ((dial_mode != nil)&&(dial_mode != ""))
  1633.          i4l_rc_config_entries = add (i4l_rc_config_entries,"I4L_DIALMODE_"+dev_num,dial_mode);
  1634.       if ((callback_mode != nil)&&(callback_mode != ""))
  1635.          i4l_rc_config_entries = add (i4l_rc_config_entries,"I4L_CALLBACK_"+dev_num,callback_mode);
  1636.       if (callback_mode == "in")
  1637.          i4l_rc_config_entries = add (i4l_rc_config_entries,"I4L_CBDELAY_"+dev_num,"3");
  1638.       else
  1639.          i4l_rc_config_entries = add (i4l_rc_config_entries,"I4L_CBDELAY_"+dev_num,"1");
  1640. // Hardware 
  1641.       foreach(`k, `v, card_values, ``{
  1642.          i4l_hardware_entries = add (i4l_hardware_entries,k+card_num,v);
  1643.       });
  1644.       if ((protocol != nil)&&(protocol != ""))
  1645.          i4l_hardware_entries = add (i4l_hardware_entries,"I4L_PROTOCOL_"+card_num,sformat("%1",protocol));
  1646.       net_devs = add(net_devs,tointeger(dev_num),net_dev);
  1647.       if ((IP_local != "")&&(IP_rem != ""))
  1648.          if_configs = add(if_configs,tointeger(dev_num),sformat("%1 dynamic pointopoint %2 netmask 255.255.255.255 up",IP_local,IP_rem));
  1649.       else 
  1650.          if_configs = add(if_configs,tointeger(dev_num),"");
  1651.       map rc_config_write = $[];
  1652.       integer i = 0;
  1653.       while (i <= 3) {
  1654.          rc_config_write = add(rc_config_write,"NETDEV_"+sformat("%1",i),[lookup(net_devs,i), "Device attached to network card"]);
  1655.          rc_config_write = add(rc_config_write,"IFCONFIG_"+sformat("%1",i),[lookup(if_configs,i), "ifconfig entry for network card"]);
  1656.          i=i+1;
  1657.       }
  1658.       if (dynamic)
  1659.          rc_config_write = add(rc_config_write,"IP_DYNIP",["yes",
  1660.         "Do you want the \"dynamic IP patch\" to be enabled at bootup? (yes/no)"]);
  1661.       else
  1662.          rc_config_write = add(rc_config_write,"IP_DYNIP",["no",
  1663.         "Do you want the \"dynamic IP patch\" to be enabled at bootup? (yes/no)"]);
  1664.       if (boot)
  1665.          rc_config_write = add(rc_config_write,"I4L_START",["yes","Start ISDN during system boot"]);
  1666.       else
  1667.          rc_config_write = add(rc_config_write,"I4L_START",["no","Do not start ISDN during system boot"]);
  1668.       string out = "";
  1669.       if (isdn_pcmcia) {
  1670.      active_pcmcia = add(active_pcmcia, tointeger(dev_num),"1");
  1671.          tmp = maplist(`key, `value, active_pcmcia, ``{
  1672.             out = out + sformat("_%1 ",key);
  1673.          }); 
  1674.          rc_config_write = add(rc_config_write,"NETCONFIG_PCMCIA", [out,"contains all indices of active PCMCIA network devices"]);
  1675.       } else {
  1676.          active = add(active, tointeger(dev_num),"1");
  1677.          tmp = maplist(`key, `value, active, ``{
  1678.             out = out + sformat("_%1 ",key);
  1679.          }); 
  1680.          rc_config_write = add(rc_config_write,"NETCONFIG",[out,"Number of network cards: \"_0\" for one, \"_0 _1 _2 _3\" for four cards"]);
  1681.       }
  1682.       rc_config_write = add(rc_config_write,"ISDN4ALL",[isdn4all,"Any user may dialout via ISDN ?"]);
  1683.  
  1684.       tmp = maplist(`entry, i4l_rc_config, ``{
  1685.          en_k = lookup(entry, "key");
  1686.          fillup = lookup(entry, "`FILLUP");
  1687.          en_v = lookup(i4l_rc_config_entries, en_k);
  1688.          if (en_v == nil) {
  1689.             i4l_rc_config_new = add(i4l_rc_config_new, entry);
  1690.          } else {
  1691.             i4l_rc_config_new = add(i4l_rc_config_new, $["key":en_k,"value":"\""+en_v+"\"","`FILLUP":fillup]);
  1692.          }
  1693.       });
  1694.  
  1695.       tmp = maplist(`entry, i4l_hardware, ``{
  1696.          en_k = lookup(entry, "key");
  1697.          fillup = lookup(entry, "`FILLUP");
  1698.          en_v = lookup(i4l_hardware_entries, en_k);
  1699.          if (en_v == nil) {
  1700.             i4l_hardware_new = add(i4l_hardware_new, entry);
  1701.          } else {
  1702.             i4l_hardware_new = add(i4l_hardware_new, $["key":en_k,"value":"\""+en_v+"\"","`FILLUP":fillup]);
  1703.          }
  1704.       });
  1705.  
  1706.       tmp = maplist(`key, `value, pap_secrets_int, ``{
  1707.          pap_secrets = add(pap_secrets,$["client":key,"server":lookup(value,"server",""),"secret":lookup(value,"secret","")]);   
  1708.       });
  1709.  
  1710.       tmp = maplist(`key, `value, chap_secrets_int, ``{
  1711.          chap_secrets = add(chap_secrets,$["client":key,"server":lookup(value,"server",""),"secret":lookup(value,"secret","")]);   
  1712.       });
  1713.       
  1714.       tmp = maplist(`entry, ippp_options, ``{
  1715.          en_k = lookup(entry, "key","");
  1716.          fillup = lookup(entry, "`FILLUP");
  1717.          en_v = lookup(ippp_options_int, en_k,"");
  1718.          if (en_v == nil) {
  1719.             ippp_options_new = add(ippp_options_new, entry);
  1720.          } else {
  1721.             if (en_k != "ms-get-dns") {
  1722.                ippp_options_new = add(ippp_options_new, $["key":en_k,"value":en_v,"`FILLUP":fillup]);
  1723.             }
  1724.          }
  1725.       });
  1726.       if (dynDNS) { 
  1727.          ippp_options_new = add(ippp_options_new, $["key":"ms-get-dns",
  1728.             "value":"", "`FILLUP":"# Get dns info from peer\n"]);
  1729.       }
  1730.       any ret = SCR(`Write(.etc.ppp.pap_secrets, pap_secrets)); 
  1731.       if (ret != false)
  1732.          ret = SCR(`Write(.etc.ppp.chap_secrets, chap_secrets)); 
  1733.       if (ret != false)
  1734.          ret = SCR(`Write(.etc.ppp.ioptions, ippp_options_new)); 
  1735.       if (ret != false)
  1736.          ret = SCR(`Write(.etc.i4l,i4l_rc_config_new)); 
  1737.       if (ret != false)
  1738.          ret = SCR(`Write(.etc.i4l_hw,i4l_hardware_new)); 
  1739.       if (ret != false) {
  1740.          ret = SCR(`Write(.etc.rcconfig,rc_config_write)); 
  1741.      Shell("/sbin/SuSEconfig --quick --nonewpackage");
  1742.       }
  1743. //Set default route if needed
  1744.       list|any routes = SCR(`Read(.etc.route_conf));
  1745.       route = true;
  1746.       if (routes != nil)  
  1747.          tmp = maplist(`entry, routes, ``{
  1748.             if (lookup(entry,"key") == "default") {
  1749.                i = 0;
  1750.                tmp2 = maplist (`entry2, split(lookup(entry,"value")," "), ``{
  1751.                   if ((entry2 == "ippp0")||(entry2 == "isdn0"))
  1752.                      i = i + 1;
  1753.                });   
  1754.                if (i == 0)
  1755.                   route = false; 
  1756.             }
  1757.          });
  1758.       if (route) {
  1759.          Shell("touch /etc/route.conf");
  1760.          Shell("mv /etc/route.conf /etc/route.conf.old");
  1761.          Shell("grep -v '^[     ]*default.*ippp0' /etc/route.conf.old > /etc/route.conf.tmp");
  1762.          Shell("grep -v '^[     ]*default.*isdn0' /etc/route.conf.tmp > /etc/route.conf.tmp2");
  1763.          Shell("grep -v '# yast2 default' /etc/route.conf.tmp2 > /etc/route.conf");
  1764.          Shell("rm -f /etc/route.conf.tmp");
  1765.          Shell("rm -f /etc/route.conf.tmp2");
  1766.          Shell("echo '# yast2 default entry for "+net_dev+"' >> /etc/route.conf");  
  1767.          Shell("echo default "+IP_rem+" 0.0.0.0 "+net_dev+" >> /etc/route.conf");  
  1768.       }
  1769.    
  1770.       
  1771. //Check if there is ippp0 running and restart it if it's needed 
  1772.       if (ReadString("/var/run/ipppd.ippp0.pid") != nil) {
  1773.          Shell("/usr/sbin/rci4l stop");
  1774.          Shell("/usr/sbin/rci4l_hardware stop");
  1775.          Shell("/usr/sbin/rci4l_hardware start");
  1776.          Shell("/usr/sbin/rci4l start");
  1777.       }      
  1778.  
  1779.       if (ret != false)
  1780.          contents = 
  1781.             `HSquash(`VBox(
  1782.                `Label(_("Configuration completed")),
  1783.                `Left(`Label(_("All required information has been saved succesfully."))),
  1784.                `Left(`Label(_("You can start ISDN service manually by typing the commands"))),
  1785.                `Left(`Label(_("\"rci4l_hardware start\" and \"rci4l start\".")))));
  1786.       else {
  1787.          contents = 
  1788.             `HSquash(`VBox(
  1789. //Saving configuration failed
  1790.                `Label(_("Configuration failed due to writing error")),
  1791.                `Label(_("You must run ISDN configuration as a <B>root</B> user!")))); 
  1792.          help = UI(_("Saving failed"));
  1793.       }
  1794.       ret = UI(`ShowPage(_("Internet access configuration"),contents,help,true,false));
  1795.       if (ret == `back)
  1796.          return `ISDN_net_cfg;
  1797.       else if (ret == `cancel)
  1798.          return `cancel;
  1799.       else 
  1800.          return `next;
  1801.    };
  1802.  
  1803.  
  1804.  
  1805.    UI(``{
  1806. //Creates YaST2 screen
  1807. //Parameters:         t (string) - title of screen
  1808. //                     c (term) - contents of screen
  1809. //                     enable_back (boolean) - is BACK button enabled?
  1810. //                     regular_next (boolean) - is label of NEXT button "next"?
  1811. //Return value:      return value of UserInput() function
  1812.       define ShowPage(
  1813.          string t,
  1814.          term c,
  1815.          string help,
  1816.          boolean enable_back,
  1817.          boolean regular_next
  1818.          ) ``{
  1819.             ChangeWidget(`id(`title), `Value, t);
  1820.             ChangeWidget(`id(`help), `Value, help);
  1821.             ChangeWidget(`id(`back), `Enabled, enable_back);
  1822.             string next_label = _("&Next");
  1823.             if (!regular_next)
  1824.                next_label = _("&Finish");
  1825.             ChangeWidget(`id(`next), `Label, next_label);
  1826.             ReplaceWidget(`id(`contents), c);
  1827.             return UserInput();
  1828.          };
  1829.  
  1830.       OpenDialog(
  1831.          `opt(`defaultsize),
  1832.          `VBox(
  1833.          `Image(`suseheader, "SuSE"),
  1834.          `HBox(`HWeight(30, `RichText(`id(`help), "")),
  1835.             `HWeight(70, `VBox(
  1836.                `Left(`Label(`id(`title), _("Internet Connection Configuration")
  1837.              )),
  1838.             `HVCenter(`ReplacePoint(`id(`contents), `Empty())),
  1839.               `HBox(
  1840.                `PushButton(`id(`back), `opt(`disabled), _("&Back")),
  1841.                `HStretch(),
  1842.             `PushButton(`id(`next), _("&Next"))
  1843.          ))))));
  1844.    });
  1845.  
  1846.    symbol|void stage = nil;
  1847.    stage = `modem_detection;
  1848.    while (true) {
  1849.       if (stage == `ISP_sel)
  1850.          stage = ISP_sel();
  1851.       else if ((stage == `save_cfg) && (!isdn_det))
  1852.          stage = save_cfg_modem(false);
  1853.       else if ((stage == `save_cfg) && (isdn_det))
  1854.          stage = save_cfg_ISDN();
  1855.       else if ((stage == `ISDN_net_cfg) && (isdn_det))
  1856.          stage = ISDN_net_cfg();
  1857.       else if ((stage == `device_cfg) && (!isdn_det))
  1858.          stage = modem_cfg();
  1859.       else if ((stage == `device_cfg) && (isdn_det))
  1860.          stage = ISDN_cfg();
  1861.       else if (stage == `check_devices)
  1862.          stage = check_devices();
  1863.       else if (stage == `modem_detection)
  1864.          stage = modem_detection();
  1865.       else if (stage == `ISDN_man)
  1866.          stage = ISDN_man();
  1867.       else
  1868.          break;
  1869.    }
  1870.    UI(``{
  1871.      CloseDialog();
  1872.    });
  1873.  
  1874.    return stage;
  1875. }
  1876.