From 2f82a2b04ff05f8d2e2204997554ac340640f0a7 Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 3 Apr 2008 09:14:43 +0000 Subject: [PATCH] Updated sudo stuff git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10132 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../plugins/admin/sudo/class_sudoGeneric.inc | 13 +- .../plugins/admin/sudo/class_sudoOptions.inc | 150 +++++++++++++++++- gosa-core/plugins/admin/sudo/generic.tpl | 7 - gosa-core/plugins/admin/sudo/options.tpl | 68 ++++++-- 4 files changed, 209 insertions(+), 29 deletions(-) diff --git a/gosa-core/plugins/admin/sudo/class_sudoGeneric.inc b/gosa-core/plugins/admin/sudo/class_sudoGeneric.inc index a14d87c8f..6f62286b5 100644 --- a/gosa-core/plugins/admin/sudo/class_sudoGeneric.inc +++ b/gosa-core/plugins/admin/sudo/class_sudoGeneric.inc @@ -28,12 +28,11 @@ class sudo extends plugin var $sudoUser = array(); var $sudoCommand= array(); - var $sudoOption = array(); var $sudoHost = array(); var $sudoRunas = array(); var $objectclasses = array("top","sudoRole"); - var $attributes = array("cn","description","sudoUser","sudoCommand","sudoOption","sudoHost","sudoRunas"); + var $attributes = array("cn","description","sudoUser","sudoCommand","sudoHost","sudoRunas"); var $is_account = TRUE; @@ -41,7 +40,7 @@ class sudo extends plugin { plugin::plugin ($config, $dn); - foreach(array("sudoUser","sudoCommand","sudoOption","sudoHost","sudoRunas") as $attr){ + foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunas") as $attr){ $this->$attr = array(); if(isset($this->attrs[$attr])){ $tmp = array(); @@ -171,15 +170,13 @@ class sudo extends plugin $divlist_sudoHost->Setheight("90"); $divlist_sudoRunas = new divSelectBox("divlist_sudoRunas"); $divlist_sudoRunas->Setheight("90"); - $divlist_sudoOption = new divSelectBox("divlist_sudoOption"); - $divlist_sudoOption->Setheight("90"); $divlist_sudoCommand = new divSelectBox("divlist_sudoCommand"); $divlist_sudoCommand->Setheight("90"); $neg_img= "!"; $option = ""; $option.= ""; - foreach(array("sudoUser","sudoCommand","sudoOption","sudoHost","sudoRunas") as $attr){ + foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunas") as $attr){ foreach($this->$attr as $key => $entry){ $entry = preg_replace("/^!/",$neg_img,$entry); $list_name = "divlist_".$attr; @@ -194,7 +191,6 @@ class sudo extends plugin $smarty->assign("divlist_sudoUser",$divlist_sudoUser->DrawList()); $smarty->assign("divlist_sudoHost",$divlist_sudoHost->DrawList()); $smarty->assign("divlist_sudoRunas",$divlist_sudoRunas->DrawList()); - $smarty->assign("divlist_sudoOption",$divlist_sudoOption->DrawList()); $smarty->assign("divlist_sudoCommand",$divlist_sudoCommand->DrawList()); return($smarty->fetch(get_template_path('generic.tpl', TRUE))); @@ -265,8 +261,7 @@ class sudo extends plugin "sudoUser" => _("Users"), "sudoHost" => _("Host"), "sudoCommand" => _("Command"), - "sudoRunas" => _("Run as user"), - "sudoOption" => _("Flags")) + "sudoRunas" => _("Run as user")) )); } } diff --git a/gosa-core/plugins/admin/sudo/class_sudoOptions.inc b/gosa-core/plugins/admin/sudo/class_sudoOptions.inc index 8c003e4a9..0b1572211 100644 --- a/gosa-core/plugins/admin/sudo/class_sudoOptions.inc +++ b/gosa-core/plugins/admin/sudo/class_sudoOptions.inc @@ -180,6 +180,30 @@ class sudo_options extends plugin $option['VALUE'] = array($value); $option['NEGATE'] = $negation; + /* Special handling for mixed flag types. + Some attributes like (BOOL_INTEGER) can be TRUE/FALSE and INTEGER. + This means, if the value is empty it is BOOL and $negation defines its boolean value. + */ + if(in_array($this->options[$opt]['TYPE'],array("BOOL_INTEGER","STRING_BOOL"))){ + if(empty($value)){ + $option['NEGATE'] = FALSE; + if($negation){ + $option['VALUE'] = array(0 => "FALSE"); + }else{ + $option['VALUE'] = array(0 => "TRUE"); + } + } + } + + if(in_array($this->options[$opt]['TYPE'],array("BOOLEAN"))){ + $option['NEGATE'] = FALSE; + if($negation){ + $option['VALUE'] = array(0 => "FALSE"); + }else{ + $option['VALUE'] = array(0 => "TRUE"); + } + } + if(!isset($this->sudoOption[$opt])){ $this->sudoOption[$opt] = $option; }else{ @@ -193,6 +217,51 @@ class sudo_options extends plugin { /* Call parent execute */ plugin::execute(); + + foreach($_POST as $name => $value){ + if(preg_match("/^negOption_/",$name)){ + $opt = preg_replace("/^negOption_/","",$name); + $opt = preg_replace("/_[^_]*$/","",$opt); + if(isset($this->sudoOption[$opt])){ + $val = $this->sudoOption[$opt]['VALUE'][0]; + + /***** + Negate STRING_BOOL && BOOL_INTEGER + *****/ + if(in_array($this->options[$opt]['TYPE'],array('STRING_BOOL','BOOL_INTEGER'))){ + if(in_array($val, array("TRUE","FALSE"))){ + if($val == "TRUE"){ + $this->sudoOption[$opt]['VALUE'][0] = "FALSE"; + }else{ + $this->sudoOption[$opt]['VALUE'][0] = "TRUE"; + } + }else{ + $this->sudoOption[$opt]['NEGATE'] = !$this->sudoOption[$opt]['NEGATE']; + } + } + + /***** + Negate STRING / INTEGER + *****/ + if(in_array($this->options[$opt]['TYPE'],array('STRING','INTEGER'))){ + $this->sudoOption[$opt]['NEGATE'] = !$this->sudoOption[$opt]['NEGATE']; + } + + /***** + Negate BOOLEAN + *****/ + if(in_array($this->options[$opt]['TYPE'],array('BOOLEAN'))){ + if($val == "TRUE"){ + $this->sudoOption[$opt]['VALUE'][0] = "FALSE"; + }else{ + $this->sudoOption[$opt]['VALUE'][0] = "TRUE"; + } + } + } + break; + } + } + $smarty = get_smarty(); $smarty->assign("map", array("STRINGS" => _("string"), "BOOLEAN" => _("bool"), @@ -213,9 +282,40 @@ class sudo_options extends plugin plugin::save_object(); foreach($this->sudoOption as $name => $opt){ + + /**** + Get posted value for BOOLEAN + ****/ + if(in_array($this->options[$name]['TYPE'],array("BOOLEAN"))){ + $this->sudoOption[$name]['VALUE'][0] = get_post('option_value__'.$name); + } + + /**** + Get posted value for STRING / INTEGER + ****/ if(in_array($this->options[$name]['TYPE'],array("STRING","INTEGER"))){ if(isset($_POST['option_value__'.$name])){ - $this->sudoOption[$name]['VALUE'] = get_post('option_value__'.$name); + $this->sudoOption[$name]['VALUE'][0] = get_post('option_value__'.$name); + } + } + + /**** + Get posted value for STRING_BOOL / BOOL_INTEGER + ****/ + if(in_array($this->options[$name]['TYPE'],array("BOOL_INTEGER","STRING_BOOL"))){ + if(isset($_POST['option_selection__'.$name])){ + $sel = get_post('option_selection__'.$name); + $val = ""; + if(isset($_POST['option_value__'.$name])){ + $val = get_post('option_value__'.$name); + } + + if($sel == "FALSE" || $sel == "TRUE"){ + $this->sudoOption[$name]['VALUE'] = array($sel); + $this->sudoOption[$name]['NEGATE'] = FALSE; + }else{ + $this->sudoOption[$name]['VALUE'] = array($val); + } } } } @@ -225,9 +325,55 @@ class sudo_options extends plugin function save() { plugin::save(); + + $this->attrs['sudoOption'] = array(); + foreach($this->sudoOption as $name => $opt){ + + $type = $this->options[$name]['TYPE']; + $neg = $opt['NEGATE']; + $value = $opt['VALUE'][0]; + $option = ""; + + /**** + Save BOOLEAN + ****/ + if(in_array($type,array("BOOLEAN"))){ + $option = $name; + if($value == "FALSE"){ + $option = "!".$option; + } + } + + /**** + Save STRING / INTEGER + ****/ + if(in_array($type,array("STRING","INTEGER"))){ + $option = $name."=".$value; + if($neg){ + $option = "!".$option; + } + } + + /**** + Save STRING_BOOL / BOOL_INTEGER + ****/ + if(in_array($type,array("STRING_BOOL","BOOL_INTEGER"))){ + if($value == "FALSE"){ + $option = "!".$name; + }elseif($value == "TRUE"){ + $option = $name; + }else{ + $option = $name."=".$value; + if($neg){ + $option = "!".$option; + } + } + } + + $this->attrs['sudoOption'][] = $option; + } $this->cleanup(); $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->config->current['BASE']); $ldap->cd($this->dn); $ldap->modify($this->attrs);; } diff --git a/gosa-core/plugins/admin/sudo/generic.tpl b/gosa-core/plugins/admin/sudo/generic.tpl index e0849e8db..be45c1709 100644 --- a/gosa-core/plugins/admin/sudo/generic.tpl +++ b/gosa-core/plugins/admin/sudo/generic.tpl @@ -34,13 +34,6 @@

 

- - Flags - {$divlist_sudoOption} - - - -

 

Hosts {$divlist_sudoHost} diff --git a/gosa-core/plugins/admin/sudo/options.tpl b/gosa-core/plugins/admin/sudo/options.tpl index 2cac4f0e0..94685e32e 100644 --- a/gosa-core/plugins/admin/sudo/options.tpl +++ b/gosa-core/plugins/admin/sudo/options.tpl @@ -18,29 +18,75 @@ {if $options[$item.NAME].TYPE == "STRING"} + {elseif $options[$item.NAME].TYPE == "INTEGER"} + {elseif $options[$item.NAME].TYPE == "BOOLEAN"} - + + {elseif $options[$item.NAME].TYPE == "BOOL_INTEGER"} - + + {elseif $options[$item.NAME].TYPE == "STRING_BOOL"} - + + {else} {$options[$item.NAME].TYPE} {/if} + + + + {/foreach} + + + + -- 2.30.2