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