-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheyesis4pi_conf_files_backup.php
102 lines (76 loc) · 2.79 KB
/
eyesis4pi_conf_files_backup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*!***************************************************************************
*! FILE NAME : eyesis4pi_backup.php
*! DESCRIPTION: backup some important files
*! Copyright (C) 2012 Elphel, Inc
*! -----------------------------------------------------------------------------**
*! This program is free software: you can redistribute it and/or modify
*! it under the terms of the GNU General Public License as published by
*! the Free Software Foundation, either version 3 of the License, or
*! (at your option) any later version.
*!
*! This program is distributed in the hope that it will be useful,
*! but WITHOUT ANY WARRANTY; without even the implied warranty of
*! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*! GNU General Public License for more details.
*!
*! The four essential freedoms with GNU GPL software:
*! * the freedom to run the program for any purpose
*! * the freedom to study how the program works and change it to make it do what you wish
*! * the freedom to redistribute copies so you can help your neighbor
*! * the freedom to distribute copies of your modified versions to others
*!
*! You should have received a copy of the GNU General Public License
*! along with this program. If not, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------**
*! $Log: eyesis4pi_backup.php,v $
*/
$BaseIP=221;
$N=9;
$BACKUP_DIR = "EYESIS4PI_BKP_".time();
$pattern = array(
"<textarea rows=20 cols=80 name=content>",
"</textarea>"
);
//full path only
$list = array(
"/etc/autocampars.xml",
"/etc/conf.d/hostname",
"/etc/conf.d/net.eth0",
"/etc/conf.d/mac",
"/usr/html/eyesis_ide.php",
"/etc/imu_logger.xml",
"/etc/10364.config",
);
backup($BaseIP,$N,$BACKUP_DIR,$list);
function backup($ip,$n,$bkp_dir,$list){
if (!is_dir($bkp_dir)) mkdir($bkp_dir);
$RQ = "/admin-bin/editcgi.cgi?file";
for ($i=$ip;$i<($ip+$n);$i++) {
$final_dir = $bkp_dir."/".$i;
if (!is_dir($final_dir)) mkdir($final_dir);
foreach ($list as $file){
create_tree($file,$final_dir);
$content = file_get_contents("http://192.168.0.$i".$RQ."=".$file);
$tmp_arr = get_positions($content);
$content = substr($content,$tmp_arr[0],$tmp_arr[1]-$tmp_arr[0]);
// no need for "/" between names
file_put_contents($final_dir.$file,$content);
}
}
}
function create_tree($file,$path){
$tmp_path = $path;
$arr = explode("/",trim($file,"/"));
for ($i=0;$i<(count($arr)-1);$i++){
$tmp_path .= "/".$arr[$i];
if (!is_dir($tmp_path)) mkdir($tmp_path);
}
}
function get_positions($str){
global $pattern;
$arr[0] = strpos($str,$pattern[0])+strlen($pattern[0])+1;
$arr[1] = strrpos($str,$pattern[1]);
return $arr;
}
?>