Browse Source

Prepare for full CRUD support

Maurits van der Schee 10 years ago
parent
commit
6e79552dc9
2 changed files with 12 additions and 11 deletions
  1. 3
    5
      .htaccess
  2. 9
    6
      read.php

+ 3
- 5
.htaccess View File

@@ -1,7 +1,5 @@
1 1
 RewriteEngine On
2
-RewriteBase /
2
+RewriteBase /api/
3 3
 
4
-RewriteCond %{REQUEST_FILENAME} !-f
5
-RewriteCond %{REQUEST_FILENAME} !-d
6
-RewriteRule (.+) api.php?table=$1 [L,QSA]
7
-RewriteRule ^$ api.php [L,QSA]
4
+RewriteCond %{REQUEST_METHOD} GET
5
+RewriteRule (.*) read.php?table=$1 [L,QSA]

api.php → read.php View File

@@ -1,22 +1,25 @@
1 1
 <?php
2 2
 include "config.php";
3 3
 
4
-$table = str_replace('*','%',preg_replace('/[^a-zA-Z0-9\-_*]/','',isset($_GET["table"])?$_GET["table"]:'*'));
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 6
 
7 7
 $mysqli = new mysqli($config["hostname"], $config["username"], $config["password"], $config["database"]);
8 8
 
9 9
 if ($mysqli->connect_errno) die('Connect failed: '.$mysqli->connect_error);
10 10
 
11
+$tablelist = explode('/',$table);
11 12
 $tables = array();
12 13
 
13
-if ($result = $mysqli->query("SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME` LIKE '$table' AND `TABLE_SCHEMA` = '$config[database]'")) {
14
-    while ($row = $result->fetch_row()) $tables[] = $row[0];
15
-    $result->close();
14
+foreach ($tablelist as $table) {
15
+    if ($result = $mysqli->query("SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME` LIKE '$table' AND `TABLE_SCHEMA` = '$config[database]'")) {
16
+        while ($row = $result->fetch_row()) $tables[] = $row[0];
17
+        $result->close();
18
+    }
16 19
 }
17 20
 
18
-if ($config["whitelist"]) $tables = array_intersect($tables, $config["whitelist"]);
19
-if ($config["blacklist"]) $tables = array_diff($tables, $config["blacklist"]);
21
+if ($config["read_whitelist"]) $tables = array_intersect($tables, $config["read_whitelist"]);
22
+if ($config["read_blacklist"]) $tables = array_diff($tables, $config["read_blacklist"]);
20 23
 
21 24
 if (empty($tables)) {
22 25
     die(header("Content-Type:",true,404));

Loading…
Cancel
Save