示例#1
0
 /**
  * This action is called before every other action in that class. It is
  * the common boiler plate for every action. It is triggered by the
  * underlying framework.
  */
 public function firstAction()
 {
     if (!FreshRSS_Auth::hasAccess()) {
         Minz_Error::error(403);
     }
     Minz_View::prependTitle(_t('admin.stats.title') . ' · ');
 }
示例#2
0
 /**
  * Initialize the different FreshRSS / Minz components.
  *
  * PLEASE DON'T CHANGE THE ORDER OF INITIALIZATIONS UNLESS YOU KNOW WHAT
  * YOU DO!!
  *
  * Here is the list of components:
  * - Create a configuration setter and register it to system conf
  * - Init extension manager and enable system extensions (has to be done asap)
  * - Init authentication system
  * - Init user configuration (need auth system)
  * - Init FreshRSS context (need user conf)
  * - Init i18n (need context)
  * - Init sharing system (need user conf and i18n)
  * - Init generic styles and scripts (need user conf)
  * - Init notifications
  * - Enable user extensions (need all the other initializations)
  */
 public function init()
 {
     if (!isset($_SESSION)) {
         Minz_Session::init('FreshRSS');
     }
     // Register the configuration setter for the system configuration
     $configuration_setter = new FreshRSS_ConfigurationSetter();
     $system_conf = Minz_Configuration::get('system');
     $system_conf->_configurationSetter($configuration_setter);
     // Load list of extensions and enable the "system" ones.
     Minz_ExtensionManager::init();
     // Auth has to be initialized before using currentUser session parameter
     // because it's this part which create this parameter.
     $this->initAuth();
     // Then, register the user configuration and use the configuration setter
     // created above.
     $current_user = Minz_Session::param('currentUser', '_');
     Minz_Configuration::register('user', join_path(USERS_PATH, $current_user, 'config.php'), join_path(USERS_PATH, '_', 'config.default.php'), $configuration_setter);
     // Finish to initialize the other FreshRSS / Minz components.
     FreshRSS_Context::init();
     $this->initI18n();
     FreshRSS_Share::load(join_path(DATA_PATH, 'shares.php'));
     $this->loadStylesAndScripts();
     $this->loadNotifications();
     // Enable extensions for the current (logged) user.
     if (FreshRSS_Auth::hasAccess()) {
         $ext_list = FreshRSS_Context::$user_conf->extensions_enabled;
         Minz_ExtensionManager::enableByList($ext_list);
     }
 }
 /**
  * This action is called before every other action in that class. It is
  * the common boiler plate for every action. It is triggered by the
  * underlying framework.
  *
  */
 public function firstAction()
 {
     if (!FreshRSS_Auth::hasAccess()) {
         Minz_Error::error(403);
     }
     $catDAO = new FreshRSS_CategoryDAO();
     $catDAO->checkDefault();
 }
示例#4
0
 public static function truncate()
 {
     file_put_contents(join_path(DATA_PATH, 'users', Minz_Session::param('currentUser', '_'), 'log.txt'), '');
     if (FreshRSS_Auth::hasAccess('admin')) {
         file_put_contents(join_path(DATA_PATH, 'users', '_', 'log.txt'), '');
         file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_api.txt'), '');
         file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_pshb.txt'), '');
     }
 }
 /**
  * This action is called before every other action in that class. It is
  * the common boiler plate for every action. It is triggered by the
  * underlying framework.
  */
 public function firstAction()
 {
     if (!FreshRSS_Auth::hasAccess()) {
         Minz_Error::error(403);
     }
     $catDAO = new FreshRSS_CategoryDAO();
     $catDAO->checkDefault();
     $this->view->categories = $catDAO->listCategories(false);
     $this->view->default_category = $catDAO->getDefault();
 }
 /**
  * This action is called before every other action in that class. It is
  * the common boiler plate for every action. It is triggered by the
  * underlying framework.
  */
 public function firstAction()
 {
     if (!FreshRSS_Auth::hasAccess()) {
         Minz_Error::error(403);
     }
     require_once LIB_PATH . '/lib_opml.php';
     $this->catDAO = new FreshRSS_CategoryDAO();
     $this->entryDAO = FreshRSS_Factory::createEntryDao();
     $this->feedDAO = FreshRSS_Factory::createFeedDao();
 }
示例#7
0
 /**
  * This action is called before every other action in that class. It is
  * the common boiler plate for every action. It is triggered by the
  * underlying framework.
  */
 public function firstAction()
 {
     if (!FreshRSS_Auth::hasAccess()) {
         Minz_Error::error(403);
     }
     // If ajax request, we do not print layout
     $this->ajax = Minz_Request::param('ajax');
     if ($this->ajax) {
         $this->view->_useLayout(false);
         Minz_Request::_param('ajax');
     }
 }
示例#8
0
 public function firstAction()
 {
     if (!FreshRSS_Auth::hasAccess('admin')) {
         Minz_Error::error(403);
     }
     invalidateHttpCache();
     $this->view->update_to_apply = false;
     $this->view->last_update_time = 'unknown';
     $timestamp = @filemtime(join_path(DATA_PATH, 'last_update.txt'));
     if ($timestamp !== false) {
         $this->view->last_update_time = timestamptodate($timestamp);
     }
 }
示例#9
0
 /**
  * This action is called before every other action in that class. It is
  * the common boiler plate for every action. It is triggered by the
  * underlying framework.
  */
 public function firstAction()
 {
     if (!FreshRSS_Auth::hasAccess()) {
         // Token is useful in the case that anonymous refresh is forbidden
         // and CRON task cannot be used with php command so the user can
         // set a CRON task to refresh his feeds by using token inside url
         $token = FreshRSS_Context::$user_conf->token;
         $token_param = Minz_Request::param('token', '');
         $token_is_ok = $token != '' && $token == $token_param;
         $action = Minz_Request::actionName();
         $allow_anonymous_refresh = FreshRSS_Context::$system_conf->allow_anonymous_refresh;
         if ($action !== 'actualize' || !($allow_anonymous_refresh || $token_is_ok)) {
             Minz_Error::error(403);
         }
     }
 }
示例#10
0
 /**
  * This action handles the login page.
  *
  * It forwards to the correct login page (form or Persona) or main page if
  * the user is already connected.
  */
 public function loginAction()
 {
     if (FreshRSS_Auth::hasAccess()) {
         Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
     }
     $auth_type = FreshRSS_Context::$system_conf->auth_type;
     switch ($auth_type) {
         case 'form':
             Minz_Request::forward(array('c' => 'auth', 'a' => 'formLogin'));
             break;
         case 'persona':
             Minz_Request::forward(array('c' => 'auth', 'a' => 'personaLogin'));
             break;
         case 'http_auth':
         case 'none':
             // It should not happened!
             Minz_Error::error(404);
         default:
             // TODO load plugin instead
             Minz_Error::error(404);
     }
 }
示例#11
0
 /**
  * This action handles the archive configuration page.
  *
  * It displays the archive configuration page.
  * If this action is reached through a POST request, it stores all new
  * configuration values then sends a notification to the user.
  *
  * The options available on that page are:
  *   - duration to retain old article (default: 3)
  *   - number of article to retain per feed (default: 0)
  *   - refresh frequency (default: -2)
  *
  * @todo explain why the default value is -2 but this value does not
  *       exist in the drop-down list
  */
 public function archivingAction()
 {
     if (Minz_Request::isPost()) {
         FreshRSS_Context::$user_conf->old_entries = Minz_Request::param('old_entries', 3);
         FreshRSS_Context::$user_conf->keep_history_default = Minz_Request::param('keep_history_default', 0);
         FreshRSS_Context::$user_conf->ttl_default = Minz_Request::param('ttl_default', -2);
         FreshRSS_Context::$user_conf->save();
         invalidateHttpCache();
         Minz_Request::good(_t('feedback.conf.updated'), array('c' => 'configure', 'a' => 'archiving'));
     }
     Minz_View::prependTitle(_t('conf.archiving.title') . ' · ');
     $entryDAO = FreshRSS_Factory::createEntryDao();
     $this->view->nb_total = $entryDAO->count();
     $this->view->size_user = $entryDAO->size();
     if (FreshRSS_Auth::hasAccess('admin')) {
         $this->view->size_total = $entryDAO->size(true);
     }
 }
示例#12
0
 /**
  * This action displays logs of FreshRSS for the current user.
  */
 public function logsAction()
 {
     if (!FreshRSS_Auth::hasAccess()) {
         Minz_Error::error(403);
     }
     Minz_View::prependTitle(_t('index.log.title') . ' · ');
     if (Minz_Request::isPost()) {
         FreshRSS_LogDAO::truncate();
     }
     $logs = FreshRSS_LogDAO::lines();
     //TODO: ask only the necessary lines
     //gestion pagination
     $page = Minz_Request::param('page', 1);
     $this->view->logsPaginator = new Minz_Paginator($logs);
     $this->view->logsPaginator->_nbItemsPerPage(50);
     $this->view->logsPaginator->_currentPage($page);
 }
示例#13
0
 /**
  * This action delete an existing user.
  *
  * Request parameter is:
  *   - username
  *
  * @todo clean up this method. Idea: create a User->clean() method.
  */
 public function deleteAction()
 {
     $username = Minz_Request::param('username');
     $redirect_url = urldecode(Minz_Request::param('r', false, true));
     if (!$redirect_url) {
         $redirect_url = array('c' => 'user', 'a' => 'manage');
     }
     $self_deletion = Minz_Session::param('currentUser', '_') === $username;
     if (Minz_Request::isPost() && (FreshRSS_Auth::hasAccess('admin') || $self_deletion)) {
         $db = FreshRSS_Context::$system_conf->db;
         require_once APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php';
         $ok = ctype_alnum($username);
         $user_data = join_path(DATA_PATH, 'users', $username);
         if ($ok) {
             $default_user = FreshRSS_Context::$system_conf->default_user;
             $ok &= strcasecmp($username, $default_user) !== 0;
             //It is forbidden to delete the default user
         }
         if ($ok && $self_deletion) {
             // We check the password if it's a self-destruction
             $nonce = Minz_Session::param('nonce');
             $challenge = Minz_Request::param('challenge', '');
             $ok &= FreshRSS_FormAuth::checkCredentials($username, FreshRSS_Context::$user_conf->passwordHash, $nonce, $challenge);
         }
         if ($ok) {
             $ok &= is_dir($user_data);
         }
         if ($ok) {
             $userDAO = new FreshRSS_UserDAO();
             $ok &= $userDAO->deleteUser($username);
             $ok &= recursive_unlink($user_data);
             //TODO: delete Persona file
         }
         if ($ok && $self_deletion) {
             FreshRSS_Auth::removeAccess();
             $redirect_url = array('c' => 'index', 'a' => 'index');
         }
         invalidateHttpCache();
         $notif = array('type' => $ok ? 'good' : 'bad', 'content' => _t('feedback.user.deleted' . (!$ok ? '.error' : ''), $username));
         Minz_Session::_param('notification', $notif);
     }
     Minz_Request::forward($redirect_url, true);
 }
示例#14
0
 /**
  * This action handles the system configuration page.
  *
  * It displays the system configuration page.
  * If this action is reach through a POST request, it stores all new
  * configuration values then sends a notification to the user.
  *
  * The options available on the page are:
  *   - user limit (default: 1)
  *   - user category limit (default: 16384)
  *   - user feed limit (default: 16384)
  */
 public function systemAction()
 {
     if (!FreshRSS_Auth::hasAccess('admin')) {
         Minz_Error::error(403);
     }
     if (Minz_Request::isPost()) {
         $limits = FreshRSS_Context::$system_conf->limits;
         $limits['max_registrations'] = Minz_Request::param('max-registrations', 1);
         $limits['max_feeds'] = Minz_Request::param('max-feeds', 16384);
         $limits['max_categories'] = Minz_Request::param('max-categories', 16384);
         FreshRSS_Context::$system_conf->limits = $limits;
         FreshRSS_Context::$system_conf->title = Minz_Request::param('instance-name', 'FreshRSS');
         FreshRSS_Context::$system_conf->auto_update_url = Minz_Request::param('auto-update-url', false);
         FreshRSS_Context::$system_conf->save();
         invalidateHttpCache();
         Minz_Session::_param('notification', array('type' => 'good', 'content' => _t('feedback.conf.updated')));
     }
 }
示例#15
0
 public function deleteAction()
 {
     if (Minz_Request::isPost() && FreshRSS_Auth::hasAccess('admin')) {
         $db = FreshRSS_Context::$system_conf->db;
         require_once APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php';
         $username = Minz_Request::param('username');
         $ok = ctype_alnum($username);
         $user_data = join_path(DATA_PATH, 'users', $username);
         if ($ok) {
             $default_user = FreshRSS_Context::$system_conf->default_user;
             $ok &= strcasecmp($username, $default_user) !== 0;
             //It is forbidden to delete the default user
         }
         if ($ok) {
             $ok &= is_dir($user_data);
         }
         if ($ok) {
             $userDAO = new FreshRSS_UserDAO();
             $ok &= $userDAO->deleteUser($username);
             $ok &= recursive_unlink($user_data);
             //TODO: delete Persona file
         }
         invalidateHttpCache();
         $notif = array('type' => $ok ? 'good' : 'bad', 'content' => _t('feedback.user.deleted' . (!$ok ? '.error' : ''), $username));
         Minz_Session::_param('notification', $notif);
     }
     Minz_Request::forward(array('c' => 'user', 'a' => 'manage'), true);
 }
示例#16
0
 /**
  * This action handles deletion of an extension.
  *
  * Only administrator can remove an extension.
  * This action must be reached by a POST request.
  *
  * Parameter is:
  * -e: extension name (urlencoded)
  */
 public function removeAction()
 {
     if (!FreshRSS_Auth::hasAccess('admin')) {
         Minz_Error::error(403);
     }
     $url_redirect = array('c' => 'extension', 'a' => 'index');
     if (Minz_Request::isPost()) {
         $ext_name = urldecode(Minz_Request::param('e'));
         $ext = Minz_ExtensionManager::findExtension($ext_name);
         if (is_null($ext)) {
             Minz_Request::bad(_t('feedback.extensions.not_found', $ext_name), $url_redirect);
         }
         $res = recursive_unlink($ext->getPath());
         if ($res) {
             Minz_Request::good(_t('feedback.extensions.removed', $ext_name), $url_redirect);
         } else {
             Minz_Request::bad(_t('feedback.extensions.cannot_delete', $ext_name), $url_redirect);
         }
     }
     Minz_Request::forward($url_redirect, true);
 }