]>
Commit | Line | Data |
---|---|---|
bba7212c 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 | * Misc. stuff for the lib. | |
8 | * | |
9 | */ | |
e1457ba0 MT |
10 | |
11 | // Translation | |
12 | #include <libintl.h> | |
13 | #define _(x) dgettext("setup", x) | |
14 | ||
bba7212c MT |
15 | #include "setup.h" |
16 | ||
17 | extern FILE *flog; | |
18 | extern char *mylog; | |
19 | ||
bba7212c MT |
20 | extern int automode; |
21 | ||
22 | /* This will rewrite /etc/hosts, /etc/hosts.*, and the apache ServerName file. */ | |
23 | int writehostsfiles(void) | |
24 | { | |
25 | char address[STRING_SIZE] = ""; | |
26 | char netaddress[STRING_SIZE] = ""; | |
27 | char netmask[STRING_SIZE] = ""; | |
28 | char message[1000]; | |
29 | FILE *file, *hosts; | |
30 | struct keyvalue *kv; | |
31 | char hostname[STRING_SIZE]; | |
8dc9629e | 32 | char domainname[STRING_SIZE] = "localdomain"; |
bba7212c MT |
33 | char commandstring[STRING_SIZE]; |
34 | char buffer[STRING_SIZE]; | |
35 | ||
36 | kv = initkeyvalues(); | |
37 | if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))) | |
38 | { | |
39 | freekeyvalues(kv); | |
e1457ba0 | 40 | errorbox(_("Unable to open settings file")); |
bba7212c MT |
41 | return 0; |
42 | } | |
43 | findkey(kv, "GREEN_ADDRESS", address); | |
44 | findkey(kv, "GREEN_NETADDRESS", netaddress); | |
45 | findkey(kv, "GREEN_NETMASK", netmask); | |
46 | freekeyvalues(kv); | |
47 | ||
48 | kv = initkeyvalues(); | |
49 | if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings"))) | |
50 | { | |
51 | freekeyvalues(kv); | |
e1457ba0 | 52 | errorbox(_("Unable to open settings file")); |
bba7212c MT |
53 | return 0; |
54 | } | |
55 | strcpy(hostname, SNAME ); | |
56 | findkey(kv, "HOSTNAME", hostname); | |
57 | findkey(kv, "DOMAINNAME", domainname); | |
58 | freekeyvalues(kv); | |
59 | ||
60 | if (!(file = fopen(CONFIG_ROOT "/main/hostname.conf", "w"))) | |
61 | { | |
e1457ba0 | 62 | sprintf (message, _("Unable to write %s/main/hostname.conf"), CONFIG_ROOT); |
bba7212c MT |
63 | errorbox(message); |
64 | return 0; | |
65 | } | |
66 | fprintf(file, "ServerName %s.%s\n", hostname,domainname); | |
67 | fclose(file); | |
68 | ||
69 | if (!(file = fopen(CONFIG_ROOT "/main/hosts", "r"))) | |
70 | { | |
e1457ba0 | 71 | errorbox(_("Unable to open main hosts file.")); |
bba7212c MT |
72 | return 0; |
73 | } | |
74 | if (!(hosts = fopen("/etc/hosts", "w"))) | |
75 | { | |
e1457ba0 | 76 | errorbox(_("Unable to write /etc/hosts.")); |
bba7212c MT |
77 | return 0; |
78 | } | |
79 | fprintf(hosts, "127.0.0.1\tlocalhost\n"); | |
80 | if (strlen(domainname)) | |
81 | fprintf(hosts, "%s\t%s.%s\t%s\n",address,hostname,domainname,hostname); | |
82 | else | |
83 | fprintf(hosts, "%s\t%s\n",address,hostname); | |
84 | while (fgets(buffer, STRING_SIZE, file)) | |
85 | { | |
86 | char *token, *ip, *host, *domain; | |
87 | ||
88 | buffer[strlen(buffer) - 1] = 0; | |
89 | ||
90 | token = strtok(buffer, ","); | |
91 | ||
92 | ip = strtok(NULL, ","); | |
93 | host = strtok(NULL, ","); | |
94 | domain = strtok(NULL, ","); | |
95 | ||
96 | if (!(ip && host)) | |
97 | break; | |
98 | ||
99 | if (strlen(ip) < 7 || strlen(ip) > 15 | |
100 | || strspn(ip, "0123456789.") != strlen(ip)) | |
101 | break; | |
102 | ||
103 | if (strspn(host, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-") != strlen(host)) | |
104 | break; | |
105 | ||
106 | if (domain) | |
107 | fprintf(hosts, "%s\t%s.%s\t%s\n",ip,host,domain,host); | |
108 | else | |
109 | fprintf(hosts, "%s\t%s\n",ip,host); | |
110 | } | |
111 | fclose(file); | |
112 | fclose(hosts); | |
113 | ||
114 | /* TCP wrappers stuff. */ | |
115 | if (!(file = fopen("/etc/hosts.deny", "w"))) | |
116 | { | |
e1457ba0 | 117 | errorbox(_("Unable to write /etc/hosts.deny.")); |
bba7212c MT |
118 | return 0; |
119 | } | |
120 | fprintf(file, "ALL : ALL\n"); | |
121 | fclose(file); | |
122 | ||
123 | if (!(file = fopen("/etc/hosts.allow", "w"))) | |
124 | { | |
e1457ba0 | 125 | errorbox(_("Unable to write /etc/hosts.allow.")); |
bba7212c MT |
126 | return 0; |
127 | } | |
128 | fprintf(file, "sshd : ALL\n"); | |
129 | fprintf(file, "ALL : localhost\n"); | |
130 | fprintf(file, "ALL : %s/%s\n", netaddress, netmask); | |
131 | fclose(file); | |
132 | ||
133 | sprintf(commandstring, "/bin/hostname %s.%s", hostname, domainname); | |
46b56e20 | 134 | if (mysystem(NULL, commandstring)) |
bba7212c | 135 | { |
e1457ba0 | 136 | errorbox(_("Unable to set hostname.")); |
bba7212c MT |
137 | return 0; |
138 | } | |
139 | ||
140 | return 1; | |
141 | } | |
142 | ||
143 | int handleisdn(void) | |
144 | { | |
145 | char command[STRING_SIZE]; | |
146 | sprintf(command, "/etc/rc.d/init.d/mISDN config"); | |
46b56e20 | 147 | if (runcommandwithstatus(command, _("ISDN"), _("Scanning and configuring ISDN devices."), NULL)) |
e1457ba0 | 148 | errorbox(_("Unable to scan for ISDN devices.")); |
bba7212c | 149 | // Need to write some lines that count the cards and say the names... |
0db33b56 | 150 | return 1; |
bba7212c | 151 | } |