]> git.wh0rd.org - tt-rss.git/blobdiff - classes/rpc.php
pngcrush.sh
[tt-rss.git] / classes / rpc.php
index 6ec14dd42ea19e3ac6f5ad540d178addc46bcfdb..bd4337fbe64ae8bf58729441c5ea3e026cf7b12c 100755 (executable)
@@ -8,14 +8,14 @@ class RPC extends Handler_Protected {
        }
 
        function setprofile() {
-               $_SESSION["profile"] = $_REQUEST["id"];
+               $_SESSION["profile"] = clean($_REQUEST["id"]);
 
                // default value
                if (!$_SESSION["profile"]) $_SESSION["profile"] = null;
        }
 
        function remprofiles() {
-               $ids = explode(",", trim($_REQUEST["ids"]));
+               $ids = explode(",", trim(clean($_REQUEST["ids"])));
 
                foreach ($ids as $id) {
                        if ($_SESSION["profile"] != $id) {
@@ -28,7 +28,7 @@ class RPC extends Handler_Protected {
 
        // Silent
        function addprofile() {
-               $title = trim($_REQUEST["title"]);
+               $title = trim(clean($_REQUEST["title"]));
 
                if ($title) {
                        $this->pdo->beginTransaction();
@@ -62,8 +62,8 @@ class RPC extends Handler_Protected {
        }
 
        function saveprofile() {
-               $id = $_REQUEST["id"];
-               $title = trim($_REQUEST["value"]);
+               $id = clean($_REQUEST["id"]);
+               $title = trim(clean($_REQUEST["value"]));
 
                if ($id == 0) {
                        print __("Default profile");
@@ -82,7 +82,7 @@ class RPC extends Handler_Protected {
 
        // Silent
        function remarchive() {
-               $ids = explode(",", $_REQUEST["ids"]);
+               $ids = explode(",", clean($_REQUEST["ids"]));
 
                $sth = $this->pdo->prepare("DELETE FROM ttrss_archived_feeds WHERE
                                (SELECT COUNT(*) FROM ttrss_user_entries
@@ -95,10 +95,11 @@ class RPC extends Handler_Protected {
        }
 
        function addfeed() {
-               $feed = $_REQUEST['feed'];
-               $cat = $_REQUEST['cat'];
-               $login = $_REQUEST['login'];
-               $pass = trim($_REQUEST['pass']);
+               $feed = clean($_REQUEST['feed']);
+               $cat = clean($_REQUEST['cat']);
+               $need_auth = isset($_REQUEST['need_auth']);
+               $login = $need_auth ? clean($_REQUEST['login']) : '';
+               $pass = $need_auth ? trim(clean($_REQUEST['pass'])) : '';
 
                $rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass);
 
@@ -106,7 +107,7 @@ class RPC extends Handler_Protected {
        }
 
        function togglepref() {
-               $key = $_REQUEST["key"];
+               $key = clean($_REQUEST["key"]);
                set_pref($key, !get_pref($key));
                $value = get_pref($key);
 
@@ -115,8 +116,8 @@ class RPC extends Handler_Protected {
 
        function setpref() {
                // set_pref escapes input, so no need to double escape it here
-               $key = $_REQUEST['key'];
-               $value = str_replace("\n", "<br/>", $_REQUEST['value']);
+               $key = clean($_REQUEST['key']);
+               $value = $_REQUEST['value'];
 
                set_pref($key, $value, false, $key != 'USER_STYLESHEET');
 
@@ -124,8 +125,8 @@ class RPC extends Handler_Protected {
        }
 
        function mark() {
-               $mark = $_REQUEST["mark"];
-               $id = $_REQUEST["id"];
+               $mark = clean($_REQUEST["mark"]);
+               $id = clean($_REQUEST["id"]);
 
                $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET marked = ?,
                                        last_marked = NOW()
@@ -137,7 +138,7 @@ class RPC extends Handler_Protected {
        }
 
        function delete() {
-               $ids = explode(",", $_REQUEST["ids"]);
+               $ids = explode(",", clean($_REQUEST["ids"]));
                $ids_qmarks = arr_qmarks($ids);
 
                $sth = $this->pdo->prepare("DELETE FROM ttrss_user_entries
@@ -150,7 +151,7 @@ class RPC extends Handler_Protected {
        }
 
        function unarchive() {
-               $ids = explode(",", $_REQUEST["ids"]);
+               $ids = explode(",", clean($_REQUEST["ids"]));
 
                foreach ($ids as $id) {
                        $this->pdo->beginTransaction();
@@ -203,7 +204,7 @@ class RPC extends Handler_Protected {
        }
 
        function archive() {
-               $ids = explode(",", $_REQUEST["ids"]);
+               $ids = explode(",", clean($_REQUEST["ids"]));
 
                foreach ($ids as $id) {
                        $this->archive_article($id, $_SESSION["uid"]);
@@ -257,8 +258,8 @@ class RPC extends Handler_Protected {
        }
 
        function publ() {
-               $pub = $_REQUEST["pub"];
-               $id = $_REQUEST["id"];
+               $pub = clean($_REQUEST["pub"]);
+               $id = clean($_REQUEST["id"]);
 
                $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
                        published = ?, last_published = NOW()
@@ -270,7 +271,7 @@ class RPC extends Handler_Protected {
        }
 
        function getAllCounters() {
-               $last_article_id = (int) $_REQUEST["last_article_id"];
+               $last_article_id = (int) clean($_REQUEST["last_article_id"]);
 
                $reply = array();
 
@@ -287,8 +288,8 @@ class RPC extends Handler_Protected {
 
        /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
        function catchupSelected() {
-               $ids = explode(",", $_REQUEST["ids"]);
-               $cmode = sprintf("%d", $_REQUEST["cmode"]);
+               $ids = explode(",", clean($_REQUEST["ids"]));
+               $cmode = sprintf("%d", clean($_REQUEST["cmode"]));
 
                Article::catchupArticlesById($ids, $cmode);
 
@@ -296,8 +297,8 @@ class RPC extends Handler_Protected {
        }
 
        function markSelected() {
-               $ids = explode(",", $_REQUEST["ids"]);
-               $cmode = (int)$_REQUEST["cmode"];
+               $ids = explode(",", clean($_REQUEST["ids"]));
+               $cmode = (int)clean($_REQUEST["cmode"]);
 
                $this->markArticlesById($ids, $cmode);
 
@@ -305,8 +306,8 @@ class RPC extends Handler_Protected {
        }
 
        function publishSelected() {
-               $ids = explode(",", $_REQUEST["ids"]);
-               $cmode = (int)$_REQUEST["cmode"];
+               $ids = explode(",", clean($_REQUEST["ids"]));
+               $cmode = (int)clean($_REQUEST["cmode"]);
 
                $this->publishArticlesById($ids, $cmode);
 
@@ -314,10 +315,10 @@ class RPC extends Handler_Protected {
        }
 
        function sanityCheck() {
-               $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true";
-               $_SESSION["hasSandbox"] = $_REQUEST["hasSandbox"] === "true";
-               $_SESSION["hasMp3"] = $_REQUEST["hasMp3"] === "true";
-               $_SESSION["clientTzOffset"] = $_REQUEST["clientTzOffset"];
+               $_SESSION["hasAudio"] = clean($_REQUEST["hasAudio"]) === "true";
+               $_SESSION["hasSandbox"] = clean($_REQUEST["hasSandbox"]) === "true";
+               $_SESSION["hasMp3"] = clean($_REQUEST["hasMp3"]) === "true";
+               $_SESSION["clientTzOffset"] = clean($_REQUEST["clientTzOffset"]);
 
                $reply = array();
 
@@ -332,9 +333,9 @@ class RPC extends Handler_Protected {
        }
 
        function completeLabels() {
-               $search = $_REQUEST["search"];
+               $search = clean($_REQUEST["search"]);
 
-               $sth = $this->pdo->query("SELECT DISTINCT caption FROM
+               $sth = $this->pdo->prepare("SELECT DISTINCT caption FROM
                                ttrss_labels2
                                WHERE owner_uid = ? AND
                                LOWER(caption) LIKE LOWER(?) ORDER BY caption
@@ -348,28 +349,12 @@ class RPC extends Handler_Protected {
                print "</ul>";
        }
 
-       function purge() {
-               $ids = explode(",", $_REQUEST["ids"]);
-               $days = (int) $_REQUEST["days"];
-
-               $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE
-                               id = ? AND owner_uid = ?");
-
-               foreach ($ids as $id) {
-                       $sth->execute([$id, $_SESSION['uid']]);
-
-                       if ($sth->fetch()) {
-                               purge_feed($id, $days);
-                       }
-               }
-       }
-
        function updateFeedBrowser() {
                if (defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER) return;
 
-               $search = $_REQUEST["search"];
-               $limit = $_REQUEST["limit"];
-               $mode = (int) $_REQUEST["mode"];
+               $search = clean($_REQUEST["search"]);
+               $limit = clean($_REQUEST["limit"]);
+               $mode = (int) clean($_REQUEST["mode"]);
 
                require_once "feedbrowser.php";
 
@@ -381,8 +366,8 @@ class RPC extends Handler_Protected {
        // Silent
        function massSubscribe() {
 
-               $payload = json_decode($_REQUEST["payload"], false);
-               $mode = $_REQUEST["mode"];
+               $payload = json_decode(clean($_REQUEST["payload"]), false);
+               $mode = clean($_REQUEST["mode"]);
 
                if (!$payload || !is_array($payload)) return;
 
@@ -433,11 +418,11 @@ class RPC extends Handler_Protected {
        }
 
        function catchupFeed() {
-               $feed_id = $_REQUEST['feed_id'];
-               $is_cat = $_REQUEST['is_cat'] == "true";
-               $mode = $_REQUEST['mode'];
-               $search_query = $_REQUEST['search_query'];
-               $search_lang = $_REQUEST['search_lang'];
+               $feed_id = clean($_REQUEST['feed_id']);
+               $is_cat = clean($_REQUEST['is_cat']) == "true";
+               $mode = clean($_REQUEST['mode']);
+               $search_query = clean($_REQUEST['search_query']);
+               $search_lang = clean($_REQUEST['search_lang']);
 
                Feeds::catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]);
 
@@ -445,7 +430,7 @@ class RPC extends Handler_Protected {
        }
 
        function setpanelmode() {
-               $wide = (int) $_REQUEST["wide"];
+               $wide = (int) clean($_REQUEST["wide"]);
 
                setcookie("ttrss_widescreen", $wide,
                        time() + COOKIE_LIFETIME_LONG);
@@ -582,7 +567,7 @@ class RPC extends Handler_Protected {
        }
 
        function getlinktitlebyid() {
-               $id = $_REQUEST['id'];
+               $id = clean($_REQUEST['id']);
 
                $sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries
                        WHERE ref_id = ? AND ref_id = id AND owner_uid = ?");
@@ -599,10 +584,10 @@ class RPC extends Handler_Protected {
        }
 
        function log() {
-               $msg = $_REQUEST['msg'];
-               $file = basename($_REQUEST['file']);
-               $line = (int) $_REQUEST['line'];
-               $context = $_REQUEST['context'];
+               $msg = clean($_REQUEST['msg']);
+               $file = basename(clean($_REQUEST['file']));
+               $line = (int) clean($_REQUEST['line']);
+               $context = clean($_REQUEST['context']);
 
                if ($msg) {
                        Logger::get()->log_error(E_USER_WARNING,