_cli.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. if (php_sapi_name() !== 'cli') {
  3. die('FreshRSS error: This PHP script may only be invoked from command line!');
  4. }
  5. require(dirname(__FILE__) . '/../constants.php');
  6. require(LIB_PATH . '/lib_rss.php');
  7. Minz_Configuration::register('system',
  8. DATA_PATH . '/config.php',
  9. DATA_PATH . '/config.default.php');
  10. FreshRSS_Context::$system_conf = Minz_Configuration::get('system');
  11. Minz_Translate::init('en');
  12. FreshRSS_Context::$isCli = true;
  13. function fail($message) {
  14. fwrite(STDERR, $message . "\n");
  15. die(1);
  16. }
  17. function cliInitUser($username) {
  18. $aValid = array('-', '_', '.');
  19. if (!ctype_alnum(str_replace($aValid, '', $username))) {
  20. fail('FreshRSS error: invalid username: ' . $username . "\n");
  21. }
  22. $usernames = listUsers();
  23. if (!in_array($username, $usernames)) {
  24. fail('FreshRSS error: user not found: ' . $username . "\n");
  25. }
  26. FreshRSS_Context::$user_conf = get_user_configuration($username);
  27. if (FreshRSS_Context::$user_conf == null) {
  28. fail('FreshRSS error: invalid configuration for user: ' . $username . "\n");
  29. }
  30. new Minz_ModelPdo($username);
  31. return $username;
  32. }
  33. function accessRights() {
  34. echo '• Remember to re-apply the appropriate access rights, such as:' , "\n",
  35. "\t", 'sudo chown -R :www-data . && sudo chmod -R g+r . && sudo chmod -R g+w ./data/', "\n";
  36. }
  37. function done($ok = true) {
  38. fwrite(STDERR, 'Result: ' . ($ok ? 'success' : 'fail') . "\n");
  39. exit($ok ? 0 : 1);
  40. }