X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=829d5513542789bf4c220cb457ca22f0f12bb166;hb=refs%2Ftags%2F0.2.1;hp=d56c19410d4f530bb02f069a5c1d027ed604502d;hpb=3c8d80aec5f5ba15910014bb4dcb48e948041ec9;p=github%2Fwallabag%2Fwallabag.git diff --git a/index.php b/index.php old mode 100755 new mode 100644 index d56c1941..829d5513 --- a/index.php +++ b/index.php @@ -9,158 +9,66 @@ */ include dirname(__FILE__).'/inc/config.php'; -$db = new db(DB_PATH); -$action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; -$view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : ''; -$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; -$url = (isset ($_GET['url'])) ? $_GET['url'] : ''; +myTool::initPhp(); -switch ($action) -{ - case 'add': +# XSRF protection with token +if (!empty($_POST)) { + if (!Session::isToken($_POST['token'])) { + die('Wrong token.'); + } + unset($_SESSION['tokens']); +} - if ($url == '') - continue; +$ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; - $parametres_url = prepare_url($url); +if (isset($_GET['login'])) { + // Login + if (!empty($_POST['login']) && !empty($_POST['password'])) { + if (Session::login('poche', 'poche', $_POST['login'], $_POST['password'])) { + logm('login successful'); + $msg->add('s', 'welcome in your pocket!'); + 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); - try - { - # insert query - $query = $db->getHandle()->prepare('INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'); - $query->execute(array($url, $parametres_url['title'], $parametres_url['content'])); - } - catch (Exception $e) - { - error_log('insert query error : '.$e->getMessage()); + MyTool::redirect($ref); } - - break; - case 'delete': - $sql_action = "DELETE FROM entries WHERE id=?"; - $params_action = array($id); - break; - default: - break; -} - -try -{ - # action query - if (isset($sql_action)) - { - $query = $db->getHandle()->prepare($sql_action); - $query->execute($params_action); + logm('login failed'); + die("Login failed !"); + } else { + logm('login failed'); } } -catch (Exception $e) -{ - die('action query error : '.$e->getMessage()); +elseif (isset($_GET['logout'])) { + logm('logout'); + Session::logout(); + MyTool::redirect(); } -switch ($view) -{ - case 'archive': - $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; - $params = array(-1); - break; - case 'fav' : - $sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc"; - $params = array(-1); - break; - default: - $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; - $params = array(0); - $view = 'index'; - break; -} +# 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->assign('isLogged', Session::isLogged()); +$tpl->assign('referer', $ref); +$tpl->assign('view', $view); +$tpl->assign('poche_url', myTool::getUrl()); +$tpl->assign('title', 'poche, a read it later open source system'); -# view query -try -{ - $query = $db->getHandle()->prepare($sql); - $query->execute($params); - $entries = $query->fetchAll(); +if (Session::isLogged()) { + action_to_do($action, $url, $id); + display_view($view, $id, $full_head); } -catch (Exception $e) -{ - die('view query error : '.$e->getMessage()); +else { + $tpl->draw('login'); } - -?> - - - - - - - - - - - poche, a read it later open source system - - - - - - - - -
-

logo pochepoche

-
-
- -
- -
- -

- -

-
- - - -
-
-
- -
-
- - - - - - -