reconfigure.php 2.0 KB

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