X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=78daaaf98fdaca7dd8994b93aaab7c7af273751e;hb=45161a64026cec35fcf07659508143a6f55ddf57;hp=e32996fab206758cd519961be13bdc429f62b29f;hpb=c44908ddd02eb5fd63c292bb7e0fa99a52f73222;p=github%2Fwallabag%2Fwallabag.git diff --git a/index.php b/index.php old mode 100755 new mode 100644 index e32996fa..78daaaf9 --- a/index.php +++ b/index.php @@ -3,100 +3,92 @@ * poche, a read it later open source system * * @category poche - * @author Nicolas Lœuillet + * @author Nicolas Lœuillet * @copyright 2013 * @license http://www.wtfpl.net/ see COPYING file */ -/** - * TODO - * gestion des erreurs sqlite (duplicate tout ça) - * gérer si url vide - * traiter les variables passées en get - * récupérer le titre de la page pochée (cf readityourself.php) - * actions archive, fav et delete à traiter - * bookmarklet - * améliorer présentation des liens - * améliorer présentation d'un article - * aligner verticalement les icones d'action - * afficher liens mis en favoris et archivés - * tri des liens - */ +include dirname(__FILE__).'/inc/config.php'; -try -{ - $db_handle = new PDO('sqlite:poche.sqlite'); - $db_handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -} -catch (Exception $e) -{ - die('error : '.$e->getMessage()); +pocheTool::initPhp(); + +# XSRF protection with token +if (!empty($_POST)) { + if (!Session::isToken($_POST['token'])) { + die(_('Wrong token.')); + } + unset($_SESSION['tokens']); } -$action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; +$referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; + +if (isset($_GET['login'])) { + // Login + if (!empty($_POST['login']) && !empty($_POST['password'])) { + if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], encode_string($_POST['password'] . $_POST['login']))) { + pocheTool::logm('login successful'); + if (!empty($_POST['longlastingsession'])) { + $_SESSION['longlastingsession'] = 31536000; + $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; + session_set_cookie_params($_SESSION['longlastingsession']); + } else { + session_set_cookie_params(0); // when browser closes + } + session_regenerate_id(true); -switch ($action) { - case 'add': - $url = (isset ($_GET['url'])) ? htmlspecialchars($_GET['url']) : ''; - $title = $url; - $query = $db_handle->prepare('INSERT INTO entries ( url, title ) VALUES (?, ?)'); - $query->execute(array($url, $title)); - break; - case 'archive': - break; - case 'fav' : - break; - case 'delete': - break; - default: - break; + pocheTool::redirect($referer); + } + pocheTool::logm('login failed'); + die(_("Login failed !")); + } else { + pocheTool::logm('login failed'); + } +} +elseif (isset($_GET['logout'])) { + pocheTool::logm('logout'); + Session::logout(); + pocheTool::redirect(); } +elseif (isset($_GET['config'])) { + if (isset($_POST['password']) && isset($_POST['password_repeat'])) { + if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { + pocheTool::logm('password updated'); + if (!MODE_DEMO) { + $store->updatePassword(encode_string($_POST['password'] . $_SESSION['login'])); + #your password has been updated + } + else { + #in demo mode, you can\'t update password + } + } + #else + #your password can\'t be empty and you have to repeat it in the second field + } +} + +# Traitement des paramètres et déclenchement des actions +$view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index'; +$full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes'; +$action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; +$_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id'; +$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; +$url = (isset ($_GET['url'])) ? $_GET['url'] : ''; + +$tpl_vars = array( + 'isLogged' => Session::isLogged(), + 'referer' => $referer, + 'view' => $view, + 'poche_url' => pocheTool::getUrl(), + 'demo' => MODE_DEMO, + 'title' => _('poche, a read it later open source system'), +); -function url(){ - $protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http"; - return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; +if (Session::isLogged()) { + action_to_do($action, $url, $id); + display_view($view, $id, $full_head); } -?> - - - - - - - - - - - poche : queue - - - - -
-

poche, a read it later open source system

-
-
- - prepare("SELECT * FROM entries WHERE read=?"); - $query->execute(array('FALSE')); - $entries = $query->fetchAll(); - ?> - -
- - - \ No newline at end of file +else { + $template = $twig->loadTemplate('login.twig'); +} + +echo $template->render($tpl_vars); \ No newline at end of file