From: Michael Tremer Date: Wed, 30 Jul 2014 20:03:55 +0000 (+0200) Subject: Move setup to an own directory. X-Git-Tag: v2.17-core87~103^2~51^2~96 X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=commitdiff_plain;h=7064bbd9914fc5dbafad1e3ea20ac2a27caaa3d5 Move setup to an own directory. --- diff --git a/lfs/setup b/lfs/setup index 1b33b966c1..a5dee7359e 100644 --- a/lfs/setup +++ b/lfs/setup @@ -48,17 +48,13 @@ md5 : $(TARGET) : @$(PREBUILD) - @rm -rf $(DIR_APP) && mkdir $(DIR_APP) && cp -R $(DIR_SRC)/src/install+setup/* $(DIR_APP) + @rm -rf $(DIR_APP) && mkdir $(DIR_APP) && cp -R $(DIR_SRC)/src/setup/* $(DIR_APP) - cd $(DIR_APP)/libsmooth && make CFLAGS="$(CFLAGS) -Wall \ + cd $(DIR_APP) && make CFLAGS="$(CFLAGS) -Wall \ -DNAME='\"$(NAME)\"' -DSNAME='\"$(SNAME)\"' -DVERSION='\"$(VERSION)\"' \ -DSLOGAN='\"$(SLOGAN)\"' -DCONFIG_ROOT='\"$(CONFIG_ROOT)\"'" - cd $(DIR_APP)/setup && make CFLAGS="$(CFLAGS) -Wall \ - -DNAME='\"$(NAME)\"' -DSNAME='\"$(SNAME)\"' -DVERSION='\"$(VERSION)\"' \ - -DSLOGAN='\"$(SLOGAN)\"' -DCONFIG_ROOT='\"$(CONFIG_ROOT)\"'" - - cd $(DIR_APP)/setup && install -m 0755 setup /usr/local/sbin - install -m 0755 $(DIR_SRC)/src/install+setup/install/probenic.sh /bin + cd $(DIR_APP) && install -m 0755 setup /usr/local/sbin + cd $(DIR_APP) && install -m 0755 probenic.sh /bin @rm -rf $(DIR_APP) @$(POSTBUILD) diff --git a/src/install+setup/setup/setup.h b/src/install+setup/setup/setup.h deleted file mode 100644 index e6a32a6a61..0000000000 --- a/src/install+setup/setup/setup.h +++ /dev/null @@ -1,40 +0,0 @@ -/* SmoothWall setup program. - * - * This program is distributed under the terms of the GNU General Public - * Licence. See the file COPYING for details. - * - * (c) Lawrence Manning, 2001 - * Main include file. - * - * $Id: setup.h,v 1.4 2003/12/11 11:25:54 riddles Exp $ - * - */ - -#include "../libsmooth/libsmooth.h" - -/* hostname.c */ -int handlehostname(void); - -/* domainname.c */ -int handledomainname(void); - -/* networking.c */ -int handlenetworking(void); - -/* dhcp.c */ -int handledhcp(void); - -/* passwords.c */ -int handlerootpassword(void); -int handlesetuppassword(void); -int handleadminpassword(void); - -/* misc.c */ -int writehostsfiles(void); -int handleisdn(void); - -/* keymap.c */ -int handlekeymap(void); - -/* timezone.c */ -int handletimezone(void); diff --git a/src/install+setup/setup/Makefile b/src/setup/Makefile similarity index 96% rename from src/install+setup/setup/Makefile rename to src/setup/Makefile index 924da77dbe..9bbd479411 100644 --- a/src/install+setup/setup/Makefile +++ b/src/setup/Makefile @@ -24,7 +24,7 @@ INCLUDE = LD = gcc LDFLAGS = -LIBS = -lnewt -lslang +LIBS = -lnewt -lslang -lsmooth COMPILE = $(CC) -c $(INCLUDE) $(CFLAGS) @@ -40,7 +40,7 @@ clean : ###### OBJS=main.o hostname.o domainname.o passwords.o networking.o misc.o \ - dhcp.o keymap.o timezone.o ../libsmooth/libsmooth.o + dhcp.o keymap.o timezone.o setup: $(OBJS) $(LINK) $(OBJS) -o $@ $(LIBS) diff --git a/src/install+setup/setup/dhcp.c b/src/setup/dhcp.c similarity index 100% rename from src/install+setup/setup/dhcp.c rename to src/setup/dhcp.c diff --git a/src/install+setup/setup/domainname.c b/src/setup/domainname.c similarity index 100% rename from src/install+setup/setup/domainname.c rename to src/setup/domainname.c diff --git a/src/install+setup/setup/hostname.c b/src/setup/hostname.c similarity index 100% rename from src/install+setup/setup/hostname.c rename to src/setup/hostname.c diff --git a/src/install+setup/setup/keymap.c b/src/setup/keymap.c similarity index 100% rename from src/install+setup/setup/keymap.c rename to src/setup/keymap.c diff --git a/src/install+setup/setup/main.c b/src/setup/main.c similarity index 100% rename from src/install+setup/setup/main.c rename to src/setup/main.c diff --git a/src/install+setup/setup/misc.c b/src/setup/misc.c similarity index 100% rename from src/install+setup/setup/misc.c rename to src/setup/misc.c diff --git a/src/setup/netstuff.c b/src/setup/netstuff.c new file mode 100644 index 0000000000..8c6f3fa90f --- /dev/null +++ b/src/setup/netstuff.c @@ -0,0 +1,776 @@ +/* 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 + +extern FILE *flog; +extern char *mylog; + +extern char **ctr; + +extern struct nic nics[]; +extern struct knic knics[]; + +char *ucolourcard[] = { "GREEN", "RED", "ORANGE", "BLUE", NULL }; +char *lcolourcard[] = { "green", "red", "orange", "blue", NULL }; + +int scanned_nics_read_done = 0; + +newtComponent networkform; +newtComponent addressentry; +newtComponent netmaskentry; +newtComponent statictyperadio; +newtComponent dhcptyperadio; +newtComponent pppoetyperadio; +newtComponent dhcphostnameentry; +newtComponent dhcpforcemtuentry; + +/* 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; + char *dhcpforcemturesult; + struct newtExitStruct es; + newtComponent header; + newtComponent addresslabel; + newtComponent netmasklabel; + newtComponent dhcphostnamelabel; + newtComponent dhcpforcemtulabel; + 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]; + char dhcpforcemtufield[STRING_SIZE]; + int error; + int result = 0; + char type[STRING_SIZE]; + int startstatictype = 0; + int startdhcptype = 0; + int startpppoetype = 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(dhcpforcemtufield, "%s_DHCP_FORCE_MTU", 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; + statictyperadio = newtRadiobutton(2, 4, ctr[TR_STATIC], startstatictype, NULL); + dhcptyperadio = newtRadiobutton(2, 5, ctr[TR_DHCP], startdhcptype, statictyperadio); + pppoetyperadio = newtRadiobutton(2, 6, ctr[TR_PPP_DIALUP], startpppoetype, dhcptyperadio); + newtFormAddComponents(networkform, statictyperadio, dhcptyperadio, + pppoetyperadio, NULL); + newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL); + newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL); + newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL); + dhcphostnamelabel = newtTextbox(2, 8, 18, 1, 0); + newtTextboxSetText(dhcphostnamelabel, ctr[TR_DHCP_HOSTNAME]); + dhcpforcemtulabel = newtTextbox(2, 9, 18, 1, 0); + newtTextboxSetText(dhcpforcemtulabel, ctr[TR_DHCP_FORCE_MTU]); + strcpy(temp, defaultdhcphostname); + findkey(kv, dhcphostnamefield, temp); + dhcphostnameentry = newtEntry(20, 8, temp, 20, &dhcphostnameresult, 0); + strcpy(temp, ""); + findkey(kv, dhcpforcemtufield, temp); + dhcpforcemtuentry = newtEntry(20, 9, temp, 20, &dhcpforcemturesult, 0); + newtFormAddComponent(networkform, dhcphostnamelabel); + newtFormAddComponent(networkform, dhcphostnameentry); + newtFormAddComponent(networkform, dhcpforcemtulabel); + newtFormAddComponent(networkform, dhcpforcemtuentry); + if (startdhcptype == 0) + { + newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); + newtEntrySetFlags(dhcpforcemtuentry, 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) + 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) + 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) + { + 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); + replacekeyvalue(kv, dhcpforcemtufield, dhcpforcemturesult); + if (strcmp(type, "STATIC") != 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; + } + } + /* Workaround for a bug that dhcp radiobutton also end the dialog at arm + */ + else { + if (es.u.co != cancel) { + error = 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 + 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) + { + 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); + newtEntrySetFlags(dhcpforcemtuentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET); + } + else + { + newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); + newtEntrySetFlags(dhcpforcemtuentry, 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; +} + +int get_knic(int card) //returns "0" for zero cards or error and "1" card is found. +{ + struct keyvalue *kv = initkeyvalues(); + char temp[STRING_SIZE], searchstr[STRING_SIZE]; + int ret_value; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) + { + freekeyvalues(kv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + sprintf(searchstr, "%s_MACADDR", ucolourcard[card]); + strcpy(temp, ""); findkey(kv, searchstr, temp); + if (strlen(temp)) { + strcpy(knics[ card ].macaddr, temp); + strcpy(knics[ card ].colour, ucolourcard[card]); + + sprintf(searchstr, "%s_DESCRIPTION", ucolourcard[card]); + findkey(kv, searchstr, temp); + strcpy(knics[ card ].description, temp); + + sprintf(searchstr, "%s_DRIVER", ucolourcard[card]); + findkey(kv, searchstr, temp); + strcpy(knics[ card ].driver, temp); + ret_value = 1; + } else { + strcpy(knics[ card ].description, ctr[TR_UNSET]); + ret_value = 0; + } + freekeyvalues(kv); + + return ret_value; +} + +int init_knics(void) +{ + int found = 0; + found += get_knic(_GREEN_CARD_); + found += get_knic(_RED_CARD_); + found += get_knic(_ORANGE_CARD_); + found += get_knic(_BLUE_CARD_); + + return found; +} + +int fmt_exists(const char *fname) { /* Check if it is any file or directory */ + struct stat st; + if (stat(fname, &st) == -1) return 0; + else return 1; +} + +int is_interface_up(char *card) { /* Check if the interface is UP */ + char temp[STRING_SIZE]; + + sprintf(temp,"ip link show dev %s | grep -q UP", card); + if (mysystem(temp)) return 0; else return 1; +} + +int rename_device(char *old_name, char *new_name) { + char temp[STRING_SIZE]; + + sprintf(temp,SYSDIR "/%s", old_name); + if (!(fmt_exists(temp))) { + fprintf(flog,"Device not found: %s\n",old_name); + return 0; + } + sprintf(temp,"/sbin/ip link set dev %s name %s",old_name ,new_name ); + mysystem(temp); + + return 1; +} + +char g_temp[STRING_SIZE]=""; +char* readmac(char *card) { + FILE *fp; + char temp[STRING_SIZE], mac[20]; + + sprintf(temp,"/sys/class/net/%s/address",card); + if( (fp = fopen(temp, "r")) == NULL ) { + fprintf(flog,"Couldn't open: %s\n",temp); + return NULL; + } + fgets(mac, 18, fp); + strtok(mac,"\n"); + fclose(fp); + strcpy(g_temp, mac); + return g_temp; +} + +char* find_nic4mac(char *findmac) { + DIR *dir; + struct dirent *dirzeiger; + char temp[STRING_SIZE], temp2[STRING_SIZE]; + + if((dir=opendir(SYSDIR)) == NULL) { + fprintf(flog,"Fehler bei opendir (find_name4nic) ...\n"); + return NULL; + } + + sprintf(temp, ""); + while((dirzeiger=readdir(dir)) != NULL) { + if(*((*dirzeiger).d_name) != '.' & strcmp(((*dirzeiger).d_name), "lo") != 0) { + sprintf(temp2, "%s", readmac((*dirzeiger).d_name) ); + if (strcmp(findmac, temp2) == 0) { + sprintf(temp,"%s", (*dirzeiger).d_name); + break; + } + } + } + + if(closedir(dir) == -1) fprintf(flog,"Fehler beim schliessen von %s\n", SYSDIR); + strcpy(g_temp, temp); + return g_temp; +} + +int nic_shutdown(char *nic) { + char temp[STRING_SIZE]; + + sprintf(temp,"ip link set %s down", nic); + mysystem(temp); +} + +int nic_startup(char *nic) { + char temp[STRING_SIZE]; + + sprintf(temp,"ip link set %s up", nic); + mysystem(temp); + +} + +int rename_nics(void) { + int i, j, k; + int fnics = scan_network_cards(); + char nic2find[STRING_SIZE], temp[STRING_SIZE]; + + for(i=0; i<4; i++) + if (strcmp(knics[i].macaddr, "")) + for(j=0; j 15 ) { + sprintf(nics[count].nic, "%s", find_nic4mac(nics[count].macaddr)); + count++; + } + } + fclose(fp); + scanned_nics_read_done = count; + } else fprintf(flog,"Scan Networkcards does read.\n"); + return scanned_nics_read_done; +} + + + +int nicmenu(int 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 temp[STRING_SIZE]; + + char cMenuInhalt[STRING_SIZE]; + char MenuInhalt[20][180]; + char *pMenuInhalt[20]; + + 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 + + // 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; + break; + } + } + if (!(nic_in_use)) { + 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); + sprintf(MenuInhalt[mcount], cMenuInhalt); + strcat (MenuInhalt[mcount], "..."); + } + + while ( strlen(MenuInhalt[mcount]) < 53) 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, ctr[TR_CHOOSE_NETCARD], ucolourcard[colour]); + rc=2; + while ( rc == 2 ) { + rc = newtWinMenu( ctr[TR_NETCARDMENU2], message, 50, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_SELECT], ctr[TR_IDENTIFY], ctr[TR_CANCEL], NULL); + if ( rc == 2 ) { + sprintf(temp, "/sbin/ip link set %s up", nics[found_NIC_as_Card[choise]].nic); + mysystem(temp); + sprintf(temp, "/usr/sbin/ethtool -p %s 10", nics[found_NIC_as_Card[choise]].nic); + if (runcommandwithstatus(temp,ctr[TR_IDENTIFY_SHOULD_BLINK]) != 0) { + errorbox(ctr[TR_IDENTIFY_NOT_SUPPORTED]); + sprintf(temp, "/sbin/ip link set %s down", nics[found_NIC_as_Card[choise]].nic); + mysystem(temp); + } + } + } + if ( rc == 0 || rc == 1) { + write_configs_netudev(found_NIC_as_Card[choise], colour); + } + return 0; + } else { + // We have to add here that you can manually add a device + errorbox( ctr[TR_ERROR_INTERFACES]); + return 1; + } +} + +int clear_card_entry(int card) +{ + struct keyvalue *kv = initkeyvalues(); + char temp[STRING_SIZE]; + + if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) + { + freekeyvalues(kv); + errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); + return 0; + } + + strcpy(knics[card].driver, ""); + strcpy(knics[card].description, ctr[TR_UNSET]); + strcpy(knics[card].macaddr, ""); + strcpy(knics[card].colour, ""); + sprintf(temp, "%s_DRIVER", ucolourcard[card]); + replacekeyvalue(kv, temp, ""); + sprintf(temp, "%s_DEV", ucolourcard[card]); + replacekeyvalue(kv, temp, ""); + sprintf(temp, "%s_MACADDR", ucolourcard[card]); + replacekeyvalue(kv, temp, ""); + sprintf(temp, "%s_DESCRIPTION", ucolourcard[card]); + replacekeyvalue(kv, temp, ""); + + writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); + freekeyvalues(kv); + + return 0; +} + +int ask_clear_card_entry(int card) +{ + char message[STRING_SIZE]; + int rc; + + sprintf(message, ctr[TR_REMOVE_CARD], ucolourcard[card]); + rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message); + + if ( rc = 0 || rc == 1) { + clear_card_entry(card); + } else return 1; + + 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; +} diff --git a/src/install+setup/setup/networking.c b/src/setup/networking.c similarity index 100% rename from src/install+setup/setup/networking.c rename to src/setup/networking.c diff --git a/src/install+setup/setup/passwords.c b/src/setup/passwords.c similarity index 100% rename from src/install+setup/setup/passwords.c rename to src/setup/passwords.c diff --git a/src/setup/setup.h b/src/setup/setup.h new file mode 100644 index 0000000000..71f7e6f11e --- /dev/null +++ b/src/setup/setup.h @@ -0,0 +1,86 @@ +/* SmoothWall setup program. + * + * This program is distributed under the terms of the GNU General Public + * Licence. See the file COPYING for details. + * + * (c) Lawrence Manning, 2001 + * Main include file. + * + * $Id: setup.h,v 1.4 2003/12/11 11:25:54 riddles Exp $ + * + */ + +#include "../libsmooth/libsmooth.h" + +/* hostname.c */ +int handlehostname(void); + +/* domainname.c */ +int handledomainname(void); + +/* networking.c */ +int handlenetworking(void); + +/* dhcp.c */ +int handledhcp(void); + +/* passwords.c */ +int handlerootpassword(void); +int handlesetuppassword(void); +int handleadminpassword(void); + +/* misc.c */ +int writehostsfiles(void); +int handleisdn(void); + +/* keymap.c */ +int handlekeymap(void); + +/* timezone.c */ +int handletimezone(void); + +/* netstuff.c */ +#define ADDRESS 0 +#define NETADDRESS 1 +#define NETMASK 2 +#define DHCP 3 +#define NETCHANGE_TOTAL 4 + +#define SCANNED_NICS "/var/ipfire/ethernet/scanned_nics" +#define SYSDIR "/sys/class/net" + +#define _GREEN_CARD_ 0 +#define _RED_CARD_ 1 +#define _ORANGE_CARD_ 2 +#define _BLUE_CARD_ 3 + +struct nic +{ + char driver[80]; + char description[256]; + char macaddr[20]; + char nic[20]; +}; + +struct knic +{ + char driver[80]; + char description[256]; + char macaddr[20]; + char colour[20]; +}; + +int changeaddress(struct keyvalue *kv, char *colour, int typeflag, + char *defaultdhcphostname); +int gettype(char *type); +int setnetaddress(struct keyvalue *kv, char *colour); +void networkdialogcallbacktype(newtComponent cm, void *data); +int interfacecheck(struct keyvalue *kv, char *colour); +int rename_nics(void); +int init_knics(void); +int create_udev(void); +int scan_network_cards(void); +int nicmenu(int colour); +int clear_card_entry(int cards); +int ask_clear_card_entry(int cards); +int manualdriver(char *driver, char *driveroptions); diff --git a/src/install+setup/setup/timezone.c b/src/setup/timezone.c similarity index 100% rename from src/install+setup/setup/timezone.c rename to src/setup/timezone.c