-/* SmoothWall libsmooth.\r
- *\r
- * This program is distributed under the terms of the GNU General Public\r
- * Licence. See the file COPYING for details.\r
- *\r
- * (c) Lawrence Manning, 2001\r
- * Contains network library functions.\r
- * \r
- * $Id: netstuff.c,v 1.19.2.7 2004/11/05 23:40:17 alanh Exp $\r
- * \r
- */\r
-\r
-#include "libsmooth.h"\r
-#include <signal.h>\r
-\r
-extern FILE *flog;\r
-extern char *mylog;\r
-\r
-extern char **ctr;\r
-\r
-newtComponent networkform;\r
-newtComponent addressentry;\r
-newtComponent netmaskentry;\r
-newtComponent statictyperadio;\r
-newtComponent dhcptyperadio;\r
-newtComponent pppoetyperadio;\r
-newtComponent pptptyperadio;\r
-newtComponent dhcphostnameentry;\r
-\r
-/* acceptable character filter for IP and netmaks entry boxes */\r
-static int ip_input_filter(newtComponent entry, void * data, int ch, int cursor)\r
-{\r
- if ((ch >= '0' && ch <= '9') || ch == '.' || ch == '\r' || ch >= NEWT_KEY_EXTRA_BASE)\r
- return ch;\r
- return 0;\r
-}\r
-\r
-/* This is a groovie dialog for showing network info. Takes a keyvalue list,\r
- * a colour and a dhcp flag. Shows the current settings, and rewrites them\r
- * if necessary. DHCP flag sets wether to show the dhcp checkbox. */\r
-int changeaddress(struct keyvalue *kv, char *colour, int typeflag,\r
- char *defaultdhcphostname)\r
-{\r
- char *addressresult;\r
- char *netmaskresult;\r
- char *dhcphostnameresult;\r
- struct newtExitStruct es;\r
- newtComponent header;\r
- newtComponent addresslabel;\r
- newtComponent netmasklabel;\r
- newtComponent dhcphostnamelabel;\r
- newtComponent ok, cancel; \r
- char message[1000];\r
- char temp[STRING_SIZE];\r
- char addressfield[STRING_SIZE];\r
- char netmaskfield[STRING_SIZE];\r
- char typefield[STRING_SIZE];\r
- char dhcphostnamefield[STRING_SIZE];\r
- int error;\r
- int result = 0;\r
- char type[STRING_SIZE];\r
- int startstatictype = 0;\r
- int startdhcptype = 0;\r
- int startpppoetype = 0;\r
- int startpptptype = 0;\r
- \r
- /* Build some key strings. */\r
- sprintf(addressfield, "%s_ADDRESS", colour);\r
- sprintf(netmaskfield, "%s_NETMASK", colour);\r
- sprintf(typefield, "%s_TYPE", colour);\r
- sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour);\r
- \r
- sprintf(message, ctr[TR_INTERFACE], colour);\r
- newtCenteredWindow(44, (typeflag ? 18 : 12), message);\r
- \r
- networkform = newtForm(NULL, NULL, 0);\r
-\r
- sprintf(message, ctr[TR_ENTER_THE_IP_ADDRESS_INFORMATION], colour);\r
- header = newtTextboxReflowed(1, 1, message, 42, 0, 0, 0);\r
- newtFormAddComponent(networkform, header);\r
-\r
- /* See if we need a dhcp checkbox. If we do, then we shift the contents\r
- * of the window down two rows to make room. */\r
- if (typeflag)\r
- {\r
- strcpy(temp, "STATIC"); findkey(kv, typefield, temp);\r
- if (strcmp(temp, "STATIC") == 0) startstatictype = 1;\r
- if (strcmp(temp, "DHCP") == 0) startdhcptype = 1;\r
- if (strcmp(temp, "PPPOE") == 0) startpppoetype = 1;\r
- if (strcmp(temp, "PPTP") == 0) startpptptype = 1;\r
- statictyperadio = newtRadiobutton(2, 4, ctr[TR_STATIC], startstatictype, NULL);\r
- dhcptyperadio = newtRadiobutton(2, 5, "DHCP", startdhcptype, statictyperadio);\r
- pppoetyperadio = newtRadiobutton(2, 6, "PPPOE", startpppoetype, dhcptyperadio);\r
- pptptyperadio = newtRadiobutton(2, 7, "PPTP", startpptptype, pppoetyperadio);\r
- newtFormAddComponents(networkform, statictyperadio, dhcptyperadio, \r
- pppoetyperadio, pptptyperadio, NULL);\r
- newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL);\r
- newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL);\r
- newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL);\r
- newtComponentAddCallback(pptptyperadio, networkdialogcallbacktype, NULL);\r
- dhcphostnamelabel = newtTextbox(2, 9, 18, 1, 0);\r
- newtTextboxSetText(dhcphostnamelabel, ctr[TR_DHCP_HOSTNAME]);\r
- strcpy(temp, defaultdhcphostname);\r
- findkey(kv, dhcphostnamefield, temp);\r
- dhcphostnameentry = newtEntry(20, 9, temp, 20, &dhcphostnameresult, 0);\r
- newtFormAddComponent(networkform, dhcphostnamelabel); \r
- newtFormAddComponent(networkform, dhcphostnameentry); \r
- if (startdhcptype == 0)\r
- newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);\r
- }\r
- /* Address */\r
- addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0);\r
- newtTextboxSetText(addresslabel, ctr[TR_IP_ADDRESS_PROMPT]);\r
- strcpy(temp, "");\r
- findkey(kv, addressfield, temp);\r
- addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0);\r
- newtEntrySetFilter(addressentry, ip_input_filter, NULL);\r
- if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 )\r
- newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);\r
- newtFormAddComponent(networkform, addresslabel);\r
- newtFormAddComponent(networkform, addressentry);\r
- \r
- /* Netmask */\r
- netmasklabel = newtTextbox(2, (typeflag ? 11 : 4) + 1, 18, 1, 0);\r
- newtTextboxSetText(netmasklabel, ctr[TR_NETMASK_PROMPT]);\r
- strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp);\r
- netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0);\r
- newtEntrySetFilter(netmaskentry, ip_input_filter, NULL);\r
- if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 ) \r
- newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);\r
-\r
- newtFormAddComponent(networkform, netmasklabel);\r
- newtFormAddComponent(networkform, netmaskentry);\r
-\r
- /* Buttons. */\r
- ok = newtButton(8, (typeflag ? 14 : 7), ctr[TR_OK]);\r
- cancel = newtButton(26, (typeflag ? 14 : 7), ctr[TR_CANCEL]);\r
-\r
- newtFormAddComponents(networkform, ok, cancel, NULL);\r
-\r
- newtRefresh();\r
- newtDrawForm(networkform);\r
-\r
- do\r
- {\r
- error = 0;\r
- newtFormRun(networkform, &es);\r
- \r
- if (es.u.co == ok)\r
- {\r
- /* OK was pressed; verify the contents of each entry. */\r
- strcpy(message, ctr[TR_INVALID_FIELDS]);\r
- \r
- strcpy(type, "STATIC");\r
- if (typeflag)\r
- gettype(type);\r
- if (strcmp(type, "STATIC") == 0 || strcmp(type, "PPTP") == 0 )\r
- { \r
- if (inet_addr(addressresult) == INADDR_NONE)\r
- {\r
- strcat(message, ctr[TR_IP_ADDRESS_CR]);\r
- error = 1;\r
- }\r
- if (inet_addr(netmaskresult) == INADDR_NONE)\r
- {\r
- strcat(message, ctr[TR_NETWORK_MASK_CR]);\r
- error = 1;\r
- }\r
- }\r
- if (strcmp(type, "DHCP") == 0)\r
- {\r
- if (!strlen(dhcphostnameresult))\r
- {\r
- strcat(message, ctr[TR_DHCP_HOSTNAME_CR]);\r
- error = 1;\r
- }\r
- }\r
- if (error)\r
- errorbox(message);\r
- else\r
- {\r
- /* No errors! Set new values, depending on dhcp flag etc. */\r
- if (typeflag)\r
- {\r
- replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult);\r
- if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0)\r
- {\r
- replacekeyvalue(kv, addressfield, "0.0.0.0");\r
- replacekeyvalue(kv, netmaskfield, "0.0.0.0");\r
- }\r
- else\r
- {\r
- replacekeyvalue(kv, addressfield, addressresult);\r
- replacekeyvalue(kv, netmaskfield, netmaskresult);\r
- }\r
- replacekeyvalue(kv, typefield, type); \r
- }\r
- else\r
- {\r
- replacekeyvalue(kv, addressfield, addressresult);\r
- replacekeyvalue(kv, netmaskfield, netmaskresult);\r
- }\r
- \r
- setnetaddress(kv, colour);\r
- result = 1;\r
- }\r
- } \r
- }\r
- while (error);\r
-\r
- newtFormDestroy(networkform);\r
- newtPopWindow();\r
- \r
- return result;\r
-}\r
-\r
-/* for pppoe: return string thats type STATIC, DHCP or PPPOE */\r
-int gettype(char *type)\r
-{\r
- newtComponent selected = newtRadioGetCurrent(statictyperadio);\r
- \r
- if (selected == statictyperadio)\r
- strcpy(type, "STATIC");\r
- else if (selected == dhcptyperadio)\r
- strcpy(type, "DHCP");\r
- else if (selected == pppoetyperadio)\r
- strcpy(type, "PPPOE");\r
- else if (selected == pptptyperadio)\r
- strcpy(type, "PPTP");\r
- else\r
- strcpy(type, "ERROR");\r
- \r
- return 0;\r
-}\r
-\r
-/* 0.9.9: calculates broadcast too. */\r
-int setnetaddress(struct keyvalue *kv, char *colour)\r
-{\r
- char addressfield[STRING_SIZE];\r
- char netaddressfield[STRING_SIZE]; \r
- char netmaskfield[STRING_SIZE];\r
- char broadcastfield[STRING_SIZE];\r
- char address[STRING_SIZE];\r
- char netmask[STRING_SIZE];\r
- unsigned long int intaddress;\r
- unsigned long int intnetaddress;\r
- unsigned long int intnetmask;\r
- unsigned long int intbroadcast;\r
- struct in_addr temp;\r
- char *netaddress;\r
- char *broadcast;\r
- \r
- /* Build some key strings. */\r
- sprintf(addressfield, "%s_ADDRESS", colour);\r
- sprintf(netaddressfield, "%s_NETADDRESS", colour);\r
- sprintf(netmaskfield, "%s_NETMASK", colour);\r
- sprintf(broadcastfield, "%s_BROADCAST", colour);\r
-\r
- strcpy(address, ""); findkey(kv, addressfield, address); \r
- strcpy(netmask, ""); findkey(kv, netmaskfield, netmask); \r
-\r
- /* Calculate netaddress. Messy.. */\r
- intaddress = inet_addr(address);\r
- intnetmask = inet_addr(netmask);\r
- \r
- intnetaddress = intaddress & intnetmask;\r
- temp.s_addr = intnetaddress; \r
- netaddress = inet_ntoa(temp);\r
- \r
- replacekeyvalue(kv, netaddressfield, netaddress);\r
- \r
- intbroadcast = intnetaddress | ~intnetmask;\r
- temp.s_addr = intbroadcast;\r
- broadcast = inet_ntoa(temp); \r
- \r
- replacekeyvalue(kv, broadcastfield, broadcast);\r
- \r
- return 1;\r
-} \r
-\r
-/* Called when dhcp flag is toggled. Toggle disabled state of other 3\r
- * controls. */\r
-void networkdialogcallbacktype(newtComponent cm, void *data)\r
-{\r
- char type[STRING_SIZE];\r
- \r
- gettype(type);\r
-\r
- if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0 )\r
- {\r
- newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);\r
- newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);\r
- }\r
- else\r
- {\r
- newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);\r
- newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);\r
- }\r
- if (strcmp(type, "DHCP") == 0)\r
- newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);\r
- else\r
- newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); \r
- \r
- newtRefresh();\r
- newtDrawForm(networkform); \r
-}\r
-\r
-int interfacecheck(struct keyvalue *kv, char *colour)\r
-{\r
- char temp[STRING_SIZE];\r
- char colourfields[NETCHANGE_TOTAL][STRING_SIZE];\r
- int c;\r
-\r
- sprintf(colourfields[ADDRESS], "%s_ADDRESS", colour);\r
- sprintf(colourfields[NETADDRESS], "%s_NETADDRESS", colour);\r
- sprintf(colourfields[NETMASK], "%s_NETMASK", colour);\r
-\r
- for (c = 0; c < 3; c++)\r
- {\r
- strcpy(temp, ""); findkey(kv, colourfields[c], temp);\r
- if (!(strlen(temp))) return 0;\r
- }\r
- return 1;\r
-}\r
- \r
-/* Network probing! */\r
-struct nic nics[] = {\r
- { "100VG-AnyLan Network Adapters, HP J2585B, J2585A, etc", "hp100" },\r
- { "3Com EtherLink III", "3c509" },\r
- { "3Com 3c501", "3c501" },\r
- { "3Com ISA EtherLink XL", "3c515" },\r
- { "3Com 3c503 and 3c503/16", "3c503" },\r
- { "3Com EtherLink MC (3c523)", "3c523" },\r
- { "3Com EtherLink MC/32 (3c527)", "3c527" },\r
- { "3Com EtherLink Plus (3c505)", "3c505" },\r
- { "3Com EtherLink 16", "3c507" },\r
- { "3Com \"Corkscrew\" EtherLink PCI III/XL, etc.", "3c59x" },\r
- { "3Com Typhoon Family (3C990, 3CR990, and variants)", "typhoon" },\r
- { "Adaptec Starfire/DuraLAN", "starfire" },\r
- { "Alteon AceNIC/3Com 3C985/Netgear GA620 Gigabit", "acenic" },\r
- { "AMD8111 based 10/100 Ethernet Controller", "amd8111e" },\r
- { "AMD LANCE/PCnetAllied Telesis AT1500, J2405A, etc", "lance" },\r
- { "AMD PCnet32 and AMD PCnetPCI", "pcnet32" },\r
- { "Ansel Communications EISA 3200", "ac3200" },\r
- { "Apricot 680x0 VME, 82596 chipset", "82596" },\r
- { "AT1700/1720", "at1700" },\r
- { "Broadcom 4400", "b44" },\r
- { "Broadcom Tigon3", "tg3" },\r
- { "Cabletron E2100 series ethercards", "e2100" },\r
- { "CATC USB NetMate-based Ethernet", "catc" },\r
- { "CDC USB Ethernet", "CDCEther" },\r
- { "Crystal LAN CS8900/CS8920", "cs89x0" },\r
- { "Compaq Netelligent 10/100 TX PCI UTP, etc", "tlan" },\r
- { "D-Link DL2000-based Gigabit Ethernet", "dl2k" },\r
- { "Digi Intl. RightSwitch SE-X EISA and PCI", "dgrs" },\r
- { "Digital 21x4x Tulip PCI ethernet cards, etc.", "tulip" },\r
- { "Digital DEPCA & EtherWORKS,DEPCA, DE100, etc", "depca" },\r
- { "DM9102 PCI Fast Ethernet Adapter", "dmfe", },\r
- { "Dummy Network Card (testing)", "dummy", },\r
- { "EtherWORKS DE425 TP/COAX EISA, DE434 TP PCI, etc.", "de4x5" },\r
- { "EtherWORKS 3 (DE203, DE204 and DE205)", "ewrk3" },\r
- { "HP PCLAN/plus", "hp-plus" },\r
- { "HP LAN ethernet", "hp" },\r
- { "IBM LANA", "ibmlana" },\r
- { "ICL EtherTeam 16i/32" ,"eth16i" },\r
- { "Intel i82557/i82558 PCI EtherExpressPro", "e100" },\r
- { "Intel EtherExpress Cardbus Ethernet", "eepro100_cb" },\r
- { "Intel i82595 ISA EtherExpressPro10/10+ driver" ,"eepro" },\r
- { "Intel EtherExpress 16 (i82586)", "eexpress" },\r
- { "Intel Panther onboard i82596 driver", "lp486e" },\r
- { "Intel PRO/1000 Gigabit Ethernet", "e1000" },\r
- { "KLSI USB KL5USB101-based", "kaweth" },\r
- { "MiCom-Interlan NI5010 ethercard", "ni5010" },\r
- { "Mylex EISA LNE390A/B", "lne390", },\r
- { "Myson MTD-8xx PCI Ethernet", "fealnx" },\r
- { "National Semiconductor DP8381x" , "natsemi" },\r
- { "National Semiconductor DP83820" , "ns83820" },\r
- { "NE/2 MCA", "ne2" },\r
- { "NE2000 PCI cards, RealTEk RTL-8029, etc", "ne2k-pci" },\r
- { "NE1000 / NE2000 (non-pci)", "ne" },\r
- { "NI50 card (i82586 Ethernet chip)", "ni52" },\r
- { "NI6510, ni6510 EtherBlaster", "ni65" },\r
- { "Novell/Eagle/Microdyne NE3210 EISA", "ne3210" },\r
- { "NVidia Nforce2 Driver", "forcedeth" },\r
- { "Packet Engines Hamachi GNIC-II", "hamachi" },\r
- { "Packet Engines Yellowfin Gigabit-NIC", "yellowfin" },\r
- { "Pegasus/Pegasus-II USB ethernet", "pegasus" },\r
- { "PureData PDUC8028,WD8003 and WD8013 compatibles", "wd" },\r
- { "Racal-Interlan EISA ES3210", "es3210" },\r
- { "RealTek RTL-8139 Fast Ethernet", "8139too" },\r
- { "RealTek RTL-8139C+ series 10/100 PCI Ethernet", "8139cp" },\r
- { "RealTek RTL-8150 USB ethernet", "rtl8150" },\r
- { "RealTek RTL-8169 Gigabit Ethernet", "r8169" },\r
- { "SiS 900 PCI", "sis900" },\r
- { "SKnet MCA", "sk_mca" },\r
- { "SMC 9000 series of ethernet cards", "smc9194" },\r
- { "SMC EtherPower II", "epic100" },\r
- { "SMC Ultra/EtherEZ ISA/PnP Ethernet", "smc-ultra" },\r
- { "SMC Ultra32 EISA Ethernet", "smc-ultra32" },\r
- { "SMC Ultra MCA Ethernet", "smc-mca" },\r
- { "Sundance Alta", "sundance" },\r
- { "SysKonnect SK-98xx", "sk98lin" },\r
- { "Toshiba TC35815 Ethernet", "tc35815" },\r
- { "Tulip chipset Cardbus Ethernet", "tulip_cb" },\r
- { "USB Ethernet", "usbnet" },\r
- { "VIA Rhine PCI Fast Ethernet, etc", "via-rhine" },\r
- { "Winbond W89c840 Ethernet", "winbond-840" },\r
- { "Xircom Cardbus Ethernet", "xircom_cb" },\r
- { "Xircom (tulip-like) Cardbus Ethernet", "xircom_tulip_cb" },\r
- { NULL, NULL }\r
-};\r
-\r
-/* Funky routine for loading all drivers (cept those are already loaded.). */\r
-int probecards(char *driver, char *driveroptions)\r
-{\r
- int c = 0;\r
- int n = 0;\r
- char message[1000];\r
- char commandstring[STRING_SIZE];\r
-\r
- n = countcards();\r
-\r
- /* PCMCIA Detection */\r
- runcommandwithstatus("cardmgr -o", \r
- ctr[TR_LOADING_PCMCIA]);\r
-\r
- if (countcards() > n) \r
- {\r
- strcpy(driver, "pcmcia");\r
- strcpy(driveroptions,"");\r
- return 1;\r
- }\r
-\r
- /* Regular module detection */\r
- while (nics[c].modulename)\r
- {\r
- /* Skip dummy driver during autoprobe as it always succeeds */\r
- if (strncmp(nics[c].modulename, "dummy", strlen("dummy")))\r
- {\r
- if (!checkformodule(nics[c].modulename)) {\r
- sprintf(commandstring, "/sbin/modprobe %s", nics[c].modulename);\r
- sprintf(message, ctr[TR_LOOKING_FOR_NIC], nics[c].description);\r
- if (runcommandwithstatus(commandstring, message) == 0)\r
- {\r
- if (countcards() > n) {\r
- strcpy(driver, nics[c].modulename);\r
- strcpy(driveroptions, "");\r
- return 1;\r
- }\r
- }\r
- }\r
- }\r
- c++;\r
- }\r
- strcpy(driver, "");\r
- strcpy(driveroptions, "");\r
- \r
- return 0;\r
-}\r
-\r
-/* A listbox for selected the card... with a * MANUAL * entry at top for\r
- * manual module names. */\r
-int choosecards(char *driver, char *driveroptions)\r
-{\r
- int c;\r
- char **sections;\r
- int drivercount;\r
- int rc;\r
- int choice;\r
- char commandstring[STRING_SIZE];\r
- char message[STRING_SIZE];\r
- int done = 0;\r
- \r
- /* Count 'em */\r
- c = 0; drivercount = 0;\r
- while (nics[c].modulename)\r
- {\r
- drivercount++;\r
- c++;\r
- }\r
- drivercount++;\r
- sections = malloc((drivercount + 1) * sizeof(char *));\r
- \r
- /* Copy 'em. */\r
- c = 0;\r
- sections[c] = ctr[TR_MANUAL];\r
- c++;\r
- while (nics[c - 1].modulename)\r
- {\r
- sections[c] = nics[c - 1].description;\r
- c++;\r
- }\r
- sections[c] = NULL;\r
- \r
- strcpy(driver, "");\r
- strcpy(driveroptions, "");\r
- \r
- done = 0; choice = 1;\r
- while (!done)\r
- {\r
- rc = newtWinMenu(ctr[TR_SELECT_NETWORK_DRIVER],\r
- ctr[TR_SELECT_NETWORK_DRIVER_LONG], 50, 5, 5, 6,\r
- sections, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);\r
- if (rc == 0 || rc == 1)\r
- {\r
- if (choice > 0)\r
- {\r
- /* Find module number, load module. */\r
- c = choice - 1; \r
- \r
- if (!checkformodule(nics[c].modulename))\r
- {\r
- sprintf(commandstring, "/sbin/modprobe %s", nics[c].modulename);\r
- sprintf(message, ctr[TR_LOOKING_FOR_NIC], nics[c].description);\r
- if (runcommandwithstatus(commandstring, message) == 0)\r
- {\r
- strcpy(driver, nics[c].modulename);\r
- strcpy(driveroptions, "");\r
- done = 1;\r
- }\r
- else\r
- errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]);\r
- }\r
- else\r
- errorbox(ctr[TR_THIS_DRIVER_MODULE_IS_ALREADY_LOADED]);\r
- }\r
- else\r
- {\r
- manualdriver(driver, driveroptions);\r
- if (strlen(driver))\r
- done = 1;\r
- }\r
- }\r
- else\r
- done = 1; \r
- }\r
-\r
- return 1;\r
-}\r
-\r
-/* Manual entry for gurus. */\r
-int manualdriver(char *driver, char *driveroptions)\r
-{\r
- char *values[] = { NULL, NULL }; /* pointers for the values. */\r
- struct newtWinEntry entries[] =\r
- { { "", &values[0], 0,}, { NULL, NULL, 0 } };\r
- int rc;\r
- char commandstring[STRING_SIZE];\r
- char *driverend;\r
-\r
- strcpy(driver, "");\r
- strcpy(driveroptions, "");\r
- \r
- rc = newtWinEntries(ctr[TR_SELECT_NETWORK_DRIVER], \r
- ctr[TR_MODULE_PARAMETERS], 50, 5, 5, 40, entries, \r
- ctr[TR_OK], ctr[TR_CANCEL], NULL); \r
- if (rc == 0 || rc == 1)\r
- {\r
- if (strlen(values[0]))\r
- {\r
- sprintf(commandstring, "/sbin/modprobe %s", values[0]);\r
- if (runcommandwithstatus(commandstring, ctr[TR_LOADING_MODULE]) == 0)\r
- {\r
- if ((driverend = strchr(values[0], ' ')))\r
- {\r
- *driverend = '\0';\r
- strcpy(driver, values[0]);\r
- strcpy(driveroptions, driverend + 1);\r
- } \r
- else\r
- {\r
- strcpy(driver, values[0]);\r
- strcpy(driveroptions, "");\r
- }\r
- }\r
- else\r
- errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]);\r
- }\r
- else\r
- errorbox(ctr[TR_MODULE_NAME_CANNOT_BE_BLANK]);\r
- }\r
- free(values[0]);\r
-\r
- return 1;\r
-}\r
-\r
-/* Returns the total number of nics current available as ethX devices. */\r
-int countcards(void)\r
-{\r
- FILE *file;\r
- char buffer[STRING_SIZE];\r
- char *start;\r
- int niccount = 0;\r
- \r
- if (!(file = fopen("/proc/net/dev", "r")))\r
- {\r
- fprintf(flog, "Unable to open /proc/net/dev in countnics()\n");\r
- return 0;\r
- }\r
- \r
- while (fgets(buffer, STRING_SIZE, file))\r
- {\r
- start = buffer;\r
- while (*start == ' ') start++;\r
- if (strncmp(start, "eth", strlen("eth")) == 0)\r
- niccount++;\r
- if (strncmp(start, "dummy", strlen("dummy")) == 0)\r
- niccount++;\r
- }\r
- \r
- fclose(file);\r
- \r
- return niccount;\r
-}\r
-\r
-/* Finds the listed module name and copies the card description back. */\r
-int findnicdescription(char *modulename, char *description)\r
-{\r
- int c = 0;\r
- \r
- if (strcmp(modulename, "pcmcia") == 0) {\r
- strcpy(description, "PCMCIA Ethernet card");\r
- return 0;\r
- }\r
-\r
- while (nics[c].description)\r
- {\r
- if (strcmp(nics[c].modulename, modulename) == 0)\r
- {\r
- strcpy(description, nics[c].description);\r
- return 1;\r
- }\r
- c++;\r
- }\r
- \r
- strcpy(description, "UNKNOWN");\r
- return 0;\r
-}\r
+/* SmoothWall libsmooth.
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence. See the file COPYING for details.
+ *
+ * (c) Lawrence Manning, 2001
+ * Contains network library functions.
+ *
+ */
+
+#include "libsmooth.h"
+#include <signal.h>
+
+extern FILE *flog;
+extern char *mylog;
+
+extern char **ctr;
+
+extern struct nic nics[];
+extern struct knic knics[];
+
+int scanned_nics_read_done = 0;
+
+newtComponent networkform;
+newtComponent addressentry;
+newtComponent netmaskentry;
+newtComponent statictyperadio;
+newtComponent dhcptyperadio;
+newtComponent pppoetyperadio;
+newtComponent pptptyperadio;
+newtComponent dhcphostnameentry;
+
+/* acceptable character filter for IP and netmaks entry boxes */
+static int ip_input_filter(newtComponent entry, void * data, int ch, int cursor)
+{
+ if ((ch >= '0' && ch <= '9') || ch == '.' || ch == '\r' || ch >= NEWT_KEY_EXTRA_BASE)
+ return ch;
+ return 0;
+}
+
+/* This is a groovie dialog for showing network info. Takes a keyvalue list,
+ * a colour and a dhcp flag. Shows the current settings, and rewrites them
+ * if necessary. DHCP flag sets wether to show the dhcp checkbox. */
+int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
+ char *defaultdhcphostname)
+{
+ char *addressresult;
+ char *netmaskresult;
+ char *dhcphostnameresult;
+ struct newtExitStruct es;
+ newtComponent header;
+ newtComponent addresslabel;
+ newtComponent netmasklabel;
+ newtComponent dhcphostnamelabel;
+ newtComponent ok, cancel;
+ char message[1000];
+ char temp[STRING_SIZE];
+ char addressfield[STRING_SIZE];
+ char netmaskfield[STRING_SIZE];
+ char typefield[STRING_SIZE];
+ char dhcphostnamefield[STRING_SIZE];
+ int error;
+ int result = 0;
+ char type[STRING_SIZE];
+ int startstatictype = 0;
+ int startdhcptype = 0;
+ int startpppoetype = 0;
+ int startpptptype = 0;
+
+ /* Build some key strings. */
+ sprintf(addressfield, "%s_ADDRESS", colour);
+ sprintf(netmaskfield, "%s_NETMASK", colour);
+ sprintf(typefield, "%s_TYPE", colour);
+ sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour);
+
+ sprintf(message, ctr[TR_INTERFACE], colour);
+ newtCenteredWindow(44, (typeflag ? 18 : 12), message);
+
+ networkform = newtForm(NULL, NULL, 0);
+
+ sprintf(message, ctr[TR_ENTER_THE_IP_ADDRESS_INFORMATION], colour);
+ header = newtTextboxReflowed(1, 1, message, 42, 0, 0, 0);
+ newtFormAddComponent(networkform, header);
+
+ /* See if we need a dhcp checkbox. If we do, then we shift the contents
+ * of the window down two rows to make room. */
+ if (typeflag)
+ {
+ strcpy(temp, "STATIC"); findkey(kv, typefield, temp);
+ if (strcmp(temp, "STATIC") == 0) startstatictype = 1;
+ if (strcmp(temp, "DHCP") == 0) startdhcptype = 1;
+ if (strcmp(temp, "PPPOE") == 0) startpppoetype = 1;
+ if (strcmp(temp, "PPTP") == 0) startpptptype = 1;
+ statictyperadio = newtRadiobutton(2, 4, ctr[TR_STATIC], startstatictype, NULL);
+ dhcptyperadio = newtRadiobutton(2, 5, "DHCP", startdhcptype, statictyperadio);
+ pppoetyperadio = newtRadiobutton(2, 6, "PPPOE", startpppoetype, dhcptyperadio);
+ pptptyperadio = newtRadiobutton(2, 7, "PPTP", startpptptype, pppoetyperadio);
+ newtFormAddComponents(networkform, statictyperadio, dhcptyperadio,
+ pppoetyperadio, pptptyperadio, NULL);
+ newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL);
+ newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL);
+ newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL);
+ newtComponentAddCallback(pptptyperadio, networkdialogcallbacktype, NULL);
+ dhcphostnamelabel = newtTextbox(2, 9, 18, 1, 0);
+ newtTextboxSetText(dhcphostnamelabel, ctr[TR_DHCP_HOSTNAME]);
+ strcpy(temp, defaultdhcphostname);
+ findkey(kv, dhcphostnamefield, temp);
+ dhcphostnameentry = newtEntry(20, 9, temp, 20, &dhcphostnameresult, 0);
+ newtFormAddComponent(networkform, dhcphostnamelabel);
+ newtFormAddComponent(networkform, dhcphostnameentry);
+ if (startdhcptype == 0)
+ newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
+ }
+ /* Address */
+ addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0);
+ newtTextboxSetText(addresslabel, ctr[TR_IP_ADDRESS_PROMPT]);
+ strcpy(temp, "");
+ findkey(kv, addressfield, temp);
+ addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0);
+ newtEntrySetFilter(addressentry, ip_input_filter, NULL);
+ if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 )
+ newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
+ newtFormAddComponent(networkform, addresslabel);
+ newtFormAddComponent(networkform, addressentry);
+
+ /* Netmask */
+ netmasklabel = newtTextbox(2, (typeflag ? 11 : 4) + 1, 18, 1, 0);
+ newtTextboxSetText(netmasklabel, ctr[TR_NETMASK_PROMPT]);
+ strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp);
+ netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0);
+ newtEntrySetFilter(netmaskentry, ip_input_filter, NULL);
+ if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 )
+ newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
+
+ newtFormAddComponent(networkform, netmasklabel);
+ newtFormAddComponent(networkform, netmaskentry);
+
+ /* Buttons. */
+ ok = newtButton(8, (typeflag ? 14 : 7), ctr[TR_OK]);
+ cancel = newtButton(26, (typeflag ? 14 : 7), ctr[TR_CANCEL]);
+
+ newtFormAddComponents(networkform, ok, cancel, NULL);
+
+ newtRefresh();
+ newtDrawForm(networkform);
+
+ do
+ {
+ error = 0;
+ newtFormRun(networkform, &es);
+
+ if (es.u.co == ok)
+ {
+ /* OK was pressed; verify the contents of each entry. */
+ strcpy(message, ctr[TR_INVALID_FIELDS]);
+
+ strcpy(type, "STATIC");
+ if (typeflag)
+ gettype(type);
+ if (strcmp(type, "STATIC") == 0 || strcmp(type, "PPTP") == 0 )
+ {
+ if (inet_addr(addressresult) == INADDR_NONE)
+ {
+ strcat(message, ctr[TR_IP_ADDRESS_CR]);
+ error = 1;
+ }
+ if (inet_addr(netmaskresult) == INADDR_NONE)
+ {
+ strcat(message, ctr[TR_NETWORK_MASK_CR]);
+ error = 1;
+ }
+ }
+ if (strcmp(type, "DHCP") == 0)
+ {
+ if (!strlen(dhcphostnameresult))
+ {
+ strcat(message, ctr[TR_DHCP_HOSTNAME_CR]);
+ error = 1;
+ }
+ }
+ if (error)
+ errorbox(message);
+ else
+ {
+ /* No errors! Set new values, depending on dhcp flag etc. */
+ if (typeflag)
+ {
+ replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult);
+ if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0)
+ {
+ replacekeyvalue(kv, addressfield, "0.0.0.0");
+ replacekeyvalue(kv, netmaskfield, "0.0.0.0");
+ }
+ else
+ {
+ replacekeyvalue(kv, addressfield, addressresult);
+ replacekeyvalue(kv, netmaskfield, netmaskresult);
+ }
+ replacekeyvalue(kv, typefield, type);
+ }
+ else
+ {
+ replacekeyvalue(kv, addressfield, addressresult);
+ replacekeyvalue(kv, netmaskfield, netmaskresult);
+ }
+
+ setnetaddress(kv, colour);
+ result = 1;
+ }
+ }
+ }
+ while (error);
+
+ newtFormDestroy(networkform);
+ newtPopWindow();
+
+ return result;
+}
+
+/* for pppoe: return string thats type STATIC, DHCP or PPPOE */
+int gettype(char *type)
+{
+ newtComponent selected = newtRadioGetCurrent(statictyperadio);
+
+ if (selected == statictyperadio)
+ strcpy(type, "STATIC");
+ else if (selected == dhcptyperadio)
+ strcpy(type, "DHCP");
+ else if (selected == pppoetyperadio)
+ strcpy(type, "PPPOE");
+ else if (selected == pptptyperadio)
+ strcpy(type, "PPTP");
+ else
+ strcpy(type, "ERROR");
+
+ return 0;
+}
+
+/* 0.9.9: calculates broadcast too. */
+int setnetaddress(struct keyvalue *kv, char *colour)
+{
+ char addressfield[STRING_SIZE];
+ char netaddressfield[STRING_SIZE];
+ char netmaskfield[STRING_SIZE];
+ char broadcastfield[STRING_SIZE];
+ char address[STRING_SIZE];
+ char netmask[STRING_SIZE];
+ unsigned long int intaddress;
+ unsigned long int intnetaddress;
+ unsigned long int intnetmask;
+ unsigned long int intbroadcast;
+ struct in_addr temp;
+ char *netaddress;
+ char *broadcast;
+
+ /* Build some key strings. */
+ sprintf(addressfield, "%s_ADDRESS", colour);
+ sprintf(netaddressfield, "%s_NETADDRESS", colour);
+ sprintf(netmaskfield, "%s_NETMASK", colour);
+ sprintf(broadcastfield, "%s_BROADCAST", colour);
+
+ strcpy(address, ""); findkey(kv, addressfield, address);
+ strcpy(netmask, ""); findkey(kv, netmaskfield, netmask);
+
+ /* Calculate netaddress. Messy.. */
+ intaddress = inet_addr(address);
+ intnetmask = inet_addr(netmask);
+
+ intnetaddress = intaddress & intnetmask;
+ temp.s_addr = intnetaddress;
+ netaddress = inet_ntoa(temp);
+
+ replacekeyvalue(kv, netaddressfield, netaddress);
+
+ intbroadcast = intnetaddress | ~intnetmask;
+ temp.s_addr = intbroadcast;
+ broadcast = inet_ntoa(temp);
+
+ replacekeyvalue(kv, broadcastfield, broadcast);
+
+ return 1;
+}
+
+/* Called when dhcp flag is toggled. Toggle disabled state of other 3
+ * controls. */
+void networkdialogcallbacktype(newtComponent cm, void *data)
+{
+ char type[STRING_SIZE];
+
+ gettype(type);
+
+ if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0 )
+ {
+ newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
+ newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
+ }
+ else
+ {
+ newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
+ newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
+ }
+ if (strcmp(type, "DHCP") == 0)
+ newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
+ else
+ newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
+
+ newtRefresh();
+ newtDrawForm(networkform);
+}
+
+int interfacecheck(struct keyvalue *kv, char *colour)
+{
+ char temp[STRING_SIZE];
+ char colourfields[NETCHANGE_TOTAL][STRING_SIZE];
+ int c;
+
+ sprintf(colourfields[ADDRESS], "%s_ADDRESS", colour);
+ sprintf(colourfields[NETADDRESS], "%s_NETADDRESS", colour);
+ sprintf(colourfields[NETMASK], "%s_NETMASK", colour);
+
+ for (c = 0; c < 3; c++)
+ {
+ strcpy(temp, ""); findkey(kv, colourfields[c], temp);
+ if (!(strlen(temp))) return 0;
+ }
+ return 1;
+}
+
+/* Funky routine for loading all drivers (cept those are already loaded.). */
+int probecards(char *driver, char *driveroptions)
+{
+ return 0;
+}
+
+/* ### alter strupper ###
+char *strupper(char *s)
+{
+ int n;
+ for (n=0;s[n];n++) s[n]=toupper(s[n]);
+ return s;
+}
+*/
+
+/* neuer StringUpper, wird zur Zeit nicht benutzt da UTF-8 nicht geht.
+void strupper(unsigned char *string)
+{
+ unsigned char *str;
+ for (str = string; *str != '\0'; str++)
+ if (!(*str & 0x80) && islower(*str))
+ *str = toupper(*str);
+}
+*/
+
+int write_configs_netudev(char *description, char *macaddr, char *colour)
+{
+ #define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules"
+ FILE *fp;
+ char commandstring[STRING_SIZE];
+ struct keyvalue *kv = initkeyvalues();
+ char temp1[STRING_SIZE], temp2[STRING_SIZE], temp3[STRING_SIZE];
+ char ucolour[STRING_SIZE];
+
+// sprintf(ucolour, colour);
+// strupper(ucolour);
+
+ switch (*colour)
+ {
+ case 'g': sprintf(ucolour, "GREEN");
+ strcpy(knics[_GREEN_CARD_].description, description);
+ strcpy(knics[_GREEN_CARD_].macaddr, macaddr);
+ break;
+ case 'r': sprintf(ucolour, "RED");
+ strcpy(knics[_RED_CARD_].description, description);
+ strcpy(knics[_RED_CARD_].macaddr, macaddr);
+ break;
+ case 'o': sprintf(ucolour, "ORANGE");
+ strcpy(knics[_ORANGE_CARD_].description, description);
+ strcpy(knics[_ORANGE_CARD_].macaddr, macaddr);
+ break;
+ case 'b': sprintf(ucolour, "BLUE");
+ strcpy(knics[_BLUE_CARD_].description, description);
+ strcpy(knics[_BLUE_CARD_].macaddr, macaddr);
+ break;
+ default: sprintf(ucolour, "DUMMY");
+ break;
+ }
+
+ if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
+ {
+ freekeyvalues(kv);
+ errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
+ return 0;
+ }
+
+ sprintf(temp1, "%s_DEV", ucolour);
+ sprintf(temp2, "%s_MACADDR", ucolour);
+ sprintf(temp3, "%s0", colour);
+ replacekeyvalue(kv, temp1, temp3);
+ replacekeyvalue(kv, temp2, macaddr);
+ sprintf(temp1, "%s_DESCRIPTION", ucolour);
+ replacekeyvalue(kv, temp1, description);
+
+ writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
+ freekeyvalues(kv);
+
+ // Make sure that there is no conflict
+ snprintf(commandstring, STRING_SIZE, "/usr/bin/touch "UDEV_NET_CONF" >/dev/null 2>&1");
+ system(commandstring);
+
+ snprintf(commandstring, STRING_SIZE, "/bin/cat "UDEV_NET_CONF" | /bin/grep -v \"%s\" > "UDEV_NET_CONF" 2>/dev/null", macaddr);
+ system(commandstring);
+
+ snprintf(commandstring, STRING_SIZE, "/bin/cat "UDEV_NET_CONF" | /bin/grep -v \"%s\" > "UDEV_NET_CONF" 2>/dev/null", colour);
+ system(commandstring);
+
+ if( (fp = fopen(UDEV_NET_CONF, "a")) == NULL )
+ {
+ fprintf(stderr,"Couldn't open" UDEV_NET_CONF);
+ return 1;
+ }
+ fprintf(fp,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{address}==\"%s\", NAME=\"%s0\" # %s\n", macaddr, colour, description);
+ fclose(fp);
+
+ return 0;
+}
+
+int scan_network_cards(void)
+{
+ FILE *fp;
+ char description[STRING_SIZE], macaddr[STRING_SIZE], temp_line[STRING_SIZE];
+ int count = 0;
+
+ if (!(scanned_nics_read_done))
+ {
+ fprintf(flog,"Enter scan_network_cards\n"); // #### Debug ####
+ mysystem("/bin/probenic.sh");
+ // Read our scanned nics
+ if( (fp = fopen(SCANNED_NICS, "r")) == NULL )
+ {
+ fprintf(stderr,"Couldn't open "SCANNED_NICS);
+ return 1;
+ }
+ while (fgets(temp_line, STRING_SIZE, fp) != NULL)
+ {
+ strcpy(description, strtok(temp_line,";"));
+ strcpy(macaddr, strtok(NULL,";"));
+ if ( strlen(macaddr) ) {
+ strcpy(nics[count].description , description );
+ strcpy(nics[count].macaddr , macaddr );
+ count++;
+ }
+ }
+ fclose(fp);
+ }
+ scanned_nics_read_done = 1;
+ return count;
+}
+
+
+
+int nicmenu(char *colour)
+{
+ int rc, choise = 0, count = 0, kcount = 0, mcount = 0, i, j, nic_in_use;
+ int found_NIC_as_Card[4];
+ char message[STRING_SIZE];
+
+ char cMenuInhalt[STRING_SIZE];
+ char MenuInhalt[20][180];
+ char *pMenuInhalt[20];
+
+// strcpy( message , pnics[count].macaddr);
+// while (strcmp(message, "")) {
+// count++;
+// strcpy( message , pnics[count].macaddr);
+// }
+
+ while (strcmp(nics[count].macaddr, "")) count++; // 2 find how many nics in system
+ for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++; // loop to find all knowing nics
+ fprintf(flog, "Enter NicMenu\n"); // #### Debug ####
+ fprintf(flog, "count nics %i\ncount knics %i\n", count, kcount); // #### Debug ####
+
+ // If new nics are found...
+ if (count > kcount) {
+ for (i=0 ; i < count ; i++)
+ {
+ nic_in_use = 0;
+ for (j=0 ; j <= kcount ; j++) {
+ if (strcmp(nics[ i ].macaddr, knics[ j ].macaddr) == 0 ) {
+ nic_in_use = 1;
+ fprintf(flog,"NIC \"%s\" is in use.\n", nics[ i ].macaddr); // #### Debug ####
+ break;
+ }
+ }
+ if (!(nic_in_use)) {
+ fprintf(flog,"NIC \"%s\" is free.\n", nics[ i ].macaddr); // #### Debug ####
+ if ( strlen(nics[i].description) < 55 )
+ sprintf(MenuInhalt[mcount], "%.*s", strlen(nics[i].description)-2, nics[i].description+1);
+ else {
+ sprintf(cMenuInhalt, "%.50s", nics[i].description + 1);
+ strncpy(MenuInhalt[mcount], cMenuInhalt,(strrchr(cMenuInhalt,' ') - cMenuInhalt));
+ strcat (MenuInhalt[mcount], "...");
+ }
+
+ while ( strlen(MenuInhalt[mcount]) < 50) strcat(MenuInhalt[mcount], " "); // Fill with space.
+
+ strcat(MenuInhalt[mcount], " (");
+ strcat(MenuInhalt[mcount], nics[i].macaddr);
+ strcat(MenuInhalt[mcount], ")");
+ pMenuInhalt[mcount] = MenuInhalt[mcount];
+ found_NIC_as_Card[mcount]=i;
+ mcount++;
+ }
+ }
+
+ pMenuInhalt[mcount] = NULL;
+
+// sprintf(message, "Es wurde(n) %d freie Netzwerkkarte(n) in Ihrem System gefunden.\nBitte waehlen Sie im naechsten Dialog eine davon aus.\n", count);
+// newtWinMessage("NetcardMenu", ctr[TR_OK], message);
+
+ sprintf(message, "(TR) Bitte waehlen Sie eine der untenstehenden Netzwerkkarten fuer die Schnittstelle \"%s\" aus.\n", colour);
+ rc = newtWinMenu("(TR) NetcardMenu2", message, 50, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_OK], ctr[TR_SELECT], ctr[TR_CANCEL], NULL);
+
+ if ( rc == 0 || rc == 1) {
+ write_configs_netudev(nics[choise].description, nics[found_NIC_as_Card[choise]].macaddr, colour);
+ } else if (rc == 2) {
+// manualdriver("pcnet32","");
+ }
+ return 0;
+ } else {
+ // We have to add here that you can manually add a device
+ errorbox("(TR) Es wurden leider keine freien Netzwerkkarten fuer die Schnittstelle in ihrem System gefunden.");
+ return 1;
+ }
+}
+
+int remove_nic_entry(char *colour)
+{
+ struct keyvalue *kv = initkeyvalues();
+ char message[STRING_SIZE];
+ char temp1[STRING_SIZE], temp2[STRING_SIZE];
+ char ucolour[STRING_SIZE];
+ int rc;
+
+
+ if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
+ {
+ freekeyvalues(kv);
+ errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
+ return 0;
+ }
+
+ switch (*colour)
+ {
+ case 'g': sprintf(ucolour, "GREEN");
+ strcpy(knics[_GREEN_CARD_].description, ctr[TR_UNSET]);
+ strcpy(knics[_GREEN_CARD_].macaddr, "");
+ strcpy(knics[_GREEN_CARD_].colour, "");
+ break;
+ case 'r': sprintf(ucolour, "RED");
+ strcpy(knics[_RED_CARD_].description, ctr[TR_UNSET]);
+ strcpy(knics[_RED_CARD_].macaddr, "");
+ strcpy(knics[_RED_CARD_].colour, "");
+ break;
+ case 'o': sprintf(ucolour, "ORANGE");
+ strcpy(knics[_ORANGE_CARD_].description, ctr[TR_UNSET]);
+ strcpy(knics[_ORANGE_CARD_].macaddr, "");
+ strcpy(knics[_ORANGE_CARD_].colour, "");
+ break;
+ case 'b': sprintf(ucolour, "BLUE");
+ strcpy(knics[_BLUE_CARD_].description, ctr[TR_UNSET]);
+ strcpy(knics[_BLUE_CARD_].macaddr, "");
+ strcpy(knics[_BLUE_CARD_].colour, "");
+ break;
+ default: sprintf(ucolour, "DUMMY");
+ break;
+ }
+
+ sprintf(message, "(TR) Soll die Netzwerkkarte \"%s\" entfernt werden ?\n", colour);
+ rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);
+
+ if ( rc = 0 || rc == 1) {
+ sprintf(temp1, "%s_DEV", ucolour);
+ sprintf(temp2, "%s_MACADDR", ucolour);
+ replacekeyvalue(kv, temp1, "");
+ replacekeyvalue(kv, temp2, "");
+ sprintf(temp1, "%s_DESCRIPTION", ucolour);
+ replacekeyvalue(kv, temp1, "");
+
+ writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
+ } else return 1;
+
+ freekeyvalues(kv);
+ return 0;
+}
+
+/* Manual entry for gurus. */
+int manualdriver(char *driver, char *driveroptions)
+{
+ char *values[] = { NULL, NULL }; /* pointers for the values. */
+ struct newtWinEntry entries[] =
+ { { "", &values[0], 0,}, { NULL, NULL, 0 } };
+ int rc;
+ char commandstring[STRING_SIZE];
+ char *driverend;
+
+ strcpy(driver, "");
+ strcpy(driveroptions, "");
+
+ rc = newtWinEntries(ctr[TR_SELECT_NETWORK_DRIVER],
+ ctr[TR_MODULE_PARAMETERS], 50, 5, 5, 40, entries,
+ ctr[TR_OK], ctr[TR_CANCEL], NULL);
+ if (rc == 0 || rc == 1)
+ {
+ if (strlen(values[0]))
+ {
+ sprintf(commandstring, "/sbin/modprobe %s", values[0]);
+ if (runcommandwithstatus(commandstring, ctr[TR_LOADING_MODULE]) == 0)
+ {
+ if ((driverend = strchr(values[0], ' ')))
+ {
+ *driverend = '\0';
+ strcpy(driver, values[0]);
+ strcpy(driveroptions, driverend + 1);
+ }
+ else
+ {
+ strcpy(driver, values[0]);
+ strcpy(driveroptions, "");
+ }
+ }
+ else
+ errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]);
+ }
+ else
+ errorbox(ctr[TR_MODULE_NAME_CANNOT_BE_BLANK]);
+ }
+ free(values[0]);
+
+ return 1;
+}