Example #1
0
int oktoleave(void)
{
	struct keyvalue *kv = initkeyvalues();
	char temp[STRING_SIZE];
	int configtype;
	int rc;
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}	

	strcpy(temp, "1"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
	if (configtype < 1 || configtype > 4) configtype = 1;

	if (HAS_GREEN)
	{
		strcpy(temp, ""); findkey(kv, "GREEN_DEV", temp);
		if (!(strlen(temp)))
		{
			errorbox(_("No GREEN interface assigned."));
			freekeyvalues(kv);
			return 0;
		}
		if (!(interfacecheck(kv, "GREEN")))
		{
			errorbox(_("Missing an IP address on GREEN."));
			freekeyvalues(kv);
			return 0;
		}
	}
	if (HAS_RED)
	{

		strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
		if (!(strlen(temp)))
		{
			rc = newtWinChoice(_("Error"), _("OK"), _("Ignore"),
				_("No RED interface assigned."));
			if (rc == 0 || rc == 1)
			{
				freekeyvalues(kv);
				return 0;
			}
		}
		if (!(interfacecheck(kv, "RED")))
		{
			errorbox(_("Missing an IP address on RED."));
			freekeyvalues(kv);
			return 0;
		}
	}
	if (HAS_ORANGE)
	{
		strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
		if (!(strlen(temp)))
		{
			errorbox(_("No ORANGE interface assigned."));
			freekeyvalues(kv);
			return 0;
		}
		if (!(interfacecheck(kv, "ORANGE")))
		{
			errorbox(_("Missing an IP address on ORANGE."));
			freekeyvalues(kv);
			return 0;
		}
	}
	if (HAS_BLUE)
	{
		strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
		if (!(strlen(temp)))
		{
			errorbox(_("No BLUE interface assigned."));
			freekeyvalues(kv);
			return 0;
		}
		if (!(interfacecheck(kv, "BLUE")))
		{
			errorbox(_("Missing an IP address on BLUE."));
			freekeyvalues(kv);
			return 0;
		}
	}
	
	strcpy(temp, ""); findkey(kv, "RED_TYPE", temp);
	if ((configtype == 0) || (strcmp(temp, "STATIC") == 0))
	{
		strcpy(temp, ""); findkey(kv, "DNS1", temp);
		if (!(strlen(temp)))
		{
                       errorbox(_("Missing DNS."));
			freekeyvalues(kv);
			return 0;
		}
		strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
		if (!(strlen(temp)))
		{
			errorbox(_("Missing Default Gateway."));
			freekeyvalues(kv);
			return 0;
		}
	}
	return 1;
}
Example #2
0
/* 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;
}
/* 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;
}			
Example #4
0
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;
}
Example #5
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);
}
/* 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;
}
int oktoleave(char *errormessage)
{
	struct keyvalue *kv = initkeyvalues();
	char temp[STRING_SIZE];
	int configtype;
	
	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 (configtype < 0 || configtype > 7)
		configtype = 0;

	if (CONFIG_TYPE_GREEN(configtype))
	{
		strcpy(temp, "");
		findkey(kv, "GREEN_DEV", temp);
		if (!(strlen(temp)))
		{
			strcpy(errormessage, ctr[TR_NO_GREEN_INTERFACE]);
			goto EXIT;
		}
		if (!(interfacecheck(kv, "GREEN")))
		{
			strcpy(errormessage, ctr[TR_MISSING_GREEN_IP]);
			goto EXIT;
		}
	}
	if (CONFIG_TYPE_ORANGE(configtype))
	{
		strcpy(temp, "");
		findkey(kv, "ORANGE_DEV", temp);
		if (!(strlen(temp)))
		{
			strcpy(errormessage, ctr[TR_NO_ORANGE_INTERFACE]);
			goto EXIT;
		}
		if (!(interfacecheck(kv, "ORANGE")))
		{
			strcpy(errormessage, ctr[TR_MISSING_ORANGE_IP]);
			goto EXIT;
		}
	}
	if (CONFIG_TYPE_PURPLE(configtype))
	{
		strcpy(temp, "");
		findkey(kv, "PURPLE_DEV", temp);
		if (strlen(temp) == 0)
		{
			strcpy(errormessage, ctr[TR_NO_PURPLE_INTERFACE]);
			goto EXIT;
		}
		if (!interfacecheck(kv, "PURPLE"))
		{
			strcpy(errormessage, ctr[TR_MISSING_PURPLE_IP]);
			goto EXIT;
		}
	}
	if (CONFIG_TYPE_RED(configtype))
	{
		strcpy(temp, "");
		findkey(kv, "RED_DEV", temp);
		if (!(strlen(temp)))
		{
			strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]);
			goto EXIT;
		}
		if (!(interfacecheck(kv, "RED")))
		{
			strcpy(errormessage, ctr[TR_MISSING_RED_IP]);
			goto EXIT;
		}
	}
	strcpy(errormessage, "");
EXIT:
	freekeyvalues(kv);
	
	if (strlen(errormessage))
		return 0;
	else
		return 1;
}
Example #8
0
/* 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;
}			
Example #9
0
/* This is a groovie dialog for showing network info.  Takes a keyvalue list,
 * a colour and a dhcp flag.  Shows the current settings, and rewrites them
 * if necessary.  DHCP flag sets wether to show the dhcp checkbox. */
int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
	char *defaultdhcphostname)
{
	char *addressresult;
	char *netmaskresult;
	char *dhcphostnameresult;
	char *dhcpforcemturesult;
	struct newtExitStruct es;
	newtComponent header;
	newtComponent addresslabel;
	newtComponent netmasklabel;
	newtComponent dhcphostnamelabel;
	newtComponent dhcpforcemtulabel;
	newtComponent ok, cancel;	
	char message[1000];
	char temp[STRING_SIZE];
	char addressfield[STRING_SIZE];
	char netmaskfield[STRING_SIZE];
	char typefield[STRING_SIZE];
	char dhcphostnamefield[STRING_SIZE];
	char dhcpforcemtufield[STRING_SIZE];
	int error;
	int result = 0;
	char type[STRING_SIZE];
	int startstatictype = 0;
	int startdhcptype = 0;
	int startpppoetype = 0;
		
	/* Build some key strings. */
	sprintf(addressfield, "%s_ADDRESS", colour);
	sprintf(netmaskfield, "%s_NETMASK", colour);
	sprintf(typefield, "%s_TYPE", colour);
	sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour);
	sprintf(dhcpforcemtufield, "%s_DHCP_FORCE_MTU", colour);
		
	sprintf(message, _("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;
}
Example #10
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;
	}
}
Example #11
0
/* This will rewrite /etc/hosts, /etc/hosts.*, and the apache ServerName file. */
int writehostsfiles(void)
{	
	char address[STRING_SIZE] = "";
	char netaddress[STRING_SIZE] = "";
	char netmask[STRING_SIZE] = "";
	char message[1000];
	FILE *file, *hosts;
	struct keyvalue *kv;
	char hostname[STRING_SIZE];
	char domainname[STRING_SIZE] = "";
	char commandstring[STRING_SIZE];
	char buffer[STRING_SIZE];
	
	kv = initkeyvalues();
	if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}
	findkey(kv, "GREEN_ADDRESS", address);
	findkey(kv, "GREEN_NETADDRESS", netaddress);
	findkey(kv, "GREEN_NETMASK", netmask);	
	freekeyvalues(kv);
	
	kv = initkeyvalues();
	if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
	{
		freekeyvalues(kv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}
	strcpy(hostname, SNAME );
	findkey(kv, "HOSTNAME", hostname);
	findkey(kv, "DOMAINNAME", domainname);
	freekeyvalues(kv);
		
	if (!(file = fopen(CONFIG_ROOT "/main/hostname.conf", "w")))
	{
		sprintf (message, ctr[TR_UNABLE_TO_WRITE_VAR_SMOOTHWALL_MAIN_HOSTNAMECONF], CONFIG_ROOT);
		errorbox(message);
		return 0;
	}
	fprintf(file, "ServerName %s.%s\n", hostname,domainname);
	fclose(file);
	
	if (!(file = fopen(CONFIG_ROOT "/main/hosts", "r")))
	{
		errorbox(ctr[TR_UNABLE_TO_OPEN_HOSTS_FILE]);
		return 0;
	}
	if (!(hosts = fopen("/etc/hosts", "w")))
	{
		errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_HOSTS]);
		return 0;
	}
	fprintf(hosts, "127.0.0.1\tlocalhost\n");
	if (strlen(domainname))
		fprintf(hosts, "%s\t%s.%s\t%s\n",address,hostname,domainname,hostname);
	else
		fprintf(hosts, "%s\t%s\n",address,hostname);
	while (fgets(buffer, STRING_SIZE, file))
	{
		char *token, *ip, *host, *domain;

		buffer[strlen(buffer) - 1] = 0;

		token = strtok(buffer, ",");

		ip = strtok(NULL, ",");
		host = strtok(NULL, ",");
		domain = strtok(NULL, ",");

		if (!(ip && host))
			break;

		if (strlen(ip) < 7 || strlen(ip) > 15
		 || strspn(ip, "0123456789.") != strlen(ip))
			break;

		if (strspn(host, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-") != strlen(host))
			break;

		if (domain)
			fprintf(hosts, "%s\t%s.%s\t%s\n",ip,host,domain,host);
		else
			fprintf(hosts, "%s\t%s\n",ip,host);
	}
	fclose(file);
	fclose(hosts);
	
	/* TCP wrappers stuff. */
	if (!(file = fopen("/etc/hosts.deny", "w")))
	{
		errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_HOSTS_DENY]);
		return 0;
	}
	fprintf(file, "ALL : ALL\n");
	fclose(file);
	
	if (!(file = fopen("/etc/hosts.allow", "w")))
	{
		errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_HOSTS_ALLOW]);
		return 0;
	}
	fprintf(file, "sshd : ALL\n");
	fprintf(file, "ALL  : localhost\n");
	fprintf(file, "ALL  : %s/%s\n", netaddress, netmask);
	fclose(file);
	
	sprintf(commandstring, "/bin/hostname %s.%s", hostname, domainname);
	if (mysystem(commandstring))
	{
		errorbox(ctr[TR_UNABLE_TO_SET_HOSTNAME]);
		return 0;
	}
	
	return 1;
}	
Example #12
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;
}
Example #13
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;
}
Example #14
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;
}
/* Driver menu.  Choose drivers.. */
int drivermenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	char message[1000];
	char temp[STRING_SIZE], temp1[STRING_SIZE];
	char driver[STRING_SIZE], dev[STRING_SIZE];
	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);

	strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]);
	
	/* This horrible bit formats the heading :( */
	strcpy(driver, "");
	findkey(kv, "GREEN_DISPLAYDRIVER", driver);
	findnicdescription(driver, temp);
	strcpy(dev, ctr[TR_UNSET]);
	findkey(kv, "GREEN_DEV", dev);
	displaynicinfowithmac(temp1, sizeof(temp1), "GREEN", dev, temp);
	strcat(message, temp1);

	if (CONFIG_TYPE_ORANGE(configtype))
	{
		strcpy(driver, ""); findkey(kv, "ORANGE_DISPLAYDRIVER", driver);
		findnicdescription(driver, temp);
		strcpy(dev, ctr[TR_UNSET]); findkey(kv, "ORANGE_DEV", dev);
		displaynicinfowithmac(temp1, sizeof(temp1), "ORANGE", dev, temp);
		strcat(message, temp1);
	}
	if (CONFIG_TYPE_PURPLE(configtype))
	{
		strcpy(driver, "");
		findkey(kv, "PURPLE_DISPLAYDRIVER", driver);
		findnicdescription(driver, temp);
		strcpy(dev, ctr[TR_UNSET]);
		findkey(kv, "PURPLE_DEV", dev);
		displaynicinfowithmac(temp1, sizeof(temp1), "PURPLE", dev, temp);
		strcat(message, temp1);
	}
	if (CONFIG_TYPE_RED(configtype))
	{
		strcpy(driver, ""); findkey(kv, "RED_DISPLAYDRIVER", driver);
		findnicdescription(driver, temp);
		strcpy(dev, ctr[TR_UNSET]); findkey(kv, "RED_DEV", dev);
		displaynicinfowithmac(temp1, sizeof(temp1), "RED", dev, temp);
		strcat(message, temp1);
	}
	strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]);
	rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK],
		ctr[TR_CANCEL], message);
	if (rc == 0 || rc == 1)
	{
		/* Shit, got to do something.. */
		changedrivers();
	}
	
	freekeyvalues(kv);

	return 1;
}
Example #16
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;
}
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;
}
Example #18
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;
}
Example #19
0
/* Small window to change IP and Netmask of some colour */
void changeaddress(char *colour, int *changed_flag)
{
    newtComponent networkform;
    newtComponent text;
    newtComponent ok, cancel;
    struct newtExitStruct exitstruct;
    char keyvalue[STRING_SIZE];
    char addresskey[STRING_SIZE];
    char netmaskkey[STRING_SIZE];
    char netaddresskey[STRING_SIZE];
    newtComponent addresslabel;
    newtComponent netmasklabel;
    newtComponent addressentry;
    newtComponent netmaskentry;
    const char *addressresult;
    const char *netmaskresult;
    char message[STRING_SIZE_LARGE];
    int error;
    int numLines;
    char *tmpstring;

    /* Build some key strings. */
    sprintf(addresskey, "%s_1_ADDRESS", colour);
    sprintf(netmaskkey, "%s_1_NETMASK", colour);
    sprintf(netaddresskey, "%s_1_NETADDRESS", colour);

    /* workaround gcc warning, there is really 1 %s there */
    tmpstring=strdup(gettext("TR_ENTER_THE_IP_ADDRESS_INFORMATION"));
    snprintf(message, STRING_SIZE, tmpstring, colour);
    free(tmpstring);
    text = newtTextboxReflowed(1, 1, message, 68, 0, 0, 0);
    numLines = newtTextboxGetNumLines(text);

    /* workaround gcc warning, there is really 1 %s there */
    tmpstring=strdup(gettext("TR_INTERFACE"));
    snprintf(message, STRING_SIZE, tmpstring, colour);
    free(tmpstring);
    newtCenteredWindow(72, 10 + numLines, message);
    networkform = newtForm(NULL, NULL, 0);
    newtFormAddComponent(networkform, text);

    /* Address */
    addresslabel = newtTextbox(2, 2 + numLines, 18, 1, 0);
    newtTextboxSetText(addresslabel, gettext("TR_IP_ADDRESS_PROMPT"));
    if (!strcmp(colour, "GREEN")) {
        /* green only for now */
        strcpy(keyvalue, DEFAULT_IP);
    }
    else {
        strcpy(keyvalue, "");
    }
    find_kv_default(eth_kv, addresskey, keyvalue);
    addressentry = newtEntry(20, 2 + numLines, keyvalue, 20, &addressresult, 0);
    newtEntrySetFilter(addressentry, filterip, NULL);
    newtFormAddComponent(networkform, addresslabel);
    newtFormAddComponent(networkform, addressentry);

    /* Netmask */
    netmasklabel = newtTextbox(2, 3 + numLines, 18, 1, 0);
    newtTextboxSetText(netmasklabel, gettext("TR_NETMASK_PROMPT"));
    strcpy(keyvalue, DEFAULT_NETMASK);
    find_kv_default(eth_kv, netmaskkey, keyvalue);
    netmaskentry = newtEntry(20, 3 + numLines, keyvalue, 20, &netmaskresult, 0);
    newtEntrySetFilter(netmaskentry, filterip, NULL);
    newtFormAddComponent(networkform, netmasklabel);
    newtFormAddComponent(networkform, netmaskentry);

    ok = newtButton(6, 5 + numLines, gettext("TR_OK"));
    /* In case of installer we need a valid address, no turning back */
    if (flag_is_state == setupchroot) {
        newtFormAddComponent(networkform, ok);
    }
    else {
        cancel = newtButton(26, 5 + numLines, gettext("TR_GO_BACK"));
        newtFormAddComponents(networkform, ok, cancel, NULL);
    }
    newtRefresh();
    newtDrawForm(networkform);

    do {
        error = 0;
        newtFormRun(networkform, &exitstruct);

        if (exitstruct.u.co == ok) {

            strcpy(message, gettext("TR_INVALID_FIELDS"));
            if (VALID_IP(addressresult) == FALSE) {
                strcat(message, gettext("TR_IP_ADDRESS_CR"));
                error = 1;
                newtFormSetCurrent(networkform, addressentry);
            }
            if (VALID_IP(netmaskresult) == FALSE) {
                strcat(message, gettext("TR_NETWORK_MASK_CR"));
                error = 1;
                newtFormSetCurrent(networkform, netmaskentry);
            }

            // TODO: additional network mask validation

            if (error) {
                errorbox(message);
            }
            else {
                /* all is well, calc netaddress and store everything */
                unsigned long int intaddress;
                unsigned long int intnetaddress;
                unsigned long int intnetmask;
                struct in_addr i_addr;
                char *netaddress;

                update_kv(&eth_kv, addresskey, (char *) addressresult);
                update_kv(&eth_kv, netmaskkey, (char *) netmaskresult);
                /* calculate netaddress */
                intaddress = inet_addr(addressresult);
                intnetmask = inet_addr(netmaskresult);
                intnetaddress = intaddress & intnetmask;
                i_addr.s_addr = intnetaddress;
                netaddress = inet_ntoa(i_addr);
                update_kv(&eth_kv, netaddresskey, (char *) netaddress);

                changed_config = 1;
                *changed_flag = 1;
            }
        }
    }
    while (error);

    newtFormDestroy(networkform);
    newtPopWindow();
}