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.

index.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. require_once "utils.php";
  3. require_once "status.php";
  4. require_once "user.php";
  5. require_once "sql.php";
  6. function check_api_key_()
  7. {
  8. $headers = apache_request_headers();
  9. if (!isset($headers["Api-Key"]))
  10. return false;
  11. $q = database_exec("SELECT id FROM api_keys WHERE `key` = :key",
  12. array(":key" => $headers["Api-Key"]));
  13. if ($q->fetch() !== false)
  14. return true;
  15. return false;
  16. }
  17. function check_api_key()
  18. {
  19. if (!check_api_key_())
  20. error(401, "Bad API Key");
  21. }
  22. function main()
  23. {
  24. $m_get = ($_SERVER['REQUEST_METHOD'] == "GET");
  25. $m_post = ($_SERVER['REQUEST_METHOD'] == "POST");
  26. $matches = array();
  27. $path = rtrim($_GET['_url'], "/");
  28. if ($path === "")
  29. $path = "/";
  30. if (preg_match($path, "^/status/([0-9]+)/confirm$", $matches) && $m_post)
  31. status_confirm($matches[1]);
  32. else if ($path === "/status" && $m_post)
  33. status_create();
  34. else if ($path === "/status/feed" && $m_get)
  35. status_feed();
  36. else if ($path === "/user" && $m_post)
  37. user_create();
  38. else if ($path === "/user/login" && $m_post)
  39. user_login();
  40. else
  41. error(501, "Not Implemented");
  42. }
  43. check_api_key();
  44. main();
  45. ?>