reconfigure.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env php
  2. <?php
  3. declare(strict_types=1);
  4. require(__DIR__ . '/_cli.php');
  5. $params = array(
  6. 'environment:',
  7. 'base_url:',
  8. 'language:',
  9. 'title:',
  10. 'default_user:',
  11. 'allow_anonymous',
  12. 'allow_anonymous_refresh',
  13. 'auth_type:',
  14. 'api_enabled',
  15. 'allow_robots',
  16. 'disable_update',
  17. );
  18. $dBparams = array(
  19. 'db-type:',
  20. 'db-host:',
  21. 'db-user:',
  22. 'db-password:',
  23. 'db-base:',
  24. 'db-prefix::',
  25. );
  26. $options = getopt('', array_merge($params, $dBparams));
  27. if (!validateOptions($argv, array_merge($params, $dBparams))) {
  28. fail('Usage: ' . basename(__FILE__) . " --default_user admin ( --auth_type form" .
  29. " --environment production --base_url https://rss.example.net --allow_robots" .
  30. " --language en --title FreshRSS --allow_anonymous --allow_anonymous_refresh --api_enabled" .
  31. " --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123" .
  32. " --db-base freshrss --db-prefix freshrss_ --disable_update )");
  33. }
  34. fwrite(STDERR, 'Reconfiguring FreshRSS…' . "\n");
  35. foreach ($params as $param) {
  36. $param = rtrim($param, ':');
  37. if (isset($options[$param])) {
  38. FreshRSS_Context::$system_conf->$param = $options[$param] === false ? true : $options[$param];
  39. }
  40. }
  41. $db = FreshRSS_Context::$system_conf->db;
  42. foreach ($dBparams as $dBparam) {
  43. $dBparam = rtrim($dBparam, ':');
  44. if (isset($options[$dBparam])) {
  45. $param = substr($dBparam, strlen('db-'));
  46. $db[$param] = $options[$dBparam];
  47. }
  48. }
  49. FreshRSS_Context::$system_conf->db = $db;
  50. if (!FreshRSS_user_Controller::checkUsername(FreshRSS_Context::$system_conf->default_user)) {
  51. fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' .
  52. FreshRSS_Context::$system_conf->default_user);
  53. }
  54. if (isset(FreshRSS_Context::$system_conf->auth_type) &&
  55. !in_array(FreshRSS_Context::$system_conf->auth_type, ['form', 'http_auth', 'none'], true)) {
  56. fail('FreshRSS invalid authentication method (auth_type must be one of { form, http_auth, none }: '
  57. . FreshRSS_Context::$system_conf->auth_type);
  58. }
  59. FreshRSS_Context::$system_conf->save();
  60. done();