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