From: Jerome Jutteau Date: Tue, 10 Mar 2015 16:38:34 +0000 (+0100) Subject: Fixes #16 Permits to authenticate administrator using HTTP auth X-Git-Tag: 1.1~161 X-Git-Url: https://git.p6c8.net/jirafeau.git/commitdiff_plain/4c5e2caa3a0fedd86292b213c3bb3aa8c812d8c2?ds=sidebyside;hp=625f38a7decfc1ed72e0120c6ff34fcbe2d55100 Fixes #16 Permits to authenticate administrator using HTTP auth This patch permits to ease integration of Jirafeau in external projects like https://yunohost.org/. Also fix a license oversight. --- diff --git a/admin.php b/admin.php index afcccb5..837686e 100644 --- a/admin.php +++ b/admin.php @@ -33,7 +33,7 @@ if (file_exists (JIRAFEAU_ROOT . 'install.php') } /* Disable admin interface if we have a empty admin password. */ -if (empty($cfg['admin_password'])) +if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user'])) { require (JIRAFEAU_ROOT . 'lib/template/header.php'); echo '

'. @@ -50,8 +50,8 @@ session_start(); if (isset ($_POST['action']) && (strcmp ($_POST['action'], 'logout') == 0)) $_SESSION['admin_auth'] = false; -/* Check password. */ -if (isset ($_POST['admin_password'])) +/* Check classic admin password authentification. */ +if (isset ($_POST['admin_password']) && empty($cfg['admin_http_auth_user'])) { if (strcmp ($cfg['admin_password'], $_POST['admin_password']) == 0) $_SESSION['admin_auth'] = true; @@ -65,8 +65,9 @@ if (isset ($_POST['admin_password'])) exit; } } -/* Ask for password. */ -elseif (!isset ($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true) +/* Ask for classic admin password authentification. */ +elseif ((!isset ($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true) + && empty($cfg['admin_http_auth_user'])) { require (JIRAFEAU_ROOT . 'lib/template/header.php'); ?>

@@ -95,6 +96,25 @@ elseif (!isset ($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true) require (JIRAFEAU_ROOT.'lib/template/footer.php'); exit; } +/* Check authenticated user if HTTP authentification is enable. */ +elseif ((!isset ($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true) + && !empty($cfg['admin_http_auth_user'])) +{ + if ($cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER']) + $_SESSION['admin_auth'] = true; +} + +/* Be sure that no one can access further without admin_auth. */ +if (!isset ($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true) +{ + $_SESSION['admin_auth'] = false; + require (JIRAFEAU_ROOT . 'lib/template/header.php'); + echo '

'. + t('Sorry, you are not authenticated on admin interface.') . + '

'; + require (JIRAFEAU_ROOT.'lib/template/footer.php'); + exit; +} /* Operations may take a long time. * Be sure PHP's safe mode is off. diff --git a/lib/config.original.php b/lib/config.original.php index fefd61e..76d5870 100644 --- a/lib/config.original.php +++ b/lib/config.original.php @@ -2,6 +2,7 @@ /* * Jirafeau, your web file repository * Copyright (C) 2008 Julien "axolotl" BERNARD + * Copyright (C) 2015 Jerome Jutteau * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -34,8 +35,6 @@ $cfg['var_root'] = ''; $cfg['lang'] = 'auto'; $cfg['style'] = 'modern'; $cfg['rewrite'] = false; -/* An empty admin password will disable the admin interface. */ -$cfg['admin_password'] = ''; /* preview: false (will download file) or true (will preview in browser if * possible) . */ $cfg['preview'] = true; @@ -55,10 +54,21 @@ $cfg['link_name_lenght'] = 8; * ... and so on */ $cfg['upload_password'] = array(); - +/* An empty admin password will disable the classic admin password + * authentication. + */ +$cfg['admin_password'] = ''; +/* If set, let's the user to be authenticated as administrator. + * The user provided here is the user authenticated by HTTP authentication. + * Note that Jirafeau does not manage the HTTP login part, it just check + * that the provided user is logged. + * If admin_password parameter is also set, admin_password is ignored. + */ +$cfg['admin_http_auth_user'] = ''; /* Installation is done ? */ $cfg['installation_done'] = false; +/* Try to include user's local configuration. */ if ((basename (__FILE__) != 'config.local.php') && file_exists (JIRAFEAU_ROOT.'lib/config.local.php')) { diff --git a/lib/lang/fr.php b/lib/lang/fr.php index 02142e5..d806dc9 100644 --- a/lib/lang/fr.php +++ b/lib/lang/fr.php @@ -102,6 +102,7 @@ $tr = array ( 'Administration password' => 'Mot de passe d\'administration', /* admin.php */ 'Sorry, the admin interface is not enabled.' => 'Désolé, l\'interface d\'administration n\'est pas activée.', + 'Sorry, you are not authenticated on admin interface.' => 'Désolé, vous n\'êtes pas authentifié sur l\'interface d\'administration', 'Login' => 'Connexion', 'Wrong password.' => 'Mot de passe invalide.', 'Admin interface' => 'Interface d\'administration',