Esempio n. 1
0
 /**
  * Permet de lancer une erreur
  * @param $code le type de l'erreur, par défaut 404 (page not found)
  * @param $logs logs d'erreurs découpés de la forme
  *      > $logs['error']
  *      > $logs['warning']
  *      > $logs['notice']
  * @param $redirect indique s'il faut forcer la redirection (les logs ne seront pas transmis)
  */
 public static function error($code = 404, $logs = array(), $redirect = false)
 {
     $logs = self::processLogs($logs);
     $error_filename = APP_PATH . '/Controllers/errorController.php';
     if (file_exists($error_filename)) {
         $params = array('code' => $code, 'logs' => $logs);
         Minz_Response::setHeader($code);
         if ($redirect) {
             Minz_Request::forward(array('c' => 'error'), true);
         } else {
             Minz_Request::forward(array('c' => 'error', 'params' => $params), false);
         }
     } else {
         $text = '<h1>An error occured</h1>' . "\n";
         if (!empty($logs)) {
             $text .= '<ul>' . "\n";
             foreach ($logs as $log) {
                 $text .= '<li>' . $log . '</li>' . "\n";
             }
             $text .= '</ul>' . "\n";
         }
         Minz_Response::setHeader($code);
         Minz_Response::setBody($text);
         Minz_Response::send();
         exit;
     }
 }
Esempio n. 2
0
 /**
  * Constructeur
  * Initialise le dispatcher, met à jour la Request
  */
 public function __construct()
 {
     try {
         Minz_Configuration::register('system', DATA_PATH . '/config.php', DATA_PATH . '/config.default.php');
         $this->setReporting();
         Minz_Request::init();
         $url = $this->buildUrl();
         $url['params'] = array_merge($url['params'], Minz_Request::fetchPOST());
         Minz_Request::forward($url);
     } catch (Minz_Exception $e) {
         Minz_Log::error($e->getMessage());
         $this->killApp($e->getMessage());
     }
     $this->dispatcher = Minz_Dispatcher::getInstance();
 }
Esempio n. 3
0
 /**
  * Initialise le Router en déterminant le couple Controller / Action
  * Mets à jour la Request
  * @exception RouteNotFoundException si l'uri n'est pas présente dans
  *          > la table de routage
  */
 public function init()
 {
     $url = array();
     if (Minz_Configuration::useUrlRewriting()) {
         try {
             $url = $this->buildWithRewriting();
         } catch (Minz_RouteNotFoundException $e) {
             throw $e;
         }
     } else {
         $url = $this->buildWithoutRewriting();
     }
     $url['params'] = array_merge($url['params'], Minz_Request::fetchPOST());
     Minz_Request::forward($url);
 }
Esempio n. 4
0
 /**
  * Permet de lancer une erreur
  * @param $code le type de l'erreur, par défaut 404 (page not found)
  * @param $logs logs d'erreurs découpés de la forme
  *      > $logs['error']
  *      > $logs['warning']
  *      > $logs['notice']
  * @param $redirect indique s'il faut forcer la redirection (les logs ne seront pas transmis)
  */
 public static function error($code = 404, $logs = array(), $redirect = true)
 {
     $logs = self::processLogs($logs);
     $error_filename = APP_PATH . '/Controllers/errorController.php';
     if (file_exists($error_filename)) {
         Minz_Session::_param('error_code', $code);
         Minz_Session::_param('error_logs', $logs);
         Minz_Request::forward(array('c' => 'error'), $redirect);
     } else {
         echo '<h1>An error occured</h1>' . "\n";
         if (!empty($logs)) {
             echo '<ul>' . "\n";
             foreach ($logs as $log) {
                 echo '<li>' . $log . '</li>' . "\n";
             }
             echo '</ul>' . "\n";
         }
         exit;
     }
 }
Esempio n. 5
0
 /**
  * This action displays the global view of FreshRSS.
  */
 public function globalAction()
 {
     $allow_anonymous = FreshRSS_Context::$system_conf->allow_anonymous;
     if (!FreshRSS_Auth::hasAccess() && !$allow_anonymous) {
         Minz_Request::forward(array('c' => 'auth', 'a' => 'login'));
         return;
     }
     Minz_View::appendScript(Minz_Url::display('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js')));
     try {
         $this->updateContext();
     } catch (FreshRSS_Context_Exception $e) {
         Minz_Error::error(404);
     }
     $this->view->categories = FreshRSS_Context::$categories;
     $this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title();
     $title = _t('index.feed.title_global');
     if (FreshRSS_Context::$get_unread > 0) {
         $title = '(' . FreshRSS_Context::$get_unread . ') ' . $title;
     }
     Minz_View::prependTitle($title . ' · ');
 }
Esempio n. 6
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);
     }
 }
Esempio n. 7
0
 /**
  * This action deletes a feed.
  *
  * This page must be reached by a POST request.
  * If there are related queries, they are deleted too.
  *
  * Parameters are:
  *   - id (default: false)
  *   - r (default: false)
  * r permits to redirect to a given page at the end of this action.
  *
  * @todo handle "r" redirection in Minz_Request::forward()?
  */
 public function deleteAction()
 {
     $redirect_url = Minz_Request::param('r', false, true);
     if (!$redirect_url) {
         $redirect_url = array('c' => 'subscription', 'a' => 'index');
     }
     if (!Minz_Request::isPost()) {
         Minz_Request::forward($redirect_url, true);
     }
     $id = Minz_Request::param('id');
     $feedDAO = FreshRSS_Factory::createFeedDao();
     if ($feedDAO->deleteFeed($id)) {
         // TODO: Delete old favicon
         // Remove related queries
         FreshRSS_Context::$user_conf->queries = remove_query_by_get('f_' . $id, FreshRSS_Context::$user_conf->queries);
         FreshRSS_Context::$user_conf->save();
         Minz_Request::good(_t('feedback.sub.feed.deleted'), $redirect_url);
     } else {
         Minz_Request::bad(_t('feedback.sub.feed.error'), $redirect_url);
     }
 }
Esempio n. 8
0
 public function applyAction()
 {
     if (!file_exists(UPDATE_FILENAME) || !is_writable(FRESHRSS_PATH)) {
         Minz_Request::forward(array('c' => 'update'), true);
     }
     require UPDATE_FILENAME;
     if (Minz_Request::param('post_conf', false)) {
         $res = do_post_update();
         Minz_ExtensionManager::callHook('post_update');
         if ($res === true) {
             @unlink(UPDATE_FILENAME);
             @file_put_contents(join_path(DATA_PATH, 'last_update.txt'), '');
             Minz_Request::good(_t('feedback.update.finished'));
         } else {
             Minz_Request::bad(_t('feedback.update.error', $res), array('c' => 'update', 'a' => 'index'));
         }
     }
     if (Minz_Request::isPost()) {
         save_info_update();
     }
     if (!need_info_update()) {
         $res = apply_update();
         if ($res === true) {
             Minz_Request::forward(array('c' => 'update', 'a' => 'apply', 'params' => array('post_conf' => true)), true);
         } else {
             Minz_Request::bad(_t('feedback.update.error', $res), array('c' => 'update', 'a' => 'index'));
         }
     }
 }
 public function archivingAction()
 {
     if (Minz_Request::isPost()) {
         $old = Minz_Request::param('old_entries', 3);
         $keepHistoryDefault = Minz_Request::param('keep_history_default', 0);
         $this->view->conf->_old_entries($old);
         $this->view->conf->_keep_history_default($keepHistoryDefault);
         $this->view->conf->save();
         invalidateHttpCache();
         $notif = array('type' => 'good', 'content' => Minz_Translate::t('configuration_updated'));
         Minz_Session::_param('notification', $notif);
         Minz_Request::forward(array('c' => 'configure', 'a' => 'archiving'), true);
     }
     Minz_View::prependTitle(Minz_Translate::t('archiving_configuration') . ' · ');
     $entryDAO = new FreshRSS_EntryDAO();
     $this->view->nb_total = $entryDAO->count();
     $this->view->size_user = $entryDAO->size();
     if (Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
         $this->view->size_total = $entryDAO->size(true);
     }
 }
Esempio n. 10
0
 public function deleteAction()
 {
     if (Minz_Request::isPost()) {
         $type = Minz_Request::param('type', 'feed');
         $id = Minz_Request::param('id');
         $feedDAO = new FreshRSS_FeedDAO();
         if ($type == 'category') {
             if ($feedDAO->deleteFeedByCategory($id)) {
                 $notif = array('type' => 'good', 'content' => Minz_Translate::t('category_emptied'));
                 //TODO: Delete old favicons
             } else {
                 $notif = array('type' => 'bad', 'content' => Minz_Translate::t('error_occured'));
             }
         } else {
             if ($feedDAO->deleteFeed($id)) {
                 $notif = array('type' => 'good', 'content' => Minz_Translate::t('feed_deleted'));
                 //TODO: Delete old favicon
             } else {
                 $notif = array('type' => 'bad', 'content' => Minz_Translate::t('error_occured'));
             }
         }
         Minz_Session::_param('notification', $notif);
         if ($type == 'category') {
             Minz_Request::forward(array('c' => 'configure', 'a' => 'categorize'), true);
         } else {
             Minz_Request::forward(array('c' => 'configure', 'a' => 'feed'), true);
         }
     }
 }
Esempio n. 11
0
 /**
  * This action deletes all the feeds relative to a given category.
  * Feed-related queries are deleted.
  *
  * Request parameter is:
  *   - id (of a category)
  */
 public function emptyAction()
 {
     $feedDAO = FreshRSS_Factory::createFeedDao();
     $url_redirect = array('c' => 'subscription', 'a' => 'index');
     if (Minz_Request::isPost()) {
         invalidateHttpCache();
         $id = Minz_Request::param('id');
         if (!$id) {
             Minz_Request::bad(_t('feedback.sub.category.no_id'), $url_redirect);
         }
         // List feeds to remove then related user queries.
         $feeds = $feedDAO->listByCategory($id);
         if ($feedDAO->deleteFeedByCategory($id)) {
             // TODO: Delete old favicons
             // Remove related queries
             foreach ($feeds as $feed) {
                 FreshRSS_Context::$user_conf->queries = remove_query_by_get('f_' . $feed->id(), FreshRSS_Context::$user_conf->queries);
             }
             FreshRSS_Context::$user_conf->save();
             Minz_Request::good(_t('feedback.sub.category.emptied'), $url_redirect);
         } else {
             Minz_Request::bad(_t('feedback.sub.category.error'), $url_redirect);
         }
     }
     Minz_Request::forward($url_redirect, true);
 }
 /**
  * This action handles export action.
  *
  * This action must be reached by a POST request.
  *
  * Parameters are:
  *   - export_opml (default: false)
  *   - export_starred (default: false)
  *   - export_feeds (default: array()) a list of feed ids
  */
 public function exportAction()
 {
     if (!Minz_Request::isPost()) {
         Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true);
     }
     $this->view->_useLayout(false);
     $export_opml = Minz_Request::param('export_opml', false);
     $export_starred = Minz_Request::param('export_starred', false);
     $export_feeds = Minz_Request::param('export_feeds', array());
     $export_files = array();
     if ($export_opml) {
         $export_files['feeds.opml'] = $this->generateOpml();
     }
     if ($export_starred) {
         $export_files['starred.json'] = $this->generateEntries('starred');
     }
     foreach ($export_feeds as $feed_id) {
         $feed = $this->feedDAO->searchById($feed_id);
         if ($feed) {
             $filename = 'feed_' . $feed->category() . '_' . $feed->id() . '.json';
             $export_files[$filename] = $this->generateEntries('feed', $feed);
         }
     }
     $nb_files = count($export_files);
     if ($nb_files > 1) {
         // If there are more than 1 file to export, we need a zip archive.
         try {
             $this->exportZip($export_files);
         } catch (Exception $e) {
             # Oops, there is no Zip extension!
             Minz_Request::bad(_t('feedback.import_export.export_no_zip_extension'), array('c' => 'importExport', 'a' => 'index'));
         }
     } elseif ($nb_files === 1) {
         // Only one file? Guess its type and export it.
         $filename = key($export_files);
         $type = $this->guessFileType($filename);
         $this->exportFile('freshrss_' . $filename, $export_files[$filename], $type);
     } else {
         // Nothing to do...
         Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true);
     }
 }
Esempio n. 13
0
 public function purgeAction()
 {
     @set_time_limit(300);
     $nb_month_old = max($this->view->conf->old_entries, 1);
     $date_min = time() - 3600 * 24 * 30 * $nb_month_old;
     $feedDAO = new FreshRSS_FeedDAO();
     $feeds = $feedDAO->listFeedsOrderUpdate();
     $nbTotal = 0;
     invalidateHttpCache();
     foreach ($feeds as $feed) {
         $feedHistory = $feed->keepHistory();
         if ($feedHistory == -2) {
             //default
             $feedHistory = $this->view->conf->keep_history_default;
         }
         if ($feedHistory >= 0) {
             $nb = $feedDAO->cleanOldEntries($feed->id(), $date_min, $feedHistory);
             if ($nb > 0) {
                 $nbTotal += $nb;
                 Minz_Log::record($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG);
                 $feedDAO->updateLastUpdate($feed->id());
             }
         }
     }
     invalidateHttpCache();
     $notif = array('type' => 'good', 'content' => Minz_Translate::t('purge_completed', $nbTotal));
     Minz_Session::_param('notification', $notif);
     Minz_Request::forward(array('c' => 'configure', 'a' => 'archiving'), true);
 }
Esempio n. 14
0
 public function formLogoutAction()
 {
     $this->view->_useLayout(false);
     invalidateHttpCache();
     Minz_Session::_param('currentUser');
     Minz_Session::_param('mail');
     Minz_Session::_param('passwordHash');
     Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
 }
Esempio n. 15
0
 /**
  * This action optimizes database to reduce its size.
  *
  * This action shouldbe reached by a POST request.
  *
  * @todo move this action in configure controller.
  * @todo call this action through web-cron when available
  */
 public function optimizeAction()
 {
     $url_redirect = array('c' => 'configure', 'a' => 'archiving');
     if (!Minz_Request::isPost()) {
         Minz_Request::forward($url_redirect, true);
     }
     @set_time_limit(300);
     $entryDAO = FreshRSS_Factory::createEntryDao();
     $entryDAO->optimizeTable();
     $feedDAO = FreshRSS_Factory::createFeedDao();
     $feedDAO->updateCachedValues();
     invalidateHttpCache();
     Minz_Request::good(_t('feedback.admin.optimization_complete'), $url_redirect);
 }
Esempio n. 16
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);
 }
Esempio n. 17
0
 public static function bad($msg, $url = array())
 {
     Minz_Session::_param('notification', array('type' => 'bad', 'content' => $msg));
     Minz_Request::forward($url, true);
 }
Esempio n. 18
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);
 }
Esempio n. 19
0
 public function deleteAction()
 {
     if (Minz_Request::isPost() && Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
         require_once APP_PATH . '/sql.php';
         $username = Minz_Request::param('username');
         $ok = ctype_alnum($username);
         if ($ok) {
             $ok &= strcasecmp($username, Minz_Configuration::defaultUser()) !== 0;
             //It is forbidden to delete the default user
         }
         if ($ok) {
             $configPath = DATA_PATH . '/' . $username . '_user.php';
             $ok &= file_exists($configPath);
         }
         if ($ok) {
             $userDAO = new FreshRSS_UserDAO();
             $ok &= $userDAO->deleteUser($username);
             $ok &= unlink($configPath);
             //TODO: delete Persona file
         }
         invalidateHttpCache();
         $notif = array('type' => $ok ? 'good' : 'bad', 'content' => Minz_Translate::t($ok ? 'user_deleted' : 'error_occurred', $username));
         Minz_Session::_param('notification', $notif);
     }
     Minz_Request::forward(array('c' => 'configure', 'a' => 'users'), true);
 }
Esempio n. 20
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);
 }