api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. include "config.php";
  3. $key = preg_replace('/[^a-zA-Z0-9\-_]/','',isset($_GET["key"])?$_GET["key"]:false);
  4. $table = preg_replace('/[^a-zA-Z0-9\-_]/','',isset($_GET["table"])?$_GET["table"]:false);
  5. $callback = preg_replace('/[^a-zA-Z0-9\-_]/','',isset($_GET["callback"])?$_GET["callback"]:false);
  6. $mysqli = new mysqli($config["hostname"], $config["username"], $config["password"], $config["database"]);
  7. if ($mysqli->connect_errno) die('Connect failed: '.$mysqli->connect_error);
  8. $tables = array();
  9. if ($result = $mysqli->query("SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME` = '$table' AND `TABLE_SCHEMA` = '$config[database]'")) {
  10. while ($row = $result->fetch_row()) $tables[] = $row[0];
  11. $result->close();
  12. }
  13. $keys = array();
  14. if ($result = $mysqli->query("SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `COLUMN_KEY` = 'PRI' AND `TABLE_NAME` = '$table' AND `TABLE_SCHEMA` = '$config[database]'")) {
  15. while ($row = $result->fetch_row()) $keys[] = $row[0];
  16. $result->close();
  17. }
  18. if ($config["read_whitelist"]) $tables = array_intersect($tables, $config["read_whitelist"]);
  19. if ($config["read_blacklist"]) $tables = array_diff($tables, $config["read_blacklist"]);
  20. if (empty($tables) || empty($keys)) {
  21. die(header("Content-Type:",true,404));
  22. } if ($callback) {
  23. header("Content-Type: application/javascript");
  24. echo $callback.'(';
  25. } else {
  26. header("Content-Type: application/json");
  27. }
  28. if ($result = $mysqli->query("SELECT * FROM `$tables[0]` WHERE `$keys[0]` = '$key'")) {
  29. $value = $result->fetch_assoc();
  30. if ($value) echo json_encode($value);
  31. else die(header("Content-Type:",true,404));
  32. $result->close();
  33. }
  34. if ($callback) {
  35. echo ');';
  36. }