0af905aa2028bb0e7c67ddb4478e24034b82736a
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");
11 var $goExportEntry = array();
12 var $goTimeSource = array();
13 var $goLdapBase= "";
14 var $goXdmcpIsEnabled ="";
15 var $goFontPath= "";
16 var $goNTPServer="";
17 var $goLdapServer="";
18 var $goTerminalServer="";
19 var $goSyslogServer="";
20 var $goCupsServer="";
23 /* attribute list for save action */
24 var $attributes = array("goExportEntry","goTimeSource","goLdapBase","goXdmcpIsEnabled","goFontPath" );
25 var $objectclasses = array("top","goServer");
26 var $additionaloc = array(
28 "goNfsServer" => array("goExportEntry"),
29 "goNtpServer" => array("goTimeSource"),
30 "goLdapServer" => array("goLdapBase"),
31 "goTerminalServer"=> array("goXdmcpIsEnabled", "goFontPath"),
32 "goSyslogServer" => array(),
33 "goCupsServer" => array()
34 );
44 function servservice ($config, $dn= NULL)
45 {
46 plugin::plugin ($config, $dn);
48 foreach ($this->additionaloc as $oc => $dummy){
49 if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
50 $this->objectclasses[$oc]= $oc;
51 }
52 }
53 /* Always is account... */
54 $this->is_account= TRUE;
55 }
59 function execute()
60 {
61 /* Fill templating stuff */
62 $smarty= get_smarty();
65 /*
66 Handling for Nfs Export Entries
67 */
69 /* Here we add a new entry */
70 if(isset($_POST['NewNfsAdd']))
71 {
72 $this->attrs['goExportEntry'][]=$_POST['NewNfsExport'];
73 }
75 /* Deleting an Entry, is a bit more complicated than adding one*/
76 if(isset($_POST['DelNfsEnt']))
77 {
78 /* Go through all entries an skip the selected (The one we want to delete)*/
79 foreach($this->attrs['goExportEntry'] as $key => $val)
80 {
81 /* Add all entries in an new Array, because when deleting one entry, the could be broken*/
82 if(($val != $_POST['goExportEntry'] ))
83 {
84 /* Skip the entry that we want to delete*/
85 $new_arr[]=$val;
86 }
87 }
88 /* Deleting complete so add result to the attrs */
89 $this->attrs['goExportEntry']=$new_arr;
90 }
92 /* Set the entry which we want to show in the frontend */
93 if(isset($this->attrs['goExportEntry']))
94 {
95 $this->goExportEntry = ($this->attrs['goExportEntry']);
96 unset($this->goExportEntry['count']);
97 }
100 /*
101 Handling for NTP Export Entries
102 */
104 /* Here we add a new entry */
105 if(isset($_POST['NewNTPAdd']))
106 {
107 $this->attrs['goTimeSource'][]=$_POST['NewNTPExport'];
108 }
110 /*Deleting an Entry, is a bit more complicated than adding one*/
111 if(isset($_POST['DelNTPEnt']))
112 {
113 /* Go through all entries an skip the selected (The one we want to delete)*/
114 foreach($this->attrs['goTimeSource'] as $key => $val)
115 {
116 /* Add all entries in an new Array, because wehn deleting one entry, the could be broken*/
117 if($val != $_POST['goTimeSource'] )
118 {
119 /* Skip the entry that we want to delete*/
120 $new_arr[]=$val;
121 }
122 }
123 /* Deleting complete so add result to the attrs */
124 $this->attrs['goTimeSource']=$new_arr;
125 }
127 /* Set the entry which we want to show in the frontend */
128 if(isset($this->attrs['goTimeSource']))
129 {
130 $this->goTimeSource = ($this->attrs['goTimeSource']);
131 unset($this->goTimeSource['count']);
132 }
137 /* Attributes... */
138 foreach ($this->attributes as $attr){
139 $smarty->assign("$attr", $this->$attr);
140 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
141 $smarty->assign($attr."State","");
142 }
145 /* Classes... */
146 foreach ($this->additionaloc as $oc => $dummy){
147 if (isset($this->objectclasses[$oc])){
148 $smarty->assign("$oc", "checked");
149 $smarty->assign("$oc"."State", "");
150 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
152 } else {
153 $smarty->assign("$oc", "");
154 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
155 $smarty->assign("$oc"."State", "disabled");
156 }
157 }
160 if(isset($this->attrs['goXdmcpIsEnabled'])&&($this->attrs['goXdmcpIsEnabled']=="1"))
161 $smarty->assign("goXdmcpIsEnabled","checked");
163 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
164 }
166 function remove_from_parent()
167 {
168 /* This cannot be removed... */
169 }
172 /* Save data to object */
173 function save_object()
174 {
175 plugin::save_object();
177 /* Save checkbox state */
178 foreach ($this->additionaloc as $oc => $dummy){
179 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
180 $this->objectclasses[$oc]= $oc;
181 } else {
182 unset($this->objectclasses[$oc]);
183 }
184 }
186 }
189 /* Check supplied data */
190 function check()
191 {
192 $message= array();
194 return ($message);
195 }
198 /* Save to LDAP */
199 function save()
200 {
202 /* Normalize lazy objectclass arrays */
203 $objectclasses= array();
204 foreach($this->objectclasses as $oc){
205 $objectclasses[]= $oc;
206 }
207 plugin::save();
209 $test = $this->objectclasses;
210 $tmp = array_flip($this->attrs['objectClass']);
214 foreach($this->additionaloc as $key=>$val) {
215 unset($tmp[$key]);
216 }
219 $classes = (array_flip(array_merge(array_flip($test),$tmp)));
221 unset($this->attrs['objectClass']);
223 foreach($classes as $class){
224 $this->attrs['objectClass'][]=$class;
225 }
228 /* Remove unneeded attributes */
229 foreach ($this->additionaloc as $oc => $attrs){
230 if (!in_array($oc, $this->attrs['objectClass'])){
231 foreach ($attrs as $attr){
232 $this->attrs[$attr]= array();
233 }
234 }
235 }
236 $this->attrs = array_reverse($this->attrs);
238 /* Check if we are able to set these attributes */
239 #fixme : It Would be better to check ObjectClass rights to, but what is to do if there are insuficient rights
240 foreach($this->additionaloc as $oc => $attrs)
241 {
242 foreach($attrs as $val)
243 {
244 if(chkacl($this->acl,$val)=="")
245 {
246 unset($this->attrs[$val]);
247 unset($this->$val);
248 }
249 }
250 }
252 /* Write to LDAP */
253 $ldap= $this->config->get_ldap_link();
254 $ldap->cd($this->dn);
255 $ldap->modify($this->attrs);
256 show_ldap_error($ldap->get_error());
257 /* Optionally execute a command after we're done */
258 if ($this->initially_was_account == $this->is_account){
259 if ($this->is_modified){
260 $this->handle_post_events("mofify");
261 }
262 } else {
263 $this->handle_post_events("add");
264 }
265 }
267 }
269 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
270 ?>