diff --git a/css/style.css b/css/style.css index 959a411..d77fb9e 100644 --- a/css/style.css +++ b/css/style.css @@ -65,6 +65,16 @@ footer { cursor: pointer; } +input[type=submit].delete { + background : url('../img/delete.png') no-repeat center center; + width : 16px; + height :16px; + border : none; + color : transparent; + cursor: pointer; + font-size : 0; +} + #main #content { margin-top: 20px; } @@ -77,13 +87,15 @@ footer { min-height: 8em; -webkit-border-radius: 2px; border-radius: 2px; - -webkit-box-shadow: 0px 0px 2px -1px #000; - box-shadow: 0px 0px 2px -1px #000; + -webkit-box-shadow: 0px 0px 6px -1px #000; + box-shadow: 0px 0px 6px -1px #000; width: 30%; margin: 10px; float: left; } - +#main .entrie h2 { + width: 95%; +} #main .entrie h2 a { text-decoration: none; } @@ -92,20 +104,38 @@ footer { color: #F5BE00; } -#main .entrie .tools { - position:absolute; - bottom: 0; - width: 100%; +.tools { + position: absolute; + top: 20px; + right: 20px; + width: 30px; text-align: right; - margin-left: -20px; +} + +.tools ul { + padding: 0; margin: 0; + list-style-type: none; +} + +.tools ul li { + line-height: 20px; +} + +.tools a.tool { + cursor: pointer; } #article .tools { + position: relative; display: inline; + top: 0px; + right: 0px; + width: 100%; + text-align: left; } -#article .tools a.tool { - cursor: pointer; +#article.tools ul li{ + display: inline; } #main .entrie .tools a.tool span, #article .tools a.tool span { diff --git a/inc/config.php b/inc/config.php index 29a2250..84b8699 100644 --- a/inc/config.php +++ b/inc/config.php @@ -22,4 +22,12 @@ raintpl::$cache_dir = './cache/'; raintpl::$base_url = get_poche_url(); raintpl::configure('path_replace', false); raintpl::configure('debug', false); -$tpl = new raintpl(); \ No newline at end of file +$tpl = new raintpl(); + +session_start(); + +if (!isset($_SESSION['token_poche'])) { + $token = md5(uniqid(rand(), TRUE)); + $_SESSION['token_poche'] = $token; + $_SESSION['token_time_poche'] = time(); +} \ No newline at end of file diff --git a/inc/functions.php b/inc/functions.php index 45828bf..30e0039 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -125,7 +125,7 @@ function prepare_url($url) /** * Appel d'une action (mark as fav, archive, delete) */ -function action_to_do($action, $id) +function action_to_do($action, $id, $url, $token) { global $db; @@ -140,8 +140,11 @@ function action_to_do($action, $id) $params_action = array($url, $parametres_url['title'], $parametres_url['content']); break; case 'delete': - $sql_action = "DELETE FROM entries WHERE id=?"; - $params_action = array($id); + if (verif_token($token)) { + $sql_action = "DELETE FROM entries WHERE id=?"; + $params_action = array($id); + } + else die('CSRF problem'); break; default: break; @@ -224,4 +227,25 @@ function get_article($id) } return $entry; +} + +/** + * Vérifie si le jeton passé en $_POST correspond à celui en session + */ +function verif_token($token) +{ + if(isset($_SESSION['token_poche']) && isset($_SESSION['token_time_poche']) && isset($token)) + { + if($_SESSION['token_poche'] == $token) + { + $old_timestamp = time() - (15*60); + if($_SESSION['token_time_poche'] >= $old_timestamp) + { + return TRUE; + } + else return FALSE; + } + else return FALSE; + } + else return FALSE; } \ No newline at end of file diff --git a/index.php b/index.php index 1cb32f5..d477d69 100755 --- a/index.php +++ b/index.php @@ -10,12 +10,16 @@ include dirname(__FILE__).'/inc/config.php'; -$action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; -$view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : 'index'; -$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; +$action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; +$view = (isset ($_GET['view'])) ? htmlentities($_GET['view']) : 'index'; +$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; +$token = (isset ($_POST['token'])) ? $_POST['token'] : ''; + +if ($action != '') { + action_to_do($action, $id, $url, $token); +} -action_to_do($action, $id); $entries = display_view($view); $tpl->assign('title', 'poche, a read it later open source system'); @@ -23,4 +27,5 @@ $tpl->assign('view', $view); $tpl->assign('poche_url', get_poche_url()); $tpl->assign('entries', $entries); $tpl->assign('load_all_js', 1); +$tpl->assign('token', $_SESSION['token_poche']); $tpl->draw('home'); \ No newline at end of file diff --git a/js/poche.js b/js/poche.js index 64df553..0dcc0a3 100644 --- a/js/poche.js +++ b/js/poche.js @@ -1,16 +1,16 @@ -function toggle_favorite(element, id) { +function toggle_favorite(element, id, token) { $(element).toggleClass('fav-off'); $.ajax ({ url: "process.php?action=toggle_fav", - data:{id:id} + data:{id:id, token:token} }); } -function toggle_archive(element, id, view_article) { +function toggle_archive(element, id, token, view_article) { $(element).toggleClass('archive-off'); $.ajax ({ url: "process.php?action=toggle_archive", - data:{id:id} + data:{id:id, token:token} }); var obj = $('#entry-'+id); diff --git a/process.php b/process.php index 0bd20e5..5a056ca 100644 --- a/process.php +++ b/process.php @@ -11,27 +11,30 @@ include dirname(__FILE__).'/inc/config.php'; $db = new db(DB_PATH); -$action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; -$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; +$action = (isset ($_GET['action'])) ? htmlentities($_GET['action']) : ''; +$id = (isset ($_GET['id'])) ? htmlentities($_GET['id']) : ''; +$token = (isset ($_GET['token'])) ? $_GET['token'] : ''; -switch ($action) -{ - case 'toggle_fav' : - $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?"; - $params_action = array($id); - break; - case 'toggle_archive' : - $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?"; - $params_action = array($id); - break; - default: - break; -} +if (verif_token($token)) { + switch ($action) + { + case 'toggle_fav' : + $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?"; + $params_action = array($id); + break; + case 'toggle_archive' : + $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?"; + $params_action = array($id); + break; + default: + break; + } -# action query -if (isset($sql_action)) -{ - $query = $db->getHandle()->prepare($sql_action); - $query->execute($params_action); + # action query + if (isset($sql_action)) + { + $query = $db->getHandle()->prepare($sql_action); + $query->execute($params_action); + } } -?> \ No newline at end of file +else die('CSRF problem'); \ No newline at end of file diff --git a/tpl/home.html b/tpl/home.html index 70a35a7..0de8007 100644 --- a/tpl/home.html +++ b/tpl/home.html @@ -8,7 +8,7 @@