javascriptController.php 1.9 KB

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