Code

Updated policy stuff for heimdal
[gosa.git] / gosa-plugins / heimdal / admin / systems / services / kerberos / class_goKrbServer.inc
1 <?php
3 class goKrbServer extends goService{
4         
5   var $cli_summary      = "This pluign is used within the ServerService Pluign \nand indicates that this server supports NTP service.";
6   var $cli_description  = "Some longer text\nfor help";
7   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* This plugin only writes its objectClass */
10   var $objectclasses    = array("goKrbServer");
11   var $attributes       = array("goKrbRealm");
12   var $StatusFlag       = "goKrbServerStatus";
13  
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goKrbServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $goKrbServerStatus= "";
20   var $cn               = "";
21   var $goKrbRealm       = "";
22   var $view_logged      = FALSE;
24   var $policies         = array();
25   var $id               = -1;
26  
27   function goKrbServer(&$config,$dn)
28   {
29     goService::goService($config,$dn);
30     $this->DisplayName = _("Kerberos service");
32     /* Get configured policies 
33      */ 
34     $o = new gosaSupportDaemon();
35     $tmp = $o->krb5_list_policies("00:01:6c:9d:aa:16");
36     if($o->is_error()){
37       msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
38     }else{
39       $this->policies = array();
40       foreach($tmp as $policy){
41         $this->policies[] = array("NAME" => $policy,"STATUS" => "LOADED","DATA" => array());
42       }
43     }
44   }
47   function execute()
48   { 
49     $smarty = get_smarty(); 
51     if(!$this->view_logged){
52       $this->view_logged = TRUE;
53       new log("view","server/".get_class($this),$this->dn);
54     }
56     /*******  
57       Display sub dialogs
58      *******/
60     /*  CANCEL Policy dialog 
61      */
62     if(isset($_POST['cancel_policy'])){
63       $this->dialog = NULL;
64     }
65     
66     /*  SAVE Policy dialog 
67      */
68     if($this->dialog instanceof krb5_policy && isset($_POST['save_policy'])){
69       $this->dialog->save_object();
70       $msgs = $this->dialog->check();
71       if(count($msgs)){
72         msg_dialog::displayChecks($msgs);
73       }else{
74         $this->AddPolicy($this->id,$this->dialog->save());
75         $this->dialog = NULL;
76       }
77     }
79     /* DISPLAY policy dialog
80      */
81     if($this->dialog instanceof krb5_policy){
82       $this->dialog->save_object();
83       return($this->dialog->execute());
84     } 
86     /*******
87       Create HTML output for this plugin
88      *******/  
90     $tmp = $this->plinfo();
91     foreach($tmp['plProvidedAcls'] as $name => $translation){
92       $smarty->assign($name."ACL",$this->getacl($name));
93     }
95     foreach($this->attributes as $attr){
96       $smarty->assign($attr,$this->$attr);
97     }
99     $divlist = new divSelectBox("Kerberos Policies");
100     $action  = "<input type='image' src='images/lists/edit.png' class='center' name='policy_edit_%id'>";
101     $action .= "<input type='image' src='images/lists/trash.png' class='center' name='policy_del_%id'>";
102     foreach($this->policies as $key => $policy){
103       if($policy['STATUS'] == "REMOVED") continue;
104   
105       $actions = preg_replace("/%id/",$key,$action);
106       $field1 = array("string" => $policy['NAME']);
107       $field3 = array("string" => $actions, 
108                       "attach"=>"style='width:40px; text-align:right; border:0px;'");
110       $divlist->AddEntry(array($field1,$field3));
111     }
113     $smarty->assign("divlist",$divlist->DrawList());
114     return($smarty->fetch(get_template_path("goKrbServer.tpl",TRUE,dirname(__FILE__))));
115   }
118   function getListEntry()
119   {
120     $fields               = goService::getListEntry();
121     $fields['Message']    = _("Kerberos service (kadmin access informations)");
122     $fields['AllowEdit']  = true;
123     return($fields);
124   }
126   function check()
127   { 
128     $message = plugin::check();
129     if (empty($this->goKrbRealm)){
130       $message[]= msgPool::required(_("Realm"));
131     }
132     return($message);
133   }
134   
137   function AddPolicy($id,$policy)
138   {
139     if($id != -1 && $this->policies[$id]['NAME'] == $policy['NAME']){
141       /* Policy was edited 
142        */
143       if($this->policies[$id]['STATUS'] == "LOADED"){
144         $policy['STATUS'] = "EDITED";
145       }else{
146         $policy['STATUS'] = $this->policies[$id]['STATUS'];
147       }
148       $this->policies[$this->id] = $policy;
150     }elseif($id != -1 && $this->policies[$id]['NAME'] != $policy['NAME']){
152       /* Policy was renamed, remove old and add new policy  
153        */
154       $this->RemovePolicy($id);
155       $this->AddPolicy(-1,$policy);
156     }else{
158       /* Policy was added 
159        */
160       $name = $policy['NAME'];
161     
162       /* Check if there is already a policy with this name 
163           which was removed before
164        */
165       foreach($this->policies as $pid => $entry){
166         if($entry['NAME'] == $name && $entry['STATUS'] == "REMOVED"){
167           $id = $pid;
168           break;
169         }
170       }
171        
172       /* Update existing policy or create new one
173        */ 
174       if(isset($this->policies[$id])){
175         $policy['STATUS'] = "EDITED";
176         $this->policies[$id] = $policy;
177       }else{
178         $policy['STATUS'] = "ADDED";
179         $this->policies[] = $policy;
180       }
181     }
182   }
185   function getPolicyNames()
186   {
187     $ret = array();
188     foreach($this->policies as $policy){
189       if($policy['STATUS'] == "REMOVED") continue;
190       $ret[] = $policy['NAME'];
191     }
192     return($ret);
193   }
195   
196   function RemovePolicy($id)
197   {
198     if($this->policies[$id]['STATUS'] == "ADDED"){
199       unset($this->policies[$id]);
200     }else{
201       $this->policies[$id]['STATUS'] = "REMOVED";
202     }
203   }  
204   
206   function save_object()
207   {
208     if(isset($_POST['goKrbServerPosted'])){
209       plugin::save_object();
211       /* Add new Policy requested 
212        */
213       if(isset($_POST['policy_add'])){
214         $this->dialog = new krb5_policy($this->config,array(),&$this);
215         $this->id = -1;
216       }
218       /* Walk through POSTs an check for image-button posts 
219        */
220       foreach($_POST as $name => $value){
222         /* Remove policy requested 
223          */
224         if(preg_match("/^policy_del/",$name)){
225           $id = preg_replace("/^policy_del_([0-9]*)_.*/i","\\1",$name);
226           if(isset($this->policies[$id])){
227             $this->RemovePolicy($id);
228           }
229           break;
230         }
232         /* Edit Policy requested 
233          */
234         if(preg_match("/^policy_edit/",$name)){
235           $id = preg_replace("/^policy_edit_([0-9]*)_.*/i","\\1",$name);
236           if(isset($this->policies[$id])){
238             /* Load policy information, if not done before 
239              */ 
240             if($this->policies[$id]['STATUS'] == "LOADED" && empty($this->policies[$id]['DATA'])){
241               $o = new gosaSupportDaemon();
242               $this->policies[$id]['DATA'] = $o->krb5_get_policy("00:01:6c:9d:aa:16",$this->policies[$id]['NAME']);
243             }
245             /* Open dialog */
246             $this->id = $id;
247             $this->dialog = new krb5_policy($this->config,$this->policies[$id],&$this);
248           }
249           break;
250         }
251       }
252     }
253   } 
256   /* Return plugin informations for acl handling */
257   static function plInfo()
258   {
259     return (array(
260           "plShortName"   => _("Kerberos"),
261           "plDescription" => _("Kerberos access information")." ("._("Services").")",
262           "plSelfModify"  => FALSE,
263           "plDepends"     => array(),
264           "plPriority"    => 95,
265           "plSection"     => array("administration"),
266           "plCategory"    => array("server"),
268           "plProvidedAcls"=> array(
269             "goKrbPolicy"   => _("Policies"),
270             "goKrbRealm"    => _("Realm")) 
271           ));
272   }
274 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
275 ?>