Code

Updated an error message. fixed server acl string
[gosa.git] / plugins / admin / systems / class_goService.inc
1 <?php
3 class goService extends plugin{
4         
5   var $cli_summary      = "This plugin is used within the ServerService plugin.";
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();
11   var $attributes       = array();
12   var $StatusFlag       = "";
13  
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts            = array();
16   var $dn                   = NULL;
17   var $cn                   = "";
18   var $DisplayName          = "";
20    
21   /* Construcktion */ 
22   function goService($config,$dn)
23   {
24     plugin::plugin($config,$dn);
25     $this->DisplayName = _("Empty service");
26   }
28   
29   /* Create content */
30   function execute()
31   {
32     $str ="<div style='width:100%; text-align:right;'>".
33           "  <input type='submit' name='SaveService' value='"._("Save")."'>&nbsp;".
34           "  <input type='submit' name='CancelService' value='"._("Cancel")."'>".
35           "</div>";
36     return($str);
37   }
40   /* Get service information for serverService plugin */
41   function getListEntry()
42   {
43     
44     $this->updateStatusState();
46     /* Assign status flag */
47     if(!empty($this->StatusFlag)){
48       $flag                   = $this->StatusFlag;
49       $fields['Status']       = $this->$flag;
50     }else{
51       $fields['Status']       = "";
52     }
54     /* Name displayed in service overview */
55     $fields['Message']      = _("Empty service");
57     /* Allow/disallow some functions */
58     $fields['AllowStart']   = $this->acl_is_writeable("start");
59     $fields['AllowStop']    = $this->acl_is_writeable("stop");
60     $fields['AllowRestart'] = $this->acl_is_writeable("restart");
61     $fields['AllowRemove']  = $this->acl_is_removeable();
62     $fields['AllowEdit']    = true;
63     return($fields);
64   }
67   /* Remove service */
68   function remove_from_parent()
69   {
70     if(!$this->initially_was_account || !$this->acl_is_removeable()){
71       return;
72     }
73     
74     plugin::remove_from_parent();
76     /* Remove status flag, it is not a memeber of 
77         this->attributes, so ensure that it is deleted too */
78     if(!empty($this->StatusFlag)){
79       $this->attrs[$this->StatusFlag] = array();
80     }
82     /* Check if this is a new entry ... add/modify */
83     $ldap = $this->config->get_ldap_link();
84     $ldap->cat($this->dn,array("objectClass"));
85     if($ldap->count()){
86       $ldap->cd($this->dn);
87       $ldap->modify($this->attrs);
88     }else{
89       $ldap->cd($this->dn);
90       $ldap->add($this->attrs);
91     }
92     show_ldap_error($ldap->get_error(), sprintf(_("Removing of server services/".get_class($this)." - (".$this->DisplayName.") with dn '%s' failed."),$this->dn));
93     $this->handle_post_events("remove");
94   }
97   /* Save service */
98   function save()
99   {
100     plugin::save();
101     /* Check if this is a new entry ... add/modify */
102     $ldap = $this->config->get_ldap_link();
103     $ldap->cat($this->dn,array("objectClass"));
104     if($ldap->count()){
105       $ldap->cd($this->dn);
106       $ldap->modify($this->attrs);
107     }else{
108       $ldap->cd($this->dn);
109       $ldap->add($this->attrs);
110     }
111     if($this->initially_was_account){
112       $this->handle_post_events("modify");
113     }else{
114       $this->handle_post_events("add");
115     }
116     show_ldap_error($ldap->get_error(), sprintf(_("Saving of server services/".get_class($this)." - (".$this->DisplayName.") with dn '%s' failed."),$this->dn));
117   }
120   /* Directly save new status flag */
121   function setStatus($value)
122   {
123     if($value == "none") return;
125     /* Can't set status flag for new services (Object doesn't exists in ldap tree) */
126     if(!$this->initially_was_account) return;
128     /* Can't set status flag, if no flag is specified  */
129     if(empty($this->StatusFlag)){
130       return;
131     }
133     /* Get object (server), update status flag and save changes */
134     $ldap = $this->config->get_ldap_link();
135     $ldap->cd($this->dn);
136     $ldap->cat($this->dn,array("objectClass"));
137     if($ldap->count()){
139       $tmp = $ldap->fetch();
140       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
141         $attrs['objectClass'][] = $tmp['objectClass'][$i];
142       }
143       $flag = $this->StatusFlag;
144       $attrs[$flag] = $value;
145       $this->$flag = $value;
146       $ldap->modify($attrs);
147       show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/".get_class($this)." - (".$this->DisplayName.") with dn '%s' failed."),$this->dn));
148       $this->action_hook();
149     }
150   }
153   function check()
154   { 
155     $message = plugin::check();
156     return($message);
157   }
158   
160   function save_object()
161   {
162     plugin::save_object();
163   }  
165   
166   function action_hook($add_attrs= array())
167   {
168     /* Find postcreate entries for this class */
169     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
170     if ($command == "" && isset($this->config->data['TABS'])){
171       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
172     }
174     if ($command != ""){
176       /* Walk through attribute list */
177       foreach ($this->attributes as $attr){
178         if (!is_array($this->$attr)){
179           $command= preg_replace("/%$attr/", $this->$attr, $command);
180         }
181       }
182       $command= preg_replace("/%dn/", $this->dn, $command);
184       /* Additional attributes */
185       foreach ($add_attrs as $name => $value){
186         $command= preg_replace("/%$name/", $value, $command);
187       }
189       /* If there are still some %.. in our command, try to fill these with some other class vars */
190       if(preg_match("/%/",$command)){
191         $attrs = get_object_vars($this);
192         foreach($attrs as $name => $value){
193           if(!is_string($value)) continue;
194           $command= preg_replace("/%$name/", $value, $command);
195         }
196       }
198       if (check_command($command)){
199         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
200             $command, "Execute");
202         exec($command);
203       } else {
204         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
205         print_red ($message);
206       }
207     }
208   }
211   /* Get updates for status flag */
212   function updateStatusState()
213   {
214     if(empty($this->StatusFlag)) return;
216     $attrs = array();
217     $flag = $this->StatusFlag;
218     $ldap = $this->config->get_ldap_link();
219     $ldap->cd($this->cn);
220     $ldap->cat($this->dn,array($flag));
221     if($ldap->count()){
222       $attrs = $ldap->fetch();
223     }
224     if(isset($attrs[$flag][0])){
225       $this->$flag = $attrs[$flag][0];
226     }
227   }
229 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
230 ?>