4
0

javascriptController.php 2.7 KB

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