forked from andreshg112/phpMyBackupPro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbig_import.php
executable file
·226 lines (191 loc) · 8.87 KB
/
big_import.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
<?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.|
+--------------------------------------------------------------------------+
*/
// This code is derived from BigDump ver. 0.21b from 2005-02-08
// Author: Alexey Ozerov (alexey at ozerov dot de)
// More Infos: http://www.ozerov.de/bigdump
// License: GNU General Public License 2
require_once "login.php";
@session_start();
// print html header
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">
<html" . ARABIC_HTML . ">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">
<link rel=\"stylesheet\" href=\"" . PMBP_STYLESHEET_DIR . $CONF['stylesheet'] . ".css\" type=\"text/css\">
<title>phpMyBackupPro - " . INF_INFO . "</title>
</head>
<body>
<table border=\"0\" cellspacing=\"2\" cellpadding=\"0\" width=\"100%\">\n
<tr><th colspan=\"2\" class=\"active\">\n";
echo PMBP_image_tag("logo.png", "phpMyBackupPro PMBP_WEBSITE", PMBP_WEBSITE);
echo "\n</th></tr>\n";
@set_time_limit($CONF['timelimit']);
// set parameters
$linespersession = 10000;
// set some basic values on start up
$error = false;
if (!isset($_GET['sn'])) {
$_GET['sn'] = 0;
} else {
$_GET['sn']++;
}
if (!isset($_GET['totalqueries'])) {
$_GET['totalqueries'] = 0;
}
if (!isset($_GET['dbn'])) {
$_GET['dbn'] = " ";
}
if (!isset($_GET['delete'])) {
$_GET['delete'] = false;
}
if (!isset($_GET['start']) || !isset($_GET['foffset'])) {
$_GET['start'] = $_GET['foffset'] = 0;
$firstSession = true;
$linenumber = 0;
$foffset = 0;
$totalqueries = 0;
}
// connect to the database
if (!isset($firstSession)) {
$con = PMBP_mysql_connect();
if (!$con) {
$error = C_WRONG_SQL;
}
if (!$error) {
$db = @mysqli_select_db($_GET['dbn']);
}
if (!$db) {
$error = C_WRONG_DB . " (" . $_GET['dbn'] . ")";
}
}
// open the file
if (!$error && !isset($firstSession)) {
// gzopen can be used for plain text too!
// extract zip file
if (PMBP_file_info("comp", $_GET["fn"]) == "zip") {
include_once "pclzip.lib.php";
$pclzip = new PclZip($_GET["fn"]);
$extracted_file = $pclzip->extractByIndex(0, PMBP_EXPORT_DIR, "");
if ($pclzip->error_code != 0) {
$error = "plczip: " . $pclzip->error_string . "<br>" . BI_BROKEN_ZIP . "!";
}
$_GET["fn"] = substr($_GET["fn"], 0, strlen($_GET["fn"]) - 4);
unset($pclzip);
}
if (!$error && !$file = @gzopen($_GET["fn"], "r")) {
$error = C_OPEN . " " . $_GET["fn"];
}
}
if (!$error) {
// get start time to calculate duration
if (function_exists("microtime")) {
$microtime = explode(" ", microtime());
$starttime = ($microtime[0] + $microtime[1]);
} else {
$starttime = time();
}
if (file_exists($_GET["fn"] . ".zip")) {
echo "<tr><td><div class=\"bold_left\">" . BI_IMPORTING_FILE . ":</div></td><td>" . basename($_GET["fn"]) . ".zip</td></tr>\n";
} else {
echo "<tr><td><div class=\"bold_left\">" . BI_IMPORTING_FILE . ":</div></td><td>" . basename($_GET["fn"]) . "</td></tr>\n";
}
echo "<tr><td><div class=\"bold_left\">" . BI_INTO_DB . ":</div></td><td>" . $_GET["dbn"] . "</td></tr>\n";
echo "<tr><td><div class=\"bold_left\">" . BI_SESSION_NO . ":</div></td><td>" . $_GET["sn"] . "</td></tr>\n";
echo "<tr><td><div class=\"bold_left\">" . BI_STARTING_LINE . ":</div></td><td>" . $_GET["start"] . "</td></tr>\n";
// start or continue the import process
if (!isset($firstSession)) {
if (gzseek($file, $_GET["foffset"]) != 0) {
$error = "UNEXPECTED ERROR: Can't set gzip file pointer to offset: " . $_GET["foffset"];
}
// execute sql queries
if (!$error) {
extract(PMBP_exec_sql($file, $con, $linespersession), EXTR_OVERWRITE);
}
// get the current file position
if (!$error) {
$foffset = gztell($file);
if ($foffset === false) {
$error = "UNEXPECTED ERROR: Can't read the file pointer offset";
}
}
}
// clean up
if (!isset($firstSession)) {
if ($con) {
@mysqli_close();
}
@gzclose($file);
}
if (!$error || isset($firstSession)) {
// calculate execution duration of this session
if (function_exists("microtime")) {
$microtime = explode(" ", microtime());
$endtime = ($microtime[0] + $microtime[1]);
} else {
$endtime = time();
}
if (!isset($firstSession)) {
// print information table
echo "<tr><td><div class=\"bold_left\">" . BI_STOPPING_LINE . ":</div></td><td>" . ($linenumber - 1) . "</td></tr>\n";
echo "<tr><td><div class=\"bold_left\">" . BI_QUERY_NO . "<br>(" . BI_THIS_LAST . "):</div></td><td>" . $queries . "/" . $totalqueries . "</td></tr>\n";
echo "<tr><td><div class=\"bold_left\">" . BI_BYTE_NO . ":</div></td><td>" . round($foffset / 1024) . " KB</td></tr>\n";
echo "<tr><td><div class=\"bold_left\">" . BI_DURATION . ":</div></td><td>" . number_format($endtime - $starttime, 3) . " " . F_SECONDS . "</td></tr>\n";
}
if ($linenumber < $_GET["start"] + $linespersession && !isset($firstSession)) {
// delete extracted zip file
if (file_exists($_GET["fn"] . ".zip")) {
@unlink($_GET["fn"]);
}
// all sql queries executed
echo "<tr><td colspan=\"2\"> </td></tr>\n";
echo "<tr><td colspan=\"2\" class=\"active\">" . PMBP_addOutput(BI_END, "green_left");
// delete the temporary created file
if (!$_GET['delete']) {
if (file_exists($_GET["fn"] . ".zip")) {
echo "<br>(<a href=\"" . $_SERVER["PHP_SELF"] . "?fn=" . $_GET["fn"] . ".zip&dbn=" . $_GET['dbn'] . "\">" . BI_RESTART . "" . basename($_GET['fn']) . ".zip</a>)</td></tr>\n";
} else {
echo "<br>(<a href=\"" . $_SERVER["PHP_SELF"] . "?fn=" . $_GET["fn"] . "&dbn=" . $_GET['dbn'] . "\">" . BI_RESTART . "" . basename($_GET['fn']) . "</a>)</td></tr>\n";
}
}
echo "</table>\n";
} else {
// restart script to execute next queries
echo "<tr><td colspan=\"2\"> </td></tr>\n";
echo "<tr><td colspan=\"2\" class=\"active\">" . PMBP_addOutput(BI_SCRIPT_RUNNING, "red_left") . "</td></tr>\n";
echo "</table>\n";
echo "<script language=\"JavaScript\" type=\"text/javascript\">window.setTimeout('location.href=\"" . $_SERVER["PHP_SELF"] . "?fn=" . $_GET["fn"];
echo "&dbn=" . $_GET['dbn'] . "&delete=" . $_GET['delete'] . "&start=" . $linenumber . "&foffset=" . $foffset . "&totalqueries=" . $totalqueries . "&sn=" . $_GET['sn'] . "\";',500);</script>\n";
echo "<noscript>\n";
$link = $_SERVER["PHP_SELF"] . "?delete=" . $_GET['delete'] . "&start=" . $linenumber . "&fn=" . $_GET["fn"] . "&foffset=" . $foffset . "&dbn=" . $_GET['dbn'] . "&totalqueries=" . $totalqueries . "&sn=" . $_GET['sn'];
echo PMBP_addOutput("<a href=\"" . $link . "\">" . BI_CONTINUE . " " . $linenumber . "</a> (" . BI_ENABLE_JS . "!)", "red_left");
echo "</noscript>\n";
}
}
}
if ($error) {
echo "<tr><td colspan=\"2\">" . PMBP_addOutput($error, "red_left") . "</td></tr>";
}
echo "</table></body>\n</html>";