4
0

javascriptController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. declare(strict_types=1);
  3. class FreshRSS_javascript_Controller extends FreshRSS_ActionController {
  4. /**
  5. * @var FreshRSS_ViewJavascript
  6. * @phpstan-ignore property.phpDocType
  7. */
  8. protected $view;
  9. public function __construct() {
  10. parent::__construct(FreshRSS_ViewJavascript::class);
  11. }
  12. #[\Override]
  13. public function firstAction(): void {
  14. $this->view->_layout(null);
  15. }
  16. public function actualizeAction(): void {
  17. if (!FreshRSS_Auth::hasAccess() && !(
  18. FreshRSS_Context::systemConf()->allow_anonymous
  19. && FreshRSS_Context::systemConf()->allow_anonymous_refresh
  20. )) {
  21. Minz_Error::error(403);
  22. return;
  23. }
  24. header('Content-Type: application/json; charset=UTF-8');
  25. Minz_Session::_param('actualize_feeds', false);
  26. $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
  27. $databaseDAO->minorDbMaintenance();
  28. Minz_ExtensionManager::callHookVoid('freshrss_user_maintenance');
  29. $catDAO = FreshRSS_Factory::createCategoryDao();
  30. $this->view->categories = $catDAO->listCategoriesOrderUpdate(FreshRSS_Context::userConf()->dynamic_opml_ttl_default);
  31. $feedDAO = FreshRSS_Factory::createFeedDao();
  32. $this->view->feeds = $feedDAO->listFeedsOrderUpdate(FreshRSS_Context::userConf()->ttl_default);
  33. }
  34. public function nbUnreadsPerFeedAction(): void {
  35. if (!FreshRSS_Auth::hasAccess() && !FreshRSS_Context::systemConf()->allow_anonymous) {
  36. Minz_Error::error(403);
  37. return;
  38. }
  39. header('Content-Type: application/json; charset=UTF-8');
  40. $catDAO = FreshRSS_Factory::createCategoryDao();
  41. $this->view->categories = $catDAO->listCategories(prePopulateFeeds: true, details: false);
  42. $tagDAO = FreshRSS_Factory::createTagDao();
  43. $this->view->tags = $tagDAO->listTags(precounts: true);
  44. }
  45. //For Web-form login
  46. /**
  47. * @throws Exception
  48. */
  49. public function nonceAction(): void {
  50. header('Content-Type: application/json; charset=UTF-8');
  51. header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T'));
  52. header('Expires: 0');
  53. header('Cache-Control: private, no-cache, no-store, must-revalidate');
  54. header('Pragma: no-cache');
  55. $user = $_GET['user'] ?? '';
  56. if (!is_string($user) || $user === '') {
  57. Minz_Error::error(400);
  58. return;
  59. }
  60. FreshRSS_Context::initUser($user);
  61. if (FreshRSS_Context::hasUserConf()) {
  62. try {
  63. $salt = FreshRSS_Context::systemConf()->salt;
  64. $s = FreshRSS_Context::userConf()->passwordHash;
  65. if (strlen($s) >= 60) {
  66. //CRYPT_BLOWFISH Salt: "$2a$", a two digit cost parameter, "$", and 22 characters from the alphabet "./0-9A-Za-z".
  67. $this->view->salt1 = substr($s, 0, 29);
  68. $this->view->nonce = sha1($salt . uniqid('' . mt_rand(), true));
  69. Minz_Session::_param('nonce', $this->view->nonce);
  70. return; //Success
  71. }
  72. } catch (Minz_Exception $me) {
  73. Minz_Log::warning('Nonce failure: ' . $me->getMessage());
  74. }
  75. } else {
  76. Minz_Log::notice('Nonce failure due to invalid username! ' . $user);
  77. }
  78. //Failure: Return random data.
  79. $this->view->salt1 = sprintf('$2a$%02d$', FreshRSS_password_Util::BCRYPT_COST);
  80. $alphabet = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  81. for ($i = 22; $i > 0; $i--) {
  82. $this->view->salt1 .= $alphabet[random_int(0, 63)];
  83. }
  84. $this->view->nonce = sha1('' . mt_rand());
  85. Minz_Session::_param('nonce', $this->view->nonce);
  86. }
  87. }