]> git.immae.eu Git - github/wallabag/wallabag.git/blame - index.php
security check
[github/wallabag/wallabag.git] / index.php
CommitLineData
1a268ba7
NL
1<?php
2/**
c95b78a8 3 * wallabag, self hostable application allowing you to not miss any content anymore
1a268ba7 4 *
c95b78a8
NL
5 * @category wallabag
6 * @author Nicolas Lœuillet <nicolas@loeuillet.org>
1a268ba7
NL
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
8038b388 11define ('POCHE', '1.7.0');
792097fb 12require 'check_setup.php';
00dbaf90 13require_once 'inc/poche/global.inc.php';
bb5a7d9e 14
752cd4a8 15# Set error reporting level
a13ff957 16if (defined('ERROR_REPORTING')) {
17 error_reporting(ERROR_REPORTING);
752cd4a8
MR
18}
19
eb5b6772
MR
20# Start session
21Session::$sessionName = 'poche';
ad53faf2 22Session::init();
eb5b6772 23
00dbaf90
NL
24# Start Poche
25$poche = new Poche();
26$notInstalledMessage = $poche -> getNotInstalledMessage();
1a268ba7 27
ed06f040 28# Parse GET & REFERER vars
a4565e88 29$referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
7f959169 30$view = Tools::checkVar('view', 'home');
63c35580
NL
31$action = Tools::checkVar('action');
32$id = Tools::checkVar('id');
f6df40db 33$_SESSION['sort'] = Tools::checkVar('sort', 'id');
63c35580 34$url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
8c72b98d 35
00dbaf90
NL
36# vars to _always_ send to templates
37$tpl_vars = array(
38 'referer' => $referer,
39 'view' => $view,
40 'poche_url' => Tools::getPocheUrl(),
dcc73856 41 'title' => _('wallabag, a read it later open source system'),
00dbaf90
NL
42 'token' => Session::getToken(),
43 'theme' => $poche->getTheme()
44);
45
46if (! empty($notInstalledMessage)) {
47 if (! Poche::$canRenderTemplates || ! Poche::$configFileAvailable) {
182faf26 48 # We cannot use Twig to display the error message
9d3b88b3
NL
49 echo '<h1>Errors</h1><ol>';
50 foreach ($notInstalledMessage as $message) {
51 echo '<li>' . $message . '</li>';
52 }
53 echo '</ol>';
54 die();
00dbaf90
NL
55 } else {
56 # Twig is installed, put the error message in the template
57 $tpl_file = Tools::getTplFile('error');
58 $tpl_vars = array_merge($tpl_vars, array('msg' => $poche->getNotInstalledMessage()));
59 echo $poche->tpl->render($tpl_file, $tpl_vars);
60 exit;
61 }
62}
63
ed06f040 64# poche actions
a1953dff 65if (isset($_GET['login'])) {
4f5b44bd 66 # hello you
c765c367 67 $poche->login($referer);
00dbaf90 68} elseif (isset($_GET['logout'])) {
4f5b44bd 69 # see you soon !
c765c367 70 $poche->logout();
00dbaf90 71} elseif (isset($_GET['config'])) {
4f5b44bd 72 # Update password
c765c367 73 $poche->updatePassword();
4d99bae8 74} elseif (isset($_GET['newuser'])) {
75 $poche->createNewUser();
76} elseif (isset($_GET['deluser'])) {
77 $poche->deleteUser();
87090d8a 78} elseif (isset($_GET['epub'])) {
79 $poche->createEpub();
00dbaf90 80} elseif (isset($_GET['import'])) {
182faf26
MR
81 $import = $poche->import();
82 $tpl_vars = array_merge($tpl_vars, $import);
d460914f 83} elseif (isset($_GET['download'])) {
6285e57c
NL
84 Tools::download_db();
85} elseif (isset($_GET['empty-cache'])) {
86 $poche->emptyCache();
00dbaf90 87} elseif (isset($_GET['export'])) {
63c35580 88 $poche->export();
00dbaf90
NL
89} elseif (isset($_GET['updatetheme'])) {
90 $poche->updateTheme();
5011388f
NL
91} elseif (isset($_GET['updatelanguage'])) {
92 $poche->updateLanguage();
31a10069
NL
93} elseif (isset($_GET['uploadfile'])) {
94 $poche->uploadFile();
72c20a52 95} elseif (isset($_GET['feed'])) {
f0133fe5 96 if (isset($_GET['action']) && $_GET['action'] == 'generate') {
72c20a52
NL
97 $poche->generateToken();
98 }
99 else {
f778e472 100 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
a13ff957 101 $poche->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']);
72c20a52 102 }
63c35580 103}
5011388f 104
ce4a1dcc
NL
105elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
106 $plain_url = new Url(base64_encode($_GET['plainurl']));
107 $poche->action('add', $plain_url);
108}
693b3f86 109
e4d2565e 110if (Session::isLogged()) {
eb1af592
NL
111 $poche->action($action, $url, $id);
112 $tpl_file = Tools::getTplFile($view);
113 $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id));
df6afaf0 114} elseif(isset($_SERVER['PHP_AUTH_USER'])) {
027b4e15
DS
115 if($poche->store->userExists($_SERVER['PHP_AUTH_USER'])) {
116 $poche->login($referer);
117 } else {
118 $poche->messages->add('e', _('login failed: user doesn\'t exist'));
119 Tools::logm('user doesn\'t exist');
120 $tpl_file = Tools::getTplFile('login');
121 $tpl_vars['http_auth'] = 1;
122 }
1810c13b
NL
123} elseif(isset($_SERVER['REMOTE_USER'])) {
124 if($poche->store->userExists($_SERVER['REMOTE_USER'])) {
125 $poche->login($referer);
126 } else {
127 $poche->messages->add('e', _('login failed: user doesn\'t exist'));
128 Tools::logm('user doesn\'t exist');
129 $tpl_file = Tools::getTplFile('login');
130 $tpl_vars['http_auth'] = 1;
131 }
00dbaf90
NL
132} else {
133 $tpl_file = Tools::getTplFile('login');
027b4e15 134 $tpl_vars['http_auth'] = 0;
ad53faf2 135 Session::logout();
8c72b98d 136}
a4565e88 137
55821e04 138# because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
6a361945
NL
139$messages = $poche->messages->display('all', FALSE);
140$tpl_vars = array_merge($tpl_vars, array('messages' => $messages));
55821e04 141
ed06f040 142# display poche
df6afaf0 143echo $poche->tpl->render($tpl_file, $tpl_vars);