]> git.ipfire.org Git - ipfire-2.x.git/blame - src/setup/domainname.c
Merge branch 'next' of ssh://git.ipfire.org/pub/git/ipfire-2.x into asterisk-update
[ipfire-2.x.git] / src / setup / domainname.c
CommitLineData
c6fbd6ea
MT
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 */
e1457ba0
MT
9
10// Translation
11#include <libintl.h>
12#define _(x) dgettext("setup", x)
13
c6fbd6ea
MT
14#include "setup.h"
15
16extern FILE *flog;
17extern char *mylog;
18
c6fbd6ea
MT
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);
e1457ba0 34 errorbox(_("Unable to open settings file"));
c6fbd6ea
MT
35 return 0;
36 }
37
38 findkey(kv, "DOMAINNAME", domainname);
39
40 for (;;)
41 {
e1457ba0
MT
42 rc = newtWinEntries(_("Domain name"), _("Enter Domain name"),
43 50, 5, 5, 40, entries, _("OK"), _("Cancel"), NULL);
c6fbd6ea 44
e1457ba0 45 if (rc == 1) {
c6fbd6ea
MT
46 strcpy(domainname, values[0]);
47 if (!(strlen(domainname)))
e1457ba0 48 errorbox(_("Domain name cannot be empty."));
c6fbd6ea 49 else if (strchr(domainname, ' '))
e1457ba0 50 errorbox(_("Domain name cannot contain spaces."));
c6fbd6ea
MT
51 else if (strlen(domainname) != strspn(domainname,
52 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-."))
e1457ba0 53 errorbox(_("Domain name may only contain letters, numbers, hyphens and periods."));
c6fbd6ea
MT
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}