4871be46fb1e50ef9ea39ab613ff76b9306a35b2
1 <?php
3 class servservice extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage server basic objects";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 var $goExportEntry = array();
11 var $goTimeSource = array();
12 var $goLdapBase = "";
13 var $goXdmcpIsEnabled = "";
14 var $goFontPath = "";
15 var $goNTPServer = "";
16 var $goShareServer = false;
17 var $goLdapServer = "";
18 var $goTerminalServer = "";
19 var $goSyslogServer = "";
20 var $goCupsServer = "";
21 var $goMailServer = "";
22 var $o_subWindow = NULL;
24 /* attribute list for save action */
25 var $ignore_account= TRUE;
26 var $attributes = array("goLdapBase","goXdmcpIsEnabled","goFontPath","goExportEntry","goTimeSource");
27 var $possible_objectclasses= array( "goShareServer", "goNtpServer", "goServer", "goLdapServer",
28 "goTerminalServer", "goSyslogServer", "goCupsServer","goMailServer");
29 var $objectclasses = array( "top","goServer");
30 var $additionaloc = array( "goShareServer" => array("goExportEntry"),
31 "goNtpServer" => array("goTimeSource"),
32 "goLdapServer" => array("goLdapBase"),
33 "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
34 "goSyslogServer" => array(),
35 "goMailServer" => array(),
36 "goCupsServer" => array());
38 function servservice ($config, $dn= NULL)
39 {
40 plugin::plugin ($config, $dn);
42 /* Assemble final object class list */
43 foreach ($this->additionaloc as $oc => $dummy){
44 if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
45 $this->objectclasses[$oc]= $oc;
46 }
47 }
49 /* Load arrays */
50 foreach (array("goTimeSource") as $name){
51 $tmp= array();
52 if (isset($this->attrs[$name])){
53 for ($i= 0; $i<$this->attrs[$name]['count']; $i++){
54 $tmp[$this->attrs[$name][$i]]= $this->attrs[$name][$i];
55 }
56 }
57 $this->$name= $tmp;
58 }
61 $tmp =array();
62 $tmp2=array();
63 if(isset($this->attrs['goExportEntry'])){
64 unset($this->attrs['goExportEntry']['count']);
65 if((isset($this->attrs['goExportEntry']))&&(isset($this->attrs['goExportEntry']))){
66 foreach($this->attrs['goExportEntry'] as $entry){
67 $tmp2= split("\|",$entry);
68 $tmp[$tmp2[0]]= $entry;
69 }
70 }
71 }
72 $this->goExportEntry = $tmp;
74 /* Always is account... */
75 $this->is_account= TRUE;
77 /* Check if goShareServer is defined */
78 if((isset($this->attrs['objectClass']))&&(is_array($this->attrs['objectClass']))){
79 if(in_array("goShareServer",$this->attrs['objectClass'])){
80 $this->goShareServer = true;
81 }
82 }
83 }
85 function addToList($entry){
86 $key = key($entry);
87 $this->goExportEntry[$key]=$entry[$key];
88 }
90 function deleteFromList($id){
91 unset($this->goExportEntry[$id]);
92 }
95 function execute()
96 {
97 /* Call parent execute */
98 plugin::execute();
100 /* Fill templating stuff */
101 $smarty= get_smarty();
103 $smarty->assign("staticAddress", "");
105 if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntry']))){
106 $this->deleteFromList($_POST['goExportEntry']);
107 }
109 if(isset($_POST['NewNfsAdd'])){
110 $this->o_subWindow = new servnfs($this->config, $this->dn);
111 $this->dialog = true;
112 }
114 if((isset($_POST['NewNfsEdit']))&&(isset($_POST['goExportEntry']))){
115 $entry = $this->goExportEntry[$_POST['goExportEntry']];
116 $this->o_subWindow = new servnfs($this->config, $this->dn,$entry);
117 $this->dialog = true;
118 }
120 if(isset($this->o_subWindow)){
121 $this->o_subWindow->save_object(TRUE);
122 }
124 /* Save NFS setup */
125 if(isset($_POST['NFSsave'])){
126 if(count($this->o_subWindow->check())>0){
127 foreach($this->o_subWindow->check() as $msg) {
128 print_red($msg);
129 }
130 }else{
131 $this->o_subWindow->save_object();
132 $newone = $this->o_subWindow->save();
133 $this->addToList($newone) ;
134 unset($this->o_subWindow);
135 $this->dialog = false;
136 }
137 }
139 /* Cancel NFS setup */
140 if(isset($_POST['NFScancel'])){
141 unset($this->o_subWindow);
142 $this->dialog = false;
143 }
145 /* Execute NFS setup dialog*/
146 if(isset($this->o_subWindow)){
147 return $this->o_subWindow->execute();
148 }
150 /* Here we add a new entry */
151 if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
152 $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
153 asort($this->goTimeSource);
154 }
156 /* Deleting an Entry, is a bit more complicated than adding one*/
157 if(isset($_POST['DelNTPEnt'])) {
158 foreach ($_POST['goTimeSource'] as $entry){
159 if (isset($this->goTimeSource[$entry])){
160 unset($this->goTimeSource[$entry]);
161 }
162 }
163 }
165 /* Attributes */
166 foreach ($this->attributes as $attr){
167 $smarty->assign("$attr", $this->$attr);
168 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
169 $smarty->assign($attr."State","");
170 }
172 $tellSmarty=array();
173 foreach($this->goExportEntry as $name=>$values){
174 $tmp = split("\|",$values);
175 $tellSmarty[$name] = $tmp[0]." ".$tmp[4];
176 }
177 $smarty->assign("goExportEntry",array_keys($tellSmarty));
178 $smarty->assign("goExportEntryKeys",($tellSmarty));
179 $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
181 $smarty->assign("goTimeSource", $this->goTimeSource);
182 $smarty->assign("goTimeSourceACL", chkacl($this->acl, "goTimeSource"));
183 $smarty->assign("goTimeSourceState","");
186 /* Classes... */
187 foreach ($this->additionaloc as $oc => $dummy){
188 if (isset($this->objectclasses[$oc])){
189 $smarty->assign("$oc", "checked");
190 $smarty->assign("$oc"."State", "");
191 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
193 } else {
194 $smarty->assign("$oc", "");
195 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
196 $smarty->assign("$oc"."State", "disabled");
197 }
198 }
200 if(!$this->goShareServer){
201 $smarty->assign("goShareServerState", " disabled ");
202 $smarty->assign("goExportEntryACL", " disabled ");
203 }else{
204 $smarty->assign("goShareServerState", " ");
205 $smarty->assign("goExportEntryACL", " ");
206 }
208 /* Different handling for checkbox */
209 if($this->goXdmcpIsEnabled == "true"){
210 $smarty->assign("goXdmcpIsEnabled","checked");
211 } else {
212 $smarty->assign("goXdmcpIsEnabled","");
213 }
215 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
216 }
219 function remove_from_parent()
220 {
221 /* This cannot be removed... */
222 }
225 /* Save data to object */
226 function save_object()
227 {
228 if (isset($_POST['servicetab'])){
229 plugin::save_object();
231 /* Save checkbox state */
232 foreach ($this->additionaloc as $oc => $dummy){
233 if (chkacl($this->acl, $oc) == ""){
234 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
235 $this->objectclasses[$oc]= $oc;
236 } else {
237 unset($this->objectclasses[$oc]);
238 }
239 }
240 }
242 /* Save xdmcp is enabled flag */
243 if (isset($_POST['goXdmcpIsEnabled'])){
244 $this->goXdmcpIsEnabled= "true";
245 } else {
246 $this->goXdmcpIsEnabled= "false";
247 }
249 /* Save xdmcp is enabled flag */
250 if (isset($_POST['goShareServer'])){
251 $this->goShareServer = true;
252 } else {
253 $this->goShareServer = false;
254 }
255 }
256 }
259 /* Check supplied data */
260 function check()
261 {
262 $message= array();
264 if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
265 $message[]=_("Terminal server, must have fontpath specified.");
266 }
268 return ($message);
269 }
272 /* Save to LDAP */
273 function save()
274 {
275 plugin::save();
277 $tmp= array();
279 /* Remove all from this plugin */
280 foreach($this->attrs['objectClass'] as $oc){
281 if (!in_array_ics($oc, $this->possible_objectclasses)){
282 $tmp[]= $oc;
283 }
284 }
286 /* Merge our current objectclasses */
287 foreach($this->objectclasses as $oc){
288 if (!in_array_ics($oc, $tmp)){
289 $tmp[]= $oc;
290 }
291 }
293 /* Reassign cleaned value */
294 $this->attrs['objectClass']= $tmp;
296 /* Arrays */
297 foreach (array("goTimeSource", "goExportEntry") as $name){
298 $this->attrs[$name]= array();
299 foreach ($this->$name as $element){
300 $this->attrs[$name][]= $element;
301 }
302 }
304 /* Remove illegal attributes */
305 foreach ($this->additionaloc as $oc => $attrs){
306 if (!in_array($oc, $this->objectclasses)){
307 foreach ($attrs as $attr){
308 $this->attrs[$attr]= array();
309 }
310 }
311 }
313 /* Write to LDAP */
314 $ldap= $this->config->get_ldap_link();
315 $ldap->cd($this->dn);
316 $this->cleanup();
317 $ldap->modify ($this->attrs);
319 show_ldap_error($ldap->get_error());
321 /* Optionally execute a command after we're done */
322 if ($this->initially_was_account == $this->is_account){
323 if ($this->is_modified){
324 $this->handle_post_events("mofify");
325 }
326 } else {
327 $this->handle_post_events("add");
328 }
329 }
331 }
333 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
334 ?>