Ejemplo n.º 1
0
enum return_type ask_from_list_index_newt(const char *msg, const char ** elems, const char ** elems_comments, int * answer)
{
	char * items[50000];
	int rc;

	if (elems_comments) {
	    int i;

	    i = 0;
	    while (elems && *elems) {
		    int j = (*elems_comments) ? strlen(*elems_comments) : 0;
		    items[i] = (char*)malloc(sizeof(char) * (strlen(*elems) + j + 4));
		    strcpy(items[i], *elems);
		    if (*elems_comments) {
			    strcat(items[i], " (");
			    strcat(items[i], *elems_comments);
			    strcat(items[i], ")");
		    }
		    elems_comments++;
		    i++;
		    elems++;
	    }
	    items[i] = NULL;
	}

	rc = newtWinMenu((char*)"Please choose...", (char*)msg, 52, 5, 5, 7, (elems_comments ? items : (char**)elems), answer, (char*)"Ok", (char*)"Cancel", NULL);

	if (rc == 2)
		return RETURN_BACK;

	return RETURN_OK;
}
Ejemplo n.º 2
0
static VALUE rb_ext_Screen_WinMenu(VALUE self, VALUE args)
{
  long len;
  int i, listItem;
  char **cptr;

  len = RARRAY_LEN(args);
  if (len == 8) {
    Check_Type(RARRAY_PTR(args)[6], T_ARRAY);

    len = RARRAY_LEN(RARRAY_PTR(args)[6]);
    cptr = ALLOCA_N(char*, len + 1);
    for (i = 0; i < len; i++) {
      Check_Type(RARRAY_PTR(RARRAY_PTR(args)[6])[i], T_STRING);
      cptr[i] = StringValuePtr(RARRAY_PTR(RARRAY_PTR(args)[6])[i]);
    }
    cptr[len] = NULL;

    newtWinMenu(StringValuePtr(RARRAY_PTR(args)[0]), StringValuePtr(RARRAY_PTR(args)[1]),
        NUM2INT(RARRAY_PTR(args)[2]),
        NUM2INT(RARRAY_PTR(args)[3]), NUM2INT(RARRAY_PTR(args)[4]),
        NUM2INT(RARRAY_PTR(args)[5]),
        cptr, &listItem, StringValuePtr(RARRAY_PTR(args)[7]), NULL);
    return INT2NUM(listItem);
  } else if (len == 9) {
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
/* 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;
}
Ejemplo n.º 5
0
int chooseLanguage(char ** lang) {
    int choice = 0;
    char ** langs;
    int i;
    int current = -1;
    char * currentLangName = getenv("LANG");
    int numLangs = 0;
    char * langPicked;

    if (!languages) loadLanguageList();

    langs = alloca(sizeof(*langs) * (numLanguages + 1)); 

    for (i = 0; i < numLanguages; i++) {
        if (!strncmp(languages[i].key, "en", 2))
            english = numLangs;
        if (currentLangName &&
            !strcmp(languages[i].lang, currentLangName))
            current = numLangs;

        langs[numLangs++] = languages[i].lang;
    }

    langs[numLangs] = NULL;

    if (current >= 0)
        choice = current;
    else
        choice = english;

    if (!FL_CMDLINE(flags))
        newtWinMenu(_("Choose a Language"),
                    _("What language would you like to use during the "
                      "installation process?"), 40, 5, 5, 8,
                    langs, &choice, _("OK"), NULL);

    langPicked = langs[choice];
    for (i = 0; i < numLanguages; i++) {
        if (!strcmp(langPicked, languages[i].lang)) {
            *lang = languages[i].lc_all;
            choice = i;
            break;
        }
    }

    /* this can't happen */
    if (i == numLanguages) abort();

    return setupLanguage(choice, 0);
}
Ejemplo n.º 6
0
/* Shows the main menu and a summary of the current settings. */
int firstmenu(void)
{
	char *sections[] = {
		_("Network configuration type"),
		_("Drivers and card assignments"),
		_("Address settings"),
		_("DNS and Gateway settings"),
		NULL
	};
	int rc;
	static int choice = 0;
	struct keyvalue *kv = initkeyvalues();
	char message[1000];
	char temp[STRING_SIZE] = "1";
	int x;
	int result;
	char networkrestart[STRING_SIZE] = "";
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}	

	if (netaddresschange) 
		strcpy(networkrestart, _("When configuration is complete, a network restart will be required."));

	strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); 
	x = atol(temp);
	x--;
	if (x < 0 || x > 4) x = 0;
	/* Format heading bit. */
	snprintf(message, 1000, _("Current config: %s\n\n%s"), configtypenames[x], networkrestart);
	rc = newtWinMenu(_("Network configuration menu"), message, 50, 5, 5, 6,
			sections, &choice, _("OK"), _("Done"), NULL);

	if (rc == 0 || rc == 1)
		result = choice + 1;
	else
		result = 0;

	return result;
}
/* Shows the main menu and a summary of the current settings. */
int firstmenu(void)
{
	char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE],
		ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS],
		ctr[TR_ADDRESS_SETTINGS],
		ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL, NULL };
	int rc;
	static int choice = 0;
	struct keyvalue *kv = initkeyvalues();
	char message[1000];
	char temp[STRING_SIZE];
	int x;
	int result;
	char networkrestart[STRING_SIZE] = "";
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}	

	if (netaddresschange) 
		strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]);

	strcpy(temp, "");
	findkey(kv, "CONFIG_TYPE", temp);
	x = atol(temp);
	if (x < 0 || x > 7)
		x = 0;
	/* Format heading bit. */
	snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x],
		networkrestart);
	rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6,
		sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);

	if (rc == 0 || rc == 1)
		result = choice + 1;
	else
		result = 0;

	return result;
}
Ejemplo n.º 8
0
/* Open a window with selection of which password to modify */
int handlepasswords(void)
{
    int rc;
    int choice;
    char *menuchoices[5];

    menuchoices[0] = gettext("TR_ROOT_PASSWORD");
    menuchoices[1] = gettext("TR_ADMIN_PASSWORD");
    menuchoices[2] = gettext("TR_BACKUP_PASSWORD");
    menuchoices[3] = gettext("TR_DIAL_PASSWORD");

    menuchoices[4] = NULL;

    for (;;) {

        rc = newtWinMenu(gettext("TR_PASSWORDS"),
                         gettext("TR_SELECT_THE_ITEM"), 50, 5, 5, 11,
                         menuchoices, &choice, gettext("TR_OK"), gettext("TR_GO_BACK"), NULL);

        if (rc == 2)
            break;

        switch (choice) {
        case 0:
            password("root");
            break;
        case 1:
            password("admin");
            break;
        case 2:
            password("backup");
            break;
        case 3:
            password("dial");
            break;
        default:
            break;
        }
    }

    return SUCCESS;
}
/* 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;
}
Ejemplo n.º 10
0
// 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;
}
Ejemplo n.º 11
0
int changedrivers(void)
{
	struct keyvalue *kv = initkeyvalues();
	char temp[STRING_SIZE], message[STRING_SIZE];
	int configtype;
	int green = 0, red = 0, blue = 0, orange = 0;
	char MenuInhalt[10][180];
	char *pMenuInhalt[10];
	int count = 0, choise = 0, rc;
	int NicEntry[10];

	if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (automode == 0)
		runcommandwithstatus("/etc/rc.d/init.d/network stop red blue orange",
			_("Networking"), _("Restarting non-local network..."), NULL);

	findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
	if (configtype == 1)
		{ green = 1; red = 1; }
	else if (configtype == 2)
		{ green = 1; red = 1; orange = 1; }
	else if (configtype == 3)
		{ green = 1; red = 1; blue = 1; }
	else if (configtype == 4)
		{ green = 1; red=1; orange=1; blue = 1; }
	else if (configtype == "")
	  { green = 1; red = 1; }

	do
	{
		count = 0;
		strcpy(message, _("Please choose the interface you wish to change.\n\n"));

		if (green) {
			strcpy(MenuInhalt[count], "GREEN");
			pMenuInhalt[count] = MenuInhalt[count];
			NicEntry[_GREEN_CARD_] = count;
			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);
			}
			count++;
		}

		if (red) {
			strcpy(MenuInhalt[count], "RED");
			pMenuInhalt[count] = MenuInhalt[count];
			NicEntry[_RED_CARD_] = count;
			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);
			}
			count++;
		}

		if (orange) {
			strcpy(MenuInhalt[count], "ORANGE");
			pMenuInhalt[count] = MenuInhalt[count];
			NicEntry[_ORANGE_CARD_] = count;
			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);
			}
			count++;
		}

		if (blue) {
			strcpy(MenuInhalt[count], "BLUE");
			pMenuInhalt[count] = MenuInhalt[count];
			NicEntry[_BLUE_CARD_] = count;
			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);
			}
			count++;
		}
		pMenuInhalt[count] = NULL;

		rc = newtWinMenu(_("Assigned Cards"), message, 70, 5, 5, 6, pMenuInhalt,
			&choise, _("Select"), _("Remove"), _("Done"), NULL);
			
		if ( rc == 0 || rc == 1) {
			if ((green) && ( choise == NicEntry[0])) nicmenu(_GREEN_CARD_);
			if ((red) && ( choise == NicEntry[1])) nicmenu(_RED_CARD_);
			if ((orange) && ( choise == NicEntry[2])) nicmenu(_ORANGE_CARD_);
			if ((blue) && ( choise == NicEntry[3])) nicmenu(_BLUE_CARD_);
			netaddresschange = 1;
		} else if (rc == 2) {
			if ((green) && ( choise == NicEntry[0])) ask_clear_card_entry(_GREEN_CARD_);
			if ((red) && ( choise == NicEntry[1])) ask_clear_card_entry(_RED_CARD_);
			if ((orange) && ( choise == NicEntry[2])) ask_clear_card_entry(_ORANGE_CARD_);
			if ((blue) && ( choise == NicEntry[3])) ask_clear_card_entry(_BLUE_CARD_);
			netaddresschange = 1;
		}
	}
	while ( rc <= 2);

	freekeyvalues(kv);
	return 1;
}
Ejemplo n.º 12
0
int handleisdn(void)
{
	char *protocolnames[] = { ctr[TR_GERMAN_1TR6], ctr[TR_EURO_EDSS1],
		ctr[TR_LEASED_LINE], ctr[TR_US_NI1], NULL };
	struct keyvalue *kv;
	int rc;
	char protocolname[STRING_SIZE] = "";
	char cardname[STRING_SIZE] = "";
	char msn[STRING_SIZE] = "";
	char temps[STRING_SIZE];
	int tempd;
	char message[1000];
	int c;
	char *sections[] = { ctr[TR_PROTOCOL_COUNTRY],
		ctr[TR_SET_ADDITIONAL_MODULE_PARAMETERS], ctr[TR_ISDN_CARD],
		ctr[TR_MSN_CONFIGURATION], NULL, NULL };
	int choice;
	char enableddisabled[STRING_SIZE];
	FILE *f;
	
	if ((f = fopen(CONFIG_ROOT "red/active", "r")))
	{
		fclose(f);
		errorbox(ctr[TR_RED_IN_USE]);
		return 1;
	}
	
	/* isdn-cleanup is a small script to bring down ippp0 and kill ipppd
	 * and removes the ISDN modules. */
	mysystem("/etc/ppp/isdn-cleanup");

	choice = 0;	
	for (;;)
	{
		kv = initkeyvalues();
		if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings")))
		{
			freekeyvalues(kv);
			errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
			return 0;
		}

		strcpy(enableddisabled, ctr[TR_DISABLED]);
		findkey(kv, "ENABLED", temps);
		if (strcmp(temps, "on") == 0)
			strcpy(enableddisabled, ctr[TR_ENABLED]);
		
		strcpy(temps, "-1");
		findkey(kv, "PROTOCOL", temps);
		tempd = atol(temps);
		if (tempd < 1 || tempd > 4)
			strcpy(protocolname, ctr[TR_UNSET]);
		else
			strcpy(protocolname, protocolnames[tempd - 1]);
				
		strcpy(temps, "-1");
		findkey(kv, "TYPE", temps);
		tempd = atol(temps);
		c = 0;
		while (cards[c].name)
		{
			if (cards[c].type == tempd)
			{
				strcpy(cardname, cards[c].name);
				break;
			}
			c++;
		}
		if (!strlen(cardname))
			strcpy(cardname, ctr[TR_UNSET]);		

		strcpy(temps, "");		
		findkey(kv, "MSN", temps);
		if (strlen(temps))
			strcpy(msn, temps);
		else
			strcpy(msn, ctr[TR_UNSET]);
		sprintf(message, ctr[TR_ISDN_STATUS], enableddisabled, protocolname,
			cardname, msn);
		
		freekeyvalues(kv);
		
		rc = newtWinMenu(ctr[TR_ISDN_CONFIGURATION_MENU], message, 50, 5, 5, 6,
			sections, &choice, ctr[TR_OK], ctr[TR_ENABLE_ISDN],
			ctr[TR_DISABLE_ISDN], NULL);
		
		if (rc == 1 || rc == 0)
		{
			switch (choice)
			{
				case 0:
					handleisdnprotocol(protocolnames);
					break;
					
				case 1:
					handlemoduleparams();
					break;
							
				case 2:
					handleisdncard();
					break;
		
				case 3:
					handleisdnmsn();
					break;
				
				default:
					break;
			}
		}

		else if (rc == 2)
		{
			if (!isdnenabledpressed())
				break;
		}
		else
		{
			if (!(isdndisabledpressed()))
				break;
		}	
	}
	
	return 1;
}
int main(int argc, char *argv[])
{
	int choice;
	char *sections[13]; /* need to fill this out AFTER knowing lang */
	int rc;
	struct keyvalue *kv;
	char selectedshortlang[STRING_SIZE] = "en";
	int autook = 0;
	int doreboot = 0;
	struct stat statbuf;
	
	memset(&statbuf, 0, sizeof(struct stat));
			
	/* Log file/terminal stuff. */
	if (argc >= 2)
		logname = argv[1];	
	else
		logname = strdup("/root/setup.log");

	if (!(flog = fopen(logname, "w+")))
	{
		printf("Couldn't open log terminal\n");
		return 1;
	}
	
	if (argc >= 3)
		automode = 1;
	
	fprintf(flog, "Setup program started.\n");

	kv = initkeyvalues();
	if (!(readkeyvalues(kv, CONFIG_ROOT "main/settings")))
	{
		printf("SmoothWall is not properly installed.\n");
		return 1;
	}
	findkey(kv, "LANGUAGE", selectedshortlang);
	
	ctr = english_tr; 
	
	newtInit();
	newtCls();

	newtDrawRootText(0, 0, "                SmoothWall Express 3.0 -- http://smoothwall.org/");
	newtPushHelpLine(ctr[TR_HELPLINE]);		

	if (automode == 0)
	{
		sections[0] = ctr[TR_RESTORE_CONFIGURATION];
		sections[1] = ctr[TR_KEYBOARD_MAPPING];
		sections[2] = ctr[TR_HOSTNAME];
		sections[3] = ctr[TR_WEB_PROXY];
		sections[4] = ctr[TR_DEFAULT_SECURITY_LEVEL];
		sections[5] = ctr[TR_ISDN_CONFIGURATION];
		sections[6] = ctr[TR_ADSL_CONFIGURATION];
		sections[7] = ctr[TR_NETWORKING];	
		sections[8] = ctr[TR_DHCP_SERVER_CONFIGURATION],
		sections[9] = ctr[TR_ROOT_PASSWORD];
		sections[10] = ctr[TR_SETUP_PASSWORD];
		sections[11] = ctr[TR_ADMIN_PASSWORD];
		sections[12] = NULL;	
	
		usbfail = 1;
		if (!stat("/proc/bus/usb/devices", &statbuf))
			usbfail = 0;
			
		if (usbfail)
			fprintf(flog, "USB HCI not detected.\n");
		else
			fprintf(flog, "USB HCI detected.\n");		
			
		choice = 0;
		for (;;)
		{
			rc = newtWinMenu(ctr[TR_SECTION_MENU],
				ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8,
				sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL);
			
			if (rc == 2)
				break;
			
			switch (choice)
			{
				case 0:
					handlerestore();
					break;

				case 1:
					handlekeymap();
					break;
				
				case 2:
					handlehostname();
					break;

				case 3:
					handlewebproxy();
					break;
					
				case 4:
					handledefaults();
					break;

				case 5:
					handleisdn();
					break;

				case 6:
					handleadsl();
					break;
				
				case 7:
					handlenetworking();
					break;
					
				case 8:
					handledhcp();
					break;
									
				case 9:
					handlerootpassword();
					break;

				case 10:
					handlesetuppassword();
					break;
					
				case 11:
					handleadminpassword();
					break;
		
				default:
					break;
			}
		}
	}
	else
	{
		usbfail = 1;
		if (!stat("/proc/bus/usb/devices", &statbuf))
			usbfail = 0;
				
		if (newtWinChoice(TITLE, ctr[TR_NO], ctr[TR_YES],
			ctr[TR_RESTORE_LONG]) != 1)
		{
			if (!(handlerestore()))
				goto EXIT;
		}
	
		if (!(handlekeymap()))
			goto EXIT;
		if (!(handlehostname()))
			goto EXIT;
		if (!(handledefaults()))
			goto EXIT;
		if (!(handlenetworking()))
			goto EXIT;

		if (!performedrestore)
		{
			choice = 0;
			
			for (;;)
			{		
				sections[0] = ctr[TR_WEB_PROXY];
				sections[1] = ctr[TR_ISDN_CONFIGURATION];
				sections[2] = ctr[TR_ADSL_CONFIGURATION];
				sections[3] = ctr[TR_DHCP_SERVER_CONFIGURATION],
				sections[4] = NULL;	
	
				rc = newtWinMenu(ctr[TR_SECTION_MENU],
					ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8,
					sections, &choice, ctr[TR_OK], ctr[TR_FINISHED], NULL);
				
				if (rc == 2)
					break;
				
				switch (choice)
				{
					case 0:
						handlewebproxy();
						break;
						
					case 1:
						handleisdn();
						break;
	
					case 2:
						handleadsl();
						break;
											
					case 3:
						handledhcp();
						break;
	
					default:
						break;
				}
			}
		}	

		if (!(handleadminpassword()))
			goto EXIT;
		if (!(handlerootpassword()))
			goto EXIT;
	
		autook = 1;
	}

EXIT:	
	if (automode != 0)
	{
		if (autook)
			newtWinMessage(TITLE, ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
		else
			newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
	}
	else
	{
		if (rebootrequired)
		{
			if (newtWinChoice(TITLE, ctr[TR_YES], ctr[TR_NO],
				ctr[TR_DO_YOU_WANT_TO_REBOOT]) != 2)
			{
				doreboot = 1;
			}
		} 
	}

	fprintf(flog, "Setup program ended.\n");
	fflush(flog);
	fclose(flog);
		
	newtFinished();

 	if (doreboot)
		system("/sbin/shutdown -r now");

	return 0;
}
Ejemplo n.º 14
0
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;
}
/* 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;
}
Ejemplo n.º 16
0
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);
}
Ejemplo n.º 17
0
int main(int argc, char *argv[])
{
	int choice;
	char *sections[14]; /* need to fill this out AFTER knowing lang */
	int rc;
	struct keyvalue *kv;
	char selectedshortlang[STRING_SIZE] = "en";
	int autook = 0;
	int doreboot = 0;
	struct stat statbuf;
	
	memset(&statbuf, 0, sizeof(struct stat));
			
	/* Log file/terminal stuff. */
	if (argc >= 2)
		logname = argv[1];	
	else
		logname = strdup("/root/setup.log");

	if (!(flog = fopen(logname, "w+")))
	{
		printf("Couldn't open log terminal\n");
		return 1;
	}
	
	/* Engage auto operation (run through 'normal' selections automatically) */
	if (argc >= 3)
	{
		if (strlen(argv[2]) == 12 && strncmp(argv[2], "firstInstall", 12) == 0)
		{
			/* This execution only follows the installer; outgoing rules are cleared */
			automode = 1;
		}
		else if (strlen(argv[2]) == 15 && strncmp(argv[2], "networkingOnly", 15) == 0)
		{
			/* This execution only runs during bootup when the NICs have changed */
			automode = 2;
		}
		else
		{
			/* All other values mean generic auto mode during normal operation */
			automode = 3;
		}
	}
	
	fprintf(flog, "Setup program started.\n");

	kv = initkeyvalues();
	if (!(readkeyvalues(kv, CONFIG_ROOT "main/settings")))
	{
		printf("Smoothwall is not properly installed.\n");
		return 1;
	}
	findkey(kv, "LANGUAGE", selectedshortlang);
	
	ctr = english_tr; 
	
	newtInit();
	newtCls();

	newtDrawRootText(0, 0, TITLE " -- http://smoothwall.org/");
	newtPushHelpLine(ctr[TR_HELPLINE]);		

	if (automode == 0)
	{
		/* Admin selects each menu item individually */
		sections[0] = ctr[TR_RESTORE_CONFIGURATION];
		sections[1] = ctr[TR_KEYBOARD_MAPPING];
		sections[2] = ctr[TR_TIMEZONE];
		sections[3] = ctr[TR_HOSTNAME];
		sections[4] = ctr[TR_WEB_PROXY];
		sections[5] = ctr[TR_DEFAULT_SECURITY_LEVEL];
		sections[6] = ctr[TR_ISDN_CONFIGURATION];
		sections[7] = ctr[TR_ADSL_CONFIGURATION];
		sections[8] = ctr[TR_NETWORKING];	
		sections[9] = ctr[TR_DHCP_SERVER_CONFIGURATION],
		sections[10] = ctr[TR_ROOT_PASSWORD];
		sections[11] = ctr[TR_SETUP_PASSWORD];
		sections[12] = ctr[TR_ADMIN_PASSWORD];
		sections[13] = NULL;	
	
		usbfail = 1;
		if (!stat("/proc/bus/usb/devices", &statbuf))
			usbfail = 0;
			
		if (usbfail)
			fprintf(flog, "USB HCI not detected.\n");
		else
			fprintf(flog, "USB HCI detected.\n");		
			
		choice = 0;
		for (;;)
		{
			rc = newtWinMenu(ctr[TR_SECTION_MENU],
				ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8,
				sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL);
			
			if (rc == 2)
				break;
			
			switch (choice)
			{
				case 0:
					handlerestore();
					break;

				case 1:
					handlekeymap();
					break;
				
				case 2:
					handletimezone();
					break;
				
				case 3:
					handlehostname();
					break;

				case 4:
					handlewebproxy();
					break;
					
				case 5:
					handledefaults();
					break;

				case 6:
					handleisdn();
					break;

				case 7:
					handleadsl();
					break;
				
				case 8:
					handlenetworking();
					break;
					
				case 9:
					handledhcp();
					break;
									
				case 10:
					handlerootpassword();
					break;

				case 11:
					handlesetuppassword();
					break;
					
				case 12:
					handleadminpassword();
					break;
		
				default:
					break;
			}
		}
	}
	else if (automode == 2)
	{
		/* Admin specified networkingOnly as the third arg */
		/* This happens when the NIC change and rc.sysint runs setup */
		handlenetworking();
		autook = 2;
	}
	else
	{
		/* automode is 1 (firstInstall) or 3 (generic) */
		usbfail = 1;
				
		if (newtWinChoice(ctr[TR_RESTORE_CONFIGURATION], ctr[TR_NO], ctr[TR_YES],
			ctr[TR_RESTORE_LONG]) != 1)
		{
			if (!(handlerestore()))
				goto EXIT;
		}
	
		if (!(handlekeymap()))
			goto EXIT;
		if (!(handletimezone()))
			goto EXIT;
		if (!(handlehostname()))
			goto EXIT;
		if (!(handledefaults()))
			goto EXIT;
		if (!(handlenetworking()))
			goto EXIT;

		if (!performedrestore)
		{
			choice = 0;
			
			for (;;)
			{		
				sections[0] = ctr[TR_WEB_PROXY];
				sections[1] = ctr[TR_ISDN_CONFIGURATION];
				sections[2] = ctr[TR_ADSL_CONFIGURATION];
				sections[3] = ctr[TR_DHCP_SERVER_CONFIGURATION],
				sections[4] = NULL;	
	
				rc = newtWinMenu(ctr[TR_SECTION_MENU],
					ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 8,
					sections, &choice, ctr[TR_OK], ctr[TR_FINISHED], NULL);
				
				if (rc == 2)
					break;
				
				switch (choice)
				{
					case 0:
						handlewebproxy();
						break;
						
					case 1:
						handleisdn();
						break;
	
					case 2:
						handleadsl();
						break;
											
					case 3:
						handledhcp();
						break;
	
					default:
						break;
				}
			}
		}	

		if (!(handleadminpassword()))
			goto EXIT;
		if (!(handlerootpassword()))
			goto EXIT;
	
		autook = 1;
	}

EXIT:	
	if (automode == 1 || automode == 3)
	{
		if (autook)
			newtWinMessage("", ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
		else
			newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
	}
	else if (automode == 2)
	{
		if (autook == 2)
		{
			fprintf(flog, "Setup program ended.\n");
			fflush(flog);
			fclose(flog);
			newtFinished();
			return 0;
		}
		else
		{
			return -1;
		}
	}
	else
	{
		if (rebootrequired)
		{
			if (newtWinChoice("", ctr[TR_YES], ctr[TR_NO],
				ctr[TR_DO_YOU_WANT_TO_REBOOT]) != 2)
			{
				doreboot = 1;
			}
		} 
	}

	fprintf(flog, "Setup program ended.\n");
	fflush(flog);
	fclose(flog);
		
	newtFinished();

 	if (doreboot)
		system("/sbin/shutdown -r now");

	return 0;
}
Ejemplo n.º 18
0
int main(void) {
    newtComponent b1, b2, b3, b4;
    newtComponent answer, f, t;
    newtGrid grid, subgrid;
    char * flowedText;
    int textWidth, textHeight, rc;
    char * menuContents[] = { "One", "Two", "Three", "Four", "Five", NULL };
    char * entries[10];
    struct newtWinEntry autoEntries[] = {
	{ "An entry", entries + 0, 0 },
	{ "Another entry", entries + 1, 0 },
	{ "Third entry", entries + 2, 0 },
	{ "Fourth entry", entries + 3, 0 },
	{ NULL, NULL, 0 } };

    memset(entries, 0, sizeof(entries));

    newtInit();
    newtCls();

    b1 = newtCheckbox(-1, -1, "An pretty long checkbox for testing", ' ', NULL, NULL);
    b2 = newtButton(-1, -1, "Another Button");
    b3 = newtButton(-1, -1, "But, but");
    b4 = newtButton(-1, -1, "But what?");

    f = newtForm(NULL, NULL, 0);

    grid = newtCreateGrid(2, 2);
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 
			NEWT_ANCHOR_RIGHT, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
    newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0);
    newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0);


    newtFormAddComponents(f, b1, b2, b3, b4, NULL);

    newtGridWrappedWindow(grid, "first window");
    newtGridFree(grid, 1);

    answer = newtRunForm(f);
	
    newtFormDestroy(f);
    newtPopWindow();

    flowedText = newtReflowText("This is a quite a bit of text. It is 40 "
			  	"columns long, so some wrapping should be "
			  	"done. Did you know that the quick, brown "
			  	"fox jumped over the lazy dog?\n\n"
				"In other news, it's pretty important that we "
				"can properly force a line break.",
				40, 5, 5, &textWidth, &textHeight);
    t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP);
    newtTextboxSetText(t, flowedText);
    free(flowedText);

    
    b1 = newtButton(-1, -1, "Okay");
    b2 = newtButton(-1, -1, "Cancel");

    grid = newtCreateGrid(1, 2);
    subgrid = newtCreateGrid(2, 1);

    newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0);
    newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);

    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
			NEWT_GRID_FLAG_GROWX);
    newtGridWrappedWindow(grid, "another example");
    newtGridDestroy(grid, 1);

    f = newtForm(NULL, NULL, 0);
    newtFormAddComponents(f, b1, t, b2, NULL);
    answer = newtRunForm(f);

    newtPopWindow();
    newtFormDestroy(f);

    newtWinMessage("Simple", "Ok", "This is a simple message window");
    newtWinChoice("Simple", "Ok", "Cancel", "This is a simple choice window");

    textWidth = 0;
    rc = newtWinMenu("Test Menu", "This is a sample invovation of the "
		     "newtWinMenu() call. It may or may not have a scrollbar, "
		     "depending on the need for one.", 50, 5, 5, 3, 
		     menuContents, &textWidth, "Ok", "Cancel", NULL);

    rc = newtWinEntries("Text newtWinEntries()", "This is a sample invovation of "
		     "newtWinEntries() call. It lets you get a lot of input "
		     "quite easily.", 50, 5, 5, 20, autoEntries, "Ok", 
		     "Cancel", NULL);

    newtFinished();

    printf("rc = 0x%x item = %d\n", rc, textWidth);

    return 0;
}
Ejemplo n.º 19
0
int nicmenu(int colour)
{
	int rc, choise = 0, count = 0, kcount = 0, mcount = 0, i, j, nic_in_use;
	int found_NIC_as_Card[MAX_NICS];
	char message[STRING_SIZE];
	char temp[STRING_SIZE];

	char cMenuInhalt[STRING_SIZE];
	char MenuInhalt[MAX_NICS][STRING_SIZE];
	char *pMenuInhalt[MAX_NICS];
	
	while (strcmp(nics[count].macaddr, "")) count++;			// 2 find how many nics in system
	for (i=0; i<MAX_NICS; 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, _("Please choose a networkcard for the following interface - %s."), ucolourcard[colour]);
		rc=2;
		while ( rc == 2 ) {
			rc = newtWinMenu(_("Extended Network Menu"), message, 50, 5, 5, 6, pMenuInhalt, &choise,
				_("Select"), _("Identify"), _("Cancel"), NULL);
			if ( rc == 2 ) {
				sprintf(temp, "/sbin/ip link set %s up", nics[found_NIC_as_Card[choise]].nic);
				mysystem(NULL, temp);
				sprintf(temp, "/usr/sbin/ethtool -p %s 10", nics[found_NIC_as_Card[choise]].nic);
				if (runcommandwithstatus(temp, _("Device Identification"), _("The lights on the selected port should flash now for 10 seconds..."), NULL) != 0) {
					errorbox(_("Identification is not supported by this interface."));
				sprintf(temp, "/sbin/ip link set %s down", nics[found_NIC_as_Card[choise]].nic);
				mysystem(NULL, 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(_("There are no unassigned interfaces on your system."));
		return 1;
	}
}
Ejemplo n.º 20
0
int chooseKeyboard(struct loaderData_s * loaderData, char ** kbdtypep) {
    int num = -1;
    int rc;
    gzFile f;
    struct kmapHeader hdr;
    struct kmapInfo * infoTable;
    struct langInfo * languages;
    int numLanguages;
    char ** kbds;
    char buf[16384]; 			/* I hope this is big enough */
    int i;
    char * defkbd = loaderData->kbd ? loaderData->kbd : NULL;
    char *lang;

#if defined(__s390__) || defined(__s390x__)
    return LOADER_NOOP;
#endif

    if (FL_SERIAL (flags) || FL_VIRTPCONSOLE(flags)) return LOADER_NOOP;

    numLanguages = getLangInfo(&languages);

    lang = getenv("LANG");
    if (!lang)
       lang = loaderData->lang;

    if (!defkbd && lang) {
	for (i = 0; i < numLanguages; i++) {
	    if (!strncmp(languages[i].lc_all, lang, 2)) {
		defkbd = languages[i].keyboard;
		break;
	    }
	}
    }

    if (!defkbd)
	defkbd = "us";

    f = gzopen("/etc/keymaps.gz", "r");
    if (!f) {
	errorWindow("cannot open /etc/keymaps.gz: %s");
	return LOADER_ERROR;
    }

    if (gzread(f, &hdr, sizeof(hdr)) != sizeof(hdr)) {
	errorWindow("failed to read keymaps header: %s");
	gzclose(f);
	return LOADER_ERROR;
    }

    logMessage(INFO, "%d keymaps are available", hdr.numEntries);

    i = hdr.numEntries * sizeof(*infoTable);
    infoTable = alloca(i);
    if (gzread(f, infoTable, i) != i) {
	errorWindow("failed to read keymap information: %s");
	gzclose(f);
	return LOADER_ERROR;
    }

    if (num == -1 ) {
	kbds = alloca(sizeof(*kbds) * (hdr.numEntries + 1));
	for (i = 0; i < hdr.numEntries; i++)  {
	    kbds[i] = infoTable[i].name;
	}

	kbds[i] = NULL;
	qsort(kbds, i, sizeof(*kbds), simpleStringCmp);

	for (i = 0; i < hdr.numEntries; i++) 
	    if (!strcmp(kbds[i], defkbd)) 
		num = i;

	rc = newtWinMenu(_("Keyboard Type"), 
			_("What type of keyboard do you have?"),
		        40, 5, 5, 8, kbds, &num, _("OK"), _("Back"), NULL);
	if (rc == 2) return LOADER_BACK;

	/* num needs to index the right keyboard infoTable */
	for (i = 0; i < hdr.numEntries; i++)
	    if (!strcmp(kbds[num], infoTable[i].name)) break;
	num = i;
    }

    rc = 0;

    for (i = 0; i < num; i++) {
	if (gzread(f, buf, infoTable[i].size) != infoTable[i].size) {
	    logMessage(ERROR, "error reading %d bytes from file: %m",
		       infoTable[i].size);
	    gzclose(f);
	    rc = LOADER_ERROR;
	}
    }

    if (!rc) rc = loadKeymap(f);

    /* normalize the error condition */
    /* MSWFIXME - do we want to warn the user that setting the
       keyboard didn't work?
    */
    if (rc != 0)
	rc = LOADER_ERROR;
    else
        gzclose(f);

    loaderData->kbd = strdup(infoTable[num].name);

    return rc;
}
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;
}