diff --git a/lam/help/help.inc b/lam/help/help.inc index 55f0049c..a051b145 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -122,12 +122,14 @@ $helpArray = array ( "Text" => _("This changes the password of the selected profile.")), "234" => array ("ext" => "FALSE", "Headline" => _("Profile management") . " - " . _("Change default profile"), "Text" => _("This changes the profile which is selected by default at login.")), - "235" => array ("ext" => "FALSE", "Headline" => _("Profile management") . " - " . _("Change master password"), + "235" => array ("ext" => "FALSE", "Headline" => _("Change master password"), "Text" => _("If you want to change your master configuration password, please enter it here.")), - "236" => array ("ext" => "FALSE", "Headline" => _("Profile management") . " - " . _("Master password"), + "236" => array ("ext" => "FALSE", "Headline" => _("Master password"), "Text" => _("Please enter the master configuration password. This is NOT your LDAP password. It is stored in your config.cfg file. If this is the first time you log in, enter \"lam\".")), "237" => array ("ext" => "FALSE", "Headline" => _("Configuration wizard") . " - " . _("Base module"), "Text" => _("Every account type needs exactly one base module. This module provides a structural object class.")), + "238" => array ("ext" => "FALSE", "Headline" => _("Session timeout"), + "Text" => _("This is the time (in minutes) of inactivity after which a user is automatically logged off.")), "250" => array ("ext" => "FALSE", "Headline" => _("Account lists - Filters"), "Text" => _("Here you can input small filter expressions (e.g. 'value' or 'v*'). LAM will filter case-insensitive.")), // 300 - 399 diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 3d83e33b..9e837a2d 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -718,11 +718,15 @@ class CfgMain { /** Password to change config.cfg */ var $password; + + /** Time of inactivity before session times out (minutes) */ + var $sessionTimeout; /** * Loads preferences from config file */ function CfgMain() { + $this->sessionTimeout = 30; $this->reload(); } @@ -742,11 +746,15 @@ class CfgMain { if (($line == "")||($line[0] == "#")) continue; // ignore comments // search keywords if (substr($line, 0, 10) == "password: ") { - $this->password = substr($line, 10, strlen($line)-10); + $this->password = substr($line, 10, strlen($line) - 10); continue; } if (substr($line, 0, 9) == "default: ") { - $this->default = substr($line, 9, strlen($line)-9); + $this->default = substr($line, 9, strlen($line) - 9); + continue; + } + if (substr($line, 0, 16) == "sessionTimeout: ") { + $this->sessionTimeout = intval(substr($line, 16, strlen($line) - 16)); continue; } } @@ -784,11 +792,17 @@ class CfgMain { $save_default = True; continue; } + if (substr($file_array[$i], 0, 16) == "sessionTimeout: ") { + $file_array[$i] = "sessionTimeout: " . $this->sessionTimeout . "\n"; + $save_sessionTimeout = True; + continue; + } } } // check if we have to add new entries (e.g. if user upgraded LAM and has an old config file) if (!$save_password == True) array_push($file_array, "\n\n# password to add/delete/rename configuration profiles\n" . "password: " . $this->password); if (!$save_default == True) array_push($file_array, "\n\n# default profile, without \".conf\"\n" . "default: " . $this->default); + if (!$save_sessionTimeout == True) array_push($file_array, "\n\n# session timeout in minutes\n" . "sessionTimeout: " . $this->sessionTimeout); $file = @fopen($conffile, "w"); if ($file) { for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]); diff --git a/lam/lib/security.inc b/lam/lib/security.inc index ed8d3ac7..f3a07545 100644 --- a/lam/lib/security.inc +++ b/lam/lib/security.inc @@ -28,11 +28,16 @@ $Id$ * @author Roland Gruber */ +/** configuration options */ +include_once('config.inc'); + /** * Starts a session and checks the environment. * The script is stopped if one of the checks fail. */ function startSecureSession() { + // check if client IP is on the list of valid IPs + checkClientIP(); // start session if (isset($_SESSION)) unset($_SESSION); $sessionDir = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/sess"; @@ -48,10 +53,15 @@ function startSecureSession() { // IP is invalid die(); } - // check if client IP is on the list of valid IPs - checkClientIP(); // check if session time has not expired - // TODO + if (($_SESSION['sec_sessionTime'] + (60 * $_SESSION['cfgMain']->sessionTimeout)) > time()) { + // ok, update time + $_SESSION['sec_sessionTime'] = time(); + } + else { + // session expired, logoff user + logoffAndBackToLoginPage(); + } } /** @@ -83,4 +93,45 @@ function getValidUserDNs($dn) { return array("uid=test,o=test", "uid=test2,o=test"); } +/** + * Logs off the user and displays the login page. + * + */ +function logoffAndBackToLoginPage() { + // delete key and iv in cookie + if (function_exists('mcrypt_create_iv')) { + setcookie("Key", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 0, "/"); + setcookie("IV", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 0, "/"); + } + // close LDAP connection + @$_SESSION["ldap"]->destroy(); + // link back to login page + $paths = array('./', '../', '../../', '../../../'); + $page = 'login.php'; + for ($i = 0; $i < sizeof($paths); $i++) { + if (file_exists($paths[$i] . $page)) { + $page = $paths[$i] . $page; + break; + } + } + echo $_SESSION['header']; + echo "\n"; + echo "\n"; + echo "\n"; + // print JavaScript refresh + echo "\n"; + // print link if refresh does not work + echo "

\n"; + echo "" . _("Your session expired, click here to go back to the login page.") . "\n"; + echo "

\n"; + echo "\n"; + echo "\n"; + // destroy session + session_destroy(); + unset($_SESSION); + die(); +} + ?> \ No newline at end of file diff --git a/lam/templates/config/mainmanage.php b/lam/templates/config/mainmanage.php index 06545034..77fcb1b8 100644 --- a/lam/templates/config/mainmanage.php +++ b/lam/templates/config/mainmanage.php @@ -70,30 +70,30 @@ echo $_SESSION['header']; // check if submit button was pressed if ($_POST['submit']) { + $errors = array(); // set master password if (isset($_POST['masterpassword']) && ($_POST['masterpassword'] != "")) { if ($_POST['masterpassword'] && $_POST['masterpassword2'] && ($_POST['masterpassword'] == $_POST['masterpassword2'])) { $cfg->password = $_POST['masterpassword']; - $cfg->save(); $msg = _("New master password set successfully."); unset($_SESSION["mainconf_password"]); } - else $error = _("Master passwords are different or empty!"); + else $errors[] = _("Master passwords are different or empty!"); + } + // set session timeout + $cfg->sessionTimeout = $_POST['sessionTimeout']; + // save settings + $cfg->save(); + // print messages + if (sizeof($errors) > 0) { + for ($i = 0; $i < sizeof($errors); $i++) StatusMessage("ERROR", $errors[$i]); } else { - $msg = _("No changes were made."); + StatusMessage("INFO", _("Your settings were successfully saved.")); + // back to login page + echo "

" . _("Back to login") . "

"; + exit(); } - // print messages - if ($error || $msg) { - if ($error) StatusMessage("ERROR", "", $error); - if ($msg) { - StatusMessage("INFO", "", $msg); - // back to login page - echo "

" . _("Back to login") . "

"; - exit(); - } - } - else exit; } ?> @@ -102,6 +102,40 @@ if ($_POST['submit']) {
@@ -126,7 +160,7 @@ if ($_POST['submit']) { diff --git a/lam/templates/login.php b/lam/templates/login.php index 5f405742..90073a38 100644 --- a/lam/templates/login.php +++ b/lam/templates/login.php @@ -367,6 +367,7 @@ if(!empty($_POST['checklogin'])) // set security settings for session $_SESSION['sec_session_id'] = session_id(); $_SESSION['sec_client_ip'] = $_SERVER['REMOTE_ADDR']; + $_SESSION['sec_sessionTime'] = time(); // Load main frame include("./main.php"); } @@ -407,6 +408,7 @@ else $default_Config = new CfgMain(); $default_Profile = $default_Config->default; $_SESSION["config"] = new Config($default_Profile); // Create new Config object + $_SESSION["cfgMain"] = $default_Config; // Create new CfgMain object display_LoginPage($_SESSION["config"]); // Load Login page }
+
+ +

+ + + + + + +
+ + +   + "; + echo "\"""; + echo "\n"; + ?> +
+

+

@@ -110,7 +144,7 @@ if ($_POST['submit']) {

- +
- +