This repository has been archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscheduled.php
executable file
·379 lines (324 loc) · 13.8 KB
/
scheduled.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<?php
/*
+--------------------------------------------------------------------------+
| phpMyBackupPro |
+--------------------------------------------------------------------------+
| Copyright (c) 2004-2015 by Dirk Randhahn |
| http://www.phpMyBackupPro.net |
| version information can be found in definitions.php. |
| |
| 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 2 |
| 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. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program; if not, write to the Free Software |
| Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.|
+--------------------------------------------------------------------------+
*/
require_once "login.php";
// used variables
if (!isset($_POST['db'])) {
$_POST['db'] = false;
}
if (!isset($_POST['tables'])) {
$_POST['tables'] = false;
}
if (!isset($_POST['data'])) {
$_POST['data'] = false;
}
if (!isset($_POST['zip'])) {
$_POST['zip'] = false;
}
if (!isset($_POST['drop'])) {
$_POST['drop'] = false;
}
if (!isset($_POST['man_dirs'])) {
$_POST['man_dirs'] = false;
}
if (!isset($_POST['comments'])) {
$_POST['comments'] = false;
}
if (!isset($_POST['packed'])) {
$_POST['packed'] = false;
}
PMBP_print_header(preg_replace("#.*/#", "", $_SERVER['SCRIPT_NAME']));
// if first use or no db-connection possible
if (!PMBP_mysql_connect()) {
echo PMBP_addOutput(I_SQL_ERROR, "red");
}
// check if a db or directory was posted
if (isset($_POST['dirs'])) {
if (is_array($_POST['db']) || is_array($_POST['dirs']) || $_POST['man_dirs']) {
$selection_ok = true;
} else {
$selection_ok = false;
}
} elseif ($_POST['man_dirs']) {
$selection_ok = true;
} elseif (isset($_POST['db'])) {
if (is_array($_POST['db'])) {
$selection_ok = true;
} else {
$selection_ok = false;
}
} elseif (isset($_POST)) {
$selection_ok = false;
}
// generate and print php script
if ($selection_ok) {
$cmp = 0;
$pos = 0;
while ($cmp == 0) {
$cmp = strncasecmp($_POST['path'], $_SERVER['DOCUMENT_ROOT'], ++$pos);
}
// echo $_POST['path'];
// echo $_POST['path']= substr($_POST['path'],$pos-1);
// echo $_POST['path']= substr($_SERVER['DOCUMENT_ROOT'],$pos-1);
// create path to scheduled.php
// $path_back="";
// if (strstr($_SERVER['SCRIPT_NAME'],"\\")) $delimiter="\\"; else $delimiter="/";
// $script_path=explode($delimiter,$_SERVER['SCRIPT_NAME']);
// $path_d=count(explode("..",$_POST['path']))-1;
// $path_u=count(explode($delimiter,$_POST['path']))-$path_d-1;
// for ($i=0;$i<$path_u;$i++) $path_back.="../";
// for ($i=count($script_path)-$path_d-1;$i<count($script_path)-1;$i++) $path_back.=$script_path[$i]."/";
//
// // set sql server in multi server mode
// if (count($CONF['sql_passwd_s'])) {
// if ($CONF['sql_host']==$_SESSION['sql_host_org'] && $CONF['sql_user']==$_SESSION['sql_user_org']) {
// $_POST['mysql_host']=-1;
// } else {
// for($i=0;$i<count($CONF['sql_passwd_s']);$i++) {
// if ($CONF['sql_host']==$CONF['sql_host_s'][$i] && $CONF['sql_user']==$CONF['sql_user_s'][$i]) $_POST['mysql_host']=$i;
// }
// }
// }
// generate the dynamic php script
$result = "<?php\n";
$result .= "// This script was created by phpMyBackupPro " . PMBP_VERSION . " (" . PMBP_WEBSITE . ")\n";
$result .= "// In order to work probably, it must be saved in the directory " . $_POST['path'] . ".\n";
// list dbs
if (is_array($_POST['db'])) {
$result .= "\$_POST['db']=array(";
foreach ($_POST['db'] as $value) {
$result .= "\"" . $value . "\", ";
}
$result .= ");\n";
}
// list directories
if (isset($_POST['dirs'])) {
$result .= "\$_POST['dirs']=array(";
foreach ($_POST['dirs'] as $value) {
$result .= "\"" . $value . "\", ";
}
$result .= ");\n";
}
// print the backup options
foreach ($_POST as $key => $value) {
$value = str_replace("\"", "'", $value);
if ($key != "period" && $key != "path" && $key != "db" && $key != "dirs" && $key != "filename" && $value != '') {
$result .= "\$_POST['" . $key . "']=\"" . $value . "\";\n";
}
}
// print the current working database (but always only once)
if (isset($_SESSION['wss']) && !isset($_POST['mysql_host'])) {
$result .= "\$_POST['mysql_host']=\"" . $_SESSION['wss'] . "\";\n";
}
// add include(backup.php) to do all the work
$result .= "\$period=(3600*24)" . str_replace(array(';', '$', '+'), '', $_POST['period']) . ";\n";
$result .= "\$security_key=\"" . ($PMBP_SYS_VAR['security_key']) . "\";\n";
$result .= "// switch to the phpMyBackupPro " . PMBP_VERSION . " directory\n";
// $result .= "@chdir(\"" . $_SERVER['DOCUMENT_ROOT'] . "\");\n";
$result .= "@include(\"backup.php\");\n";
$result .= "// switch back to the directory containing this script\n";
$result .= "@chdir(\"" . $_POST['path'] . "\");\n";
$result .= "?>";
// show the generated php script
printf(PMBP_EXS_INCL, $_POST['path'] . "???.php");
echo ":\n<br><textarea name=\"code\" rows=\"16\" cols=\"120\" readOnly>" . $result . "</textarea>\n<br><br>";
echo "<form name=\"save\" action=\"scheduled.php\" method=\"post\">\n";
// list all post variables as hidden fields
foreach ($_POST as $key => $value) {
if ($key != "db" && $key != "dirs") {
echo "<input type=\"hidden\" name=\"" . $key . "\" value=\"" . $value . "\">\n";
} elseif (is_array($_POST[$key])) {
foreach ($value as $dbname) {
echo "<input type=\"hidden\" name=\"" . $key . "[]\" value=\"" . $dbname . "\">\n";
}
}
}
// save file including the backup script
if (isset($_POST['filename'])) {
if (PMBP_save_to_file($_POST['path'] . $_POST['filename'], "", $result, "w")) {
echo PMBP_addOutput(EX_SAVED . " " . $_POST['path'] . $_POST['filename'], "green_left");
@chmod($_POST['path'] . $_POST['filename'], 0644);
// save specific settings for scheduled backups
if ($PMBP_SYS_VAR['EXS_scheduled_file'] != $_POST['filename']) {
$PMBP_SYS_VAR['EXS_scheduled_file'] = $_POST['filename'];
}
} else {
echo PMBP_addOutput(C_WRITE . " " . $_POST['path'] . $_POST['filename'], "red_left");
}
}
echo PMBP_EXS_SAVE . ":<br>\n";
echo $_POST['path'] . "<input type=\"text\" name=\"filename\" value=\"" . $PMBP_SYS_VAR['EXS_scheduled_file'] . "\"> ";
echo "<input type=\"submit\" value=\"" . C_SAVE . "\">";
if ($PMBP_SYS_VAR['EXS_scheduled_file'] != "???.php") {
echo " (<a href=\"\">" . PMBP_pop_up("get_file.php?view=" . $_POST['path'] . $PMBP_SYS_VAR['EXS_scheduled_file'], B_VIEW, "view") . "</a>)";
}
echo "</form>";
echo "\n<a href=\"scheduled.php\"> <- " . EXS_BACK . "</a>\n";
// update specific settings for scheduled backups
if ($_POST['path'] != $PMBP_SYS_VAR['EXS_scheduled_dir'] or $_POST['period'] != $PMBP_SYS_VAR['EXS_period']) {
$PMBP_SYS_VAR['EXS_scheduled_dir'] = $_POST['path'];
$PMBP_SYS_VAR['EXS_period'] = $_POST['period'];
}
// save PMBP_SYS_VARS
PMBP_save_export_settings();
// print instructions and export form
} else {
if (isset($selection_ok) && isset($_POST['period'])) {
echo PMBP_addOutput(EX_NO_DB . "!", "red");
}
echo "<form name=\"backup\" action=\"scheduled.php\" method=\"post\">\n<div>\n";
echo EXS_PERIOD . ":<br>\n";
echo "<select name=\"period\">\n";
if ($PMBP_SYS_VAR['EXS_period'] == "*0") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"*0\"" . $selected . ">" . PMBP_EXS_ALWAYS . "</option>\n";
echo "<option>---------------------</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "/24") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"/24\"" . $selected . ">1 " . EXS_HOUR . "</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "/4") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"/4\"" . $selected . ">6 " . EXS_HOURS . "</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "/2") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"/2\"" . $selected . ">12 " . EXS_HOURS . "</option>\n";
echo "<option>---------------------</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "*1") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"*1\"" . $selected . ">1 " . EXS_DAY . "</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "*2") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"*2\"" . $selected . ">2 " . EXS_DAYS . "</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "*3") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"*3\"" . $selected . ">3 " . EXS_DAYS . "</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "*5") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"*5\"" . $selected . ">5 " . EXS_DAYS . "</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "*10") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"*10\"" . $selected . ">10 " . EXS_DAYS . "</option>\n";
echo "<option>---------------------</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "*7") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"*7\"" . $selected . ">1 " . EXS_WEEK . "</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "*14") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"*14\"" . $selected . ">2 " . EXS_WEEKS . "</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "*21") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"*21\"" . $selected . ">3 " . EXS_WEEKS . "</option>\n";
echo "<option>---------------------</option>\n";
if ($PMBP_SYS_VAR['EXS_period'] == "*30") {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value=\"*30\"" . $selected . ">1 " . EXS_MONTH . " (30 " . EXS_DAYS . ")</option>\n";
echo "</select>\n<br><br>";
// get content of these directories (I know, it's partly redundant - but I think this is necessary)
if ($_SESSION['multi_user_mode']) {
$search_path1 = $PMBP_MU_CONF['user_export_dir'];
$search_path2 = $PMBP_MU_CONF['user_scheduled_dir'];
} else {
$search_path1 = substr($_SERVER['DOCUMENT_ROOT'], 0, strrpos($_SERVER['DOCUMENT_ROOT'], "/"));
$search_path2 = substr($search_path1, 0, strrpos($search_path1, "/"));
$search_path1 .= "/";
// $search_path1=$_SERVER['DOCUMENT_ROOT']."/"."../";
// $search_path2=$_SERVER['DOCUMENT_ROOT']."/"."../../";
}
if ($PMBP_SYS_VAR['dir_lists'] >= 1) {
$dirs1 = PMBP_get_dirs($search_path1);
}
if ($PMBP_SYS_VAR['dir_lists'] >= 2) {
$dirs2 = PMBP_get_dirs($search_path2);
}
echo EXS_PATH . ": (<a href=\"scheduled.php?update_dir_list=TRUE\">" . PMBP_EXS_UPDATE_DIRS . "</a>)<br>\n";
echo "<select name=\"path\">\n";
//echo " <option value=\"/\" selected>./</option>\n";
if (isset($dirs1)) {
foreach ($dirs1 as $value) {
if ($PMBP_SYS_VAR['EXS_scheduled_dir'] == $search_path1 . $value) {
echo "<option value=\"" . $search_path1 . $value . "\" selected>" . $search_path1 . $value . "</option>\n";
} else {
echo "<option value=\"" . $search_path1 . $value . "\">" . $search_path1 . $value . "</option>\n";
}
}
}
if (isset($dirs2)) {
echo "<option value=\"\">----------------------------</option>\n";
foreach ($dirs2 as $value) {
if ($PMBP_SYS_VAR['EXS_scheduled_dir'] == $search_path1 . $value) {
echo "<option value=\"" . $search_path2 . $value . "\" selected>" . $search_path2 . $value . "</option>\n";
} else {
echo "<option value=\"" . $search_path2 . $value . "\">" . $search_path2 . $value . "</option>\n";
}
}
}
echo "</select>\n<br><br>";
// include the export form (known from the export page) and submitt the file list
if (isset($dirs1)) {
PMBP_print_export_form($dirs1, true);
} else {
PMBP_print_export_form(false, true);
}
echo "\n<input type=\"submit\" value=\"" . EXS_SHOW . "\" class=\"button\">\n</div>\n</form>";
}
PMBP_print_footer();