Linux multi-monitor fullscreen support
[ryzomcore.git] / nelns / admin / public_html / backup_interface.php
blobfb50e2ebd04998f3adaf380b5daf3d00a9b1cde0
1 <?php
2 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
3 // Copyright (C) 2010 Winch Gate Property Limited
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 $publicAccess = true;
19 include('authenticate.php');
20 include('request_interface.php');
22 $error = '';
24 if ($allowDownload && $download)
26 // query file to BSs
27 $query = "*.*.BS.getFileBase64Content $file";
28 $qstate = nel_query($query, $commandResult);
30 //echo "$commandResult";
32 if ($commandResult)
34 $res_array = explode("\n", $commandResult);
35 $parse_start = 0;
36 while (true)
38 if ($parse_start >= count($res_array))
39 break;
41 $offset = 4;
42 list($res_shard) = sscanf($res_array[$parse_start], "----- Result from Shard %s");
43 list($dld_file, $num_res, $file_size, $originalMD5) = sscanf($res_array[$parse_start+$offset-1], "file %s lines %d size %d haskey %s");
44 $start = $parse_start+$offset;
45 $stop = $start+$num_res;
46 $parse_start += $num_res+$offset;
47 if ($num_res == 0)
48 continue;
50 $buffer = '';
51 for ($line=$start; $line<$stop; ++$line)
52 $buffer .= trim($res_array[$line]);
54 $decoded = base64_decode($buffer);
55 $decodedMD5 = md5($decoded);
57 if ($originalMD5 != '' && $originalMD5 != $decodedMD5)
59 $error = "<font color=#ff0000>ERROR:</font> failed to download file '$file', MD5 signature indicates file is corrupted.";
61 else
63 header("Content-type: application/bin");
64 header("Content-Disposition: attachment; filename=".basename($file));
65 echo $decoded;
67 die();
72 if (!$error)
73 $error = "<font color=#ff0000>ERROR:</font> failed to download file '$file', file may not exist on any server.";
76 if ($allowUpload && $upload)
78 $f = fopen($upld_file, "rb");
79 if ($f)
81 $content = base64_encode(fread($f, $upld_file_size));
82 $query = $shard_addr.".putFileBase64Content $file $content";
84 $qstate = nel_query($query, $commandResult);
88 htmlProlog($_SERVER['PHP_SELF'], "Backup Interface (Character Up/Download)");
90 // input variables :
91 // - $charid : character id to upload/download
92 // - $file : filename to upload/download
95 $query = "*.*.BS.State";
96 $qstate = nel_query($query, $result);
97 if ($qstate)
99 $arr = explode(' ', $result);
100 $numRes = count($arr);
101 $numRows = current($arr);
102 $numLines = ($numRes-$numRows-2)/$numRows;
103 next($arr);
104 for ($i=0; $i<$numRows; ++$i)
106 $vars[] = current($arr);
107 next($arr);
109 unset($shards);
110 for ($i=0; $i<$numLines; ++$i)
112 unset($l);
113 foreach($vars as $var)
115 $l[$var] = current($arr);
116 next($arr);
118 $shards[] = $l;
123 echo "<br><br>\n";
125 if ($error)
127 echo "<b>$error</b><br><br>\n";
130 if ($allowDownload)
132 echo "<table border=1>";
133 echo "<form method='post' action='$_SERVER['PHP_SELF']'>";
134 echo "<tr><td bgcolor=#DDDDEE>Download file</td><tr>";
135 echo "<td>";
136 echo "<input type=text name='file' size=40 maxlength=255 value='$file'/>";
137 echo "<input type=submit name='download' value='Download'/>";
138 echo "</td>";
139 echo "</tr>";
140 echo "</form>";
141 echo "</table>";
143 echo "<br>";
146 if ($allowUpload)
148 echo "<table border=1>";
149 echo "<form enctype='multipart/form-data' method='post' action='$_SERVER['PHP_SELF']'>";
150 echo "<tr><td bgcolor=#DDDDEE>Upload file</td><tr>";
151 echo "<td>";
152 echo "<input type=file name='upld_file' size=40 maxlength=255/><br>";
153 echo "<select name=shard_addr>\n";
154 foreach ($shards as $shard)
156 $addr = $shard['shard'].".".$shard['server'].".".$shard['service'];
157 echo "<option value='$addr'".($shard_addr == $addr ? " selected" : "").">$addr</option>";
159 echo "</select>\n";
160 echo "<input type=text name='file' size=40 maxlength=255 value='$file'/>";
161 echo "<input type=submit name='upload' value='Upload'/>";
162 echo "</td>";
163 echo "</tr>";
164 echo "</form>";
165 echo "</table>";
169 echo "<table border=0><tr valign=top>\n";
170 echo "<form method=post action='$_SERVER['PHP_SELF']' name='cmdform'>\n";
171 echo "<td>\n";
173 $result = sqlquery("SELECT DISTINCT shard FROM service ORDER BY shard");
175 echo "<select multiple size=".(sqlnumrows($result))." name='selshards[]'>";
176 while ($result && ($arr=sqlfetch($result)))
178 $selected = (isset($selshards) && in_array($arr["shard"], $selshards)) ||
179 (isset($admfilter_shard) && $admfilter_shard!="" && strstr($arr["shard"], $admfilter_shard) ||
180 ($admfilter_shard == "" && !isset($selshards)));
182 if ($selected)
183 $selected_shards[] = $arr["shard"];
185 echo "<option value='".$arr["shard"]."'".($selected ? " selected" : "").">".$arr["shard"];
187 echo "</select>\n";
189 echo "</td>\n";
191 echo "<td width=30>&nbsp;</td>\n";
193 echo "<td>\n";
194 echo "<table border=0>\n";
195 echo "<tr><th align=left>Player/Character name</th></tr>\n";
196 echo "<tr><td><input name=char_name value='".stripslashes($char_name)."' size=50 maxlength=20480></td>\n";
197 echo "<td><input type=submit value='Locate'></td></tr>\n";
198 echo "</form></table>\n";
200 if (isset($char_name))
202 $addr = (count($selected_shards) > 0 ? "[".join(",", $selected_shards)."]" : "*").".*.EGS.playerInfo $char_name";
203 $qstate = nel_query($addr, $commandResult);
206 if ($commandResult)
208 $res_array = explode("\n", $commandResult);
210 $parse_start = 0;
211 echo "<br><br>\n";
213 $num_player = 0;
215 echo "<script><!--\n";
216 echo "var player_eid = new Array(30000);\n";
217 echo "var player_select = new Array(30000);\n";
218 echo "var player_bgcolor = new Array(30000);\n";
219 echo "var player_sel_bgcolor = new Array(30000);\n";
220 echo "var player_state = new Array(30000);\n";
221 echo "var player_uidslot = new Array(30000);\n";
222 echo "//--></script>\n";
224 while (true)
226 if ($res_array[$parse_start] == "")
227 break;
229 $offset = 4;
230 list($res_shard) = sscanf($res_array[$parse_start], "----- Result from Shard %s");
231 list($num_res) = sscanf($res_array[$parse_start+$offset-1], "%d");
232 $start = $parse_start+$offset;
233 $stop = $start+$num_res;
234 $parse_start += $num_res+$offset;
236 $last_uid = "";
237 $icolor = 0;
239 echo "<b>Result of search for '$char_name' on Shard '$res_shard' ($num_res entr".($num_res>1 ? "ies" : "y")." found)</b><br>\n";
240 echo "<font size=-2>Click on EntityId to get directly to DefaultPlayer view, <br>or click anywhere else to select a player and then click Select Players button.</font><br><br>\n";
242 echo "<table border=1><tr><th>UId</th><th>UserName</th><th>EId</th><th>EntityName</th><th>EntitySlot</th><th>State</th><th>Ext commands</th></tr>\n";
244 for ($line=$start; $line<$stop; ++$line)
246 $l = explode(" ", $res_array[$line]);
248 for ($i=1; $i<count($l); $i+=2)
249 $parse[$l[$i-1]] = str_replace("'", "", $l[$i]);
250 $parse["State"] = $l[count($l)-1];
252 $chUser = ($last_uid == "");
253 if ($last_uid != "" && $parse["UId"] != $last_uid)
255 $icolor = 1-$icolor;
256 $chUser = true;
259 $last_uid = $parse["UId"];
261 $bgcolor_online = ($icolor ? "#CCEECC" : "#BBDDBB");
262 $bgcolor_offline = ($icolor ? "#EEEEEE" : "#DDDDDD");
263 $bgcolor = ($parse['State'] == 'Online') ? $bgcolor_online : $bgcolor_offline;
264 $sel_bgcolor = ($icolor ? "#FFDDAA" : "#FFCC88");
266 echo "<script><!--\n";
267 echo "player_eid[$num_player]='".$parse["EId"]."';\n";
268 echo "player_select[$num_player]=false;\n";
269 echo "player_bgcolor[$num_player]='$bgcolor';\n";
270 echo "player_sel_bgcolor[$num_player]='$sel_bgcolor';\n";
271 echo "player_uidslot[$num_player]='".$parse["UId"]." ".$parse["EntitySlot"]."';\n";
272 echo "player_state[$num_player]='".$parse["State"]."';\n";
273 echo "//--></script>\n";
275 echo "<tr id='player_$num_player' onClick='clickOnEntity($num_player); return true;' bgcolor=$bgcolor>";
276 echo "<td>".($chUser ? $parse["UId"] : "")."</td>";
277 echo "<td>".$parse["UserName"]."</td>";
278 echo "<td><a href='index.php?select_view=DefaultPlayer&filter_shard=$res_shard&filter_entity=".$parse["EId"]."'>".$parse["EId"]."</a></td>";
279 echo "<td>".$parse["EntityName"]."</td>";
280 echo "<td>".$parse["EntitySlot"]."</td>";
281 echo "<td>".$parse["State"]."</td>";
282 echo "<td>";
283 if (isset($parse["SaveFile"]))
285 echo "<a href='backup_interface.php?file=".$parse["SaveFile"]."'>Load/Save sheet</a>";
287 echo "</td>";
288 echo "</tr>\n";
290 ++$num_player;
293 echo "</table>\n";
296 echo "<script><!--\n";
297 echo "var num_player = $num_player;\n";
298 echo "//--></script>\n";
300 echo "<form name='select_player_form' method=post action='index.php?select_view=DefaultPlayer'>\n";
301 echo "<input type=submit name='from_player_locator' value='Select Players'>\n";
302 echo "<input id='filter_entity_hidden' type=hidden name=filter_entity value=''>\n";
303 echo "<input id='active_player_hidden' type=hidden name=active_player value=''>\n";
304 echo "</form>\n";
307 echo "</td>\n";
309 echo "</tr></table>\n";
311 echo "<script type='text/javascript'><!--\n";
312 echo "if (document.cmdform) { document.cmdform.execCommand.focus(); }\n";
313 echo "// --></script>\n";
315 htmlEpilog();