4
0

javascriptController.php 2.1 KB

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