// Let user change GREEN address. int greenaddressmenu(void) { struct keyvalue *kv = initkeyvalues(); char message[1000]; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); errorbox(_("Unable to open settings file")); return 0; } sprintf(message, _("If you change this IP address, and you are logged in remotely, " "your connection to the %s machine will be broken, and you will have to reconnect " "on the new IP. This is a risky operation, and should only be attempted if you " "have physical access to the machine, should something go wrong."), NAME); rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message); if (rc == 0 || rc == 1) { if (changeaddress(kv, "GREEN", 0, "")) { netaddresschange = 1; writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); writehostsfiles(); } } freekeyvalues(kv); return 0; }
/* Let user change GREEN address. */ int greenaddressmenu(void) { struct keyvalue *kv = initkeyvalues(); int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_WARNING_LONG]); if (rc == 0 || rc == 1) { if (changeaddress(kv, "GREEN", 0, "")) { netaddresschange = 1; writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); writehostsfiles(); } } freekeyvalues(kv); return 0; }
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; }
// They can change BLUE, ORANGE and GREEN too :) int addressesmenu(void) { struct keyvalue *kv = initkeyvalues(); struct keyvalue *mainkv = initkeyvalues(); int rc = 0; char *sections[5]; char *green = "GREEN"; char *orange = "ORANGE"; char *blue = "BLUE"; char *red = "RED"; int c = 0; char greenaddress[STRING_SIZE]; char oldgreenaddress[STRING_SIZE]; char temp[STRING_SIZE]; char temp2[STRING_SIZE]; char message[1000]; int configtype; int done; int choice; char hostname[STRING_SIZE]; if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) { freekeyvalues(kv); freekeyvalues(mainkv); errorbox(_("Unable to open settings file")); return 0; } if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings"))) { freekeyvalues(kv); freekeyvalues(mainkv); errorbox(_("Unable to open settings file")); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); sections[c] = green; c++; if (HAS_BLUE) { sections[c] = blue; c++; } if (HAS_ORANGE) { sections[c] = orange; c++; } if (HAS_RED) { sections[c] = red; c++; } sections[c] = NULL; choice = 0; done = 0; while (!done) { rc = newtWinMenu(_("Address settings"), _("Select the interface you wish to reconfigure."), 50, 5, 5, 6, sections, &choice, _("OK"), _("Done"), NULL); if (rc == 0 || rc == 1) { if (strcmp(sections[choice], "GREEN") == 0) { findkey(kv, "GREEN_ADDRESS", oldgreenaddress); sprintf(message, _("If you change this IP address, and you are logged in remotely, " "your connection to the %s machine will be broken, and you will have to reconnect " "on the new IP. This is a risky operation, and should only be attempted if you " "have physical access to the machine, should something go wrong."), NAME); rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message); if (rc == 0 || rc == 1) { if (changeaddress(kv, "GREEN", 0, "")) { netaddresschange = 1; writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); writehostsfiles(); findkey(kv, "GREEN_ADDRESS", greenaddress); snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress); snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress); replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2); chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); } } } if (strcmp(sections[choice], "BLUE") == 0) { if (changeaddress(kv, "BLUE", 0, "")) netaddresschange = 1; } if (strcmp(sections[choice], "ORANGE") == 0) { if (changeaddress(kv, "ORANGE", 0, "")) netaddresschange = 1; } if (strcmp(sections[choice], "RED") == 0) { strcpy(hostname, ""); findkey(mainkv, "HOSTNAME", hostname); if (changeaddress(kv, "RED", 1, hostname)) netaddresschange = 1; } } else done = 1; } writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings"); freekeyvalues(kv); freekeyvalues(mainkv); return 0; }
/* They can change ORANGE and GREEN too :) */ int addressesmenu(void) { struct keyvalue *kv = initkeyvalues(); struct keyvalue *mainkv = initkeyvalues(); int rc = 0; char *sections[6]; char *green = "GREEN"; char *orange = "ORANGE"; char *purple = "PURPLE"; char *red = "RED"; int c = 0; char temp[STRING_SIZE]; int configtype; int done; int choice; char hostname[STRING_SIZE]; if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings"))) { freekeyvalues(kv); freekeyvalues(mainkv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } if (!(readkeyvalues(mainkv, CONFIG_ROOT "main/settings"))) { freekeyvalues(kv); freekeyvalues(mainkv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp); sections[c] = green; c++; if (CONFIG_TYPE_ORANGE(configtype)) { sections[c] = orange; c++; } if (CONFIG_TYPE_PURPLE(configtype)) { sections[c] = purple; c++; } if (CONFIG_TYPE_RED(configtype)) { sections[c] = red; c++; } sections[c] = NULL; choice = 0; done = 0; while (!done) { rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS], ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5, 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL); if (rc == 0 || rc == 1) { if (strcmp(sections[choice], "GREEN") == 0) { rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], ctr[TR_WARNING_LONG]); if (rc == 0 || rc == 1) { if (changeaddress(kv, "GREEN", 0, "")) { netaddresschange = 1; writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); writehostsfiles(); } } } if (strcmp(sections[choice], "ORANGE") == 0) { if (changeaddress(kv, "ORANGE", 0, "")) netaddresschange = 1; } if (strcmp(sections[choice], "PURPLE") == 0) { if (changeaddress(kv, "PURPLE", 0, "")) netaddresschange = 1; } if (strcmp(sections[choice], "RED") == 0) { strcpy(hostname, ""); findkey(mainkv, "HOSTNAME", hostname); if (changeaddress(kv, "RED", 1, hostname)) netaddresschange = 1; } } else done = 1; } writekeyvalues(kv, CONFIG_ROOT "ethernet/settings"); freekeyvalues(kv); freekeyvalues(mainkv); return 0; }