Code

sudo-ldap parameters passing
[gosa.git] / sudo-ldap / src / class_sudoldap.inc
index 8629e73f303e8c22ee0fa1fefb82e5c6ac1cfd77..3354163738b700827cc9019c4622672acee6f1fd 100644 (file)
@@ -28,6 +28,8 @@ class sudoldap extends plugin
                                "sudoOption");
   
   var $objectclasses   = array("sudoRole");
+
+  var $Roles           = array();
   
   /* constructor, if 'dn' is set, the node loads the given
      'dn' from LDAP */
@@ -40,7 +42,6 @@ class sudoldap extends plugin
     plugin::plugin($config, $dn, $parent);
 
     $ldap= $this->config->get_ldap_link();
-    
   }
 
 
@@ -52,6 +53,7 @@ class sudoldap extends plugin
        $display= "";
        $smarty= get_smarty();
 
+       $this->Roles = $this->getRoles();
 
        /* Edited or Added zone 
         */
@@ -71,7 +73,7 @@ class sudoldap extends plugin
                        //if(!$this->dialog->isNew){
                        //      unset($this->Roles[$this->dialog->OldRoleName]);
                        //}
-                       $this->Roles[$ret['roleName']] = $ret;
+                       $this->Roles[$ret['cn']] = $ret;
                        $this->dialog = NULL;
                }
        }
@@ -89,6 +91,36 @@ class sudoldap extends plugin
                $this->dialog = new sudoldapEditRole($this->config);
        }
 
+       /* Check for edit role request 
+        */
+       $once = false;
+       foreach( $_POST as $name => $value){
+  
+               /* check all post for edit request 
+                        */
+               //if(preg_match("/^editRole_/",$name)&&!$once && chkacl($this->acl,"sudoldap") == ""){
+               if(preg_match("/^editRole_/",$name)&&!$once){
+                       $once =true;
+                       $tmp = preg_replace("/^editRole_/","",$name);
+                       $tmp = base64_decode(preg_replace("/_.*$/","",$tmp));
+                       $this->dialog= new sudoldapeditRole($this->config,$this->dn,$this->Roles[$tmp]);
+               }
+
+               /* check posts for delete zone 
+                        */
+               //if(preg_match("/^delRole_/",$name)&&!$once && chkacl($this->acl,"sudoldap") == ""){
+               if(preg_match("/^delRole_/",$name)&&!$once){
+
+                       $once =true;
+                       $tmp = preg_replace("/^delRole_/","",$name);
+                       $tmp = base64_decode(preg_replace("/_.*$/","",$tmp));
+     
+               /* Initiate deletion
+                */ 
+               $this->RemoveRole($tmp); 
+               }
+       }
+
        /* Show dialog 
         */
        if($this->dialog!= NULL){
@@ -101,18 +133,16 @@ class sudoldap extends plugin
        $RoleList -> SetHeight(300);
        $editImg = "<input type='image' src='images/edit.png' name='editRole_%s'>
        <input type='image' src='images/edittrash.png' name='delRole_%s'>";
-       /*
-       foreach($this->Zones as $zone => $values ){
+       foreach($this->Roles as $role => $values ){
                $link = "<a href='?plug=".$_GET['plug']."&act=edit&id=%s'>%s</a>";
-               $ZoneList->AddEntry(array(
-                       array("string" => sprintf($link,base64_encode($zone),getNameFromMix($zone))),
-                       array("string" => sprintf($link,base64_encode($zone),_("Reverse zone")." : ".getNameFromMix($values['ReverseZone']))),
-                       array("string" => _("TTL")." : ".$values['sOAttl']),
-                       array("string" => _("Class")." : ".$values['dNSClass']),
-                       array("string" => str_replace("%s",base64_encode($zone),$editImg))
+               $RoleList->AddEntry(array(
+                       array("string" => sprintf($link,base64_encode($role),$role)),
+                       //array("string" => sprintf($link,base64_encode($zone),_("Reverse zone")." : ".getNameFromMix($values['ReverseZone']))),
+                       //array("string" => _("TTL")." : ".$values['sOAttl']),
+                       //array("string" => _("Class")." : ".$values['dNSClass']),
+                       array("string" => str_replace("%s",base64_encode($role),$editImg))
             ));
        }    
-       */
 
        $smarty->assign("sudoldapACL",chkacl($this->acl,"sudoldap"));
 
@@ -121,6 +151,24 @@ class sudoldap extends plugin
        return($display);
   }
 
+  function getRoles()
+  {
+    $ret = array();
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(objectClass=sudoRole)",$this->attributes);
+    while ($attrs= $ldap->fetch()){
+       $cn= $attrs['cn'][0];
+       foreach($this->attributes as $value){
+               if(isset($attrs[$value])){
+                       $ret[$cn][$value] = $attrs[$value][0];
+               }
+       }
+    }
+    return($ret);
+  }  
+
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: