#include #include "gurus.h" #include "gurus.m" #include #include #include #include <../../libmodules/guruengine/guruengine.h> static HELP_FILE help_netbase ("gurus","netbase"); static HELP_FILE help_serial ("gurus","serial"); /* Check if the gtw address is valid and fit within the network */ static bool network_validgtw( SSTRING &ip, SSTRING &netmask, SSTRING >w) { bool ret = false; if (gtw.is_empty()){ // Gateway are optionals ret = true; }else if (ipnum_validip(gtw.get(),netmask.get(),true)){ // Ok, this is a valid IP number const char *aip = ip.get(); unsigned long ip = ipnum_aip2l (aip); const char *pt = netmask.get(); if (pt[0] == '\0') pt = ipnum_getdefaultmask (aip); unsigned long mask = ipnum_aip2l (pt); unsigned long network = ip & mask; unsigned long defgtw = ipnum_aip2l (gtw.get()); ret = (defgtw & mask) == network; } return ret; } /* Translate a 0xff to some initial value. 0xff means the field has never been set. */ static char network_notset2val(char val, char initval) { if (val == 0xff) val = initval; return val; } /* Translate a 0xff to 0. 0xff means the field has never been set. */ static char network_notset2zero(char val) { return network_notset2val (val,0); } static int network_atoi (const char *s, int defval) { int ret = defval; if (s != NULL && s[0] != '\0') ret = atoi(s); return ret; } void guru_setnetwork() { SSTRING hostname; char is_lan; // Is there lan connection char is_ppp; // Is there a PPP connection char lanconfig; // manual, bootp dhcp char firewall; // Do you want to enable the firewall on PPP SSTRING phone,serial,login,password; char pppmode; SSTRING ip,netmask,gateway,domain,dns1,dns2,dns3; glocal.is_lan = 0xff; glocal.is_ppp = 0xff; glocal.lanconfig = 0xff; glocal.firewall = 0xff; glocal.pppmode = 0xff; { // Load the current values master_registry.start_session(); glocal.hostname.setfrom (master_registry.get("netbase.hostname")); const char *val = master_registry.get("netbase.adaptor1on"); if (val != NULL && strcmp(val,"1")==0){ glocal.is_lan = 1; glocal.lanconfig = network_atoi(master_registry.get("netbase.adaptor1mode"),0xff); } glocal.ip.setfrom (master_registry.get("netbase.ipadaptor1")); glocal.netmask.setfrom (master_registry.get("netbase.maskadaptor1")); glocal.domain.setfrom (master_registry.get("resolv.defdom")); glocal.dns1.setfrom (master_registry.get("resolv.nameserver1")); glocal.dns2.setfrom (master_registry.get("resolv.nameserver2")); glocal.dns3.setfrom (master_registry.get("resolv.nameserver3")); glocal.gateway.setfrom (master_registry.get("routing.gateway")); if (file_type("/etc/ppp/internet.dconf")==0){ glocal.is_ppp = 1; glocal.phone.setfrom (master_registry.get("dialout.phone.internet")); glocal.serial.setfrom (master_registry.get("dialout.device.internet")); glocal.login.setfrom (master_registry.get("dialout.login.internet")); glocal.password.setfrom (master_registry.get("dialout.password.internet")); glocal.pppmode = network_atoi (master_registry.get("dialout.connectmode.internet"),0xff); glocal.firewall = network_atoi(master_registry.get("inetdconf.firewall"),0xff); } master_registry.end_session(); } int ret = (MSG_U(T_NETSETUP,"Network setup") ,MSG_U(I_NETSETUP ,"You will be presented with a set of dialog to fully\n" "establish network connectivity.") ,help_netbase); // hostname (mode,status); settitle (MSG_U(T_HOSTNAME,"Host name")); status.is_possible = true; status.is_filled = !glocal.hostname.is_empty(); setintro (MSG_U(I_HOSTNAME ,"You must enter a name for your machine.\n" "The name include the domain as well.\n" "(For example: machinename.domain.com)\n" "\n" "This name will be used by various linux sub-system\n" "such as the email and web server.")); dia.newf_str (MSG_U(F_HOSTNAME,"Computer name"),glocal.hostname); edit (); // Network connection type (mode,status); settitle (MSG_U(T_CONECTIVITY,"Network conectivity")); status.is_possible = true; status.is_filled = glocal.is_lan != 0xff && glocal.is_ppp != 0xff; setintro (MSG_U(I_CONECTIVITY ,"Your computer may be connected or not to\n" "network. The network is either local, using\n" "an ethernet adaptor, or remote, using a modem.\n" "\n" "A machine may be connected both ways.")); char is_lan = network_notset2zero(glocal.is_lan); char is_ppp = network_notset2zero(glocal.is_ppp); dia.newf_chk ("",is_lan,MSG_U(I_LAN,"Local network")); dia.newline(); dia.newf_chk ("",is_ppp,MSG_U(I_PPPNET,"PPP/Modem network")); if (edit ()){ glocal.is_lan = is_lan; glocal.is_ppp = is_ppp; } // LAN configuration (mode,status); settitle (MSG_U(T_LANCONFIG,"Local network configuration mode")); status.is_possible = glocal.is_lan==1; status.is_filled = glocal.lanconfig != 0xff; setintro (MSG_U(I_LANCONFIG, "You must select the way your computer gets its\n" "network parameters necessary to communicate\n" "with the workstations or your network and the Internet.\n")); char lanconfig = network_notset2val(glocal.lanconfig,1); dia.newf_radio (MSG_U(F_IPMODE,"Mode"),lanconfig,0,MSG_U(I_MANUAL,"Manual setup (You provide the parameters)")); dia.newline(); dia.newf_radio ("",lanconfig,1,MSG_U(I_DHCP,"DHCP: Dynamic host configuration protocol")); dia.newline(); dia.newf_radio ("",lanconfig,2,MSG_U(I_BOOTP,"BOOTP: Older boot protocol")); dia.newline(); if (edit ()){ glocal.lanconfig = lanconfig; } // Manual configuration (mode,status); settitle (MSG_U(T_MANUALNET,"Manual network configuration")); status.is_possible = glocal.is_lan==1 && glocal.lanconfig == 0; status.is_filled = !glocal.ip.is_empty(); status.some_errors = false; if (status.is_filled){ status.some_errors = !ipnum_validip(glocal.ip.get(),glocal.netmask.get(),true); } dia.newf_str (MSG_U(F_IPNUMBER,"IP number"),glocal.ip); dia.newline(); dia.newf_str (MSG_U(F_NETMASK,"netmask"),glocal.netmask); edit (); // Default gateway (mode,status); settitle (MSG_U(T_DEFAULTGATEWAY,"Default gateway")); status.is_possible = glocal.is_lan==1 && glocal.lanconfig == 0; status.is_filled = !glocal.gateway.is_empty(); if (status.is_filled){ status.some_errors = !network_validgtw (glocal.ip,glocal.netmask,glocal.gateway); } dia.newf_str (MSG_R(F_IPNUMBER),glocal.gateway); dia.newline(); edit (); // DNS setup (mode,status); settitle (MSG_U(T_NAMESERVER,"Name server(s)")); status.is_possible = true; status.is_filled = !glocal.dns1.is_empty(); setterminal (MSG_U(I_LANMANUAL,"Manual LAN config") ,MSG_U(I_OKLANMANUAL,"Ok, the network is manually configured")); dia.newf_str (MSG_U(F_DEFDOMAIN,"Default domain name"),glocal.domain); dia.newline(); dia.newf_str (MSG_U(F_DNS1,"First DNS (IP number)"),glocal.dns1); dia.newline(); dia.newf_str (MSG_U(F_DNS2,"Second DNS (optional)"),glocal.dns2); dia.newline(); dia.newf_str (MSG_U(F_DNS3,"Third DNS (optional)"),glocal.dns3); dia.newline(); edit (); // PPP configuration (mode,status); settitle (MSG_U(T_MODEM,"Modem selection")); status.is_possible = glocal.is_ppp == 1; // Always possible status.is_filled = !glocal.serial.is_empty(); dia.newf_str (MSG_U(F_SERIAL,"Serial device"),glocal.serial); dia.newline(); setbutinfo (1,MSG_U(B_PROBE,"Probe"),MSG_R(B_PROBE)); edit (help_serial); DEVCONF_API *tbapi[MAX_API_PROVIDERS]; int nbapi = devconf_apis_init ("gurus/network",tbapi); bool found = false; for (int i=0; iprobe (DEVCONF_MODEM,tbs)>0){ found = true; glocal.serial.setfrom (tbs.getitem(0)->get()); break; } } devconf_apis_end(tbapi,nbapi); if (!found){ xconf_error (MSG_U(E_NOMODEM,"No modem found")); } (mode,status); settitle (MSG_U(T_PPPAUTH,"PPP account information")); status.is_possible = glocal.is_ppp == 1; // Always possible status.is_filled = !glocal.phone.is_empty() && !glocal.login.is_empty() && !glocal.password.is_empty(); SSTRING password_confirmation; setintro (MSG_U(I_PPPAUTH ,"You must provide the minimal information\n" "used to identify yourself to you Internet\n" "provider")); dia.newf_str (MSG_U(F_PHONE,"Phone"),glocal.phone); dia.newline(); dia.newf_str (MSG_U(F_LOGIN,"Login ID"),glocal.login); dia.newline(); dia.newf_pass (MSG_U(F_PASSWORD,"Password"),glocal.password); dia.newline(); dia.newf_pass (MSG_U(F_CONFIRMPASSWORD,"Confirm password"),password_confirmation); bool run_this_dialog = true; while (run_this_dialog){ run_this_dialog = false; if (edit ()){ if (strcmp (glocal.password.get(),password_confirmation.get())){ xconf_error (MSG_U(E_PASSWDSDIFFER,"The password strings differ between!")); run_this_dialog = true; } } } (mode,status); settitle (MSG_U(T_PPPMODE,"PPP authentication mode")); status.is_possible = glocal.is_ppp == 1; // Always possible status.is_filled = glocal.pppmode != 0xff; setintro (MSG_U(I_PPPMODE ,"Some internet providers support different\n" "authentication protocols. Most support PAP\n" "and few support CHAP.")); char pppmode = network_notset2val(glocal.pppmode,1); dia.newf_radio (MSG_U(F_AUTHPROT,"Authentication protocol") ,pppmode,1 ,MSG_U(I_USEPAP,"Use PAP")); dia.newline(); dia.newf_radio ("",pppmode,0 ,MSG_U(I_USELOGIN,"Use a chat script")); dia.newline(); dia.newf_radio ("",pppmode,2 ,MSG_U(I_USECHAP,"Use CHAP")); dia.newline(); if (edit()){ glocal.pppmode = pppmode; } // Firewall (mode,status); settitle (MSG_U(T_FIREWALL,"Firewall setting")); status.is_possible = glocal.is_ppp == 1; status.is_filled = glocal.firewall != 0xff; setterminal (MSG_U(I_PPPCONFIG,"Modem PPP configuration"),""); char firewall = glocal.firewall; if (firewall == 0xff) firewall = 0; dia.newf_chk ("",firewall,MSG_U(I_FIREWALL,"Enable firewall")); if (edit ()){ glocal.firewall = firewall; } if (ret != -1){ // Update the system master_registry.start_session(); master_registry.set("netbase.hostname",glocal.hostname); if (glocal.is_lan){ master_registry.set("netbase.adaptor1on",1); master_registry.set("netbase.adaptor1mode",glocal.lanconfig); if (glocal.lanconfig == 0){ master_registry.set("netbase.ipadaptor1",glocal.ip); master_registry.set("netbase.maskadaptor1",glocal.netmask); master_registry.set("resolv.defdom",glocal.domain); master_registry.set("resolv.nameserver1",glocal.dns1); master_registry.set("resolv.nameserver2",glocal.dns2); master_registry.set("resolv.nameserver3",glocal.dns3); master_registry.set("routing.gateway",glocal.gateway); } if (glocal.is_ppp && !glocal.phone.is_empty()){ master_registry.set("dialout.phone.internet",glocal.phone); master_registry.set("dialout.device.internet",glocal.serial); master_registry.set("dialout.login.internet",glocal.login); master_registry.set("dialout.password.internet",glocal.password); master_registry.set("dialout.connectmode.internet",glocal.pppmode); master_registry.set("inetdconf.firewall",glocal.firewall); } } master_registry.end_session(); xconf_notice (MSG_U(I_WASUPDATED,"The configurations were updated")); } }