-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfunctions.inc.php
executable file
·2160 lines (1855 loc) · 75.8 KB
/
functions.inc.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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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.|
+--------------------------------------------------------------------------+
*/
// default debug function
function PMBP_debug($object)
{
echo "<pre>";
print_r($object);
echo "</pre>";
}
// prints the basis html header in the $lang language with $scriptname scriptname
function PMBP_print_header($scriptname)
{
global $CONF;
global $_POST;
global $PMBP_SYS_VAR;
global $PMBP_MU_CONF;
// register callback handler
ob_start("PMBP_shutdown_handler");
if (!isset($CONF['stylesheet'])) {
$CONF['stylesheet'] = "standard";
}
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">
<html" . ARABIC_HTML . ">
<head>
<title>phpMyBackupPro " . PMBP_VERSION;
// print mu mode info in browser title
if ($_SESSION['multi_user_mode']) {
echo " (Multi User Mode)";
}
if (isset($_SESSION['sql_user']) && isset($_SESSION['sql_passwd'])) {
if ($_SESSION['sql_user'] && $_SESSION['sql_user'] == $PMBP_MU_CONF['sql_user_admin'] && $_SESSION['sql_passwd'] == $PMBP_MU_CONF['sql_passwd_admin']) {
echo " (Multi User Mode Administration)";
}
}
if (!file_exists(PMBP_STYLESHEET_DIR . $CONF['stylesheet'] . ".css")) {
if (!file_exists(PMBP_STYLESHEET_DIR . ($CONF['stylesheet'] = "standard") . "css")) {
echo "STYLESHEET IS MISSING!";
}
}
echo "</title>
<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">
<meta name=\"robots\" content=\"noindex\">
<meta name=\"robots\" content=\"nofollow\">
<link href=\"images/favicon.png\" type=\"image/png\" rel=\"icon\">
<link rel=\"stylesheet\" href=\"" . PMBP_STYLESHEET_DIR . $CONF['stylesheet'] . ".css\" type=\"text/css\">
";
readfile(PMBP_JAVASCRIPTS);
// define menue
$menu = array("index.php" => F_START);
// disable config tab
if (!$PMBP_SYS_VAR['C_disable_config']) {
$menu = array_merge($menu, array("config.php" => F_CONFIG));
}
$menu = array_merge($menu, array("import.php" => F_IMPORT, "backup.php" => F_BACKUP, "scheduled.php" => F_SCHEDULE, "db_info.php" => F_DB_INFO));
// disable sql queries in mu mode if allow_sql_queries is false or if the system-variable C_disable_sqlquery is set
if ((!$PMBP_SYS_VAR['C_disable_sqlquery'] && $_SESSION['multi_user_mode'] && $PMBP_MU_CONF['allow_sql_queries']) || (!$PMBP_SYS_VAR['C_disable_sqlquery'] && !$_SESSION['multi_user_mode'])) {
$menu = array_merge($menu, array("sql_query.php" => F_SQL_QUERY));
}
$accesskeys = array("index.php" => "m", "config.php" => "c", "import.php" => "i", "backup.php" => "b", "scheduled.php" => "s", "db_info.php" => "d", "sql_query.php" => "q", "logout" => "l", "help" => "h");
$simple_width = 140;
$width = count($menu) * $simple_width;
echo "</head>
<body><center>
<table width=\"" . $width . "\">
<colgroup>
<col span=\"" . count($menu) . "\" width=\"" . $simple_width . "\">
</colgroup>
<tr>
<th colspan=\"" . count($menu) . "\" class=\"active\" id=\"menu\">\n";
// print titel
echo "<div id=\"logo\">\n";
echo PMBP_image_tag("logo.png", "phpMyBackupPro", "phpMyBackupPro Homepage", PMBP_WEBSITE);
echo " " . PMBP_VERSION . "\n";
// support links
echo "<div style=\"position:relative;left:380px;top:-40px\">";
echo "\n<a href=\"http://sourceforge.net/donate/index.php?group_id=76148\"><img src=\"http://images.sourceforge.net/images/project-support.jpg\" width=\"88\" height=\"32\" border=\"0\" alt=\"Support phpMyBackupPro\" /> </a>";
echo "\n<a href=\"http://flattr.com/thing/464503/phpMyBackupPro-the-MySQL-backup-tool\" target=\"_blank\" >\n<img src=\"http://api.flattr.com/button/flattr-badge-large.png\" alt=\"Flattr this\" title=\"Flattr this\" border=\"0\" /></a>";
echo "</div>";
echo "</div>\n<div id=\"help\">\n";
// generate popup link for proper help file
if (!file_exists("./" . PMBP_LANGUAGE_DIR . $CONF['lang'] . "_help.php")) {
echo PMBP_pop_up("./" . PMBP_LANGUAGE_DIR . "english_help.php?script=" . $scriptname, PMBP_image_tag("help.gif", "", "help") . F_HELP, "help", "help");
} else {
echo PMBP_pop_up("./" . PMBP_LANGUAGE_DIR . $CONF['lang'] . "_help.php?script=" . $scriptname, PMBP_image_tag("help.gif", "", "help") . F_HELP, "help", "help");
}
echo "\n</div>\n<div id=\"logout\">\n";
// print logout link if function is not disabled
if (!($CONF['no_login'] == "1" && $CONF['login'] == "0")) {
echo "<a href=\"login.php?logout=TRUE\" accesskey=\"l\" title=\"[access key = l]\">";
echo PMBP_image_tag("login.gif", "", "[access key = l]");
echo F_LOGOUT . "</a>\n";
}
echo "\n</div>\n";
echo " </th>\n";
// print selection for several sql servers
if (count($CONF['sql_passwd_s']) && basename($_SERVER['SCRIPT_NAME']) !== "config.php" && !isset($_POST['period'])) {
echo " </tr>
<tr>
<th colspan=\"" . count($menu) . "\">
<form action=\"" . basename($_SERVER['SCRIPT_NAME']) . "\" method=\"POST\">
<span class=\"bold_left\">Select working SQL server:</span>
<select name=\"mysql_host\" onchange=\"submit()\">\n";
if ($CONF['sql_host'] == $_SESSION['sql_host_org'] && $CONF['sql_user'] == $_SESSION['sql_user_org']) {
echo "<option value=\"-1\" selected>" . $_SESSION['sql_host_org'] . " (" . $_SESSION['sql_user_org'] . ")</option>\n";
} else {
echo "<option value=\"-1\">" . $_SESSION['sql_host_org'] . " (" . $_SESSION['sql_user_org'] . ")</option>\n";
}
for ($i = 0; $i < count($CONF['sql_passwd_s']); $i++) {
if (isset($CONF['sql_host_s'])) {
if ($CONF['sql_host'] == $CONF['sql_host_s'][$i] && $CONF['sql_user'] == $CONF['sql_user_s'][$i]) {
echo "<option value=\"" . $i . "\" selected>" . $CONF['sql_host_s'][$i] . " (" . $CONF['sql_user_s'][$i] . ")</option>\n";
} else {
echo "<option value=\"" . $i . "\">" . $CONF['sql_host_s'][$i] . " (" . $CONF['sql_user_s'][$i] . ")</option>\n";
}
} else {
echo "<option value=\"" . $i . "\">" . $CONF['sql_host_s'][$i] . " (" . $CONF['sql_user_s'][$i] . ")</option>\n";
}
}
echo " </select></form>
</th>\n";
}
echo " </tr>
<!-- MENU -->
<tr>\n";
// generate menu
foreach ($menu as $filename => $title) {
// print active link
if ($filename == $scriptname && $filename != "login.php?logout=TRUE" && $filename != "HELP") {
echo " <th class=\"active\">\n <a href=\"" . $filename . "\" accesskey=\"" . $accesskeys[$filename] . "\" title=\"[access key = " . $accesskeys[$filename] . "]\">" . PMBP_image_tag(substr($filename, 0, strpos($filename, ".")) . ".gif", "", "[accesskey = " . $accesskeys[$filename] . "]") . $title . "</a>\n </th>\n";
// print lasting menu
} elseif ($filename != "login.php?logout=TRUE" && $filename != "HELP") {
echo " <th>\n <a href=\"" . $filename . "\" accesskey=\"" . $accesskeys[$filename] . "\" title=\"[access key = " . $accesskeys[$filename] . "]\">" . PMBP_image_tag(substr($filename, 0, strpos($filename, ".")) . ".gif", "", "[accesskey = " . $accesskeys[$filename] . "]") . $title . "</a>\n </th>\n";
}
}
echo " </tr>
</table>
<table width=\"" . $width . "\">
<colgroup>
<col width=\"20\">
<col width=\"*\">
<col width=\"20\">
</colgroup>
<tr>
<td>
</td>
<td class=\"main\">
<!-- HEADER END -->
";
}
// print basis html footer
function PMBP_print_footer()
{
global $PMBP_SYS_VAR;
global $PMBP_MU_CONF;
// print but do not call the callback handler of ob_start()
ob_flush();
ob_end_clean();
// adjust width of table to the number of menu items
if (($_SESSION['multi_user_mode'] && $PMBP_MU_CONF['allow_sql_queries']) || !$_SESSION['multi_user_mode']) {
$tabe_width = 980;
} else {
$tabe_width = 840;
}
echo "\n<!-- FOOTER -->
</td>
<td>
</td>
</tr>
</table>
<table width=\"" . $tabe_width . "\">
<tr>
<th class=\"active\">\n";
printf(F_FOOTER, "<a target='_blank' href=\"" . PMBP_WEBSITE . "\">", "</a>");
echo "\n</th>\n </tr>\n";
// check for updates
if ($PMBP_SYS_VAR['F_updates']) {
// do this only once per session
if (!$_SESSION['multi_user_mode'] && !isset($_SESSION['PMBP_VERSION'])) {
$_SESSION['PMBP_VERSION'] = false;
// check web connection
$ping_res = PMBP_is_connected();
if ($ping_res) {
if (isset($CONF['sql_host_s'])) {
$mode = $_SESSION['multi_user_mode'] ? 'm' : 's'+count($CONF['sql_host_s']) ? 'm' : 's';
}
@set_time_limit("5");
if (isset($PMBP_SYS_VAR['security_key'])) {
$last_vers = @file("http://www.phpMyBackupPro.net/vers.php?v=" . PMBP_VERSION . "&m=" . $mode . "&c=" . count($CONF['sql_host_s']) . "&k=" . md5($PMBP_SYS_VAR['security_key']));
} else {
$last_vers = @file("http://www.phpMyBackupPro.net/vers.php?v=" . PMBP_VERSION . "&m=" . $mode . "&c=" . count($CONF['sql_host_s']));
}
@set_time_limit("30");
if ($last_vers) {
if (floatval($last_vers[0]) > floatval(PMBP_VERSION)) {
$_SESSION['PMBP_VERSION'] = true;
}
}
}
}
// new version found, print hint
if ($_SESSION['PMBP_VERSION']) {
echo "\n <tr>
<td class=\"red large12\">
";
printf(F_NOW_AVAILABLE, "<a href=\"" . PMBP_WEBSITE . "\">", "</a>");
echo " !!!<br><br>
</td>
</tr>\n";
}
}
// set to 0 if you don't want to see the PHP version hint any more
if (1) {
// check PHP version
$tmp = phpversion();
$phpvers = $tmp[0] . $tmp[1] . $tmp[2];
if ($phpvers < 4.3) {
echo "<tr><td>PHP " . $tmp . " detected. It is not recommended to use phpMyBackupPro with PHP < PHP 4.3. You can disable this message if you want in functions.inc.php line " . __LINE__ . ".</td></tr>";
}
}
// set F_ffadd on the configuration page to 0 if you don't want to see the Firefox add any more
if ($PMBP_SYS_VAR['F_ffadd']) {
// removed with v2.2
}
;
echo "
</table>
</center>
</body>
</html>
";
}
// checks if the server is connected to the web
function PMBP_is_connected()
{
$timeout = 5; //timeout in seconds
$connected = @fsockopen("phpmybackup.sourceforge.net", 80, $dontCare1, $dontCare2, $timeout);
if ($connected) {
fclose($connected);
return true;
} else {
return false;
}
}
//
function PMBP_mysql_connect()
{
global $CONF;
$res = @mysqli_connect($CONF['sql_host'], $CONF['sql_user'], $CONF['sql_passwd']);
if ($res) {
PMBP_set_character_set($res);
}
return $res;
}
function PMBP_set_character_set($con)
{
$characterSet = PMBP_get_character_set($con);
$characterSet = "utf8";
@mysqli_set_charset($con, $characterSet);
// @mysqli_query("set names " . $characterSet);
return $characterSet;
}
// prints html export form used on several pages
function PMBP_print_export_form($dirs1 = false, $scheduled = false)
{
global $CONF;
global $PMBP_SYS_VAR;
echo "\n<table width=\"940\">\n";
echo "<tr>\n<td>\n";
echo F_SELECT_DB . ":\n";
echo "</td>\n<td> </td>\n<td>";
echo F_COMMENTS . ":";
echo "</td>\n</tr><tr>\n<td>\n";
echo "<select name=\"db[]\" multiple=\"multiple\" size=\"10\">\n";
if (!$con = PMBP_mysql_connect());
// find the availabe compression methods and set which are disabled and which is selected
if (!@function_exists("gzopen") || !@function_exists("gzcompress")) {
$disable_gzip = " disabled";
} else {
$disable_gzip = "";
}
$last_dbs = explode("|", $PMBP_SYS_VAR['F_dbs']);
if (count($db_list = PMBP_get_db_list()) > 0) {
foreach ($db_list as $db) {
if (in_array($db, $last_dbs)) {
echo "<option value=\"" . $db . "\" selected>" . $db . "</option>\n";
} else {
echo "<option value=\"" . $db . "\">" . $db . "</option>\n";
}
}
} else {
echo "<option></option>\n";
}
echo "</select>\n<br>";
echo PMBP_set_select("backup", "db[]", "[" . F_SELECT_ALL . "]");
echo "\n</td>\n<td> </td>\n<td>\n";
echo "<textarea name=\"comments\" rows=\"9\" cols=\"80\">" . $PMBP_SYS_VAR['F_comment'] . "</textarea>\n<br>";
if ($PMBP_SYS_VAR['F_tables']) {
$checked = "checked";
} else {
$checked = "";
}
echo "<input type=\"checkbox\" name=\"tables\" " . $checked . ">" . F_EX_TABLES . " | ";
if ($PMBP_SYS_VAR['F_data']) {
$checked = "checked";
} else {
$checked = "";
}
echo "<input type=\"checkbox\" name=\"data\" " . $checked . ">" . F_EX_DATA . " | ";
if ($PMBP_SYS_VAR['F_drop']) {
$checked = "checked";
} else {
$checked = "";
}
echo "<input type=\"checkbox\" name=\"drop\" " . $checked . ">" . F_EX_DROP . " | ";
$comp_off = $comp_gzip = $comp_zip = "";
if ($PMBP_SYS_VAR['F_compression'] == "gzip" && !$disable_gzip) {
$comp_gzip = " selected";
} elseif ($PMBP_SYS_VAR['F_compression'] == "zip") {
$comp_zip = " selected";
} else {
$comp_off = " selected";
}
echo F_EX_COMP . "
<select name=\"zip\">
<option" . $comp_off . " value=\"\">" . F_EX_OFF . "</option>
<option " . $comp_gzip . " " . $disable_gzip . " value=\"gzip\">" . F_EX_GZIP . "</option>
<option" . $comp_zip . " value=\"zip\">" . F_EX_ZIP . "</option>
</select>\n</td>\n</tr>\n</table>\n<p></p>\n";
// show directory backup form
if ($CONF['dir_backup']) {
if (!is_array($dirs1) && $PMBP_SYS_VAR['dir_lists'] >= 1) {
$dirs1 = PMBP_get_dirs("../");
}
$last_dirs = explode("|", $PMBP_SYS_VAR['F_ftp_dirs']);
echo "\n\n<table width=\"940\">\n";
echo "<tr>\n<td>\n";
if ($scheduled) {
echo EX_DIRS . ":<br>(<a href=\"scheduled.php?update_dir_list=TRUE\">" . PMBP_EXS_UPDATE_DIRS . "</a>)<br>\n";
} else {
echo EX_DIRS . ":<br>(<a href=\"backup.php?update_dir_list=TRUE\">" . PMBP_EXS_UPDATE_DIRS . "</a>)<br>\n";
}
echo "</td>\n<td> </td>\n<td>\n";
echo EX_DIRS_MAN . ":<br>\n";
echo "</td>\n</tr><tr>\n<td>";
echo "<select name='dirs[]' multiple=\"multiple\" size=\"9\">";
foreach ($dirs1 as $value) {
if (in_array("../" . $value, $last_dirs)) {
echo "<option value=\"" . "../" . $value . "\" selected>" . "../" . $value . "</option>\n";
} else {
echo "<option value=\"" . "../" . $value . "\">" . "../" . $value . "</option>\n";
}
}
echo "</select>\n";
echo "\n</td>\n<td> </td>\n<td>\n";
echo "<textarea rows=\"7\" cols=\"63\" name=\"man_dirs\">" . $PMBP_SYS_VAR['F_ftp_dirs_2'] . "</textarea><br>\n";
if ($PMBP_SYS_VAR['F_packed']) {
$checked = "checked";
} else {
$checked = "";
}
echo "<input type=\"checkbox\" name=\"packed\" " . $checked . ">" . EX_PACKED . "\n";
echo "</td>\n</tr>\n</table>\n<p></p>\n";
}
}
// checks if settings on the export form where made and saves them
function PMBP_save_export_settings()
{
global $PMBP_SYS_VAR;
// check if any settings have changed
if ($PMBP_SYS_VAR['F_data'] != $_POST['data'] or $PMBP_SYS_VAR['F_tables'] != $_POST['tables'] or
$PMBP_SYS_VAR['F_compression'] != $_POST['zip'] or $PMBP_SYS_VAR['F_drop'] != $_POST['drop'] or $PMBP_SYS_VAR['F_packed'] != $_POST['packed']) {
$PMBP_SYS_VAR['F_data'] = $_POST['data'];
$PMBP_SYS_VAR['F_tables'] = $_POST['tables'];
$PMBP_SYS_VAR['F_compression'] = $_POST['zip'];
$PMBP_SYS_VAR['F_drop'] = $_POST['drop'];
$PMBP_SYS_VAR['F_packed'] = $_POST['packed'];
}
if (isset($_POST['db'])) {
if (is_array($_POST['db'])) {
if ($PMBP_SYS_VAR['F_dbs'] != implode("|", $_POST['db'])) {
$PMBP_SYS_VAR['F_dbs'] = implode("|", $_POST['db']);
}
} else {
$PMBP_SYS_VAR['F_dbs'] = "";
}
} else {
$PMBP_SYS_VAR['F_dbs'] = "";
}
if ($PMBP_SYS_VAR['F_comment'] != $_POST['comments']) {
$PMBP_SYS_VAR['F_comment'] = $_POST['comments'];
}
if (isset($_POST['dirs'])) {
if ($PMBP_SYS_VAR['F_ftp_dirs'] != implode("|", $_POST['dirs'])) {
$PMBP_SYS_VAR['F_ftp_dirs'] = implode("|", $_POST['dirs']);
}
} else {
$PMBP_SYS_VAR['F_ftp_dirs'] = "";
}
if ($PMBP_SYS_VAR['F_ftp_dirs_2'] != $_POST['man_dirs']) {
$PMBP_SYS_VAR['F_ftp_dirs_2'] = $_POST['man_dirs'];
}
// update global_conf.php
PMBP_save_global_conf();
}
// generates image tag
function PMBP_image_tag($image, $alt = "", $title = "", $link = "")
{
if (strpos($image, "/") === false) {
$image = PMBP_IMAGE_DIR . $image;
$size = getimagesize($image);
} else {
$size = getimagesize(PMBP_IMAGE_DIR . basename($image));
}
if ($link) {
return "<a href=\"" . $link . "\"><img src=\"" . $image . "\" alt=\"" . $alt . "\" title=\"" . $title . "\" " . $size[3] . "></a>";
} else {
return "<img src=\"" . $image . "\" alt=\"" . $alt . "\" title=\"" . $title . "\" " . $size[3] . ">";
}
}
// generates javascript 'select all in input select' link
function PMBP_set_select($form, $select, $link)
{
return "<a href=\"\" onclick=\"setSelect('" . $form . "','" . $select . "'); return false;\">" . $link . "</a>";
}
// generates javascript PMBP_pop_up link
function PMBP_pop_up($path, $link, $type, $title_attr = "")
{
return "<a href='javascript:popUp(\"" . $path . "\",\"" . $type . "\",false,\"\")' title=\"" . $title_attr . "\">" . $link . "</a>";
}
// generates event hanlders to change the border color in a td.list list
function PMBP_change_color($color1, $color2)
{
return "onmouseout=\"changeColor(this, '" . $color1 . "');\" onmouseover=\"changeColor(this, '" . $color2 . "');\"";
}
// generates javascript confirm dialog
// if $popupType is "view" or something else, a pop up like in PMBP_pop_up will be opened after the confirmation
function PMBP_confirm($text, $path, $link, $popupType = false)
{
global $CONF;
switch ($CONF['confirm']) {
case 0:
if ($popupType) {
return "<a href='javascript:popUp(\"" . $path . "\",\"" . $popupType . "\",true,\"" . $text . "\")'>" . $link . "</a>";
} else {
return "<a href='javascript:confirmClick(\"" . $text . "\",\"" . $path . "\")'>" . $link . "</a>";
}
case 1:
if ($popupType) {
if (strstr($path, "all") || strstr($path, "ALL")) {
return "<a href='javascript:popUp(\"" . $path . "\",\"" . $popupType . "\",true,\"" . $text . "\")'>" . $link . "</a>";
} else {
return "<a href='javascript:popUp(\"" . $path . "\",\"" . $popupType . "\",false,\"\")'>" . $link . "</a>";
}
} else {
if (strstr($path, "all") || strstr($path, "ALL")) {
return "<a href='javascript:confirmClick(\"" . $text . "\",\"" . $path . "\")'>" . $link . "</a>";
} else {
return "<a href=\"" . $path . "\">" . $link . "</a>";
}
}
case 2:
if ($popupType) {
if (strstr($path, "ALL")) {
return "<a href='javascript:popUp(\"" . $path . "\",\"" . $popupType . "\",true,\"" . $text . "\")'>" . $link . "</a>";
} else {
return "<a href='javascript:popUp(\"" . $path . "\",\"" . $popupType . "\",false,\"\")'>" . $link . "</a>";
}
} else {
if (strstr($path, "ALL")) {
return "<a href='javascript:confirmClick(\"" . $text . "\",\"" . $path . "\")'>" . $link . "</a>";
} else {
return "<a href=\"" . $path . "\">" . $link . "</a>";
}
}
case 3:
if ($popupType) {
return "<a href='javascript:popUp(\"" . $path . "\",\"" . $popupType . "\",false,\"\")'>" . $link . "</a>";
} else {
return "<a href=\"" . $path . "\">" . $link . "</a>";
}
}
}
// function to execute the sql queries provided by the file handler $file
// $file can be a gzopen() or open() handler, $con is the database connection
// $linespersession says how many lines should be executed; if false, all lines will be executed
function PMBP_exec_sql($file, $con, $linespersession = false, $noFile = false)
{
$query = "";
$queries = 0;
$error = "";
if (isset($_GET["totalqueries"])) {
$totalqueries = $_GET["totalqueries"];
} else {
$totalqueries = 0;
}
if (isset($_GET["start"])) {
$linenumber = $_GET["start"];
} else {
$linenumber = $_GET['start'] = 0;
}
if (!$linespersession) {
$_GET['start'] = 1;
}
$inparents = false;
$querylines = 0;
// $tableQueries and $insertQueries only count this session
$tableQueries = 0;
$insertQueries = 0;
// stop if a query is longer than 300 lines long
$max_query_lines = 300;
// lines starting with these strings are comments and will be ignored
$comment[0] = "#";
$comment[1] = "-- ";
while (($linenumber < $_GET["start"] + $linespersession || $query != "") && ($dumpline = gzgets($file, 65536))) {
// increment $_GET['start'] when $linespersession was not set
// so all lines of $file will be exeuted at once
if (!$linespersession) {
$_GET['start']++;
}
// handle DOS and Mac encoded linebreaks
$dumpline = preg_replace("/\r\n$/", "\n", $dumpline);
$dumpline = preg_replace("/\r$/", "\n", $dumpline);
// skip comments and blank lines only if NOT in parents
if (!$inparents) {
$skipline = false;
foreach ($comment as $comment_value) {
if (!$inparents && (trim($dumpline) == "" || strpos($dumpline, $comment_value) === 0)) {
$skipline = true;
break;
}
}
if ($skipline) {
$linenumber++;
continue;
}
}
// remove double back-slashes from the dumpline prior to count the quotes ('\\' can only be within strings)
$dumpline_deslashed = str_replace("\\\\", "", $dumpline);
// count ' and \' in the dumpline to avoid query break within a text field ending by ;
// please don't use double quotes ('"')to surround strings, it wont work
$parents = substr_count($dumpline_deslashed, "'") - substr_count($dumpline_deslashed, "\\'");
if ($parents % 2 != 0) {
$inparents = !$inparents;
}
// add the line to query
$query .= $dumpline;
// don't count the line if in parents (text fields may include unlimited linebreaks)
if (!$inparents) {
$querylines++;
}
// stop if query contains more lines as defined by $max_query_lines
if ($querylines > $max_query_lines) {
$error = sprintf(BI_WRONG_FILE . "\n", $linenumber, $max_query_lines);
break;
}
// execute query if end of query detected (; as last character) AND NOT in parents
if (preg_match("/;$/", trim($dumpline)) && !$inparents) {
if (!mysqli_query($con, trim($query), $con)) {
$error = SQ_ERROR . " " . ($linenumber + 1) . "<br>" . nl2br(htmlentities(trim($query))) . "\n<br>" . htmlentities(mysqli_error($con));
break;
}
if (strtolower(substr(trim($query), 0, 6)) == "insert") {
$tableQueries++;
} elseif (strtolower(substr(trim($query), 0, 12)) == "create table") {
$insertQueries++;
}
$totalqueries++;
$queries++;
$query = "";
$querylines = 0;
}
$linenumber++;
}
return array("queries" => $queries, "totalqueries" => $totalqueries, "linenumber" => $linenumber, "error" => $error, "tableQueries" => $tableQueries, "insertQueries" => $insertQueries);
}
function PMBP_get_character_set($con)
{
$res = mysqli_query($con, "SHOW VARIABLES LIKE 'character_set_database'");
$obj = mysqli_fetch_array($res);
if ($obj['Value']) {
return $obj['Value'];
} else {
return "utf8";
}
}
// Liefert ein Array mit den Tabellen in ['tables'] und den views in ['views'] zurück
function PMBP_list_tables_and_view($con)
{
// get auto_increment values and names of all tables
$result = array('tables' => array(), 'views' => array());
$res = mysqli_query($con, "show table status");
while ($row = mysqli_fetch_array($res)) {
if (!isset($row['Engine'])) {
$result['views'][] = $row;
} else {
$result['tables'][] = $row;
}
}
return $result;
}
// generates a dump of $db database
// $tables and $data set whether tables or data to backup. $comment sets the commment text
// $drop and $zip tell if to include the drop table statement or dry to pack
function PMBP_dump($db, $tables, $data, $drop, $zip, $comment)
{
global $CONF;
global $PMBP_SYS_VAR;
$error = false;
// set max string size before writing to file
if (@ini_get("memory_limit")) {
$max_size = 500000 * intval(ini_get("memory_limit"));
} else {
ini_set("memory_limit", $PMBP_SYS_VAR['memory_limit'] / 1024000);
$max_size = 500000 * ($PMBP_SYS_VAR['memory_limit'] / 1024000);
}
// set backupfile name
$time = time();
if ($zip == "gzip") {
$backupfile = $db . "." . $time . ".sql.gz";
} else {
$backupfile = $db . "." . $time . ".sql";
}
$backupfile = PMBP_EXPORT_DIR . $backupfile;
if ($con = PMBP_mysql_connect()) {
// don't backup tables in $PMBP_SYS_VAR['except_tables']
$except_tables = explode(",", $PMBP_SYS_VAR['except_tables']);
//create comment
$out = "# MySQL dump of database '" . $db . "' on host '" . $CONF['sql_host'] . "'\n";
$out .= "# backup date and time: " . strftime($CONF['date'], $time) . "\n";
$out .= "# built by phpMyBackupPro " . PMBP_VERSION . "\n";
$out .= "# " . PMBP_WEBSITE . "\n\n";
// write users comment
if ($comment) {
$out .= "# comment:\n";
$comment = preg_replace("'\n'", "\n# ", "# " . $comment);
foreach (explode("\n", $comment) as $line) {
$out .= $line . "\n";
}
$out .= "\n";
}
// set and log character set
$characterSet = PMBP_set_character_set($con);
$out .= "### used character set: " . $characterSet . " ###\n";
$out .= "set names " . $characterSet . ";\n\n";
// print "use database" if more than one database is available
if (count(PMBP_get_db_list()) > 1) {
$out .= "CREATE DATABASE IF NOT EXISTS `" . $db . "`;\n\n";
$out .= "USE `" . $db . "`;\n";
}
// select db
@mysqli_select_db($con, $db);
// get tables and views
$tables_and_views = PMBP_list_tables_and_view($con);
$all_tables = $tables_and_views['tables'];
$all_views = $tables_and_views['views'];
// get table structures
$all_tables_new = array();
foreach ($all_tables as $key => $table) {
if (!in_array($table['Name'], $except_tables)) {
$res1 = mysqli_query($con, "SHOW CREATE TABLE `" . $table['Name'] . "`");
$tmp = mysqli_fetch_array($res1);
$table_sql[$table['Name']] = $tmp["Create Table"];
$all_tables_new[$key] = $table;
}
}
$all_tables = $all_tables_new;
unset($all_tables_new);
// find foreign keys
$fks = array();
if (isset($table_sql)) {
foreach ($table_sql as $tablenme => $table) {
$tmp_table = $table;
// save all tables, needed for creating this table in $fks
while (($ref_pos = strpos($tmp_table, " REFERENCES ")) > 0) {
$tmp_table = substr($tmp_table, $ref_pos + 12);
$ref_pos = strpos($tmp_table, "(");
// cut of '`' at the begining and end of fk-name
$fks[$tablenme][] = trim(str_replace('`', '', substr($tmp_table, 0, $ref_pos)));
}
}
}
// order $all_tables and check for ring constraints
$all_tables_copy = $all_tables;
$all_tables = PMBP_order_sql_tables($all_tables, $fks);
$ring_constraints = false;
// ring constraints found
if ($all_tables === false) {
$ring_constraints = true;
$all_tables = $all_tables_copy;
$out .= "\n# ring constraints workaround\n";
$out .= "SET FOREIGN_KEY_CHECKS=0;\n";
$out .= "SET AUTOCOMMIT=0;\n";
$out .= "START TRANSACTION;\n";
}
unset($all_tables_copy);
// as long as no error occurred
if (!$error) {
if ($drop) {
$out .= "\n### drop all tables first ###\n";
foreach (array_reverse($all_tables) as $row) {
$out .= "\nDROP TABLE IF EXISTS `" . $row['Name'] . "`;";
}
$out .= "\n";
}
foreach ($all_tables as $row) {
$tablename = $row['Name'];
$auto_incr[$tablename] = $row['Auto_increment'];
$out .= "\n\n";
// export tables
if ($tables) {
$out .= "### structure of table `" . $tablename . "` ###\n\n";
$out .= $table_sql[$tablename];
// add auto_increment value
if ($auto_incr[$tablename]) {
$out .= " AUTO_INCREMENT=" . $auto_incr[$tablename];
}
$out .= ";";
}
$out .= "\n\n\n";
// export data
if ($data && !$error) {
$out .= "### data of table `" . $tablename . "` ###\n\n";
// check if field types are NULL or NOT NULL
$res3 = mysqli_query($con, "show columns from `" . $tablename . "`");
$res2 = mysqli_query($con, "select * from `" . $tablename . "`");
if ($res2) {
$number_of_rows = mysqli_num_rows($res2);
if ($number_of_rows > 0) {
for ($j = 0; $j < $number_of_rows; $j++) {
$out .= "insert into `" . $tablename . "` values (";
$row2 = mysqli_fetch_row($res2);
// run through each field
for ($k = 0; $k < $nf = mysqli_num_fields($res2); $k++) {
// identify null values and save them as null instead of ''
if (is_null($row2[$k])) {
$out .= "null";
} else {
$out .= "'" . mysqli_real_escape_string($con, $row2[$k]) . "'";
}
if ($k < ($nf - 1)) {
$out .= ", ";
}
}
$out .= ");\n";
// if saving is successful, then empty $out, else set error flag
if (strlen($out) > $max_size) {
if ($out = PMBP_save_to_file($backupfile, $zip, $out, "a")) {
$out = "";
} else {
$error = true;
}
}
}
} else {
$out .= "-- table is empty\n"; // no data
}
} else {
echo "MySQL error: " . mysqli_error($con);
@unlink(PMBP_EXPORT_DIR . $backupfile);
return false;
}
// an error occurred! Try to delete file and return error status
} elseif ($error) {
@unlink(PMBP_EXPORT_DIR . $backupfile);
return false;
}
// if saving is successful, then empty $out, else set error flag
if (strlen($out) > $max_size) {
if ($out = PMBP_save_to_file($backupfile, $zip, $out, "a")) {
$out = "";
} else {
$error = true;
}
}
}
// views
// get all view definitions
$all_views_definitions = array();
foreach ($all_views as $row) {
$viewname = $row['Name'];
if (!in_array($viewname, $except_tables)) {
$res4 = mysqli_query($con, "show create view `" . $viewname . "`");
if ($res4) {
$row4 = mysqli_fetch_array($res4);
$all_views_definitions[$viewname] = $row4['Create View'];
} else {
echo "MySQL error: " . mysqli_error($con);
@unlink(PMBP_EXPORT_DIR . $backupfile);
return false;
}
}
}
if (sizeof($all_views_definitions) > 0) {
$out .= "\n\n### views ###\n\n";
}
// order $all_views and check for ring constraints
$all_views_definitions_copy = $all_views_definitions;
$all_views_definitions = PMBP_order_sql_views($all_views_definitions);
$ring_constraints = false;
// ring constraints found
if ($all_views_definitions === false) {
$all_views_definitions = $all_views_definitions_copy;
// if not already written because of tabel ring constraints
if (!$ring_constraints) {
$out .= "\n# ring constraints workaround\n";
$out .= "SET FOREIGN_KEY_CHECKS=0;\n";
$out .= "SET AUTOCOMMIT=0;\n";
$out .= "START TRANSACTION;\n";
}
$ring_constraints = true;
}
unset($all_views_definitions_copy);
// view drop statements (in reverse order)
if ($drop && count($all_views_definitions) > 0) {
$out .= "### drop all views first ###\n\n";
foreach (array_reverse($all_views_definitions) as $view_name => $view_definition) {
$out .= "DROP VIEW IF EXISTS `" . $view_name . "`;\n";
}
$out .= "\n\n";
}
// view definitions
foreach ($all_views_definitions as $view_name => $view_definition) {
$out .= "### create statement of view `" . $view_name . "` ###\n\n";
$out .= $view_definition;
$out .= ";\n\n";
}
// if saving is successful, then empty $out, else set error flag
if (strlen($out) > $max_size) {
if ($out = PMBP_save_to_file($backupfile, $zip, $out, "a")) {
$out = "";
} else {
$error = true;
}
}
// an error occurred! Try to delete file and return error status
} else {
@unlink($backupfile);