-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdump.php
More file actions
executable file
·164 lines (140 loc) · 3.96 KB
/
dump.php
File metadata and controls
executable file
·164 lines (140 loc) · 3.96 KB
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
<?php
/**************************************************************************
* 0xBB ~ Bullettin Board *
**************************************************************************
* 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 3 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, see <http://www.gnu.org/licenses/>
* =========================================================================*
* Software: 0xBB
* Software version: 2.0
* Author: KinG-InFeT
* Copyleft: GNU General Public License
* =========================================================================*
* dump.php
***************************************************************************/
set_time_limit(0);
include "kernel.php";
list ($username, $password) = get_data ();
if (!login ($username, $password))
_err("ACCESS DENIED");
if (!(level($username) == 'admin'))
_err("ACCESS DENIED");
if(isset($_REQUEST['esegui_backup'])) {
$mysql_host = $db_host;
$mysql_database = $db_name;
$mysql_username = $db_user;
$mysql_password = $db_pass;
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="'.$mysql_host."_".$mysql_database."_".date('YmdHis').'.sql"');
_mysqldump($mysql_database);
}
function _mysqldump($mysql_database)
{
$sql = "show tables;";
$result = mysql_query($sql);
if( $result)
{
while( $row = mysql_fetch_row($result))
{
_mysqldump_table_structure($row[0]);
if( isset($_REQUEST['sql_table_data']))
{
_mysqldump_table_data($row[0]);
}
}
}
else
{
print "/* no tables in $mysql_database */\n";
}
mysql_free_result($result);
}
function _mysqldump_table_structure($table)
{
print "/* Table structure for table `$table` */\n";
if( isset($_REQUEST['sql_drop_table']))
{
print "DROP TABLE IF EXISTS `$table`;\n\n";
}
if( isset($_REQUEST['sql_create_table']))
{
$sql="show create table `$table`; ";
$result=mysql_query($sql);
if( $result)
{
if($row = mysql_fetch_assoc($result))
{
print $row['Create Table'].";\n\n";
}
}
mysql_free_result($result);
}
}
function _mysqldump_table_data($table)
{
$sql = "select * from `$table`;";
$result = mysql_query($sql);
if( $result)
{
$num_rows = mysql_num_rows($result);
$num_fields = mysql_num_fields($result);
if( $num_rows > 0)
{
print "/* dumping data for table `$table` */\n";
$field_type = array();
$i = 0;
while( $i < $num_fields)
{
$meta = mysql_fetch_field($result, $i);
array_push($field_type, $meta->type);
$i++;
}
print "INSERT INTO `$table` VALUES\n";
$index = 0;
while( $row = mysql_fetch_row($result))
{
print "(";
for( $i = 0; $i < $num_fields; $i++)
{
if( is_null( $row[$i]) )
print "null";
else
{
switch( $field_type[$i])
{
case 'int':
print $row[$i];
break;
case 'string':
case 'blob' :
default:
print "'".mysql_real_escape_string($row[$i])."'";
}
}
if( $i < $num_fields - 1)
print ",";
}
print ")";
if( $index < $num_rows - 1)
print ",";
else
print ";";
print "\n";
$index++;
}
}
}
mysql_free_result($result);
print "\n";
}
?>