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 /* Fill templating stuff */
95 $smarty= get_smarty();
97 $smarty->assign("staticAddress", "");
99 if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntry']))){
100 $this->deleteFromList($_POST['goExportEntry']);
101 }
103 if(isset($_POST['NewNfsAdd'])){
104 $this->o_subWindow = new servnfs($this->config, $this->dn);
105 $this->dialog = true;
106 }
108 if((isset($_POST['NewNfsEdit']))&&(isset($_POST['goExportEntry']))){
109 $entry = $this->goExportEntry[$_POST['goExportEntry']];
110 $this->o_subWindow = new servnfs($this->config, $this->dn,$entry);
111 $this->dialog = true;
112 }
114 if(isset($this->o_subWindow)){
115 $this->o_subWindow->save_object(TRUE);
116 }
118 /* Save NFS setup */
119 if(isset($_POST['NFSsave'])){
120 if(count($this->o_subWindow->check())>0){
121 foreach($this->o_subWindow->check() as $msg) {
122 print_red($msg);
123 }
124 }else{
125 $this->o_subWindow->save_object();
126 $newone = $this->o_subWindow->save();
127 $this->addToList($newone) ;
128 unset($this->o_subWindow);
129 $this->dialog = false;
130 }
131 }
133 /* Cancel NFS setup */
134 if(isset($_POST['NFScancel'])){
135 unset($this->o_subWindow);
136 $this->dialog = false;
137 }
139 /* Execute NFS setup dialog*/
140 if(isset($this->o_subWindow)){
141 return $this->o_subWindow->execute();
142 }
144 /* Here we add a new entry */
145 if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
146 $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
147 asort($this->goTimeSource);
148 }
150 /* Deleting an Entry, is a bit more complicated than adding one*/
151 if(isset($_POST['DelNTPEnt'])) {
152 foreach ($_POST['goTimeSource'] as $entry){
153 if (isset($this->goTimeSource[$entry])){
154 unset($this->goTimeSource[$entry]);
155 }
156 }
157 }
159 /* Attributes */
160 foreach ($this->attributes as $attr){
161 $smarty->assign("$attr", $this->$attr);
162 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
163 $smarty->assign($attr."State","");
164 }
166 $tellSmarty=array();
167 foreach($this->goExportEntry as $name=>$values){
168 $tmp = split("\|",$values);
169 $tellSmarty[$name] = $tmp[0]." ".$tmp[4];
170 }
171 $smarty->assign("goExportEntry",array_keys($tellSmarty));
172 $smarty->assign("goExportEntryKeys",($tellSmarty));
173 $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
175 $smarty->assign("goTimeSource", $this->goTimeSource);
176 $smarty->assign("goTimeSourceACL", chkacl($this->acl, "goTimeSource"));
177 $smarty->assign("goTimeSourceState","");
180 /* Classes... */
181 foreach ($this->additionaloc as $oc => $dummy){
182 if (isset($this->objectclasses[$oc])){
183 $smarty->assign("$oc", "checked");
184 $smarty->assign("$oc"."State", "");
185 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
187 } else {
188 $smarty->assign("$oc", "");
189 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
190 $smarty->assign("$oc"."State", "disabled");
191 }
192 }
194 if(!$this->goShareServer){
195 $smarty->assign("goShareServerState", " disabled ");
196 $smarty->assign("goExportEntryACL", " disabled ");
197 }else{
198 $smarty->assign("goShareServerState", " ");
199 $smarty->assign("goExportEntryACL", " ");
200 }
202 /* Different handling for checkbox */
203 if($this->goXdmcpIsEnabled == "true"){
204 $smarty->assign("goXdmcpIsEnabled","checked");
205 } else {
206 $smarty->assign("goXdmcpIsEnabled","");
207 }
209 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
210 }
213 function remove_from_parent()
214 {
215 /* This cannot be removed... */
216 }
219 /* Save data to object */
220 function save_object()
221 {
222 if (isset($_POST['servicetab'])){
223 plugin::save_object();
225 /* Save checkbox state */
226 foreach ($this->additionaloc as $oc => $dummy){
227 if (chkacl($this->acl, $oc) == ""){
228 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
229 $this->objectclasses[$oc]= $oc;
230 } else {
231 unset($this->objectclasses[$oc]);
232 }
233 }
234 }
236 /* Save xdmcp is enabled flag */
237 if (isset($_POST['goXdmcpIsEnabled'])){
238 $this->goXdmcpIsEnabled= "true";
239 } else {
240 $this->goXdmcpIsEnabled= "false";
241 }
243 /* Save xdmcp is enabled flag */
244 if (isset($_POST['goShareServer'])){
245 $this->goShareServer = true;
246 } else {
247 $this->goShareServer = false;
248 }
249 }
250 }
253 /* Check supplied data */
254 function check()
255 {
256 $message= array();
258 if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
259 $message[]=_("Terminal server, must have fontpath specified.");
260 }
262 return ($message);
263 }
266 /* Save to LDAP */
267 function save()
268 {
269 plugin::save();
271 $tmp= array();
273 /* Remove all from this plugin */
274 foreach($this->attrs['objectClass'] as $oc){
275 if (!in_array_ics($oc, $this->possible_objectclasses)){
276 $tmp[]= $oc;
277 }
278 }
280 /* Merge our current objectclasses */
281 foreach($this->objectclasses as $oc){
282 if (!in_array_ics($oc, $tmp)){
283 $tmp[]= $oc;
284 }
285 }
287 /* Reassign cleaned value */
288 $this->attrs['objectClass']= $tmp;
290 /* Arrays */
291 foreach (array("goTimeSource", "goExportEntry") as $name){
292 $this->attrs[$name]= array();
293 foreach ($this->$name as $element){
294 $this->attrs[$name][]= $element;
295 }
296 }
298 /* Remove illegal attributes */
299 foreach ($this->additionaloc as $oc => $attrs){
300 if (!in_array($oc, $this->objectclasses)){
301 foreach ($attrs as $attr){
302 $this->attrs[$attr]= array();
303 }
304 }
305 }
307 /* Write to LDAP */
308 $ldap= $this->config->get_ldap_link();
309 $ldap->cd($this->dn);
310 $ldap->modify($this->attrs);
311 show_ldap_error($ldap->get_error());
313 /* Optionally execute a command after we're done */
314 if ($this->initially_was_account == $this->is_account){
315 if ($this->is_modified){
316 $this->handle_post_events("mofify");
317 }
318 } else {
319 $this->handle_post_events("add");
320 }
321 }
323 }
325 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
326 ?>