4
0

javascriptController.php 2.7 KB

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