]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/install+setup/install/upgrade-v12-v13.c
b8e838ee7c8f97669e3f89a5531d596f96152453
2 * This file is part of the IPCop Firewall.
4 * IPCop is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * IPCop is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with IPCop; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Copyright 2002: Mark Wormgoor <mark@wormgoor.com>
20 * $Id: upgrade-v12-v13.c,v 1.2.2.3 2004/11/11 09:39:25 alanh Exp $
26 void _convert_ppp_settings() {
29 char filename
[STRING_SIZE
];
31 dirp
= opendir( "/harddisk/var/ipcop/ppp" );
32 while ( (dp
= readdir( dirp
)) != NULL
) {
33 if ( strstr( dp
->d_name
, "settings" ) == dp
->d_name
) {
34 snprintf (filename
, STRING_SIZE
-1, "%s/%s",
35 "/harddisk/var/ipcop/ppp", dp
->d_name
);
37 /* reduce furthur replacements from commands below */
38 replace (filename
, "TYPE=modem", "");
39 replace (filename
, "COMPORT=ttyS0", "TYPE=modem\nCOMPORT=ttyS0");
40 replace (filename
, "COMPORT=ttyS1", "TYPE=modem\nCOMPORT=ttyS1");
41 replace (filename
, "COMPORT=ttyS2", "TYPE=modem\nCOMPORT=ttyS2");
42 replace (filename
, "COMPORT=ttyS3", "TYPE=modem\nCOMPORT=ttyS3");
43 /* reduce furthur replacements from commands below */
44 replace (filename
, "TYPE=isdn", "");
45 replace (filename
, "COMPORT=isdn1", "TYPE=isdn\nCOMPORT=isdn1");
46 replace (filename
, "COMPORT=isdn2", "TYPE=isdn\nCOMPORT=isdn2");
47 replace (filename
, "COMPORT=pppoe", "TYPE=pppoe");
48 replace (filename
, "COMPORT=pptp", "TYPE=pptp");
49 replace (filename
, "COMPORT=usbadsl", "TYPE=alcatelusb");
50 replace (filename
, "COMPORT=pppoa", "TYPE=pulsardsl");
52 chown (filename
, 99, 99);
55 (void) closedir( dirp
);
58 int _convert_xtaccess() {
59 int count
=1, count2
=0;
60 FILE *portfw1
, *portfw2
;
61 char portsrctemp
[STRING_SIZE
], portdsttemp
[STRING_SIZE
];
62 char *portproto
, *portsrcip
, *portsrcport
, *portdstip
, *portdstport
, *portenabled
, *portremip
;
64 FILE *xtaccess1
, *xtaccess2
;
65 char xtsrctemp
[STRING_SIZE
], xtdsttemp
[STRING_SIZE
];
66 char *xtproto
, *xtsrcip
, *xtdstip
, *xtdstport
, *xtenabled
;
68 if (!(portfw1
= fopen ("/harddisk/var/ipcop/portfw/config", "r"))) return 1;
69 if (!(portfw2
= fopen ("/harddisk/var/ipcop/portfw/config.new", "w")))
75 while (fgets (portsrctemp
, STRING_SIZE
, portfw1
) != NULL
) {
85 if (!(xtaccess1
= fopen ("/harddisk/var/ipcop/xtaccess/config", "r")))
91 if (!(xtaccess2
= fopen ("/harddisk/var/ipcop/xtaccess/config.new", "w")))
99 if (isdigit (portsrctemp
[0])) {
100 /* Already converted to new format */
101 fputs(portsrctemp
, portfw2
);
105 if (portsrctemp
[strlen(portsrctemp
) - 1] == '\n')
106 portsrctemp
[strlen(portsrctemp
) - 1] = '\0';
107 portproto
= strtok (portsrctemp
, ",");
108 portsrcport
= strtok (NULL
, ",");
109 portdstip
= strtok (NULL
, ",");
110 portdstport
= strtok (NULL
, ",");
111 portenabled
= strtok (NULL
, ",");
112 portsrcip
= strtok (NULL
, ",");
113 portremip
= strtok (NULL
, ",");
114 if (!(portproto
&& portsrcport
&& portdstip
&&
115 portdstport
&& portenabled
))
118 if (portsrcip
== NULL
) portsrcip
= strdup ("0.0.0.0");
120 while (fgets (xtsrctemp
, STRING_SIZE
, xtaccess1
)) {
127 if (xtsrctemp
[strlen(xtsrctemp
) - 1] == '\n')
128 xtsrctemp
[strlen(xtsrctemp
) - 1] = '\0';
129 xtproto
= strtok (xtsrctemp
, ",");
130 xtsrcip
= strtok (NULL
, ",");
131 xtdstport
= strtok (NULL
, ",");
132 xtenabled
= strtok (NULL
, ",");
133 xtdstip
= strtok (NULL
, ",");
134 if (!(xtproto
&& xtsrcip
&& xtdstport
&& xtenabled
)) continue;
136 if (xtdstip
== NULL
) xtdstip
= strdup ("0.0.0.0");
138 if (strcmp (portproto
, xtproto
) == 0 &&
139 strcmp (portsrcport
, xtdstport
) == 0 &&
140 strcmp (portsrcip
, xtdstip
) == 0) {
141 portremip
= strdup (xtsrcip
);
142 if ((strcmp (portremip
, "0.0.0.0/0") == 0) && (count2
== 0)) {
143 sprintf (portdsttemp
, "%d,%d,%s,%s,%s,%s,%s,%s,%s\n",
144 count
, count2
, portproto
, portsrcport
, portdstip
,
145 portdstport
, portenabled
, portsrcip
, portremip
);
146 fputs(portdsttemp
, portfw2
);
149 sprintf (portdsttemp
, "%d,%d,%s,%s,%s,%s,%s,%s,%d\n",
150 count
,count2
,portproto
, portsrcport
, portdstip
,
151 portdstport
, portenabled
, portsrcip
, 0);
152 fputs(portdsttemp
, portfw2
);
155 sprintf (portdsttemp
, "%d,%d,%s,%d,%s,%s,%s,%d,%s\n",
156 count
,count2
,portproto
, 0, portdstip
,
157 portdstport
, portenabled
, 0, portremip
);
158 fputs(portdsttemp
, portfw2
);
162 sprintf (xtdsttemp
, "%s,%s,%s,%s,%s\n",
163 xtproto
, xtsrcip
, xtdstport
, xtenabled
, xtdstip
);
164 fputs(xtdsttemp
, xtaccess2
);
168 /* Close source and destination xtaccess files */
172 /* Move the new xtaccess file */
173 rename ("/harddisk/var/ipcop/xtaccess/config.new",
174 "/harddisk/var/ipcop/xtaccess/config");
176 /* If no external access line existed, add a no access line */
178 if (portremip
== NULL
) portremip
= strdup ("127.0.0.1/32");
180 /* Print new port forwarding line to file */
181 sprintf (portdsttemp
, "%d,%d,%s,%s,%s,%s,%s,%s,%s\n",
182 count
, count2
, portproto
, portsrcport
, portdstip
,
183 portdstport
, portenabled
, portsrcip
, portremip
);
184 fputs(portdsttemp
, portfw2
);
189 /* Close source and destination portfw files */
193 /* Move the new portfw file */
194 rename ("/harddisk/var/ipcop/portfw/config.new",
195 "/harddisk/var/ipcop/portfw/config");
196 chown ("/harddisk/var/ipcop/xtaccess/config", 99, 99);
197 chown ("/harddisk/var/ipcop/portfw/config", 99, 99);
202 int _convert_pulsardsl() {
205 char filename
[STRING_SIZE
];
206 FILE *settings
, *pulsardsl
;
207 char line
[STRING_SIZE
];
209 if (!(pulsardsl
= fopen ("/harddisk/var/ipcop/pciadsl/settings", "r"))) return 1;
211 dirp
= opendir( "/harddisk/var/ipcop/ppp" );
212 while ( (dp
= readdir( dirp
)) != NULL
) {
213 if ( strstr( dp
->d_name
, "settings" ) == dp
->d_name
) {
214 snprintf (filename
, STRING_SIZE
-1, "%s/%s",
215 "/harddisk/var/ipcop/ppp", dp
->d_name
);
216 if (!(settings
= fopen (filename
, "r+"))) {
221 while (fgets (line
, STRING_SIZE
, settings
) != NULL
) {
222 if (strstr (line
, "TYPE=pulsardsl") == line
) {
223 fseek(settings
,0,SEEK_END
);
225 while (fgets(line
, STRING_SIZE
, pulsardsl
) != NULL
) {
226 fputs (line
, settings
);
229 chown (filename
, 99, 99);
235 (void) closedir( dirp
);
241 int _convert_pulsardsl_ethernet() {
244 FILE *ethernet
, *settings
;
245 char line
[STRING_SIZE
];
246 char type
[STRING_SIZE
];
247 char ip
[STRING_SIZE
];
248 char filename
[STRING_SIZE
];
250 if (!(ethernet
= fopen ("/harddisk/var/ipcop/ethernet/settings", "r"))) return 1;
252 while (fgets (line
, STRING_SIZE
, ethernet
) != NULL
) {
253 if (strstr (line
, "RED_DRIVER=pciadsl") == line
) {
255 while (fgets (line
, STRING_SIZE
, ethernet
) != NULL
) {
256 if (strstr (line
, "RED_TYPE") == line
) {
257 strcpy (type
, line
+ 9*sizeof(char));
258 if (type
[strlen(type
) - 1] == '\n')
259 type
[strlen(type
) - 1] = '\0';
261 if (strstr (line
, "RED_ADDRESS") == line
) {
262 strcpy (ip
, line
+ 12*sizeof(char));
263 if (ip
[strlen(ip
) - 1] == '\n')
264 type
[strlen(ip
) - 1] = '\0';
268 replace ("/harddisk/var/ipcop/ethernet/settings", "RED_DEV=eth1", "RED_DEV=");
269 replace ("/harddisk/var/ipcop/ethernet/settings", "CONFIG_TYPE=2", "CONFIG_TYPE=0");
270 replace ("/harddisk/var/ipcop/ethernet/settings", "CONFIG_TYPE=3", "CONFIG_TYPE=1");
271 replace ("/harddisk/var/ipcop/ethernet/settings", "RED_DEV=eth2", "RED_DEV=");
272 chown ("/harddisk/var/ipcop/ethernet/settings", 99, 99);
274 dirp
= opendir( "/harddisk/var/ipcop/ppp" );
275 while ( (dp
= readdir( dirp
)) != NULL
) {
276 if ( strstr( dp
->d_name
, "settings-" ) == dp
->d_name
) {
277 snprintf (filename
, STRING_SIZE
-1, "%s/%s",
278 "/harddisk/var/ipcop/ppp", dp
->d_name
);
279 if (!(settings
= fopen (filename
, "r+")))
284 while (fgets (line
, STRING_SIZE
, settings
) != NULL
) {
285 if (strstr (line
, "TYPE=pulsardsl") == line
) {
286 fseek(settings
,0,SEEK_END
);
287 fprintf (settings
, "METHOD=%s\n", type
);
288 fprintf (settings
, "IP=%s\n", ip
);
290 chown (filename
, 99, 99);
295 (void) closedir( dirp
);
303 int upgrade_v12_v13() {
305 replace ("/harddisk/var/ipcop/ethernet/settings", "rtl8139", "8139too");
306 replace ("/harddisk/var/ipcop/vpn/ipsec.conf", "auto=add", "auto=start");
307 chown ("/harddisk/var/ipcop/vpn/ipsec.conf", 99, 99);
308 chown ("/harddisk/var/ipcop/ethernet/settings", 99, 99);
309 chown ("/harddisk/var/ipcop/main/settings", 99, 99);
310 _convert_ppp_settings();
312 _convert_pulsardsl();
313 _convert_pulsardsl_ethernet();
315 /* Rename usbadsl directory */
316 stat ("/harddisk/var/ipcop/usbadsl", &s
);
317 if (S_ISDIR(s
.st_mode
)) {
318 remove ("/harddisk/var/ipcop/usbadsl/settings");
319 if (! system("/bin/chroot /harddisk /bin/rm -rf /var/ipcop/alcatelusb"))
320 rename ("/harddisk/var/ipcop/usbadsl", "/harddisk/var/ipcop/alcatelusb");
323 /* Rename pciadsl module and directory */
324 remove ("/harddisk/var/ipcop/pulsar/settings");
325 rename ("/harddisk/var/ipcop/pciadsl/pciadsl.o", "/harddisk/var/ipcop/pciadsl/pulsar.o");
326 stat ("/harddisk/var/ipcop/pciadsl", &s
);
327 if (S_ISDIR(s
.st_mode
)) {
328 if (! system("/bin/chroot /harddisk /bin/rm -rf /var/ipcop/pulsardsl"))
329 rename ("/harddisk/var/ipcop/pciadsl", "/harddisk/var/ipcop/pulsardsl");
332 /* Change squid cache directory */
333 replace ("/harddisk/var/ipcop/proxy/squid.conf", "/var/spool/squid", "/var/log/cache");
334 chown ("/harddisk/var/ipcop/proxy/squid.conf", 99, 99);
336 /* Change setup user shell */
337 replace ("/harddisk/etc/passwd", ":/usr/local/sbin/setup", ":/bin/bash -c /usr/local/sbin/setup");