javascriptController.php 2.4 KB

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