]> git.wh0rd.org - tt-rss.git/blame - backend.php
set csrf and access_level in single user mode session
[tt-rss.git] / backend.php
CommitLineData
1d3a17c7 1<?php
8484ce22 2 set_include_path(get_include_path() . PATH_SEPARATOR .
f03a795d 3 dirname(__FILE__) . "/include");
107d0cf3 4
ce885e21
AD
5 /* remove ill effects of magic quotes */
6
5fa17372 7 if (get_magic_quotes_gpc()) {
c0793f64 8 function stripslashes_deep($value) {
009646d2 9 $value = is_array($value) ?
c0793f64
AD
10 array_map('stripslashes_deep', $value) : stripslashes($value);
11 return $value;
12 }
13
14 $_POST = array_map('stripslashes_deep', $_POST);
15 $_GET = array_map('stripslashes_deep', $_GET);
16 $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
17 $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
ce885e21
AD
18 }
19
f9da2388 20 $op = $_REQUEST["op"];
5f0a3741
AD
21 @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
22
8484ce22
AD
23 if (!$method)
24 $method = 'index';
25 else
26 $method = strtolower($method);
27
5f0a3741
AD
28 /* Public calls compatibility shim */
29
30 $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
31 "fbexport", "logout", "pubsub");
32
33 if (array_search($op, $public_calls) !== false) {
34 header("Location: public.php?" . $_SERVER['QUERY_STRING']);
35 return;
36 }
f9da2388 37
66b042fc 38 @$csrf_token = $_REQUEST['csrf_token'];
8484ce22 39
fb074239 40 require_once "functions.php";
5f0a3741 41 require_once "sessions.php";
657770a0
AD
42 require_once "sanity_check.php";
43 require_once "config.php";
af106b0e
AD
44 require_once "db.php";
45 require_once "db-prefs.php";
657770a0 46
dc56b3b7 47 no_cache_incantation();
8d039718 48
7b26a148 49 startup_gettext();
dc56b3b7 50
7f0acba7
AD
51 $script_started = getmicrotime();
52
009646d2 53 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
7f0acba7 54
5f0a3741 55 if (!init_connection($link)) return;
3f363052
AD
56
57 header("Content-Type: text/plain; charset=utf-8");
262bd8ea 58
bd202c3f
AD
59 if (ENABLE_GZIP_OUTPUT) {
60 ob_start("ob_gzhandler");
61 }
62
9c883208
AD
63 if (SINGLE_USER_MODE) {
64 authenticate_user($link, "admin", null);
65 }
66
5f0a3741 67 // TODO remove and handle within Handlers
009646d2 68
5f0a3741 69 if (!($_SESSION["uid"] && validate_session($link))) {
1395083e 70 if ($op == 'pref-feeds' && $method == 'add') {
d0f73380
AD
71 header("Content-Type: text/html");
72 login_sequence($link);
73 render_login_form($link);
74 } else {
75 header("Content-Type: text/plain");
76 print json_encode(array("error" => array("code" => 6)));
77 }
009646d2 78 return;
262bd8ea 79 }
1c7f75ed 80
ad815c71 81 $purge_intervals = array(
d1db26aa
AD
82 0 => __("Use default"),
83 -1 => __("Never purge"),
84 5 => __("1 week old"),
85 14 => __("2 weeks old"),
86 31 => __("1 month old"),
87 60 => __("2 months old"),
88 90 => __("3 months old"));
ad815c71
AD
89
90 $update_intervals = array(
ecace165 91 0 => __("Default interval"),
d1db26aa 92 -1 => __("Disable updates"),
1e7cbe16 93 15 => __("Each 15 minutes"),
d1db26aa 94 30 => __("Each 30 minutes"),
505f2f0e
AD
95 60 => __("Hourly"),
96 240 => __("Each 4 hours"),
97 720 => __("Each 12 hours"),
98 1440 => __("Daily"),
99 10080 => __("Weekly"));
100
101 $update_intervals_nodefault = array(
102 -1 => __("Disable updates"),
103 15 => __("Each 15 minutes"),
104 30 => __("Each 30 minutes"),
d1db26aa
AD
105 60 => __("Hourly"),
106 240 => __("Each 4 hours"),
107 720 => __("Each 12 hours"),
108 1440 => __("Daily"),
109 10080 => __("Weekly"));
ad815c71 110
16211ddb 111 $update_methods = array(
ecace165 112 0 => __("Default"),
0dd9c0cf 113 1 => __("Magpie"),
009646d2 114 2 => __("SimplePie"),
b3009bcd 115 3 => __("Twitter OAuth"));
16211ddb 116
78a5c296 117 if (DEFAULT_UPDATE_METHOD == "1") {
16211ddb
AD
118 $update_methods[0] .= ' (SimplePie)';
119 } else {
120 $update_methods[0] .= ' (Magpie)';
121 }
122
3c5783b7 123 $access_level_names = array(
009646d2 124 0 => __("User"),
a88d37e5 125 5 => __("Power User"),
d1db26aa 126 10 => __("Administrator"));
3c5783b7 127
ebb948c2
AD
128 $error = sanity_check($link);
129
2376ad49 130 if ($error['code'] != 0 && $op != "logout") {
ebb948c2
AD
131 print json_encode(array("error" => $error));
132 return;
133 }
023fe037 134
5f0a3741
AD
135 function __autoload($class) {
136 $file = "classes/".strtolower(basename($class)).".php";
137 if (file_exists($file)) {
138 require $file;
139 }
140 }
141
afcfe6ca
AD
142 $op = str_replace("-", "_", $op);
143
d5112468
AD
144 if (class_exists($op)) {
145 $handler = new $op($link, $_REQUEST);
45004d43 146
d5112468 147 if ($handler) {
8484ce22
AD
148 if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
149 if ($handler->before($method)) {
150 if ($method && method_exists($handler, $method)) {
151 $handler->$method();
152 }
153 $handler->after();
154 return;
d5112468 155 }
8484ce22
AD
156 } else {
157 header("Content-Type: text/plain");
158 print json_encode(array("error" => array("code" => 6)));
3f363052 159 return;
d5112468
AD
160 }
161 }
162 }
163
5f0a3741
AD
164 header("Content-Type: text/plain");
165 print json_encode(array("error" => array("code" => 7)));
ba7e88e5 166
45004d43 167 // We close the connection to database.
4b3dff6e 168 db_close($link);
1cd17194 169?>