1 <?php
3 class goKrbServer extends goService{
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";
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 var $macAddress = "00:01:6c:9d:aa:16" ;
28 public function goKrbServer(&$config,$dn)
29 {
30 goService::goService($config,$dn);
31 $this->DisplayName = _("Kerberos service");
33 /* Get configured policies
34 */
35 $o = new gosaSupportDaemon();
36 $tmp = $o->krb5_list_policies($this->macAddress);
37 if($o->is_error()){
38 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o->get_error()),ERROR_DIALOG);
39 }else{
40 $this->policies = array();
41 foreach($tmp as $policy){
42 $this->policies[] = array("NAME" => $policy,"STATUS" => "LOADED","DATA" => array());
43 }
44 }
45 }
48 /*! \brief Create HTML output
49 @return String HMTL output.
50 */
51 public function execute()
52 {
53 $smarty = get_smarty();
55 if(!$this->view_logged){
56 $this->view_logged = TRUE;
57 new log("view","server/".get_class($this),$this->dn);
58 }
60 /*******
61 Display sub dialogs
62 *******/
64 /* CANCEL Policy dialog
65 */
66 if(isset($_POST['cancel_policy'])){
67 $this->dialog = NULL;
68 }
70 /* SAVE Policy dialog
71 */
72 if($this->dialog instanceof krb5_policy && isset($_POST['save_policy'])){
73 $this->dialog->save_object();
74 $msgs = $this->dialog->check();
75 if(count($msgs)){
76 msg_dialog::displayChecks($msgs);
77 }else{
78 $this->AddPolicy($this->id,$this->dialog->save());
79 $this->dialog = NULL;
80 }
81 }
83 /* DISPLAY policy dialog
84 */
85 if($this->dialog instanceof krb5_policy){
86 $this->dialog->save_object();
87 return($this->dialog->execute());
88 }
90 /*******
91 Create HTML output for this plugin
92 *******/
94 $tmp = $this->plinfo();
95 foreach($tmp['plProvidedAcls'] as $name => $translation){
96 $smarty->assign($name."ACL",$this->getacl($name));
97 }
99 foreach($this->attributes as $attr){
100 $smarty->assign($attr,$this->$attr);
101 }
103 $divlist = new divSelectBox("Kerberos Policies");
104 $action = "<input type='image' src='images/lists/edit.png' class='center' name='policy_edit_%id'>";
105 $action .= "<input type='image' src='images/lists/trash.png' class='center' name='policy_del_%id'>";
106 foreach($this->policies as $key => $policy){
107 if($policy['STATUS'] == "REMOVED") continue;
109 $actions = preg_replace("/%id/",$key,$action);
110 $field1 = array("string" => $policy['NAME']);
111 $field3 = array("string" => $actions,
112 "attach"=>"style='width:40px; text-align:right; border:0px;'");
114 $divlist->AddEntry(array($field1,$field3));
115 }
117 $smarty->assign("divlist",$divlist->DrawList());
118 return($smarty->fetch(get_template_path("goKrbServer.tpl",TRUE,dirname(__FILE__))));
119 }
122 /* \brief Return serice informations, which will be shown in the service overview.
123 @return Array Some service information.
124 */
125 public function getListEntry()
126 {
127 $fields = goService::getListEntry();
128 $fields['Message'] = _("Kerberos service (kadmin access informations)");
129 $fields['AllowEdit'] = true;
130 return($fields);
131 }
134 /*! \brief Checks if all given values are valid
135 @return Array An array containing all error messages.
136 */
137 public function check()
138 {
139 $message = plugin::check();
140 if (empty($this->goKrbRealm)){
141 $message[]= msgPool::required(_("Realm"));
142 }
143 return($message);
144 }
147 /*! \brief Adds or updated a given policy.
148 @param Integer ID The policy to update, or -1 if it is a new one.
149 @param Array The policy settings.
150 */
151 public function AddPolicy($id,$policy)
152 {
153 if($id != -1 && $this->policies[$id]['NAME'] == $policy['NAME']){
155 /* Policy was edited
156 */
157 if($this->policies[$id]['STATUS'] == "LOADED"){
158 $policy['STATUS'] = "EDITED";
159 }else{
160 $policy['STATUS'] = $this->policies[$id]['STATUS'];
161 }
162 $this->policies[$this->id] = $policy;
164 }elseif($id != -1 && $this->policies[$id]['NAME'] != $policy['NAME']){
166 /* Policy was renamed, remove old and add new policy
167 */
168 $this->RemovePolicy($id);
169 $this->AddPolicy(-1,$policy);
170 }else{
172 /* Policy was added
173 */
174 $name = $policy['NAME'];
176 /* Check if there is already a policy with this name
177 which was removed before
178 */
179 foreach($this->policies as $pid => $entry){
180 if($entry['NAME'] == $name && $entry['STATUS'] == "REMOVED"){
181 $id = $pid;
182 break;
183 }
184 }
186 /* Update existing policy or create new one
187 */
188 if(isset($this->policies[$id])){
189 $policy['STATUS'] = "EDITED";
190 $this->policies[$id] = $policy;
191 }else{
192 $policy['STATUS'] = "ADDED";
193 $this->policies[] = $policy;
194 }
195 }
196 }
199 /*! \brief Returns all used policy names.
200 @return Array A list of used policy names.
201 */
202 public function getPolicyNames()
203 {
204 $ret = array();
205 foreach($this->policies as $policy){
206 if($policy['STATUS'] == "REMOVED") continue;
207 $ret[] = $policy['NAME'];
208 }
209 return($ret);
210 }
213 /*! \brief Marks a policy as remvoed
214 @param Integer the Id of the policy to remove
215 */
216 public function RemovePolicy($id)
217 {
218 if($this->policies[$id]['STATUS'] == "ADDED"){
219 unset($this->policies[$id]);
220 }else{
221 $this->policies[$id]['STATUS'] = "REMOVED";
222 }
223 }
226 /*! \brief Save POSTed html variables
227 */
228 public function save_object()
229 {
230 if(isset($_POST['goKrbServerPosted'])){
231 plugin::save_object();
233 /* Add new Policy requested
234 */
235 if(isset($_POST['policy_add'])){
236 $this->dialog = new krb5_policy($this->config,array(),$this);
237 $this->id = -1;
238 }
240 /* Walk through POSTs an check for image-button posts
241 */
242 foreach($_POST as $name => $value){
244 /* Remove policy requested
245 */
246 if(preg_match("/^policy_del/",$name)){
247 $id = preg_replace("/^policy_del_([0-9]*)_.*/i","\\1",$name);
248 if(isset($this->policies[$id])){
249 $this->RemovePolicy($id);
250 }
251 break;
252 }
254 /* Edit Policy requested
255 */
256 if(preg_match("/^policy_edit/",$name)){
257 $id = preg_replace("/^policy_edit_([0-9]*)_.*/i","\\1",$name);
258 if(isset($this->policies[$id])){
260 /* Load policy information, if not done before
261 */
262 if($this->policies[$id]['STATUS'] == "LOADED" && empty($this->policies[$id]['DATA'])){
263 $o = new gosaSupportDaemon();
264 $this->policies[$id]['DATA'] = $o->krb5_get_policy($this->macAddress,$this->policies[$id]['NAME']);
265 }
267 /* Open dialog */
268 $this->id = $id;
269 $this->dialog = new krb5_policy($this->config,$this->policies[$id], $this);
270 }
271 break;
272 }
273 }
274 }
275 }
278 /*! \brief Save changes to ldap
279 */
280 public function save()
281 {
282 goService::save();
284 /* Send policy changes back to the si daemon
285 */
286 $actions = array("del" => array(),"add" => array(),"edit"=>array());
287 foreach($this->policies as $policy){
288 switch($policy['STATUS']){
289 case "REMOVED" : $actions['del'] [] = $policy;break;
290 case "ADDED" : $actions['add'] [] = $policy;break;
291 case "EDITED" : $actions['edit'][] = $policy;break;
292 }
293 }
295 $o = new gosaSupportDaemon();
296 /* Send remove policy event
297 */
298 foreach($actions['del'] as $policy){
299 if(!$o->krb5_del_policy($this->macAddress,$policy['NAME'])){
300 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o->get_error()),ERROR_DIALOG);
301 }
302 }
304 /* Send add new policy event
305 */
306 foreach($actions['add'] as $policy){
307 if(!$o->krb5_add_policy($this->macAddress,$policy['NAME'],$policy['DATA'])){
308 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o->get_error()),ERROR_DIALOG);
309 }
310 }
312 /* Send update policy event
313 */
314 foreach($actions['edit'] as $policy){
315 if(!$o->krb5_set_policy($this->macAddress,$policy['NAME'],$policy['DATA'])){
316 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o->get_error()),ERROR_DIALOG);
317 }
318 }
319 }
322 /*! \brief Return plugin informations for acl handling
323 @return Array ACL infos.
324 */
325 static function plInfo()
326 {
327 return (array(
328 "plShortName" => _("Kerberos"),
329 "plDescription" => _("Kerberos access information")." ("._("Services").")",
330 "plSelfModify" => FALSE,
331 "plDepends" => array(),
332 "plPriority" => 95,
333 "plSection" => array("administration"),
334 "plCategory" => array("server"),
336 "plProvidedAcls"=> array(
337 "goKrbPolicy" => _("Policies"),
338 "goKrbRealm" => _("Realm"))
339 ));
340 }
341 }
342 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
343 ?>