4
0

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. */
  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::userConf()->dynamic_opml_ttl_default);
  19. $feedDAO = FreshRSS_Factory::createFeedDao();
  20. $this->view->feeds = $feedDAO->listFeedsOrderUpdate(FreshRSS_Context::userConf()->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. FreshRSS_Context::initUser($user);
  41. if (!FreshRSS_Context::hasUserConf()) {
  42. try {
  43. $salt = FreshRSS_Context::systemConf()->salt;
  44. $s = FreshRSS_Context::userConf()->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. }