Code

Added default attribute to goService class. This allows to add kerberos service suppo...
[gosa.git] / gosa-plugins / systems / admin / systems / services / class_goService.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class goService extends plugin{
24         
25   /* This plugin only writes its objectClass */
26   var $objectclasses    = array();
27   var $attributes       = array();
28   var $StatusFlag       = "";
29  
30   /* This class can't be assigned twice so it conflicts with itsself */
31   var $conflicts            = array();
32   var $dn                   = NULL;
33   var $cn                   = "";
34   var $DisplayName          = "";
35   var $view_logged          = FALSE;
37   var $krb_service_prefix   = "";
38   var $krb_host_key         = NULL; 
39    
40   /* Construcktion */ 
41   function goService(&$config,$dn)
42   {
43     plugin::plugin($config,$dn);
44     $this->DisplayName = _("Empty service");
45   }
47   
48   /* Create content */
49   function execute()
50   {
51     if($this->is_account && !$this->view_logged){
52       $this->view_logged = TRUE;
53       new log("view","server/".get_class($this),$this->dn);
54     }
56     $str ="<div style='width:100%; text-align:right;'>".
57           "  <input type='submit' name='SaveService' value='".msgPool::saveButton()."'>&nbsp;".
58           "  <input type='submit' name='CancelService' value='".msgPool::cancelButton()."'>".
59           "</div>";
60     return($str);
61   }
64   /* Get service information for serverService plugin */
65   function getListEntry()
66   {
67     
68     $this->updateStatusState();
70     /* Assign status flag */
71     if(!empty($this->StatusFlag)){
72       $flag                   = $this->StatusFlag;
73       $fields['Status']       = $this->$flag;
74     }else{
75       $fields['Status']       = "";
76     }
78     /* Name displayed in service overview */
79     $fields['Message']      = _("Empty service");
81     /* Allow/disallow some functions */
82     $fields['AllowStart']   = $this->acl_is_writeable("start");
83     $fields['AllowStop']    = $this->acl_is_writeable("stop");
84     $fields['AllowRestart'] = $this->acl_is_writeable("restart");
85     $fields['AllowRemove']  = $this->acl_is_removeable();
86     $fields['AllowEdit']    = true;
87     return($fields);
88   }
91   /* Remove service */
92   function remove_from_parent()
93   {
94     if(!$this->initially_was_account || !$this->acl_is_removeable()){
95       return;
96     }
97     
98     plugin::remove_from_parent();
100     /* Remove status flag, it is not a memeber of 
101         this->attributes, so ensure that it is deleted too */
102     if(!empty($this->StatusFlag)){
103       $this->attrs[$this->StatusFlag] = array();
104     }
106     /* Check if this is a new entry ... add/modify */
107     $ldap = $this->config->get_ldap_link();
108     $ldap->cat($this->dn,array("objectClass"));
109     if($ldap->count()){
110       $ldap->cd($this->dn);
111       $ldap->modify($this->attrs);
112     }else{
113       $ldap->cd($this->dn);
114       $ldap->add($this->attrs);
115       
116     }
118     new log("remove","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
120     if (!$ldap->success()){
121       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
122     }
123     $this->handle_post_events("remove");
124   }
127   /* Save service */
128   function save()
129   {
130     plugin::save();
131     /* Check if this is a new entry ... add/modify */
132     $ldap = $this->config->get_ldap_link();
133     $ldap->cat($this->dn,array("objectClass"));
134     if($ldap->count()){
135       $ldap->cd($this->dn);
136       $ldap->modify($this->attrs);
137     }else{
138       $ldap->cd($this->dn);
139       $ldap->add($this->attrs);
140     }
141     if($this->initially_was_account){
142       new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
143       $this->handle_post_events("modify");
144     }else{
145       $this->handle_post_events("add");
146       new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
147     }
148     if (!$ldap->success()){
149       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
150     }
151   }
154   /* Directly save new status flag */
155   function setStatus($value)
156   {
157     if($value == "none") return;
159     /* Can't set status flag for new services (Object doesn't exists in ldap tree) */
160     if(!$this->initially_was_account) return;
162     /* Can't set status flag, if no flag is specified  */
163     if(empty($this->StatusFlag)){
164       return;
165     }
167     /* Get object (server), update status flag and save changes */
168     $ldap = $this->config->get_ldap_link();
169     $ldap->cd($this->dn);
170     $ldap->cat($this->dn,array("objectClass"));
171     if($ldap->count()){
173       $tmp = $ldap->fetch();
174       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
175         $attrs['objectClass'][] = $tmp['objectClass'][$i];
176       }
177       $flag = $this->StatusFlag;
178       $attrs[$flag] = $value;
179       $this->$flag = $value;
180       $ldap->modify($attrs);
181       if (!$ldap->success()){
182         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
183       }
184       $this->action_hook();
185     }
186   }
189   function check()
190   { 
191     $message = plugin::check();
192     return($message);
193   }
194   
196   function save_object()
197   {
198     plugin::save_object();
199   }  
201   
202   function action_hook($add_attrs= array())
203   {
204     /* Find postcreate entries for this class */
205     $command= $this->config->search(get_class($this), "ACTION_HOOK",array('menu','tabs'));
206     if ($command != ""){
208       /* Walk through attribute list */
209       foreach ($this->attributes as $attr){
210         if (!is_array($this->$attr)){
211           $command= preg_replace("/%$attr/", $this->$attr, $command);
212         }
213       }
214       $command= preg_replace("/%dn/", $this->dn, $command);
216       /* Additional attributes */
217       foreach ($add_attrs as $name => $value){
218         $command= preg_replace("/%$name/", $value, $command);
219       }
221       /* If there are still some %.. in our command, try to fill these with some other class vars */
222       if(preg_match("/%/",$command)){
223         $attrs = get_object_vars($this);
224         foreach($attrs as $name => $value){
225           if(!is_string($value)) continue;
226           $command= preg_replace("/%$name/", $value, $command);
227         }
228       }
230       if (check_command($command)){
231         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
232             $command, "Execute");
234         exec($command);
235       } else {
236         msg_dialog::display(_("Configuration error"), msgPool::cmdnotfound("ACTION_HOOK", get_class($this)), ERROR_DIALOG);
237       }
238     }
239   }
242   /* Get updates for status flag */
243   function updateStatusState()
244   {
245     if(empty($this->StatusFlag)) return;
247     $attrs = array();
248     $flag = $this->StatusFlag;
249     $ldap = $this->config->get_ldap_link();
250     $ldap->cd($this->cn);
251     $ldap->cat($this->dn,array($flag));
252     if($ldap->count()){
253       $attrs = $ldap->fetch();
254     }
255     if(isset($attrs[$flag][0])){
256       $this->$flag = $attrs[$flag][0];
257     }
258   }
260 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
261 ?>