]> git.wh0rd.org - tt-rss.git/blobdiff - backend.php
fix daemon sleep interval
[tt-rss.git] / backend.php
index 62cd6229d6206ff5f06d07ec03eabe7fa89a8a89..3b1208f316997965ba901716ca519eabec7c50e3 100644 (file)
@@ -1,5 +1,6 @@
 <?php
-       set_include_path(get_include_path() . PATH_SEPARATOR . "include");
+       set_include_path(get_include_path() . PATH_SEPARATOR .
+               dirname(__FILE__) . "/include");
 
        /* remove ill effects of magic quotes */
 
        $op = $_REQUEST["op"];
        @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
 
+       if (!$method)
+               $method = 'index';
+       else
+               $method = strtolower($method);
+
        /* Public calls compatibility shim */
 
        $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
@@ -29,6 +35,8 @@
                return;
        }
 
+       $csrf_token = $_REQUEST['csrf_token'];
+
        require_once "functions.php";
        require_once "sessions.php";
        require_once "sanity_check.php";
                $handler = new $op($link, $_REQUEST);
 
                if ($handler) {
-                       if ($handler->before()) {
-                               if ($method && method_exists($handler, $method)) {
-                                       $handler->$method();
-                               } else if (method_exists($handler, 'index')) {
-                                       $handler->index();
+                       if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
+                               if ($handler->before($method)) {
+                                       if ($method && method_exists($handler, $method)) {
+                                               $handler->$method();
+                                       }
+                                       $handler->after();
+                                       return;
                                }
-                               $handler->after();
+                       } else {
+                               header("Content-Type: text/plain");
+                               print json_encode(array("error" => array("code" => 6)));
                                return;
                        }
                }