X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-plugins%2Fsudo%2Fadmin%2Fsudo%2Fclass_sudoGeneric.inc;h=a4ca4c12683cc5cddf72e4212076f0523f80f770;hb=fbf8e4356f625423e3ccfcb0c6520942726a44e1;hp=05a1a13d51ef45ad407c25d1275e823d32328833;hpb=a43059e5ce59378451f635b83be9afe7bf4388a8;p=gosa.git diff --git a/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc b/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc index 05a1a13d5..a4ca4c126 100644 --- a/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc +++ b/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc @@ -26,25 +26,25 @@ */ class sudo extends plugin { - /* Group attributes */ - var $cn= ""; - var $description= ""; - var $sudoUser = array("ALL"); - var $sudoCommand= array(); - var $sudoHost = array("ALL"); - var $sudoRunAs = array("ALL"); + protected $cn= ""; + protected $description= ""; - var $accessTo = array(); - var $trustModel = ""; - var $show_ws_dialog = FALSE; + protected $sudoUser = array("ALL"); + protected $sudoCommand= array(); + protected $sudoHost = array("ALL"); + protected $sudoRunAs = array("ALL"); + protected $accessTo = array(); + protected $trustModel = ""; - var $objectclasses = array("top","sudoRole"); - var $attributes = array("cn","description","sudoUser","sudoCommand","sudoHost","sudoRunAs","accessTo","trustModel"); + private $is_default = FALSE; + private $show_ws_dialog = FALSE; + private $was_trust_account= FALSE; - var $is_account = TRUE; + public $objectclasses = array("top","sudoRole"); + public $attributes = array("cn","description","sudoUser","sudoCommand","sudoHost","sudoRunAs","accessTo","trustModel"); - var $dialog; + public $ignore_account = TRUE; /*! \brief Returns to the base department for sudo roles. This department is then used to store new roles. @@ -96,7 +96,7 @@ class sudo extends plugin } /* Is this account a trustAccount? */ - if ($this->is_account && isset($this->attrs['trustModel'])){ + if (isset($this->attrs['trustModel'])){ $this->trustModel= $this->attrs['trustModel'][0]; $this->was_trust_account= TRUE; } else { @@ -105,7 +105,7 @@ class sudo extends plugin } $this->accessTo = array(); - if ($this->is_account && isset($this->attrs['accessTo'])){ + if (isset($this->attrs['accessTo'])){ for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){ $tmp= $this->attrs['accessTo'][$i]; $this->accessTo[$tmp]= $tmp; @@ -114,6 +114,10 @@ class sudo extends plugin } + if(preg_match("/^defaults$/i",$this->cn)){ + $this->is_default = TRUE; + } + /* Get global filter config */ if (!session::is_set("sysfilter")){ $ui= get_userinfo(); @@ -188,9 +192,13 @@ class sudo extends plugin if(isset($_POST['SaveMultiSelectWindow']) && $this->dialog instanceof target_list_users){ if($this->acl_is_writeable("sudoUser")){ foreach($this->dialog->save() as $entry){ - $cn = trim($entry['uid'][0]); - if(!in_array($cn,$this->sudoUser) && !in_array("!".$cn,$this->sudoUser)){ - $this->sudoUser[] = $cn; + if(in_array("posixGroup",$entry['objectClass'])){ + $name = trim("%".$entry['cn'][0]); + }else{ + $name = trim($entry['uid'][0]); + } + if(!in_array($name,$this->sudoUser) && !in_array("!".$name,$this->sudoUser)){ + $this->sudoUser[] = $name; } } } @@ -318,8 +326,13 @@ class sudo extends plugin *********************/ $smarty = get_smarty(); + $smarty->assign("is_default",$this->is_default); foreach($this->attributes as $attr){ - $smarty->assign($attr,$this->$attr); + if(is_string($this->$attr)){ + $smarty->assign($attr,htmlentities($this->$attr)); + }else{ + $smarty->assign($attr,$this->$attr); + } $smarty->assign($attr."ACL",$this->getacl($attr)); } @@ -361,14 +374,48 @@ class sudo extends plugin */ $neg_img= "!"; $option = ""; - $option.= ""; - foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunAs") as $attr){ + $option.= ""; + foreach(array("sudoCommand","sudoHost","sudoRunAs") as $attr){ if($this->acl_is_readable($attr)){ foreach($this->$attr as $key => $entry){ - $entry = preg_replace("/^!/",$neg_img,$entry); + $neg = ""; + if(preg_match("/^!/",$entry)){ + $neg = $neg_img; + } + $entry = preg_replace("/^!/","",$entry); + $list_name = "divlist_".$attr; + $$list_name->AddEntry( + array( + array("string" => $neg,"attach" => "style='width:18px;'"), + array("string" => $entry), + array("string" => preg_replace(array("/%KEY%/","/%ATTR%/"),array($key,$attr),$option), + "attach" => "style='width:40px; border-right: 0px;'"))); + } + } + } + + foreach(array("sudoUser") as $attr){ + $img1 = ""._("User").""; + $img2 = ""._("Group").""; + if($this->acl_is_readable($attr)){ + foreach($this->$attr as $key => $entry){ + $neg = ""; + if(preg_match("/^!/",$entry)){ + $neg = $neg_img; + } + $entry = preg_replace("/^!/","",$entry); + + $img = $img1; + if(preg_match("/^%/",$entry)){ + $img = $img2; + } + $entry = preg_replace("/^%/","",$entry); + $list_name = "divlist_".$attr; $$list_name->AddEntry( array( + array("string" => $neg,"attach" => "style='width:18px;'"), + array("string" => $img,"attach" => "style='width:18px;'"), array("string" => $entry), array("string" => preg_replace(array("/%KEY%/","/%ATTR%/"),array($key,$attr),$option), "attach" => "style='width:40px; border-right: 0px;'"))); @@ -376,6 +423,9 @@ class sudo extends plugin } } + + + /* Tell smarty about our divlists */ $smarty->assign("divlist_sudoUser", $divlist_sudoUser->DrawList()); @@ -406,6 +456,10 @@ class sudo extends plugin function save_object() { plugin::save_object(); + + if($this->is_default){ + $this->cn = "defaults"; + } if(is_object($this->dialog)){ $this->dialog->save_object(); @@ -468,13 +522,12 @@ class sudo extends plugin $this->attrs['sudoRunAs'] = array_values($this->attrs['sudoRunAs']); $this->attrs['sudoUser'] = array_values($this->attrs['sudoUser']); $this->attrs['sudoCommand'] = array_values($this->attrs['sudoCommand']); - print_a($this->attrs); - $this->cleanup(); - print_a($this->attrs); + $this->cleanup(); $ldap = $this->config->get_ldap_link(); $ldap->cd($this->config->current['BASE']); + if($this->is_new){ $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); $ldap->cd($this->dn); @@ -502,6 +555,32 @@ class sudo extends plugin function check() { $message = plugin::check(); + + /* Is a name given? */ + if(empty($this->cn)){ + $message[] = msgPool::required(_("Name")); + } + + /* Check if name is reserved */ + if(!$this->is_default && preg_match("/^defaults$/i",$this->cn)){ + $message[] = msgPool::reserved(_("Name")); + } + + /* Check name */ + if(!preg_match("/^[0-9a-z\@]*$/i",$this->cn)){ + $message[] = msgPool::invalid(_("Name"),$this->cn,"/[0-9a-z\@]/i"); + } + + /* Check if this entry will cause duplicated ldap entries */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->get_sudoers_ou($this->config)); + $ldap->search("(&(objectClass=sudoRole)(cn=".$this->cn."))"); + while($attrs = $ldap->fetch()){ + if($attrs['dn'] != $this->dn){ + $message[] = msgPool::duplicated(_("Name")); + } + } + return ($message); } @@ -558,7 +637,7 @@ class sudo extends plugin $smarty->assign("$type", $sysfilter[$type]); } $smarty->assign("search_image", get_template_path('images/search.png')); - $smarty->assign("launchimage", get_template_path('images/small_filter.png')); + $smarty->assign("launchimage", get_template_path('images/lists/action.png')); $smarty->assign("tree_image", get_template_path('images/tree.png')); $smarty->assign("deplist", $this->config->idepartments); $smarty->assign("alphabet", generate_alphabet()); @@ -570,6 +649,16 @@ class sudo extends plugin } + /*! \brief Force this entry to be handled and saved as 'default' + @param BOOL TRUE -force defaults FALSE -normal + */ + public function set_default($state) + { + $this->is_default = TRUE; + $this->cn = "defaults"; + } + + /*! \brief Add ACL object @return Returns the ACL object. */ @@ -594,6 +683,77 @@ class sudo extends plugin "trustModel" => _("Access control list")) )); } + + + /*! \brief This function will be called if an object gets copied. + This function adapts attributes from the source object. + @param Array The source object. + */ + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunAs") as $attr){ + $this->$attr = array(); + if(isset($source[$attr])){ + $tmp = array(); + for($i = 0 ; $i < $source[$attr]['count']; $i++){ + $tmp[] = $source[$attr][$i]; + } + $this->$attr = $tmp; + } + } + + /* Is this account a trustAccount? */ + if (isset($source['trustModel'])){ + $this->trustModel= $source['trustModel'][0]; + $this->was_trust_account= TRUE; + } else { + $this->was_trust_account= FALSE; + $this->trustModel= ""; + } + + $this->accessTo = array(); + if (isset($source['accessTo'])){ + for ($i= 0; $i<$source['accessTo']['count']; $i++){ + $tmp= $source['accessTo'][$i]; + $this->accessTo[$tmp]= $tmp; + } + } + } + + + /*! \brief Used for copy & paste. + Returns a HTML input mask, which allows to change the cn of this entry. + @param Array Array containing current status && a HTML template. + */ + function getCopyDialog() + { + $vars = array("cn"); + $smarty = get_smarty(); + $smarty->assign("cn", htmlentities($this->cn)); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); + } + + + public function get_cn() + { + return($this->cn); + } + + + /*! \brief Used for copy & paste. + Some entries must be renamed to avaoid duplicate entries. + */ + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = get_post('cn'); + } + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>