]> git.wh0rd.org - tt-rss.git/blob - api/index.php
api: lower maximum lifetime of api sessions
[tt-rss.git] / api / index.php
1 <?php
2 error_reporting(E_ERROR | E_PARSE);
3
4 require_once "../config.php";
5
6 set_include_path(dirname(__FILE__) . PATH_SEPARATOR .
7 dirname(dirname(__FILE__)) . PATH_SEPARATOR .
8 dirname(dirname(__FILE__)) . "/include" . PATH_SEPARATOR .
9 get_include_path());
10
11 chdir("..");
12
13 define('TTRSS_SESSION_NAME', 'ttrss_api_sid');
14
15 require_once "db.php";
16 require_once "db-prefs.php";
17 require_once "functions.php";
18 require_once "sessions.php";
19
20 ini_set("session.gc_maxlifetime", 86400);
21
22 define('AUTH_DISABLE_OTP', true);
23
24 if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
25 function_exists("ob_gzhandler")) {
26
27 ob_start("ob_gzhandler");
28 } else {
29 ob_start();
30 }
31
32 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
33
34 $input = file_get_contents("php://input");
35
36 if (defined('_API_DEBUG_HTTP_ENABLED') && _API_DEBUG_HTTP_ENABLED) {
37 // Override $_REQUEST with JSON-encoded data if available
38 // fallback on HTTP parameters
39 if ($input) {
40 $input = json_decode($input, true);
41 if ($input) $_REQUEST = $input;
42 }
43 } else {
44 // Accept JSON only
45 $input = json_decode($input, true);
46 $_REQUEST = $input;
47 }
48
49 if ($_REQUEST["sid"]) {
50 session_id($_REQUEST["sid"]);
51 @session_start();
52 }
53
54 if (!init_connection($link)) return;
55
56 $method = strtolower($_REQUEST["op"]);
57
58 $handler = new API($link, $_REQUEST);
59
60 if ($handler->before($method)) {
61 if ($method && method_exists($handler, $method)) {
62 $handler->$method();
63 } else if (method_exists($handler, 'index')) {
64 $handler->index($method);
65 }
66 $handler->after();
67 }
68
69 db_close($link);
70
71 header("Api-Content-Length: " . ob_get_length());
72
73 ob_end_flush();
74 ?>