From d45a41dbd7e2fa452ac010353243becd4ea87694 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 14 Jan 2009 15:15:49 +0000 Subject: [PATCH] Updated samba Tab -Added info for domain policies git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@13352 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/personal/samba/class_sambaAccount.inc | 305 ++++++++++++++++++ plugins/personal/samba/samba3.tpl | 61 ++-- 2 files changed, 337 insertions(+), 29 deletions(-) diff --git a/plugins/personal/samba/class_sambaAccount.inc b/plugins/personal/samba/class_sambaAccount.inc index e596081a2..99cbeabe3 100644 --- a/plugins/personal/samba/class_sambaAccount.inc +++ b/plugins/personal/samba/class_sambaAccount.inc @@ -72,6 +72,8 @@ class sambaAccount extends plugin var $mungedObject; /* Helper */ + var $cache = array(); + var $display_information = FALSE; var $dialog; var $show_ws_dialog= FALSE; var $logon_time_set= 0; @@ -641,6 +643,44 @@ class sambaAccount extends plugin } } + /* Create additional info for sambaKickOffTime and sambaPwdMustChange. + e.g. Display effective kickoff time. Domain policy + user settings. + */ + $additional_info_PwdMustChange = ""; + + /* Calculate effective max Password Age + This can only be calculated if sambaPwdLastSet ist set. + */ + if(isset($this->attrs['sambaPwdLastSet'][0])){ + $last = $this->attrs['sambaPwdLastSet'][0]; + + $sid = $this->get_domain_info(); + if(isset($sid['sambaMaxPwdAge'][0])){ + $d = ($last + $sid['sambaMaxPwdAge'][0]) - time(); + + /* A negative value means the password is outdated + */ + if($d < 0){ + $additional_info_PwdMustChange = sprintf(_("The password is outdated since %s, by domain policy."), + date("d.m.Y H:i:s",$last + $sid['sambaMaxPwdAge'][0])); + }else{ + if($this->password_expires && ($last + $sid['sambaMaxPwdAge'][0]) > $this->sambaPwdMustChange){ + $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by user policy."), + date("d.m.Y H:i:s", $this->sambaPwdMustChange)); + }else{ + $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by domain policy."), + date("d.m.Y H:i:s", ($last + $sid['sambaMaxPwdAge'][0]))); + } + } + } + } + $smarty->assign("additional_info_PwdMustChange",$additional_info_PwdMustChange); + $smarty->assign("samba_information",""); + $smarty->assign("display_information",$this->display_information); + if($this->display_information){ + $smarty->assign("samba_information",$this->get_samba_information()); + } + /* Show main page */ if ($this->samba3){ $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__))); @@ -756,6 +796,10 @@ class sambaAccount extends plugin if (isset($_POST['sambaTab'])){ plugin::save_object(); + if(isset($_POST['display_information'])){ + $this->display_information = !$this->display_information; + } + /* Take care about access options */ if (chkacl ($this->acl, "acctFlags") == ""){ if ($this->samba3){ @@ -1136,6 +1180,267 @@ class sambaAccount extends plugin } } + + /*! \brief Returns the samba Domain object, selected in the samba tab. + */ + function get_domain_info() + { + /* Only search once, return last result if available + */ + if(!isset($this->cache['DOMAIN'][$this->sambaDomainName])){ + $this->cache['DOMAIN'][$this->sambaDomainName] = array(); + if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){ + $cfg = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]; + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=sambaDomain)(sambaSID=".$cfg['SID']."))",array("*")); + if($ldap->count()){ + $this->cache['DOMAIN'][$this->sambaDomainName] = $ldap->fetch(); + } + } + } + return($this->cache['DOMAIN'][$this->sambaDomainName]); + } + + + + function get_samba_information() + { + + /* Defaults + */ + $sambaMinPwdLength = "unset"; + $sambaPwdHistoryLength = "unset"; + $sambaLogonToChgPwd = "unset"; + $sambaMaxPwdAge = "unset"; + $sambaMinPwdAge = "unset"; + $sambaLockoutDuration = "unset"; + $sambaLockoutThreshold = "unset"; + $sambaForceLogoff = "unset"; + $sambaRefuseMachinePwdChange = "unset"; + $sambaPwdLastSet = "unset"; + $sambaLogonTime = "unset"; + $sambaLogoffTime = "unset"; + + $sambaKickoffTime = "unset"; + $sambaPwdCanChange = "unset"; + $sambaPwdMustChange = "unset"; + $sambaBadPasswordCount = "unset"; + $sambaBadPasswordTime = "unset"; + + /* Domain attributes + */ + $domain_attributes = array("sambaMinPwdLength","sambaPwdHistoryLength","sambaMaxPwdAge", + "sambaMinPwdAge","sambaLockoutDuration","sambaRefuseMachinePwdChange", + "sambaLogonToChgPwd","sambaLockoutThreshold","sambaForceLogoff"); + + /* User attributes + */ + $user_attributes = array("sambaBadPasswordTime","sambaPwdLastSet","sambaLogonTime","sambaLogoffTime", + "sambaKickoffTime","sambaPwdCanChange","sambaPwdMustChange","sambaBadPasswordCount"); + + /* Get samba SID object and parse settings. + */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){ + $attrs = $this->get_domain_info(); + foreach($domain_attributes as $attr){ + if(isset($attrs[$attr])){ + $$attr = $attrs[$attr][0]; + } + } + } + /* Get user infos + */ + foreach($user_attributes as $attr){ + if(isset($this->attrs[$attr])){ + $$attr = $this->attrs[$attr][0]; + } + } + if($this->password_expires){ + $sambaPwdMustChange = $this->sambaPwdMustChange; + } + if($this->kickoff_time_set){ + $sambaKickoffTime = $this->sambaKickoffTime; + } + $sambaPwdCanChange = $this->sambaPwdCanChange; + + + /* DOMAIN Attributes + */ + + /* sambaMinPwdLength: Password length has a default of 5 + */ + if($sambaMinPwdLength == "unset" || $sambaMinPwdLength == 5){ + $sambaMinPwdLength = "5 ("._("default").")"; + } + + /* sambaPwdHistoryLength: Length of Password History Entries (default: 0 => off) + */ + if($sambaPwdHistoryLength == "unset" || $sambaPwdHistoryLength == 0){ + $sambaPwdHistoryLength = _("Off")." ("._("default").")"; + } + + /* sambaLogonToChgPwd: Force Users to logon for password change (default: 0 => off, 2 => on) + */ + if($sambaLogonToChgPwd == "unset" || $sambaLogonToChgPwd == 0){ + $sambaLogonToChgPwd = _("Off")." ("._("default").")"; + }else{ + $sambaLogonToChgPwd = _("On"); + } + + /* sambaMaxPwdAge: Maximum password age, in seconds (default: -1 => never expire passwords)' + */ + if($sambaMaxPwdAge == "unset" || $sambaMaxPwdAge == "-1"){ + $sambaMaxPwdAge = _("disabled")." ("._("default").")"; + }else{ + $sambaMaxPwdAge .= " "._("seconds"); + } + /* sambaMinPwdAge: Minimum password age, in seconds (default: 0 => allow immediate password change + */ + if($sambaMinPwdAge == "unset" || $sambaMinPwdAge == 0){ + $sambaMinPwdAge = _("disabled")." ("._("default").")"; + }else{ + $sambaMinPwdAge .= " "._("seconds"); + } + + /* sambaLockoutDuration: Lockout duration in minutes (default: 30, -1 => forever) + */ + if($sambaLockoutDuration == "unset" || $sambaLockoutDuration == 30){ + $sambaLockoutDuration = "30 "._("minutes")." ("._("default").")"; + }elseif($sambaLockoutDuration == -1){ + $sambaLockoutDuration = _("forever"); + }else{ + $sambaLockoutDuration .= " "._("minutes"); + } + + /* sambaLockoutThreshold: Lockout users after bad logon attempts (default: 0 => off + */ + if($sambaLockoutThreshold == "unset" || $sambaLockoutThreshold == 0){ + $sambaLockoutThreshold = _("disabled")." ("._("default").")"; + } + + /* sambaForceLogoff: Disconnect Users outside logon hours (default: -1 => off, 0 => on + */ + if($sambaForceLogoff == "unset" || $sambaForceLogoff == -1){ + $sambaForceLogoff = _("off")." ("._("default").")"; + }else{ + $sambaForceLogoff = _("on"); + } + + /* sambaRefuseMachinePwdChange: Allow Machine Password changes (default: 0 => off + */ + if($sambaRefuseMachinePwdChange == "none" || $sambaRefuseMachinePwdChange == 0){ + $sambaRefuseMachinePwdChange = _("off")." ("._("default").")"; + }else{ + $sambaRefuseMachinePwdChange = _("on"); + } + + /* USER Attributes + */ + /* sambaBadPasswordTime: Time of the last bad password attempt + */ + if($sambaBadPasswordTime == "unset" || empty($sambaBadPasswordTime)){ + $sambaBadPasswordTime = "("._("unset").")"; + }else{ + $sambaBadPasswordTime = date("d.m.Y H:i:s",$sambaBadPasswordTime); + } + + /* sambaBadPasswordCount: Bad password attempt count + */ + if($sambaBadPasswordCount == "unset" || empty($sambaBadPasswordCount)){ + $sambaBadPasswordCount = "("._("unset").")"; + }else{ + $sambaBadPasswordCount = date("d.m.Y H:i:s",$sambaBadPasswordCount); + } + + /* sambaPwdLastSet: Timestamp of the last password update + */ + if($sambaPwdLastSet == "unset" || empty($sambaPwdLastSet)){ + $sambaPwdLastSet = "("._("unset").")"; + }else{ + $sambaPwdLastSet = date("d.m.Y H:i:s",$sambaPwdLastSet); + } + + /* sambaLogonTime: Timestamp of last logon + */ + if($sambaLogonTime == "unset" || empty($sambaLogonTime)){ + $sambaLogonTime = "("._("unset").")"; + }else{ + $sambaLogonTime = date("d.m.Y H:i:s",$sambaLogonTime); + } + + /* sambaLogoffTime: Timestamp of last logoff + */ + if($sambaLogoffTime == "unset" || empty($sambaLogoffTime)){ + $sambaLogoffTime = "("._("unset").")"; + }else{ + $sambaLogoffTime = date("d.m.Y H:i:s",$sambaLogoffTime); + } + + /* sambaKickoffTime: Timestamp of when the user will be logged off automatically + */ + if($sambaKickoffTime == "unset" || empty($sambaKickoffTime)){ + $sambaKickoffTime = "("._("unset").")"; + }else{ + $sambaKickoffTime = date("d.m.Y H:i:s",$sambaKickoffTime); + } + + /* sambaPwdMustChange: Timestamp of when the password will expire + */ + if($sambaPwdMustChange == "unset" || empty($sambaPwdMustChange)){ + $sambaPwdMustChange = "("._("unset").")"; + }else{ + $sambaPwdMustChange = date("d.m.Y H:i:s",$sambaPwdMustChange); + } + + + /* sambaPwdCanChange: Timestamp of when the user is allowed to update the password + */ + if($sambaPwdCanChange == "unset" || empty($sambaPwdCanChange)){ + $sambaPwdCanChange = "("._("unset").")"; + }elseif($sambaPwdCanChange != "unset" && time() > $sambaPwdCanChange){ + $sambaPwdCanChange = _("immediately") ; + }else{ + $days = floor((($sambaPwdCanChange - time()) / 60 / 60 / 24)) ; + $hours = floor((($sambaPwdCanChange - time()) / 60 / 60) % 24) ; + $minutes = floor((($sambaPwdCanChange - time()) / 60 ) % 60) ; + + $sambaPwdCanChange = " ".$days." "._("days"); + $sambaPwdCanChange.= " ".$hours." "._("hours"); + $sambaPwdCanChange.= " ".$minutes." "._("minutes"); + } + + $str = + "\n
". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n
"._("Domain attributes")."
"._("Min password length").": ".$sambaMinPwdLength."
"._("Min password length").": ".$sambaMinPwdLength."
"._("Password history").": ".$sambaPwdHistoryLength."
"._("Force password change").": ".$sambaLogonToChgPwd."
"._("Maximum password age").": ".$sambaMaxPwdAge."
"._("Minimum password age").": ".$sambaMinPwdAge."
"._("Lockout duration").": ".$sambaLockoutDuration."
"._("Bad lockout attempt").": ".$sambaLockoutThreshold."
"._("Disconnect time").": ".$sambaForceLogoff."
"._("Refuse machine password change").":".$sambaRefuseMachinePwdChange."
". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n
"._("User attributes")."
"._("Last failed login").": ".$sambaBadPasswordTime."
"._("Logon attempts").": ".$sambaBadPasswordCount."
"._("Last password update").": ".$sambaPwdLastSet."
"._("Last logon").": ".$sambaLogonTime."
"._("Last logoff").": ".$sambaLogoffTime."
"._("Automatic logoff").": ".$sambaKickoffTime."
"._("Password expires").": ".$sambaPwdMustChange."
"._("Password change available").": ".$sambaPwdCanChange."
"; + return($str); + } + + function PrepareForCopyPaste($source) { plugin::PrepareForCopyPaste($source); diff --git a/plugins/personal/samba/samba3.tpl b/plugins/personal/samba/samba3.tpl index 2bfcf2093..c4f5d2ec1 100644 --- a/plugins/personal/samba/samba3.tpl +++ b/plugins/personal/samba/samba3.tpl @@ -21,7 +21,8 @@ - {html_options values=$domains output=$domains selected=$sambaDomainName} @@ -52,6 +53,27 @@

 

+

  {t}Information{/t}

+ + + + + {if $display_information} + + + + {/if} +
{t}Show information{/t} + {if $display_information} + + {else} + + {/if} +
+ {$samba_information} +
+

 

+

 {t}Terminal Server{/t}

@@ -263,41 +285,22 @@
- + - {html_options values=$days output=$days selected=$day} - {html_options options=$months selected=$month} - {html_options values=$years output=$years selected=$year} -
- - - - - -
- - - - - + {if $additional_info_PwdMustChange} +
({$additional_info_PwdMustChange}) + {/if} +
-- 2.30.2