]>
Commit | Line | Data |
---|---|---|
cd1a2927 MT |
1 | /* SmoothWall setup program.\r |
2 | *\r | |
3 | * This program is distributed under the terms of the GNU General Public\r | |
4 | * Licence. See the file COPYING for details.\r | |
5 | *\r | |
6 | * (c) Lawrence Manning, 2001\r | |
7 | * Stuff for setting the hostname.\r | |
8 | * \r | |
9 | * $Id: hostname.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $\r | |
10 | * \r | |
11 | */\r | |
12 | \r | |
13 | #include "setup.h"\r | |
14 | \r | |
15 | extern FILE *flog;\r | |
16 | extern char *mylog;\r | |
17 | \r | |
18 | extern char **ctr;\r | |
19 | \r | |
20 | extern int automode;\r | |
21 | \r | |
22 | int handlehostname(void)\r | |
23 | {\r | |
24 | char hostname[STRING_SIZE] = "";\r | |
25 | struct keyvalue *kv = initkeyvalues();\r | |
26 | char *values[] = { hostname, NULL }; /* pointers for the values. */\r | |
27 | struct newtWinEntry entries[] =\r | |
28 | { { "", &values[0], 0,}, { NULL, NULL, 0 } };\r | |
29 | int rc;\r | |
30 | int result;\r | |
31 | \r | |
32 | if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))\r | |
33 | {\r | |
34 | freekeyvalues(kv);\r | |
35 | errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);\r | |
36 | return 0;\r | |
37 | } \r | |
38 | \r | |
39 | strcpy(hostname, SNAME);\r | |
40 | findkey(kv, "HOSTNAME", hostname);\r | |
41 | \r | |
42 | for (;;)\r | |
43 | {\r | |
44 | rc = newtWinEntries(ctr[TR_HOSTNAME], ctr[TR_ENTER_HOSTNAME],\r | |
45 | 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);\r | |
46 | \r | |
47 | if (rc == 1)\r | |
48 | {\r | |
49 | strcpy(hostname, values[0]);\r | |
50 | if (!(strlen(hostname)))\r | |
51 | errorbox(ctr[TR_HOSTNAME_CANNOT_BE_EMPTY]);\r | |
52 | else if (strchr(hostname, ' '))\r | |
53 | errorbox(ctr[TR_HOSTNAME_CANNOT_CONTAIN_SPACES]);\r | |
54 | else if (strlen(hostname) != strspn(hostname,\r | |
55 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"))\r | |
56 | errorbox(ctr[TR_HOSTNAME_NOT_VALID_CHARS]);\r | |
57 | else\r | |
58 | {\r | |
59 | replacekeyvalue(kv, "HOSTNAME", hostname);\r | |
60 | writekeyvalues(kv, CONFIG_ROOT "/main/settings");\r | |
61 | writehostsfiles();\r | |
62 | result = 1;\r | |
63 | break;\r | |
64 | }\r | |
65 | }\r | |
66 | else\r | |
67 | {\r | |
68 | result = 0;\r | |
69 | break;\r | |
70 | }\r | |
71 | }\r | |
72 | free(values[0]);\r | |
73 | freekeyvalues(kv);\r | |
74 | \r | |
75 | return result;\r | |
76 | } \r |