diff options
| author | 2016-10-25 00:37:34 +0200 | |
|---|---|---|
| committer | 2016-10-25 00:37:34 +0200 | |
| commit | 062c65d22878f2402e4add7c1758d794d46aff48 (patch) | |
| tree | 99047b1a45f706d3c21bde799c6d2a59ebd18b30 /cli/_cli.php | |
| parent | 4d6fdc589e89c2a7d4072b497d9dfd8504a1cb5c (diff) | |
| parent | 2cbf307963c72c4f5cf18732bb581a88a46d668b (diff) | |
Merge pull request #1338 from Alkarex/cli
CLI: Command-Line Interface
Diffstat (limited to 'cli/_cli.php')
| -rw-r--r-- | cli/_cli.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cli/_cli.php b/cli/_cli.php new file mode 100644 index 000000000..7d1a7c6b2 --- /dev/null +++ b/cli/_cli.php @@ -0,0 +1,49 @@ +<?php +if (php_sapi_name() !== 'cli') { + die('FreshRSS error: This PHP script may only be invoked from command line!'); +} + +require(dirname(__FILE__) . '/../constants.php'); +require(LIB_PATH . '/lib_rss.php'); + +Minz_Configuration::register('system', + DATA_PATH . '/config.php', + DATA_PATH . '/config.default.php'); +FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); +Minz_Translate::init('en'); + +FreshRSS_Context::$isCli = true; + +function fail($message) { + fwrite(STDERR, $message . "\n"); + die(1); +} + +function cliInitUser($username) { + if (!ctype_alnum($username)) { + fail('FreshRSS error: invalid username: ' . $username . "\n"); + } + + $usernames = listUsers(); + if (!in_array($username, $usernames)) { + fail('FreshRSS error: user not found: ' . $username . "\n"); + } + + FreshRSS_Context::$user_conf = get_user_configuration($username); + if (FreshRSS_Context::$user_conf == null) { + fail('FreshRSS error: invalid configuration for user: ' . $username . "\n"); + } + new Minz_ModelPdo($username); + + return $username; +} + +function accessRights() { + echo '• Remember to re-apply the appropriate access rights, such as:' , "\n", + "\t", 'sudo chown -R :www-data . && sudo chmod -R g+r . && sudo chmod -R g+w ./data/', "\n"; +} + +function done($ok = true) { + fwrite(STDERR, 'Result: ' . ($ok ? 'success' : 'fail') . "\n"); + exit($ok ? 0 : 1); +} |
