diff --git a/html/autocomplete.php b/html/autocomplete.php index d4bfa059240b86ee91d5397ee36ac520fa607780..0499e7a2ef7c377773ae25c71eaf34a550092489 100644 --- a/html/autocomplete.php +++ b/html/autocomplete.php @@ -1,5 +1,4 @@ <?php - /* This code is part of FusionDirectory (http://www.fusiondirectory.org/) Copyright (C) 2003-2010 Cajus Pollmeier @@ -27,11 +26,11 @@ session_cache_limiter("private"); session::start(); -session::global_set('errorsAlreadyPosted',array()); +session::global_set('errorsAlreadyPosted', array()); /* Logged in? Simple security check */ -if (!session::global_is_set('ui')){ - new log("security","unknown","",array(),"Error: autocomplete.php called without session") ; +if (!session::global_is_set('ui')) { + new log("security", "unknown", "", array(), "Error: autocomplete.php called without session"); header ("Location: index.php"); exit; } @@ -41,25 +40,25 @@ if (isset($_GET['type']) && $_GET['type'] == "base") { // Find dn based on name and description if (session::is_set("pathMapping") && count($_POST) == 1) { - $res= ""; - $pathMapping= session::get("pathMapping"); - $search= preg_replace('/"/', '"', current($_POST)); + $res = ""; + $pathMapping = session::get("pathMapping"); + $search = preg_replace('/"/', '"', current($_POST)); $config = session::global_get('config'); foreach ($config->department_info as $dn => $info) { if (!isset($pathMapping[$dn])) { continue; } - if (mb_stristr($info['name'], $search) !== false) { - $res.= "<li>".mark($search, $pathMapping[$dn]).($info['description']==''?"":"<span class='informal'> [".mark($search, $info['description'])."]</span>")."</li>"; + if (mb_stristr($info['name'], $search) !== FALSE) { + $res .= "<li>".mark($search, $pathMapping[$dn]).($info['description'] == ''?"":"<span class='informal'> [".mark($search, $info['description'])."]</span>")."</li>"; continue; } - if (mb_stristr($info['description'], $search) !== false) { - $res.= "<li>".mark($search, $pathMapping[$dn]).($info['description']==''?"":"<span class='informal'> [".mark($search, $info['description'])."]</span>")."</li>"; + if (mb_stristr($info['description'], $search) !== FALSE) { + $res .= "<li>".mark($search, $pathMapping[$dn]).($info['description'] == ''?"":"<span class='informal'> [".mark($search, $info['description'])."]</span>")."</li>"; continue; } - if (mb_stristr($pathMapping[$dn], $search) !== false) { - $res.= "<li>".mark($search, $pathMapping[$dn]).($info['description']==''?"":"<span class='informal'> [".mark($search, $info['description'])."]</span>")."</li>"; + if (mb_stristr($pathMapping[$dn], $search) !== FALSE) { + $res .= "<li>".mark($search, $pathMapping[$dn]).($info['description'] == ''?"":"<span class='informal'> [".mark($search, $info['description'])."]</span>")."</li>"; continue; } } @@ -75,8 +74,8 @@ if (isset($_GET['type']) && $_GET['type'] == "base") { $ui = session::global_get('ui'); /* Is there a filter object arround? */ - if (session::is_set("autocomplete")){ - $filter= session::get("autocomplete"); + if (session::is_set("autocomplete")) { + $filter = session::get("autocomplete"); $filter->processAutocomplete(); } } diff --git a/html/index.php b/html/index.php index 16edfbe23bfc0d249f065b1b292085367461768b..4ceda939c4c19cb6d58c3b521d6ee5244ceb6ec7 100644 --- a/html/index.php +++ b/html/index.php @@ -38,8 +38,8 @@ function displayLogin() error_reporting(E_ALL | E_STRICT); /* Fill template with required values */ $username = ""; - if(isset($_POST["username"])){ - $username= trim(get_post("username")); + if (isset($_POST["username"])) { + $username = trim(get_post("username")); } $smarty->assign ('date', gmdate("D, d M Y H:i:s")); $smarty->assign ('username', $username); @@ -49,8 +49,8 @@ function displayLogin() $smarty->append ('css_files', get_template_path('login.css')); /* Some error to display? */ - if (!isset($message)){ - $message= ""; + if (!isset($message)) { + $message = ""; } $smarty->assign ("message", $message); @@ -61,33 +61,33 @@ function displayLogin() $smarty->assign ("ssl", ""); } - if(!$config->check_session_lifetime()){ + if (!$config->check_session_lifetime()) { $smarty->assign ("lifetime", _("Warning").": ". _("The session lifetime configured in your fusiondirectory.conf will be overridden by php.ini settings.")); - }else{ + } else { $smarty->assign ("lifetime", ""); } /* Generate server list */ - $servers= array(); - if (isset($_POST['server'])){ - $selected= get_post('server'); + $servers = array(); + if (isset($_POST['server'])) { + $selected = get_post('server'); } else { - $selected= $config->data['MAIN']['DEFAULT']; + $selected = $config->data['MAIN']['DEFAULT']; } - foreach ($config->data['LOCATIONS'] as $key => $ignored){ - $servers[$key]= $key; + foreach ($config->data['LOCATIONS'] as $key => $ignored) { + $servers[$key] = $key; } $smarty->assign ("server_options", $servers); $smarty->assign ("server_id", $selected); /* show login screen */ $smarty->assign ("PHPSESSID", session_id()); - if (session::is_set('errors')){ + if (session::is_set('errors')) { $smarty->assign("errors", session::get('errors')); } - if ($error_collector != ""){ - $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>"); + if ($error_collector != "") { + $smarty->assign("php_errors", preg_replace("/%BUGBODY%/", $error_collector_mailto, $error_collector)."</div>"); } else { $smarty->assign("php_errors", ""); } @@ -98,6 +98,7 @@ function displayLogin() $smarty->assign("rtl", language_is_rtl($lang)); $smarty->display (get_template_path('headers.tpl')); + $smarty->assign("version", FD_VERSION); $smarty->display(get_template_path('login.tpl')); @@ -140,7 +141,7 @@ session::set('errors', ""); /* Check if fusiondirectory.conf (.CONFIG_FILE) is accessible */ if (!is_readable(CONFIG_DIR."/".CONFIG_FILE)) { - msg_dialog::display(_("Configuration error"), sprintf(_("FusionDirectory configuration %s/%s is not readable. Please run fusiondirectory-setup --check-config to fix this."), CONFIG_DIR,CONFIG_FILE), FATAL_ERROR_DIALOG); + msg_dialog::display(_("Configuration error"), sprintf(_("FusionDirectory configuration %s/%s is not readable. Please run fusiondirectory-setup --check-config to fix this."), CONFIG_DIR, CONFIG_FILE), FATAL_ERROR_DIALOG); exit(); } @@ -157,7 +158,7 @@ $smarty->compile_dir = $config->get_cfg_value("templateCompileDirectory", SPOOL_ /* Check for compile directory */ if (!(is_dir($smarty->compile_dir) && is_writable($smarty->compile_dir))) { msg_dialog::display(_("Smarty error"), sprintf(_("Directory '%s' specified as compile directory is not accessible!"), - $smarty->compile_dir),FATAL_ERROR_DIALOG); + $smarty->compile_dir), FATAL_ERROR_DIALOG); exit(); } @@ -230,7 +231,7 @@ if (($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])) || $htacces /* Destroy old sessions, they cause a successfull login to relog again ...*/ if (session::global_is_set('_LAST_PAGE_REQUEST')) { - session::global_set('_LAST_PAGE_REQUEST',time()); + session::global_set('_LAST_PAGE_REQUEST', time()); } /* Admin-logon and verify */ @@ -250,13 +251,13 @@ if (($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])) || $htacces if (!count($ldap->get_objectclasses())) { msg_dialog::display(_("LDAP error"), _("Cannot detect information about the installed LDAP schema!"), ERROR_DIALOG); displayLogin(); - exit() ; + exit(); } else { $cfg = array(); - $cfg['admin'] = $config->current['ADMINDN']; - $cfg['password'] = $config->current['ADMINPASSWORD']; - $cfg['connection']= $config->current['SERVER']; - $cfg['tls'] = $tls; + $cfg['admin'] = $config->current['ADMINDN']; + $cfg['password'] = $config->current['ADMINPASSWORD']; + $cfg['connection'] = $config->current['SERVER']; + $cfg['tls'] = $tls; $str = check_schema($cfg, $config->get_cfg_value("rfc2307bis") == "TRUE"); $checkarr = array(); foreach ($str as $tr) { @@ -296,84 +297,84 @@ if (($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])) || $htacces if ($ok) { /* Login as user, initialize user ACL's */ - if ($htaccess_authenticated){ - $ui= ldap_login_user_htaccess($username); - if ($ui === NULL || !$ui){ + if ($htaccess_authenticated) { + $ui = ldap_login_user_htaccess($username); + if ($ui === NULL || !$ui) { msg_dialog::display(_("Authentication error"), _("Cannot retrieve user information for htaccess authentication!"), FATAL_ERROR_DIALOG); exit; } } else { $ui = ldap_login_user($username, $_POST["password"]); } - if ($ui === NULL || !$ui){ - $message= _("Please check the username/password combination."); + if ($ui === NULL || !$ui) { + $message = _("Please check the username/password combination."); $smarty->assign ('nextfield', 'password'); - session::global_set('config',$config); + session::global_set('config', $config); - if(isset($_SERVER['REMOTE_ADDR'])) { - $ip= $_SERVER['REMOTE_ADDR']; - new log("security","login","",array(),"Authentication failed for user \"$username\" [from $ip]"); + if (isset($_SERVER['REMOTE_ADDR'])) { + $ip = $_SERVER['REMOTE_ADDR']; + new log("security", "login", "", array(), "Authentication failed for user \"$username\" [from $ip]"); } else { - new log("security","login","",array(),"Authentication failed for user \"$username\""); + new log("security", "login", "", array(), "Authentication failed for user \"$username\""); } } else { /* Remove all locks of this user */ del_user_locks($ui->dn); /* Save userinfo and plugin structure */ - session::global_set('ui',$ui); - session::global_set('session_cnt',0); + session::global_set('ui', $ui); + session::global_set('session_cnt', 0); /* Let FusionDirectory trigger a new connection for each POST, save config to session. */ $config->get_departments(); $config->make_idepartments(); - session::global_set('config',$config); + session::global_set('config', $config); /* Restore filter settings from cookie, if available */ - if($config->get_cfg_value("storeFilterSettings") == "TRUE"){ + if ($config->get_cfg_value("storeFilterSettings") == "TRUE") { - if(isset($_COOKIE['FusionDirectory_Filter_Settings']) || isset($HTTP_COOKIE_VARS['FusionDirectory_Filter_Settings'])){ + if (isset($_COOKIE['FusionDirectory_Filter_Settings']) || isset($HTTP_COOKIE_VARS['FusionDirectory_Filter_Settings'])) { - if(isset($_COOKIE['FusionDirectory_Filter_Settings'])){ + if (isset($_COOKIE['FusionDirectory_Filter_Settings'])) { $cookie_all = unserialize(base64_decode($_COOKIE['FusionDirectory_Filter_Settings'])); - }else{ + } else { $cookie_all = unserialize(base64_decode($HTTP_COOKIE_VARS['FusionDirectory_Filter_Settings'])); } - if(isset($cookie_all[$ui->dn])){ + if (isset($cookie_all[$ui->dn])) { $cookie = $cookie_all[$ui->dn]; - $cookie_vars= array("MultiDialogFilters","CurrentMainBase","plug"); - foreach($cookie_vars as $var){ - if(isset($cookie[$var])){ - session::global_set($var,$cookie[$var]); + $cookie_vars = array("MultiDialogFilters","CurrentMainBase","plug"); + foreach ($cookie_vars as $var) { + if (isset($cookie[$var])) { + session::global_set($var, $cookie[$var]); } } - if(isset($cookie['plug'])){ - $plug =$cookie['plug']; + if (isset($cookie['plug'])) { + $plug = $cookie['plug']; } } } } /* are we using accountexpiration */ - if ($config->get_cfg_value("handleExpiredAccounts") == "TRUE"){ + if ($config->get_cfg_value("handleExpiredAccounts") == "TRUE") { $expired = $ui->expired_status(); if ($expired == POSIX_ACCOUNT_EXPIRED) { - $message= _("Account locked. Please contact your system administrator!"); + $message = _("Account locked. Please contact your system administrator!"); $smarty->assign ('nextfield', 'password'); - new log("security","login","",array(),"Account for user \"$username\" has expired") ; + new log("security", "login", "", array(), "Account for user \"$username\" has expired"); displayLogin(); exit(); } } /* Not account expired or password forced change go to main page */ - new log("security","login","",array(),"User \"$username\" logged in successfully") ; - $plist= new pluglist($config, $ui); - if(isset($plug) && isset($plist->dirlist[$plug])){ + new log("security", "login", "", array(), "User \"$username\" logged in successfully"); + $plist = new pluglist($config, $ui); + if (isset($plug) && isset($plist->dirlist[$plug])) { header ("Location: main.php?plug=".$plug."&global_check=1"); - }else{ + } else { header ("Location: main.php?global_check=1"); } exit; @@ -385,11 +386,11 @@ if (($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['login'])) || $htacces $smarty->assign ("cookies", "<b>"._("Warning").":<\/b> "._("Your browser has cookies disabled. Please enable cookies and reload this page before logging in!")); /* Set focus to the error button if we've an error message */ -$focus= ""; -if (session::is_set('errors') && session::get('errors') != ""){ - $focus= '<script language="JavaScript" type="text/javascript">'; - $focus.= 'document.forms[0].error_accept.focus();'; - $focus.= '</script>'; +$focus = ""; +if (session::is_set('errors') && session::get('errors') != "") { + $focus = '<script type="text/javascript">'; + $focus .= 'document.forms[0].error_accept.focus();'; + $focus .= '</script>'; } $smarty->assign("focus", $focus); displayLogin(); diff --git a/html/logout.php b/html/logout.php index 357dbd44fc8110eb320593ec10271edd6812dda0..fb53f8808d80691400aa66048eda2819c66905fc 100644 --- a/html/logout.php +++ b/html/logout.php @@ -1,5 +1,4 @@ <?php - /* This code is part of FusionDirectory (http://www.fusiondirectory.org/) Copyright (C) 2003-2010 Cajus Pollmeier @@ -30,33 +29,33 @@ header("Content-type: text/html; charset=UTF-8"); /* try to start session, so we can remove userlocks, if the old session is still available */ @session::start(); -session::set('errorsAlreadyPosted',array()); -if(session::global_is_set('ui')){ +session::set('errorsAlreadyPosted', array()); +if (session::global_is_set('ui')) { /* Get config & ui informations */ - $ui= session::global_get("ui"); + $ui = session::global_get("ui"); /* config used for del_user_locks & some lines below to detect the language */ - $config= session::global_get("config"); + $config = session::global_get("config"); /* Remove all locks of this user */ del_user_locks($ui->dn); /* Write something to log */ - new log("security","logout","",array(),"User \"".$ui->username."\" logged out") ; + new log("security", "logout", "", array(), "User \"".$ui->username."\" logged out"); } /* Language setup */ -if ((!isset($config)) || $config->get_cfg_value("language") == ""){ - $lang= get_browser_language(); +if ((!isset($config)) || $config->get_cfg_value("language") == "") { + $lang = get_browser_language(); } else { - $lang= $config->get_cfg_value("language"); + $lang = $config->get_cfg_value("language"); } putenv("LANGUAGE="); putenv("LANG=$lang"); setlocale(LC_ALL, $lang); -$GLOBALS['t_language']= $lang; +$GLOBALS['t_language'] = $lang; $GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/'; /* Set the text domain as 'fusiondirectory' */ @@ -65,22 +64,22 @@ bindtextdomain($domain, LOCALE_DIR); textdomain($domain); /* Set smarty template compile directory */ -if (isset($config)){ - $smarty->compile_dir= $config->get_cfg_value("templateCompileDirectory", SPOOL_DIR); +if (isset($config)) { + $smarty->compile_dir = $config->get_cfg_value("templateCompileDirectory", SPOOL_DIR); } else { - $smarty->compile_dir= SPOOL_DIR; + $smarty->compile_dir = SPOOL_DIR; } $smarty->assign("date", date("l, dS F Y H:i:s O")); /* If GET request is posted, the logout was forced by pressing the link */ -if (isset($_GET['request'])){ +if (isset($_GET['request'])) { /* destroy old session */ session::destroy (); /* If we're not using htaccess authentication, just redirect... */ - if (isset($config) && $config->get_cfg_value("htaccessAuthentication") == "TRUE"){ + if (isset($config) && $config->get_cfg_value("htaccessAuthentication") == "TRUE") { /* Else notice that the user has to close the browser... */ $smarty->assign("usePrototype", "false"); @@ -92,13 +91,12 @@ if (isset($_GET['request'])){ header ("Location: index.php"); exit(); -}else{ // The logout wasn't forced, so the session is invalid +} else { // The logout wasn't forced, so the session is invalid $smarty->assign("usePrototype", "false"); $smarty->display (get_template_path('headers.tpl')); $smarty->display (get_template_path('logout.tpl')); exit; } -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> </html> diff --git a/html/main.php b/html/main.php index a58c9f2aeac034c4dd85c0a7f7e9b91cb43b9a7a..8d8a3ed7d679ee5950dfcd97580656b600857d3d 100644 --- a/html/main.php +++ b/html/main.php @@ -38,9 +38,9 @@ textdomain($domain); /* Remember everything we did after the last click */ session::start(); -session::set('errorsAlreadyPosted',array()); -session::global_set('runtime_cache',array()); -session::set('limit_exceeded',FALSE); +session::set('errorsAlreadyPosted', array()); +session::global_set('runtime_cache', array()); +session::set('limit_exceeded', FALSE); if ($_SERVER["REQUEST_METHOD"] == "POST") { @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST"); @@ -49,7 +49,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { /* Logged in? Simple security check */ if (!session::global_is_set('config')) { - new log("security","login","",array(),"main.php called without session - logging out") ; + new log("security", "login", "", array(), "main.php called without session - logging out"); header ("Location: logout.php"); exit; } @@ -57,7 +57,7 @@ if (!session::global_is_set('config')) { /* Check for uniqe ip address */ $ui = session::global_get('ui'); if ($_SERVER['REMOTE_ADDR'] != $ui->ip) { - new log("security","login","",array(),"main.php called with session which has a changed IP address.") ; + new log("security", "login", "", array(), "main.php called with session which has a changed IP address."); header ("Location: logout.php"); exit; } @@ -73,32 +73,32 @@ timezone::get_default_timezone(); /* Check for invalid sessions */ if (session::global_get('_LAST_PAGE_REQUEST') == "") { - session::global_set('_LAST_PAGE_REQUEST',time()); + session::global_set('_LAST_PAGE_REQUEST', time()); } else { /* check FusionDirectory.conf for defined session lifetime */ - $max_life = $config->get_cfg_value("sessionLifetime", 60*60*2); + $max_life = $config->get_cfg_value("sessionLifetime", 60 * 60 * 2); /* get time difference between last page reload */ - $request_time = (time()- session::global_get('_LAST_PAGE_REQUEST')); + $request_time = (time() - session::global_get('_LAST_PAGE_REQUEST')); /* If page wasn't reloaded for more than max_life seconds * kill session */ if ($request_time > $max_life) { session::destroy(); - new log("security","login","",array(),"main.php called without session - logging out") ; + new log("security", "login", "", array(), "main.php called without session - logging out"); header ("Location: logout.php"); exit; } - session::global_set('_LAST_PAGE_REQUEST',time()); + session::global_set('_LAST_PAGE_REQUEST', time()); } @DEBUG (DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config"); /* Set template compile directory */ -$smarty->compile_dir= $config->get_cfg_value("templateCompileDirectory", SPOOL_DIR); +$smarty->compile_dir = $config->get_cfg_value("templateCompileDirectory", SPOOL_DIR); /* Set default */ $reload_navigation = FALSE; @@ -111,11 +111,11 @@ if ((!session::global_is_set('Last_init_lang')) || (session::global_get('Last_in } /* Language setup */ -session::global_set('Last_init_lang',$lang); +session::global_set('Last_init_lang', $lang); /* Preset current main base */ if (!session::global_is_set('CurrentMainBase')) { - session::global_set('CurrentMainBase',get_base_from_people($ui->dn)); + session::global_set('CurrentMainBase', get_base_from_people($ui->dn)); } putenv("LANGUAGE="); @@ -133,7 +133,7 @@ textdomain($domain); /* Prepare plugin list */ if (!session::global_is_set('plist')) { /* Initially load all classes */ - $class_list= get_declared_classes(); + $class_list = get_declared_classes(); foreach ($class_mapping as $class => $path) { if (!in_array($class, $class_list)) { if (is_readable("$BASE_DIR/$path")) { @@ -161,16 +161,16 @@ if (isset($global_check) && $config->get_cfg_value("forceglobals") == "TRUE") { _("Fatal error: Register globals is on. FusionDirectory will refuse to login unless this is fixed by an administrator."), FATAL_ERROR_DIALOG); - new log("security","login","",array(),"Register globals is on. For security reasons, this should be turned off.") ; + new log("security", "login", "", array(), "Register globals is on. For security reasons, this should be turned off."); session::destroy (); exit; } /* Check Plugin variable */ if (session::global_is_set('plugin_dir')) { - $old_plugin_dir= session::global_get('plugin_dir'); + $old_plugin_dir = session::global_get('plugin_dir'); } else { - $old_plugin_dir= ""; + $old_plugin_dir = ""; } /* reload navigation if language changed*/ @@ -182,50 +182,48 @@ $plist->gen_menu(); /* check if we are using account expiration */ $smarty->assign("hideMenus", FALSE); if ($config->get_cfg_value("handleExpiredAccounts") == "TRUE") { - $expired = $ui->expired_status(); - if ($expired == POSIX_WARN_ABOUT_EXPIRATION && !session::is_set('POSIX_WARN_ABOUT_EXPIRATION__DONE')) { - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, "This user account (".$ui->username.") is about to expire"); - - // The users password is about to xpire soon, display a warning message. - new log("security","fusiondirectory","",array(),"password for user '".$ui->username."' is about to expire") ; - msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG); - session::set('POSIX_WARN_ABOUT_EXPIRATION__DONE', TRUE); - - } elseif ($expired == POSIX_FORCE_PASSWORD_CHANGE) { - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, "This user account expired"); - - // The password is expired, we are now going to enforce a new one from the user. - - // Hide the FusionDirectory menus to avoid leaving the enforced password change dialog. - $smarty->assign("hideMenus", TRUE); - $plug = (isset($_GET['plug'])) ? $_GET['plug'] : null; - - // Search for the 'password' class and set its id as active plug. - foreach ($plist->dirlist as $key => $value) { - if (preg_match("/\bpassword\b/i",$value)) { - if($plug != $key) { - $_GET['plug'] = $key; - } - break; - } + $expired = $ui->expired_status(); + if ($expired == POSIX_WARN_ABOUT_EXPIRATION && !session::is_set('POSIX_WARN_ABOUT_EXPIRATION__DONE')) { + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, "This user account (".$ui->username.") is about to expire"); + + // The users password is about to xpire soon, display a warning message. + new log("security", "fusiondirectory", "", array(), "password for user '".$ui->username."' is about to expire"); + msg_dialog::display(_("Password change"), _("Your password is about to expire, please change your password!"), INFO_DIALOG); + session::set('POSIX_WARN_ABOUT_EXPIRATION__DONE', TRUE); + } elseif ($expired == POSIX_FORCE_PASSWORD_CHANGE) { + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, "This user account expired"); + + // The password is expired, we are now going to enforce a new one from the user. + + // Hide the FusionDirectory menus to avoid leaving the enforced password change dialog. + $smarty->assign("hideMenus", TRUE); + $plug = (isset($_GET['plug'])) ? $_GET['plug'] : NULL; + + // Search for the 'password' class and set its id as active plug. + foreach ($plist->dirlist as $key => $value) { + if (preg_match("/\bpassword\b/i", $value)) { + if ($plug != $key) { + $_GET['plug'] = $key; } + break; + } } + } } if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])) { - $plug= validate($_GET['plug']); - $plugin_dir= $plist->get_path($plug); - session::global_set('plugin_dir',$plugin_dir); + $plug = validate($_GET['plug']); + $plugin_dir = $plist->get_path($plug); + session::global_set('plugin_dir', $plugin_dir); if ($plugin_dir == "") { - new log("security","fusiondirectory","",array(),"main.php called with invalid plug parameter \"$plug\"") ; + new log("security", "fusiondirectory", "", array(), "main.php called with invalid plug parameter \"$plug\""); header ("Location: logout.php"); exit; } } else { - /* set to welcome page as default plugin */ - session::global_set('plugin_dir',"welcome"); - $plugin_dir= "$BASE_DIR/plugins/generic/welcome"; + session::global_set('plugin_dir', "welcome"); + $plugin_dir = "$BASE_DIR/plugins/generic/welcome"; } /* Handle plugin locks. @@ -233,8 +231,8 @@ if (isset($_GET['plug']) && $plist->plugin_access_allowed($_GET['plug'])) { - Remove all created locks if "reset" was posted. - Remove all created locks if we switched to another plugin. */ -$cleanup = FALSE; -$remove_lock= FALSE; +$cleanup = FALSE; +$remove_lock = FALSE; /* Check if we have changed the selected plugin */ @@ -244,11 +242,8 @@ if ($old_plugin_dir != $plugin_dir && $old_plugin_dir != "") { require ("$old_plugin_dir/main.inc"); $cleanup = $remove_lock = FALSE; } -} else // elseif - -/* Reset was posted, remove all created locks for the current plugin -*/ -if((isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['delete_lock'])) { +} elseif ((isset($_GET['reset']) && $_GET['reset'] == 1) || isset($_POST['delete_lock'])) { + /* Reset was posted, remove all created locks for the current plugin */ $remove_lock = TRUE; } @@ -269,7 +264,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { extract the number and step the correct plugin. */ foreach ($_POST as $key => $value) { if (preg_match("/^back[0-9]+$/", $key)) { - $back= substr($key, 4); + $back = substr($key, 4); header ("Location: main.php?plug=$back"); exit; } @@ -303,9 +298,9 @@ $smarty->assign ("lang", preg_replace('/_.*$/', '', $lang)); $smarty->assign ("rtl", language_is_rtl($lang)); $smarty->assign ("must", '<span class="must">*</span>'); if (isset($plug)) { - $plug= "?plug=$plug"; + $plug = "?plug=$plug"; } else { - $plug= ""; + $plug = ""; } if ($ui->ignore_acl_for_current_user()) { @@ -350,7 +345,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { /* Load plugin */ if (is_file("$plugin_dir/main.inc")) { - $display =""; + $display = ""; require ("$plugin_dir/main.inc"); } else { msg_dialog::display( @@ -364,7 +359,7 @@ if (is_file("$plugin_dir/main.inc")) { /* Print_out last ErrorMessage repeated string. */ $smarty->assign("msg_dialogs", msg_dialog::get_dialogs()); $smarty->assign("contents", $display); -$smarty->assign("sessionLifetime", $config->get_cfg_value("sessionLifetime", 60*60*2)); +$smarty->assign("sessionLifetime", $config->get_cfg_value("sessionLifetime", 60 * 60 * 2)); /* If there's some post, take a look if everything is there... */ if (isset($_POST) && count($_POST)) { @@ -382,41 +377,41 @@ if (session::is_set('errors')) { $smarty->assign("errors", session::get('errors')); } if ($error_collector != "") { - $smarty->assign("php_errors", preg_replace("/%BUGBODY%/",$error_collector_mailto,$error_collector)."</div>"); + $smarty->assign("php_errors", preg_replace("/%BUGBODY%/", $error_collector_mailto, $error_collector)."</div>"); } else { $smarty->assign("php_errors", ""); } /* Set focus to the error button if we've an error message */ -$focus= ""; +$focus = ""; if (session::is_set('errors') && session::get('errors') != "") { - $focus= '<script language="JavaScript" type="text/javascript">'; - $focus.= 'document.forms[0].error_accept.focus();'; - $focus.= '</script>'; + $focus = '<script type="text/javascript">'; + $focus .= 'document.forms[0].error_accept.focus();'; + $focus .= '</script>'; } -$focus= '<script language="JavaScript" type="text/javascript">'; -$focus.= 'next_msg_dialog();'; -$focus.= '</script>'; +$focus = '<script type="text/javascript">'; +$focus .= 'next_msg_dialog();'; +$focus .= '</script>'; $smarty->assign("focus", $focus); /* Set channel if needed */ -#TODO: * move all global session calls to global_ -# * create a new channel where needed (mostly management dialogues) -# * remove regulary created channels when not needed anymore -# * take a look at external php calls (i.e. get fax, ldif, etc.) -# * handle aborted sessions (by pressing anachors i.e. Main, Menu, etc.) -# * check lock removals, is "dn" global or not in this case? -# * last page request -> global or not? -# * check that filters are still global -# * maxC global? +//TODO: * move all global session calls to global_ +// * create a new channel where needed (mostly management dialogues) +// * remove regulary created channels when not needed anymore +// * take a look at external php calls (i.e. get fax, ldif, etc.) +// * handle aborted sessions (by pressing anachors i.e. Main, Menu, etc.) +// * check lock removals, is "dn" global or not in this case? +// * last page request -> global or not? +// * check that filters are still global +// * maxC global? if (isset($_POST['_channel_'])) { echo "DEBUG - current channel: ".$_POST['_channel_']; $smarty->assign("channel", $_POST['_channel_']); } else { $smarty->assign("channel", ""); } -$smarty->assign ("title","FusionDirectory"); +$smarty->assign ("title", "FusionDirectory"); if (class_available('Game')) { $smarty->assign('game_screen', Game::run()); @@ -424,7 +419,7 @@ if (class_available('Game')) { $smarty->assign('game_screen', ''); } -$display = $smarty->fetch(get_template_path('headers.tpl')). +$display = $smarty->fetch(get_template_path('headers.tpl')). $smarty->fetch(get_template_path('framework.tpl')); /* Save dialog filters and selected base in a cookie. @@ -434,7 +429,7 @@ $cookie = array(); if (isset($_COOKIE['FusionDirectory_Filter_Settings'])) { $cookie = unserialize(base64_decode($_COOKIE['FusionDirectory_Filter_Settings'])); -} elseif(isset($HTTP_COOKIE_VARS['FusionDirectory_Filter_Settings'])) { +} elseif (isset($HTTP_COOKIE_VARS['FusionDirectory_Filter_Settings'])) { $cookie = unserialize(base64_decode($HTTP_COOKIE_VARS['FusionDirectory_Filter_Settings'])); } @@ -449,15 +444,15 @@ if ($config->get_cfg_value("storeFilterSettings") == "TRUE") { if (isset($_GET['plug'])) { $cookie[$ui->dn]['plug'] = $_GET['plug']; } - @setcookie("FusionDirectory_Filter_Settings",base64_encode(serialize($cookie)),time() + (60*60*24)); + @setcookie("FusionDirectory_Filter_Settings", base64_encode(serialize($cookie)), time() + (60 * 60 * 24)); } /* Show page... */ echo $display; /* Save plist and config */ -session::global_set('plist',$plist); -session::global_set('config',$config); -session::set('errorsAlreadyPosted',array()); +session::global_set('plist', $plist); +session::global_set('config', $config); +session::set('errorsAlreadyPosted', array()); ?> diff --git a/html/progress.php b/html/progress.php index 6bce2b9baa6e72c98bab3d02d36f7d85eff229e1..e8a15dbcf72992eda4390f371b23e133ae82c9f6 100644 --- a/html/progress.php +++ b/html/progress.php @@ -23,53 +23,53 @@ session_cache_limiter("private"); /* Check for parameter completenes */ -if (!isset($_GET['x']) || !isset($_GET['y']) || !isset($_GET['p'])){ +if (!isset($_GET['x']) || !isset($_GET['y']) || !isset($_GET['p'])) { die ("Missing parameters!"); } -if (!is_numeric($_GET['x']) || !is_numeric($_GET['y'])){ +if (!is_numeric($_GET['x']) || !is_numeric($_GET['y'])) { die ("Parameters must be numeric!"); } -$p= (int)($_GET['p']); -$x= (int)($_GET['x']); -$y= (int)($_GET['y']); +$p = (int)($_GET['p']); +$x = (int)($_GET['x']); +$y = (int)($_GET['y']); /* Check percentage */ -if ($p < 0){ - $p= 0; -} elseif ($p > 100){ - $p= 100; +if ($p < 0) { + $p = 0; +} elseif ($p > 100) { + $p = 100; } -$p= intval ($p); +$p = intval ($p); /* Check dimensions */ -if ($x < 3 || $x > 1000){ - $x= 180; +if ($x < 3 || $x > 1000) { + $x = 180; } -if ($y < 3 || $y > 700){ - $y= 20; +if ($y < 3 || $y > 700) { + $y = 20; } -if(!function_exists("imagecreate")){ +if (!function_exists("imagecreate")) { syslog(LOG_ERR, "FusionDirectory is missing the gd library, please install php5-gd to be able to see progress images."); echo "Please install the php5-gd library, FusionDirectory can't create images without it."; exit(); -}else{ +} else { - $x_matches= FALSE; - $y_matches= FALSE; - foreach (array(7,6,5,4,3,2,1,0) as $font){ - $fx= ImageFontWidth($font) * strlen("$p%"); - $fy= ImageFontHeight($font); + $x_matches = FALSE; + $y_matches = FALSE; + foreach (array(7,6,5,4,3,2,1,0) as $font) { + $fx = ImageFontWidth($font) * strlen("$p%"); + $fy = ImageFontHeight($font); /* Look if font size matches image size */ - if ($fx < ($x-2)){ - $x_matches= TRUE; + if ($fx < ($x - 2)) { + $x_matches = TRUE; } - if ($fy < ($y-2)){ - $y_matches= TRUE; + if ($fy < ($y - 2)) { + $y_matches = TRUE; } - if ($x_matches && $y_matches){ + if ($x_matches && $y_matches) { break; } } @@ -79,18 +79,18 @@ if(!function_exists("imagecreate")){ or die ("Cannot Initialize new GD image stream"); /* Set colors */ - $bg_color= imagecolorallocate ($im, 255, 255, 255); - $br_color= imagecolorallocate ($im, 0,0,0); - $fi_color= imagecolorallocate ($im, 0,0,180); - $tx_color= imagecolorallocate ($im, 240, 10, 90); + $bg_color = imagecolorallocate($im, 255, 255, 255); + $br_color = imagecolorallocate($im, 0, 0, 0); + $fi_color = imagecolorallocate($im, 0, 0, 180); + $tx_color = imagecolorallocate($im, 240, 10, 90); /* Draw progress bar */ - imagerectangle ($im, 0, 0, $x-1, $y-1, $br_color); + imagerectangle ($im, 0, 0, $x - 1, $y - 1, $br_color); imagefilledrectangle ($im, 1, 1, (($x - 2) * $p / 100), $y - 2, $fi_color); /* Is font to big for progress bar? */ - if ($font != 0){ + if ($font != 0) { imagestring ($im, $font, ($x - $fx) / 2, ($y - $fy) / 2, "$p%", $tx_color); } diff --git a/include/class_session.inc b/include/class_session.inc index 09bdce75ad3a4e0418904b2bda8680a1a8594a1c..de67138ecb066fffbd280bd4d2fda6e3d9b061d9 100644 --- a/include/class_session.inc +++ b/include/class_session.inc @@ -1,5 +1,4 @@ <?php - /* This code is part of FusionDirectory (http://www.fusiondirectory.org/) Copyright (C) 2003-2010 Cajus Pollmeier @@ -32,12 +31,10 @@ class session { public static function get_session_size() { - } public static function get_element_size() { - } /*! @@ -48,14 +45,14 @@ class session { public static function add_channel($name) { /* If there's already such kind of channel, skip... */ - if (isset($_SESSION[$name])){ - return (FALSE); + if (isset($_SESSION[$name])) { + return FALSE; } /* Allocate it... */ - $_SESSION[$name]= array(); - $_POST["_channel_"]= $name; - return (TRUE); + $_SESSION[$name] = array(); + $_POST["_channel_"] = $name; + return TRUE; } @@ -67,15 +64,15 @@ class session { public static function remove_channel($name) { /* If there's already such kind of channel, skip... */ - if (isset($_SESSION[$name])){ + if (isset($_SESSION[$name])) { unset($_SESSION[$name]); - if (isset($_POST["_channel_"])){ + if (isset($_POST["_channel_"])) { unset($_POST["_channel_"]); } - return (TRUE); + return TRUE; } - return (FALSE); + return FALSE; } /*! @@ -85,23 +82,23 @@ class session { */ public static function is_set($name) { - $channel= ""; - if (isset($_POST['_channel_'])){ - $channel= $_POST['_channel_']; + $channel = ""; + if (isset($_POST['_channel_'])) { + $channel = $_POST['_channel_']; } /* Global fallback if not set */ - if ($channel == ""){ - return(isset($_SESSION[$name])); + if ($channel == "") { + return isset($_SESSION[$name]); } /* Sanity check */ - if (!session::channel_exists($channel)){ + if (!session::channel_exists($channel)) { msg_dialog::display(_("Internal error"), _("Requested channel does not exist! Please contact your Administrator."), FATAL_ERROR_DIALOG); } - $channel= "gch_".$channel; - return(isset($_SESSION[$channel][$name])); + $channel = "gch_".$channel; + return isset($_SESSION[$channel][$name]); } /*! @@ -111,7 +108,7 @@ class session { */ public static function global_is_set($name) { - return(isset($_SESSION[$name])); + return isset($_SESSION[$name]); } /*! @@ -121,19 +118,19 @@ class session { * * \param $value The new value */ - public static function set($name,$value) + public static function set($name, $value) { - $channel= ""; - if (isset($_POST['_channel_'])){ - $channel= $_POST['_channel_']; + $channel = ""; + if (isset($_POST['_channel_'])) { + $channel = $_POST['_channel_']; } /* Global fallback if not set */ - if ($channel == ""){ + if ($channel == "") { $_SESSION[$name] = $value; } else { /* Sanity check */ - if (!session::channel_exists($channel)){ + if (!session::channel_exists($channel)) { msg_dialog::display(_("Internal error"), _("Requested channel does not exist! Please contact your Administrator."), FATAL_ERROR_DIALOG); } $_SESSION[$channel][$name] = $value; @@ -147,7 +144,7 @@ class session { * * \param $value The new value */ - public static function global_set($name,$value) + public static function global_set($name, $value) { $_SESSION[$name] = $value; } @@ -159,25 +156,25 @@ class session { */ public static function &get($name) { - $channel= ""; - if (isset($_POST['_channel_'])){ - $channel= $_POST['_channel_']; + $channel = ""; + if (isset($_POST['_channel_'])) { + $channel = $_POST['_channel_']; } /* Global fallback if not set */ - if ($channel == ""){ + if ($channel == "") { $ret = &$_SESSION[$name]; - return($ret); + return $ret; } /* Sanity check */ - if (!session::channel_exists($channel)){ + if (!session::channel_exists($channel)) { msg_dialog::display(_("Internal error"), _("Requested channel does not exist! Please contact your Administrator."), FATAL_ERROR_DIALOG); } - $channel= "gch_".$channel; - $ret = &$_SESSION[$channel][$name]; - return($ret); + $channel = "gch_".$channel; + $ret = &$_SESSION[$channel][$name]; + return $ret; } /*! @@ -188,7 +185,7 @@ class session { public static function &global_get($name) { $ret = &$_SESSION[$name]; - return($ret); + return $ret; } /*! @@ -198,18 +195,18 @@ class session { */ public static function delete($name) { - $channel= ""; - if (isset($_POST['_channel_'])){ - $channel= $_POST['_channel_']; + $channel = ""; + if (isset($_POST['_channel_'])) { + $channel = $_POST['_channel_']; } /* Global fallback if not set */ - if ($channel == ""){ - if(isset($_SESSION[$name])){ + if ($channel == "") { + if (isset($_SESSION[$name])) { unset($_SESSION[$name]); } } else { - if(isset($_SESSION[$channel][$name])){ + if (isset($_SESSION[$channel][$name])) { unset($_SESSION[$channel][$name]); } } @@ -222,7 +219,7 @@ class session { */ public static function global_delete($name) { - if($_SESSION[$name]){ + if ($_SESSION[$name]) { unset($_SESSION[$name]); } } @@ -234,7 +231,7 @@ class session { */ public static function un_set($name) { - return(session::delete($name)); + return session::delete($name); } /*! @@ -244,7 +241,7 @@ class session { */ public static function global_un_set($name) { - return(session::global_delete($name)); + return session::global_delete($name); } /*! @@ -254,21 +251,22 @@ class session { { session_name("FusionDirectory"); /* Set cookie lifetime to one day (The parameter is in seconds ) */ - session_set_cookie_params(24*60*60); + session_set_cookie_params(24 * 60 * 60); /* Set cache limter to one day (parameter is minute !!)*/ - session_cache_expire(60*24); // default is 180 + session_cache_expire(60 * 24); // default is 180 /* Set session max lifetime, to prevent the garbage collector to delete session before timeout. !! The garbage collector is a cron job on debian systems, the cronjob will fetch the timeout from the php.ini, so if you use debian, you must hardcode session.gc_maxlifetime in your php.ini */ - ini_set("session.gc_maxlifetime",24*60*60); + + ini_set("session.gc_maxlifetime", 24 * 60 * 60); + session_name("FusionDirectory"); session_start(); /* Check for changed browsers and bail out */ - if (isset($_SESSION['HTTP_USER_AGENT'])) - { - if ($_SESSION['HTTP_USER_AGENT'] != md5($_SERVER['HTTP_USER_AGENT'])) { + if (isset($_SESSION['HTTP_USER_AGENT'])) { + if ($_SESSION['HTTP_USER_AGENT'] != md5($_SERVER['HTTP_USER_AGENT'])) { session_destroy(); session_name("FusionDirectory"); session_start(); @@ -278,9 +276,9 @@ class session { } /* Regenerate ID to increase security */ - if (!isset($_SESSION['started'])){ + if (!isset($_SESSION['started'])) { session_regenerate_id(); - $_SESSION['started'] = true; + $_SESSION['started'] = TRUE; } } @@ -304,9 +302,8 @@ class session { public static function &get_all() { $ret = &$_SESSION; - return($ret); + return $ret; } } -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/include/class_tests.inc b/include/class_tests.inc index 1505c977ce4aac9164d9cb7514faa4ccc0c09443..4e4402f65894691d9a0de060b3d3004a9b0781c9 100644 --- a/include/class_tests.inc +++ b/include/class_tests.inc @@ -1,5 +1,4 @@ <?php - /* This code is part of FusionDirectory (http://www.fusiondirectory.org/) Copyright (C) 2003-2010 Cajus Pollmeier @@ -48,8 +47,8 @@ class tests { */ public static function is_phone_nr($nr) { - if ($nr == ""){ - return (TRUE); + if ($nr == "") { + return TRUE; } return preg_match ("/^[\/0-9 ()+*-]+$/", $nr); @@ -63,7 +62,7 @@ class tests { */ public static function is_dns_name($str) { - return(preg_match("/^[a-z0-9\.\-_]*$/i",$str)); + return preg_match("/^[a-z0-9\.\-_]*$/i", $str); } @@ -74,7 +73,7 @@ class tests { */ public static function is_valid_hostname($str) { - return(preg_match("/^[a-z0-9\.\-]*$/i",$str)); + return preg_match("/^[a-z0-9\.\-]*$/i", $str); } @@ -101,8 +100,8 @@ class tests { */ public static function is_dn($dn) { - if ($dn == ""){ - return (TRUE); + if ($dn == "") { + return TRUE; } return preg_match ("/^[a-z0-9 _-]+$/i", $dn); @@ -116,13 +115,13 @@ class tests { */ public static function is_uid($uid) { - if ($uid == ""){ - return (TRUE); + if ($uid == "") { + return TRUE; } /* STRICT adds spaces and case insenstivity to the uid check. This is dangerous and should not be used. */ - if (strict_uid_mode()){ + if (strict_uid_mode()) { return preg_match ("/^[a-z0-9_-]+$/", $uid); } else { return preg_match ("/^[a-z0-9 _.-]+$/i", $uid); @@ -137,7 +136,7 @@ class tests { */ public static function is_ip($ip) { - if(function_exists('filter_var')) { + if (function_exists('filter_var')) { return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } else { return preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/", $ip); @@ -151,11 +150,11 @@ class tests { */ public static function is_ipv6($ip) { - if(function_exists('filter_var')) { + if (function_exists('filter_var')) { return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); } else { $ipv4 = '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'; - $g = '([0-9a-f]{1,4})'; //IPv6 group + $g = '([0-9a-f]{1,4})'; //IPv6 group return preg_match("/^$g:$g:$g:$g:$g:$g:$g:$g$/", $ip) || preg_match("/^$g:$g:$g:$g:$g:$g:$ipv4$/", $ip); } @@ -181,40 +180,40 @@ class tests { */ public static function is_ip_with_subnetmask($ip) { - /* Generate list of valid submasks */ - $res = array(); - for($e = 0 ; $e <= 32; $e++){ - $res[$e] = $e; - } - $i[0] =255; - $i[1] =255; - $i[2] =255; - $i[3] =255; - for($a= 3 ; $a >= 0 ; $a --){ - $c = 1; - while($i[$a] > 0 ){ - $str = $i[0].".".$i[1].".".$i[2].".".$i[3]; - $res[$str] = $str; - $i[$a] -=$c; - $c = 2*$c; - } - } - $res["0.0.0.0"] = "0.0.0.0"; - if(preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". - "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". - "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". - "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)){ - $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". - "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". - "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". - "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/","",$ip); - - $mask = preg_replace("/^\//","",$mask); - if((in_array("$mask",$res)) && preg_match("/^[0-9\.]/",$mask)){ - return(TRUE); - } - } - return(FALSE); + /* Generate list of valid submasks */ + $res = array(); + for ($e = 0; $e <= 32; $e++) { + $res[$e] = $e; + } + $i[0] = 255; + $i[1] = 255; + $i[2] = 255; + $i[3] = 255; + for ($a = 3; $a >= 0; $a--) { + $c = 1; + while ($i[$a] > 0) { + $str = $i[0].".".$i[1].".".$i[2].".".$i[3]; + $res[$str] = $str; + $i[$a] -= $c; + $c = 2 * $c; + } + } + $res["0.0.0.0"] = "0.0.0.0"; + if (preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ip)) { + $mask = preg_replace("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.". + "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", "", $ip); + + $mask = preg_replace("/^\//", "", $mask); + if ((in_array("$mask", $res)) && preg_match("/^[0-9\.]/", $mask)) { + return TRUE; + } + } + return FALSE; } @@ -227,7 +226,7 @@ class tests { */ public static function is_domain($str) { - return(preg_match("/^(([a-z0-9\-]{2,63})\.)*[a-z]{2,63}$/i",$str)); + return preg_match("/^(([a-z0-9\-]{2,63})\.)*[a-z]{2,63}$/i", $str); } @@ -238,8 +237,8 @@ class tests { */ public static function is_id($id) { - if ($id == ""){ - return (FALSE); + if ($id == "") { + return FALSE; } return preg_match ("/^[0-9]+$/", $id); @@ -253,11 +252,11 @@ class tests { */ public static function is_path($path) { - if ($path == ""){ - return (TRUE); + if ($path == "") { + return TRUE; } - if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)){ - return (FALSE); + if (!preg_match('/^[a-z0-9%\/_.+-]+$/i', $path)) { + return FALSE; } return preg_match ("/\/.+$/", $path); @@ -293,25 +292,25 @@ class tests { * * \param string $base */ - public static function is_department_name_reserved($name,$base) + public static function is_department_name_reserved($name, $base) { $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook", - preg_replace("/ou=(.*),/","\\1",get_people_ou()), - preg_replace("/ou=(.*),/","\\1",get_groups_ou())); + preg_replace("/ou=(.*),/", "\\1", get_people_ou()), + preg_replace("/ou=(.*),/", "\\1", get_groups_ou())); $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disk","packages","variables","profiles"); /* Check if name is one of the reserved names */ - if(in_array_ics($name,$reservedName)) { - return(true); + if (in_array_ics($name, $reservedName)) { + return TRUE; } /* Check all follow combinations if name is in array && parent base == array_key, return false*/ - foreach($follwedNames as $key => $names){ - if((in_array_ics($name,$names)) && (preg_match($key,$base))){ - return(true); + foreach ($follwedNames as $key => $names) { + if ((in_array_ics($name, $names)) && (preg_match($key, $base))) { + return TRUE; } } - return(false); + return FALSE; } @@ -324,17 +323,17 @@ class tests { * * \return TRUE in case of a valid range, FALSE in case of an error. */ - public static function is_ip_range($ip1,$ip2) + public static function is_ip_range($ip1, $ip2) { - if(!tests::is_ip($ip1) || !tests::is_ip($ip2)){ - return(FALSE); - }else{ - $ar1 = explode(".",$ip1); + if (!tests::is_ip($ip1) || !tests::is_ip($ip2)) { + return FALSE; + } else { + $ar1 = explode(".", $ip1); $var1 = $ar1[0] * (16777216) + $ar1[1] * (65536) + $ar1[2] * (256) + $ar1[3]; - $ar2 = explode(".",$ip2); + $ar2 = explode(".", $ip2); $var2 = $ar2[0] * (16777216) + $ar2[1] * (65536) + $ar2[2] * (256) + $ar2[3]; - return($var1 < $var2); + return ($var1 < $var2); } } @@ -350,22 +349,22 @@ class tests { */ public static function is_in_network($network, $netmask, $address) { - $nw= explode('.', $network); - $nm= explode('.', $netmask); - $ad= explode('.', $address); + $nw = explode('.', $network); + $nm = explode('.', $netmask); + $ad = explode('.', $address); /* Generate inverted netmask */ - for ($i= 0; $i<4; $i++){ - $ni[$i]= 255-$nm[$i]; - $la[$i]= $nw[$i] | $ni[$i]; + for ($i = 0; $i < 4; $i++) { + $ni[$i] = 255 - $nm[$i]; + $la[$i] = $nw[$i] | $ni[$i]; } /* Transform to integer */ - $first= $nw[0] * (16777216) + $nw[1] * (65536) + $nw[2] * (256) + $nw[3]; - $curr= $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3]; - $last= $la[0] * (16777216) + $la[1] * (65536) + $la[2] * (256) + $la[3]; + $first = $nw[0] * (16777216) + $nw[1] * (65536) + $nw[2] * (256) + $nw[3]; + $curr = $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3]; + $last = $la[0] * (16777216) + $la[1] * (65536) + $la[2] * (256) + $la[3]; - return ($first < $curr&& $last > $curr); + return ($first < $curr && $last > $curr); } /* @@ -377,16 +376,16 @@ class tests { { global $lang; - if ($date == ""){ - return (TRUE); + if ($date == "") { + return TRUE; } - #TODO: use $lang to check date format + //TODO: use $lang to check date format if (!preg_match("/([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})/", $date, $matches)) { - return false; + return FALSE; } - return checkdate($matches[2],$matches[1],$matches[3]); + return checkdate($matches[2], $matches[1], $matches[3]); } /* \brief Check if the specified IP address $address is inside the given network */ @@ -397,13 +396,12 @@ class tests { $ad = explode('.', $address); /* Transform to integer */ - $from= $from[0] * (16777216) + $from[1] * (65536) + $from[2] * (256) + $from[3]; - $to= $to[0] * (16777216) + $to[1] * (65536) + $to[2] * (256) + $to[3]; - $ad= $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3]; + $from = $from[0] * (16777216) + $from[1] * (65536) + $from[2] * (256) + $from[3]; + $to = $to[0] * (16777216) + $to[1] * (65536) + $to[2] * (256) + $to[3]; + $ad = $ad[0] * (16777216) + $ad[1] * (65536) + $ad[2] * (256) + $ad[3]; return ($ad >= $from && $ad <= $to); } } -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/include/functions.inc b/include/functions.inc index 2f0b79e7b06c83db733673afc1f331948d3560a4..fac00d18187df74677911fa1fc9cd1f448637e56 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -988,7 +988,7 @@ function get_sub_list($filter, $category, $sub_deps, $base = "", $attributes = a $sub_deps = array($sub_deps); } - /* Remove ,.*$ ("ou=1,ou=2.." => "ou=1") */ + /* Remove ,.*$ : "ou=1,ou=2.." => "ou=1" */ $sub_bases = array(); foreach ($sub_deps as $key => $sub_base) { if (empty($sub_base)) { @@ -2718,7 +2718,7 @@ function check_schema($cfg, $rfc2307bis = FALSE) "STATUS" => FALSE, "IS_MUST_HAVE" => FALSE, "MSG" => "", - "INFO" => ""); // "There is currently no information specified for this schema extension."; + "INFO" => ""); // There is currently no information specified for this schema extension.; /* The FusionDirectory base schema */ $checks['gosaObject'] = $def_check; @@ -3184,7 +3184,6 @@ function add_objectClass($classes, &$attrs) function remove_objectClass($classes, &$attrs) { if (isset($attrs['objectClass'])) { - /* Array? */ if (is_array($classes)) { $list = $classes; } else { @@ -3352,7 +3351,7 @@ function cred_decrypt($input, $password) $data = ''; $d = ''; - while (strlen($data) < $key_len+$iv_len) { + while (strlen($data) < $key_len + $iv_len) { $d = md5($d . $password . $salt, TRUE); $data .= $d; }