From: hickert Date: Mon, 7 Apr 2008 06:57:18 +0000 (+0000) Subject: Updated sudo classes. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8021f7add19b98dc9f5176bb9ff2c16d1428ee35;p=gosa.git Updated sudo classes. -Added comments renamed option class git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10217 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/sudo/admin/sudo/class_divListSudo.inc b/gosa-plugins/sudo/admin/sudo/class_divListSudo.inc index 1148b991a..d13d554e0 100644 --- a/gosa-plugins/sudo/admin/sudo/class_divListSudo.inc +++ b/gosa-plugins/sudo/admin/sudo/class_divListSudo.inc @@ -140,7 +140,7 @@ class divListSudo extends MultiSelectWindow if(preg_match("/d/",$acl)){ $actions.= ""; + src='images/edittrash.png' alt='".msgPool::delButton()."' name='sudo_del_%KEY%' title='"._("Delete this entry")."'>"; } $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'"; diff --git a/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc b/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc index 0ee163d98..9bb9e9c84 100644 --- a/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc +++ b/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc @@ -20,6 +20,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/*! \brief Sudo generic class. Allow setting User/Host/Command/Runas + for a sudo role object. + */ class sudo extends plugin { /* Group attributes */ @@ -36,6 +40,11 @@ class sudo extends plugin var $is_account = TRUE; + /*! \brief Returns to the base department for sudo roles. + This department is then used to store new roles. + @param Object GOsa configuration object. + @return String sudo store department + */ public static function get_sudoers_ou($config) { /*** @@ -59,6 +68,11 @@ class sudo extends plugin return($base); } + /*! \brief Initializes this sudo class, with all required attributes. + @param Object $config GOsa configuration object. + @param String $db "new" or the sudo role dn. + @return . + */ function sudo(&$config, $dn= NULL) { plugin::plugin ($config, $dn); @@ -114,6 +128,9 @@ class sudo extends plugin //STRINGS } + /*! \brief Creates the sudo generic ui. + @return String The generated HTML content for this plugin. + */ function execute() { /* Call parent execute */ @@ -219,6 +236,9 @@ class sudo extends plugin return($smarty->fetch(get_template_path('generic.tpl', TRUE))); } + + /*! \brief Remove this sudo role from the ldap server + */ function remove_from_parent() { plugin::remove_from_parent(); @@ -231,13 +251,17 @@ class sudo extends plugin $this->handle_post_events("remove"); } - /* Save data to object */ + + /*! \brief Save all relevant HTML posts. + */ function save_object() { plugin::save_object(); } - /* Save to LDAP */ + + /*! \brief Save changes into the ldap database. + */ function save() { plugin::save(); @@ -261,13 +285,20 @@ class sudo extends plugin } } + + /*! \brief Check the given input. + @return Array All error messages in an array(); + */ function check() { $message = plugin::check(); return ($message); } - /* Return plugin informations for acl handling */ + + /*! \brief Add ACL object + @return Returns the ACL object. + */ static function plInfo() { return (array( diff --git a/gosa-plugins/sudo/admin/sudo/class_sudoManagement.inc b/gosa-plugins/sudo/admin/sudo/class_sudoManagement.inc index fdd354938..7be36c35f 100644 --- a/gosa-plugins/sudo/admin/sudo/class_sudoManagement.inc +++ b/gosa-plugins/sudo/admin/sudo/class_sudoManagement.inc @@ -48,6 +48,8 @@ class sudoManagement extends plugin } + /*! \brief Generate && Display HTML content + */ public function execute() { /* Call parent execute */ @@ -309,7 +311,10 @@ class sudoManagement extends plugin return($this->DivListSudo->Draw()); } - + + /*! \brief Return all selected elements from HTML list + @return Array List of all selected list elements + */ private function list_get_selected_items() { $ids = array(); @@ -323,6 +328,8 @@ class sudoManagement extends plugin } + /*! \brief Reload the list of sudo roles. + */ private function reload($CreatePosixsList=false) { $this->list = array(); @@ -351,12 +358,16 @@ class sudoManagement extends plugin } - /* Save data to object */ + /*! \brief Save HTML post data to object + */ public function save_object() { $this->DivListSudo->save_object(); } + + /*! \brief Remove this account + */ public function remove_from_parent() { /* Optionally execute a command after we're done */ @@ -364,13 +375,17 @@ class sudoManagement extends plugin } - /* Save to LDAP */ + /*! \brief Save to LDAP + */ public function save() { /* Optionally execute a command after we're done */ $this->postcreate(); } + + /*! \brief Remove lock from entry + */ public function remove_lock() { if (isset($this->sudotabs->dn)){ diff --git a/gosa-plugins/sudo/admin/sudo/class_sudoOption.inc b/gosa-plugins/sudo/admin/sudo/class_sudoOption.inc new file mode 100644 index 000000000..eb2cd1e80 --- /dev/null +++ b/gosa-plugins/sudo/admin/sudo/class_sudoOption.inc @@ -0,0 +1,427 @@ +'long_otp_prompt' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['ignore_dot']= array('NAME' =>'ignore_dot' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['mail_always']= array('NAME' =>'mail_always' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['mail_badpass']= array('NAME' =>'mail_badpass' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['mail_no_user']= array('NAME' =>'mail_no_user' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['mail_no_host']= array('NAME' =>'mail_no_host' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['mail_no_perms']= array('NAME' =>'mail_no_perms' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['tty_tickets']= array('NAME' =>'tty_tickets' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['authenticate']= array('NAME' =>'authenticate' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['root_sudo']= array('NAME' =>'root_sudo' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['log_host']= array('NAME' =>'log_host' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['log_year']= array('NAME' =>'log_year' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['shell_noargs']= array('NAME' =>'shell_noargs' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['set_home']= array('NAME' =>'set_home' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['always_set_home']= array('NAME' =>'always_set_home' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['path_info']= array('NAME' =>'path_info' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['preserve_groups']= array('NAME' =>'preserve_groups' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['fqdn']= array('NAME' =>'fqdn' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['insults']= array('NAME' =>'insults' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['requiretty']= array('NAME' =>'requiretty' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['env_editor']= array('NAME' =>'env_editor' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['rootpw']= array('NAME' =>'rootpw' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['runaspw']= array('NAME' =>'runaspw' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['targetpw']= array('NAME' =>'targetpw' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['set_logname']= array('NAME' =>'set_logname' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['stay_setuid']= array('NAME' =>'stay_setuid' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['env_reset']= array('NAME' =>'env_reset' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['use_loginclass']= array('NAME' =>'use_loginclass' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['noexec']= array('NAME' =>'noexec' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['ignore_local_sudoers']= array('NAME' =>'ignore_local_sudoers' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); + $option['passwd_tries']= array('NAME' =>'passwd_tries' , 'TYPE' => 'INTEGER' , 'DEFAULT' => ''); + $option['loglinelen']= array('NAME' =>'loglinelen' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); + $option['timestamp_timeout']= array('NAME' =>'timestamp_timeout' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); + $option['passwd_timeout']= array('NAME' =>'passwd_timeout' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); + $option['umask']= array('NAME' =>'umask' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); + $option['mailsub']= array('NAME' =>'mailsub' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['badpass_message']= array('NAME' =>'badpass_message' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['timestampdir']= array('NAME' =>'timestampdir' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['timestampowner']= array('NAME' =>'timestampowner' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['passprompt']= array('NAME' =>'passprompt' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['runas_default']= array('NAME' =>'runas_default' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['syslog_goodpri']= array('NAME' =>'syslog_goodpri' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['syslog_badpri']= array('NAME' =>'syslog_badpri' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['editor']= array('NAME' =>'editor' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['noexec_file']= array('NAME' =>'noexec_file' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); + $option['lecture']= array('NAME' =>'lecture' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); + $option['lecture_file']= array('NAME' =>'lecture_file' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); + $option['logfile']= array('NAME' =>'logfile' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); + $option['syslog']= array('NAME' =>'syslog' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); + $option['mailerpath']= array('NAME' =>'mailerpath' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); + $option['mailerflags']= array('NAME' =>'mailerflags' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); + $option['mailto']= array('NAME' =>'mailto' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); + $option['exempt_group']= array('NAME' =>'exempt_group' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); + $option['verifypw']= array('NAME' =>'verifypw' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); + $option['listpw']= array('NAME' =>'listpw' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); + $option['env_check']= array('NAME' =>'env_check' , 'TYPE' => 'LISTS' , 'DEFAULT' => ''); + $option['env_delete']= array('NAME' =>'env_delete' , 'TYPE' => 'LISTS' , 'DEFAULT' => ''); + $option['env_keep']= array('NAME' =>'env_keep' , 'TYPE' => 'LISTS' , 'DEFAULT' => ''); + ksort($option); + $this->options = $option; + + /**** + Parse given sudoOption attributes + ****/ + $this->sudoOption = array(); + if(isset($this->attrs['sudoOption'])){ + for($i = 0 ; $i < $this->attrs['sudoOption']['count']; $i++){ + + /**** + Detect attribute name/value/negation + ****/ + $opt = $this->attrs['sudoOption'][$i]; + + /* Get negation */ + $negation = FALSE; + if(preg_match("/^!/",$opt)){ + $negation = TRUE; + $opt = preg_replace("/^!/","",$opt); + } + + /* Get value / name*/ + $value = ""; + if(preg_match("/=/",$opt)){ + $value = preg_replace("/^[^=]*+=/","",$opt); + $opt = preg_replace("/=.*$/","",$opt); + } + + /* Check if the given value is part of our options list. + If it is not, add it as type STRING and display a warning. + */ + if(!isset($this->options[$opt])){ + $this->options[$opt]=array('NAME'=>$opt,'TYPE'=>'STRING','DEFAULT' => ''); + msg_dialog::display(_("Unknown option"), + sprintf(_("The sudo option '%s' is invalid!"), + $opt),WARNING_DIALOG); + } + + /* Create internal sudoOption object */ + $option = array(); + $option['NAME'] = $opt; + $option['VALUE'] = $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'] = "FALSE"; + }else{ + $option['VALUE'] = "TRUE"; + } + } + } + + /* Special handling for BOOLEAN values */ + if(in_array($this->options[$opt]['TYPE'],array("BOOLEAN"))){ + $option['NEGATE'] = FALSE; + if($negation){ + $option['VALUE'] = "FALSE"; + }else{ + $option['VALUE'] = "TRUE"; + } + } + + /* Append values */ + if(!isset($this->sudoOption[$opt])){ + $this->sudoOption[$opt][] = $option; + } + } + } + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /***** + Handle Posts + *****/ + foreach($_POST as $name => $value){ + + if(preg_match("/^negOption_/",$name)){ + + $opt = preg_replace("/^negOption_/","",$name); + $opt = preg_replace("/_[^_]*$/","",$opt); + $id = preg_replace("/^.*_([0-9])*$/","\\1",$opt); + $opt = preg_replace("/_[0-9]*$/","",$opt); + + if(isset($this->sudoOption[$opt][$id])){ + $val = $this->sudoOption[$opt][$id]["VALUE"]; + + /***** + 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][$id]["VALUE"] = "FALSE"; + }else{ + $this->sudoOption[$opt][$id]["VALUE"] = "TRUE"; + } + }else{ + $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; + } + } + + /***** + Negate STRING / INTEGER + *****/ + if(in_array($this->options[$opt]['TYPE'],array('STRING','INTEGER','LISTS'))){ + $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; + } + + /***** + Negate BOOLEAN + *****/ + if(in_array($this->options[$opt]['TYPE'],array('BOOLEAN'))){ + if($val == "TRUE"){ + $this->sudoOption[$opt][$id]["VALUE"] = "FALSE"; + }else{ + $this->sudoOption[$opt][$id]["VALUE"] = "TRUE"; + } + } + } + break; + } + + /***** + Remove options + *****/ + if(preg_match("/^delOption/",$name)){ + $opt = preg_replace("/^delOption_/","",$name); + $opt = preg_replace("/_[^_]*$/","",$opt); + $id = preg_replace("/^.*_([0-9])*$/","\\1",$opt); + $opt = preg_replace("/_[0-9]*$/","",$opt); + + if(isset($this->sudoOption[$opt][$id])){ + unset($this->sudoOption[$opt][$id]); + } + if(!count($this->sudoOption[$opt])){ + unset($this->sudoOption[$opt]); + } + break; + } + } + + + $smarty = get_smarty(); + $smarty->assign("map", array("STRING" => _("string"), "BOOLEAN" => _("bool"), + "INTEGER" => _("integer") , "BOOL_INTEGER" => _("integer")."-"._("bool") , + "STRING_BOOL" => _("string")."-"._("bool"),"LISTS" => _("list"))); + $smarty->assign("sudoOption",$this->sudoOption); + $smarty->assign("options",$this->options); + return($smarty->fetch(get_template_path('options.tpl', TRUE))); + } + + function remove_from_parent() + { + } + + /* Save data to object */ + function save_object() + { + plugin::save_object(); + + if(isset($_POST['add_option']) && isset($_POST['option'])){ + $opt = get_post("option"); + + /* Append attribute only once, lists are handled below */ + if(isset($this->options[$opt])){ + $type = $this->options[$opt]['TYPE']; + $val = $this->options[$opt]['DEFAULT']; + $option = array("NAME" => $opt, "VALUE" => $val , "NEGATE" => FALSE); + $this->sudoOption[$opt][] = $option; + } + } + + foreach($this->sudoOption as $name => $opts){ + foreach($opts as $id => $opt){ + + /**** + Get posted value for BOOLEAN + ****/ + if(in_array($this->options[$name]['TYPE'],array("BOOLEAN"))){ + if(isset($_POST['option_value__'.$name.'_'.$id])){ + $this->sudoOption[$name][$id]["VALUE"] = get_post('option_value__'.$name.'_'.$id); + } + } + + /**** + Get posted value for STRING / INTEGER + ****/ + if(in_array($this->options[$name]['TYPE'],array("STRING","INTEGER"))){ + if(isset($_POST['option_value__'.$name.'_'.$id])){ + $this->sudoOption[$name][$id]["VALUE"] = get_post('option_value__'.$name.'_'.$id); + } + } + + /**** + 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.'_'.$id])){ + $sel = get_post('option_selection__'.$name.'_'.$id); + $val = ""; + if(isset($_POST['option_value__'.$name.'_'.$id])){ + $val = get_post('option_value__'.$name.'_'.$id); + } + + if($sel == "FALSE" || $sel == "TRUE"){ + $this->sudoOption[$name][$id]['VALUE'] = $sel; + $this->sudoOption[$name][$id]['NEGATE'] = FALSE; + }else{ + $this->sudoOption[$name][$id]['VALUE'] = $val; + } + } + } + + /**** + Get posted value for LISTS + ****/ + if(in_array($this->options[$name]['TYPE'],array("LISTS"))){ + foreach($this->sudoOption[$name] as $entry_key => $entry){ + if(isset($_POST['list_value__'.$name.'_'.$entry_key])){ + $val = get_post('list_value__'.$name.'_'.$entry_key); + $this->sudoOption[$name][$entry_key]["VALUE"] = $val; + } + } + } + } + } + } + + /* Save to LDAP */ + function save() + { + plugin::save(); + + $this->attrs['sudoOption'] = array(); + foreach($this->sudoOption as $name => $opts){ + foreach($opts as $id => $opt){ + + $type = $this->options[$name]['TYPE']; + $neg = $opt['NEGATE']; + $value = $opt['VALUE']; + $option = ""; + + /**** + Save LISTS + ****/ + if($type=="LISTS"){ + if(empty($value)){ + $option = $name; + }else{ + $option = $name."=".$value; + } + if($neg){ + $option = "!".$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"))){ + if(!empty($value)){ + $option = $name."=".$value; + }else{ + $option = $name; + } + 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{ + if(!empty($value)){ + $option = $name."=".$value; + }else{ + $option = $name; + } + if($neg){ + $option = "!".$option; + } + } + } + + $this->attrs['sudoOption'][] = $option; + } + } + $this->cleanup(); + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $ldap->modify($this->attrs);; + } + + function check() + { + $message = plugin::check(); + return ($message); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/sudo/admin/sudo/class_sudoOptions.inc b/gosa-plugins/sudo/admin/sudo/class_sudoOptions.inc deleted file mode 100644 index eb2cd1e80..000000000 --- a/gosa-plugins/sudo/admin/sudo/class_sudoOptions.inc +++ /dev/null @@ -1,427 +0,0 @@ -'long_otp_prompt' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['ignore_dot']= array('NAME' =>'ignore_dot' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['mail_always']= array('NAME' =>'mail_always' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['mail_badpass']= array('NAME' =>'mail_badpass' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['mail_no_user']= array('NAME' =>'mail_no_user' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['mail_no_host']= array('NAME' =>'mail_no_host' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['mail_no_perms']= array('NAME' =>'mail_no_perms' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['tty_tickets']= array('NAME' =>'tty_tickets' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['authenticate']= array('NAME' =>'authenticate' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['root_sudo']= array('NAME' =>'root_sudo' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['log_host']= array('NAME' =>'log_host' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['log_year']= array('NAME' =>'log_year' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['shell_noargs']= array('NAME' =>'shell_noargs' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['set_home']= array('NAME' =>'set_home' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['always_set_home']= array('NAME' =>'always_set_home' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['path_info']= array('NAME' =>'path_info' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['preserve_groups']= array('NAME' =>'preserve_groups' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['fqdn']= array('NAME' =>'fqdn' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['insults']= array('NAME' =>'insults' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['requiretty']= array('NAME' =>'requiretty' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['env_editor']= array('NAME' =>'env_editor' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['rootpw']= array('NAME' =>'rootpw' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['runaspw']= array('NAME' =>'runaspw' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['targetpw']= array('NAME' =>'targetpw' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['set_logname']= array('NAME' =>'set_logname' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['stay_setuid']= array('NAME' =>'stay_setuid' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['env_reset']= array('NAME' =>'env_reset' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['use_loginclass']= array('NAME' =>'use_loginclass' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['noexec']= array('NAME' =>'noexec' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['ignore_local_sudoers']= array('NAME' =>'ignore_local_sudoers' , 'TYPE' => 'BOOLEAN' , 'DEFAULT' => ''); - $option['passwd_tries']= array('NAME' =>'passwd_tries' , 'TYPE' => 'INTEGER' , 'DEFAULT' => ''); - $option['loglinelen']= array('NAME' =>'loglinelen' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); - $option['timestamp_timeout']= array('NAME' =>'timestamp_timeout' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); - $option['passwd_timeout']= array('NAME' =>'passwd_timeout' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); - $option['umask']= array('NAME' =>'umask' , 'TYPE' => 'BOOL_INTEGER' , 'DEFAULT' => ''); - $option['mailsub']= array('NAME' =>'mailsub' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); - $option['badpass_message']= array('NAME' =>'badpass_message' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); - $option['timestampdir']= array('NAME' =>'timestampdir' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); - $option['timestampowner']= array('NAME' =>'timestampowner' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); - $option['passprompt']= array('NAME' =>'passprompt' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); - $option['runas_default']= array('NAME' =>'runas_default' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); - $option['syslog_goodpri']= array('NAME' =>'syslog_goodpri' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); - $option['syslog_badpri']= array('NAME' =>'syslog_badpri' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); - $option['editor']= array('NAME' =>'editor' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); - $option['noexec_file']= array('NAME' =>'noexec_file' , 'TYPE' => 'STRING' , 'DEFAULT' => ''); - $option['lecture']= array('NAME' =>'lecture' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['lecture_file']= array('NAME' =>'lecture_file' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['logfile']= array('NAME' =>'logfile' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['syslog']= array('NAME' =>'syslog' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['mailerpath']= array('NAME' =>'mailerpath' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['mailerflags']= array('NAME' =>'mailerflags' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['mailto']= array('NAME' =>'mailto' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['exempt_group']= array('NAME' =>'exempt_group' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['verifypw']= array('NAME' =>'verifypw' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['listpw']= array('NAME' =>'listpw' , 'TYPE' => 'STRING_BOOL' , 'DEFAULT' => ''); - $option['env_check']= array('NAME' =>'env_check' , 'TYPE' => 'LISTS' , 'DEFAULT' => ''); - $option['env_delete']= array('NAME' =>'env_delete' , 'TYPE' => 'LISTS' , 'DEFAULT' => ''); - $option['env_keep']= array('NAME' =>'env_keep' , 'TYPE' => 'LISTS' , 'DEFAULT' => ''); - ksort($option); - $this->options = $option; - - /**** - Parse given sudoOption attributes - ****/ - $this->sudoOption = array(); - if(isset($this->attrs['sudoOption'])){ - for($i = 0 ; $i < $this->attrs['sudoOption']['count']; $i++){ - - /**** - Detect attribute name/value/negation - ****/ - $opt = $this->attrs['sudoOption'][$i]; - - /* Get negation */ - $negation = FALSE; - if(preg_match("/^!/",$opt)){ - $negation = TRUE; - $opt = preg_replace("/^!/","",$opt); - } - - /* Get value / name*/ - $value = ""; - if(preg_match("/=/",$opt)){ - $value = preg_replace("/^[^=]*+=/","",$opt); - $opt = preg_replace("/=.*$/","",$opt); - } - - /* Check if the given value is part of our options list. - If it is not, add it as type STRING and display a warning. - */ - if(!isset($this->options[$opt])){ - $this->options[$opt]=array('NAME'=>$opt,'TYPE'=>'STRING','DEFAULT' => ''); - msg_dialog::display(_("Unknown option"), - sprintf(_("The sudo option '%s' is invalid!"), - $opt),WARNING_DIALOG); - } - - /* Create internal sudoOption object */ - $option = array(); - $option['NAME'] = $opt; - $option['VALUE'] = $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'] = "FALSE"; - }else{ - $option['VALUE'] = "TRUE"; - } - } - } - - /* Special handling for BOOLEAN values */ - if(in_array($this->options[$opt]['TYPE'],array("BOOLEAN"))){ - $option['NEGATE'] = FALSE; - if($negation){ - $option['VALUE'] = "FALSE"; - }else{ - $option['VALUE'] = "TRUE"; - } - } - - /* Append values */ - if(!isset($this->sudoOption[$opt])){ - $this->sudoOption[$opt][] = $option; - } - } - } - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /***** - Handle Posts - *****/ - foreach($_POST as $name => $value){ - - if(preg_match("/^negOption_/",$name)){ - - $opt = preg_replace("/^negOption_/","",$name); - $opt = preg_replace("/_[^_]*$/","",$opt); - $id = preg_replace("/^.*_([0-9])*$/","\\1",$opt); - $opt = preg_replace("/_[0-9]*$/","",$opt); - - if(isset($this->sudoOption[$opt][$id])){ - $val = $this->sudoOption[$opt][$id]["VALUE"]; - - /***** - 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][$id]["VALUE"] = "FALSE"; - }else{ - $this->sudoOption[$opt][$id]["VALUE"] = "TRUE"; - } - }else{ - $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; - } - } - - /***** - Negate STRING / INTEGER - *****/ - if(in_array($this->options[$opt]['TYPE'],array('STRING','INTEGER','LISTS'))){ - $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; - } - - /***** - Negate BOOLEAN - *****/ - if(in_array($this->options[$opt]['TYPE'],array('BOOLEAN'))){ - if($val == "TRUE"){ - $this->sudoOption[$opt][$id]["VALUE"] = "FALSE"; - }else{ - $this->sudoOption[$opt][$id]["VALUE"] = "TRUE"; - } - } - } - break; - } - - /***** - Remove options - *****/ - if(preg_match("/^delOption/",$name)){ - $opt = preg_replace("/^delOption_/","",$name); - $opt = preg_replace("/_[^_]*$/","",$opt); - $id = preg_replace("/^.*_([0-9])*$/","\\1",$opt); - $opt = preg_replace("/_[0-9]*$/","",$opt); - - if(isset($this->sudoOption[$opt][$id])){ - unset($this->sudoOption[$opt][$id]); - } - if(!count($this->sudoOption[$opt])){ - unset($this->sudoOption[$opt]); - } - break; - } - } - - - $smarty = get_smarty(); - $smarty->assign("map", array("STRING" => _("string"), "BOOLEAN" => _("bool"), - "INTEGER" => _("integer") , "BOOL_INTEGER" => _("integer")."-"._("bool") , - "STRING_BOOL" => _("string")."-"._("bool"),"LISTS" => _("list"))); - $smarty->assign("sudoOption",$this->sudoOption); - $smarty->assign("options",$this->options); - return($smarty->fetch(get_template_path('options.tpl', TRUE))); - } - - function remove_from_parent() - { - } - - /* Save data to object */ - function save_object() - { - plugin::save_object(); - - if(isset($_POST['add_option']) && isset($_POST['option'])){ - $opt = get_post("option"); - - /* Append attribute only once, lists are handled below */ - if(isset($this->options[$opt])){ - $type = $this->options[$opt]['TYPE']; - $val = $this->options[$opt]['DEFAULT']; - $option = array("NAME" => $opt, "VALUE" => $val , "NEGATE" => FALSE); - $this->sudoOption[$opt][] = $option; - } - } - - foreach($this->sudoOption as $name => $opts){ - foreach($opts as $id => $opt){ - - /**** - Get posted value for BOOLEAN - ****/ - if(in_array($this->options[$name]['TYPE'],array("BOOLEAN"))){ - if(isset($_POST['option_value__'.$name.'_'.$id])){ - $this->sudoOption[$name][$id]["VALUE"] = get_post('option_value__'.$name.'_'.$id); - } - } - - /**** - Get posted value for STRING / INTEGER - ****/ - if(in_array($this->options[$name]['TYPE'],array("STRING","INTEGER"))){ - if(isset($_POST['option_value__'.$name.'_'.$id])){ - $this->sudoOption[$name][$id]["VALUE"] = get_post('option_value__'.$name.'_'.$id); - } - } - - /**** - 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.'_'.$id])){ - $sel = get_post('option_selection__'.$name.'_'.$id); - $val = ""; - if(isset($_POST['option_value__'.$name.'_'.$id])){ - $val = get_post('option_value__'.$name.'_'.$id); - } - - if($sel == "FALSE" || $sel == "TRUE"){ - $this->sudoOption[$name][$id]['VALUE'] = $sel; - $this->sudoOption[$name][$id]['NEGATE'] = FALSE; - }else{ - $this->sudoOption[$name][$id]['VALUE'] = $val; - } - } - } - - /**** - Get posted value for LISTS - ****/ - if(in_array($this->options[$name]['TYPE'],array("LISTS"))){ - foreach($this->sudoOption[$name] as $entry_key => $entry){ - if(isset($_POST['list_value__'.$name.'_'.$entry_key])){ - $val = get_post('list_value__'.$name.'_'.$entry_key); - $this->sudoOption[$name][$entry_key]["VALUE"] = $val; - } - } - } - } - } - } - - /* Save to LDAP */ - function save() - { - plugin::save(); - - $this->attrs['sudoOption'] = array(); - foreach($this->sudoOption as $name => $opts){ - foreach($opts as $id => $opt){ - - $type = $this->options[$name]['TYPE']; - $neg = $opt['NEGATE']; - $value = $opt['VALUE']; - $option = ""; - - /**** - Save LISTS - ****/ - if($type=="LISTS"){ - if(empty($value)){ - $option = $name; - }else{ - $option = $name."=".$value; - } - if($neg){ - $option = "!".$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"))){ - if(!empty($value)){ - $option = $name."=".$value; - }else{ - $option = $name; - } - 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{ - if(!empty($value)){ - $option = $name."=".$value; - }else{ - $option = $name; - } - if($neg){ - $option = "!".$option; - } - } - } - - $this->attrs['sudoOption'][] = $option; - } - } - $this->cleanup(); - $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->dn); - $ldap->modify($this->attrs);; - } - - function check() - { - $message = plugin::check(); - return ($message); - } -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?>