4
0

javascriptController.php 2.5 KB

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