]>
Commit | Line | Data |
---|---|---|
1 | /*\r | |
2 | * This file is part of the IPCop Firewall.\r | |
3 | *\r | |
4 | * IPCop is free software; you can redistribute it and/or modify\r | |
5 | * it under the terms of the GNU General Public License as published by\r | |
6 | * the Free Software Foundation; either version 2 of the License, or\r | |
7 | * (at your option) any later version.\r | |
8 | *\r | |
9 | * IPCop is distributed in the hope that it will be useful,\r | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r | |
12 | * GNU General Public License for more details.\r | |
13 | *\r | |
14 | * You should have received a copy of the GNU General Public License\r | |
15 | * along with IPCop; if not, write to the Free Software\r | |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r | |
17 | *\r | |
18 | * Copyright 2002: Mark Wormgoor <mark@wormgoor.com>\r | |
19 | * \r | |
20 | * $Id: upgrade-v12-v13.c,v 1.2.2.3 2004/11/11 09:39:25 alanh Exp $\r | |
21 | * \r | |
22 | */\r | |
23 | \r | |
24 | #include "install.h"\r | |
25 | \r | |
26 | void _convert_ppp_settings() {\r | |
27 | DIR *dirp;\r | |
28 | struct dirent *dp;\r | |
29 | char filename[STRING_SIZE];\r | |
30 | \r | |
31 | dirp = opendir( "/harddisk/var/ipcop/ppp" );\r | |
32 | while ( (dp = readdir( dirp )) != NULL ) {\r | |
33 | if ( strstr( dp->d_name, "settings" ) == dp->d_name ) {\r | |
34 | snprintf (filename, STRING_SIZE-1, "%s/%s", \r | |
35 | "/harddisk/var/ipcop/ppp", dp->d_name);\r | |
36 | \r | |
37 | /* reduce furthur replacements from commands below */\r | |
38 | replace (filename, "TYPE=modem", "");\r | |
39 | replace (filename, "COMPORT=ttyS0", "TYPE=modem\nCOMPORT=ttyS0");\r | |
40 | replace (filename, "COMPORT=ttyS1", "TYPE=modem\nCOMPORT=ttyS1");\r | |
41 | replace (filename, "COMPORT=ttyS2", "TYPE=modem\nCOMPORT=ttyS2");\r | |
42 | replace (filename, "COMPORT=ttyS3", "TYPE=modem\nCOMPORT=ttyS3");\r | |
43 | /* reduce furthur replacements from commands below */\r | |
44 | replace (filename, "TYPE=isdn", "");\r | |
45 | replace (filename, "COMPORT=isdn1", "TYPE=isdn\nCOMPORT=isdn1");\r | |
46 | replace (filename, "COMPORT=isdn2", "TYPE=isdn\nCOMPORT=isdn2");\r | |
47 | replace (filename, "COMPORT=pppoe", "TYPE=pppoe");\r | |
48 | replace (filename, "COMPORT=pptp", "TYPE=pptp");\r | |
49 | replace (filename, "COMPORT=usbadsl", "TYPE=alcatelusb");\r | |
50 | replace (filename, "COMPORT=pppoa", "TYPE=pulsardsl");\r | |
51 | \r | |
52 | chown (filename, 99, 99);\r | |
53 | } \r | |
54 | }\r | |
55 | (void) closedir( dirp );\r | |
56 | }\r | |
57 | \r | |
58 | int _convert_xtaccess() {\r | |
59 | int count=1, count2=0;\r | |
60 | FILE *portfw1, *portfw2;\r | |
61 | char portsrctemp[STRING_SIZE], portdsttemp[STRING_SIZE];\r | |
62 | char *portproto, *portsrcip, *portsrcport, *portdstip, *portdstport, *portenabled, *portremip;\r | |
63 | \r | |
64 | FILE *xtaccess1, *xtaccess2;\r | |
65 | char xtsrctemp[STRING_SIZE], xtdsttemp[STRING_SIZE];\r | |
66 | char *xtproto, *xtsrcip, *xtdstip, *xtdstport, *xtenabled;\r | |
67 | \r | |
68 | if (!(portfw1 = fopen ("/harddisk/var/ipcop/portfw/config", "r"))) return 1;\r | |
69 | if (!(portfw2 = fopen ("/harddisk/var/ipcop/portfw/config.new", "w"))) \r | |
70 | {\r | |
71 | fclose(portfw1);\r | |
72 | return 1;\r | |
73 | }\r | |
74 | \r | |
75 | while (fgets (portsrctemp, STRING_SIZE, portfw1) != NULL) {\r | |
76 | count2 = 0;\r | |
77 | portproto = NULL;\r | |
78 | portsrcip = NULL;\r | |
79 | portsrcport = NULL;\r | |
80 | portdstip = NULL;\r | |
81 | portdstport = NULL;\r | |
82 | portremip = NULL;\r | |
83 | portenabled = NULL;\r | |
84 | \r | |
85 | if (!(xtaccess1 = fopen ("/harddisk/var/ipcop/xtaccess/config", "r"))) \r | |
86 | {\r | |
87 | fclose(portfw1);\r | |
88 | fclose(portfw2);\r | |
89 | return 1;\r | |
90 | }\r | |
91 | if (!(xtaccess2 = fopen ("/harddisk/var/ipcop/xtaccess/config.new", "w"))) \r | |
92 | {\r | |
93 | fclose(portfw1);\r | |
94 | fclose(portfw2);\r | |
95 | fclose(xtaccess1);\r | |
96 | return 1;\r | |
97 | }\r | |
98 | \r | |
99 | if (isdigit (portsrctemp[0])) {\r | |
100 | /* Already converted to new format */\r | |
101 | fputs(portsrctemp, portfw2);\r | |
102 | continue;\r | |
103 | }\r | |
104 | \r | |
105 | if (portsrctemp[strlen(portsrctemp) - 1] == '\n')\r | |
106 | portsrctemp[strlen(portsrctemp) - 1] = '\0';\r | |
107 | portproto = strtok (portsrctemp, ",");\r | |
108 | portsrcport = strtok (NULL, ",");\r | |
109 | portdstip = strtok (NULL, ",");\r | |
110 | portdstport = strtok (NULL, ",");\r | |
111 | portenabled = strtok (NULL, ",");\r | |
112 | portsrcip = strtok (NULL, ",");\r | |
113 | portremip = strtok (NULL, ",");\r | |
114 | if (!(portproto && portsrcport && portdstip && \r | |
115 | portdstport && portenabled ))\r | |
116 | continue;\r | |
117 | \r | |
118 | if (portsrcip == NULL) portsrcip = strdup ("0.0.0.0");\r | |
119 | \r | |
120 | while (fgets (xtsrctemp, STRING_SIZE, xtaccess1)) {\r | |
121 | xtproto = NULL;\r | |
122 | xtsrcip = NULL;\r | |
123 | xtdstip = NULL;\r | |
124 | xtdstport = NULL;\r | |
125 | xtenabled = NULL;\r | |
126 | \r | |
127 | if (xtsrctemp[strlen(xtsrctemp) - 1] == '\n')\r | |
128 | xtsrctemp[strlen(xtsrctemp) - 1] = '\0';\r | |
129 | xtproto = strtok (xtsrctemp, ",");\r | |
130 | xtsrcip = strtok (NULL, ",");\r | |
131 | xtdstport = strtok (NULL, ",");\r | |
132 | xtenabled = strtok (NULL, ",");\r | |
133 | xtdstip = strtok (NULL, ",");\r | |
134 | if (!(xtproto && xtsrcip && xtdstport && xtenabled)) continue;\r | |
135 | \r | |
136 | if (xtdstip == NULL) xtdstip = strdup ("0.0.0.0");\r | |
137 | \r | |
138 | if (strcmp (portproto, xtproto) == 0 &&\r | |
139 | strcmp (portsrcport, xtdstport) == 0 &&\r | |
140 | strcmp (portsrcip, xtdstip) == 0) {\r | |
141 | portremip = strdup (xtsrcip);\r | |
142 | if ((strcmp (portremip, "0.0.0.0/0") == 0) && (count2 == 0)) {\r | |
143 | sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%s\n",\r | |
144 | count, count2, portproto, portsrcport, portdstip,\r | |
145 | portdstport, portenabled, portsrcip, portremip);\r | |
146 | fputs(portdsttemp, portfw2);\r | |
147 | } else {\r | |
148 | if (count2 == 0) {\r | |
149 | sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%d\n",\r | |
150 | count,count2,portproto, portsrcport, portdstip,\r | |
151 | portdstport, portenabled, portsrcip, 0);\r | |
152 | fputs(portdsttemp, portfw2);\r | |
153 | count2++;\r | |
154 | }\r | |
155 | sprintf (portdsttemp, "%d,%d,%s,%d,%s,%s,%s,%d,%s\n",\r | |
156 | count,count2,portproto, 0, portdstip,\r | |
157 | portdstport, portenabled, 0, portremip);\r | |
158 | fputs(portdsttemp, portfw2);\r | |
159 | }\r | |
160 | count2++;\r | |
161 | } else {\r | |
162 | sprintf (xtdsttemp, "%s,%s,%s,%s,%s\n",\r | |
163 | xtproto, xtsrcip, xtdstport, xtenabled, xtdstip);\r | |
164 | fputs(xtdsttemp, xtaccess2);\r | |
165 | }\r | |
166 | }\r | |
167 | \r | |
168 | /* Close source and destination xtaccess files */\r | |
169 | fclose (xtaccess1);\r | |
170 | fclose (xtaccess2);\r | |
171 | \r | |
172 | /* Move the new xtaccess file */\r | |
173 | rename ("/harddisk/var/ipcop/xtaccess/config.new",\r | |
174 | "/harddisk/var/ipcop/xtaccess/config");\r | |
175 | \r | |
176 | /* If no external access line existed, add a no access line */\r | |
177 | if (count2 == 0) {\r | |
178 | if (portremip == NULL) portremip = strdup ("127.0.0.1/32");\r | |
179 | \r | |
180 | /* Print new port forwarding line to file */\r | |
181 | sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%s\n",\r | |
182 | count, count2, portproto, portsrcport, portdstip, \r | |
183 | portdstport, portenabled, portsrcip, portremip);\r | |
184 | fputs(portdsttemp, portfw2);\r | |
185 | }\r | |
186 | count++;\r | |
187 | }\r | |
188 | \r | |
189 | /* Close source and destination portfw files */\r | |
190 | fclose (portfw1);\r | |
191 | fclose (portfw2);\r | |
192 | \r | |
193 | /* Move the new portfw file */\r | |
194 | rename ("/harddisk/var/ipcop/portfw/config.new",\r | |
195 | "/harddisk/var/ipcop/portfw/config");\r | |
196 | chown ("/harddisk/var/ipcop/xtaccess/config", 99, 99);\r | |
197 | chown ("/harddisk/var/ipcop/portfw/config", 99, 99);\r | |
198 | \r | |
199 | return 0;\r | |
200 | }\r | |
201 | \r | |
202 | int _convert_pulsardsl() {\r | |
203 | DIR *dirp;\r | |
204 | struct dirent *dp;\r | |
205 | char filename[STRING_SIZE];\r | |
206 | FILE *settings, *pulsardsl;\r | |
207 | char line[STRING_SIZE];\r | |
208 | \r | |
209 | if (!(pulsardsl = fopen ("/harddisk/var/ipcop/pciadsl/settings", "r"))) return 1;\r | |
210 | \r | |
211 | dirp = opendir( "/harddisk/var/ipcop/ppp" );\r | |
212 | while ( (dp = readdir( dirp )) != NULL ) {\r | |
213 | if ( strstr( dp->d_name, "settings" ) == dp->d_name ) {\r | |
214 | snprintf (filename, STRING_SIZE-1, "%s/%s", \r | |
215 | "/harddisk/var/ipcop/ppp", dp->d_name);\r | |
216 | if (!(settings = fopen (filename, "r+"))) {\r | |
217 | closedir(dirp);\r | |
218 | fclose(pulsardsl);\r | |
219 | return 1;\r | |
220 | }\r | |
221 | while (fgets (line, STRING_SIZE, settings) != NULL) {\r | |
222 | if (strstr (line, "TYPE=pulsardsl") == line) {\r | |
223 | fseek(settings,0,SEEK_END);\r | |
224 | rewind(pulsardsl);\r | |
225 | while (fgets(line, STRING_SIZE, pulsardsl) != NULL) {\r | |
226 | fputs (line, settings);\r | |
227 | }\r | |
228 | fclose (settings);\r | |
229 | chown (filename, 99, 99);\r | |
230 | }\r | |
231 | }\r | |
232 | }\r | |
233 | }\r | |
234 | fclose(pulsardsl);\r | |
235 | (void) closedir( dirp );\r | |
236 | \r | |
237 | \r | |
238 | return 0;\r | |
239 | }\r | |
240 | \r | |
241 | int _convert_pulsardsl_ethernet() {\r | |
242 | DIR *dirp;\r | |
243 | struct dirent *dp;\r | |
244 | FILE *ethernet, *settings;\r | |
245 | char line[STRING_SIZE];\r | |
246 | char type[STRING_SIZE];\r | |
247 | char ip[STRING_SIZE];\r | |
248 | char filename[STRING_SIZE];\r | |
249 | \r | |
250 | if (!(ethernet = fopen ("/harddisk/var/ipcop/ethernet/settings", "r"))) return 1;\r | |
251 | \r | |
252 | while (fgets (line, STRING_SIZE, ethernet) != NULL) {\r | |
253 | if (strstr (line, "RED_DRIVER=pciadsl") == line) {\r | |
254 | rewind (ethernet);\r | |
255 | while (fgets (line, STRING_SIZE, ethernet) != NULL) {\r | |
256 | if (strstr (line, "RED_TYPE") == line) {\r | |
257 | strcpy (type, line + 9*sizeof(char));\r | |
258 | if (type[strlen(type) - 1] == '\n')\r | |
259 | type[strlen(type) - 1] = '\0';\r | |
260 | }\r | |
261 | if (strstr (line, "RED_ADDRESS") == line) {\r | |
262 | strcpy (ip, line + 12*sizeof(char));\r | |
263 | if (ip[strlen(ip) - 1] == '\n')\r | |
264 | type[strlen(ip) - 1] = '\0';\r | |
265 | }\r | |
266 | fclose (ethernet);\r | |
267 | \r | |
268 | replace ("/harddisk/var/ipcop/ethernet/settings", "RED_DEV=eth1", "RED_DEV=");\r | |
269 | replace ("/harddisk/var/ipcop/ethernet/settings", "CONFIG_TYPE=2", "CONFIG_TYPE=0");\r | |
270 | replace ("/harddisk/var/ipcop/ethernet/settings", "CONFIG_TYPE=3", "CONFIG_TYPE=1");\r | |
271 | replace ("/harddisk/var/ipcop/ethernet/settings", "RED_DEV=eth2", "RED_DEV=");\r | |
272 | chown ("/harddisk/var/ipcop/ethernet/settings", 99, 99);\r | |
273 | \r | |
274 | dirp = opendir( "/harddisk/var/ipcop/ppp" );\r | |
275 | while ( (dp = readdir( dirp )) != NULL ) {\r | |
276 | if ( strstr( dp->d_name, "settings-" ) == dp->d_name ) {\r | |
277 | snprintf (filename, STRING_SIZE-1, "%s/%s", \r | |
278 | "/harddisk/var/ipcop/ppp", dp->d_name);\r | |
279 | if (!(settings = fopen (filename, "r+"))) \r | |
280 | {\r | |
281 | closedir(dirp);\r | |
282 | return 1;\r | |
283 | }\r | |
284 | while (fgets (line, STRING_SIZE, settings) != NULL) {\r | |
285 | if (strstr (line, "TYPE=pulsardsl") == line) {\r | |
286 | fseek(settings,0,SEEK_END);\r | |
287 | fprintf (settings, "METHOD=%s\n", type);\r | |
288 | fprintf (settings, "IP=%s\n", ip);\r | |
289 | fclose (settings);\r | |
290 | chown (filename, 99, 99);\r | |
291 | }\r | |
292 | }\r | |
293 | }\r | |
294 | }\r | |
295 | (void) closedir( dirp );\r | |
296 | }\r | |
297 | }\r | |
298 | }\r | |
299 | \r | |
300 | return 0;\r | |
301 | }\r | |
302 | \r | |
303 | int upgrade_v12_v13() {\r | |
304 | struct stat s;\r | |
305 | replace ("/harddisk/var/ipcop/ethernet/settings", "rtl8139", "8139too");\r | |
306 | replace ("/harddisk/var/ipcop/vpn/ipsec.conf", "auto=add", "auto=start");\r | |
307 | chown ("/harddisk/var/ipcop/vpn/ipsec.conf", 99, 99);\r | |
308 | chown ("/harddisk/var/ipcop/ethernet/settings", 99, 99);\r | |
309 | chown ("/harddisk/var/ipcop/main/settings", 99, 99);\r | |
310 | _convert_ppp_settings();\r | |
311 | _convert_xtaccess();\r | |
312 | _convert_pulsardsl();\r | |
313 | _convert_pulsardsl_ethernet();\r | |
314 | \r | |
315 | /* Rename usbadsl directory */\r | |
316 | stat ("/harddisk/var/ipcop/usbadsl", &s);\r | |
317 | if (S_ISDIR(s.st_mode)) {\r | |
318 | remove ("/harddisk/var/ipcop/usbadsl/settings");\r | |
319 | if (! system("/bin/chroot /harddisk /bin/rm -rf /var/ipcop/alcatelusb"))\r | |
320 | rename ("/harddisk/var/ipcop/usbadsl", "/harddisk/var/ipcop/alcatelusb");\r | |
321 | }\r | |
322 | \r | |
323 | /* Rename pciadsl module and directory */\r | |
324 | remove ("/harddisk/var/ipcop/pulsar/settings");\r | |
325 | rename ("/harddisk/var/ipcop/pciadsl/pciadsl.o", "/harddisk/var/ipcop/pciadsl/pulsar.o");\r | |
326 | stat ("/harddisk/var/ipcop/pciadsl", &s);\r | |
327 | if (S_ISDIR(s.st_mode)) {\r | |
328 | if (! system("/bin/chroot /harddisk /bin/rm -rf /var/ipcop/pulsardsl"))\r | |
329 | rename ("/harddisk/var/ipcop/pciadsl", "/harddisk/var/ipcop/pulsardsl");\r | |
330 | }\r | |
331 | \r | |
332 | /* Change squid cache directory */\r | |
333 | replace ("/harddisk/var/ipcop/proxy/squid.conf", "/var/spool/squid", "/var/log/cache");\r | |
334 | chown ("/harddisk/var/ipcop/proxy/squid.conf", 99, 99);\r | |
335 | \r | |
336 | /* Change setup user shell */\r | |
337 | replace ("/harddisk/etc/passwd", ":/usr/local/sbin/setup", ":/bin/bash -c /usr/local/sbin/setup");\r | |
338 | \r | |
339 | return 0;\r | |
340 | }\r |