2003-04-23 21:01:18 +00:00
< ? php
2003-03-13 19:48:49 +00:00
/*
$Id $
This code is part of LDAP Account Manager ( http :// www . sourceforge . net / projects / lam )
Copyright ( C ) 2003 Michael Duergner
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
2003-03-14 11:32:28 +00:00
2003-03-13 19:48:49 +00:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2003-03-14 11:32:28 +00:00
2003-03-13 19:48:49 +00:00
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2003-03-14 11:32:28 +00:00
2003-04-23 22:00:42 +00:00
LDAP Account Manager checking login datas .
2003-03-13 19:48:49 +00:00
*/
2003-03-18 20:55:43 +00:00
2003-04-23 21:01:18 +00:00
include_once ( " ../lib/config.inc " ); // Include config.inc which provides Config class
2003-03-23 14:41:15 +00:00
2003-05-03 15:47:42 +00:00
session_save_path ( " ../sess " ); // Set session save path
2003-03-23 14:41:15 +00:00
@ session_start (); // Start LDAP Account Manager session
2003-04-23 21:01:18 +00:00
2003-07-20 18:28:38 +00:00
function display_LoginPage ( $config_object , $profile )
2003-04-23 21:01:18 +00:00
{
2003-05-12 20:46:58 +00:00
global $error_message ;
2003-04-23 21:01:18 +00:00
// generate 256 bit key and initialization vector for user/passwd-encryption
$key = mcrypt_create_iv ( 32 , MCRYPT_DEV_RANDOM );
$iv = mcrypt_create_iv ( 32 , MCRYPT_DEV_RANDOM );
// save both in cookie
setcookie ( " Key " , base64_encode ( $key ), 0 , " / " );
setcookie ( " IV " , base64_encode ( $iv ), 0 , " / " );
2003-05-12 20:46:58 +00:00
session_register ( " language " );
2003-07-20 18:28:38 +00:00
$_SESSION [ 'language' ] = $config_object -> get_defaultLanguage ();
session_register ( " header " );
$language = explode ( " : " , $_SESSION [ 'language' ]);
2003-07-23 07:16:59 +00:00
$_SESSION [ 'header' ] = " <?xml version= \" 1.0 \" encoding= \" " . $language [ 0 ] . " \" ?> \n <!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN \" \" http://www.w3.org/TR/html4/loose.dtd \" > \n \n " ;
2003-05-12 20:46:58 +00:00
2003-04-23 21:01:18 +00:00
// loading available languages from language.conf file
2003-07-14 21:59:09 +00:00
$languagefile = " ../config/language " ;
2003-04-23 21:01:18 +00:00
if ( is_file ( $languagefile ) == True )
{
$file = fopen ( $languagefile , " r " );
$i = 0 ;
while ( ! feof ( $file ))
{
$line = fgets ( $file , 1024 );
2003-05-12 20:46:58 +00:00
if ( $line == " " || $line == " \n " || $line [ 0 ] == " # " ) continue ; // ignore comment and empty lines
2003-04-23 21:01:18 +00:00
$value = explode ( " : " , $line );
$languages [ $i ][ " link " ] = $value [ 0 ] . " : " . $value [ 1 ];
$languages [ $i ][ " descr " ] = $value [ 2 ];
2003-05-12 20:46:58 +00:00
if ( rtrim ( $line ) == $_SESSION [ " language " ])
{
$languages [ $i ][ " default " ] = " YES " ;
}
else
{
$languages [ $i ][ " default " ] = " NO " ;
}
2003-04-23 21:01:18 +00:00
$i ++ ;
}
fclose ( $file );
}
else
{
2003-05-03 15:47:42 +00:00
$message = _ ( " Unable to load available languages. Setting English as default language. For further instructions please contact the Admin of this site. " );
2003-04-23 21:01:18 +00:00
}
2003-07-14 21:59:09 +00:00
$profiles = getConfigProfiles ();
2003-05-07 19:53:58 +00:00
setlanguage (); // setting correct language
2003-07-23 08:08:25 +00:00
echo $_SESSION [ " header " ];
?>
< html >
< head >
< title > LDAP Account Manager - Login -</ title >
< link rel = " stylesheet " type = " text/css " href = " ../style/layout.css " >
</ head >
< body >
< p align = " center " >
< a href = " http://lam.sf.net " target = " _blank " >< img src = " ../graphics/banner.jpg " border = " 1 " ></ a >
</ p >
< table width = " 100% " border = " 0 " >
< tr >
< td width = " 100% " align = " right " >
< a href = " ./config/conflogin.php " target = " _self " >< ? php echo _ ( " Configuration Login " ); ?> </a>
</ td >
</ tr >
</ table >
< hr >< br >< br >
< p align = " center " >
< b >< ? php echo _ ( " Enter Username and Password for Account: " ); ?> </b>
</ p >
< ? php
if ( $error_message != " " ) {
?>
< p align = " center " >
< ? php
echo $error_message ;
?>
</ p >
< ? php
}
?>
< form action = " login.php " method = " post " >
< input type = " hidden " name = " action " value = " checklogin " >
< table width = " 500 " align = " center " border = " 0 " >
2003-04-23 21:01:18 +00:00
< tr >
2003-07-23 08:08:25 +00:00
< td width = " 45% " align = " right " >
< ? php
echo _ ( " Username: " );
?>
</ td >
< td width = " 10% " >
</ td >
< td width = " 45% " align = " left " >
< select name = " username " size = " 1 " >
< ? php
for ( $i = 0 ; $i < count ( $config_object -> Admins ); $i ++ ) {
$text = explode ( " , " , $config_object -> Admins [ $i ]);
$text = explode ( " = " , $text [ 0 ]);
?>
< option value = " <?php echo $config_object->Admins [ $i ]; ?> " >< ? php echo $text [ 1 ]; ?> </option>
< ? php
}
?>
</ select >
2003-04-23 21:01:18 +00:00
</ td >
</ tr >
2003-07-23 08:08:25 +00:00
< tr >
< td width = " 45% " align = " right " >
< ? php
echo _ ( " Password: " );
?>
</ td >
< td width = " 10% " >
</ td >
< td width = " 45% " align = " left " >
< input type = " password " name = " passwd " >
</ td >
</ tr >
< tr >
< ? php
if ( $message != " " ) {
?>
< td width = " 100% " colspan = " 3 " align = " center " >
< ? php
echo $message ;
?>
< input type = \ " hidden \" name= \" language \" value= \" english \" >
</ td >
< ? php
2003-04-23 21:01:18 +00:00
}
2003-07-23 08:08:25 +00:00
else
{
?>
< td width = " 45% " align = " right " >
< ? php
echo _ ( " Your Language: " );
?>
</ td >
< td width = " 10% " >
</ td >
< td width = " 45% " align = " left " >
< select name = " language " size = " 1 " >
< ? php
for ( $i = 0 ; $i < count ( $languages ); $i ++ ) {
if ( $languages [ $i ][ " default " ] == " YES " ) {
?>
< option selected value = " <?php echo $languages[$i] [ " link " ] . " : " . $languages[$i] [ " descr " ]; ?> " >< ? php echo $languages [ $i ][ " descr " ]; ?> </option>
< ? php
2003-04-23 21:01:18 +00:00
}
else
{
2003-07-23 08:08:25 +00:00
?>
< option value = " <?php echo $languages[$i] [ " link " ] . " : " . $languages[$i] [ " descr " ]; ?> " >< ? php echo $languages [ $i ][ " descr " ]; ?> </option>
< ? php
2003-04-23 21:01:18 +00:00
}
2003-07-23 08:08:25 +00:00
}
?>
</ select >
</ td >
< ? php
}
?>
</ tr >
< tr >
< td width = " 100% " colspan = " 3 " align = " center " >
< input type = " submit " name = " submit " value = " <?php echo _( " Login " ); ?> " >
</ td >
</ tr >
</ table >
< br >< br >
< table width = " 345 " align = " center " bgcolor = " #C7E7C7 " border = " 0 " >
< tr >
< td width = " 100% " align = " center " >
< ? php
echo _ ( " You are connecting to ServerURL: " );
?>
< b >< ? php echo $config_object -> get_ServerURL (); ?> </b>
</ td >
</ tr >
</ table >
</ form >
< br >< br >
< form action = " ./login.php " method = " post " enctype = " plain/text " >
< input type = " hidden " name = " action " value = " profileChange " >
< p align = " center " >
< ? php
echo _ ( " You are currently using Profile: " );
if ( ! $_POST [ 'profile' ]) {
$_POST [ 'profile' ] = $profile ;
}
?>
< b >< ? php echo $_POST [ 'profile' ]; ?> </b>
< br >
< select name = " profile " size = " 1 " >
< ? php
for ( $i = 0 ; $i < count ( $profiles ); $i ++ ) {
?>
< option value = " <?php echo $profiles[$i] ; ?> " >< ? php echo $profiles [ $i ]; ?> </option>
< ? php
}
?>
</ select >
< input type = " submit " value = " <?php echo _( " Change Profile " ); ?> " >
</ p >
</ form >
</ body >
</ html >
< ? php
2003-04-23 21:01:18 +00:00
}
2003-03-14 11:32:28 +00:00
// checking if the submitted username/password is correct.
2003-05-03 15:47:42 +00:00
if ( $_POST [ 'action' ] == " checklogin " )
2003-03-14 11:32:28 +00:00
{
2003-04-23 21:01:18 +00:00
include_once ( " ../lib/ldap.inc " ); // Include ldap.php which provides Ldap class
2003-03-20 16:41:52 +00:00
2003-07-20 18:36:39 +00:00
session_register ( " ldap " ); // Register $ldap object in session
$_SESSION [ 'ldap' ] = new Ldap ( $_SESSION [ 'config' ]); //$config); // Create new Ldap object
2003-05-18 18:59:02 +00:00
if ( $_POST [ 'passwd' ] == " " )
2003-03-14 11:32:28 +00:00
{
2003-05-18 18:59:02 +00:00
$error_message = _ ( " Empty Password submitted. Try again. " );
2003-07-20 18:28:38 +00:00
display_LoginPage ( $_SESSION [ 'config' ], " " ); // Empty password submitted. Return to login page.
2003-03-14 11:32:28 +00:00
}
2003-03-15 12:13:49 +00:00
else
2003-03-14 11:32:28 +00:00
{
2003-07-20 18:36:39 +00:00
$result = $_SESSION [ 'ldap' ] -> connect ( $_POST [ 'username' ], $_POST [ 'passwd' ]); // Connect to LDAP server for verifing username/password
2003-05-18 18:59:02 +00:00
if ( $result == True ) // Username/password correct. Do some configuration and load main frame.
2003-03-15 12:13:49 +00:00
{
2003-07-20 18:28:38 +00:00
$_SESSION [ 'language' ] = $_POST [ 'language' ]; // Write selected language in session
$language = explode ( " : " , $_SESSION [ 'language' ]);
$_SESSION [ 'header' ] = " <?xml version= \" 1.0 \" encoding= \" " . $language [ 3 ] . " \" ?> \n <!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN \" \" http://www.w3.org/TR/html4/loose.dtd \" > \n \n " ;
2003-05-18 18:59:02 +00:00
include ( " ./main.php " ); // Load main frame
2003-03-15 12:13:49 +00:00
}
else
{
2003-05-18 18:59:02 +00:00
if ( $ldap -> server )
{
$error_message = _ ( " Wrong Password/Username combination. Try again. " );
2003-07-20 18:28:38 +00:00
display_LoginPage ( $_SESSION [ 'config' ], " " ); // Username/password invalid. Return to login page.
2003-05-18 18:59:02 +00:00
}
else
{
$error_message = _ ( " Cannot connect to specified LDAP-Server. Try again. " );
2003-07-20 18:28:38 +00:00
display_LoginPage ( $_SESSION [ 'config' ], " " ); // Username/password invalid. Return to login page.
2003-05-18 18:59:02 +00:00
}
2003-03-15 12:13:49 +00:00
}
2003-03-14 11:32:28 +00:00
}
}
2003-07-14 21:59:09 +00:00
// Reload loginpage after a profile change
elseif ( $_POST [ 'action' ] == " profileChange " ) {
$config = new Config ( $_POST [ 'profile' ]); // Recreate the config object with the submited profile
2003-07-20 18:28:38 +00:00
display_LoginPage ( $config , " " ); // Load login page
2003-07-14 21:59:09 +00:00
}
2003-03-23 14:41:15 +00:00
// Load login page
2003-03-14 11:32:28 +00:00
else
{
2003-03-20 16:37:20 +00:00
session_register ( " config " ); // Register $config object in session
2003-07-14 21:59:09 +00:00
$default_Config = new CfgMain ();
$default_Profile = $default_Config -> default ;
2003-07-20 18:28:38 +00:00
//echo "default_Profile=" . $default_Profile . "<br>";
$_SESSION [ " config " ] = new Config ( $default_Profile ); // Create new Config object
2003-03-20 16:37:20 +00:00
2003-07-20 18:28:38 +00:00
display_LoginPage ( $_SESSION [ " config " ], $default_Profile ); // Load Login page
2003-03-14 11:32:28 +00:00
}
?>