57131149446dd6af1ec1d1157f83d68ce479da9c
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 }
144 /* Classes... */
145 foreach ($this->additionaloc as $oc => $dummy){
146 if (isset($this->objectclasses[$oc])){
147 $smarty->assign("$oc", "checked");
148 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
149 } else {
150 $smarty->assign("$oc"."State", "disabled");
151 }
152 }
155 if(isset($this->attrs['goXdmcpIsEnabled'])&&($this->attrs['goXdmcpIsEnabled']=="1"))
156 $smarty->assign("goXdmcpIsEnabled","checked");
158 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
159 }
161 function remove_from_parent()
162 {
163 /* This cannot be removed... */
164 }
167 /* Save data to object */
168 function save_object()
169 {
170 plugin::save_object();
172 /* Save checkbox state */
173 foreach ($this->additionaloc as $oc => $dummy){
174 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
175 $this->objectclasses[$oc]= $oc;
176 } else {
177 unset($this->objectclasses[$oc]);
178 }
179 }
181 }
184 /* Check supplied data */
185 function check()
186 {
187 $message= array();
189 return ($message);
190 }
193 /* Save to LDAP */
194 function save()
195 {
197 /* Normalize lazy objectclass arrays */
198 $objectclasses= array();
199 foreach($this->objectclasses as $oc){
200 $objectclasses[]= $oc;
201 }
202 plugin::save();
204 $test = $this->objectclasses;
205 $tmp = array_flip($this->attrs['objectClass']);
207 foreach($this->additionaloc as $key=>$val) {
208 unset($tmp[$key]);
209 }
211 foreach($tmp as $val){
212 if(in_array($val,$test)){
213 $tmp[$val];
214 }
215 }
217 $classes = (array_flip(array_merge(array_flip($test),$tmp)));
219 unset($this->attrs['objectClass']);
221 foreach($classes as $class){
222 $this->attrs['objectClass'][]=$class;
223 }
226 /* Remove unneeded attributes */
227 foreach ($this->additionaloc as $oc => $attrs){
228 if (!in_array($oc, $this->attrs['objectClass'])){
229 foreach ($attrs as $attr){
230 $this->attrs[$attr]= array();
231 }
232 }
233 }
234 $this->attrs = array_reverse($this->attrs);
239 /* Write to LDAP */
240 $ldap= $this->config->get_ldap_link();
241 $ldap->cd($this->dn);
242 $ldap->modify($this->attrs);
243 show_ldap_error($ldap->get_error());
244 /* Optionally execute a command after we're done */
245 if ($this->initially_was_account == $this->is_account){
246 if ($this->is_modified){
247 $this->handle_post_events("mofify");
248 }
249 } else {
250 $this->handle_post_events("add");
251 }
253 }
255 }
257 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
258 ?>