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 = "";
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 unset($this->attrs['goExportEntry']['count']);
61 if((isset($this->attrs['goExportEntry']))&&(isset($this->attrs['goExportEntry']))){
62 foreach($this->attrs['goExportEntry'] as $entry){
63 $tmp2= split("\|",$entry);
64 $tmp[$tmp2[0]]= $entry;
65 }
66 }
67 $this->goExportEntry = $tmp;
69 /* Always is account... */
70 $this->is_account= TRUE;
71 }
73 function addToList($entry){
74 $key = key($entry);
75 $this->goExportEntry[$key]=$entry[$key];
76 }
78 function deleteFromList($id){
79 unset($this->goExportEntry[$id]);
80 }
83 function execute()
84 {
85 /* Fill templating stuff */
86 $smarty= get_smarty();
88 $smarty->assign("staticAddress", "");
90 if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntry']))){
91 $this->deleteFromList($_POST['goExportEntry']);
92 }
94 if(isset($_POST['NewNfsAdd'])){
95 $this->o_subWindow = new servnfs($this->config, $this->dn);
96 $this->dialog = true;
97 }
99 if((isset($_POST['NewNfsEdit']))&&(isset($_POST['goExportEntry']))){
100 $entry = $this->goExportEntry[$_POST['goExportEntry']];
101 $this->o_subWindow = new servnfs($this->config, $this->dn,$entry);
102 $this->dialog = true;
103 }
105 if(isset($this->o_subWindow)){
106 $this->o_subWindow->save_object(TRUE);
107 }
109 /* Save NFS setup */
110 if(isset($_POST['NFSsave'])){
111 if(count($this->o_subWindow->check())>0){
112 foreach($this->o_subWindow->check() as $msg) {
113 print_red($msg);
114 }
115 }else{
116 $this->o_subWindow->save_object();
117 $newone = $this->o_subWindow->save();
118 $this->addToList($newone) ;
119 unset($this->o_subWindow);
120 $this->dialog = false;
121 }
122 }
124 /* Cancel NFS setup */
125 if(isset($_POST['NFScancel'])){
126 unset($this->o_subWindow);
127 $this->dialog = false;
128 }
130 /* Execute NFS setup dialog*/
131 if(isset($this->o_subWindow)){
132 return $this->o_subWindow->execute();
133 }
135 /* Here we add a new entry */
136 if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
137 $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
138 asort($this->goTimeSource);
139 }
141 /* Deleting an Entry, is a bit more complicated than adding one*/
142 if(isset($_POST['DelNTPEnt'])) {
143 foreach ($_POST['goTimeSource'] as $entry){
144 if (isset($this->goTimeSource[$entry])){
145 unset($this->goTimeSource[$entry]);
146 }
147 }
148 }
150 /* Attributes */
151 foreach ($this->attributes as $attr){
152 $smarty->assign("$attr", $this->$attr);
153 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
154 $smarty->assign($attr."State","");
155 }
157 $tellSmarty=array();
158 foreach($this->goExportEntry as $name=>$values){
159 $tmp = split("\|",$values);
160 $tellSmarty[$name] = $tmp[0]." ".$tmp[4];
161 }
162 $smarty->assign("goExportEntry",array_keys($tellSmarty));
163 $smarty->assign("goExportEntryKeys",($tellSmarty));
164 $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
166 $smarty->assign("goTimeSource", $this->goTimeSource);
167 $smarty->assign("goTimeSourceACL", chkacl($this->acl, "goTimeSource"));
168 $smarty->assign("goTimeSourceState","");
171 /* Classes... */
172 foreach ($this->additionaloc as $oc => $dummy){
173 if (isset($this->objectclasses[$oc])){
174 $smarty->assign("$oc", "checked");
175 $smarty->assign("$oc"."State", "");
176 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
178 } else {
179 $smarty->assign("$oc", "");
180 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
181 $smarty->assign("$oc"."State", "disabled");
182 }
183 }
185 if(!count($this->goExportEntry)){
186 $smarty->assign("goShareServerState", " disabled ");
187 }
189 /* Different handling for checkbox */
190 if($this->goXdmcpIsEnabled == "true"){
191 $smarty->assign("goXdmcpIsEnabled","checked");
192 } else {
193 $smarty->assign("goXdmcpIsEnabled","");
194 }
196 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
197 }
200 function remove_from_parent()
201 {
202 /* This cannot be removed... */
203 }
206 /* Save data to object */
207 function save_object()
208 {
209 if (isset($_POST['servicetab'])){
210 plugin::save_object();
212 /* Save checkbox state */
213 foreach ($this->additionaloc as $oc => $dummy){
214 if (chkacl($this->acl, $oc) == ""){
215 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
216 $this->objectclasses[$oc]= $oc;
217 } else {
218 unset($this->objectclasses[$oc]);
219 }
220 }
221 }
223 /* Save xdmcp is enabled flag */
224 if (isset($_POST['goXdmcpIsEnabled'])){
225 $this->goXdmcpIsEnabled= "true";
226 } else {
227 $this->goXdmcpIsEnabled= "false";
228 }
230 }
231 }
234 /* Check supplied data */
235 function check()
236 {
237 $message= array();
239 if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
240 $message[]=_("Terminal server, must have fontpath specified.");
241 }
243 return ($message);
244 }
247 /* Save to LDAP */
248 function save()
249 {
250 plugin::save();
252 $tmp= array();
254 /* Remove all from this plugin */
255 foreach($this->attrs['objectClass'] as $oc){
256 if (!in_array_ics($oc, $this->possible_objectclasses)){
257 $tmp[]= $oc;
258 }
259 }
261 /* Merge our current objectclasses */
262 foreach($this->objectclasses as $oc){
263 if (!in_array_ics($oc, $tmp)){
264 $tmp[]= $oc;
265 }
266 }
268 /* Reassign cleaned value */
269 $this->attrs['objectClass']= $tmp;
271 /* Arrays */
272 foreach (array("goTimeSource", "goExportEntry") as $name){
273 $this->attrs[$name]= array();
274 foreach ($this->$name as $element){
275 $this->attrs[$name][]= $element;
276 }
277 }
279 /* Remove illegal attributes */
280 foreach ($this->additionaloc as $oc => $attrs){
281 if (!in_array($oc, $this->objectclasses)){
282 foreach ($attrs as $attr){
283 $this->attrs[$attr]= array();
284 }
285 }
286 }
288 /* Write to LDAP */
289 $ldap= $this->config->get_ldap_link();
290 $ldap->cd($this->dn);
291 $ldap->modify($this->attrs);
292 show_ldap_error($ldap->get_error());
294 /* Optionally execute a command after we're done */
295 if ($this->initially_was_account == $this->is_account){
296 if ($this->is_modified){
297 $this->handle_post_events("mofify");
298 }
299 } else {
300 $this->handle_post_events("add");
301 }
302 }
304 }
306 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
307 ?>