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{
25 /* This plugin only writes its objectClass */
26 var $objectclasses = array();
27 var $attributes = array();
28 var $StatusFlag = "";
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;
40 /* Construcktion */
41 function goService(&$config,$dn,$parent = NULL)
42 {
43 plugin::plugin($config,$dn);
44 $this->DisplayName = _("Empty service");
45 }
48 /* Create content */
49 function execute()
50 {
51 plugin::execute();
53 if($this->is_account && !$this->view_logged){
54 $this->view_logged = TRUE;
55 new log("view","server/".get_class($this),$this->dn);
56 }
58 $str ="<div style='width:100%; text-align:right;'>".
59 " <input type='submit' name='SaveService' value='".msgPool::saveButton()."'> ".
60 " <input type='submit' name='CancelService' value='".msgPool::cancelButton()."'>".
61 "</div>";
62 return($str);
63 }
66 /* Get service information for serverService plugin */
67 function getListEntry()
68 {
70 $this->updateStatusState();
72 /* Assign status flag */
73 if(!empty($this->StatusFlag)){
74 $flag = $this->StatusFlag;
75 $fields['Status'] = $this->$flag;
76 }else{
77 $fields['Status'] = "";
78 }
80 /* Name displayed in service overview */
81 $fields['Message'] = _("Empty service");
83 /* Allow/disallow some functions */
84 $sf = !empty($this->StatusFlag);
85 $fields['AllowStart'] = $sf && $this->acl_is_writeable("start");
86 $fields['AllowStop'] = $sf && $this->acl_is_writeable("stop");
87 $fields['AllowRestart'] = $sf && $this->acl_is_writeable("restart");
88 $fields['AllowRemove'] = $this->acl_is_removeable();
89 $fields['AllowEdit'] = $this->acl_is_readable("");
90 return($fields);
91 }
94 /* Remove service */
95 function remove_from_parent()
96 {
97 if(!$this->initially_was_account || !$this->acl_is_removeable()){
98 return;
99 }
101 plugin::remove_from_parent();
103 /* Remove status flag, it is not a memeber of
104 this->attributes, so ensure that it is deleted too */
105 if(!empty($this->StatusFlag)){
106 $this->attrs[$this->StatusFlag] = array();
107 }
109 /* Check if this is a new entry ... add/modify */
110 $ldap = $this->config->get_ldap_link();
111 $ldap->cat($this->dn,array("objectClass"));
112 if($ldap->count()){
113 $ldap->cd($this->dn);
114 $ldap->modify($this->attrs);
115 }else{
116 $ldap->cd($this->dn);
117 $ldap->add($this->attrs);
119 }
121 new log("remove","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
123 if (!$ldap->success()){
124 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
125 }
126 $this->handle_post_events("remove");
127 }
130 /* Save service */
131 function save()
132 {
133 plugin::save();
134 /* Check if this is a new entry ... add/modify */
135 $ldap = $this->config->get_ldap_link();
136 $ldap->cat($this->dn,array("objectClass"));
137 if($ldap->count()){
138 $ldap->cd($this->dn);
139 $ldap->modify($this->attrs);
140 }else{
141 $ldap->cd($this->dn);
142 $ldap->add($this->attrs);
143 }
144 if($this->initially_was_account){
145 new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
146 $this->handle_post_events("modify");
147 }else{
148 $this->handle_post_events("add");
149 new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
150 }
151 if (!$ldap->success()){
152 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
153 }
154 }
157 /* Directly save new status flag */
158 function setStatus($value)
159 {
160 if($value == "none") return;
162 /* Can't set status flag for new services (Object doesn't exists in ldap tree) */
163 if(!$this->initially_was_account) return;
165 /* Can't set status flag, if no flag is specified */
166 if(empty($this->StatusFlag)){
167 return;
168 }
170 /* Get object (server), update status flag and save changes */
171 $ldap = $this->config->get_ldap_link();
172 $ldap->cd($this->dn);
173 $ldap->cat($this->dn,array("objectClass"));
174 if($ldap->count()){
176 $tmp = $ldap->fetch();
177 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
178 $attrs['objectClass'][] = $tmp['objectClass'][$i];
179 }
180 $flag = $this->StatusFlag;
181 $attrs[$flag] = $value;
182 $this->$flag = $value;
183 $ldap->modify($attrs);
184 if (!$ldap->success()){
185 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
186 }
187 $this->action_hook();
188 }
189 }
192 function check()
193 {
194 $message = plugin::check();
195 return($message);
196 }
199 function save_object()
200 {
201 plugin::save_object();
202 }
205 function action_hook($addAttrs= array())
206 {
207 $this->callHook('SERVICEACTIONHOOK', $addAttrs);
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 }
228 }
229 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
230 ?>