javascriptController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class FreshRSS_javascript_Controller extends Minz_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. $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".
  33. $this->view->nonce = sha1($salt . uniqid(mt_rand(), true));
  34. Minz_Session::_param('nonce', $this->view->nonce);
  35. return; //Success
  36. }
  37. } catch (Minz_Exception $me) {
  38. Minz_Log::warning('Nonce failure: ' . $me->getMessage());
  39. }
  40. } else {
  41. Minz_Log::notice('Nonce failure due to invalid username!');
  42. }
  43. //Failure: Return random data.
  44. $this->view->salt1 = sprintf('$2a$%02d$', FreshRSS_password_Util::BCRYPT_COST);
  45. $alphabet = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  46. for ($i = 22; $i > 0; $i--) {
  47. $this->view->salt1 .= $alphabet[mt_rand(0, 63)];
  48. }
  49. $this->view->nonce = sha1(mt_rand());
  50. }
  51. }