int clear_card_entry(int card) { struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE]; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } strcpy(knics[card].driver, ""); strcpy(knics[card].description, _("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 write_configs_netudev(int card , int colour) { char commandstring[STRING_SIZE]; struct keyvalue *kv = initkeyvalues(); char temp1[STRING_SIZE], temp2[STRING_SIZE], temp3[STRING_SIZE]; char ucolour[STRING_SIZE]; sprintf(ucolour, ucolourcard[colour]); strcpy(knics[colour].driver, nics[card].driver); strcpy(knics[colour].description, nics[card].description); strcpy(knics[colour].macaddr, nics[card].macaddr); if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } sprintf(temp1, "%s_DEV", ucolour); sprintf(temp2, "%s_MACADDR", ucolour); sprintf(temp3, "%s0", lcolourcard[colour]); replacekeyvalue(kv, temp1, temp3); replacekeyvalue(kv, temp2, nics[card].macaddr); sprintf(temp1, "%s_DESCRIPTION", ucolour); replacekeyvalue(kv, temp1, nics[card].description); sprintf(temp1, "%s_DRIVER", ucolour); replacekeyvalue(kv, temp1, nics[card].driver); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); freekeyvalues(kv); return 0; }
int write_lang_configs(char* lang) { struct keyvalue *kv = initkeyvalues(); /* default stuff for main/settings. */ replacekeyvalue(kv, "LANGUAGE", lang); replacekeyvalue(kv, "HOSTNAME", SNAME); replacekeyvalue(kv, "THEME", "ipfire"); writekeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings"); freekeyvalues(kv); return 1; }
/* Returns 0 if main ISDN setup loop should exit. */ int isdnenabledpressed(void) { struct keyvalue *kv = initkeyvalues(); char protocol[STRING_SIZE] = ""; char type[STRING_SIZE] = ""; char msn[STRING_SIZE] = ""; char moduleparams[STRING_SIZE] = ""; char commandstring[STRING_SIZE]; int result = 0; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } findkey(kv, "PROTOCOL", protocol); findkey(kv, "TYPE", type); findkey(kv, "MSN", msn); findkey(kv, "MODULE_PARAMS", moduleparams); if (strlen(protocol) && strlen(type) && strlen(msn)) { if (!strcmp(type, "100")) { sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=%s %s", protocol, moduleparams); } else { sprintf(commandstring, "/sbin/modprobe hisax protocol=%s type=%s %s", protocol, type, moduleparams); } if (runcommandwithstatus(commandstring, ctr[TR_INITIALISING_ISDN]) != 0) { errorbox(ctr[TR_UNABLE_TO_INITIALISE_ISDN]); replacekeyvalue(kv, "ENABLED", "off"); result = 1; } else replacekeyvalue(kv, "ENABLED", "on"); } else { errorbox(ctr[TR_ISDN_NOT_SETUP]); replacekeyvalue(kv, "ENABLED", "off"); result = 1; } writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); freekeyvalues(kv); return result; }
void handleisdnprotocol(char **protocolnames) { int rc; int choice; struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE] = "1"; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "PROTOCOL", temp); choice = atol(temp) - 1; rc = newtWinMenu(ctr[TR_ISDN_PROTOCOL_SELECTION], ctr[TR_CHOOSE_THE_ISDN_PROTOCOL], 50, 5, 5, 6, protocolnames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 2) return; sprintf(temp, "%d", choice + 1); replacekeyvalue(kv, "PROTOCOL", temp); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); freekeyvalues(kv); }
/* 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; }
int handlehostname(void) { char hostname[STRING_SIZE] = ""; struct keyvalue *kv = initkeyvalues(); char *values[] = { hostname, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; int result; if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } strcpy(hostname, SNAME); findkey(kv, "HOSTNAME", hostname); for (;;) { rc = newtWinEntries(_("Hostname"), _("Enter the machine's hostname."), 50, 5, 5, 40, entries, _("OK"), _("Cancel"), NULL); if (rc == 1) { strcpy(hostname, values[0]); if (!(strlen(hostname))) errorbox(_("Hostname cannot be empty.")); else if (strchr(hostname, ' ')) errorbox(_("Hostname cannot contain spaces.")); else if (strlen(hostname) != strspn(hostname, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-")) errorbox(_("Hostname may only contain letters, numbers and hyphens.")); else { replacekeyvalue(kv, "HOSTNAME", hostname); writekeyvalues(kv, CONFIG_ROOT "/main/settings"); writehostsfiles(); result = 1; break; } } else { result = 0; break; } } free(values[0]); freekeyvalues(kv); return result; }
/* Here they choose general network config, number of nics etc. */ int configtypemenu(void) { struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE] = "1"; char message[1000]; int choise, found; int rc, configtype; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } found = scan_network_cards(); findkey(kv, "CONFIG_TYPE", temp); choise = atol(temp); choise--; sprintf(message, _("Select the network configuration for %s. " "The following configuration types list those interfaces which have ethernet attached. " "If you change this setting, a network restart will be required, and you will have to " "reconfigure the network driver assignments."), NAME); rc = newtWinMenu(_("Network configuration type"), message, 50, 5, 5, 6, configtypenames, &choise, _("OK"), _("Cancel"), NULL); if ( configtypecards[choise] > found ) { sprintf(message, _("Not enough netcards for your choice.\n\nNeeded: %d - Available: %d\n"), configtypecards[choise], found); errorbox(message); } if (rc == 0 || rc == 1) { choise++; sprintf(temp, "%d", choise); replacekeyvalue(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (!HAS_RED) clear_card_entry(_RED_CARD_); if (!HAS_ORANGE) clear_card_entry(_ORANGE_CARD_); if (!HAS_BLUE) clear_card_entry(_BLUE_CARD_); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); netaddresschange = 1; } freekeyvalues(kv); return 0; }
/* Here they choose general network config, number of nics etc. */ int configtypemenu(void) { struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE] = "0"; int choice; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } findkey(kv, "CONFIG_TYPE", temp); choice = atol(temp); rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], 50, 5, 5, 6, configtypenames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 0 || rc == 1) { runcommandwithstatus("/etc/rc.d/rc.netaddress.down", ctr[TR_PUSHING_NETWORK_DOWN]); sprintf(temp, "%d", choice); replacekeyvalue(kv, "CONFIG_TYPE", temp); replacekeyvalue(kv, "GREEN_DEV", ""); replacekeyvalue(kv, "ORANGE_DEV", ""); replacekeyvalue(kv, "PURPLE_DEV", ""); replacekeyvalue(kv, "RED_DEV", ""); writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); netaddresschange = 1; } freekeyvalues(kv); return 0; }
/* Returns 0 if main ISDN setup loop should exit. */ int isdndisabledpressed(void) { struct keyvalue *kv = initkeyvalues(); if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } replacekeyvalue(kv, "ENABLED", "off"); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); freekeyvalues(kv); return 0; }
void handleisdnmsn(void) { struct keyvalue *kv = initkeyvalues(); char msn[STRING_SIZE] = ""; const char *values[] = { msn, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "MSN", msn); for (;;) { rc = newtWinEntries(TITLE, ctr[TR_ENTER_THE_LOCAL_MSN], 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 1) { if (!(strlen(values[0]))) errorbox(ctr[TR_PHONENUMBER_CANNOT_BE_EMPTY]); else { strcpy(msn, values[0]); replacekeyvalue(kv, "MSN", msn); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); break; } } else break; } freekeyvalues(kv); free((char *) values[0]); }
void handlemoduleparams(void) { struct keyvalue *kv = initkeyvalues(); char moduleparams[STRING_SIZE] = ""; const char *values[] = { moduleparams, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "MODULE_PARAMS", moduleparams); for (;;) { rc = newtWinEntries(TITLE, ctr[TR_ENTER_ADDITIONAL_MODULE_PARAMS], 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 1) { strcpy(moduleparams, values[0]); replacekeyvalue(kv, "MODULE_PARAMS", moduleparams); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); break; } else break; } free((char * ) values[0]); freekeyvalues(kv); }
int networkmenu(struct keyvalue *ethernetkv) { int rc; char driver[STRING_SIZE] = ""; char driveroptions[STRING_SIZE] = ""; struct keyvalue *kv = initkeyvalues(); int result = 0; char commandstring[STRING_SIZE]; char address[STRING_SIZE], netmask[STRING_SIZE]; int done; char description[1000]; char message[1000]; char cardinfo[STRING_SIZE]; char mac[STRING_SIZE]; int c = 0; done = 0; c = 0; while (!done) { rc = newtWinTernary(ctr[TR_CONFIGURE_NETWORKING], ctr[TR_PROBE], ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_CONFIGURE_NETWORKING_LONG]); if (rc == 0 || rc == 1) { probecards(driver, driveroptions, &c); if (!strlen(driver)) errorbox(ctr[TR_PROBE_FAILED]); else { findnicdescription(driver, description); if ((getnicmac(mac, sizeof(mac), "eth0"))) /* If MAC found put it at the end of nic description. */ snprintf(cardinfo, STRING_SIZE, "%s [%s]", description, mac); else /* MAC lookup failed so just display nic description. */ snprintf(cardinfo, STRING_SIZE, "%s", description); sprintf(message, ctr[TR_FOUND_NIC], cardinfo); newtWinMessage(TITLE, ctr[TR_OK], message); } } else if (rc == 2) choosecards(driver, driveroptions); else done = 1; if (strlen(driver)) done = 1; } if (!strlen(driver)) goto EXIT; /* Default is a GREEN nic only. */ /* Smoothie is not untarred yet, so we have to delay actually writing the * settings till later. */ replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0"); replacekeyvalue(ethernetkv, "GREEN_DRIVER", driver); replacekeyvalue(ethernetkv, "GREEN_DRIVER_OPTIONS", driveroptions); replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0"); replacekeyvalue(ethernetkv, "GREEN_DISPLAYDRIVER", driver); if (!(changeaddress(ethernetkv, "GREEN", 0, ""))) goto EXIT; strcpy(address, ""); findkey(ethernetkv, "GREEN_ADDRESS", address); strcpy(netmask, ""); findkey(ethernetkv, "GREEN_NETMASK", netmask); snprintf(commandstring, STRING_SIZE, "/bin/ifconfig eth0 %s netmask %s up", address, netmask); if (mysystem(commandstring)) { errorbox(ctr[TR_INTERFACE_FAILED_TO_COME_UP]); goto EXIT; } result = 1; EXIT: freekeyvalues(kv); return result; }
/* DNS and default gateway.... */ int dnsgatewaymenu(void) { struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE] = "0"; struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ int error; int configtype; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } entries[DNS1].text = _("Primary DNS:"); strcpy(temp, ""); findkey(kv, "DNS1", temp); values[DNS1] = strdup(temp); entries[DNS1].value = &values[DNS1]; entries[DNS1].flags = 0; entries[DNS2].text = _("Secondary DNS:"); strcpy(temp, ""); findkey(kv, "DNS2", temp); values[DNS2] = strdup(temp); entries[DNS2].value = &values[DNS2]; entries[DNS2].flags = 0; entries[DEFAULT_GATEWAY].text = _("Default gateway:"); strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); values[DEFAULT_GATEWAY] = strdup(temp); entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY]; entries[DEFAULT_GATEWAY].flags = 0; entries[DNSGATEWAY_TOTAL].text = NULL; entries[DNSGATEWAY_TOTAL].value = NULL; entries[DNSGATEWAY_TOTAL].flags = 0; do { error = 0; rc = newtWinEntries(_("DNS and Gateway settings"), _("Enter the DNS and gateway information. " "These settings are used only with Static IP (and DHCP if DNS set) on the RED interface."), 50, 5, 5, 18, entries, _("OK"), _("Cancel"), NULL); if (rc == 0 || rc == 1) { strcpy(message, _("The following fields are invalid:")); strcpy(message, "\n\n"); if (strlen(values[DNS1])) { if (inet_addr(values[DNS1]) == INADDR_NONE) { strcat(message, _("Primary DNS")); strcat(message, "\n"); error = 1; } } if (strlen(values[DNS2])) { if (inet_addr(values[DNS2]) == INADDR_NONE) { strcat(message, _("Secondary DNS")); strcat(message, "\n"); error = 1; } } if (strlen(values[DEFAULT_GATEWAY])) { if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) { strcat(message, _("Default gateway")); strcat(message, "\n"); error = 1; } } if (!strlen(values[DNS1]) && strlen(values[DNS2])) { strcpy(message, _("Secondary DNS specified without a Primary DNS")); strcat(message, "\n"); error = 1; } if (error) errorbox(message); else { replacekeyvalue(kv, "DNS1", values[DNS1]); replacekeyvalue(kv, "DNS2", values[DNS2]); replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); netaddresschange = 1; free(values[DNS1]); free(values[DNS2]); free(values[DEFAULT_GATEWAY]); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); } } } while (error); freekeyvalues(kv); return 1; }
/* Driver menu. Choose drivers.. */ int drivermenu(void) { struct keyvalue *kv = initkeyvalues(); char message[STRING_SIZE]; char temp[STRING_SIZE] = "1"; int configtype; int i, rc, kcount = 0, neednics; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } if (findkey(kv, "CONFIG_TYPE", temp)) configtype = atol(temp); else { fprintf(flog,"setting CONFIG_TYPE = %s\n",temp); configtype = atol(temp); replacekeyvalue(kv, "CONFIG_TYPE", temp); writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); } strcpy(message, _("Configure network drivers, and which interface each card is assigned to. " "The current configuration is as follows:\n\n")); kcount = 0; neednics = 0; if (HAS_GREEN) { sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description); strcat(message, temp); if (strlen(knics[_GREEN_CARD_].macaddr) ) { sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr); strcat(message, temp); } neednics++; } if (HAS_RED) { sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description); strcat(message, temp); if (strlen(knics[_RED_CARD_].macaddr) ) { sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr); strcat(message, temp); } neednics++; } if (HAS_ORANGE) { sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description); strcat(message, temp); if ( strlen(knics[_ORANGE_CARD_].macaddr) ) { sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr); strcat(message, temp); } neednics++; } if (HAS_BLUE) { sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description); strcat(message, temp); if (strlen(knics[_BLUE_CARD_].macaddr)) { sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr); strcat(message, temp); } neednics++; } for ( i=0 ; i<4; i++) if (strcmp(knics[i].macaddr, "")) kcount++; if (neednics = kcount) { strcat(message, "\n"); strcat(message, _("Do you wish to change these settings?")); rc = newtWinChoice(_("Drivers and card assignments"), _("OK"), _("Cancel"), message); if (rc == 0 || rc == 1) { changedrivers(); } } else { changedrivers(); } freekeyvalues(kv); return 1; }
int handledhcp(void) { char *results[MAX_BOXES]; char enabledresult; char startenabled; struct newtExitStruct es; newtComponent header; newtComponent labels[MAX_BOXES]; newtComponent ok, cancel; char message[1000]; char *labeltexts[MAX_BOXES] = { _("Start address:"), _("End address:"), _("Primary DNS:"), _("Secondary DNS:"), _("Default lease (mins):"), _("Max lease (mins):"), _("Domain name suffix:") }; char *varnames[MAX_BOXES] = { "START_ADDR_GREEN", "END_ADDR_GREEN", "DNS1_GREEN", "DNS2_GREEN", "DEFAULT_LEASE_TIME_GREEN", "MAX_LEASE_TIME_GREEN", "DOMAIN_NAME_GREEN" }; char defaults[MAX_BOXES][STRING_SIZE]; int result; int c; char temp[STRING_SIZE]; struct keyvalue *mainkv = initkeyvalues(); struct keyvalue *dhcpkv = initkeyvalues(); struct keyvalue *ethernetkv = initkeyvalues(); int error; FILE *file; char greenaddress[STRING_SIZE]; char greennetaddress[STRING_SIZE]; char greennetmask[STRING_SIZE]; memset(defaults, 0, sizeof(char) * STRING_SIZE * MAX_BOXES); if (!(readkeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings"))) { freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); errorbox(_("Unable to open settings file")); return 0; } if (!(readkeyvalues(ethernetkv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); errorbox(_("Unable to open settings file")); return 0; } if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) { freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); freekeyvalues(mainkv); errorbox(_("Unable to open settings file")); return 0; } /* Set default values. */ findkey(ethernetkv, "GREEN_ADDRESS", defaults[PRIMARY_DNS]); findkey(mainkv, "DOMAINNAME", defaults[DOMAIN_NAME_SUFFIX]); strcpy(defaults[DEFAULT_LEASE_TIME], "60"); strcpy(defaults[MAX_LEASE_TIME], "120"); newtCenteredWindow(55, 18, _("DHCP server configuration")); dhcpform = newtForm(NULL, NULL, 0); header = newtTextboxReflowed(1, 1, _("Configure the DHCP server by entering the settings information."), 52, 0, 0, 0); newtFormAddComponent(dhcpform, header); strcpy(temp, ""); findkey(dhcpkv, "ENABLE_GREEN", temp); if (strcmp(temp, "on") == 0) startenabled = '*'; else startenabled = ' '; enabledcheckbox = newtCheckbox(2, TOP + 0, _("Enabled"), startenabled, " *", &enabledresult); newtFormAddComponent(dhcpform, enabledcheckbox); newtComponentAddCallback(enabledcheckbox, dhcpdialogcallbackdhcp, NULL); for (c = 0; c < MAX_BOXES; c++) { labels[c] = newtTextbox(2, TOP + 2 + c, 33, 1, 0); newtTextboxSetText(labels[c], labeltexts[c]); newtFormAddComponent(dhcpform, labels[c]); strcpy(temp, defaults[c]); findkey(dhcpkv, varnames[c], temp); entries[c] = newtEntry(34, TOP + 2 + c, temp, 18, &results[c], 0); newtFormAddComponent(dhcpform, entries[c]); if (startenabled == ' ') newtEntrySetFlags(entries[c], NEWT_FLAG_DISABLED, NEWT_FLAGS_SET); } ok = newtButton(10, c + 7, _("OK")); cancel = newtButton(34, c + 7, _("Cancel")); newtFormAddComponents(dhcpform, ok, cancel, NULL); do { error = 0; newtFormRun(dhcpform, &es); if (es.u.co == ok) { /* OK was pressed; verify the contents of each entry. */ if (enabledresult == '*') { strcpy(message, _("The following fields are invalid:\n\n")); if (inet_addr(results[START_ADDRESS]) == INADDR_NONE) { strcat(message, _("Start address")); strcat(message, "\n"); error = 1; } if (inet_addr(results[END_ADDRESS]) == INADDR_NONE) { strcat(message, _("End address")); strcat(message, "\n"); error = 1; } if (strlen(results[SECONDARY_DNS])) { if (inet_addr(results[PRIMARY_DNS]) == INADDR_NONE) { strcat(message, _("Primary DNS")); strcat(message, "\n"); error = 1; } } if (strlen(results[SECONDARY_DNS])) { if (inet_addr(results[SECONDARY_DNS]) == INADDR_NONE) { strcat(message, _("Secondary DNS")); strcat(message, "\n"); error = 1; } } if (!(atol(results[DEFAULT_LEASE_TIME]))) { strcat(message, _("Default lease time")); strcat(message, "\n"); error = 1; } if (!(atol(results[MAX_LEASE_TIME]))) { strcat(message, _("Max. lease time")); strcat(message, "\n"); error = 1; } } if (error) errorbox(message); else { for (c = 0; c < MAX_BOXES; c++) replacekeyvalue(dhcpkv, varnames[c], results[c]); if (enabledresult == '*') { replacekeyvalue(dhcpkv, "ENABLE_GREEN", "on"); fclose(fopen(CONFIG_ROOT "/dhcp/enable_green", "w")); chown(CONFIG_ROOT "/dhcp/enable_green", 99, 99); mysystem(NULL, "/usr/local/bin/dhcpctrl enable"); } else { replacekeyvalue(dhcpkv, "ENABLE_GREEN", "off"); unlink(CONFIG_ROOT "/dhcp/enable_green"); mysystem(NULL, "/usr/local/bin/dhcpctrl disable"); } replacekeyvalue(dhcpkv, "VALID", "yes"); writekeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings"); findkey(ethernetkv, "GREEN_ADDRESS", greenaddress); findkey(ethernetkv, "GREEN_NETADDRESS", greennetaddress); findkey(ethernetkv, "GREEN_NETMASK", greennetmask); file = fopen(CONFIG_ROOT "/dhcp/dhcpd.conf", "w"); fprintf(file, "ddns-update-style none;\n"); fprintf(file, "authoritative;\n"); fprintf(file, "subnet %s netmask %s\n", greennetaddress, greennetmask); fprintf(file, "{\n"); fprintf(file, "\toption subnet-mask %s;\n", greennetmask); fprintf(file, "\toption domain-name \"%s\";\n", results[DOMAIN_NAME_SUFFIX]); fprintf(file, "\toption routers %s;\n", greenaddress); if (strlen(results[PRIMARY_DNS])) { fprintf(file, "\toption domain-name-servers "); fprintf(file, "%s", results[PRIMARY_DNS]); if (strlen(results[SECONDARY_DNS])) fprintf(file, ", %s", results[SECONDARY_DNS]); fprintf(file, ";\n"); } fprintf(file, "\trange %s %s;\n", results[START_ADDRESS], results[END_ADDRESS]); fprintf(file, "\tdefault-lease-time %d;\n", (int) atol(results[DEFAULT_LEASE_TIME]) * 60); fprintf(file, "\tmax-lease-time %d;\n", (int) atol(results[MAX_LEASE_TIME]) * 60); fprintf(file, "}\n"); fclose(file); chown(CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); if (automode == 0) mysystem(NULL, "/usr/local/bin/dhcpctrl enable"); } result = 1; } else result = 0; } while (error); newtFormDestroy(dhcpform); newtPopWindow(); freekeyvalues(dhcpkv); freekeyvalues(ethernetkv); freekeyvalues(mainkv); return result; }
/* DNS and default gateway.... */ int dnsgatewaymenu(void) { struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE] = "0"; struct newtWinEntry entries[DNSGATEWAY_TOTAL+1]; char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */ int error; int configtype; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); if (!CONFIG_TYPE_RED(configtype)) { freekeyvalues(kv); errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]); return 0; } entries[DNS1].text = ctr[TR_PRIMARY_DNS]; strcpy(temp, ""); findkey(kv, "DNS1", temp); values[DNS1] = strdup(temp); entries[DNS1].value = (const char **) &values[DNS1]; entries[DNS1].flags = 0; entries[DNS2].text = ctr[TR_SECONDARY_DNS]; strcpy(temp, ""); findkey(kv, "DNS2", temp); values[DNS2] = strdup(temp); entries[DNS2].value = (const char **) &values[DNS2]; entries[DNS2].flags = 0; entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY]; strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp); values[DEFAULT_GATEWAY] = strdup(temp); entries[DEFAULT_GATEWAY].value = (const char **) &values[DEFAULT_GATEWAY]; entries[DEFAULT_GATEWAY].flags = 0; entries[DNSGATEWAY_TOTAL].text = NULL; entries[DNSGATEWAY_TOTAL].value = NULL; entries[DNSGATEWAY_TOTAL].flags = 0; do { error = 0; rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 0 || rc == 1) { strcpy(message, ctr[TR_INVALID_FIELDS]); if (strlen(values[DNS1])) { if (inet_addr(values[DNS1]) == INADDR_NONE) { strcat(message, ctr[TR_PRIMARY_DNS_CR]); error = 1; } } if (strlen(values[DNS2])) { if (inet_addr(values[DNS2]) == INADDR_NONE) { strcat(message, ctr[TR_SECONDARY_DNS_CR]); error = 1; } } if (strlen(values[DEFAULT_GATEWAY])) { if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE) { strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]); error = 1; } } if (!strlen(values[DNS1]) && strlen(values[DNS2])) { strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]); error = 1; } if (error) errorbox(message); else { replacekeyvalue(kv, "DNS1", values[DNS1]); replacekeyvalue(kv, "DNS2", values[DNS2]); replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]); netaddresschange = 1; free((char *) values[DNS1]); free((char *) values[DNS2]); free((char *) values[DEFAULT_GATEWAY]); writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); } } } while (error); freekeyvalues(kv); return 1; }
int changedrivers(void) { struct keyvalue *kv = initkeyvalues(); char message[1000]; char temp[STRING_SIZE]; int configtype; int rc; int c; int needcards, sofarallocated, nictocheck, countofcards, toallocate; char *green = "GREEN"; char *orange = "ORANGE"; char *purple = "PURPLE"; char *red = "RED"; char *sections[6]; int choice; char nexteth[STRING_SIZE]; int abort; char currentdriver[STRING_SIZE], currentdriveroptions[STRING_SIZE]; char displaydriver[STRING_SIZE]; char cardinfo[STRING_SIZE]; char mac[STRING_SIZE]; int driverc = 0; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); runcommandwithstatus("/etc/rc.d/rc.netaddress.down", ctr[TR_PUSHING_NETWORK_DOWN]); /* Blank them so the rc.netaddress.up dosnt get confused. */ replacekeyvalue(kv, "GREEN_DEV", ""); replacekeyvalue(kv, "ORANGE_DEV", ""); replacekeyvalue(kv, "PURPLE_DEV", ""); replacekeyvalue(kv, "RED_DEV", ""); if (configtype == 0) needcards = 1; else if (configtype == 1 || configtype == 2 || configtype == 4) needcards = 2; else if (configtype == 3 || configtype == 5 || configtype == 6) needcards = 3; else needcards = 4; /* This is the green card. */ sofarallocated = 0; nictocheck = 0; countofcards = countcards(); strcpy(displaydriver, ""); strcpy(currentdriver, ""); abort = 0; driverc = 0; /* Keep going till all cards are got, or they give up. */ while (sofarallocated < needcards && !abort) { /* This is how many cards were added by the last module. */ toallocate = countofcards - nictocheck; while (!abort && toallocate > 0 && nictocheck < countofcards && sofarallocated < needcards) { findnicdescription(displaydriver, temp); /* Get device name, eth%d is hard coded. */ sprintf(nexteth, "eth%d", nictocheck); /* Get MAC address. */ if (getnicmac(mac, STRING_SIZE, nexteth)) /* If MAC found put at the end of NIC description. */ snprintf(cardinfo, STRING_SIZE, "%s [%s]", temp, mac); else /* MAC lookup failed so just display NIC description. */ snprintf(cardinfo, STRING_SIZE, "%s", temp); sprintf(message, ctr[TR_UNCLAIMED_DRIVER], cardinfo); c = 0; choice = 0; strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp); if (CONFIG_TYPE_GREEN(configtype) &&!strlen(temp)) sections[c++] = green; strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp); if (CONFIG_TYPE_ORANGE(configtype) && !strlen(temp)) sections[c++] = orange; strcpy(temp, ""); findkey(kv, "PURPLE_DEV", temp); if (CONFIG_TYPE_PURPLE(configtype) && !strlen(temp)) sections[c++] = purple; strcpy(temp, ""); findkey(kv, "RED_DEV", temp); if (CONFIG_TYPE_RED(configtype) && !strlen(temp)) sections[c++] = red; sections[c] = NULL; rc = newtWinMenu(ctr[TR_CARD_ASSIGNMENT], message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_SKIP], ctr[TR_CANCEL], NULL); if (rc == 0 || rc == 1) { /* Now we see which iface needs its settings changed. */ if (strcmp(sections[choice], green) == 0) { replacekeyvalue(kv, "GREEN_DEV", nexteth); replacekeyvalue(kv, "GREEN_DRIVER", currentdriver); replacekeyvalue(kv, "GREEN_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "GREEN_DISPLAYDRIVER", displaydriver); sofarallocated++; nictocheck++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } if (strcmp(sections[choice], orange) == 0) { replacekeyvalue(kv, "ORANGE_DEV", nexteth); replacekeyvalue(kv, "ORANGE_DRIVER", currentdriver); replacekeyvalue(kv, "ORANGE_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "ORANGE_DISPLAYDRIVER", displaydriver); sofarallocated++; nictocheck++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } if (strcmp(sections[choice], purple) == 0) { replacekeyvalue(kv, "PURPLE_DEV", nexteth); replacekeyvalue(kv, "PURPLE_DRIVER", currentdriver); replacekeyvalue(kv, "PURPLE_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "PURPLE_DISPLAYDRIVER", displaydriver); sofarallocated++; nictocheck++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } if (strcmp(sections[choice], red) == 0) { replacekeyvalue(kv, "RED_DEV", nexteth); replacekeyvalue(kv, "RED_DRIVER", currentdriver); replacekeyvalue(kv, "RED_DRIVER_OPTIONS", currentdriveroptions); replacekeyvalue(kv, "RED_DISPLAYDRIVER", displaydriver); sofarallocated++; nictocheck++; toallocate--; strcpy(currentdriver, ""); strcpy(currentdriveroptions, ""); } } else if (rc == 2) { nictocheck++; } else if (rc == 3) { // Cancelled? Then abort abort = 1; } // Reached the end of the cards? Abort if (nictocheck >= countofcards) abort=1; // Run out of cards to allocate? Abort if (toallocate == 0) abort=1; // Got enough cards? Break and finish if (sofarallocated == needcards) break; } } if (sofarallocated >= needcards) { newtWinMessage(ctr[TR_CARD_ASSIGNMENT], ctr[TR_OK], ctr[TR_ALL_CARDS_SUCCESSFULLY_ALLOCATED]); } else errorbox(ctr[TR_NOT_ENOUGH_CARDS_WERE_ALLOCATED]); writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); freekeyvalues(kv); netaddresschange = 1; return 1; }
void handleisdncard(void) { char **selection; int c; int rc; int choice; int type; struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE] = "0"; int card; char message[STRING_SIZE]; char commandstring[STRING_SIZE]; char moduleparams[STRING_SIZE] = ""; int done = 0; if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "TYPE", temp); type = atol(temp); findkey(kv, "MODULE_PARAMS", moduleparams); /* Count cards. */ c = 0; while (cards[c].name) c++; selection = malloc((c + 1) * sizeof(char *)); /* Fill out section. */ c = 0; selection[c] = ctr[TR_AUTODETECT]; c++; while (cards[c].name) { selection[c] = cards[c].name; c++; } selection[c] = NULL; /* Determine inital value for choice. */ c = 0; choice = 0; while (cards[c].name) { if (cards[c].type == type) { choice = c; break; } c++; } while (!done) { rc = newtWinMenu(ctr[TR_ISDN_CARD_SELECTION], ctr[TR_CHOOSE_THE_ISDN_CARD_INSTALLED], 50, 5, 5, 10, selection, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 2) done = 1; else { if (choice == 0) card = probeisdncard(); else { sprintf(message, ctr[TR_CHECKING_FOR], cards[choice].name); if (cards[choice].type == 100) { sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=1 %s", moduleparams); } else { sprintf(commandstring, "/sbin/modprobe hisax type=%d protocol=1 %s", cards[choice].type, moduleparams); } if (runcommandwithstatus(commandstring, message) == 0) card = cards[choice].type; else { errorbox(ctr[TR_ISDN_CARD_NOT_DETECTED]); card = -1; } mysystem("/etc/ppp/isdn-cleanup"); } if (card != -1) { sprintf(temp, "%d", card); replacekeyvalue(kv, "TYPE", temp); writekeyvalues(kv, CONFIG_ROOT "isdn/settings"); done = 1; } } } free(selection); freekeyvalues(kv); }
/* 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, _("Interface - %s"), colour); newtCenteredWindow(44, (typeflag ? 18 : 12), message); networkform = newtForm(NULL, NULL, 0); sprintf(message, _("Enter the IP address information for the %s interface."), 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, _("Static"), startstatictype, NULL); dhcptyperadio = newtRadiobutton(2, 5, _("DHCP"), startdhcptype, statictyperadio); pppoetyperadio = newtRadiobutton(2, 6, _("PPP DIALUP (PPPoE, modem, ATM ...)"), 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, _("DHCP Hostname:")); dhcpforcemtulabel = newtTextbox(2, 9, 18, 1, 0); newtTextboxSetText(dhcpforcemtulabel, _("Force DHCP 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, _("IP address:")); 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, _("Network mask:")); 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), _("OK")); cancel = newtButton(26, (typeflag ? 14 : 7), _("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, _("The following fields are invalid:")); strcat(message, "\n\n"); strcpy(type, "STATIC"); if (typeflag) gettype(type); if (strcmp(type, "STATIC") == 0) { if (inet_addr(addressresult) == INADDR_NONE) { strcat(message, _("IP address")); strcat(message, "\n"); error = 1; } if (inet_addr(netmaskresult) == INADDR_NONE) { strcat(message, _("Network mask")); strcat(message, "\n"); error = 1; } } if (strcmp(type, "DHCP") == 0) { if (!strlen(dhcphostnameresult)) { strcat(message, _("DHCP hostname")); strcat(message, "\n"); 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; }
int handledefaults(void) { int c; int choice; struct keyvalue *kv = initkeyvalues(); char openness[STRING_SIZE]; char newopenness[STRING_SIZE]; char *opennesses[] = { "open", "halfopen", "closed", NULL }; char *displayopennesses[] = { ctr[TR_OPENNESS_OPEN], ctr[TR_OPENNESS_HALFOPEN], ctr[TR_OPENNESS_CLOSED], NULL }; int rc; int result; char commandstring[STRING_SIZE - 1]; memset(openness, 0, STRING_SIZE - 1); memset(newopenness, 0, STRING_SIZE - 1); memset(commandstring, 0, STRING_SIZE - 1); if (!(readkeyvalues(kv, CONFIG_ROOT "main/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strncpy(openness, "halfopen", STRING_SIZE - 1); findkey(kv, "OPENNESS", openness); choice = 0; for (c = 0; opennesses[c]; c++) { if (strcmp(openness, opennesses[c]) == 0) choice = c; } rc = newtWinMenu(ctr[TR_DEFAULT_OPENNESS], ctr[TR_DEFAULT_OPENNESS_LONG], 75, 30, 30, 3, displayopennesses, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); strncpy(newopenness, opennesses[choice], STRING_SIZE - 1); if (rc != 2) { /* Copy the config thingies if its changed OR its the inital * install run of the setup program. */ if (automode == 1 || strcmp(openness, newopenness) != 0) { snprintf(commandstring, STRING_SIZE - 1, "/usr/bin/smoothwall/installdefaults.pl %s", newopenness); mysystem(commandstring); replacekeyvalue(kv, "OPENNESS", newopenness); writekeyvalues(kv, CONFIG_ROOT "main/settings"); rebootrequired = 1; } result = 1; } else result = 0; freekeyvalues(kv); return result; }