mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-27 03:07:43 +02:00
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
This commit is contained in:
13
src/install+setup/setup/CVS/Entries
Normal file
13
src/install+setup/setup/CVS/Entries
Normal file
@@ -0,0 +1,13 @@
|
||||
/Makefile/1.3/Thu Dec 11 11:25:54 2003//TIPCOP_v1_4_0
|
||||
/dhcp.c/1.9.2.3/Fri Dec 3 06:46:50 2004//TIPCOP_v1_4_0
|
||||
/domainname.c/1.7.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
|
||||
/hostname.c/1.6.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
|
||||
/isdn.c/1.6.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
|
||||
/keymap.c/1.9.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
|
||||
/main.c/1.4.2.7/Thu Dec 1 20:13:08 2005//TIPCOP_v1_4_0
|
||||
/misc.c/1.5.2.3/Thu Aug 25 17:51:42 2005//TIPCOP_v1_4_0
|
||||
/networking.c/1.5.2.6/Mon Feb 6 22:00:13 2006//TIPCOP_v1_4_0
|
||||
/passwords.c/1.5.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
|
||||
/setup.h/1.4/Thu Dec 11 11:25:54 2003//TIPCOP_v1_4_0
|
||||
/timezone.c/1.4.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
|
||||
D
|
||||
1
src/install+setup/setup/CVS/Repository
Normal file
1
src/install+setup/setup/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
ipcop/src/install+setup/setup
|
||||
1
src/install+setup/setup/CVS/Root
Normal file
1
src/install+setup/setup/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ipcop
|
||||
1
src/install+setup/setup/CVS/Tag
Normal file
1
src/install+setup/setup/CVS/Tag
Normal file
@@ -0,0 +1 @@
|
||||
TIPCOP_v1_4_0
|
||||
33
src/install+setup/setup/Makefile
Normal file
33
src/install+setup/setup/Makefile
Normal file
@@ -0,0 +1,33 @@
|
||||
#
|
||||
# $Id: Makefile,v 1.3 2003/12/11 11:25:54 riddles Exp $
|
||||
#
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -O2 -Wall
|
||||
INCLUDE =
|
||||
|
||||
LD = gcc
|
||||
LDFLAGS =
|
||||
LIBS = -lnewt -lslang
|
||||
|
||||
COMPILE = $(CC) -c $(INCLUDE) $(CFLAGS)
|
||||
|
||||
LINK = $(LD) $(LDFLAGS)
|
||||
|
||||
all : programs
|
||||
|
||||
programs : setup
|
||||
|
||||
clean :
|
||||
-rm -f *.o setup core
|
||||
|
||||
######
|
||||
|
||||
OBJS=main.o hostname.o domainname.o passwords.o isdn.o networking.o misc.o \
|
||||
dhcp.o keymap.o timezone.o ../libsmooth/libsmooth.o
|
||||
|
||||
setup: $(OBJS)
|
||||
$(LINK) $(OBJS) -o $@ $(LIBS)
|
||||
|
||||
%.o : %.c
|
||||
$(COMPILE) $< -o $@
|
||||
262
src/install+setup/setup/dhcp.c
Normal file
262
src/install+setup/setup/dhcp.c
Normal file
@@ -0,0 +1,262 @@
|
||||
/* SmoothWall setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Stuff for setting up the DHCP server from the setup prog.
|
||||
*
|
||||
* $Id: dhcp.c,v 1.9.2.3 2004/12/03 06:46:50 eoberlander Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#define TOP 4
|
||||
|
||||
#define START_ADDRESS 0
|
||||
#define END_ADDRESS 1
|
||||
#define PRIMARY_DNS 2
|
||||
#define SECONDARY_DNS 3
|
||||
#define DEFAULT_LEASE_TIME 4
|
||||
#define MAX_LEASE_TIME 5
|
||||
#define DOMAIN_NAME_SUFFIX 6
|
||||
#define MAX_BOXES 7
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
extern int automode;
|
||||
|
||||
newtComponent dhcpform;
|
||||
newtComponent entries[MAX_BOXES];
|
||||
newtComponent enabledcheckbox;
|
||||
|
||||
void dhcpdialogcallbackdhcp(newtComponent cm, void *data);
|
||||
|
||||
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] = { ctr[TR_START_ADDRESS], ctr[TR_END_ADDRESS],
|
||||
ctr[TR_PRIMARY_DNS], ctr[TR_SECONDARY_DNS], ctr[TR_DEFAULT_LEASE],
|
||||
ctr[TR_MAX_LEASE], ctr[TR_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(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return 0;
|
||||
}
|
||||
if (!(readkeyvalues(ethernetkv, CONFIG_ROOT "/ethernet/settings")))
|
||||
{
|
||||
freekeyvalues(dhcpkv);
|
||||
freekeyvalues(ethernetkv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return 0;
|
||||
}
|
||||
if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
|
||||
{
|
||||
freekeyvalues(dhcpkv);
|
||||
freekeyvalues(ethernetkv);
|
||||
freekeyvalues(mainkv);
|
||||
errorbox(ctr[TR_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");
|
||||
|
||||
sprintf(message, ctr[TR_DHCP_SERVER_CONFIGURATION]);
|
||||
newtCenteredWindow(55, 18, message);
|
||||
|
||||
dhcpform = newtForm(NULL, NULL, 0);
|
||||
|
||||
sprintf(message, ctr[TR_CONFIGURE_DHCP]);
|
||||
header = newtTextboxReflowed(1, 1, message, 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, ctr[TR_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, ctr[TR_OK]);
|
||||
cancel = newtButton(34, c + 7, ctr[TR_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, ctr[TR_INVALID_FIELDS]);
|
||||
if (inet_addr(results[START_ADDRESS]) == INADDR_NONE)
|
||||
{
|
||||
strcat(message, ctr[TR_START_ADDRESS_CR]);
|
||||
error = 1;
|
||||
}
|
||||
if (inet_addr(results[END_ADDRESS]) == INADDR_NONE)
|
||||
{
|
||||
strcat(message, ctr[TR_END_ADDRESS_CR]);
|
||||
error = 1;
|
||||
}
|
||||
if (strlen(results[SECONDARY_DNS]))
|
||||
{
|
||||
if (inet_addr(results[PRIMARY_DNS]) == INADDR_NONE)
|
||||
{
|
||||
strcat(message, ctr[TR_PRIMARY_DNS_CR]);
|
||||
error = 1;
|
||||
}
|
||||
}
|
||||
if (strlen(results[SECONDARY_DNS]))
|
||||
{
|
||||
if (inet_addr(results[SECONDARY_DNS]) == INADDR_NONE)
|
||||
{
|
||||
strcat(message, ctr[TR_SECONDARY_DNS_CR]);
|
||||
error = 1;
|
||||
}
|
||||
}
|
||||
if (!(atol(results[DEFAULT_LEASE_TIME])))
|
||||
{
|
||||
strcat(message, ctr[TR_DEFAULT_LEASE_CR]);
|
||||
error = 1;
|
||||
}
|
||||
if (!(atol(results[MAX_LEASE_TIME])))
|
||||
{
|
||||
strcat(message, ctr[TR_MAX_LEASE_CR]);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
replacekeyvalue(dhcpkv, "ENABLE_GREEN", "off");
|
||||
unlink(CONFIG_ROOT "/dhcp/enable_green");
|
||||
}
|
||||
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, "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("/usr/local/bin/restartdhcp");
|
||||
}
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
result = 0;
|
||||
}
|
||||
while (error);
|
||||
|
||||
newtFormDestroy(dhcpform);
|
||||
newtPopWindow();
|
||||
|
||||
freekeyvalues(dhcpkv);
|
||||
freekeyvalues(ethernetkv);
|
||||
freekeyvalues(mainkv);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Called when enabled flag is toggled. Toggle disabled state of other 3
|
||||
* controls. */
|
||||
void dhcpdialogcallbackdhcp(newtComponent cm, void *data)
|
||||
{
|
||||
int c;
|
||||
|
||||
for (c = 0; c < MAX_BOXES; c++)
|
||||
newtEntrySetFlags(entries[c], NEWT_FLAG_DISABLED, NEWT_FLAGS_TOGGLE);
|
||||
|
||||
newtRefresh();
|
||||
newtDrawForm(dhcpform);
|
||||
}
|
||||
72
src/install+setup/setup/domainname.c
Normal file
72
src/install+setup/setup/domainname.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/* IPCop setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* $Id: domainname.c
|
||||
*
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
extern int automode;
|
||||
|
||||
int handledomainname(void)
|
||||
{
|
||||
char domainname[STRING_SIZE] = "localdomain";
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
char *values[] = { domainname, NULL }; /* pointers for the values. */
|
||||
struct newtWinEntry entries[] =
|
||||
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
|
||||
int rc;
|
||||
int result;
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
findkey(kv, "DOMAINNAME", domainname);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
rc = newtWinEntries(ctr[TR_DOMAINNAME], ctr[TR_ENTER_DOMAINNAME],
|
||||
50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
if (rc == 1)
|
||||
{
|
||||
strcpy(domainname, values[0]);
|
||||
if (!(strlen(domainname)))
|
||||
errorbox(ctr[TR_DOMAINNAME_CANNOT_BE_EMPTY]);
|
||||
else if (strchr(domainname, ' '))
|
||||
errorbox(ctr[TR_DOMAINNAME_CANNOT_CONTAIN_SPACES]);
|
||||
else if (strlen(domainname) != strspn(domainname,
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-."))
|
||||
errorbox(ctr[TR_DOMAINNAME_NOT_VALID_CHARS]);
|
||||
else
|
||||
{
|
||||
replacekeyvalue(kv, "DOMAINNAME", domainname);
|
||||
writekeyvalues(kv, CONFIG_ROOT "/main/settings");
|
||||
writehostsfiles();
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(values[0]);
|
||||
freekeyvalues(kv);
|
||||
|
||||
return result;
|
||||
}
|
||||
76
src/install+setup/setup/hostname.c
Normal file
76
src/install+setup/setup/hostname.c
Normal file
@@ -0,0 +1,76 @@
|
||||
/* SmoothWall setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Stuff for setting the hostname.
|
||||
*
|
||||
* $Id: hostname.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
extern int automode;
|
||||
|
||||
int handlehostname(void)
|
||||
{
|
||||
char hostname[STRING_SIZE] = "";
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
char *values[] = { hostname, NULL }; /* pointers for the values. */
|
||||
struct newtWinEntry entries[] =
|
||||
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
|
||||
int rc;
|
||||
int result;
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(hostname, SNAME);
|
||||
findkey(kv, "HOSTNAME", hostname);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
rc = newtWinEntries(ctr[TR_HOSTNAME], ctr[TR_ENTER_HOSTNAME],
|
||||
50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
if (rc == 1)
|
||||
{
|
||||
strcpy(hostname, values[0]);
|
||||
if (!(strlen(hostname)))
|
||||
errorbox(ctr[TR_HOSTNAME_CANNOT_BE_EMPTY]);
|
||||
else if (strchr(hostname, ' '))
|
||||
errorbox(ctr[TR_HOSTNAME_CANNOT_CONTAIN_SPACES]);
|
||||
else if (strlen(hostname) != strspn(hostname,
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"))
|
||||
errorbox(ctr[TR_HOSTNAME_NOT_VALID_CHARS]);
|
||||
else
|
||||
{
|
||||
replacekeyvalue(kv, "HOSTNAME", hostname);
|
||||
writekeyvalues(kv, CONFIG_ROOT "/main/settings");
|
||||
writehostsfiles();
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(values[0]);
|
||||
freekeyvalues(kv);
|
||||
|
||||
return result;
|
||||
}
|
||||
581
src/install+setup/setup/isdn.c
Normal file
581
src/install+setup/setup/isdn.c
Normal file
@@ -0,0 +1,581 @@
|
||||
/* SmoothWall setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* ISDN probing.
|
||||
*
|
||||
* $Id: isdn.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
extern int automode;
|
||||
|
||||
struct card
|
||||
{
|
||||
char *name;
|
||||
int type;
|
||||
};
|
||||
|
||||
struct card cards[] = {
|
||||
{ "", 0 },
|
||||
{ "Teles 16.0", 1 },
|
||||
{ "Teles 8.0", 2 },
|
||||
{ "Teles 16.3 (non PnP)", 3 },
|
||||
{ "Teles 16.3c", 14 },
|
||||
{ "Teles PCI", 21 },
|
||||
{ "Creatix/Teles PnP", 4 },
|
||||
{ "AVM A1 (Fritz)", 5 },
|
||||
{ "AVM ISA/PCI", 27 },
|
||||
{ "AVM PCI/PNP (EXPERIMENTAL driver)", 999 },
|
||||
{ "ELSA PCC/PCF cards", 6 },
|
||||
{ "ELSA Quickstep 1000", 7 },
|
||||
{ "ELSA Quickstep 1000PCI", 18 },
|
||||
{ "Eicon Diva ISA Pnp and PCI", 11 },
|
||||
{ "ASUS COM ISDNLink", 12 },
|
||||
{ "HFC-2BS0 based cards", 13 },
|
||||
{ "HFC 2BDS0 PCI", 35 },
|
||||
{ "Sedlbauer cards", 15 },
|
||||
{ "USR Sportster internal", 16 },
|
||||
{ "MIC Card", 17 },
|
||||
{ "Compaq ISDN S00 ISA", 19 },
|
||||
{ "NETjet PCI card", 20 },
|
||||
{ "Dr. Neuhauss Niccy ISA/PCI", 24 },
|
||||
{ "Teles S0Box", 25 },
|
||||
{ "Sedlbauer Speed Fax+", 28 },
|
||||
{ "Siemens I-Surf 1.0", 29 },
|
||||
{ "ACER P10", 30 },
|
||||
{ "HST Saphir", 31 },
|
||||
{ "Telekom A4T", 32 },
|
||||
{ "Scitel Quadro", 33 },
|
||||
{ "Gazel ISA/PCI", 34 },
|
||||
{ "W6692 based PCI cards", 36 },
|
||||
{ "ITK ix1-micro Rev.2", 9 },
|
||||
{ "NETspider U PCI card", 38 },
|
||||
{ "USB ST5481", 998 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
void handleisdnprotocol(char **protocolnames);
|
||||
int isdnenabledpressed(void);
|
||||
int isdndisabledpressed(void);
|
||||
void handleisdncard(void);
|
||||
void handlemoduleparams(void);
|
||||
int probeisdncard(void);
|
||||
int probeusbisdncard(char *s);
|
||||
void handleisdnmsn(void);
|
||||
|
||||
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 };
|
||||
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;
|
||||
}
|
||||
|
||||
/* rc.isdn is a small script to bring down ippp0 and kill ipppd
|
||||
* and removes the ISDN modules. */
|
||||
mysystem("/etc/rc.d/rc.isdn stop");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* Returns 0 if main ISDN setup loop should exit. */
|
||||
int isdndisabledpressed(void)
|
||||
{
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
replacekeyvalue(kv, "ENABLED", "off");
|
||||
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
|
||||
|
||||
freekeyvalues(kv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Returns 0 if main ISDN setup loop should exit. */
|
||||
int isdnenabledpressed(void)
|
||||
{
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
char protocol[STRING_SIZE] = "";
|
||||
char type[STRING_SIZE] = "";
|
||||
char msn[STRING_SIZE] = "";
|
||||
char moduleparams[STRING_SIZE] = "";
|
||||
char commandstring[STRING_SIZE];
|
||||
int result = 0;
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
findkey(kv, "PROTOCOL", protocol);
|
||||
findkey(kv, "TYPE", type);
|
||||
findkey(kv, "MSN", msn);
|
||||
findkey(kv, "MODULE_PARAMS", moduleparams);
|
||||
|
||||
if (strlen(protocol) && strlen(type) && strlen(msn))
|
||||
{
|
||||
if (atol(type) == 998)
|
||||
{
|
||||
sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=%s %s",
|
||||
protocol, moduleparams);
|
||||
}
|
||||
else if (atol(type) == 999)
|
||||
{
|
||||
sprintf(commandstring, "/sbin/modprobe hisax_fcpcipnp protocol=%s %s",
|
||||
protocol, moduleparams);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(commandstring, "/sbin/modprobe hisax protocol=%s type=%s %s",
|
||||
protocol, type, moduleparams);
|
||||
}
|
||||
if (runcommandwithstatus(commandstring, ctr[TR_INITIALISING_ISDN]) != 0)
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_INITIALISE_ISDN]);
|
||||
replacekeyvalue(kv, "ENABLED", "off");
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
replacekeyvalue(kv, "ENABLED", "on");
|
||||
}
|
||||
else
|
||||
{
|
||||
errorbox(ctr[TR_ISDN_NOT_SETUP]);
|
||||
replacekeyvalue(kv, "ENABLED", "off");
|
||||
result = 1;
|
||||
}
|
||||
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
|
||||
|
||||
freekeyvalues(kv);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void handleisdnprotocol(char **protocolnames)
|
||||
{
|
||||
int rc;
|
||||
int choice;
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
char temp[STRING_SIZE] = "1";
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return;
|
||||
}
|
||||
findkey(kv, "PROTOCOL", temp);
|
||||
choice = atol(temp) - 1;
|
||||
|
||||
rc = newtWinMenu(ctr[TR_ISDN_PROTOCOL_SELECTION], ctr[TR_CHOOSE_THE_ISDN_PROTOCOL],
|
||||
50, 5, 5, 6, protocolnames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
if (rc == 2)
|
||||
return;
|
||||
|
||||
sprintf(temp, "%d", choice + 1);
|
||||
replacekeyvalue(kv, "PROTOCOL", temp);
|
||||
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
|
||||
freekeyvalues(kv);
|
||||
}
|
||||
|
||||
void handlemoduleparams(void)
|
||||
{
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
char moduleparams[STRING_SIZE] = "";
|
||||
char *values[] = { moduleparams, NULL }; /* pointers for the values. */
|
||||
struct newtWinEntry entries[] =
|
||||
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
|
||||
char title[STRING_SIZE];
|
||||
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 (;;)
|
||||
{
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
rc = newtWinEntries(title, ctr[TR_ENTER_ADDITIONAL_MODULE_PARAMS],
|
||||
50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
if (rc == 1)
|
||||
{
|
||||
replacekeyvalue(kv, "MODULE_PARAMS", values[0]);
|
||||
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
|
||||
free(values[0]);
|
||||
break;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
freekeyvalues(kv);
|
||||
}
|
||||
|
||||
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 == 998)
|
||||
{
|
||||
sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=1 %s",
|
||||
moduleparams);
|
||||
}
|
||||
else if (cards[choice].type == 999)
|
||||
{
|
||||
sprintf(commandstring, "/sbin/modprobe hisax_fcpcipnp 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/rc.d/rc.isdn stop");
|
||||
}
|
||||
|
||||
if (card != -1)
|
||||
{
|
||||
sprintf(temp, "%d", card);
|
||||
replacekeyvalue(kv, "TYPE", temp);
|
||||
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(selection);
|
||||
freekeyvalues(kv);
|
||||
}
|
||||
|
||||
int probeusbisdncard(char *s)
|
||||
{
|
||||
FILE *file;
|
||||
char buf[STRING_SIZE];
|
||||
int found = 0;
|
||||
|
||||
if (!(file = fopen("/proc/bus/usb/devices", "r")))
|
||||
{
|
||||
fprintf(flog, "Unable to open /proc/bus/usb/devices in probeusbisdncard()\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (fgets(buf, STRING_SIZE, file)) {
|
||||
if (strstr(buf, s)) {
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
int probeisdncard(void)
|
||||
{
|
||||
int c;
|
||||
char message[STRING_SIZE];
|
||||
char commandstring[STRING_SIZE];
|
||||
char moduleparams[STRING_SIZE] = "";
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
char title[STRING_SIZE];
|
||||
int result = -1;
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return -1;
|
||||
}
|
||||
findkey(kv, "MODULE_PARAMS", moduleparams);
|
||||
|
||||
c = 1;
|
||||
while (cards[c].name)
|
||||
{
|
||||
sprintf(message, ctr[TR_CHECKING_FOR], cards[c].name);
|
||||
if (cards[c].type == 998)
|
||||
{
|
||||
/* Try to find if it exists, but should generalize
|
||||
* probeusbisdncard to pass Vendor and ProdID
|
||||
* independently, rather than a string
|
||||
*/
|
||||
if (probeusbisdncard("Vendor=0483 ProdID=481"))
|
||||
sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=1 %s", moduleparams);
|
||||
}
|
||||
else if (cards[c].type == 999)
|
||||
{
|
||||
sprintf(commandstring, "/sbin/modprobe hisax_fcpcipnp protocol=1 %s",
|
||||
moduleparams);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(commandstring, "/sbin/modprobe hisax type=%d protocol=1 %s",
|
||||
cards[c].type, moduleparams);
|
||||
}
|
||||
if (runcommandwithstatus(commandstring, message) == 0)
|
||||
{
|
||||
mysystem("/etc/rc.d/rc.isdn stop");
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
sprintf(message, ctr[TR_DETECTED], cards[c].name);
|
||||
newtWinMessage(title, ctr[TR_OK], message);
|
||||
result = cards[c].type;
|
||||
goto EXIT;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
|
||||
errorbox(ctr[TR_UNABLE_TO_FIND_AN_ISDN_CARD]);
|
||||
|
||||
EXIT:
|
||||
freekeyvalues(kv);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void handleisdnmsn(void)
|
||||
{
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
char msn[STRING_SIZE] = "";
|
||||
char *values[] = { msn, NULL }; /* pointers for the values. */
|
||||
struct newtWinEntry entries[] =
|
||||
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
|
||||
char title[STRING_SIZE];
|
||||
int rc;
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return;
|
||||
}
|
||||
findkey(kv, "MSN", msn);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
rc = newtWinEntries(title, ctr[TR_ENTER_THE_LOCAL_MSN],
|
||||
50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
if (rc == 1)
|
||||
{
|
||||
if (!(strlen(values[0])))
|
||||
errorbox(ctr[TR_PHONENUMBER_CANNOT_BE_EMPTY]);
|
||||
else
|
||||
{
|
||||
replacekeyvalue(kv, "MSN", values[0]);
|
||||
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
|
||||
free(values[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
freekeyvalues(kv);
|
||||
}
|
||||
167
src/install+setup/setup/keymap.c
Normal file
167
src/install+setup/setup/keymap.c
Normal file
@@ -0,0 +1,167 @@
|
||||
/* SmoothWall setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Stuff for setting the keymap.
|
||||
*
|
||||
* $Id: keymap.c,v 1.9.2.1 2004/04/14 22:05:41 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
extern int automode;
|
||||
|
||||
#define MAX_FILENAMES 5000
|
||||
#define KEYMAPROOT "/usr/share/kbd/keymaps/i386/"
|
||||
|
||||
static int filenamecount;
|
||||
static char *filenames[MAX_FILENAMES];
|
||||
static char *displaynames[MAX_FILENAMES];
|
||||
|
||||
static int process(char *prefix, char *path);
|
||||
static int cmp(const void *s1, const void *s2);
|
||||
|
||||
int handlekeymap(void)
|
||||
{
|
||||
int c;
|
||||
int choice;
|
||||
char *temp;
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
int rc;
|
||||
int result;
|
||||
char keymap[STRING_SIZE];
|
||||
char commandstring[STRING_SIZE];
|
||||
|
||||
filenamecount = 0;
|
||||
|
||||
process(KEYMAPROOT "azerty", "");
|
||||
process(KEYMAPROOT "dvorak", "");
|
||||
process(KEYMAPROOT "fgGIod", "");
|
||||
process(KEYMAPROOT "qwerty", "");
|
||||
process(KEYMAPROOT "qwertz", "");
|
||||
filenames[filenamecount] = NULL;
|
||||
qsort(filenames, filenamecount, sizeof(char *), cmp);
|
||||
|
||||
for (c = 0; filenames[c]; c++)
|
||||
{
|
||||
displaynames[c] = malloc(STRING_SIZE);
|
||||
if ((temp = strrchr(filenames[c], '/')))
|
||||
strcpy(displaynames[c], temp + 1);
|
||||
else
|
||||
strcpy(displaynames[c], filenames[c]);
|
||||
if ((temp = strstr(displaynames[c], ".map.gz")))
|
||||
*temp = '\0';
|
||||
}
|
||||
displaynames[c] = NULL;
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(keymap, "/usr/share/kbd/keymaps/i386/qwerty/us.map.gz");
|
||||
findkey(kv, "KEYMAP", keymap);
|
||||
|
||||
choice = 0;
|
||||
for (c = 0; filenames[c]; c++)
|
||||
{
|
||||
if (strcmp(keymap, filenames[c]) == 0)
|
||||
choice = c;
|
||||
}
|
||||
|
||||
rc = newtWinMenu(ctr[TR_KEYBOARD_MAPPING], ctr[TR_KEYBOARD_MAPPING_LONG], 50, 5, 5, 6, displaynames, &choice,
|
||||
ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
strcpy(keymap, filenames[choice]);
|
||||
|
||||
if (rc != 2)
|
||||
{
|
||||
replacekeyvalue(kv, "KEYMAP", keymap);
|
||||
writekeyvalues(kv, CONFIG_ROOT "/main/settings");
|
||||
sprintf(commandstring, "/bin/loadkeys %s", keymap);
|
||||
mysystem(commandstring);
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
result = 0;
|
||||
|
||||
for (c = 0; filenames[c]; c++)
|
||||
{
|
||||
free(filenames[c]);
|
||||
free(displaynames[c]);
|
||||
}
|
||||
freekeyvalues(kv);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int process(char *prefix, char *path)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
char newpath[PATH_MAX];
|
||||
|
||||
snprintf(newpath, PATH_MAX, "%s%s", prefix, path);
|
||||
|
||||
if (!(dir = opendir(newpath)))
|
||||
{
|
||||
if (filenamecount > MAX_FILENAMES)
|
||||
return 1;
|
||||
|
||||
filenames[filenamecount] = (char *) strdup(newpath);
|
||||
filenamecount++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ((de = readdir(dir)))
|
||||
{
|
||||
if (de->d_name[0] == '.') continue;
|
||||
snprintf(newpath, PATH_MAX, "%s/%s", path, de->d_name);
|
||||
process(prefix, newpath);
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Small wrapper for use with qsort() to sort filename part. */
|
||||
static int cmp(const void *s1, const void *s2)
|
||||
{
|
||||
/* c1 and c2 are copies. */
|
||||
char *c1 = strdup(* (char **) s1);
|
||||
char *c2 = strdup(* (char **) s2);
|
||||
/* point to somewhere in cN. */
|
||||
char *f1, *f2;
|
||||
char *temp;
|
||||
int res;
|
||||
|
||||
if ((temp = strrchr(c1, '/')))
|
||||
f1 = temp + 1;
|
||||
else
|
||||
f1 = c1;
|
||||
if ((temp = strrchr(c2, '/')))
|
||||
f2 = temp + 1;
|
||||
else
|
||||
f2 = c2;
|
||||
/* bang off the . */
|
||||
if ((temp = strchr(f1, '.')))
|
||||
*temp = '\0';
|
||||
if ((temp = strchr(f2, '.')))
|
||||
*temp = '\0';
|
||||
|
||||
res = strcmp(f1, f2);
|
||||
|
||||
free(c1); free(c2);
|
||||
|
||||
return res;
|
||||
}
|
||||
229
src/install+setup/setup/main.c
Normal file
229
src/install+setup/setup/main.c
Normal file
@@ -0,0 +1,229 @@
|
||||
/* SmoothWall setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Contains main entry point, and misc functions.
|
||||
*
|
||||
* modified 16/11/2002 eoberlander - French language added
|
||||
*
|
||||
* $Id: main.c,v 1.4.2.7 2005/12/01 20:13:08 eoberlander Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
FILE *flog = NULL;
|
||||
char *mylog;
|
||||
|
||||
char **ctr = NULL;
|
||||
|
||||
int automode = 0;
|
||||
|
||||
extern char *bz_tr[];
|
||||
extern char *cs_tr[];
|
||||
extern char *da_tr[];
|
||||
extern char *en_tr[];
|
||||
extern char *es_tr[];
|
||||
extern char *fi_tr[];
|
||||
extern char *fr_tr[];
|
||||
extern char *hu_tr[];
|
||||
extern char *la_tr[];
|
||||
extern char *nl_tr[];
|
||||
extern char *de_tr[];
|
||||
extern char *tr_tr[];
|
||||
extern char *it_tr[];
|
||||
extern char *el_tr[];
|
||||
extern char *sk_tr[];
|
||||
extern char *so_tr[];
|
||||
extern char *sv_tr[];
|
||||
extern char *no_tr[];
|
||||
extern char *pl_tr[];
|
||||
extern char *pt_tr[];
|
||||
extern char *vi_tr[];
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef LANG_EN_ONLY
|
||||
char *shortlangnames[] = { "en", NULL };
|
||||
char **langtrs[] = { en_tr, NULL };
|
||||
#else
|
||||
char *shortlangnames[] = { "bz", "cs", "da", "de", "en", "es", "fr", "el", "it", "la", "hu", "nl", "no", "pl", "pt", "sk", "so", "fi", "sv", "tr", "vi", NULL };
|
||||
char **langtrs[] = { bz_tr, cs_tr, da_tr, de_tr, en_tr, es_tr, fr_tr, el_tr, it_tr, la_tr, hu_tr, nl_tr, no_tr, pl_tr, pt_tr, sk_tr, so_tr, fi_tr, sv_tr, tr_tr, vi_tr, NULL };
|
||||
#endif
|
||||
int choice;
|
||||
char *sections[11]; /* need to fill this out AFTER knowning lang */
|
||||
int rc;
|
||||
struct keyvalue *kv;
|
||||
char selectedshortlang[STRING_SIZE] = "en";
|
||||
char title[STRING_SIZE];
|
||||
int langcounter;
|
||||
int autook = 0;
|
||||
|
||||
/* Log file/terminal stuff. */
|
||||
if (argc >= 2)
|
||||
mylog = argv[1];
|
||||
else
|
||||
mylog = strdup("/root/setup.log");
|
||||
|
||||
if (!(flog = fopen(mylog, "w+")))
|
||||
{
|
||||
printf("Couldn't open log terminal\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc >= 3)
|
||||
automode = 1;
|
||||
|
||||
fprintf(flog, "Setup program started.\n");
|
||||
|
||||
kv = initkeyvalues();
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
|
||||
{
|
||||
printf("%s is not properly installed.\n", NAME);
|
||||
return 1;
|
||||
}
|
||||
findkey(kv, "LANGUAGE", selectedshortlang);
|
||||
|
||||
for (langcounter = 0; langtrs[langcounter]; langcounter++)
|
||||
{
|
||||
if (strcmp(selectedshortlang, shortlangnames[langcounter]) == 0)
|
||||
{
|
||||
ctr = langtrs[langcounter];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ctr)
|
||||
{
|
||||
/* zh,lt,ro,ru,th languages not available in setup, so use English */
|
||||
for (choice = 0; shortlangnames[choice]; choice++)
|
||||
{
|
||||
if (strcmp(shortlangnames[choice], "en") == 0)
|
||||
break;
|
||||
}
|
||||
if (!shortlangnames[choice])
|
||||
goto EXIT;
|
||||
ctr = langtrs[choice];
|
||||
}
|
||||
|
||||
sections[0] = ctr[TR_KEYBOARD_MAPPING];
|
||||
sections[1] = ctr[TR_TIMEZONE];
|
||||
sections[2] = ctr[TR_HOSTNAME];
|
||||
sections[3] = ctr[TR_DOMAINNAME];
|
||||
sections[4] = ctr[TR_ISDN_CONFIGURATION];
|
||||
sections[5] = ctr[TR_NETWORKING];
|
||||
sections[6] = ctr[TR_ROOT_PASSWORD];
|
||||
sections[7] = ctr[TR_ADMIN_PASSWORD];
|
||||
sections[8] = NULL;
|
||||
|
||||
newtInit();
|
||||
newtCls();
|
||||
FILE *f_title;
|
||||
if ((f_title = fopen ("/etc/issue", "r")))
|
||||
{
|
||||
fgets (title, STRING_SIZE, f_title);
|
||||
if (title[strlen(title) - 1] == '\n')
|
||||
title[strlen(title) - 1] = '\0';
|
||||
fclose (f_title);
|
||||
} else {
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
}
|
||||
newtDrawRootText(14, 0, title);
|
||||
newtPushHelpLine(ctr[TR_HELPLINE]);
|
||||
|
||||
if (automode == 0)
|
||||
{
|
||||
choice = 0;
|
||||
for (;;)
|
||||
{
|
||||
rc = newtWinMenu(ctr[TR_SECTION_MENU],
|
||||
ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 11,
|
||||
sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL);
|
||||
|
||||
if (rc == 2)
|
||||
break;
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
case 0:
|
||||
handlekeymap();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
handletimezone();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
handlehostname();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
handledomainname();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
handleisdn();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
handlenetworking();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
handlerootpassword();
|
||||
break;
|
||||
|
||||
case 7:
|
||||
handleadminpassword();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(handlekeymap()))
|
||||
goto EXIT;
|
||||
if (!(handletimezone()))
|
||||
goto EXIT;
|
||||
if (!(handlehostname()))
|
||||
goto EXIT;
|
||||
if (!(handledomainname()))
|
||||
goto EXIT;
|
||||
if (!(handleisdn()))
|
||||
goto EXIT;
|
||||
if (!(handlenetworking()))
|
||||
goto EXIT;
|
||||
if (!(handledhcp()))
|
||||
goto EXIT;
|
||||
if (!(handlerootpassword()))
|
||||
goto EXIT;
|
||||
if (!(handleadminpassword()))
|
||||
goto EXIT;
|
||||
|
||||
autook = 1;
|
||||
}
|
||||
|
||||
EXIT:
|
||||
if (automode != 0)
|
||||
{
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
if (autook)
|
||||
newtWinMessage(title, ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
|
||||
else
|
||||
newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
|
||||
}
|
||||
|
||||
fprintf(flog, "Setup program ended.\n");
|
||||
fflush(flog);
|
||||
fclose(flog);
|
||||
|
||||
newtFinished();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
141
src/install+setup/setup/misc.c
Normal file
141
src/install+setup/setup/misc.c
Normal file
@@ -0,0 +1,141 @@
|
||||
/* SmoothWall setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Misc. stuff for the lib.
|
||||
*
|
||||
* $Id: misc.c,v 1.5.2.3 2005/08/25 17:51:42 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
extern int automode;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
806
src/install+setup/setup/networking.c
Normal file
806
src/install+setup/setup/networking.c
Normal file
@@ -0,0 +1,806 @@
|
||||
/* SmoothWall setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* The big one: networking.
|
||||
*
|
||||
* $Id: networking.c,v 1.5.2.6 2006/02/06 22:00:13 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#define DNS1 0
|
||||
#define DNS2 1
|
||||
#define DEFAULT_GATEWAY 2
|
||||
#define DNSGATEWAY_TOTAL 3
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
extern int automode;
|
||||
|
||||
#define HAS_ORANGE (configtype == 1 || configtype == 3 || configtype == 5 || configtype == 7)
|
||||
#define HAS_RED (configtype == 2 || configtype == 3 || configtype == 6 || configtype == 7)
|
||||
#define HAS_BLUE (configtype == 4 || configtype == 5 || configtype == 6 || configtype == 7)
|
||||
#define RED_IS_NOT_ETH (configtype == 0 || configtype == 1 || configtype == 4 || configtype == 5)
|
||||
|
||||
extern struct nic nics[];
|
||||
|
||||
char *configtypenames[] = {
|
||||
"GREEN (RED is modem/ISDN)",
|
||||
"GREEN + ORANGE (RED is modem/ISDN)",
|
||||
"GREEN + RED",
|
||||
"GREEN + ORANGE + RED",
|
||||
"GREEN + BLUE (RED is modem/ISDN) ",
|
||||
"GREEN + ORANGE + BLUE (RED is modem/ISDN)",
|
||||
"GREEN + BLUE + RED",
|
||||
"GREEN + ORANGE + BLUE + RED",
|
||||
NULL };
|
||||
int netaddresschange;
|
||||
|
||||
int oktoleave(char *errormessage);
|
||||
int firstmenu(void);
|
||||
int configtypemenu(void);
|
||||
int drivermenu(void);
|
||||
int changedrivers(void);
|
||||
int greenaddressmenu(void);
|
||||
int addressesmenu(void);
|
||||
int dnsgatewaymenu(void);
|
||||
|
||||
int handlenetworking(void)
|
||||
{
|
||||
int done;
|
||||
int choice;
|
||||
char errormessage[STRING_SIZE];
|
||||
|
||||
netaddresschange = 0;
|
||||
|
||||
done = 0;
|
||||
while (!done)
|
||||
{
|
||||
choice = firstmenu();
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
case 1:
|
||||
configtypemenu();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
drivermenu();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
addressesmenu();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
dnsgatewaymenu();
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if (oktoleave(errormessage))
|
||||
done = 1;
|
||||
else
|
||||
errorbox(errormessage);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (automode == 0)
|
||||
{
|
||||
/* Restart networking! */
|
||||
if (netaddresschange)
|
||||
{
|
||||
runcommandwithstatus("/etc/rc.d/rc.netaddress.down",
|
||||
ctr[TR_PUSHING_NETWORK_DOWN]);
|
||||
runcommandwithstatus("/etc/rc.d/rc.netaddress.up",
|
||||
ctr[TR_PULLING_NETWORK_UP]);
|
||||
mysystem("/etc/rc.d/rc.pcmcia start");
|
||||
}
|
||||
}
|
||||
|
||||
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 (HAS_BLUE)
|
||||
{
|
||||
strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
|
||||
if (!(strlen(temp)))
|
||||
{
|
||||
strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]);
|
||||
goto EXIT;
|
||||
}
|
||||
if (!(interfacecheck(kv, "BLUE")))
|
||||
{
|
||||
strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]);
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
if (HAS_ORANGE)
|
||||
{
|
||||
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 (HAS_RED)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/* 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 };
|
||||
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;
|
||||
}
|
||||
|
||||
/* Here they choose general network config, number of nics etc. */
|
||||
int configtypemenu(void)
|
||||
{
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
char temp[STRING_SIZE] = "0";
|
||||
char message[1000];
|
||||
int choice;
|
||||
int rc;
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
findkey(kv, "CONFIG_TYPE", temp); choice = atol(temp);
|
||||
sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME);
|
||||
rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5,
|
||||
6, configtypenames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
if (rc == 0 || rc == 1)
|
||||
{
|
||||
runcommandwithstatus("/etc/rc.d/rc.netaddress.down NOTGREEN",
|
||||
ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
|
||||
|
||||
sprintf(temp, "%d", choice);
|
||||
replacekeyvalue(kv, "CONFIG_TYPE", temp);
|
||||
replacekeyvalue(kv, "ORANGE_DEV", "");
|
||||
replacekeyvalue(kv, "BLUE_DEV", "");
|
||||
replacekeyvalue(kv, "RED_DEV", "");
|
||||
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
|
||||
netaddresschange = 1;
|
||||
}
|
||||
|
||||
freekeyvalues(kv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
if (configtype == 0)
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_YOUR_CONFIGURATION_IS_SINGLE_GREEN_ALREADY_HAS_DRIVER]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]);
|
||||
|
||||
/* This horrible big formats the heading :( */
|
||||
strcpy(driver, ""); findkey(kv, "GREEN_DISPLAYDRIVER", driver);
|
||||
findnicdescription(driver, temp);
|
||||
strcpy(dev, ctr[TR_UNSET]); findkey(kv, "GREEN_DEV", dev);
|
||||
if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]);
|
||||
sprintf(temp1, "GREEN: %s (%s)\n", temp, dev);
|
||||
strcat(message, temp1);
|
||||
if (HAS_BLUE)
|
||||
{
|
||||
strcpy(driver, ""); findkey(kv, "BLUE_DISPLAYDRIVER", driver);
|
||||
findnicdescription(driver, temp);
|
||||
strcpy(dev, ctr[TR_UNSET]); findkey(kv, "BLUE_DEV", dev);
|
||||
if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]);
|
||||
sprintf(temp1, "BLUE: %s (%s)\n", temp, dev);
|
||||
strcat(message, temp1);
|
||||
}
|
||||
if (HAS_ORANGE)
|
||||
{
|
||||
strcpy(driver, ""); findkey(kv, "ORANGE_DISPLAYDRIVER", driver);
|
||||
findnicdescription(driver, temp);
|
||||
strcpy(dev, ctr[TR_UNSET]); findkey(kv, "ORANGE_DEV", dev);
|
||||
if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]);
|
||||
sprintf(temp1, "ORANGE: %s (%s)\n", temp, dev);
|
||||
strcat(message, temp1);
|
||||
}
|
||||
if (HAS_RED)
|
||||
{
|
||||
strcpy(driver, ""); findkey(kv, "RED_DISPLAYDRIVER", driver);
|
||||
findnicdescription(driver, temp);
|
||||
strcpy(dev, ctr[TR_UNSET]); findkey(kv, "RED_DEV", dev);
|
||||
if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]);
|
||||
sprintf(temp1, "RED: %s (%s)\n", temp, dev);
|
||||
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;
|
||||
}
|
||||
|
||||
int changedrivers(void)
|
||||
{
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
char message[1000];
|
||||
char temp[STRING_SIZE];
|
||||
char driver[STRING_SIZE];
|
||||
int configtype;
|
||||
int rc;
|
||||
int c;
|
||||
int needcards, sofarallocated, countofcards, toallocate;
|
||||
char *orange = "ORANGE";
|
||||
char *blue = "BLUE";
|
||||
char *red = "RED";
|
||||
char *sections[4];
|
||||
int choice;
|
||||
char nexteth[STRING_SIZE];
|
||||
int abort;
|
||||
char currentdriver[STRING_SIZE], currentdriveroptions[STRING_SIZE];
|
||||
char displaydriver[STRING_SIZE];
|
||||
struct stat st;
|
||||
|
||||
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 NOTGREEN",
|
||||
ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
|
||||
|
||||
/* Remove all modules not needed for green networking. */
|
||||
c = 0;
|
||||
strcpy(driver, ""); findkey(kv, "GREEN_DRIVER", driver);
|
||||
if (strcmp(driver, "pcmcia") != 0) {
|
||||
stat("/proc/bus/pccard", &st);
|
||||
mysystem("/etc/rc.d/rc.pcmcia stop");
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
mysystem("/sbin/modprobe pcmcia_core");
|
||||
mysystem("/sbin/modprobe pcmcia-controller");
|
||||
mysystem("/sbin/modprobe ds");
|
||||
}
|
||||
}
|
||||
while (nics[c].modulename)
|
||||
{
|
||||
if (strcmp(nics[c].modulename, driver) != 0)
|
||||
{
|
||||
if (checkformodule(nics[c].modulename))
|
||||
{
|
||||
sprintf(temp, "/sbin/rmmod %s", nics[c].modulename);
|
||||
mysystem(temp);
|
||||
}
|
||||
}
|
||||
c++;
|
||||
}
|
||||
|
||||
/* Blank them so the rc.netaddress.up does not get confused. */
|
||||
replacekeyvalue(kv, "ORANGE_DEV", "");
|
||||
replacekeyvalue(kv, "BLUE_DEV", "");
|
||||
replacekeyvalue(kv, "RED_DEV", "");
|
||||
|
||||
if (configtype == 0)
|
||||
needcards = 1;
|
||||
else if (configtype == 1 || configtype == 2 || configtype == 4)
|
||||
needcards = 2;
|
||||
else if (configtype == 7)
|
||||
needcards = 4;
|
||||
else
|
||||
needcards = 3;
|
||||
|
||||
/* This is the green card. */
|
||||
sofarallocated = 1;
|
||||
|
||||
findkey(kv, "GREEN_DRIVER", currentdriver);
|
||||
findkey(kv, "GREEN_DRIVER_OPTIONS", currentdriveroptions);
|
||||
strcpy(displaydriver, currentdriver);
|
||||
|
||||
if (countcards() > 1)
|
||||
strcpy(currentdriver, "");
|
||||
|
||||
abort = 0;
|
||||
/* Keep going till all cards are got, or they give up. */
|
||||
while (sofarallocated < needcards && !abort)
|
||||
{
|
||||
countofcards = countcards();
|
||||
|
||||
/* This is how many cards were added by the last module. */
|
||||
toallocate = countofcards - sofarallocated;
|
||||
while (toallocate > 0 && sofarallocated < needcards)
|
||||
{
|
||||
findnicdescription(displaydriver, temp);
|
||||
sprintf(message, ctr[TR_UNCLAIMED_DRIVER], temp);
|
||||
c = 0; choice = 0;
|
||||
strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
|
||||
if (HAS_BLUE && !strlen(temp))
|
||||
{
|
||||
sections[c] = blue;
|
||||
c++;
|
||||
}
|
||||
strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
|
||||
if (HAS_ORANGE && !strlen(temp))
|
||||
{
|
||||
sections[c] = orange;
|
||||
c++;
|
||||
}
|
||||
strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
|
||||
if (HAS_RED && !strlen(temp))
|
||||
{
|
||||
sections[c] = red;
|
||||
c++;
|
||||
}
|
||||
sections[c] = NULL;
|
||||
rc = newtWinMenu(ctr[TR_CARD_ASSIGNMENT],
|
||||
message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK],
|
||||
ctr[TR_CANCEL], NULL);
|
||||
if (rc == 0 || rc == 1)
|
||||
{
|
||||
/* Now we see which iface needs its settings changed. */
|
||||
sprintf(nexteth, "eth%d", sofarallocated);
|
||||
if (strcmp(sections[choice], blue) == 0)
|
||||
{
|
||||
replacekeyvalue(kv, "BLUE_DEV", nexteth);
|
||||
replacekeyvalue(kv, "BLUE_DRIVER", currentdriver);
|
||||
replacekeyvalue(kv, "BLUE_DRIVER_OPTIONS", currentdriveroptions);
|
||||
replacekeyvalue(kv, "BLUE_DISPLAYDRIVER", displaydriver);
|
||||
sofarallocated++;
|
||||
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++;
|
||||
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++;
|
||||
toallocate--;
|
||||
strcpy(currentdriver, "");
|
||||
strcpy(currentdriveroptions, "");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Need another module! The nitty gritty code is in libsmooth. */
|
||||
if (sofarallocated < needcards)
|
||||
{
|
||||
rc = newtWinTernary(ctr[TR_CARD_ASSIGNMENT], ctr[TR_PROBE],
|
||||
ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_NO_UNALLOCATED_CARDS]);
|
||||
|
||||
if (rc == 0 || rc == 1)
|
||||
{
|
||||
probecards(currentdriver, currentdriveroptions);
|
||||
if (!strlen(currentdriver))
|
||||
errorbox(ctr[TR_PROBE_FAILED]);
|
||||
}
|
||||
else if (rc == 2)
|
||||
choosecards(currentdriver, currentdriveroptions);
|
||||
else
|
||||
abort = 1;
|
||||
|
||||
strcpy(displaydriver, currentdriver);
|
||||
}
|
||||
}
|
||||
|
||||
countofcards = countcards();
|
||||
|
||||
if (countofcards >= 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;
|
||||
}
|
||||
|
||||
/* Let user change GREEN address. */
|
||||
int greenaddressmenu(void)
|
||||
{
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
char message[1000];
|
||||
int rc;
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sprintf(message, ctr[TR_WARNING_LONG], NAME);
|
||||
rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);
|
||||
|
||||
if (rc == 0 || rc == 1)
|
||||
{
|
||||
if (changeaddress(kv, "GREEN", 0, ""))
|
||||
{
|
||||
netaddresschange = 1;
|
||||
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
|
||||
writehostsfiles();
|
||||
}
|
||||
}
|
||||
|
||||
freekeyvalues(kv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 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(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 (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(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)
|
||||
{
|
||||
findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
|
||||
sprintf(message, ctr[TR_WARNING_LONG], NAME);
|
||||
rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_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;
|
||||
}
|
||||
|
||||
/* 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 (RED_IS_NOT_ETH)
|
||||
{
|
||||
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 = &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 = &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 = &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(values[DNS1]);
|
||||
free(values[DNS2]);
|
||||
free(values[DEFAULT_GATEWAY]);
|
||||
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
|
||||
}
|
||||
}
|
||||
}
|
||||
while (error);
|
||||
|
||||
freekeyvalues(kv);
|
||||
|
||||
return 1;
|
||||
}
|
||||
123
src/install+setup/setup/passwords.c
Normal file
123
src/install+setup/setup/passwords.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/* SmoothWall setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Password stuff.
|
||||
*
|
||||
* $Id: passwords.c,v 1.5.2.1 2004/04/14 22:05:41 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
extern int automode;
|
||||
|
||||
int getpassword(char *password, char *text);
|
||||
|
||||
/* Root password. */
|
||||
int handlerootpassword(void)
|
||||
{
|
||||
char password[STRING_SIZE];
|
||||
char commandstring[STRING_SIZE];
|
||||
|
||||
/* Root password. */
|
||||
if (getpassword(password, ctr[TR_ENTER_ROOT_PASSWORD]) == 2)
|
||||
return 0;
|
||||
|
||||
snprintf(commandstring, STRING_SIZE,
|
||||
"/bin/echo 'root:%s' | /usr/sbin/chpasswd", password);
|
||||
if (runhiddencommandwithstatus(commandstring, ctr[TR_SETTING_ROOT_PASSWORD]))
|
||||
{
|
||||
errorbox(ctr[TR_PROBLEM_SETTING_ROOT_PASSWORD]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int handleadminpassword(void)
|
||||
{
|
||||
char password[STRING_SIZE];
|
||||
char commandstring[STRING_SIZE];
|
||||
char message[1000];
|
||||
|
||||
/* web interface admin password. */
|
||||
sprintf(message, ctr[TR_ENTER_ADMIN_PASSWORD], NAME, NAME);
|
||||
if (getpassword(password, message) == 2)
|
||||
return 0;
|
||||
|
||||
snprintf(commandstring, STRING_SIZE,
|
||||
"/usr/bin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", password);
|
||||
sprintf(message, ctr[TR_SETTING_ADMIN_PASSWORD], NAME);
|
||||
if (runhiddencommandwithstatus(commandstring, message))
|
||||
{
|
||||
sprintf(message, ctr[TR_PROBLEM_SETTING_ADMIN_PASSWORD], NAME);
|
||||
errorbox(message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Taken from the cdrom one. */
|
||||
int getpassword(char *password, char *text)
|
||||
{
|
||||
char *values[] = { NULL, NULL, NULL }; /* pointers for the values. */
|
||||
struct newtWinEntry entries[] =
|
||||
{
|
||||
{ ctr[TR_PASSWORD_PROMPT], &values[0], 2 },
|
||||
{ ctr[TR_AGAIN_PROMPT], &values[1], 2 },
|
||||
{ NULL, NULL, 0 }
|
||||
};
|
||||
char title[STRING_SIZE];
|
||||
int rc;
|
||||
int done;
|
||||
|
||||
do
|
||||
{
|
||||
done = 1;
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
rc = newtWinEntries(title, text,
|
||||
50, 5, 5, 20, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
if (rc != 2)
|
||||
{
|
||||
if (strlen(values[0]) == 0 || strlen(values[1]) == 0)
|
||||
{
|
||||
errorbox(ctr[TR_PASSWORD_CANNOT_BE_BLANK]);
|
||||
done = 0;
|
||||
strcpy(values[0], "");
|
||||
strcpy(values[1], "");
|
||||
}
|
||||
else if (strcmp(values[0], values[1]) != 0)
|
||||
{
|
||||
errorbox(ctr[TR_PASSWORDS_DO_NOT_MATCH]);
|
||||
done = 0;
|
||||
strcpy(values[0], "");
|
||||
strcpy(values[1], "");
|
||||
}
|
||||
else if (strchr(values[0], ' '))
|
||||
{
|
||||
errorbox(ctr[TR_PASSWORD_CANNOT_CONTAIN_SPACES]);
|
||||
done = 0;
|
||||
strcpy(values[0], "");
|
||||
strcpy(values[1], "");
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!done);
|
||||
|
||||
strncpy(password, values[0], STRING_SIZE);
|
||||
|
||||
if (values[0]) free(values[0]);
|
||||
if (values[1]) free(values[1]);
|
||||
|
||||
return rc;
|
||||
}
|
||||
42
src/install+setup/setup/setup.h
Normal file
42
src/install+setup/setup/setup.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* SmoothWall setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Main include file.
|
||||
*
|
||||
* $Id: setup.h,v 1.4 2003/12/11 11:25:54 riddles Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../libsmooth/libsmooth.h"
|
||||
|
||||
/* hostname.c */
|
||||
int handlehostname(void);
|
||||
|
||||
/* domainname.c */
|
||||
int handledomainname(void);
|
||||
|
||||
/* isdn.c */
|
||||
int handleisdn(void);
|
||||
|
||||
/* networking.c */
|
||||
int handlenetworking(void);
|
||||
|
||||
/* dhcp.c */
|
||||
int handledhcp(void);
|
||||
|
||||
/* passwords.c */
|
||||
int handlerootpassword(void);
|
||||
int handlesetuppassword(void);
|
||||
int handleadminpassword(void);
|
||||
|
||||
/* misc.c */
|
||||
int writehostsfiles(void);
|
||||
|
||||
/* keymap.c */
|
||||
int handlekeymap(void);
|
||||
|
||||
/* timezone.c */
|
||||
int handletimezone(void);
|
||||
134
src/install+setup/setup/timezone.c
Normal file
134
src/install+setup/setup/timezone.c
Normal file
@@ -0,0 +1,134 @@
|
||||
/* SmoothWall setup program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Stuff for setting the timezone.
|
||||
*
|
||||
* $Id: timezone.c,v 1.4.2.1 2004/04/14 22:05:41 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
extern int automode;
|
||||
|
||||
#define MAX_FILENAMES 5000
|
||||
#define ZONEFILES "/usr/share/zoneinfo/posix"
|
||||
|
||||
static int filenamecount;
|
||||
static char *filenames[MAX_FILENAMES];
|
||||
static char *displaynames[MAX_FILENAMES];
|
||||
|
||||
static int process(char *prefix, char *path);
|
||||
static int cmp(const void *s1, const void *s2);
|
||||
|
||||
int handletimezone(void)
|
||||
{
|
||||
int c;
|
||||
int choice;
|
||||
char *temp;
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
int rc;
|
||||
int result;
|
||||
char timezone[STRING_SIZE];
|
||||
|
||||
filenamecount = 0;
|
||||
|
||||
process(ZONEFILES, "");
|
||||
filenames[filenamecount] = NULL;
|
||||
qsort(filenames, filenamecount, sizeof(char *), cmp);
|
||||
|
||||
for (c = 0; filenames[c]; c++)
|
||||
{
|
||||
displaynames[c] = malloc(STRING_SIZE);
|
||||
if ((temp = strstr(filenames[c], ZONEFILES)))
|
||||
strcpy(displaynames[c], temp + strlen(ZONEFILES) + 1);
|
||||
else
|
||||
strcpy(displaynames[c], filenames[c]);
|
||||
}
|
||||
displaynames[c] = NULL;
|
||||
|
||||
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
|
||||
{
|
||||
freekeyvalues(kv);
|
||||
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(timezone, ZONEFILES "/CET");
|
||||
findkey(kv, "TIMEZONE", timezone);
|
||||
|
||||
choice = 0;
|
||||
for (c = 0; filenames[c]; c++)
|
||||
{
|
||||
if (strcmp(timezone, filenames[c]) == 0)
|
||||
choice = c;
|
||||
}
|
||||
|
||||
rc = newtWinMenu(ctr[TR_TIMEZONE], ctr[TR_TIMEZONE_LONG], 50, 5, 5, 6, displaynames, &choice,
|
||||
ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
strcpy(timezone, filenames[choice]);
|
||||
|
||||
if (rc != 2)
|
||||
{
|
||||
replacekeyvalue(kv, "TIMEZONE", timezone);
|
||||
writekeyvalues(kv, CONFIG_ROOT "/main/settings");
|
||||
unlink("/etc/localtime");
|
||||
link(timezone, "/etc/localtime");
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
result = 0;
|
||||
|
||||
for (c = 0; filenames[c]; c++)
|
||||
{
|
||||
free(filenames[c]);
|
||||
free(displaynames[c]);
|
||||
}
|
||||
freekeyvalues(kv);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int process(char *prefix, char *path)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
char newpath[PATH_MAX];
|
||||
|
||||
snprintf(newpath, PATH_MAX, "%s%s", prefix, path);
|
||||
|
||||
if (!(dir = opendir(newpath)))
|
||||
{
|
||||
if (filenamecount > MAX_FILENAMES)
|
||||
return 1;
|
||||
|
||||
filenames[filenamecount] = (char *) strdup(newpath);
|
||||
filenamecount++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while ((de = readdir(dir)))
|
||||
{
|
||||
if (de->d_name[0] == '.') continue;
|
||||
snprintf(newpath, PATH_MAX, "%s/%s", path, de->d_name);
|
||||
process(prefix, newpath);
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Small wrapper for use with qsort(). */
|
||||
static int cmp(const void *s1, const void *s2)
|
||||
{
|
||||
return (strcmp(* (char **) s1, * (char **) s2));
|
||||
}
|
||||
Reference in New Issue
Block a user