-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables.php
372 lines (360 loc) · 12.3 KB
/
tables.php
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<link rel="stylesheet" href="./styles/stylesheet.css" type="text/css" />
<link rel='stylesheet' href='./styles/humane-jackedup.css'/>
<script src='./js/jquery.min.js'></script>
<script src='./js/humane.min.js'></script>
<script src='./js/functions.js'></script>
<div id="container">
<div id="left">
<center>
<a href='./index.php'><img src="./styles/images/small_logo2.png" style="margin-top: 10px;"></a><br>
<a href='./index.php' title='Home'><img src='./styles/images/home.png'></a>
<a href='./users.php' title='Users'><img src="./styles/images/users.png"></a>
<a href='./processes.php' title='Processes'><img src="./styles/images/processes.png"></a>
<a href='./logs.php?s=0' title='Log Viewer'><img src='./styles/images/logs.png'></a>
<a href='./dumps.php' title='Dumps'><img src='./styles/images/dumps.png'></a>
<a href='./column_dump.php' title='Column Dumper'><img src='./styles/images/column_dumper.png'></a>
</center>
<?php
require_once ("./includes/functions.php");
// Check to see if password protection is enabled
if($settings->password) {
// Check to see if user is logged in
if(!logged_in()) {
$login->display_login();
}
}
if(isset($_GET['db'])) {
$database = $_GET['db'];
echo "Tables in: <a href='?db=$database'>$database</a><br>";
$get_tables = mysql_query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '$database'");
$num_tables = mysql_num_rows($get_tables);
echo "<table width='100%' style='font-size: 12px;'>";
while ($row = mysql_fetch_array($get_tables)) {
$table = $row[0];
echo "<tbody>
<tr id='table_$table'>
<td><a href='?explore&db=$database&table=$table&l=0'>$table</a></td>
</tr>
</tbody>";
}
echo "</table>";
}
?>
</div>
<div id="right">
<?php
//Display Header
$header->display_header();
if(isset($_GET['db']) && empty($_GET['table'])) {
if($settings->estimate_sizes) {
$dbsize = mysql_fetch_assoc(mysql_query("SELECT table_schema AS \"database\", sum(data_length + index_length) AS \"size\" FROM information_schema.TABLES WHERE table_schema='".$_GET['db']."' GROUP BY table_schema"));
}
$dbchar = mysql_fetch_assoc(mysql_query("SELECT default_collation_name,default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = '".$_GET['db']."'"));
echo "<center>
<a href='./dump_db.php?db=$database' title='Dump Database'><img src='./styles/images/big_db_dump.png'></a>
<a href='#' onclick=\"drop_database('".$_GET['db']."');\" title='Drop Database'><img src='./styles/images/big_db_drop.png'></a><br>
<div class='datagrid' style='width: 60%;'>
<table width='100%'>
<thead>
<tr>
<th colspan='2'>".htmlspecialchars($_GET['db'])."</th>
</tr>
<thead>
<tbody>
<tr>
<td>Tables:</td>
<td>$num_tables</td>
</tr>";
if($settings->estimate_sizes) {
echo "<tr class='alt'>
<td>Estimated Size:</td>
<td>".ByteConversion($dbsize['size'])."</td>
</tr>";
}
echo "<tr>
<td>Collation:</td>
<td>".$dbchar['default_collation_name']."</td>
</tr>
<tr class='alt'>
<td>Character Set:</td>
<td>".$dbchar['default_character_set_name']."</td>
</tbody>
</table>
</div>
</center>";
}
if(isset($_GET['explore'])) {
$database = $_GET['db'];
$table = $_GET['table'];
$limit = $_GET['l'];
$row_limit = 100;
$getcolumns = mysql_query("SHOW COLUMNS FROM $database.$table");
$numrows = mysql_num_rows($getcolumns);
$rows = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) as num_rows FROM $database.$table"));
if($settings->estimate_sizes) {
$tablesize = mysql_fetch_assoc(mysql_query("SELECT table_name AS \"table\", sum(data_length + index_length) AS \"size\" FROM information_schema.TABLES WHERE table_schema='".$database."' AND table_name='".$table."'"));
}
$status = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS FROM $database WHERE Name='".$table."'"));
// echo table information
echo "<center>
<a href='./dump_table.php?dump_table&db=$database&table=$table' title='Dump Table'><img src='./styles/images/big_db_dump.png'></a>
<a href='?insert&db=$database&table=$table' title='Insert Row'><img src='./styles/images/insert_row.png'></a>
<a href='?truncate_table&db=$database&table=$table' title='Truncate Table'><img src='./styles/images/table_truncate.png'></a>
<a href='?drop_table&db=$database&table=$table' title='Drop Table'><img src='./styles/images/big_db_drop.png'></a>
<a href='./search.php?db=$database&table=$table' title='Search Table'><img src='./styles/images/table_search.png'></a><br>
<div class='datagrid' style='width: 60%;'>
<table width='100%'>
<thead>
<tr>
<th colspan='2'>".htmlspecialchars($database).".".htmlspecialchars($table)."
</tr>
<thead>
<tbody>
<tr>
<td>Rows:</td>
<td>".number_format($rows['num_rows'])."</td>
</tr>";
if($settings->estimate_sizes) {
echo "<tr class='alt'>
<td>Estimated Size:</td>
<td>".ByteConversion($tablesize['size'])."</td>
</tr>";
}
echo "<tr>
<td>Engine:</td>
<td>".$status['Engine']."</td>
</tr>
<tr class='alt'>
<td>Version:</td>
<td>".$status['Version']."</td>
</tr>
<tr>
<td>Row Format:</td>
<td>".$status['Row_format']."</td>
</tr>
<tr class='alt'>
<td>Average Row Length:</td>
<td>".ByteConversion($status['Avg_row_length'])."</td>
</tr>
<tr>
<td>Create Time:</td>
<td>".$status['Create_time']."</td>
</tr>
<tr class='alt'>
<td>Update Time:</td>
<td>".$status['Update_time']."</td>
</tr>
<tr>
<td>Collation:</td>
<td>".$status['Collation']."</td>
</tr>
<tr class='alt'>
<td>Comment:</td>
<td>".$status['Comment']."</td>
</tr>
</tbody>
</table>
</div>
</center><br><br><br>";
// echo table data
echo "<center>
<div class='datagrid'>
<table width='100%'>
<thead>
<tr>";
$fieldarray = array();
while($row = mysql_fetch_array($getcolumns)) {
echo "<th>".$row['Field']."</th>";
array_push($fieldarray, $row['Field']);
}
echo " <th>Edit</th>
<th>Delete</th>
</tr>
</thead>";
$columndata = mysql_query("SELECT * FROM $database.$table LIMIT $limit,$row_limit");
echo " <tbody>";
$isOdd = true;
$ii = 0;
while($row = mysql_fetch_array($columndata)) {
if($isOdd) { echo "<tr class='alt' id='row_$ii'>"; } else { echo "<tr id='row_$ii'>"; }
for($i = 0; $i < $numrows + 2; $i++) {
if($i == $numrows) {
echo "<td><a href='?editrow&db=$database&table=$table&column=".$fieldarray[0]."&value=".$row[0]."' title='Edit Row'><img src='./styles/images/table_edit.png'></a></td>";
} elseif($i == $numrows + 1) {
echo "<td><a href='#' onclick=\"delete_row('$table', '$database', '".$row[0]."', '".$fieldarray[0]."', '$ii');\" title='Delete Row'><img src='./styles/images/table_row_delete.png'></a></td>";
} else {
echo "<td>".htmlspecialchars($row[$i])."</td>";
}
}
echo "</tr>";
$isOdd = ! $isOdd;
$ii++;
}
echo " <tfoot>
<tr>
<td colspan='".($numrows + 2)."'>
<div id='paging'>
<ul>
<li><a href='?explore&db=$database&table=$table&l=".($limit - 100)."'><span>Previous</span></a></li>";
$totalrows = mysql_fetch_object(mysql_query("SELECT COUNT(*) as num_rows FROM $database.$table"));
$divide = floor($totalrows->num_rows / 100);
for($i = 0; $i <= $divide; $i++) {
echo "<li><a href='?explore&db=$database&table=$table&l=".($i * 100)."'><span>".($i + 1)."</span></a></li>";
}
echo " <li><a href='?explore&db=$database&table=$table&l=".($limit + 100)."'><span>Next</span></a></li>
</ul>
</div>
</tr>
</tfoot>
<tbody>
</table>
</div>
</center>";
}
if(isset($_GET['drop_table'])) {
$table = $_GET['table'];
$database = $_GET['db'];
if(mysql_query("DROP TABLE $database.$table")) {
if($settings->logging) {
$log->logaction("Dropped $database.$table");
}
echo "<script>humane.log('Dropped table: $table', function () { window.location = '?db=$database'; });</script>";
exit;
} else {
$log->MySQLError();
echo "<script>humane.log('Failed to drop table!', function () { window.location = '?explore&db=$database&table=$table&l=0'; });</script>";
exit;
}
}
if(isset($_GET['truncate_table'])) {
$table = $_GET['table'];
$database = $_GET['db'];
if(mysql_query("TRUNCATE TABLE $database.$table")) {
if($settings->logging) {
$log->logaction("Truncated tabled $database.$table");
}
echo "<script>humane.log('Truncated table: $table', function () { window.location = '?explore&db=$database&table=$table&l=0'; });</script>";
exit;
} else {
$log->MySQLError();
echo "<script>humane.log('Failed to truncate table!', function () { window.location = '?explore&db=$database&table=$table&l=0'; });</script>";
exit;
}
}
if(isset($_POST['insert_row'])) {
$database = $_GET['db'];
$table = $_GET['table'];
$query = "INSERT INTO $database.$table VALUES (";
array_pop($_POST);
foreach($_POST as $key => $val) {
$query .= "'".mysql_real_escape_string($val)."',";
}
$query = rtrim($query, ",").")";
if(mysql_query($query)) {
if($settings->logging) {
$log->logaction("Inserted row into $database.$table");
}
echo "<script>humane.log('Inserted row!', function () { window.location = '?insert&db=dbtech&table=$table'; });</script>";
exit;
} else {
$log->MySQLerror();
echo "<script>humane.log('Failed to insert row!', function () { window.location = '?insert&db=dbtech&table=$table'; });</script>";
exit;
}
}
if(isset($_GET['insert'])) {
$database = $_GET['db'];
$table = $_GET['table'];
$getcolumns = mysql_query("SHOW COLUMNS FROM $database.$table");
echo "<center>
<div class='datagrid' style='width: 80%;'>
<form action='' method='post'>
<table width='100%'>
<thead>
<tr>
<th>Column</th>
<th>Type</th>
<th>Value</th>
</tr>
</thead>
<tbody>";
$isOdd = true;
while($row = mysql_fetch_array($getcolumns)) {
if($isOdd) { echo "<tr class='alt'>"; } else { echo "<tr>"; }
echo " <td>".$row['Field']."</td>
<td>".$row['Type']."</td>
<td><input type='text' name='".$row['Field']."' size='35'></td>";
echo "</tr>";
$isOdd = ! $isOdd;
}
echo "<tr>
<td colspan='3'><center><input type='submit' name='insert_row' value='Insert'></center></td>
</tr>";
echo " <tbody>
</table>
</form>
</div>
</center>";
}
if(isset($_POST['edit_row'])) {
$database = $_GET['db'];
$table = $_GET['table'];
$column = $_GET['column'];
$value = $_GET['value'];
$query = "UPDATE $database.$table SET ";
array_pop($_POST);
foreach($_POST as $key => $val) {
$query .= "$key='".mysql_real_escape_string($val)."', ";
}
$query = rtrim($query, ", ")." WHERE $column='$value'";
if(mysql_query($query)) {
if($settings->logging) {
$log->logaction("Edited row in $database.$table");
}
echo "<script>humane.log('Edited row!', function () { window.location = '?editrow&db=$database&table=$table&column=$column&value=$value'; });</script>";
exit;
} else {
$log->MySQLerror();
echo "<script>humane.log('Failed to edit row!', function () { window.location = '?editrow&db=$database&table=$table&column=$column&value=$value'; });</script>";
exit;
}
}
if(isset($_GET['editrow'])) {
$database = $_GET['db'];
$table = $_GET['table'];
$column = $_GET['column'];
$value = $_GET['value'];
$getcolumns = mysql_query("SHOW COLUMNS FROM $database.$table");
$columndata = mysql_fetch_array(mysql_query("SELECT * FROM $database.$table WHERE $column='$value'"));
echo "<center>
<div class='datagrid' style='width: 80%;'>
<form action='' method='post'>
<table width='100%'>
<thead>
<tr>
<th>Column</th>
<th>Type</th>
<th>Value</th>
</tr>
</thead>
<tbody>";
$i = 0;
while($row = mysql_fetch_array($getcolumns)) {
echo "<tr>
<td>".$row['Field']."</td>
<td>".$row['Type']."</td>
<td><textarea cols='50' rows='5' name='".$row['Field']."'>".htmlspecialchars($columndata[$i])."</textarea></td>
</tr>";
$i++;
}
echo "<tr>
<td colspan='3'><center><input type='submit' name='edit_row' value='Edit'></center></td>
</tr>";
echo " <tbody>
</table>
</form>
</div>
</center>";
}
?>
</div>