summaryrefslogtreecommitdiff
path: root/cli/_cli.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2019-03-31 16:38:46 +0200
committerGravatar GitHub <noreply@github.com> 2019-03-31 16:38:46 +0200
commitd413f67dd28738f4a6d8cf036e00714737f757b8 (patch)
tree1509f631dc8814bcf85d907a292ddd6437a2efcd /cli/_cli.php
parent8dcdde6251ae4dfc690b1a014488df125c5e5cdc (diff)
parent2a935516d850d63a215f9650b96ede102311f7ca (diff)
Merge pull request #2298 from FreshRSS/dev1.14.0
FreshRSS 1.14.0
Diffstat (limited to 'cli/_cli.php')
-rw-r--r--cli/_cli.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/cli/_cli.php b/cli/_cli.php
index e8fb6ae42..dec244bc3 100644
--- a/cli/_cli.php
+++ b/cli/_cli.php
@@ -3,6 +3,9 @@ if (php_sapi_name() !== 'cli') {
die('FreshRSS error: This PHP script may only be invoked from command line!');
}
+const REGEX_INPUT_OPTIONS = '/^--/';
+const REGEX_PARAM_OPTIONS = '/:*$/';
+
require(__DIR__ . '/../constants.php');
require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader
require(LIB_PATH . '/lib_install.php');
@@ -64,3 +67,25 @@ function performRequirementCheck($databaseType) {
fail($message);
}
}
+
+function getLongOptions($options, $regex) {
+ $longOptions = array_filter($options, function($a) use ($regex) {
+ return preg_match($regex, $a);
+ });
+ return array_map(function($a) use ($regex) {
+ return preg_replace($regex, '', $a);
+ }, $longOptions);
+}
+
+function validateOptions($input, $params) {
+ $sanitizeInput = getLongOptions($input, REGEX_INPUT_OPTIONS);
+ $sanitizeParams = getLongOptions($params, REGEX_PARAM_OPTIONS);
+ $unknownOptions = array_diff($sanitizeInput, $sanitizeParams);
+
+ if (0 === count($unknownOptions)) {
+ return true;
+ }
+
+ fwrite(STDERR, sprintf("FreshRSS error: unknown options: %s\n", implode (', ', $unknownOptions)));
+ return false;
+}