]>
Commit | Line | Data |
---|---|---|
c6fbd6ea MT |
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 | */ | |
e1457ba0 MT |
12 | |
13 | // Translation | |
14 | #include <libintl.h> | |
15 | #define _(x) dgettext("setup", x) | |
16 | ||
c6fbd6ea MT |
17 | #include "setup.h" |
18 | ||
19 | extern FILE *flog; | |
20 | extern char *mylog; | |
21 | ||
c6fbd6ea MT |
22 | extern int automode; |
23 | ||
24 | int handlehostname(void) | |
25 | { | |
26 | char hostname[STRING_SIZE] = ""; | |
27 | struct keyvalue *kv = initkeyvalues(); | |
28 | char *values[] = { hostname, NULL }; /* pointers for the values. */ | |
29 | struct newtWinEntry entries[] = | |
30 | { { "", &values[0], 0,}, { NULL, NULL, 0 } }; | |
31 | int rc; | |
32 | int result; | |
33 | ||
34 | if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) | |
35 | { | |
36 | freekeyvalues(kv); | |
e1457ba0 | 37 | errorbox(_("Unable to open settings file")); |
c6fbd6ea MT |
38 | return 0; |
39 | } | |
40 | ||
41 | strcpy(hostname, SNAME); | |
42 | findkey(kv, "HOSTNAME", hostname); | |
43 | ||
44 | for (;;) | |
45 | { | |
e1457ba0 MT |
46 | rc = newtWinEntries(_("Hostname"), _("Enter the machine's hostname."), |
47 | 50, 5, 5, 40, entries, _("OK"), _("Cancel"), NULL); | |
c6fbd6ea MT |
48 | |
49 | if (rc == 1) | |
50 | { | |
51 | strcpy(hostname, values[0]); | |
52 | if (!(strlen(hostname))) | |
e1457ba0 | 53 | errorbox(_("Hostname cannot be empty.")); |
c6fbd6ea | 54 | else if (strchr(hostname, ' ')) |
e1457ba0 | 55 | errorbox(_("Hostname cannot contain spaces.")); |
c6fbd6ea MT |
56 | else if (strlen(hostname) != strspn(hostname, |
57 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-")) | |
e1457ba0 | 58 | errorbox(_("Hostname may only contain letters, numbers and hyphens.")); |
c6fbd6ea MT |
59 | else |
60 | { | |
61 | replacekeyvalue(kv, "HOSTNAME", hostname); | |
62 | writekeyvalues(kv, CONFIG_ROOT "/main/settings"); | |
63 | writehostsfiles(); | |
64 | result = 1; | |
65 | break; | |
66 | } | |
67 | } | |
68 | else | |
69 | { | |
70 | result = 0; | |
71 | break; | |
72 | } | |
73 | } | |
74 | free(values[0]); | |
75 | freekeyvalues(kv); | |
76 | ||
77 | return result; | |
78 | } |