e4984e3dead1910763bc60a64a5bba0fdf7d78d1
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", "GOhard", "goLdapServer",
28 "goTerminalServer", "goSyslogServer", "goCupsServer","goMailServer");
29 var $objectclasses = array( "top","goServer", "GOhard");
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 ksort($this->goExportEntry);
174 foreach($this->goExportEntry as $name=>$values){
175 $tmp = split("\|",$values);
176 $tellSmarty[$name] = $tmp[0]." ".$tmp[4];
177 }
178 $smarty->assign("goExportEntry",array_keys($tellSmarty));
179 $smarty->assign("goExportEntryKeys",($tellSmarty));
180 $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
182 $smarty->assign("goTimeSource", $this->goTimeSource);
183 $smarty->assign("goTimeSourceACL", chkacl($this->acl, "goTimeSource"));
184 $smarty->assign("goTimeSourceState","");
187 /* Classes... */
188 foreach ($this->additionaloc as $oc => $dummy){
189 if (isset($this->objectclasses[$oc])){
190 $smarty->assign("$oc", "checked");
191 $smarty->assign("$oc"."State", "");
192 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
194 } else {
195 $smarty->assign("$oc", "");
196 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
197 $smarty->assign("$oc"."State", "disabled");
198 }
199 }
201 if(!$this->goShareServer){
202 $smarty->assign("goShareServerState", " disabled ");
203 $smarty->assign("goExportEntryACL", " disabled ");
204 }else{
205 $smarty->assign("goShareServerState", " ");
206 $smarty->assign("goExportEntryACL", " ");
207 }
209 /* Different handling for checkbox */
210 if($this->goXdmcpIsEnabled == "true"){
211 $smarty->assign("goXdmcpIsEnabled","checked");
212 } else {
213 $smarty->assign("goXdmcpIsEnabled","");
214 }
216 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
217 }
220 function remove_from_parent()
221 {
222 /* This cannot be removed... */
223 }
226 /* Save data to object */
227 function save_object()
228 {
229 if (isset($_POST['servicetab'])){
230 $tmp = $this->goTimeSource;
232 if(isset($_POST['goLdapBase'])){
233 $this->goLdapBase = $_POST['goLdapBase'];
234 }
236 /* Save checkbox state */
237 foreach ($this->additionaloc as $oc => $dummy){
238 // if($oc == "goNtpServer") continue;
239 if (chkacl($this->acl, $oc) == ""){
240 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
241 $this->objectclasses[$oc]= $oc;
242 } else {
243 unset($this->objectclasses[$oc]);
244 }
245 }
246 }
248 /* Save xdmcp is enabled flag */
249 if (isset($_POST['goXdmcpIsEnabled'])){
250 $this->goXdmcpIsEnabled= "true";
251 } else {
252 $this->goXdmcpIsEnabled= "false";
253 }
255 /* Save xdmcp is enabled flag */
256 if (isset($_POST['goShareServer'])){
257 $this->goShareServer = true;
258 } else {
259 $this->goShareServer = false;
260 }
261 $this->goTimeSource = array();
262 $this->goTimeSource = $tmp;
263 }
264 }
267 /* Check supplied data */
268 function check()
269 {
270 /* Call common method to give check the hook */
271 $message= plugin::check();
273 if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
274 $message[]=_("Terminal server, must have fontpath specified.");
275 }
277 return ($message);
278 }
281 /* Save to LDAP */
282 function save()
283 {
284 plugin::save();
286 $tmp= array();
288 /* Remove all from this plugin */
289 foreach($this->attrs['objectClass'] as $oc){
290 if (!in_array_ics($oc, $this->possible_objectclasses)){
291 $tmp[]= $oc;
292 }
293 }
295 /* Merge our current objectclasses */
296 foreach($this->objectclasses as $oc){
297 if (!in_array_ics($oc, $tmp)){
298 $tmp[]= $oc;
299 }
300 }
302 /* Reassign cleaned value */
303 $this->attrs['objectClass']= $tmp;
305 /* Arrays */
306 foreach (array("goTimeSource", "goExportEntry") as $name){
307 $this->attrs[$name]= array();
308 foreach ($this->$name as $element){
309 $this->attrs[$name][]= $element;
310 }
311 }
313 /* Remove illegal attributes */
314 foreach ($this->additionaloc as $oc => $attrs){
315 if (!in_array($oc, $this->objectclasses)){
316 foreach ($attrs as $attr){
317 $this->attrs[$attr]= array();
318 }
319 }
320 }
322 /* Write to LDAP */
323 $ldap= $this->config->get_ldap_link();
324 $ldap->cd($this->dn);
325 $this->cleanup();
326 $ldap->modify ($this->attrs);
328 show_ldap_error($ldap->get_error());
330 /* Optionally execute a command after we're done */
331 if ($this->initially_was_account == $this->is_account){
332 if ($this->is_modified){
333 $this->handle_post_events("mofify");
334 }
335 } else {
336 $this->handle_post_events("add");
337 }
338 }
340 }
342 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
343 ?>