javascriptController.php 2.3 KB

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