]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame_incremental - src/setup/domainname.c
Merge branch 'master' into next
[people/pmueller/ipfire-2.x.git] / src / setup / domainname.c
... / ...
CommitLineData
1/* IPCop 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 * $Id: domainname.c
7 *
8 */
9
10// Translation
11#include <libintl.h>
12#define _(x) dgettext("setup", x)
13
14#include "setup.h"
15
16extern FILE *flog;
17extern char *mylog;
18
19extern int automode;
20
21int handledomainname(void)
22{
23 char domainname[STRING_SIZE] = "localdomain";
24 struct keyvalue *kv = initkeyvalues();
25 char *values[] = { domainname, NULL }; /* pointers for the values. */
26 struct newtWinEntry entries[] =
27 { { "", &values[0], 0,}, { NULL, NULL, 0 } };
28 int rc;
29 int result;
30
31 if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
32 {
33 freekeyvalues(kv);
34 errorbox(_("Unable to open settings file"));
35 return 0;
36 }
37
38 findkey(kv, "DOMAINNAME", domainname);
39
40 for (;;)
41 {
42 rc = newtWinEntries(_("Domain name"), _("Enter Domain name"),
43 50, 5, 5, 40, entries, _("OK"), _("Cancel"), NULL);
44
45 if (rc == 1) {
46 strcpy(domainname, values[0]);
47 if (!(strlen(domainname)))
48 errorbox(_("Domain name cannot be empty."));
49 else if (strchr(domainname, ' '))
50 errorbox(_("Domain name cannot contain spaces."));
51 else if (strlen(domainname) != strspn(domainname,
52 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-."))
53 errorbox(_("Domain name may only contain letters, numbers, hyphens and periods."));
54 else
55 {
56 replacekeyvalue(kv, "DOMAINNAME", domainname);
57 writekeyvalues(kv, CONFIG_ROOT "/main/settings");
58 writehostsfiles();
59 result = 1;
60 break;
61 }
62 }
63 else
64 {
65 result = 0;
66 break;
67 }
68 }
69 free(values[0]);
70 freekeyvalues(kv);
71
72 return result;
73}