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