コード例 #1
0
ファイル: isdn.c プロジェクト: ShorTie8/smoothwall
void handlemoduleparams(void)
{
	struct keyvalue *kv = initkeyvalues();
	char moduleparams[STRING_SIZE] = "";
	const char *values[] = { moduleparams, NULL };	/* pointers for the values. */
	struct newtWinEntry entries[] =
		{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
	int rc;

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

	findkey(kv, "MODULE_PARAMS", moduleparams);

	for (;;)
	{	
		rc = newtWinEntries(TITLE, ctr[TR_ENTER_ADDITIONAL_MODULE_PARAMS],
			50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);	
		
		if (rc == 1)
		{
			strcpy(moduleparams, values[0]);
			replacekeyvalue(kv, "MODULE_PARAMS", moduleparams);
			writekeyvalues(kv, CONFIG_ROOT "isdn/settings");
			break;
		}
		else
			break;
	}
	free((char * ) values[0]);

	freekeyvalues(kv);
}
コード例 #2
0
ファイル: netstuff.c プロジェクト: MEitelwein/ipfire-2.x
int get_knic(int card)		//returns "0" for zero cards or error and "1" card is found.
{
    struct keyvalue *kv = initkeyvalues();
    char temp[STRING_SIZE], searchstr[STRING_SIZE];
    int ret_value;

    if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
    {
        freekeyvalues(kv);
        errorbox(_("Unable to open settings file"));
        return 0;
    }

    sprintf(searchstr, "%s_MACADDR", ucolourcard[card]);
    strcpy(temp, "");
    findkey(kv, searchstr, temp);
    if (strlen(temp)) {
        strcpy(knics[ card ].macaddr, temp);
        strcpy(knics[ card ].colour, ucolourcard[card]);

        sprintf(searchstr, "%s_DESCRIPTION", ucolourcard[card]);
        findkey(kv, searchstr, temp);
        strcpy(knics[ card ].description, temp);

        sprintf(searchstr, "%s_DRIVER", ucolourcard[card]);
        findkey(kv, searchstr, temp);
        strcpy(knics[ card ].driver, temp);
        ret_value = 1;
    } else {
        strcpy(knics[ card ].description, _("Unset"));
        ret_value = 0;
    }
    freekeyvalues(kv);

    return ret_value;
}
コード例 #3
0
ファイル: networking.c プロジェクト: ipfire/ipfire-2.x
/* 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;
}
コード例 #5
0
ファイル: networking.c プロジェクト: ipfire/ipfire-2.x
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;
}
コード例 #6
0
ファイル: ipsecctrl.c プロジェクト: kmkoehler/ipfire-2.x
int main(int argc, char *argv[]) {
        char configtype[STRING_SIZE];
        char redtype[STRING_SIZE] = "";
        struct keyvalue *kv = NULL;
                        
        if (argc < 2) {
                usage();
                exit(1);
        }
        if (!(initsetuid()))
                exit(1);
                
 FILE *file = NULL;
                

        if (strcmp(argv[1], "I") == 0) {
                safe_system("/usr/sbin/ipsec status");
                exit(0);
        }

        if (strcmp(argv[1], "R") == 0) {
                safe_system("/usr/sbin/ipsec reload >/dev/null 2>&1");
                exit(0);
        }

        /* FIXME: workaround for pclose() issue - still no real idea why
         * this is happening */
        signal(SIGCHLD, SIG_DFL);

        /* handle operations that doesn't need start the ipsec system */
        if (argc == 2) {
                if (strcmp(argv[1], "D") == 0) {
                        safe_system("/usr/sbin/ipsec stop >/dev/null 2>&1");
                        ipsec_norules();
                        exit(0);
                }
        }

        /* read vpn config */
        kv=initkeyvalues();
        if (!readkeyvalues(kv, CONFIG_ROOT "/vpn/settings"))
        {
                fprintf(stderr, "Cannot read vpn settings\n");
                exit(1);
        }

        /* check is the vpn system is enabled */
        {
            char s[STRING_SIZE];
            findkey(kv, "ENABLED", s);
            freekeyvalues(kv);
            if (strcmp (s, "on") != 0)
                exit(0);
        }

        /* read interface settings */
        kv=initkeyvalues();
        if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))
        {
                fprintf(stderr, "Cannot read ethernet settings\n");
                exit(1);
        }
        if (!findkey(kv, "CONFIG_TYPE", configtype))
        {
                fprintf(stderr, "Cannot read CONFIG_TYPE\n");
                exit(1);
        }
        findkey(kv, "RED_TYPE", redtype);


        /* Loop through the config file to find physical interface that will accept IPSEC */
        int enable_red=0;       // states 0: not used
        int enable_green=0;     //        1: error condition
        int enable_orange=0;    //        2: good
        int enable_blue=0;
        char if_red[STRING_SIZE] = "";
        char if_green[STRING_SIZE] = "";
        char if_orange[STRING_SIZE] = "";
        char if_blue[STRING_SIZE] = "";
        char s[STRING_SIZE];

        // when RED is up, find interface name in special file
        FILE *ifacefile = NULL;
        if ((ifacefile = fopen(CONFIG_ROOT "/red/iface", "r"))) {
                if (fgets(if_red, STRING_SIZE, ifacefile)) {
                        if (if_red[strlen(if_red) - 1] == '\n')
                                if_red[strlen(if_red) - 1] = '\0';
                }
                fclose (ifacefile);

                if (VALID_DEVICE(if_red))
                        enable_red++;
        }

	// Check if GREEN is enabled.
        findkey(kv, "GREEN_DEV", if_green);
        if (VALID_DEVICE(if_green))
                enable_green++;

	// Check if ORANGE is enabled.
        findkey(kv, "ORANGE_DEV", if_orange);
        if (VALID_DEVICE(if_orange))
                enable_orange++;

	// Check if BLUE is enabled.
        findkey(kv, "BLUE_DEV", if_blue);
        if (VALID_DEVICE(if_blue))
                enable_blue++;

        freekeyvalues(kv);

        // exit if nothing to do
        if ((enable_red+enable_green+enable_orange+enable_blue) == 0)
            exit(0);

        // open needed ports
        if (enable_red > 0)
                open_physical(if_red, 4500);

        if (enable_green > 0)
                open_physical(if_green, 4500);

        if (enable_orange > 0)
                open_physical(if_orange, 4500);

        if (enable_blue > 0)
                open_physical(if_blue, 4500);

        // start the system
        if ((argc == 2) && strcmp(argv[1], "S") == 0) {
		safe_system("/usr/sbin/ipsec restart >/dev/null");
                exit(0);
        }

        // it is a selective start or stop
        // second param is only a number 'key'
        if ((argc == 2) || strspn(argv[2], NUMBERS) != strlen(argv[2])) {
                fprintf(stderr, "Bad arg: %s\n", argv[2]);
                usage();
                exit(1);
        }

        // search the vpn pointed by 'key'
        if (!(file = fopen(CONFIG_ROOT "/vpn/config", "r"))) {
                fprintf(stderr, "Couldn't open vpn settings file");
                exit(1);
        }
        while (fgets(s, STRING_SIZE, file) != NULL) {
                char *key;
                char *name;
                char *type;
                if (!decode_line(s,&key,&name,&type))
                        continue;

                // is it the 'key' requested ?
                if (strcmp(argv[2], key) != 0)
                        continue;

                // Start or Delete this Connection
                if (strcmp(argv[1], "S") == 0)
                        turn_connection_on (name, type);
                else if (strcmp(argv[1], "D") == 0)
                        turn_connection_off (name);
                else {
                        fprintf(stderr, "Bad command\n");
                        exit(1);
                }
        }
        fclose(file);

        return 0;
}
コード例 #7
0
ファイル: dhcp.c プロジェクト: MEitelwein/ipfire-2.x
int handledhcp(void)
{
	char *results[MAX_BOXES];
	char enabledresult;
	char startenabled;
	struct newtExitStruct es;
	newtComponent header;
	newtComponent labels[MAX_BOXES];
	newtComponent ok, cancel;	
	char message[1000];
	char *labeltexts[MAX_BOXES] = {
		_("Start address:"),
		_("End address:"),
		_("Primary DNS:"),
		_("Secondary DNS:"),
		_("Default lease (mins):"),
		_("Max lease (mins):"),
		_("Domain name suffix:")
	};
	char *varnames[MAX_BOXES] = {
		"START_ADDR_GREEN",
		"END_ADDR_GREEN",
		"DNS1_GREEN",
		"DNS2_GREEN",
		"DEFAULT_LEASE_TIME_GREEN",
		"MAX_LEASE_TIME_GREEN",
		"DOMAIN_NAME_GREEN"
	};
	char defaults[MAX_BOXES][STRING_SIZE]; 
	int result;
	int c;
	char temp[STRING_SIZE];
	struct keyvalue *mainkv = initkeyvalues();
	struct keyvalue *dhcpkv = initkeyvalues();
	struct keyvalue *ethernetkv = initkeyvalues();
	int error;
	FILE *file;
	char greenaddress[STRING_SIZE];	
	char greennetaddress[STRING_SIZE];
	char greennetmask[STRING_SIZE];
	
 	memset(defaults, 0, sizeof(char) * STRING_SIZE * MAX_BOXES);
	
	if (!(readkeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (!(readkeyvalues(ethernetkv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		freekeyvalues(mainkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}

	/* Set default values. */	
	findkey(ethernetkv, "GREEN_ADDRESS", defaults[PRIMARY_DNS]);
	findkey(mainkv, "DOMAINNAME", defaults[DOMAIN_NAME_SUFFIX]);
	strcpy(defaults[DEFAULT_LEASE_TIME], "60");
	strcpy(defaults[MAX_LEASE_TIME], "120");

	newtCenteredWindow(55, 18, _("DHCP server configuration"));

	dhcpform = newtForm(NULL, NULL, 0);

	header = newtTextboxReflowed(1, 1,
		_("Configure the DHCP server by entering the settings information."),
		52, 0, 0, 0);
	newtFormAddComponent(dhcpform, header);

	strcpy(temp, ""); findkey(dhcpkv, "ENABLE_GREEN", temp);
	if (strcmp(temp, "on") == 0)
		startenabled = '*';
	else
		startenabled = ' ';
	enabledcheckbox = newtCheckbox(2, TOP + 0, _("Enabled"), startenabled, " *", &enabledresult);
	newtFormAddComponent(dhcpform, enabledcheckbox);
	newtComponentAddCallback(enabledcheckbox, dhcpdialogcallbackdhcp, NULL);		

	for (c = 0; c < MAX_BOXES; c++)
	{
		labels[c] = newtTextbox(2, TOP + 2 + c, 33, 1, 0);
		newtTextboxSetText(labels[c], labeltexts[c]);
		newtFormAddComponent(dhcpform, labels[c]);				
		strcpy(temp, defaults[c]); findkey(dhcpkv, varnames[c], temp);
		entries[c] = newtEntry(34, TOP + 2 + c, temp, 18, &results[c], 0);
		newtFormAddComponent(dhcpform, entries[c]);		
		if (startenabled == ' ')
			newtEntrySetFlags(entries[c], NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);			
		
	}
	
	ok = newtButton(10, c + 7, _("OK"));
	cancel = newtButton(34, c + 7, _("Cancel"));

	newtFormAddComponents(dhcpform, ok, cancel, NULL);
	
	do {
		error = 0;
		newtFormRun(dhcpform, &es);
	
		if (es.u.co == ok)
		{
			/* OK was pressed; verify the contents of each entry. */		
			if (enabledresult == '*')
			{
				strcpy(message, _("The following fields are invalid:\n\n"));
				if (inet_addr(results[START_ADDRESS]) == INADDR_NONE)
				{
					strcat(message, _("Start address"));
					strcat(message, "\n");
					error = 1;
				}
				if (inet_addr(results[END_ADDRESS]) == INADDR_NONE)
				{
					strcat(message, _("End address"));
					strcat(message, "\n");
					error = 1;
				}
				if (strlen(results[SECONDARY_DNS]))
				{
					if (inet_addr(results[PRIMARY_DNS]) == INADDR_NONE)
					{
						strcat(message, _("Primary DNS"));
						strcat(message, "\n");
						error = 1;
					}
				}
				if (strlen(results[SECONDARY_DNS]))
				{
					if (inet_addr(results[SECONDARY_DNS]) == INADDR_NONE)
					{
						strcat(message, _("Secondary DNS"));
						strcat(message, "\n");
						error = 1;
					}
				}
				if (!(atol(results[DEFAULT_LEASE_TIME])))
				{
					strcat(message, _("Default lease time"));
					strcat(message, "\n");
					error = 1;
				}
				if (!(atol(results[MAX_LEASE_TIME])))
				{
					strcat(message, _("Max. lease time"));
					strcat(message, "\n");
					error = 1;
				}
			}				
			
			if (error)
				errorbox(message);
			else
			{
				for (c = 0; c < MAX_BOXES; c++)
					replacekeyvalue(dhcpkv, varnames[c], results[c]);
				if (enabledresult == '*')
				{
					replacekeyvalue(dhcpkv, "ENABLE_GREEN", "on");
					fclose(fopen(CONFIG_ROOT "/dhcp/enable_green", "w"));
					chown(CONFIG_ROOT "/dhcp/enable_green", 99, 99);
					mysystem(NULL, "/usr/local/bin/dhcpctrl enable");
				}
				else
				{
					replacekeyvalue(dhcpkv, "ENABLE_GREEN", "off");
					unlink(CONFIG_ROOT "/dhcp/enable_green");
					mysystem(NULL, "/usr/local/bin/dhcpctrl disable");
				}
				replacekeyvalue(dhcpkv, "VALID", "yes");
				writekeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings");
				
				findkey(ethernetkv, "GREEN_ADDRESS", greenaddress);				
				findkey(ethernetkv, "GREEN_NETADDRESS", greennetaddress);
				findkey(ethernetkv, "GREEN_NETMASK", greennetmask);
			
				file = fopen(CONFIG_ROOT "/dhcp/dhcpd.conf", "w");
				fprintf(file, "ddns-update-style none;\n");
				fprintf(file, "authoritative;\n");
				fprintf(file, "subnet %s netmask %s\n", greennetaddress, greennetmask);
				fprintf(file, "{\n");
				fprintf(file, "\toption subnet-mask %s;\n", greennetmask);
				fprintf(file, "\toption domain-name \"%s\";\n", results[DOMAIN_NAME_SUFFIX]);		
				fprintf(file, "\toption routers %s;\n", greenaddress);
				if (strlen(results[PRIMARY_DNS]))
				{
					fprintf(file, "\toption domain-name-servers ");
					fprintf(file, "%s", results[PRIMARY_DNS]);
					if (strlen(results[SECONDARY_DNS]))
						fprintf(file, ", %s", results[SECONDARY_DNS]);
					fprintf(file, ";\n");
				}
				
				fprintf(file, "\trange %s %s;\n",	results[START_ADDRESS], results[END_ADDRESS]);
				fprintf(file, "\tdefault-lease-time %d;\n", (int) atol(results[DEFAULT_LEASE_TIME]) * 60);
				fprintf(file, "\tmax-lease-time %d;\n",	(int) atol(results[MAX_LEASE_TIME]) * 60);
				fprintf(file, "}\n");
				fclose(file);
				chown(CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
				if (automode == 0)
					mysystem(NULL, "/usr/local/bin/dhcpctrl enable");
			}
			result = 1;
		}
		else
			result = 0;
	} while (error);
	
	newtFormDestroy(dhcpform);
	newtPopWindow();
	
	freekeyvalues(dhcpkv);
	freekeyvalues(ethernetkv);
	freekeyvalues(mainkv);
	
	return result;
}
/* DNS and default gateway.... */
int dnsgatewaymenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	char message[1000];
	char temp[STRING_SIZE] = "0";
	struct newtWinEntry entries[DNSGATEWAY_TOTAL+1];
	char *values[DNSGATEWAY_TOTAL];         /* pointers for the values. */
	int error;
	int configtype;
	int rc;

	if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}

	strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
	configtype = atol(temp);
	
	if (!CONFIG_TYPE_RED(configtype))
	{
		freekeyvalues(kv);
		errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]);
		return 0;
	}

	entries[DNS1].text = ctr[TR_PRIMARY_DNS];
	strcpy(temp, ""); findkey(kv, "DNS1", temp);
	values[DNS1] = strdup(temp);
	entries[DNS1].value = (const char **) &values[DNS1];
	entries[DNS1].flags = 0;
	
	entries[DNS2].text = ctr[TR_SECONDARY_DNS];
	strcpy(temp, ""); findkey(kv, "DNS2", temp);
	values[DNS2] = strdup(temp);
	entries[DNS2].value = (const char **) &values[DNS2];
	entries[DNS2].flags = 0;
	
	entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY];
	strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
	values[DEFAULT_GATEWAY] = strdup(temp);
	entries[DEFAULT_GATEWAY].value = (const char **)  &values[DEFAULT_GATEWAY];
	entries[DEFAULT_GATEWAY].flags = 0;
	
	entries[DNSGATEWAY_TOTAL].text = NULL;
	entries[DNSGATEWAY_TOTAL].value = NULL;
	entries[DNSGATEWAY_TOTAL].flags = 0;
	
	do
	{
		error = 0;
		
		rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS], 
			ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries,
			ctr[TR_OK], ctr[TR_CANCEL], NULL);
		if (rc == 0 || rc == 1)
		{
			strcpy(message, ctr[TR_INVALID_FIELDS]);
			if (strlen(values[DNS1]))
			{
				if (inet_addr(values[DNS1]) == INADDR_NONE)
				{
					strcat(message, ctr[TR_PRIMARY_DNS_CR]);
					error = 1;
				}
			}
			if (strlen(values[DNS2]))
			{
				if (inet_addr(values[DNS2]) == INADDR_NONE)
				{
					strcat(message, ctr[TR_SECONDARY_DNS_CR]);
					error = 1;
				}
			}
			if (strlen(values[DEFAULT_GATEWAY]))
			{
				if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE)
				{
					strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]);
					error = 1;
				}
			}
			if (!strlen(values[DNS1]) && strlen(values[DNS2]))
			{
				strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]);
				error = 1;
			}

			if (error)
				errorbox(message);
			else
			{
				replacekeyvalue(kv, "DNS1", values[DNS1]);
				replacekeyvalue(kv, "DNS2", values[DNS2]);
				replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]);
				netaddresschange = 1;
				free((char *) values[DNS1]);
				free((char *) values[DNS2]);
				free((char *) values[DEFAULT_GATEWAY]);
				writekeyvalues(kv, CONFIG_ROOT "ethernet/settings");
			}
		}
	}
	while (error);
	
	freekeyvalues(kv);
	
	return 1;
}			
コード例 #9
0
ファイル: networking.c プロジェクト: ipfire/ipfire-2.x
/* 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;
}			
コード例 #10
0
ファイル: networking.c プロジェクト: ipfire/ipfire-2.x
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;
}
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;
}
コード例 #12
0
ファイル: misc.c プロジェクト: alfh/ipfire-2.x
/* 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;
}	
コード例 #13
0
ファイル: defaults.c プロジェクト: d4t4king/off-the-wall
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;
}
コード例 #14
0
ファイル: isdn.c プロジェクト: ShorTie8/smoothwall
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;
}
コード例 #15
0
ファイル: isdn.c プロジェクト: ShorTie8/smoothwall
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);
}
/* 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;
}
コード例 #17
0
ファイル: networking.c プロジェクト: ipfire/ipfire-2.x
/* Driver menu.  Choose drivers.. */
int drivermenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	char message[STRING_SIZE];
	char temp[STRING_SIZE] = "1";

	int configtype;
	int i, rc, kcount = 0, neednics;

	if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}

	if (findkey(kv, "CONFIG_TYPE", temp))
		configtype = atol(temp);
	else {
		fprintf(flog,"setting CONFIG_TYPE = %s\n",temp);
		configtype = atol(temp);
		replacekeyvalue(kv, "CONFIG_TYPE", temp);
		writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
	}

	strcpy(message, _("Configure network drivers, and which interface each card is assigned to. "
		"The current configuration is as follows:\n\n"));

	kcount = 0;
	neednics = 0;
	if (HAS_GREEN) {
		sprintf(temp, "%-6s: %s\n", "GREEN", knics[_GREEN_CARD_].description);
		strcat(message, temp);
		if (strlen(knics[_GREEN_CARD_].macaddr) ) {
			sprintf(temp, "%-6s: (%s)\n", "GREEN", knics[_GREEN_CARD_].macaddr);
			strcat(message, temp);
		}
		neednics++;
	}
	if (HAS_RED) {
		sprintf(temp, "%-6s: %s\n", "RED", knics[_RED_CARD_].description);
		strcat(message, temp);
		if (strlen(knics[_RED_CARD_].macaddr) ) {
			sprintf(temp, "%-6s: (%s)\n", "RED", knics[_RED_CARD_].macaddr);
			strcat(message, temp);
		}
		neednics++;
	}
	if (HAS_ORANGE) {
		sprintf(temp, "%-6s: %s\n", "ORANGE", knics[_ORANGE_CARD_].description);
		strcat(message, temp);
		if ( strlen(knics[_ORANGE_CARD_].macaddr) ) {
			sprintf(temp, "%-6s: (%s)\n", "ORANGE", knics[_ORANGE_CARD_].macaddr);
			strcat(message, temp);
		}
		neednics++;
	}
	if (HAS_BLUE) {
		sprintf(temp, "%-6s: %s\n", "BLUE", knics[_BLUE_CARD_].description);
		strcat(message, temp);
		if (strlen(knics[_BLUE_CARD_].macaddr)) {
			sprintf(temp, "%-6s: (%s)\n", "BLUE", knics[_BLUE_CARD_].macaddr);
			strcat(message, temp);
		}
		neednics++;
	}

	for ( i=0 ; i<4; i++)
		if (strcmp(knics[i].macaddr, ""))
			kcount++;

	if (neednics = kcount)
	{
		strcat(message, "\n");
		strcat(message, _("Do you wish to change these settings?"));
		rc = newtWinChoice(_("Drivers and card assignments"), _("OK"),
			_("Cancel"), message);
		if (rc == 0 || rc == 1)
		{
			changedrivers();
		}
	} else {
		changedrivers();
	}
	freekeyvalues(kv);

	return 1;
}
int 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;
}
コード例 #19
0
ファイル: networking.c プロジェクト: ipfire/ipfire-2.x
// They can change BLUE, ORANGE and GREEN too :)
int addressesmenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	struct keyvalue *mainkv = initkeyvalues();
	int rc = 0;
	char *sections[5];
	char *green = "GREEN";
	char *orange = "ORANGE";
	char *blue = "BLUE";
	char *red = "RED";
	int c = 0;
	char greenaddress[STRING_SIZE];
	char oldgreenaddress[STRING_SIZE];
	char temp[STRING_SIZE];
	char temp2[STRING_SIZE];
	char message[1000];
	int configtype;
	int done;
	int choice;
	char hostname[STRING_SIZE];
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(kv);
		freekeyvalues(mainkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
	{
		freekeyvalues(kv);
		freekeyvalues(mainkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}

	strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
	configtype = atol(temp);
	
	sections[c] = green;
	c++;
	if (HAS_BLUE)
	{
		sections[c] = blue;
		c++;
	}
	if (HAS_ORANGE)
	{
		sections[c] = orange;
		c++;
	}
	if (HAS_RED)
	{
		sections[c] = red;
		c++;
	}
	sections[c] = NULL;

	choice = 0;	
	done = 0;	
	while (!done)
	{
		rc = newtWinMenu(_("Address settings"),
			_("Select the interface you wish to reconfigure."), 50, 5,
			5, 6, sections, &choice, _("OK"), _("Done"), NULL);	

		if (rc == 0 || rc == 1)
		{
			if (strcmp(sections[choice], "GREEN") == 0)
			{
				findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
				sprintf(message, _("If you change this IP address, and you are logged in remotely, "
					"your connection to the %s machine will be broken, and you will have to reconnect "
					"on the new IP. This is a risky operation, and should only be attempted if you "
					"have physical access to the machine, should something go wrong."), NAME);
				rc = newtWinChoice(_("Warning"), _("OK"), _("Cancel"), message);
				if (rc == 0 || rc == 1)
				{
					if (changeaddress(kv, "GREEN", 0, ""))
					{
						netaddresschange = 1;
						writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
						writehostsfiles();
						findkey(kv, "GREEN_ADDRESS", greenaddress);
						snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress);
						snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress);
						replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2);
						chown  (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
					}
				}
			}
			if (strcmp(sections[choice], "BLUE") == 0)
			{
				if (changeaddress(kv, "BLUE", 0, ""))
					netaddresschange = 1;
			}
			if (strcmp(sections[choice], "ORANGE") == 0)
			{
				if (changeaddress(kv, "ORANGE", 0, ""))
					netaddresschange = 1;
			}
			if (strcmp(sections[choice], "RED") == 0)
			{
				strcpy(hostname, "");
				findkey(mainkv, "HOSTNAME", hostname);
				if (changeaddress(kv, "RED", 1, hostname))
					netaddresschange = 1;
			}
		}
		else
			done = 1;
	}
	
	writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
	freekeyvalues(kv);
	freekeyvalues(mainkv);
	
	return 0;
}
/* They can change ORANGE and GREEN too :) */
int addressesmenu(void)
{
	struct keyvalue *kv = initkeyvalues();
	struct keyvalue *mainkv = initkeyvalues();
	int rc = 0;
	char *sections[6];
	char *green = "GREEN";
	char *orange = "ORANGE";
	char *purple = "PURPLE";
	char *red = "RED";
	int c = 0;
	char temp[STRING_SIZE];
	int configtype;
	int done;
	int choice;
	char hostname[STRING_SIZE];
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings")))
	{
		freekeyvalues(kv);
		freekeyvalues(mainkv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}
	if (!(readkeyvalues(mainkv, CONFIG_ROOT "main/settings")))
	{
		freekeyvalues(kv);
		freekeyvalues(mainkv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}

	strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
	configtype = atol(temp);
	
	sections[c] = green;
	c++;
	if (CONFIG_TYPE_ORANGE(configtype))
	{
		sections[c] = orange;
		c++;
	}
	if (CONFIG_TYPE_PURPLE(configtype))
	{
		sections[c] = purple;
		c++;
	}
	if (CONFIG_TYPE_RED(configtype))
	{
		sections[c] = red;
		c++;
	}
	sections[c] = NULL;

	choice = 0;	
	done = 0;	
	while (!done)
	{
		rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS],
			ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5,
			5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);	

		if (rc == 0 || rc == 1)
		{
			if (strcmp(sections[choice], "GREEN") == 0)
			{
				rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL],
					ctr[TR_WARNING_LONG]);
				if (rc == 0 || rc == 1)
				{
					if (changeaddress(kv, "GREEN", 0, ""))
					{
						netaddresschange = 1;
						writekeyvalues(kv, CONFIG_ROOT "ethernet/settings");			
						writehostsfiles();			
					}
				}
			}
			if (strcmp(sections[choice], "ORANGE") == 0)
			{
				if (changeaddress(kv, "ORANGE", 0, ""))
					netaddresschange = 1;
			}
			if (strcmp(sections[choice], "PURPLE") == 0)
			{
				if (changeaddress(kv, "PURPLE", 0, ""))
					netaddresschange = 1;
			}
			if (strcmp(sections[choice], "RED") == 0)
			{
				strcpy(hostname, "");
				findkey(mainkv, "HOSTNAME", hostname);
				if (changeaddress(kv, "RED", 1, hostname))
					netaddresschange = 1;
			}
		}
		else
			done = 1;
	}
	
	writekeyvalues(kv, CONFIG_ROOT "ethernet/settings");
	freekeyvalues(kv);
	freekeyvalues(mainkv);
	
	return 0;
}
コード例 #21
0
ファイル: nic.c プロジェクト: ShorTie8/smoothwall
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;
}
コード例 #22
0
ファイル: setaliases.c プロジェクト: AnimaI/ipfire-2.x
void exithandler(void)
{
	if (kv) freekeyvalues(kv);
	if (file) fclose(file);
}