1
|
#!/usr/local/bin/php -f
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
rc.initial.setlanip
|
6
|
part of m0n0wall (http://m0n0.ch/wall)
|
7
|
|
8
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
|
33
|
/* parse the configuration and include all functions used below */
|
34
|
require_once("config.inc");
|
35
|
require_once("functions.inc");
|
36
|
require_once("util.inc");
|
37
|
|
38
|
$fp = fopen('php://stdin', 'r');
|
39
|
|
40
|
do {
|
41
|
$dirs = array();
|
42
|
$dirs = return_dir_as_array("/var/db/pfi/");
|
43
|
if(!is_array($dirs)) {
|
44
|
echo "\nNo capable storage devices detected.\n";
|
45
|
exit;
|
46
|
}
|
47
|
echo "\nDevices capable of config.xml storage:\n";
|
48
|
foreach($dirs as $dir) {
|
49
|
preg_match_all("/capable\_(.*)/",$dir,$match_array);
|
50
|
echo $match_array[1][0] . " ";
|
51
|
}
|
52
|
echo "\n\n";
|
53
|
echo "Enter the device that you wish the";
|
54
|
echo "\n";
|
55
|
echo "{$g['product_name']} configuration file to reside on: ";
|
56
|
$move_config_to_device = chop(fgets($fp));
|
57
|
if ($move_config_to_device == "") {
|
58
|
exit(0);
|
59
|
}
|
60
|
} while (!$move_config_to_device);
|
61
|
|
62
|
mwexec("/bin/mkdir -p /tmp/mnt/cf");
|
63
|
|
64
|
$status = mwexec("/sbin/mount -w -t msdosfs /dev/{$move_config_to_device} /tmp/mnt/cf");
|
65
|
if(!$status) {
|
66
|
echo "Error while mounting {$move_config_to_device}.\n";
|
67
|
exit;
|
68
|
}
|
69
|
|
70
|
echo "\n\nProcessing: ";
|
71
|
$lockkey = lock('config');
|
72
|
echo "moving...";
|
73
|
mwexec("mkdir -p /tmp/mnt/cf/conf/");
|
74
|
mwexec("/bin/mv /cf/conf/config.xml /tmp/mnt/cf/conf/");
|
75
|
echo "removing old...";
|
76
|
echo " nullfs... ";
|
77
|
system("/sbin/umount /cf/conf");
|
78
|
system("/sbin/umount /conf");
|
79
|
mwexec("/bin/rm -rf /conf/*.*");
|
80
|
/* use nullfs to mount */
|
81
|
system("/sbin/mount_nullfs /tmp/mnt/cf/conf /conf");
|
82
|
system("/sbin/mount_nullfs /tmp/mnt/cf /cf");
|
83
|
echo "linking...";
|
84
|
mwexec("/bin/rm -rf /var/db/pfi");
|
85
|
unlock($lockkey);
|
86
|
echo "done.\n";
|
87
|
echo "\nYour configuration has been moved to {$move_config_to_device}\n";
|
88
|
touch("/tmp/config_moved");
|
89
|
fclose($fp);
|
90
|
?>
|