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 if($this->$attr)
142 $smarty->assign($attr."State","");
143 else
144 $smarty->assign($attr."State","disabled");
145 }
148 /* Classes... */
149 foreach ($this->additionaloc as $oc => $dummy){
150 if (isset($this->objectclasses[$oc])){
151 $smarty->assign("$oc", "checked");
152 $smarty->assign("$oc"."State", "");
153 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
155 } else {
156 $smarty->assign("$oc", "");
157 $smarty->assign("$oc"."ACL", "");
158 $smarty->assign("$oc"."State", "disabled");
159 }
160 }
163 if(isset($this->attrs['goXdmcpIsEnabled'])&&($this->attrs['goXdmcpIsEnabled']=="1"))
164 $smarty->assign("goXdmcpIsEnabled","checked");
166 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
167 }
169 function remove_from_parent()
170 {
171 /* This cannot be removed... */
172 }
175 /* Save data to object */
176 function save_object()
177 {
178 plugin::save_object();
180 /* Save checkbox state */
181 foreach ($this->additionaloc as $oc => $dummy){
182 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
183 $this->objectclasses[$oc]= $oc;
184 } else {
185 unset($this->objectclasses[$oc]);
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 // print_a($this->attrs);
243 /* Write to LDAP */
244 $ldap= $this->config->get_ldap_link();
245 $ldap->cd($this->dn);
246 $ldap->modify($this->attrs);
247 show_ldap_error($ldap->get_error());
248 /* Optionally execute a command after we're done */
249 if ($this->initially_was_account == $this->is_account){
250 if ($this->is_modified){
251 $this->handle_post_events("mofify");
252 }
253 } else {
254 $this->handle_post_events("add");
255 }
257 }
259 }
261 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
262 ?>