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