From: hickert Date: Tue, 23 Jan 2007 10:14:43 +0000 (+0000) Subject: Added samba logon hours X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0bea8e34e037c3c4fb338c83b35114a7a039f125;p=gosa.git Added samba logon hours git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5591 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/html/include/focus.js b/html/include/focus.js index 4a112e0fb..3b86afac8 100644 --- a/html/include/focus.js +++ b/html/include/focus.js @@ -15,6 +15,18 @@ for (iln = 0; iln < len; iln++){ netscape= (ver.charAt(iln+1).toUpperCase() != "C"); +/* Toggle checkbox that matches regex */ +function chk_set_all(regex,value) +{ + for (var i = 0; i < document.mainform.elements.length; i++) { + var _id=document.mainform.elements[i].id; + if(_id.match(regex)) { + document.getElementById(_id).checked= value; + } + } +} + + function scrollDown() { document.body.scrollTop = document.body.scrollHeight - document.body.clientHeight; timeout= setTimeout("scrollDown()", 500); diff --git a/plugins/personal/samba/class_sambaAccount.inc b/plugins/personal/samba/class_sambaAccount.inc index d48d8821e..87712a963 100644 --- a/plugins/personal/samba/class_sambaAccount.inc +++ b/plugins/personal/samba/class_sambaAccount.inc @@ -88,7 +88,7 @@ class sambaAccount extends plugin var $objectclasses= array(); var $uid= ""; - + var $dialog = NULL; var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName"); function sambaAccount ($config, $dn= NULL) @@ -234,6 +234,32 @@ class sambaAccount extends plugin $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']); + /* Open Samaba Logong hours dialog */ + if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){ + $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours); + } + + /* Cancel dialog */ + if(isset($_POST['cancel_logonHours'])){ + $this->dialog = NULL; + } + + /* Save selected logon hours */ + if(isset($_POST['save_logonHours'])){ + $this->dialog->save_object(); + if($this->acl_is_writeable("sambaLogonHours")){ + $this->sambaLogonHours = $this->dialog->save(); + } + $this->dialog = NULL; + } + + /* Display dialog */ + if((isset($this->dialog)) && (is_object($this->dialog))){ + $this->dialog->save_object(); + return($this->dialog->execute()); + } + + /* Prepare templating */ $smarty= get_smarty(); @@ -1062,6 +1088,7 @@ class sambaAccount extends plugin "sambaLogonTime" => _("Limit Logon Time") , "sambaLogoffTime" => _("Limit Logoff Time") , + "sambaLogonHours" => _("Logon hours") , "sambaHomePath" => _("Generic home directory") , "sambaHomeDrive" => _("Generic samba home drive") , diff --git a/plugins/personal/samba/class_sambaLogonHours.inc b/plugins/personal/samba/class_sambaLogonHours.inc new file mode 100644 index 000000000..df8bf51ce --- /dev/null +++ b/plugins/personal/samba/class_sambaLogonHours.inc @@ -0,0 +1,148 @@ +sambaLogonHours = $slh; + + /* Get Timezone to be able to shift to the correct beginning */ + if(isset($this->config->current['TIMEZONE'])){ + $this->timezone = $this->config->current['TIMEZONE']; + } + + /* Convert to bin */ + $tmp = ''; + for($i = 0 ; $i < strlen($slh) ; $i ++){ + $tmp .= str_pad(base_convert($slh[$i],16,2),4,'0',STR_PAD_LEFT); + } + $slh = $tmp; + + /* Set to default if value is empty or seams to be broken */ + if(strlen($slh) != 168){ + $slh = str_pad('',168 , "1"); + } + + /* Rework string, because it was stored in little endian */ + $new = ''; + for($i = 0 ; $i < 21 ; $i ++ ){ + $part = strrev(substr($slh, $i * 8, 8)); + $byte['hi'] = substr($part,0,4); + $byte['low'] = substr($part,4,4); + $new .= $byte['hi'].$byte['low']; + } + + /* Shift string to match given timezone settings */ + $shift_by = (168 + $this->timezone) % 168; + for($i = 0 ; $i < $shift_by; $i ++){ + $new = $new[167].$new; + $new = substr($new,0,168); + } + + /* Create matrix */ + $this->Matrix = array(); + for($day = 0 ; $day < 7 ; $day ++ ){ + for($hour = 0 ; $hour < 24 ; $hour ++){ + $bitpos = ($day * 24 + $hour) % 168; + $this->Matrix[$day][$hour] = $new[$bitpos]; + } + } + } + + function execute() + { + $week_days = array(); + $week_days[0]= _("Sunday"); + $week_days[1]= _("Monday"); + $week_days[2]= _("Tuesday"); + $week_days[3]= _("Wednesday"); + $week_days[4]= _("Thursday"); + $week_days[5]= _("Friday"); + $week_days[6]= _("Saturday"); + + $hours = array(); + for($i = 0 ; $i <24 ; $i++ ){ + $hours[$i] = $i ; + } + $ui =get_userinfo(); + + $smarty = get_smarty(); + $smarty->assign("sambaLogonHoursACL",$ui->get_permissions($this->acl_base,"user/generic","sambaLogonHours")); + $smarty->assign("Matrix",$this->Matrix); + $smarty->assign("Days" ,$week_days); + $smarty->assign("Hours" ,$hours); + return($smarty->fetch(get_template_path("sambaLogonHours.tpl",TRUE,dirname(__FILE__)))); + } + + function save_object() + { + /* Get userinfo */ + $ui = get_userinfo(); + + /* Check if dialog was opened and if there were any changes */ + if(isset($_POST['sambaLogonHoursPosted']) && preg_match("/w/i",$ui->get_permissions($this->acl_base,"user/generic","sambaLogonHours"))){ + foreach($this->Matrix as $day_key => $days){ + foreach($days as $hour_key => $hour){ + if(isset($_POST['day_'.$day_key.'_'.$hour_key])){ + $this->Matrix[$day_key][$hour_key] = 1; + }else{ + $this->Matrix[$day_key][$hour_key] = 0; + } + } + } + } + } + + function save() + { + + /* Convert Matrix to Hex */ + $slh = ""; + foreach($this->Matrix as $day_key => $days){ + foreach($days as $hour_key => $hour){ + $slh .= $hour; + } + } + + /* Shift string to match given timezone settings */ + $shift_by = (168 + ($this->timezone*(-1))) % 168; + for($i = 0 ; $i < $shift_by; $i ++){ + $slh = $slh[167].$slh; + $slh = substr($slh,0,168); + } + + /* Rework string, because it was stored in little endian */ + $new = ''; + for($i = 0 ; $i < 21 ; $i ++ ){ + $part = strrev(substr($slh, $i * 8, 8)); + $byte['hi'] = substr($part,0,4); + $byte['low'] = substr($part,4,4); + $new .= $byte['hi'].$byte['low']; + } + + /* Convert to bin */ + $tmp = ''; + for($i = 0 ; $i < 21 ; $i ++){ + $tmp .= str_pad(base_convert(substr($new,$i*8,8),2,16),2,'0',STR_PAD_LEFT); + } + + /* Create uppercase HEX chars */ + $ret = strtoupper( $tmp); + + /* All hours and days selected */ + if(substr_count($ret,'F') == 42){ + $ret = ""; + } + + return($ret); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/plugins/personal/samba/samba3.tpl b/plugins/personal/samba/samba3.tpl index 3e305f01a..251cf5354 100644 --- a/plugins/personal/samba/samba3.tpl +++ b/plugins/personal/samba/samba3.tpl @@ -390,6 +390,11 @@ +
+{render acl=$sambaLogonHoursACL mode=read_active} + {t}Samba logon times{/t}  +{/render} +   diff --git a/plugins/personal/samba/sambaLogonHours.tpl b/plugins/personal/samba/sambaLogonHours.tpl new file mode 100644 index 000000000..1eb730608 --- /dev/null +++ b/plugins/personal/samba/sambaLogonHours.tpl @@ -0,0 +1,111 @@ + + + + +

{t}Specify the hours this user is allowed to log in{/t}

+
+ + + + + + + + + {foreach from=$Hours item=hours key=key_hours} + {if (($hours)%2) == 0 } + + {/foreach} + + + + + + {foreach from=$Hours item=hours key=key_hours} + {if (($hours)%2) == 0 } + + {/foreach} + + + + +{foreach from=$Matrix item=days key=key_day} + + + {foreach from=$days item=hours key=key_hour} + {if (($key_hour)%2) == 0 } + + {/foreach} + + + + +{/foreach} +
 {t}Hour{/t}
  + {else} + + {/if} + {$hours} +
+   + + {else} + + {/if} + +{render acl=$sambaLogonHoursACL} + +{/render} + + +{render acl=$sambaLogonHoursACL} + +{/render} +
+ {$Days[$key_day]} + + {else} + + {/if} + {if $Matrix[$key_day].$key_hour} +{render acl=$sambaLogonHoursACL} + +{/render} + {else} +{render acl=$sambaLogonHoursACL} + +{/render} + {/if} + +{render acl=$sambaLogonHoursACL} + +{/render} +
+
+ +
+

+ +   + +

+ +