1 | <?php
|
---|
2 | /*
|
---|
3 | * Project Name: MiniManager for Mangos Server
|
---|
4 | * Date: 17.10.2006 inital version (0.0.1a)
|
---|
5 | * Author: Q.SA
|
---|
6 | * Copyright: Q.SA
|
---|
7 | * Email: *****
|
---|
8 | * License: GNU General Public License v2(GPL)
|
---|
9 | */
|
---|
10 |
|
---|
11 | require_once("header.php");
|
---|
12 | require_once("scripts/backup_tab.php");
|
---|
13 | valid_login(3);
|
---|
14 |
|
---|
15 | //##############################################################################################
|
---|
16 | // print backup options step one
|
---|
17 | //##############################################################################################
|
---|
18 | function backup_step1(){
|
---|
19 | global $lang_backup, $lang_global, $output;
|
---|
20 |
|
---|
21 | $output .= "<center>
|
---|
22 | <br /><fieldset style=\"width: 700px;\">
|
---|
23 | <legend>{$lang_backup['backup_options']}</legend>
|
---|
24 | <table class=\"hidden\">
|
---|
25 | <tr><td colspan=\"2\">{$lang_backup['select_option']}:</td></tr>";
|
---|
26 | $output .= "<tr><td><form action=\"backup.php\" method=\"get\" name=\"form\">
|
---|
27 | <input type=\"hidden\" name=\"action\" value=\"backup_step2\" />
|
---|
28 | <input type=\"hidden\" name=\"error\" value=\"3\" />
|
---|
29 | <select name=\"backup_action\">
|
---|
30 | <option value=\"save\">{$lang_backup['save']}</option>
|
---|
31 | <option value=\"load\">{$lang_backup['load']}</option>
|
---|
32 | </select> - {$lang_backup['to_from']} -
|
---|
33 | <select name=\"backup_from_to\">
|
---|
34 | <option value=\"web\">{$lang_backup['web_backup']}</option>
|
---|
35 | <option value=\"file\">{$lang_backup['local_file']}</option>
|
---|
36 | <option value=\"acc_on_file\">{$lang_backup['acc_on_file']}</option>
|
---|
37 | </select>
|
---|
38 | </td><td>";
|
---|
39 | makebutton($lang_backup['go'], "javascript:do_submit()",80);
|
---|
40 | makebutton($lang_global['back'], "javascript:window.history.back()",80);
|
---|
41 | $output .= "<tr><td colspan=\"2\" align=\"left\"><input type=\"checkbox\" name=\"struc_backup\" value=\"1\" /> {$lang_backup['save_table_struc_backup']}.</td></tr>
|
---|
42 | <tr><td colspan=\"2\" align=\"left\"><input type=\"checkbox\" name=\"save_all_realms\" value=\"1\" checked=\"checked\" /> {$lang_backup['save_all_realms']}.</td></tr>
|
---|
43 | </form></td></tr>
|
---|
44 | </table><br /></fieldset><br /><br /></center>";
|
---|
45 | }
|
---|
46 |
|
---|
47 | //##############################################################################################
|
---|
48 | // print backup options step two
|
---|
49 | //##############################################################################################
|
---|
50 | function backup_step2(){
|
---|
51 | global $lang_backup, $lang_global, $output, $backup_dir, $realm_db, $mangos_db;
|
---|
52 |
|
---|
53 | if ( empty($_GET['backup_action']) || empty($_GET['backup_from_to'] )) {
|
---|
54 | redirect("backup.php?error=1");
|
---|
55 | } else {
|
---|
56 | $backup_action = addslashes($_GET['backup_action']);
|
---|
57 | $backup_from_to = addslashes($_GET['backup_from_to']);
|
---|
58 | $struc_backup = (isset($_GET['struc_backup'])) ? addslashes($_GET['struc_backup']) : 0;
|
---|
59 | $save_all_realms = (isset($_GET['save_all_realms'])) ? addslashes($_GET['save_all_realms']) : 0;
|
---|
60 | }
|
---|
61 |
|
---|
62 | $upload_max_filesize=ini_get("upload_max_filesize");
|
---|
63 | if (eregi("([0-9]+)K",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024;
|
---|
64 | if (eregi("([0-9]+)M",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024;
|
---|
65 |
|
---|
66 | switch ($backup_action){
|
---|
67 | case "load":
|
---|
68 | $output .= "<center><fieldset style=\"width: 700px;\">
|
---|
69 | <legend>{$lang_backup['select_file']}</legend>
|
---|
70 | <br /><table class=\"hidden\">";
|
---|
71 |
|
---|
72 | switch ($backup_from_to) {
|
---|
73 | case "file":
|
---|
74 | $output .= "<tr><td colspan=\"2\">{$lang_backup['max_file_size']} : $upload_max_filesize bytes (".round ($upload_max_filesize/1024/1024)." Mbytes)<br />
|
---|
75 | {$lang_backup['use_ftp_for_large_files']}.</td></tr><tr>";
|
---|
76 | $output .= "<td><form enctype=\"multipart/form-data\" action=\"backup.php?action=dobackup&backup_action=$backup_action&backup_from_to=$backup_from_to\" method=\"post\" name=\"form\">
|
---|
77 | <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$upload_max_filesize\" />
|
---|
78 | <select name=\"use_db\">";
|
---|
79 | foreach ($mangos_db as $db) $output .= "<option value=\"{$db['name']}\">{$db['name']}</option>";
|
---|
80 | $output .= "<option value=\"{$realm_db['name']}\">{$realm_db['name']}</option>
|
---|
81 | </select>
|
---|
82 | <input type=\"file\" name=\"uploaded_file\" />
|
---|
83 | </form></td><td>";
|
---|
84 | makebutton($lang_backup['upload'], "javascript:do_submit()",80);
|
---|
85 | break;
|
---|
86 |
|
---|
87 | case "web":
|
---|
88 | $output .= "<tr><td><form action=\"backup.php?action=dobackup&backup_action=$backup_action&backup_from_to=$backup_from_to\" method=\"post\" name=\"form\">
|
---|
89 | <select name=\"use_db\">";
|
---|
90 | foreach ($mangos_db as $db) $output .= "<option value=\"{$db['name']}\">{$db['name']}</option>";
|
---|
91 | $output .= "<option value=\"{$realm_db['name']}\">{$realm_db['name']}</option>
|
---|
92 | </select>
|
---|
93 | <select name=\"selected_file_name\">";
|
---|
94 |
|
---|
95 | if (is_dir($backup_dir)) {
|
---|
96 | if ($dh = opendir($backup_dir)) {
|
---|
97 | while (($file = readdir($dh)) != false) {
|
---|
98 | if (($file != '.')&&($file != '..')&&($file != '.htaccess')&&($file != 'accounts')&&($file != 'index.html'))
|
---|
99 | $output .= "<option value=\"$file\">$file</option>";
|
---|
100 | }
|
---|
101 | closedir($dh);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | $output .= "</select></form></td><td>";
|
---|
105 | makebutton($lang_backup['go'], "javascript:do_submit()",80);
|
---|
106 | break;
|
---|
107 |
|
---|
108 | case "acc_on_file":
|
---|
109 | $output .= "<tr><td colspan=\"2\">{$lang_backup['enter_acc_name']}:</td></tr>
|
---|
110 | <tr><td>
|
---|
111 | <form action=\"backup.php?action=dobackup&backup_action=$backup_action&backup_from_to=$backup_from_to\" method=\"post\" name=\"form\">
|
---|
112 | <select name=\"use_db\">";
|
---|
113 | foreach ($mangos_db as $db) $output .= "<option value=\"{$db['name']}\">{$db['name']}</option>";
|
---|
114 | $output .= "<option value=\"{$realm_db['name']}\">{$realm_db['name']}</option>
|
---|
115 | </select>
|
---|
116 | <select name=\"file_dir\">";
|
---|
117 |
|
---|
118 | if (is_dir($backup_dir."/accounts")) {
|
---|
119 | if ($dh = opendir($backup_dir."/accounts")) {
|
---|
120 | while (($file = readdir($dh)) != false) {
|
---|
121 | if (($file != '.')&&($file != '..')&&($file != '.htaccess')&&($file != 'index.html'))
|
---|
122 | $output .= "<option value=\"$file\">$file</option>";
|
---|
123 | }
|
---|
124 | closedir($dh);
|
---|
125 | }
|
---|
126 | }
|
---|
127 | $output .= "</select>
|
---|
128 | <input type=\"text\" name=\"selected_file_name\" size=\"20\" maxlength=\"35\" />
|
---|
129 | </form><td>";
|
---|
130 | makebutton($lang_backup['go'], "javascript:do_submit()",80);
|
---|
131 |
|
---|
132 | break;
|
---|
133 | default:
|
---|
134 | }
|
---|
135 |
|
---|
136 | makebutton($lang_global['back'], "javascript:window.history.back()",80);
|
---|
137 | $output .= "</td>
|
---|
138 | </tr>
|
---|
139 | </table><br /><br /></fieldset><br /><br /></center>";
|
---|
140 | break;
|
---|
141 |
|
---|
142 | case "save":
|
---|
143 | redirect("backup.php?action=dobackup&backup_action=$backup_action&backup_from_to=$backup_from_to&struc_backup=$struc_backup&save_all_realms=$save_all_realms");
|
---|
144 | break;
|
---|
145 | default:
|
---|
146 | redirect("backup.php?error=1");
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | //##############################################################################################
|
---|
152 | // DO Backup
|
---|
153 | //##############################################################################################
|
---|
154 | function dobackup(){
|
---|
155 | global $lang_backup,$backup_dir, $tables_backup_realmd, $tables_backup_mangos, $output, $realm_db,
|
---|
156 | $mangos_db, $realm_id, $tab_backup_user_realmd, $tab_backup_user_mangos;
|
---|
157 |
|
---|
158 | if ( empty($_GET['backup_action']) || empty($_GET['backup_from_to']) ) {
|
---|
159 | redirect("backup.php?error=1");
|
---|
160 | } else {
|
---|
161 | $backup_action = addslashes($_GET['backup_action']);
|
---|
162 | $backup_from_to = addslashes($_GET['backup_from_to']);
|
---|
163 | }
|
---|
164 |
|
---|
165 | if (("load" == $backup_action)&&("file" == $backup_from_to)){
|
---|
166 | if (!eregi("(\.(sql|qbquery))$",$_FILES["uploaded_file"]["name"])) error($lang_backup['upload_sql_file_only']);
|
---|
167 |
|
---|
168 | $uploaded_filename=str_replace(" ","_",$_FILES["uploaded_file"]["name"]);
|
---|
169 | $uploaded_filename=preg_replace("/[^_A-Za-z0-9-\.]/i",'',$uploaded_filename);
|
---|
170 | $file_name_new = $uploaded_filename."_".date("m.d.y_H.i.s").".sql";
|
---|
171 |
|
---|
172 | move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], "$backup_dir/$file_name_new") or die (error("{$lang_backup['upload_err_write_permission']} $backup_dir"));
|
---|
173 | if (file_exists("$backup_dir/$file_name_new")){
|
---|
174 | require_once("scripts/db_layer/sql_lib.php");
|
---|
175 | $use_db = addslashes($_POST['use_db']);
|
---|
176 |
|
---|
177 | if ($use_db == $realm_db['name']) $queries = run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'], "$backup_dir/$file_name_new",true);
|
---|
178 | else {
|
---|
179 | foreach ($mangos_db as $db)
|
---|
180 | if ($use_db == $db['name']) $queries = run_sql_script($db['addr'], $db['user'], $db['pass'], $db['name'], "$backup_dir/$file_name_new",true);
|
---|
181 | }
|
---|
182 |
|
---|
183 | redirect("backup.php?error=4&tot=$queries");
|
---|
184 | } else error($lang_backup['file_not_found']);
|
---|
185 |
|
---|
186 | } else if (("load" == $backup_action)&&("web" == $backup_from_to)){
|
---|
187 |
|
---|
188 | if (empty($_POST['selected_file_name'])) {
|
---|
189 | redirect("backup.php?error=1");
|
---|
190 | } else $file_name = addslashes($_POST['selected_file_name']);
|
---|
191 |
|
---|
192 | if (file_exists("$backup_dir/$file_name")){
|
---|
193 | require_once("scripts/db_layer/sql_lib.php");
|
---|
194 | $use_db = addslashes($_POST['use_db']);
|
---|
195 |
|
---|
196 | if ($use_db == $realm_db['name']) $queries = run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'], "$backup_dir/$file_name",false);
|
---|
197 | else {
|
---|
198 | foreach ($mangos_db as $db)
|
---|
199 | if ($use_db == $db['name']) $queries = run_sql_script($db['addr'], $db['user'], $db['pass'], $db['name'], "$backup_dir/$file_name",false);
|
---|
200 | }
|
---|
201 |
|
---|
202 | redirect("backup.php?error=4&tot=$queries");
|
---|
203 | } else error($lang_backup['file_not_found']);
|
---|
204 |
|
---|
205 | } else if (("save" == $backup_action)&&("file" == $backup_from_to)){
|
---|
206 | //save and send to user
|
---|
207 |
|
---|
208 | $struc_backup = addslashes($_GET['struc_backup']);
|
---|
209 | $save_all_realms = addslashes($_GET['save_all_realms']);
|
---|
210 |
|
---|
211 | if($save_all_realms) $temp_id = "all_realms";
|
---|
212 | else $temp_id = "realmid_".$realm_id;
|
---|
213 | $file_name_new = $temp_id."_backup_".date("m.d.y_H.i.s").".sql";
|
---|
214 |
|
---|
215 | $fp = fopen("$backup_dir/$file_name_new", 'w') or die (error($lang_backup['file_write_err']));
|
---|
216 |
|
---|
217 | fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$realm_db['name']};\n")or die (error($lang_backup['file_write_err']));
|
---|
218 | fwrite($fp, "USE {$realm_db['name']};\n\n")or die (error($lang_backup['file_write_err']));
|
---|
219 | fclose($fp);
|
---|
220 |
|
---|
221 | require_once("scripts/db_layer/sql_lib.php");
|
---|
222 |
|
---|
223 | foreach ($tables_backup_realmd as $value) {
|
---|
224 | sql_table_dump ($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'],$value,$struc_backup,"$backup_dir/$file_name_new");
|
---|
225 | }
|
---|
226 |
|
---|
227 | if($save_all_realms) {
|
---|
228 | foreach ($mangos_db as $db){
|
---|
229 | $fp = fopen("$backup_dir/$file_name_new", 'r+') or die (error($lang_backup['file_write_err']));
|
---|
230 | fseek($fp,0,SEEK_END);
|
---|
231 | fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$db['name']};\n")or die (error($lang_backup['file_write_err']));
|
---|
232 | fwrite($fp, "USE {$db['name']};\n\n")or die (error($lang_backup['file_write_err']));
|
---|
233 | fclose($fp);
|
---|
234 |
|
---|
235 | foreach ($tables_backup_mangos as $value) {
|
---|
236 | sql_table_dump ($db['addr'], $db['user'], $db['pass'], $db['name'],$value,$struc_backup,"$backup_dir/$file_name_new");
|
---|
237 | }
|
---|
238 | }
|
---|
239 | } else {
|
---|
240 | $fp = fopen("$backup_dir/$file_name_new", 'r+') or die (error($lang_backup['file_write_err']));
|
---|
241 | fseek($fp,0,SEEK_END);
|
---|
242 | fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$mangos_db[$realm_id]['name']};\n")or die (error($lang_backup['file_write_err']));
|
---|
243 | fwrite($fp, "USE {$mangos_db[$realm_id]['name']};\n\n")or die (error($lang_backup['file_write_err']));
|
---|
244 | fclose($fp);
|
---|
245 |
|
---|
246 | foreach ($tables_backup_mangos as $value) {
|
---|
247 | sql_table_dump ($mangos_db[$realm_id]['addr'], $mangos_db[$realm_id]['user'], $mangos_db[$realm_id]['pass'], $mangos_db[$realm_id]['name'],$value,$struc_backup,"$backup_dir/$file_name_new");
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | Header("Content-type: application/octet-stream");
|
---|
252 | Header("Content-Disposition: attachment; filename=$file_name_new");
|
---|
253 |
|
---|
254 | $fp = fopen("$backup_dir/$file_name_new", 'r') or die (error($lang_backup['file_write_err']));
|
---|
255 | while (!feof($fp)) {
|
---|
256 | $output_file = fread($fp, 1024);
|
---|
257 | echo $output_file;
|
---|
258 | }
|
---|
259 | fclose($fp);
|
---|
260 | unlink("$backup_dir/$file_name_new");
|
---|
261 | exit();
|
---|
262 |
|
---|
263 | } else if (("save" == $backup_action)&&("web" == $backup_from_to)){
|
---|
264 | //save backup to web/backup folder
|
---|
265 | $struc_backup = addslashes($_GET['struc_backup']);
|
---|
266 | $save_all_realms = addslashes($_GET['save_all_realms']);
|
---|
267 |
|
---|
268 | $file_name_new = $realm_db['name']."_backup_".date("m.d.y_H.i.s").".sql";
|
---|
269 | $fp = fopen("$backup_dir/$file_name_new", 'w') or die (error($lang_backup['file_write_err']));
|
---|
270 |
|
---|
271 | fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$realm_db['name']};\n")or die (error($lang_backup['file_write_err']));
|
---|
272 | fwrite($fp, "USE {$realm_db['name']};\n\n")or die (error($lang_backup['file_write_err']));
|
---|
273 | fclose($fp);
|
---|
274 |
|
---|
275 | require_once("scripts/db_layer/sql_lib.php");
|
---|
276 |
|
---|
277 | foreach ($tables_backup_realmd as $value) {
|
---|
278 | sql_table_dump ($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'],$value,$struc_backup,"$backup_dir/$file_name_new");
|
---|
279 | }
|
---|
280 | fclose($fp);
|
---|
281 |
|
---|
282 | if($save_all_realms) {
|
---|
283 | foreach ($mangos_db as $db){
|
---|
284 | $file_name_new = $db['name']."_backup_".date("m.d.y_H.i.s").".sql";
|
---|
285 | $fp = fopen("$backup_dir/$file_name_new", 'w') or die (error($lang_backup['file_write_err']));
|
---|
286 |
|
---|
287 | fseek($fp,0,SEEK_END);
|
---|
288 | fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$db['name']};\n")or die (error($lang_backup['file_write_err']));
|
---|
289 | fwrite($fp, "USE {$db['name']};\n\n")or die (error($lang_backup['file_write_err']));
|
---|
290 | fclose($fp);
|
---|
291 |
|
---|
292 | foreach ($tables_backup_mangos as $value) {
|
---|
293 | sql_table_dump ($db['addr'], $db['user'], $db['pass'], $db['name'],$value,$struc_backup,"$backup_dir/$file_name_new");
|
---|
294 | }
|
---|
295 | fclose($fp);
|
---|
296 | }
|
---|
297 | } else {
|
---|
298 | $file_name_new = $mangos_db[$realm_id]['name']."_backup_".date("m.d.y_H.i.s").".sql";
|
---|
299 | $fp = fopen("$backup_dir/$file_name_new", 'w') or die (error($lang_backup['file_write_err']));
|
---|
300 | fseek($fp,0,SEEK_END);
|
---|
301 | fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$mangos_db[$realm_id]['name']};\n")or die (error($lang_backup['file_write_err']));
|
---|
302 | fwrite($fp, "USE {$mangos_db[$realm_id]['name']};\n\n")or die (error($lang_backup['file_write_err']));
|
---|
303 | fclose($fp);
|
---|
304 |
|
---|
305 | foreach ($tables_backup_mangos as $value) {
|
---|
306 | sql_table_dump ($mangos_db[$realm_id]['addr'], $mangos_db[$realm_id]['user'], $mangos_db[$realm_id]['pass'], $mangos_db[$realm_id]['name'],$value,$struc_backup,"$backup_dir/$file_name_new");
|
---|
307 | }
|
---|
308 | fclose($fp);
|
---|
309 | }
|
---|
310 |
|
---|
311 | redirect("backup.php?error=2");
|
---|
312 | exit();
|
---|
313 | } else if (("save" == $backup_action)&&("acc_on_file" == $backup_from_to)){
|
---|
314 | //save evry account in different file
|
---|
315 |
|
---|
316 | $struc_backup = addslashes($_GET['struc_backup']);
|
---|
317 | $save_all_realms = addslashes($_GET['save_all_realms']);
|
---|
318 |
|
---|
319 | $sql = new SQL;
|
---|
320 | $sql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);
|
---|
321 |
|
---|
322 | $query = $sql->query("SELECT id FROM account");
|
---|
323 | $subdir = "$backup_dir/accounts/".date("m_d_y_H_i_s");
|
---|
324 | mkdir($subdir, 0750);
|
---|
325 |
|
---|
326 |
|
---|
327 | while ($acc = $sql->fetch_array($query)){
|
---|
328 | $file_name_new = $acc[0]."_{$realm_db['name']}.sql";
|
---|
329 | $fp = fopen("$subdir/$file_name_new", 'w') or die (error($lang_backup['file_write_err']));
|
---|
330 | fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$realm_db['name']};\n")or die (error($lang_backup['file_write_err']));
|
---|
331 | fwrite($fp, "USE {$realm_db['name']};\n\n")or die (error($lang_backup['file_write_err']));
|
---|
332 |
|
---|
333 | $sql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);
|
---|
334 |
|
---|
335 | foreach ($tab_backup_user_realmd as $value) {
|
---|
336 | $acc_query = $sql->query("SELECT * FROM $value[0] WHERE $value[1] = $acc[0]");
|
---|
337 | $num_fields = $sql->num_fields($acc_query);
|
---|
338 | $numrow = $sql->num_rows($acc_query);
|
---|
339 |
|
---|
340 | $result = "-- Dumping data for $value[0] ".date("m.d.y_H.i.s")."\n";
|
---|
341 | $result .= "LOCK TABLES $value[0] WRITE;\n";
|
---|
342 | $result .= "DELETE FROM $value[0] WHERE $value[1] = $acc[0];\n";
|
---|
343 |
|
---|
344 | if ($numrow){
|
---|
345 | $result .= "INSERT INTO $value[0] (";
|
---|
346 |
|
---|
347 | for($count = 0; $count < $num_fields; $count++) {
|
---|
348 | $result .= "`".$sql->field_name($acc_query,$count)."`";
|
---|
349 | if ($count < ($num_fields-1)) $result .= ",";
|
---|
350 | }
|
---|
351 | $result .= ") VALUES \n";
|
---|
352 |
|
---|
353 | for ($i =0; $i<$numrow; $i++) {
|
---|
354 | $result .= "\t(";
|
---|
355 | $row = $sql->fetch_row($acc_query);
|
---|
356 | for($j=0; $j<$num_fields; $j++) {
|
---|
357 | $row[$j] = addslashes($row[$j]);
|
---|
358 | $row[$j] = ereg_replace("\n","\\n",$row[$j]);
|
---|
359 | if (isset($row[$j])) {
|
---|
360 | if ($sql->field_type($acc_query,$j) == "int") $result .= "$row[$j]";
|
---|
361 | else $result .= "'$row[$j]'" ;
|
---|
362 | }else $result .= "''";
|
---|
363 | if ($j<($num_fields-1)) $result .= ",";
|
---|
364 | }
|
---|
365 | if ($i < ($numrow-1)) $result .= "),\n";
|
---|
366 | }
|
---|
367 | $result .= ");\n";
|
---|
368 | }
|
---|
369 | $result .= "UNLOCK TABLES;\n";
|
---|
370 | $result .= "\n";
|
---|
371 | fwrite($fp, $result)or die (error($lang_backup['file_write_err']));
|
---|
372 | }
|
---|
373 | fclose($fp);
|
---|
374 |
|
---|
375 | foreach ($mangos_db as $db){
|
---|
376 | $file_name_new = $acc[0]."_{$db['name']}.sql";
|
---|
377 | $fp = fopen("$subdir/$file_name_new", 'w') or die (error($lang_backup['file_write_err']));
|
---|
378 | fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$db['name']};\n")or die (error($lang_backup['file_write_err']));
|
---|
379 | fwrite($fp, "USE {$db['name']};\n\n")or die (error($lang_backup['file_write_err']));
|
---|
380 | $sql->connect($db['addr'], $db['user'], $db['pass'], $db['name']);
|
---|
381 | $all_char_query = $sql->query("SELECT guid,name FROM `character` WHERE account = $acc[0]");
|
---|
382 |
|
---|
383 | while ($char = $sql->fetch_array($all_char_query)){
|
---|
384 | fwrite($fp, "-- Dumping data for character $char[1]\n")or die (error($lang_backup['file_write_err']));
|
---|
385 | foreach ($tab_backup_user_mangos as $value) {
|
---|
386 | $char_query = $sql->query("SELECT * FROM $value[0] WHERE $value[1] = $char[0]");
|
---|
387 | $num_fields = $sql->num_fields($char_query);
|
---|
388 | $numrow = $sql->num_rows($char_query);
|
---|
389 |
|
---|
390 | $result = "LOCK TABLES $value[0] WRITE;\n";
|
---|
391 | $result .= "DELETE FROM $value[0] WHERE $value[1] = $char[0];\n";
|
---|
392 |
|
---|
393 | if ($numrow){
|
---|
394 | $result .= "INSERT INTO $value[0] (";
|
---|
395 |
|
---|
396 | for($count = 0; $count < $num_fields; $count++) {
|
---|
397 | $result .= "`".$sql->field_name($char_query,$count)."`";
|
---|
398 | if ($count < ($num_fields-1)) $result .= ",";
|
---|
399 | }
|
---|
400 | $result .= ") VALUES \n";
|
---|
401 |
|
---|
402 | for ($i =0; $i<$numrow; $i++) {
|
---|
403 | $result .= "\t(";
|
---|
404 | $row = $sql->fetch_row($char_query);
|
---|
405 | for($j=0; $j<$num_fields; $j++) {
|
---|
406 | $row[$j] = addslashes($row[$j]);
|
---|
407 | $row[$j] = ereg_replace("\n","\\n",$row[$j]);
|
---|
408 | if (isset($row[$j])) {
|
---|
409 | if ($sql->field_type($char_query,$j) == "int") $result .= "$row[$j]";
|
---|
410 | else $result .= "'$row[$j]'" ;
|
---|
411 | }else $result .= "''";
|
---|
412 | if ($j<($num_fields-1)) $result .= ",";
|
---|
413 | }
|
---|
414 | if ($i < ($numrow-1)) $result .= "),\n";
|
---|
415 | }
|
---|
416 | $result .= ");\n";
|
---|
417 |
|
---|
418 | }
|
---|
419 | $result .= "UNLOCK TABLES;\n";
|
---|
420 | $result .= "\n";
|
---|
421 | fwrite($fp, $result)or die (error($lang_backup['file_write_err']));
|
---|
422 | }
|
---|
423 | }
|
---|
424 | fclose($fp);
|
---|
425 | }
|
---|
426 | }
|
---|
427 | $sql->close();
|
---|
428 | redirect("backup.php?error=2");
|
---|
429 |
|
---|
430 | } else if (("load" == $backup_action)&&("acc_on_file" == $backup_from_to)){
|
---|
431 | //load saved account
|
---|
432 | if ( empty($_POST['selected_file_name'])||empty($_POST['file_dir'])) {
|
---|
433 | redirect("backup.php?error=1");
|
---|
434 | } else {
|
---|
435 | $file_name = addslashes($_POST['selected_file_name']);
|
---|
436 | $file_dir = addslashes($_POST['file_dir']);
|
---|
437 | $use_db = addslashes($_POST['use_db']);
|
---|
438 | }
|
---|
439 |
|
---|
440 | $file_tmp = "$backup_dir/accounts/$file_dir/".$file_name."_$use_db.sql";
|
---|
441 | if (file_exists($file_tmp)){
|
---|
442 | require_once("scripts/db_layer/sql_lib.php");
|
---|
443 |
|
---|
444 | if ($use_db == $realm_db['name']) $queries = run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'],$realm_db['name'], "$backup_dir/accounts/$file_dir/$file_name.sql",true);
|
---|
445 | else {
|
---|
446 | foreach ($mangos_db as $db)
|
---|
447 | if ($use_db == $db['name']) $queries = run_sql_script($db['addr'], $db['user'], $db['pass'],$db['name'], "$backup_dir/accounts/$file_dir/$file_name.sql",true);
|
---|
448 | }
|
---|
449 |
|
---|
450 | redirect("backup.php?error=4&tot=$queries");
|
---|
451 | } else error($lang_backup['file_not_found']);
|
---|
452 |
|
---|
453 | } else {
|
---|
454 | //non of the options = error
|
---|
455 | redirect("backup.php?error=1");
|
---|
456 | }
|
---|
457 | }
|
---|
458 |
|
---|
459 | //########################################################################################################################
|
---|
460 | // MAIN
|
---|
461 | //########################################################################################################################
|
---|
462 | $err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
|
---|
463 |
|
---|
464 | $output .= "<div class=\"top\">";
|
---|
465 | switch ($err) {
|
---|
466 | case 1:
|
---|
467 | $output .= "<h1><font class=\"error\">{$lang_global['empty_fields']}</font></h1></div>";
|
---|
468 | break;
|
---|
469 | case 2:
|
---|
470 | $output .= "<h1><font class=\"error\">{$lang_backup['backup_finished']}</font></h1></div>";
|
---|
471 | break;
|
---|
472 | case 3:
|
---|
473 | $output .= "<h1>{$lang_backup['select_backup']}</h1></div>";
|
---|
474 | break;
|
---|
475 | case 4:
|
---|
476 | if(isset($_GET['tot'])) $total_queries = $_GET['tot'];
|
---|
477 | else $total_queries = NULL;
|
---|
478 | $output .= "<h1><font class=\"error\">{$lang_backup['file_loaded']} $total_queries {$lang_backup['que_executed']}.</font></h1></div>";
|
---|
479 | break;
|
---|
480 | default: //no error
|
---|
481 | $output .= "<h1>{$lang_backup['backup_acc']}</h1></div>";
|
---|
482 | $output .= "<center><font class=\"large\">{$lang_backup['tables_to_save']}:</font><br />
|
---|
483 | <table width=\"700\" class=\"hidden\">
|
---|
484 | <tr><td>";
|
---|
485 | foreach ($tables_backup_realmd as $value) $output .= " {$realm_db['name']}.$value / ";
|
---|
486 | foreach ($tables_backup_mangos as $value) $output .= " $value / ";
|
---|
487 | $output .= "</td></tr></table></center>";
|
---|
488 | }
|
---|
489 |
|
---|
490 | $action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
|
---|
491 |
|
---|
492 | switch ($action) {
|
---|
493 | case "backup_step2":
|
---|
494 | backup_step2();
|
---|
495 | break;
|
---|
496 | case "dobackup":
|
---|
497 | dobackup();
|
---|
498 | break;
|
---|
499 | default:
|
---|
500 | backup_step1();
|
---|
501 | }
|
---|
502 |
|
---|
503 | include_once("footer.php");
|
---|
504 | ?>
|
---|