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 }
154 return($smarty->fetch (get_template_path('servservice.tpl', TRUE)));
155 }
157 function remove_from_parent()
158 {
159 /* This cannot be removed... */
160 }
163 /* Save data to object */
164 function save_object()
165 {
166 plugin::save_object();
168 /* Save checkbox state */
169 foreach ($this->additionaloc as $oc => $dummy){
170 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
171 $this->objectclasses[$oc]= $oc;
172 } else {
173 unset($this->objectclasses[$oc]);
174 }
175 }
177 }
180 /* Check supplied data */
181 function check()
182 {
183 $message= array();
185 return ($message);
186 }
189 /* Save to LDAP */
190 function save()
191 {
192 /* Normalize lazy objectclass arrays */
193 $objectclasses= array();
194 foreach($this->objectclasses as $oc){
195 $objectclasses[]= $oc;
196 }
198 $this->objectclasses= $objectclasses;
199 plugin::save();
201 /* Remove objectclasses */
202 foreach(array_merge($this->objectclasses, $this->additionaloc) as $oc){
203 foreach ($this->attrs['objectClass'] as $key => $value){
204 if ($value == $oc){
205 unset ($this->attrs['objectClass'][$key]);
206 }
207 }
208 }
209 $this->attrs['objectClass']=array();
210 foreach($this->objectclasses as $oc){
211 $this->attrs['objectClass'][]= $oc;
212 }
215 /* Adapt sieve server if needed */
216 if (in_array('goImapServer', $this->objectclasses)){
217 $this->attrs['goImapSieveServer']= preg_replace('/:.*$/', '',
218 preg_replace('/^{([^}]+)}$/', '\\1',
219 $this->attrs['goImapConnect']));
220 }
222 /* Remove unneeded attributes */
223 foreach ($this->additionaloc as $oc => $attrs){
224 if (!in_array($oc, $this->objectclasses)){
225 foreach ($attrs as $attr){
226 $this->attrs[$attr]= array();
227 }
228 }
229 }
231 print_a($this->attrs);
233 /* Write to LDAP */
234 $ldap= $this->config->get_ldap_link();
235 $ldap->cd($this->dn);
236 $ldap->modify($this->attrs);
237 show_ldap_error($ldap->get_error());
239 /* Optionally execute a command after we're done */
240 if ($this->initially_was_account == $this->is_account){
241 if ($this->is_modified){
242 $this->handle_post_events("mofify");
243 }
244 } else {
245 $this->handle_post_events("add");
246 }
248 }
250 }
252 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
253 ?>