Code

sudo roles listing
[gosa.git] / sudo-ldap / src / class_sudoldap.inc
1 <?php
2 /*!
3   \brief   sudo-ldap plugin
4   \author  Guido Serra <gserra@guidoserra.it>
5   \version 1.00
6   \date    22.03.2008
8   This class provides the functionality to read and write all attributes
9   relevant for sudo-ldap from/to the LDAP.
10  */
12 class sudoldap extends plugin
13 {
14   /* Definitions */
15   var $plHeadline= "sudo-ldap";
16   var $plDescription= "This does something";
18   /* Plugin specific values */
19  
20   var $dialog           = NULL;
22   var $attributes       = array("cn",
23                                 "description",
24                                 "sudoUser", 
25                                 "sudoHost", 
26                                 "sudoCommand", 
27                                 "sudoRunAs", 
28                                 "sudoOption");
29   
30   var $objectclasses    = array("sudoRole");
32   var $roles_list       = array();
33   
34   /* constructor, if 'dn' is set, the node loads the given
35      'dn' from LDAP */
36   function sudoldap ($config, $dn= NULL, $parent= NULL)
37   {
38     /* Configuration is fine, allways */
39     $this->config= $config;
41     /* Load bases attributes */
42     plugin::plugin($config, $dn, $parent);
44     $ldap= $this->config->get_ldap_link();
45     
46   }
49   /* execute generates the html output for this node */
50   function execute($isCopyPaste = false)
51   {
52         /* Call parent execute */
53         plugin::execute();
54         $display= "";
55         $smarty= get_smarty();
58         /* Edited or Added zone 
59          */
60         if((isset($_POST['SaveRoleChanges'])) && is_object($this->dialog)){
61                 $this->dialog->save_object();
63                 /* Check for errors  
64                  */
65                 if(count($this->dialog->check())){
66                         foreach($this->dialog->check() as $msgs){
67                                 print_red($msgs); 
68                         }
69                 }else{
70                         /* add new/edited zone 
71                          */
72                         $ret = $this->dialog->save();
73                         //if(!$this->dialog->isNew){
74                         //      unset($this->Roles[$this->dialog->OldRoleName]);
75                         //}
76                         $this->Roles[$ret['roleName']] = $ret;
77                         $this->dialog = NULL;
78                 }
79         }
81         /* Cancel zone edit / new 
82          */
83         if(isset($_POST['CancelRoleChanges'])){
84                 $this->dialog = NULL;
85         }
87         /* Add empty new zone 
88          */
89         //if(isset($_POST['AddRole']) && chkacl($this->acl,"sudoldap") == ""){
90         if(isset($_POST['AddRole'])){
91                 $this->dialog = new sudoldapEditRole($this->config);
92         }
94         /* Show dialog 
95          */
96         if($this->dialog!= NULL){
97                 $this->dialog->save_object();
98                 $this->dialog->parent = $this;
99                 return($this->dialog->execute());
100         }
102         $RoleList = new divSelectBox("sudoRoles");
103         $RoleList -> SetHeight(300);
104         $editImg = "<input type='image' src='images/edit.png' name='editRole_%s'>
105         <input type='image' src='images/edittrash.png' name='delRole_%s'>";
106         $this->roles_list = $this->get_list_of_roles();
107         foreach($this->roles_list as $role => $values ){
108                 $link = "<a href='?plug=".$_GET['plug']."&act=edit&id=%s'>%s</a>";
109                 $RoleList->AddEntry(array(
110                         array("string" => sprintf($link,base64_encode($role),$role)),
111                         //array("string" => sprintf($link,base64_encode($zone),_("Reverse zone")." : ".getNameFromMix($values['ReverseZone']))),
112                         //array("string" => _("TTL")." : ".$values['sOAttl']),
113                         //array("string" => _("Class")." : ".$values['dNSClass']),
114                         array("string" => str_replace("%s",base64_encode($role),$editImg))
115             ));
116         }    
118         $smarty->assign("sudoldapACL",chkacl($this->acl,"sudoldap"));
120         $smarty->assign("RoleList",$RoleList->DrawList());
121         $display.= $smarty->fetch(get_template_path('sudoldap.tpl', TRUE));
122         return($display);
123   }
125   function get_list_of_roles()
126   {
127     $ret = array();
128     $ldap = $this->config->get_ldap_link();
129     $ldap->cd($this->config->current['BASE']);
130     $ldap->search("(objectClass=sudoRole)",array("cn","description"));
131     while ($attrs= $ldap->fetch()){
132       $cn= $attrs['cn'][0];
133       if (isset($attrs['description'])){
134         $description= " - ".$attrs['description'][0];
135       } else {
136         $description= "";
137       }
138       $ret[$cn]= "$description";
139     }
140     return($ret);
141   }  
146 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
147 ?>