javascriptController.php 2.5 KB

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