diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-02-03 20:58:18 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2021-02-08 01:23:56 +0100 |
commit | a19c24edc1057bd411821f9e3e7d1d309d38b1bb (patch) | |
tree | ee572568811b8ed56630156ab88b0a2278785e65 /index.php | |
parent | 630ebca2b6359e942e5b6c057cca2b6069c1093a (diff) | |
download | Shaarli-gitolite_local/ldap.tar.gz Shaarli-gitolite_local/ldap.tar.zst Shaarli-gitolite_local/ldap.zip |
Add ldap connectiongitolite_local/ldap
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 63 |
1 files changed, 47 insertions, 16 deletions
@@ -121,7 +121,32 @@ if (isset($_COOKIE['shaarli']) && !SessionManager::checkId($_COOKIE['shaarli'])) | |||
121 | $_COOKIE['shaarli'] = session_id(); | 121 | $_COOKIE['shaarli'] = session_id(); |
122 | } | 122 | } |
123 | 123 | ||
124 | $conf = new ConfigManager(); | 124 | $folderBase = getenv("BASE"); |
125 | |||
126 | if (getenv("USERSPACE")) { | ||
127 | if (isset($_GET["do"]) && $_GET["do"] == "login") { | ||
128 | header("Location: $folderBase/?do=login"); | ||
129 | exit; | ||
130 | } | ||
131 | $userspace = preg_replace("/[^-_A-Za-z0-9]/", '', getenv("USERSPACE")); | ||
132 | } else if (isset($_SESSION["username"]) && $_SESSION["username"]) { | ||
133 | header("Location: " . $folderBase . "/" . $_SESSION["username"] . "?"); | ||
134 | exit; | ||
135 | } else if (!isset($_GET["do"]) || $_GET["do"] != "login") { | ||
136 | header("Location: $folderBase/?do=login"); | ||
137 | exit; | ||
138 | } | ||
139 | |||
140 | if (!isset($userspace) && isset($_POST["login"])) { | ||
141 | $userspace = preg_replace("/[^-_A-Za-z0-9]/", '', $_POST["login"]); | ||
142 | error_log("debugImmae: setting userspace from POST: " . $userspace); | ||
143 | } | ||
144 | |||
145 | if (isset($userspace)) { | ||
146 | $conf = new ConfigManager(null, $userspace); | ||
147 | } else { | ||
148 | $conf = new ConfigManager(); | ||
149 | } | ||
125 | $sessionManager = new SessionManager($_SESSION, $conf); | 150 | $sessionManager = new SessionManager($_SESSION, $conf); |
126 | $loginManager = new LoginManager($GLOBALS, $conf, $sessionManager); | 151 | $loginManager = new LoginManager($GLOBALS, $conf, $sessionManager); |
127 | $loginManager->generateStaySignedInToken($_SERVER['REMOTE_ADDR']); | 152 | $loginManager->generateStaySignedInToken($_SERVER['REMOTE_ADDR']); |
@@ -175,7 +200,7 @@ if (! is_file($conf->getConfigFileExt())) { | |||
175 | } | 200 | } |
176 | 201 | ||
177 | // Display the installation form if no existing config is found | 202 | // Display the installation form if no existing config is found |
178 | install($conf, $sessionManager, $loginManager); | 203 | install($conf, $sessionManager, $loginManager, $userspace); |
179 | } | 204 | } |
180 | 205 | ||
181 | $loginManager->checkLoginState($_COOKIE, $clientIpId); | 206 | $loginManager->checkLoginState($_COOKIE, $clientIpId); |
@@ -205,6 +230,7 @@ if (isset($_POST['login'])) { | |||
205 | && $loginManager->checkCredentials($_SERVER['REMOTE_ADDR'], $clientIpId, $_POST['login'], $_POST['password']) | 230 | && $loginManager->checkCredentials($_SERVER['REMOTE_ADDR'], $clientIpId, $_POST['login'], $_POST['password']) |
206 | ) { | 231 | ) { |
207 | $loginManager->handleSuccessfulLogin($_SERVER); | 232 | $loginManager->handleSuccessfulLogin($_SERVER); |
233 | $userspace = $_POST['login']; | ||
208 | 234 | ||
209 | $cookiedir = ''; | 235 | $cookiedir = ''; |
210 | if (dirname($_SERVER['SCRIPT_NAME']) != '/') { | 236 | if (dirname($_SERVER['SCRIPT_NAME']) != '/') { |
@@ -241,25 +267,25 @@ if (isset($_POST['login'])) { | |||
241 | $uri .= '&'.$param.'='.urlencode($_GET[$param]); | 267 | $uri .= '&'.$param.'='.urlencode($_GET[$param]); |
242 | } | 268 | } |
243 | } | 269 | } |
244 | header('Location: '. $uri); | 270 | header('Location: '. $userspace . $uri); |
245 | exit; | 271 | exit; |
246 | } | 272 | } |
247 | 273 | ||
248 | if (isset($_GET['edit_link'])) { | 274 | if (isset($_GET['edit_link'])) { |
249 | header('Location: ?edit_link='. escape($_GET['edit_link'])); | 275 | header('Location: ' . $userspace . '?edit_link='. escape($_GET['edit_link'])); |
250 | exit; | 276 | exit; |
251 | } | 277 | } |
252 | 278 | ||
253 | if (isset($_POST['returnurl'])) { | 279 | if (isset($_POST['returnurl'])) { |
254 | // Prevent loops over login screen. | 280 | // Prevent loops over login screen. |
255 | if (strpos($_POST['returnurl'], 'do=login') === false) { | 281 | if (strpos($_POST['returnurl'], 'do=login') === false) { |
256 | header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST'])); | 282 | header('Location: ' . generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST'])); |
257 | exit; | 283 | exit; |
258 | } | 284 | } |
259 | } | 285 | } |
260 | header('Location: ?'); exit; | 286 | header('Location: '. $userspace . '?'); exit; |
261 | } else { | 287 | } else { |
262 | $loginManager->handleFailedLogin($_SERVER); | 288 | $errorReason = $loginManager->handleFailedLogin($_SERVER); |
263 | $redir = '&username='. urlencode($_POST['login']); | 289 | $redir = '&username='. urlencode($_POST['login']); |
264 | if (isset($_GET['post'])) { | 290 | if (isset($_GET['post'])) { |
265 | $redir .= '&post=' . urlencode($_GET['post']); | 291 | $redir .= '&post=' . urlencode($_GET['post']); |
@@ -270,7 +296,7 @@ if (isset($_POST['login'])) { | |||
270 | } | 296 | } |
271 | } | 297 | } |
272 | // Redirect to login screen. | 298 | // Redirect to login screen. |
273 | echo '<script>alert("'. t("Wrong login/password.") .'");document.location=\'?do=login'.$redir.'\';</script>'; | 299 | echo '<script>alert("'. t($errorReason) .'");document.location=\'?do=login'.$redir.'\';</script>'; |
274 | exit; | 300 | exit; |
275 | } | 301 | } |
276 | } | 302 | } |
@@ -1719,7 +1745,7 @@ function buildLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager) | |||
1719 | * @param SessionManager $sessionManager SessionManager instance | 1745 | * @param SessionManager $sessionManager SessionManager instance |
1720 | * @param LoginManager $loginManager LoginManager instance | 1746 | * @param LoginManager $loginManager LoginManager instance |
1721 | */ | 1747 | */ |
1722 | function install($conf, $sessionManager, $loginManager) { | 1748 | function install($conf, $sessionManager, $loginManager, $userspace) { |
1723 | // On free.fr host, make sure the /sessions directory exists, otherwise login will not work. | 1749 | // On free.fr host, make sure the /sessions directory exists, otherwise login will not work. |
1724 | if (endsWith($_SERVER['HTTP_HOST'],'.free.fr') && !is_dir($_SERVER['DOCUMENT_ROOT'].'/sessions')) mkdir($_SERVER['DOCUMENT_ROOT'].'/sessions',0705); | 1750 | if (endsWith($_SERVER['HTTP_HOST'],'.free.fr') && !is_dir($_SERVER['DOCUMENT_ROOT'].'/sessions')) mkdir($_SERVER['DOCUMENT_ROOT'].'/sessions',0705); |
1725 | 1751 | ||
@@ -1755,7 +1781,7 @@ function install($conf, $sessionManager, $loginManager) { | |||
1755 | } | 1781 | } |
1756 | 1782 | ||
1757 | 1783 | ||
1758 | if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) | 1784 | if (true) |
1759 | { | 1785 | { |
1760 | $tz = 'UTC'; | 1786 | $tz = 'UTC'; |
1761 | if (!empty($_POST['continent']) && !empty($_POST['city']) | 1787 | if (!empty($_POST['continent']) && !empty($_POST['city']) |
@@ -1764,15 +1790,15 @@ function install($conf, $sessionManager, $loginManager) { | |||
1764 | $tz = $_POST['continent'].'/'.$_POST['city']; | 1790 | $tz = $_POST['continent'].'/'.$_POST['city']; |
1765 | } | 1791 | } |
1766 | $conf->set('general.timezone', $tz); | 1792 | $conf->set('general.timezone', $tz); |
1767 | $login = $_POST['setlogin']; | 1793 | $conf->set('credentials.login', $userspace); |
1768 | $conf->set('credentials.login', $login); | ||
1769 | $salt = sha1(uniqid('', true) .'_'. mt_rand()); | 1794 | $salt = sha1(uniqid('', true) .'_'. mt_rand()); |
1770 | $conf->set('credentials.salt', $salt); | 1795 | $conf->set('credentials.salt', $salt); |
1771 | $conf->set('credentials.hash', sha1($_POST['setpassword'] . $login . $salt)); | 1796 | $hash = sha1(uniqid('', true) .'_'. mt_rand()); |
1797 | $conf->set('credentials.hash', $hash); | ||
1772 | if (!empty($_POST['title'])) { | 1798 | if (!empty($_POST['title'])) { |
1773 | $conf->set('general.title', escape($_POST['title'])); | 1799 | $conf->set('general.title', escape($_POST['title'])); |
1774 | } else { | 1800 | } else { |
1775 | $conf->set('general.title', 'Shared links on '.escape(index_url($_SERVER))); | 1801 | $conf->set('general.title', ucwords(str_replace("_", " ", $userspace))); |
1776 | } | 1802 | } |
1777 | $conf->set('translation.language', escape($_POST['language'])); | 1803 | $conf->set('translation.language', escape($_POST['language'])); |
1778 | $conf->set('updates.check_updates', !empty($_POST['updateCheck'])); | 1804 | $conf->set('updates.check_updates', !empty($_POST['updateCheck'])); |
@@ -1841,7 +1867,12 @@ $container['history'] = $history; | |||
1841 | $app = new \Slim\App($container); | 1867 | $app = new \Slim\App($container); |
1842 | 1868 | ||
1843 | // REST API routes | 1869 | // REST API routes |
1844 | $app->group('/api/v1', function() { | 1870 | if (isset($userspace)) { |
1871 | $mountpoint = '/' . $userspace . '/api/v1'; | ||
1872 | } else { | ||
1873 | $mountpoint = '/api/v1'; | ||
1874 | } | ||
1875 | $app->group($mountpoint, function() { | ||
1845 | $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo')->setName('getInfo'); | 1876 | $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo')->setName('getInfo'); |
1846 | $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks'); | 1877 | $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks'); |
1847 | $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink'); | 1878 | $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink'); |
@@ -1860,7 +1891,7 @@ $app->group('/api/v1', function() { | |||
1860 | $response = $app->run(true); | 1891 | $response = $app->run(true); |
1861 | // Hack to make Slim and Shaarli router work together: | 1892 | // Hack to make Slim and Shaarli router work together: |
1862 | // If a Slim route isn't found and NOT API call, we call renderPage(). | 1893 | // If a Slim route isn't found and NOT API call, we call renderPage(). |
1863 | if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v1') === false) { | 1894 | if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], $mountpoint) === false) { |
1864 | // We use UTF-8 for proper international characters handling. | 1895 | // We use UTF-8 for proper international characters handling. |
1865 | header('Content-Type: text/html; charset=utf-8'); | 1896 | header('Content-Type: text/html; charset=utf-8'); |
1866 | renderPage($conf, $pluginManager, $linkDb, $history, $sessionManager, $loginManager); | 1897 | renderPage($conf, $pluginManager, $linkDb, $history, $sessionManager, $loginManager); |