reconfigure.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. switch ($param) {
  39. case 'allow_anonymous_refresh':
  40. FreshRSS_Context::systemConf()->allow_anonymous_refresh = true;
  41. break;
  42. case 'allow_anonymous':
  43. FreshRSS_Context::systemConf()->allow_anonymous = true;
  44. break;
  45. case 'allow_robots':
  46. FreshRSS_Context::systemConf()->allow_robots = true;
  47. break;
  48. case 'api_enabled':
  49. FreshRSS_Context::systemConf()->api_enabled = true;
  50. break;
  51. case 'auth_type':
  52. if (in_array($options[$param], ['form', 'http_auth', 'none'], true)) {
  53. FreshRSS_Context::systemConf()->auth_type = $options[$param];
  54. } else {
  55. fail('FreshRSS invalid authentication method! auth_type must be one of { form, http_auth, none }');
  56. }
  57. break;
  58. case 'base_url':
  59. FreshRSS_Context::systemConf()->base_url = $options[$param];
  60. break;
  61. case 'default_user':
  62. if (FreshRSS_user_Controller::checkUsername($options[$param])) {
  63. FreshRSS_Context::systemConf()->default_user = $options[$param];
  64. } else {
  65. fail('FreshRSS invalid default username! default_user must be ASCII alphanumeric');
  66. }
  67. break;
  68. case 'disable_update':
  69. FreshRSS_Context::systemConf()->disable_update = true;
  70. break;
  71. case 'environment':
  72. if (in_array($options[$param], ['development', 'production', 'silent'], true)) {
  73. FreshRSS_Context::systemConf()->environment = $options[$param];
  74. } else {
  75. fail('FreshRSS invalid environment! environment must be one of { development, production, silent }');
  76. }
  77. break;
  78. case 'language':
  79. FreshRSS_Context::systemConf()->language = $options[$param];
  80. break;
  81. case 'title':
  82. FreshRSS_Context::systemConf()->title = $options[$param];
  83. break;
  84. }
  85. }
  86. }
  87. $db = FreshRSS_Context::systemConf()->db;
  88. foreach ($dBparams as $dBparam) {
  89. $dBparam = rtrim($dBparam, ':');
  90. if (isset($options[$dBparam])) {
  91. $param = substr($dBparam, strlen('db-'));
  92. $db[$param] = $options[$dBparam];
  93. }
  94. }
  95. /** @var array{'type':string,'host':string,'user':string,'password':string,'base':string,'prefix':string,
  96. * 'connection_uri_params':string,'pdo_options':array<int,int|string|bool>} $db */
  97. FreshRSS_Context::systemConf()->db = $db;
  98. FreshRSS_Context::systemConf()->save();
  99. done();