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 $o_subWindow = NULL;
23 /* attribute list for save action */
24 var $ignore_account= TRUE;
25 var $attributes = array("goLdapBase","goXdmcpIsEnabled","goFontPath");
26 var $possible_objectclasses= array( "goShareServer", "goNtpServer", "goServer", "goLdapServer",
27 "goTerminalServer", "goSyslogServer", "goCupsServer");
28 var $objectclasses = array( "top","goServer");
29 var $additionaloc = array( "goShareServer" => array("goExportEntry"),
30 "goNtpServer" => array("goTimeSource"),
31 "goLdapServer" => array("goLdapBase"),
32 "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
33 "goSyslogServer" => array(),
34 "goCupsServer" => array());
36 function servservice ($config, $dn= NULL)
37 {
38 plugin::plugin ($config, $dn);
40 /* Assemble final object class list */
41 foreach ($this->additionaloc as $oc => $dummy){
42 if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
43 $this->objectclasses[$oc]= $oc;
44 }
45 }
47 /* Load arrays */
48 foreach (array("goTimeSource") as $name){
49 $tmp= array();
50 if (isset($this->attrs[$name])){
51 for ($i= 0; $i<$this->attrs[$name]['count']; $i++){
52 $tmp[$this->attrs[$name][$i]]= $this->attrs[$name][$i];
53 }
54 }
55 $this->$name= $tmp;
56 }
58 $tmp =array();
59 $tmp2=array();
60 if(isset($this->attrs['goExportEntry'])){
61 unset($this->attrs['goExportEntry']['count']);
62 if((isset($this->attrs['goExportEntry']))&&(isset($this->attrs['goExportEntry']))){
63 foreach($this->attrs['goExportEntry'] as $entry){
64 $tmp2= split("\|",$entry);
65 $tmp[$tmp2[0]]= $entry;
66 }
67 }
68 }
69 $this->goExportEntry = $tmp;
71 /* Always is account... */
72 $this->is_account= TRUE;
74 /* Check if goShareServer is defined */
75 if((isset($this->attrs['objectClass']))&&(is_array($this->attrs['objectClass']))){
76 if(in_array("goShareServer",$this->attrs['objectClass'])){
77 $this->goShareServer = true;
78 }
79 }
80 }
82 function addToList($entry){
83 $key = key($entry);
84 $this->goExportEntry[$key]=$entry[$key];
85 }
87 function deleteFromList($id){
88 unset($this->goExportEntry[$id]);
89 }
92 function execute()
93 {
94 /* Call parent execute */
95 plugin::execute();
96 /* Fill templating stuff */
97 $smarty= get_smarty();
99 $smarty->assign("staticAddress", "");
101 if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntry']))){
102 $this->deleteFromList($_POST['goExportEntry']);
103 }
105 if(isset($_POST['NewNfsAdd'])){
106 $this->o_subWindow = new servnfs($this->config, $this->dn);
107 $this->dialog = true;
108 }
110 if((isset($_POST['NewNfsEdit']))&&(isset($_POST['goExportEntry']))){
111 $entry = $this->goExportEntry[$_POST['goExportEntry']];
112 $this->o_subWindow = new servnfs($this->config, $this->dn,$entry);
113 $this->dialog = true;
114 }
116 if(isset($this->o_subWindow)){
117 $this->o_subWindow->save_object(TRUE);
118 }
120 /* Save NFS setup */
121 if(isset($_POST['NFSsave'])){
122 if(count($this->o_subWindow->check())>0){
123 foreach($this->o_subWindow->check() as $msg) {
124 print_red($msg);
125 }
126 }else{
127 $this->o_subWindow->save_object();
128 $newone = $this->o_subWindow->save();
129 $this->addToList($newone) ;
130 unset($this->o_subWindow);
131 $this->dialog = false;
132 }
133 }
135 /* Cancel NFS setup */
136 if(isset($_POST['NFScancel'])){
137 unset($this->o_subWindow);
138 $this->dialog = false;
139 }
141 /* Execute NFS setup dialog*/
142 if(isset($this->o_subWindow)){
143 return $this->o_subWindow->execute();
144 }
146 /* Here we add a new entry */
147 if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
148 $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
149 asort($this->goTimeSource);
150 }
152 /* Deleting an Entry, is a bit more complicated than adding one*/
153 if(isset($_POST['DelNTPEnt'])) {
154 foreach ($_POST['goTimeSource'] as $entry){
155 if (isset($this->goTimeSource[$entry])){
156 unset($this->goTimeSource[$entry]);
157 }
158 }
159 }
161 /* Attributes */
162 foreach ($this->attributes as $attr){
163 $smarty->assign("$attr", $this->$attr);
164 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
165 $smarty->assign($attr."State","");
166 }
168 $tellSmarty=array();
169 foreach($this->goExportEntry as $name=>$values){
170 $tmp = split("\|",$values);
171 $tellSmarty[$name] = $tmp[0]." ".$tmp[4];
172 }
173 $smarty->assign("goExportEntry",array_keys($tellSmarty));
174 $smarty->assign("goExportEntryKeys",($tellSmarty));
175 $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
177 $smarty->assign("goTimeSource", $this->goTimeSource);
178 $smarty->assign("goTimeSourceACL", chkacl($this->acl, "goTimeSource"));
179 $smarty->assign("goTimeSourceState","");
182 /* Classes... */
183 foreach ($this->additionaloc as $oc => $dummy){
184 if (isset($this->objectclasses[$oc])){
185 $smarty->assign("$oc", "checked");
186 $smarty->assign("$oc"."State", "");
187 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
189 } else {
190 $smarty->assign("$oc", "");
191 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
192 $smarty->assign("$oc"."State", "disabled");
193 }
194 }
196 if(!$this->goShareServer){
197 $smarty->assign("goShareServerState", " disabled ");
198 $smarty->assign("goExportEntryACL", " disabled ");
199 }else{
200 $smarty->assign("goShareServerState", " ");
201 $smarty->assign("goExportEntryACL", " ");
202 }
204 /* Different handling for checkbox */
205 if($this->goXdmcpIsEnabled == "true"){
206 $smarty->assign("goXdmcpIsEnabled","checked");
207 } else {
208 $smarty->assign("goXdmcpIsEnabled","");
209 }
211 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
212 }
215 function remove_from_parent()
216 {
217 /* This cannot be removed... */
218 }
221 /* Save data to object */
222 function save_object()
223 {
224 if (isset($_POST['servicetab'])){
225 plugin::save_object();
227 /* Save checkbox state */
228 foreach ($this->additionaloc as $oc => $dummy){
229 if (chkacl($this->acl, $oc) == ""){
230 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
231 $this->objectclasses[$oc]= $oc;
232 } else {
233 unset($this->objectclasses[$oc]);
234 }
235 }
236 }
238 /* Save xdmcp is enabled flag */
239 if (isset($_POST['goXdmcpIsEnabled'])){
240 $this->goXdmcpIsEnabled= "true";
241 } else {
242 $this->goXdmcpIsEnabled= "false";
243 }
245 /* Save xdmcp is enabled flag */
246 if (isset($_POST['goShareServer'])){
247 $this->goShareServer = true;
248 } else {
249 $this->goShareServer = false;
250 }
251 }
252 }
255 /* Check supplied data */
256 function check()
257 {
258 $message= array();
260 if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
261 $message[]=_("Terminal server, must have fontpath specified.");
262 }
264 return ($message);
265 }
268 /* Save to LDAP */
269 function save()
270 {
271 plugin::save();
273 $tmp= array();
275 /* Remove all from this plugin */
276 foreach($this->attrs['objectClass'] as $oc){
277 if (!in_array_ics($oc, $this->possible_objectclasses)){
278 $tmp[]= $oc;
279 }
280 }
282 /* Merge our current objectclasses */
283 foreach($this->objectclasses as $oc){
284 if (!in_array_ics($oc, $tmp)){
285 $tmp[]= $oc;
286 }
287 }
289 /* Reassign cleaned value */
290 $this->attrs['objectClass']= $tmp;
292 /* Arrays */
293 foreach (array("goTimeSource", "goExportEntry") as $name){
294 $this->attrs[$name]= array();
295 foreach ($this->$name as $element){
296 $this->attrs[$name][]= $element;
297 }
298 }
300 /* Remove illegal attributes */
301 foreach ($this->additionaloc as $oc => $attrs){
302 if (!in_array($oc, $this->objectclasses)){
303 foreach ($attrs as $attr){
304 $this->attrs[$attr]= array();
305 }
306 }
307 }
309 /* Write to LDAP */
310 $ldap= $this->config->get_ldap_link();
311 $ldap->cd($this->dn);
312 $ldap->modify($this->attrs);
313 show_ldap_error($ldap->get_error());
315 /* Optionally execute a command after we're done */
316 if ($this->initially_was_account == $this->is_account){
317 if ($this->is_modified){
318 $this->handle_post_events("mofify");
319 }
320 } else {
321 $this->handle_post_events("add");
322 }
323 }
325 }
327 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
328 ?>