javascriptController.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. header('Content-Type: application/json; charset=UTF-8');
  18. Minz_Session::_param('actualize_feeds', false);
  19. $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
  20. $databaseDAO->minorDbMaintenance();
  21. Minz_ExtensionManager::callHookVoid('freshrss_user_maintenance');
  22. $catDAO = FreshRSS_Factory::createCategoryDao();
  23. $this->view->categories = $catDAO->listCategoriesOrderUpdate(FreshRSS_Context::userConf()->dynamic_opml_ttl_default);
  24. $feedDAO = FreshRSS_Factory::createFeedDao();
  25. $this->view->feeds = $feedDAO->listFeedsOrderUpdate(FreshRSS_Context::userConf()->ttl_default);
  26. }
  27. public function nbUnreadsPerFeedAction(): void {
  28. header('Content-Type: application/json; charset=UTF-8');
  29. $catDAO = FreshRSS_Factory::createCategoryDao();
  30. $this->view->categories = $catDAO->listCategories(true, false) ?: [];
  31. $tagDAO = FreshRSS_Factory::createTagDao();
  32. $this->view->tags = $tagDAO->listTags(true) ?: [];
  33. }
  34. //For Web-form login
  35. /**
  36. * @throws Exception
  37. */
  38. public function nonceAction(): void {
  39. header('Content-Type: application/json; charset=UTF-8');
  40. header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T'));
  41. header('Expires: 0');
  42. header('Cache-Control: private, no-cache, no-store, must-revalidate');
  43. header('Pragma: no-cache');
  44. $user = $_GET['user'] ?? '';
  45. if (!is_string($user) || $user === '') {
  46. Minz_Error::error(400);
  47. return;
  48. }
  49. FreshRSS_Context::initUser($user);
  50. if (FreshRSS_Context::hasUserConf()) {
  51. try {
  52. $salt = FreshRSS_Context::systemConf()->salt;
  53. $s = FreshRSS_Context::userConf()->passwordHash;
  54. if (strlen($s) >= 60) {
  55. //CRYPT_BLOWFISH Salt: "$2a$", a two digit cost parameter, "$", and 22 characters from the alphabet "./0-9A-Za-z".
  56. $this->view->salt1 = substr($s, 0, 29);
  57. $this->view->nonce = sha1($salt . uniqid('' . mt_rand(), true));
  58. Minz_Session::_param('nonce', $this->view->nonce);
  59. return; //Success
  60. }
  61. } catch (Minz_Exception $me) {
  62. Minz_Log::warning('Nonce failure: ' . $me->getMessage());
  63. }
  64. } else {
  65. Minz_Log::notice('Nonce failure due to invalid username! ' . $user);
  66. }
  67. //Failure: Return random data.
  68. $this->view->salt1 = sprintf('$2a$%02d$', FreshRSS_password_Util::BCRYPT_COST);
  69. $alphabet = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  70. for ($i = 22; $i > 0; $i--) {
  71. $this->view->salt1 .= $alphabet[random_int(0, 63)];
  72. }
  73. $this->view->nonce = sha1('' . mt_rand());
  74. Minz_Session::_param('nonce', $this->view->nonce);
  75. }
  76. }