|
@@ -3,6 +3,8 @@ include "config.php";
|
3
|
3
|
|
4
|
4
|
$table = str_replace('*','%',preg_replace('/[^a-zA-Z0-9\-_*,]/','',isset($_GET["table"])?$_GET["table"]:'*'));
|
5
|
5
|
$callback = preg_replace('/[^a-zA-Z0-9\-_]/','',isset($_GET["callback"])?$_GET["callback"]:false);
|
|
6
|
+$page = preg_replace('/[^0-9:]/','',isset($_GET["page"])?$_GET["page"]:false);
|
|
7
|
+$filter = str_replace('*','%',preg_replace('/[^a-zA-Z0-9\-_*:]/','',isset($_GET["filter"])?$_GET["filter"]:false));
|
6
|
8
|
|
7
|
9
|
$mysqli = new mysqli($config["hostname"], $config["username"], $config["password"], $config["database"]);
|
8
|
10
|
|
|
@@ -18,8 +20,8 @@ foreach ($tablelist as $table) {
|
18
|
20
|
}
|
19
|
21
|
}
|
20
|
22
|
|
21
|
|
-if ($config["read_whitelist"]) $tables = array_intersect($tables, $config["read_whitelist"]);
|
22
|
|
-if ($config["read_blacklist"]) $tables = array_diff($tables, $config["read_blacklist"]);
|
|
23
|
+if ($config["list_whitelist"]) $tables = array_intersect($tables, $config["list_whitelist"]);
|
|
24
|
+if ($config["list_blacklist"]) $tables = array_diff($tables, $config["list_blacklist"]);
|
23
|
25
|
|
24
|
26
|
if (empty($tables)) {
|
25
|
27
|
die(header("Content-Type:",true,404));
|
|
@@ -30,13 +32,27 @@ if (empty($tables)) {
|
30
|
32
|
header("Content-Type: application/json");
|
31
|
33
|
}
|
32
|
34
|
|
|
35
|
+if ($filter) {
|
|
36
|
+ $filter = explode(':',$filter,2);
|
|
37
|
+ if (count($filter)<2) $filter = false;
|
|
38
|
+}
|
|
39
|
+
|
|
40
|
+if ($page) {
|
|
41
|
+ $page = explode(':',$page,2);
|
|
42
|
+ if (count($page)<2) $page[1]=20;
|
|
43
|
+ $page[0] *= $page[1];
|
|
44
|
+}
|
|
45
|
+
|
33
|
46
|
echo '{';
|
34
|
47
|
$first_table = true;
|
35
|
48
|
foreach ($tables as $table) {
|
36
|
49
|
if ($first_table) $first_table = false;
|
37
|
50
|
else echo ',';
|
38
|
51
|
echo '"'.$table.'":{"columns":';
|
39
|
|
- if ($result = $mysqli->query("SELECT * FROM `$table`")) {
|
|
52
|
+ $sql = "SELECT * FROM `$table`";
|
|
53
|
+ if ($filter) $sql .= " WHERE `$filter[0]` LIKE '$filter[1]'";
|
|
54
|
+ if ($page) $sql .= " LIMIT $page[1] OFFSET $page[0]";
|
|
55
|
+ if ($result = $mysqli->query($sql)) {
|
40
|
56
|
$fields = array();
|
41
|
57
|
foreach ($result->fetch_fields() as $field) $fields[] = $field->name;
|
42
|
58
|
echo json_encode($fields);
|
|
@@ -55,4 +71,4 @@ echo '}';
|
55
|
71
|
|
56
|
72
|
if ($callback) {
|
57
|
73
|
echo ');';
|
58
|
|
-}
|
|
74
|
+}
|