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 | valid_login(3);
|
---|
13 |
|
---|
14 | //#####################################################################################################
|
---|
15 | // DO UPLOAD/SUBMIT PATCH
|
---|
16 | //#####################################################################################################
|
---|
17 | function print_upload(){
|
---|
18 | global $lang_run_patch, $lang_global, $backup_dir, $output, $realm_db, $mangos_db, $realm_id;
|
---|
19 |
|
---|
20 | if (isset($_FILES["uploaded_file"]["name"])){
|
---|
21 | if ($_FILES["uploaded_file"]["type"] != "application/octet-stream" && $_FILES["uploaded_file"]["type"] != "text/plain") error("{$lang_run_patch['run_sql_file_only']}<br />". $_FILES["uploaded_file"]["type"]);
|
---|
22 | if (file_exists($_FILES["uploaded_file"]["tmp_name"])){
|
---|
23 | $buffer = implode('', file($_FILES["uploaded_file"]["tmp_name"]));
|
---|
24 | } else error($lang_run_patch['file_not_found']);
|
---|
25 | } else $buffer = "";
|
---|
26 |
|
---|
27 | $upload_max_filesize=ini_get("upload_max_filesize");
|
---|
28 | if (eregi("([0-9]+)K",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024;
|
---|
29 | if (eregi("([0-9]+)M",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024;
|
---|
30 |
|
---|
31 | $output .= "<center>{$lang_run_patch['select_sql_file']} :<br />
|
---|
32 | {$lang_run_patch['max_filesize']} $upload_max_filesize bytes
|
---|
33 | (".round ($upload_max_filesize/1024/1024)." Mbytes)<br />
|
---|
34 | <table class=\"hidden\">
|
---|
35 | <tr><td>";
|
---|
36 | $output .= "<form enctype=\"multipart/form-data\" action=\"run_patch.php?action=print_upload\" method=\"post\" name=\"form\">
|
---|
37 | <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$upload_max_filesize\" />
|
---|
38 | <input type=\"file\" name=\"uploaded_file\" /></form></td><td>";
|
---|
39 | makebutton($lang_run_patch['open'], "javascript:do_submit()",100);
|
---|
40 | $output .= "</td></tr>
|
---|
41 | </table><hr />
|
---|
42 | <form action=\"run_patch.php?action=do_run_patch\" method=\"post\" name=\"form1\">
|
---|
43 | <table class=\"hidden\">
|
---|
44 | <tr>
|
---|
45 | <td align=\"left\">{$lang_run_patch['run_rules']}</td>
|
---|
46 | <td align=\"right\">{$lang_run_patch['select_db']}:
|
---|
47 | <select name=\"use_db\">";
|
---|
48 | foreach ($mangos_db as $db) $output .= "<option value=\"{$db['name']}\">{$db['name']}</option>";
|
---|
49 | $output .= "<option value=\"{$realm_db['name']}\">{$realm_db['name']}</option>
|
---|
50 | </select>
|
---|
51 | </td></tr>
|
---|
52 | <tr><td colspan=\"2\"><textarea name=\"query\" rows=\"14\" cols=\"93\">$buffer</textarea></td></tr>
|
---|
53 | <tr><td colspan=\"2\">";
|
---|
54 | makebutton($lang_run_patch['run_sql'], "javascript:do_submit('form1',0)",200);
|
---|
55 | $output .= "</td></tr>
|
---|
56 | </table>
|
---|
57 | </form></center><br />";
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | //#####################################################################################################
|
---|
62 | // DO Run the Query line by line
|
---|
63 | //#####################################################################################################
|
---|
64 | function do_run_patch(){
|
---|
65 | global $lang_run_patch, $lang_global, $output, $mangos_db, $realm_db;
|
---|
66 |
|
---|
67 | if ( empty($_POST['query']) || empty($_POST['use_db']) ) redirect("run_patch.php?error=1");
|
---|
68 |
|
---|
69 | $mysql = new MySQL;
|
---|
70 | $mysql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass']);
|
---|
71 |
|
---|
72 | $use_db = $mysql->quote_smart($_POST['use_db']);
|
---|
73 | $query = $_POST['query'];
|
---|
74 |
|
---|
75 | if ($use_db == $realm_db['name']) $mysql->db($realm_db['name']);
|
---|
76 | else {
|
---|
77 | foreach ($mangos_db as $db)
|
---|
78 | if ($use_db == $db['name']) $mysql->connect($db['addr'], $db['user'], $db['pass'], $db['name']);
|
---|
79 | }
|
---|
80 |
|
---|
81 | $new_queries = array();
|
---|
82 | $good = 0;
|
---|
83 | $bad = 0;
|
---|
84 | $line = 0;
|
---|
85 |
|
---|
86 | $queries = explode("\n",$query);
|
---|
87 | for($i=0; $i<count($queries); $i++) {
|
---|
88 | $queries[$i] = trim($queries[$i]);
|
---|
89 |
|
---|
90 | if(strpos ($queries[$i], '#') === 0 || strpos ($queries[$i], '--') === 0) $line++;
|
---|
91 | else array_push($new_queries, $queries[$i]);
|
---|
92 | }
|
---|
93 | $qr=split(";\n",implode("\n",$new_queries));
|
---|
94 |
|
---|
95 | foreach($qr as $qry) {
|
---|
96 | $line++;
|
---|
97 | if(trim($qry)) ($mysql->query(trim($qry))?$good++:$bad++);
|
---|
98 | if ($bad) {
|
---|
99 | $err = ereg_replace ("\n","",mysql_error());
|
---|
100 | $err = ereg_replace ("\r\n$","",$err);
|
---|
101 | $err = ereg_replace ("\r$","",$err);
|
---|
102 | error("{$lang_run_patch['err_in_line']}: $line <br />$err");
|
---|
103 | exit();
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | $mysql->close();
|
---|
108 |
|
---|
109 | if ($queries) redirect("run_patch.php?error=2&tot=$good");
|
---|
110 | else redirect("run_patch.php?error=3");
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | //########################################################################################################################
|
---|
115 | // MAIN
|
---|
116 | //########################################################################################################################
|
---|
117 | $err = (isset($_GET['error'])) ? $_GET['error'] : NULL;
|
---|
118 |
|
---|
119 | $output .= "<div class=\"top\">";
|
---|
120 | switch ($err) {
|
---|
121 | case 1:
|
---|
122 | $output .= "<h1><font class=\"error\">{$lang_global['empty_fields']}</font></h1>";
|
---|
123 | break;
|
---|
124 | case 2:
|
---|
125 | if(isset($_GET['tot'])) $tot = $_GET['tot'];
|
---|
126 | else $tot = NULL;
|
---|
127 | $output .= "<h1><font class=\"error\">$tot {$lang_run_patch['query_executed']}</font></h1>";
|
---|
128 | break;
|
---|
129 | case 3:
|
---|
130 | $output .= "<h1><font class=\"error\">{$lang_run_patch['no_query_found']}</font></h1>";
|
---|
131 | break;
|
---|
132 | default:
|
---|
133 | $output .= "<h1>{$lang_run_patch['run_patch']}</h1>";
|
---|
134 | }
|
---|
135 | $output .= "</div>";
|
---|
136 |
|
---|
137 | $action = (isset($_GET['action'])) ? $_GET['action'] : NULL;
|
---|
138 |
|
---|
139 | switch ($action) {
|
---|
140 | case "do_run_patch":
|
---|
141 | do_run_patch();
|
---|
142 | break;
|
---|
143 | default:
|
---|
144 | print_upload();
|
---|
145 | }
|
---|
146 |
|
---|
147 | require_once("footer.php");
|
---|
148 | ?>
|
---|