1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- require_once "utils.php";
- require_once "status.php";
- require_once "user.php";
- require_once "sql.php";
-
- function check_api_key_()
- {
- $headers = apache_request_headers();
- if (!isset($headers["Api-Key"]))
- return false;
- $q = database_exec("SELECT id FROM api_keys WHERE `key` = :key",
- array(":key" => $headers["Api-Key"]));
- if ($q->fetch() !== false)
- return true;
- return false;
- }
-
- function check_api_key()
- {
- if (!check_api_key_())
- error(401, "Bad API Key");
- }
-
- function main()
- {
- $m_get = ($_SERVER['REQUEST_METHOD'] == "GET");
- $m_post = ($_SERVER['REQUEST_METHOD'] == "POST");
- $matches = array();
-
- $path = rtrim($_GET['_url'], "/");
- if ($path === "")
- $path = "/";
- if (preg_match($path, "^/status/([0-9]+)/confirm$", $matches) && $m_post)
- status_confirm($matches[1]);
- else if ($path === "/status" && $m_post)
- status_create();
- else if ($path === "/status/feed" && $m_get)
- status_feed();
- else if ($path === "/user" && $m_post)
- user_create();
- else if ($path === "/user/login" && $m_post)
- user_login();
- else
- error(501, "Not Implemented");
- }
-
- check_api_key();
- main();
- ?>
|