1: 2: /* -------------------------------------------------------------
3: This file is part of FreeNATS
4:
5: FreeNATS is (C) Copyright 2008 PurplePixie Systems
6:
7: FreeNATS is free software: you can redistribute it and/or modify
8: it under the terms of the GNU General Public License as published by
9: the Free Software Foundation, either version 3 of the License, or
10: (at your option) any later version.
11:
12: FreeNATS is distributed in the hope that it will be useful,
13: but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with FreeNATS. If not, see www.gnu.org/licenses
19:
20: For more information see www.purplepixie.org/freenats
21: -------------------------------------------------------------- */
22:
23: ob_start();
24: require("include.php");
25: $NATS->Start();
26: if (!$NATS_Session->Check($NATS->DB))
27: {
28: header("Location: ./?login_msg=Invalid+Or+Expired+Session");
29: exit();
30: }
31: if ($NATS_Session->userlevel<9) UL_Error("Backup Manager");
32:
33: if (isset($_REQUEST['action']))
34: {
35: switch ($_REQUEST['action'])
36: {
37: case "backup":
38:
39: header("Content-type: text/sql");
40: if (isset($_REQUEST['filename'])) $filename=$_REQUEST['filename'];
41: else $filename="freenats-".date("Ymd").".sql";
42: header("Content-Disposition: attachment; filename=".$filename);
43:
44: echo "-- FreeNATS SQL Data Backup\n";
45: echo "-- ".date("Y-m-d H:i:s")."\n\n";
46: echo "-- Warning: Only use on FreeNATS ".$NATS->Version." or later schemas!\n\n";
47: foreach($_REQUEST['table'] as $table)
48: {
49: echo "-- ".$table."\n";
50: if (isset($_REQUEST['truncate_'.$table]))
51: echo "TRUNCATE TABLE `".$table."`;\n";
52: $q="SELECT * FROM ".ss($table);
53: $r=$NATS->DB->Query($q);
54: while ($row=$NATS->DB->Fetch_Array($r))
55: {
56: $keys=array();
57: $vals=array();
58: foreach($row as $key => $val)
59: {
60: if (!is_numeric($key))
61: {
62: $keys[]=$key;
63: $vals[]=$val;
64: }
65: }
66: $uq="INSERT INTO `".$table."`(";
67: $first=true;
68: foreach($keys as $key)
69: {
70: if ($first) $first=false;
71: else $uq.=",";
72: $uq.="`".$key."`";
73: }
74: $uq.=") VALUES(";
75: $first=true;
76: foreach($vals as $val)
77: {
78: if ($first) $first=false;
79: else $uq.=",";
80: $uq.="\"".$val."\"";
81: }
82: $uq.=");";
83: echo $uq."\n";
84: }
85: echo "\n";
86: }
87: echo "\n-- End of Backup\n";
88: ob_end_flush();
89: exit();
90: break;
91:
92: case "restore":
93: if (isset($_REQUEST['live_run'])) $live=true;
94: else $live=false;
95: Screen_Header("Restoration",1,1,"","main","admin");
96: if ($live) echo "Live Data Restore...
";
97: else echo "Dummy Run - Show What Will be Done