Code

953389a10d8fbd1013aa8c5a6fbee357e0948c8c
[gosa.git] / plugins / admin / systems / class_goKrbServer.inc
1 <?php
3 class goKrbServer extends plugin{
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", "goKrbAdmin","goKrbPassword");
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 $acl;
21   var $cn               ="";
22   var $goKrbRealm     = "";
23   var $goKrbAdmin     = "";
24   var $goKrbPassword  ="";  
25  
26   function goKrbServer($config,$dn)
27   {
28     plugin::plugin($config,$dn);
29     $this->DisplayName = _("Kerberos service");
30   }
33   function execute()
34   { 
35     $smarty = get_smarty(); 
36     foreach($this->attributes as $attr){
37       $smarty->assign($attr,$this->$attr);
38       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
39     }
40     return($smarty->fetch(get_template_path("goKrbServer.tpl",TRUE,dirname(__FILE__))));
41   }
44   function getListEntry()
45   {
46     $this->updateStatusState();
47     $flag = $this->StatusFlag;
48     $fields['Status']      = $this->$flag;
49     $fields['Message']    = _("Kerberos kadmin access informations");
50     $fields['AllowStart'] = true;
51     $fields['AllowStop']  = true;
52     $fields['AllowRestart'] = true;
53     $fields['AllowRemove']= true;
54     $fields['AllowEdit']  = true;
55     return($fields);
56   }
59   function remove_from_parent()
60   {
61     plugin::remove_from_parent();
62     /* Check if this is a new entry ... add/modify */
63     $ldap = $this->config->get_ldap_link();
64     $ldap->cat($this->dn,array("objectClass"));
65     if($ldap->count()){
66       $ldap->cd($this->dn);
67       $ldap->modify($this->attrs);
68     }else{
69       $ldap->cd($this->dn);
70       $ldap->add($this->attrs);
71     }
72     show_ldap_error($ldap->get_error());
73     $this->handle_post_events("remove");
74   }
77   function save()
78   {
79     plugin::save();
80     /* Check if this is a new entry ... add/modify */
81     $ldap = $this->config->get_ldap_link();
82     $ldap->cat($this->dn,array("objectClass"));
83     if($ldap->count()){
84       $ldap->cd($this->dn);
85       $ldap->modify($this->attrs);
86     }else{
87       $ldap->cd($this->dn);
88       $ldap->add($this->attrs);
89     }
90     show_ldap_error($ldap->get_error());
91     if($this->initially_was_account){
92       $this->handle_post_events("modify");
93     }else{
94       $this->handle_post_events("add");
95     }
96   }
99   /* Directly save new status flag */
100   function setStatus($value)
101   {
102     if($value == "none") return;
103     if(!$this->initially_was_account) return;
104     $ldap = $this->config->get_ldap_link();
105     $ldap->cd($this->dn);
106     $ldap->cat($this->dn,array("objectClass"));
107     if($ldap->count()){
109       $tmp = $ldap->fetch();
110       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
111         $attrs['objectClass'][] = $tmp['objectClass'][$i];
112       }
113       $flag = $this->StatusFlag;
114       $attrs[$flag] = $value;
115       $this->$flag = $value;
116       $ldap->modify($attrs);
117       show_ldap_error($ldap->get_error());
118       $this->action_hook();
119     }
120   }
121  
122  
123   function check()
124   { 
125     $message = plugin::check();
126     /* goKrbPassword is a must field, if goKrbServer is used as objectClass */
127     if (empty($this->goKrbPassword)){
128       $message[]= sprintf(_("The specified kerberos password is empty."), $attr);
129     }
130     if (empty($this->goKrbAdmin)){
131       $message[]= sprintf(_("The specified kerberos admin is empty."), $attr);
132     }
133     if (empty($this->goKrbRealm)){
134       $message[]= sprintf(_("The specified kerberos realm is empty."), $attr);
135     }
137     return($message);
138   }
139   
141   function save_object()
142   {
143     if(isset($_POST['goKrbServerPosted'])){
144       plugin::save_object();
145     }
146   } 
148    function action_hook($add_attrs= array())
149   {
150     /* Find postcreate entries for this class */
151     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
152     if ($command == "" && isset($this->config->data['TABS'])){
153       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
154     }
155     if ($command != ""){
156       /* Walk through attribute list */
157       foreach ($this->attributes as $attr){
158         if (!is_array($this->$attr)){
159           $command= preg_replace("/%$attr/", $this->$attr, $command);
160         }
161       }
162       $command= preg_replace("/%dn/", $this->dn, $command);
163       /* Additional attributes */
164       foreach ($add_attrs as $name => $value){
165         $command= preg_replace("/%$name/", $value, $command);
166       }
168       /* If there are still some %.. in our command, try to fill these with some other class vars */
169       if(preg_match("/%/",$command)){
170         $attrs = get_object_vars($this);
171         foreach($attrs as $name => $value){
172           if(!is_string($value)) continue;
173           $command= preg_replace("/%$name/", $value, $command);
174         }
175       }
177       if (check_command($command)){
178         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
179             $command, "Execute");
181         exec($command);
182       } else {
183         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
184         print_red ($message);
185       }
186     }
187   }
189    
190   /* Get updates for status flag */
191   function updateStatusState()
192   {
193     if(empty($this->StatusFlag)) return;
195     $attrs = array();
196     $flag = $this->StatusFlag;
197     $ldap = $this->config->get_ldap_link();
198     $ldap->cd($this->cn);
199     $ldap->cat($this->dn,array($flag));
200     if($ldap->count()){
201       $attrs = $ldap->fetch();
202     }
203     if(isset($attrs[$flag][0])){
204       $this->$flag = $attrs[$flag][0];
205     }
206   }
208 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
209 ?>