data['MAIN']['DEBUGLEVEL'];
if ($_SERVER["REQUEST_METHOD"] != "POST"){
@DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
}
/* Set template compile directory */
if (isset ($config->data['MAIN']['COMPILE'])){
$smarty->compile_dir= $config->data['MAIN']['COMPILE'];
} else {
$smarty->compile_dir= '/var/spool/gosa';
}
$smarty->assign ('nextfield', 'username');
/* Check for compile directory */
if (!(is_dir($smarty->compile_dir) && is_writable($smarty->compile_dir))){
print_red(sprintf(_("Directory '%s' specified as compile directory is not accessable!"),
$smarty->compile_dir));
echo $_SESSION['errors'];
exit();
}
/* Check for old files in compile directory */
clean_smarty_compile_dir($smarty->compile_dir);
/* Language setup */
if ($config->data['MAIN']['LANG'] == ""){
$lang= get_browser_language();
} else {
$lang= $config->data['MAIN']['LANG'];
}
$lang.=".UTF-8";
putenv("LANGUAGE=");
putenv("LANG=$lang");
setlocale(LC_ALL, $lang);
$GLOBALS['t_language']= $lang;
$GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
/* Set the text domain as 'messages' */
$domain = 'messages';
bindtextdomain($domain, "$BASE_DIR/locale");
textdomain($domain);
if ($_SERVER["REQUEST_METHOD"] != "POST"){
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, "Setting language to");
}
/* Check for SSL connection */
$ssl= "";
if (!isset($HTTP_SERVER_VARS['HTTPS']) ||
!stristr($HTTP_SERVER_VARS['HTTPS'], "on")) {
if (empty($HTTP_SERVER_VARS['REQUEST_URI'])) {
$ssl= "https://".$HTTP_SERVER_VARS['HTTP_HOST'].
$HTTP_SERVER_VARS['PATH_INFO'];
} else {
$ssl= "https://".$HTTP_SERVER_VARS['HTTP_HOST'].
$HTTP_SERVER_VARS['REQUEST_URI'];
}
}
/* If SSL is forced, just forward to the SSL enabled site */
if ($config->data['MAIN']['FORCESSL'] == 'true' && $ssl != ''){
header ("Location: $ssl");
exit;
}
/* Got a formular answer, validate and try to log in */
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])){
/* Reset error messages */
$message= "";
$server= validate($_POST["server"]);
$config->set_current($server);
/* Admin-logon and verify */
$ldap = $config->get_ldap_link();
if (is_null($ldap) || (is_int($ldap) && $ldap == 0)){
print_red (_("Can't bind to LDAP. Please contact the system administrator."));
echo $_SESSION['errors'];
$smarty->display(get_template_path('login.tpl'));
exit();
}
/* Check for schema file presence */
require_once("functions_setup.inc");
if(!is_schema_readable($config->current['SERVER'],$config->current['ADMIN'],$config->current['PASSWORD'])){
print_red(_("GOsa cannot retrieve information about the installed schema files. Please make sure, that this is possible."));
echo $_SESSION['errors'];
exit();
}else{
$str = (schema_check($config->current['SERVER'],$config->current['ADMIN'],$config->current['PASSWORD'],0,TRUE));
$checkarr = array();
foreach($str as $tr){
if(isset($tr['needonstartup'])){
print_red($tr['msg']."
"._("Your ldap setup contains old schema definitions. Please re-run the setup."));
print $_SESSION['errors'];
exit();
}
}
}
/* Check for locking area */
$ldap->cat($config->current['CONFIG']);
$attrs= $ldap->fetch();
if (!count ($attrs)){
$ldap->cd($config->current['BASE']);
$ldap->create_missing_trees($config->current['CONFIG']);
}
/* Check for at least one subtreeACL in the complete tree */
$ldap->cd($config->current['BASE']);
$ldap->search("(&(objectClass=gosaObject)(gosaSubtreeACL=:all))");
if ($ldap->count() < 1){
print_red(_("You're missing an administrative account for GOsa, you'll not be able to administrate anything!"));
displayLogin();
exit();
}
/* Check for valid input */
$username= $_POST["username"];
if (!ereg("^[A-Za-z0-9_.-]+$", $username)){
$message= _("Please specify a valid username!");
} elseif (mb_strlen($_POST["password"], 'UTF-8') == 0){
$message= _("Please specify your password!");
$smarty->assign ('nextfield', 'password');
} else {
/* Login as user, initialize user ACL's */
$ui= ldap_login_user($username, $_POST["password"]);
if ($ui === NULL || $ui == 0){
$message= _("Please check the username/password combination.");
$smarty->assign ('nextfield', 'password');
gosa_log ("Authentication failed for user \"$username\"");
} else {
/* Remove all locks of this user */
del_user_locks($ui->dn);
/* Save userinfo and plugin structure */
$_SESSION['ui']= $ui;
$_SESSION['session_cnt']= 0;
/* Let GOsa trigger a new connection for each POST, save
config to session. */
$_SESSION['config']= $config;
/* Go to main page */
gosa_log ("User \"$username\" logged in successfully");
header ("Location: main.php?global_check=1");
exit;
}
}
}
/* Fill template with required values */
$smarty->assign ('date', gmdate("D, d M Y H:i:s"));
$smarty->assign ('username', $username);
$smarty->assign ('personal_img', get_template_path('images/personal.png'));
$smarty->assign ('password_img', get_template_path('images/password.png'));
$smarty->assign ('directory_img', get_template_path('images/ldapserver.png'));
/* Some error to display? */
if (!isset($message)){
$message= "";
}
$smarty->assign ("message", $message);
/* Displasy SSL mode warning? */
if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
$smarty->assign ("ssl", ""._("Warning").": "._("Session will not be encrypted.")." "._("Enter SSL session")."!");
} else {
$smarty->assign ("ssl", "");
}
/* Generate server list */
$servers= array();
if (isset($_POST['server'])){
$selected= validate($_POST['server']);
} else {
$selected= $config->data['MAIN']['DEFAULT'];
}
foreach ($config->data['LOCATIONS'] as $key => $ignored){
$servers[$key]= $key;
}
$smarty->assign ("server_options", $servers);
$smarty->assign ("server_id", $selected);
/* show login screen */
$smarty->display (get_template_path('headers.tpl'));
$smarty->assign ("PHPSESSID", session_id());
if (isset($_SESSION['errors'])){
$smarty->assign("errors", $_SESSION['errors']);
}
if ($error_collector != ""){
$smarty->assign("php_errors", $error_collector."");
} else {
$smarty->assign("php_errors", "");
}
$smarty->display (get_template_path('login.tpl'));
function displayLogin()
{
global $smarty,$message,$config,$ssl,$error_collector;
error_reporting(E_ALL);
/* Fill template with required values */
$username = "";
if(isset($_POST["username"])){
$username= $_POST["username"];
}
$smarty->assign ('date', gmdate("D, d M Y H:i:s"));
$smarty->assign ('username', $username);
$smarty->assign ('personal_img', get_template_path('images/personal.png'));
$smarty->assign ('password_img', get_template_path('images/password.png'));
$smarty->assign ('directory_img', get_template_path('images/ldapserver.png'));
/* Some error to display? */
if (!isset($message)){
$message= "";
}
$smarty->assign ("message", $message);
/* Displasy SSL mode warning? */
if ($ssl != "" && $config->data['MAIN']['WARNSSL'] == 'true'){
$smarty->assign ("ssl", ""._("Warning").": "._("Session will not be encrypted.")." "._("Enter SSL session")."!");
} else {
$smarty->assign ("ssl", "");
}
/* Generate server list */
$servers= array();
if (isset($_POST['server'])){
$selected= validate($_POST['server']);
} else {
$selected= $config->data['MAIN']['DEFAULT'];
}
foreach ($config->data['LOCATIONS'] as $key => $ignored){
$servers[$key]= $key;
}
$smarty->assign ("server_options", $servers);
$smarty->assign ("server_id", $selected);
/* show login screen */
$smarty->display (get_template_path('headers.tpl'));
$smarty->assign ("PHPSESSID", session_id());
if (isset($_SESSION['errors'])){
$smarty->assign("errors", $_SESSION['errors']);
}
if ($error_collector != ""){
$smarty->assign("php_errors", $error_collector."");
} else {
$smarty->assign("php_errors", "");
}
$smarty->display(get_template_path('login.tpl'));
exit();
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>