2024df2847e569bb3b0947b61c9539c3ed8cc2cf
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 $goLdapServer="";
17 var $goTerminalServer="";
18 var $goSyslogServer="";
19 var $goCupsServer="";
20 var $o_subWindow = NULL;
22 /* attribute list for save action */
23 var $ignore_account= TRUE;
24 var $attributes = array("goLdapBase","goXdmcpIsEnabled","goFontPath");
25 var $possible_objectclasses= array( "goShareServer", "goNtpServer", "goServer", "goLdapServer",
26 "goTerminalServer", "goSyslogServer", "goCupsServer");
27 var $objectclasses = array("top","goServer");
28 var $additionaloc = array( "goShareServer" => array("goExportEntry"),
29 "goNtpServer" => array("goTimeSource"),
30 "goLdapServer" => array("goLdapBase"),
31 "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
32 "goSyslogServer" => array(),
33 "goCupsServer" => array());
35 function servservice ($config, $dn= NULL)
36 {
37 plugin::plugin ($config, $dn);
39 /* Assemble final object class list */
40 foreach ($this->additionaloc as $oc => $dummy){
41 if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
42 $this->objectclasses[$oc]= $oc;
43 }
44 }
46 /* Load arrays */
47 foreach (array("goTimeSource") as $name){
48 $tmp= array();
49 if (isset($this->attrs[$name])){
50 for ($i= 0; $i<$this->attrs[$name]['count']; $i++){
51 $tmp[$this->attrs[$name][$i]]= $this->attrs[$name][$i];
52 }
53 }
54 $this->$name= $tmp;
55 }
57 $tmp =array();
58 $tmp2=array();
59 unset($this->attrs['goExportEntry']['count']);
60 if((isset($this->attrs['goExportEntry']))&&(isset($this->attrs['goExportEntry']))){
61 foreach($this->attrs['goExportEntry'] as $entry){
62 $tmp2= split("\|",$entry);
63 $tmp[$tmp2[0]]= $entry;
64 }
65 }
66 $this->goExportEntry = $tmp;
68 /* Always is account... */
69 $this->is_account= TRUE;
70 }
72 function addToList($entry){
73 $key = key($entry);
74 $this->goExportEntry[$key]=$entry[$key];
75 }
77 function deleteFromList($id){
78 unset($this->goExportEntry[$id]);
79 }
82 function execute()
83 {
84 /* Fill templating stuff */
85 $smarty= get_smarty();
87 $smarty->assign("staticAddress", "");
89 if((isset($_POST['DelNfsEnt']))&&(isset($_POST['goExportEntry']))){
90 $this->deleteFromList($_POST['goExportEntry']);
91 }
93 if(isset($_POST['NewNfsAdd'])){
94 $this->o_subWindow = new servnfs($this->config, $this->dn);
95 $this->dialog = true;
96 }
98 if((isset($_POST['NewNfsEdit']))&&(isset($_POST['goExportEntry']))){
99 $entry = $this->goExportEntry[$_POST['goExportEntry']];
100 $this->o_subWindow = new servnfs($this->config, $this->dn,$entry);
101 $this->dialog = true;
102 }
104 if(isset($this->o_subWindow)){
105 $this->o_subWindow->save_object(TRUE);
106 }
108 /* Save NFS setup */
109 if(isset($_POST['NFSsave'])){
110 if(count($this->o_subWindow->check())>0){
111 foreach($this->o_subWindow->check() as $msg) {
112 print_red($msg);
113 }
114 }else{
115 $this->o_subWindow->save_object();
116 $newone = $this->o_subWindow->save();
117 $this->addToList($newone) ;
118 unset($this->o_subWindow);
119 $this->dialog = false;
120 }
121 }
123 /* Cancel NFS setup */
124 if(isset($_POST['NFScancel'])){
125 unset($this->o_subWindow);
126 $this->dialog = false;
127 }
129 /* Execute NFS setup dialog*/
130 if(isset($this->o_subWindow)){
131 return $this->o_subWindow->execute();
132 }
134 /* Here we add a new entry */
135 if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
136 $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
137 asort($this->goTimeSource);
138 }
140 /* Deleting an Entry, is a bit more complicated than adding one*/
141 if(isset($_POST['DelNTPEnt'])) {
142 foreach ($_POST['goTimeSource'] as $entry){
143 if (isset($this->goTimeSource[$entry])){
144 unset($this->goTimeSource[$entry]);
145 }
146 }
147 }
149 /* Attributes */
150 foreach ($this->attributes as $attr){
151 $smarty->assign("$attr", $this->$attr);
152 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
153 $smarty->assign($attr."State","");
154 }
156 $tellSmarty=array();
157 foreach($this->goExportEntry as $name=>$values){
158 $tmp = split("\|",$values);
159 $tellSmarty[$name] = $tmp[0]." ".$tmp[4];
160 }
161 $smarty->assign("goExportEntry",array_keys($tellSmarty));
162 $smarty->assign("goExportEntryKeys",($tellSmarty));
163 $smarty->assign("goExportEntryACL", chkacl($this->acl, "goExportEntry"));
165 $smarty->assign("goTimeSource", $this->goTimeSource);
166 $smarty->assign("goTimeSourceACL", chkacl($this->acl, "goTimeSource"));
167 $smarty->assign("goTimeSourceState","");
170 /* Classes... */
171 foreach ($this->additionaloc as $oc => $dummy){
172 if (isset($this->objectclasses[$oc])){
173 $smarty->assign("$oc", "checked");
174 $smarty->assign("$oc"."State", "");
175 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
177 } else {
178 $smarty->assign("$oc", "");
179 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
180 $smarty->assign("$oc"."State", "disabled");
181 }
182 }
184 if(!count($this->goExportEntry)){
185 $smarty->assign("goShareServerState", " disabled ");
186 }
188 /* Different handling for checkbox */
189 if($this->goXdmcpIsEnabled == "true"){
190 $smarty->assign("goXdmcpIsEnabled","checked");
191 } else {
192 $smarty->assign("goXdmcpIsEnabled","");
193 }
195 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
196 }
199 function remove_from_parent()
200 {
201 /* This cannot be removed... */
202 }
205 /* Save data to object */
206 function save_object()
207 {
208 if (isset($_POST['servicetab'])){
209 plugin::save_object();
211 /* Save checkbox state */
212 foreach ($this->additionaloc as $oc => $dummy){
213 if (chkacl($this->acl, $oc) == ""){
214 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
215 $this->objectclasses[$oc]= $oc;
216 } else {
217 unset($this->objectclasses[$oc]);
218 }
219 }
220 }
222 /* Save xdmcp is enabled flag */
223 if (isset($_POST['goXdmcpIsEnabled'])){
224 $this->goXdmcpIsEnabled= "true";
225 } else {
226 $this->goXdmcpIsEnabled= "false";
227 }
229 }
230 }
233 /* Check supplied data */
234 function check()
235 {
236 $message= array();
238 if((isset($_POST['goTerminalServer']))&&(empty($this->goFontPath))){
239 $message[]=_("Terminal server, must have fontpath specified.");
240 }
242 return ($message);
243 }
246 /* Save to LDAP */
247 function save()
248 {
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 }
287 $oc = array();
288 foreach($this->attrs['objectClass'] as $name){
289 if($name!="goNfsServer"){
290 $oc[]=$name;
291 }
292 }
293 $this->attrs['objectClass']=$oc;
295 /* Write to LDAP */
296 $ldap= $this->config->get_ldap_link();
297 $ldap->cd($this->dn);
298 $ldap->modify($this->attrs);
299 show_ldap_error($ldap->get_error());
301 /* Optionally execute a command after we're done */
302 if ($this->initially_was_account == $this->is_account){
303 if ($this->is_modified){
304 $this->handle_post_events("mofify");
305 }
306 } else {
307 $this->handle_post_events("add");
308 }
309 }
311 }
313 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
314 ?>