javascriptController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. class FreshRSS_javascript_Controller extends FreshRSS_ActionController {
  3. public function firstAction(): void {
  4. $this->view->_layout(false);
  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. public function nonceAction(): void {
  23. header('Content-Type: application/json; charset=UTF-8');
  24. header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T'));
  25. header('Expires: 0');
  26. header('Cache-Control: private, no-cache, no-store, must-revalidate');
  27. header('Pragma: no-cache');
  28. $user = isset($_GET['user']) ? $_GET['user'] : '';
  29. if (FreshRSS_Context::initUser($user)) {
  30. try {
  31. $salt = FreshRSS_Context::$system_conf->salt;
  32. $s = FreshRSS_Context::$user_conf->passwordHash;
  33. if (strlen($s) >= 60) {
  34. //CRYPT_BLOWFISH Salt: "$2a$", a two digit cost parameter, "$", and 22 characters from the alphabet "./0-9A-Za-z".
  35. $this->view->salt1 = substr($s, 0, 29);
  36. $this->view->nonce = sha1($salt . uniqid('' . mt_rand(), true));
  37. Minz_Session::_param('nonce', $this->view->nonce);
  38. return; //Success
  39. }
  40. } catch (Minz_Exception $me) {
  41. Minz_Log::warning('Nonce failure: ' . $me->getMessage());
  42. }
  43. } else {
  44. Minz_Log::notice('Nonce failure due to invalid username!');
  45. }
  46. //Failure: Return random data.
  47. $this->view->salt1 = sprintf('$2a$%02d$', FreshRSS_password_Util::BCRYPT_COST);
  48. $alphabet = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  49. for ($i = 22; $i > 0; $i--) {
  50. $this->view->salt1 .= $alphabet[mt_rand(0, 63)];
  51. }
  52. $this->view->nonce = sha1('' . mt_rand());
  53. }
  54. }