reconfigure.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/php
  2. <?php
  3. require('_cli.php');
  4. $params = array(
  5. 'environment:',
  6. 'base_url:',
  7. 'title:',
  8. 'default_user:',
  9. 'allow_anonymous',
  10. 'allow_anonymous_refresh',
  11. 'auth_type:',
  12. 'api_enabled',
  13. 'allow_robots',
  14. 'disable_update',
  15. );
  16. $dBparams = array(
  17. 'db-type:',
  18. 'db-host:',
  19. 'db-user:',
  20. 'db-password:',
  21. 'db-base:',
  22. 'db-prefix:',
  23. );
  24. $options = getopt('', array_merge($params, $dBparams));
  25. fwrite(STDERR, 'Reconfiguring FreshRSS…' . "\n");
  26. $config = Minz_Configuration::get('system');
  27. foreach ($params as $param) {
  28. $param = rtrim($param, ':');
  29. if (isset($options[$param])) {
  30. $config->$param = $options[$param] === false ? true : $options[$param];
  31. }
  32. }
  33. $db = $config->db;
  34. foreach ($dBparams as $dBparam) {
  35. $dBparam = rtrim($dBparam, ':');
  36. if (isset($options[$dBparam])) {
  37. $param = substr($dBparam, strlen('db-'));
  38. $db[$param] = $options[$dBparam];
  39. }
  40. }
  41. $config->db = $db;
  42. if (!FreshRSS_user_Controller::checkUsername($config->default_user)) {
  43. fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . $config->default_user);
  44. }
  45. if (isset($config->auth_type) && !in_array($config->auth_type, array('form', 'http_auth', 'none'))) {
  46. fail('FreshRSS invalid authentication method (auth_type must be one of { form, http_auth, none }: ' . $config->auth_type);
  47. }
  48. $config->save();
  49. done();