]> git.wh0rd.org - tt-rss.git/blob - backend.php
login system fixes
[tt-rss.git] / backend.php
1 <?php
2 set_include_path(get_include_path() . PATH_SEPARATOR .
3 dirname(__FILE__) . "/include");
4
5 /* remove ill effects of magic quotes */
6
7 if (get_magic_quotes_gpc()) {
8 function stripslashes_deep($value) {
9 $value = is_array($value) ?
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);
18 }
19
20 $op = $_REQUEST["op"];
21 @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
22
23 if (!$method)
24 $method = 'index';
25 else
26 $method = strtolower($method);
27
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 }
37
38 @$csrf_token = $_REQUEST['csrf_token'];
39
40 require_once "functions.php";
41 require_once "sessions.php";
42 require_once "config.php";
43 require_once "db.php";
44 require_once "db-prefs.php";
45
46 no_cache_incantation();
47
48 startup_gettext();
49
50 $script_started = getmicrotime();
51
52 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
53
54 if (!init_connection($link)) return;
55
56 header("Content-Type: text/plain; charset=utf-8");
57
58 if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) {
59 ob_start("ob_gzhandler");
60 }
61
62 if (SINGLE_USER_MODE) {
63 authenticate_user($link, "admin", null);
64 }
65
66 // TODO remove and handle within Handlers
67
68 /* if (!($_SESSION["uid"] && validate_session($link))) {
69 if ($op == 'pref-feeds' && $method == 'add') {
70 header("Content-Type: text/html");
71 login_sequence($link);
72 render_login_form($link);
73 } else {
74 header("Content-Type: text/plain");
75 print json_encode(array("error" => array("code" => 6)));
76 }
77 return;
78 } */
79
80 $purge_intervals = array(
81 0 => __("Use default"),
82 -1 => __("Never purge"),
83 5 => __("1 week old"),
84 14 => __("2 weeks old"),
85 31 => __("1 month old"),
86 60 => __("2 months old"),
87 90 => __("3 months old"));
88
89 $update_intervals = array(
90 0 => __("Default interval"),
91 -1 => __("Disable updates"),
92 15 => __("Each 15 minutes"),
93 30 => __("Each 30 minutes"),
94 60 => __("Hourly"),
95 240 => __("Each 4 hours"),
96 720 => __("Each 12 hours"),
97 1440 => __("Daily"),
98 10080 => __("Weekly"));
99
100 $update_intervals_nodefault = array(
101 -1 => __("Disable updates"),
102 15 => __("Each 15 minutes"),
103 30 => __("Each 30 minutes"),
104 60 => __("Hourly"),
105 240 => __("Each 4 hours"),
106 720 => __("Each 12 hours"),
107 1440 => __("Daily"),
108 10080 => __("Weekly"));
109
110 $update_methods = array(
111 0 => __("Default"),
112 1 => __("Magpie"),
113 2 => __("SimplePie"));
114
115 if (DEFAULT_UPDATE_METHOD == "1") {
116 $update_methods[0] .= ' (SimplePie)';
117 } else {
118 $update_methods[0] .= ' (Magpie)';
119 }
120
121 $access_level_names = array(
122 0 => __("User"),
123 5 => __("Power User"),
124 10 => __("Administrator"));
125
126 #$error = sanity_check($link);
127
128 #if ($error['code'] != 0 && $op != "logout") {
129 # print json_encode(array("error" => $error));
130 # return;
131 #}
132
133 $op = str_replace("-", "_", $op);
134
135 if (class_exists($op)) {
136 $handler = new $op($link, $_REQUEST);
137
138 if ($handler && is_subclass_of($handler, 'Handler')) {
139 if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
140 if ($handler->before($method)) {
141 if ($method && method_exists($handler, $method)) {
142 $handler->$method();
143 }
144 $handler->after();
145 return;
146 } else {
147 header("Content-Type: text/plain");
148 print json_encode(array("error" => array("code" => 6)));
149 return;
150 }
151 } else {
152 header("Content-Type: text/plain");
153 print json_encode(array("error" => array("code" => 6)));
154 return;
155 }
156 }
157 }
158
159 header("Content-Type: text/plain");
160 print json_encode(array("error" => array("code" => 7)));
161
162 // We close the connection to database.
163 db_close($link);
164 ?>