reconfigure.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/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. fwrite(STDERR, 'Reconfiguring FreshRSS…' . "\n");
  27. $config = Minz_Configuration::get('system');
  28. foreach ($params as $param) {
  29. $param = rtrim($param, ':');
  30. if (isset($options[$param])) {
  31. $config->$param = $options[$param] === false ? true : $options[$param];
  32. }
  33. }
  34. $db = $config->db;
  35. foreach ($dBparams as $dBparam) {
  36. $dBparam = rtrim($dBparam, ':');
  37. if (isset($options[$dBparam])) {
  38. $param = substr($dBparam, strlen('db-'));
  39. $db[$param] = $options[$dBparam];
  40. }
  41. }
  42. $config->db = $db;
  43. if (!FreshRSS_user_Controller::checkUsername($config->default_user)) {
  44. fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . $config->default_user);
  45. }
  46. if (isset($config->auth_type) && !in_array($config->auth_type, array('form', 'http_auth', 'none'))) {
  47. fail('FreshRSS invalid authentication method (auth_type must be one of { form, http_auth, none }: '
  48. . $config->auth_type);
  49. }
  50. $config->save();
  51. done();