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 /*
65 Handling for Nfs Export Entries
66 */
68 /* Here we add a new entry */
69 if(isset($_POST['NewNfsAdd']))
70 {
71 $this->attrs['goExportEntry'][]=$_POST['NewNfsExport'];
72 }
74 /* Deleting an Entry, is a bit more complicated than adding one*/
75 if(isset($_POST['DelNfsEnt']))
76 {
77 /* Go through all entries an skip the selected (The one we want to delete)*/
78 foreach($this->attrs['goExportEntry'] as $key => $val)
79 {
80 /* Add all entries in an new Array, because when deleting one entry, the could be broken*/
81 if(($val != $_POST['goExportEntry'] ))
82 {
83 /* Skip the entry that we want to delete*/
84 $new_arr[]=$val;
85 }
86 }
87 /* Deleting complete so add result to the attrs */
88 $this->attrs['goExportEntry']=$new_arr;
89 }
91 /* Set the entry which we want to show in the frontend */
92 if(isset($this->attrs['goExportEntry']))
93 {
94 $this->goExportEntry = ($this->attrs['goExportEntry']);
95 unset($this->goExportEntry['count']);
96 }
99 /*
100 Handling for NTP Export Entries
101 */
103 /* Here we add a new entry */
104 if(isset($_POST['NewNTPAdd']))
105 {
106 $this->attrs['goTimeSource'][]=$_POST['NewNTPExport'];
107 }
109 /*Deleting an Entry, is a bit more complicated than adding one*/
110 if(isset($_POST['DelNTPEnt']))
111 {
112 /* Go through all entries an skip the selected (The one we want to delete)*/
113 foreach($this->attrs['goTimeSource'] as $key => $val)
114 {
115 /* Add all entries in an new Array, because wehn deleting one entry, the could be broken*/
116 if($val != $_POST['goTimeSource'] )
117 {
118 /* Skip the entry that we want to delete*/
119 $new_arr[]=$val;
120 }
121 }
122 /* Deleting complete so add result to the attrs */
123 $this->attrs['goTimeSource']=$new_arr;
124 }
126 /* Set the entry which we want to show in the frontend */
127 if(isset($this->attrs['goTimeSource']))
128 {
129 $this->goTimeSource = ($this->attrs['goTimeSource']);
130 unset($this->goTimeSource['count']);
131 }
136 /* Attributes... */
137 foreach ($this->attributes as $attr){
138 $smarty->assign("$attr", $this->$attr);
139 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
140 $smarty->assign($attr."State","");
141 }
144 /* Classes... */
145 foreach ($this->additionaloc as $oc => $dummy){
146 if (isset($this->objectclasses[$oc])){
147 $smarty->assign("$oc", "checked");
148 $smarty->assign("$oc"."State", "");
149 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
151 } else {
152 $smarty->assign("$oc", "");
153 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
154 $smarty->assign("$oc"."State", "disabled");
155 }
156 }
159 if(isset($this->attrs['goXdmcpIsEnabled'])&&($this->attrs['goXdmcpIsEnabled']=="1"))
160 $smarty->assign("goXdmcpIsEnabled","checked");
162 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
163 }
165 function remove_from_parent()
166 {
167 /* This cannot be removed... */
168 }
171 /* Save data to object */
172 function save_object()
173 {
174 if (isset($_POST['servicetab'])){
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 }
185 }
187 }
190 /* Check supplied data */
191 function check()
192 {
193 $message= array();
195 return ($message);
196 }
199 /* Save to LDAP */
200 function save()
201 {
203 /* Normalize lazy objectclass arrays */
204 $objectclasses= array();
205 foreach($this->objectclasses as $oc){
206 $objectclasses[]= $oc;
207 }
208 plugin::save();
210 $test = $this->objectclasses;
211 $tmp = array_flip($this->attrs['objectClass']);
215 foreach($this->additionaloc as $key=>$val) {
216 unset($tmp[$key]);
217 }
220 $classes = (array_flip(array_merge(array_flip($test),$tmp)));
222 unset($this->attrs['objectClass']);
224 foreach($classes as $class){
225 $this->attrs['objectClass'][]=$class;
226 }
229 /* Remove unneeded attributes */
230 foreach ($this->additionaloc as $oc => $attrs){
231 if (!in_array($oc, $this->attrs['objectClass'])){
232 foreach ($attrs as $attr){
233 $this->attrs[$attr]= array();
234 }
235 }
236 }
237 $this->attrs = array_reverse($this->attrs);
239 /* Check if we are able to set these attributes */
240 #fixme : It Would be better to check ObjectClass rights to, but what is to do if there are insuficient rights
241 foreach($this->additionaloc as $oc => $attrs)
242 {
243 foreach($attrs as $val)
244 {
245 if(chkacl($this->acl,$val)=="")
246 {
247 unset($this->attrs[$val]);
248 unset($this->$val);
249 }
250 }
251 }
253 /* Write to LDAP */
254 $ldap= $this->config->get_ldap_link();
255 $ldap->cd($this->dn);
256 $ldap->modify($this->attrs);
257 show_ldap_error($ldap->get_error());
258 /* Optionally execute a command after we're done */
259 if ($this->initially_was_account == $this->is_account){
260 if ($this->is_modified){
261 $this->handle_post_events("mofify");
262 }
263 } else {
264 $this->handle_post_events("add");
265 }
266 }
268 }
270 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
271 ?>