Code

Some changes repository plugin
[gosa.git] / plugins / admin / systems / class_servDB.inc
1 <?php
3 class servdb 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   /* Object information */
11   var $goImapName= "";
12   var $goImapName_old= "";
13   var $goImapConnect= "";
14   var $goImapAdmin= "";
15   var $goImapPassword= "";
16   var $goImapSieveServer= "";
17   var $goImapSievePort= "";
18   var $goKrbRealm= "";
19   var $goKrbAdmin= "";
20   var $goKrbPassword= "";
21   var $goFaxAdmin= "";
22   var $goFaxPassword= "";
23   var $goLogAdmin= "";
24   var $goLogPassword= "";
25   var $goFonAdmin= "";
26   var $goFonPassword= "";
27   var $goFonAreaCode= "";
28   var $goFonCountryCode= "";
29   var $ignore_account= TRUE;
31   /* attribute list for save action */
32   var $attributes= array("goImapName", "goImapConnect", "goImapAdmin", "goImapPassword",
33                          "goImapSieveServer", "goImapSievePort", "goKrbRealm", 
34                          "goKrbAdmin", "goKrbPassword", "goFaxAdmin", "goFaxPassword",
35                          "goLogAdmin", "goLogPassword", "goFonAdmin", "goFonPassword",
36                          "goFonAreaCode", "goFonCountryCode");
37   var $objectclasses= array("top", "goServer");
38   var $additionaloc= array("goImapServer" => array("goImapName", "goImapConnect",
39                                                 "goImapAdmin", "goImapPassword",
40                                                 "goImapSieveServer", 
41                                                 "goImapSievePort"),
42                           "goKrbServer" => array("goKrbRealm", "goKrbAdmin",
43                                                 "goKrbPassword"),
44                           "goFaxServer" => array("goFaxAdmin", "goFaxPassword"),
45                           "goLogDBServer" => array("goLogAdmin", "goLogPassword"),
46                           "goFonServer" => array("goFonAdmin", "goFonPassword",
47                                                 "goFonAreaCode", "goFonCountryCode"));
49   function servdb ($config, $dn= NULL)
50   {
51     plugin::plugin ($config, $dn);
53     /* Make dynamic list of objectClasses */
54     foreach ($this->additionaloc as $oc => $dummy){
55       if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
56         $this->objectclasses[$oc]= $oc;
57       }
58     }
60     /* We need to save the historical state of goImapName for later checking */
61     $this->goImapName_old= $this->goImapName;
63     /* Always is account... */
64     $this->is_account= TRUE;
65   }
67   function execute()
68   {
69         /* Call parent execute */
70         plugin::execute();
72     /* Fill templating stuff */
73     $smarty= get_smarty();
75     /* Attributes... */
76     foreach ($this->attributes as $attr){
77       $smarty->assign("$attr", $this->$attr);
78       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
79     }
81     /* Don't show Asterisk for non-required attribute ipHostNumber and macAddress */
82     $smarty->assign("staticAddress", "");
84     /* Classes... */
85     foreach ($this->additionaloc as $oc => $dummy){
86       if (isset($this->objectclasses[$oc])){
87         $smarty->assign("$oc", "checked");
88         $smarty->assign("$oc"."State", "");
89         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
90         
91       } else {
92         $smarty->assign("$oc", "");
93         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
94         $smarty->assign("$oc"."State", "disabled");
95       }
96     }
98     return($smarty->fetch (get_template_path('servdb.tpl', TRUE)));
99   }
101   function remove_from_parent()
102   {
103     /* This cannot be removed... */
104   }
107   /* Save data to object */
108   function save_object()
109   {
110     if (isset($_POST['dbtab'])){
111       plugin::save_object();
112       
113       /* Save checkbox state */
114       foreach ($this->additionaloc as $oc => $dummy){
115         if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
116           $this->objectclasses[$oc]= $oc;
117         } else {
118           unset($this->objectclasses[$oc]);
119         }
120       }
121     }
122   }
125   /* Check supplied data */
126   function check()
127   {
128     $message= array();
130     /* All fields are marked as *must* */
131     if (in_array("goImapServer", $this->objectclasses)){
132       foreach (array("goImapAdmin", "goImapName") as $attr){
133         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
134           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
135         }
136       }
138       /* Check connect string */
139       if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
140         $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
141                     '{server-name:port/options}');
142       }
143       if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
144         $message[]= _("The sieve port needs to be numeric.");
145       }
146     }
147     if (in_array("goKrbServer", $this->objectclasses)){
148       foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
149         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
150           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
151         }
152       }
153       /* goKrbPassword is a must field, if goKrbServer is used as objectClass */
154       if ($this->goKrbPassword == "" ){
155         $message[]= sprintf(_("The specified kerberos password is empty."), $attr);
156       }
157     }
158     if (in_array("goFaxServer", $this->objectclasses)){
159       if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
160         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
161       }
162     }
163     if (in_array("goLogServer", $this->objectclasses)){
164       if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
165         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
166       }
167     }
168     if (in_array("goFonServer", $this->objectclasses)){
169       foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
170         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
171           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
172         }
173       }
174     }
175     if (in_array("goImapServer", $this->objectclasses) && 
176         $this->goImapName != $this->goImapName_old) {
177       // Attribute has changed
178       if(!preg_match("/^[a-z0-9.-]+$/", $this->goImapName)) {
179         $message[]= sprintf(_("The imap name string needs to be a hostname or an IP-address."));
180       }
181     }
183     return ($message);
184   }
187   /* Save to LDAP */
188   function save()
189   {
190     /* Normalize lazy objectclass arrays */
191     $objectclasses= array();
192     foreach($this->objectclasses as $oc){
193       $objectclasses[]= $oc;
194     }
195     
196     /* Move cn to sieve server */
197     $this->goImapSieveServer= $this->cn;
198     
199     plugin::save();
200   
201     $test = $this->objectclasses;
202     $tmp = array_flip($this->attrs['objectClass']);
204     foreach($this->additionaloc as $key=>$val) {
205       unset($tmp[$key]);
206       }
208     $classes = (array_flip(array_merge(array_flip($test),$tmp)));
210     unset($this->attrs['objectClass']);
212     foreach($classes as $class){
213       $this->attrs['objectClass'][]=$class;
214     }
217     /* Remove unneeded attributes */
218     foreach ($this->additionaloc as $oc => $attrs){
219       if (!in_array($oc, $this->attrs['objectClass'])){
220         foreach ($attrs as $attr){
221           $this->attrs[$attr]= array();
222         }
223       }
224     }
225     $this->attrs = array_reverse($this->attrs);
227     /* Write to LDAP */
228     $ldap= $this->config->get_ldap_link();
229     $ldap->cd($this->dn);
230     $ldap->modify($this->attrs);
231     show_ldap_error($ldap->get_error());
233     /* Optionally execute a command after we're done */
234     if ($this->initially_was_account == $this->is_account){
235       if ($this->is_modified){
236         $this->handle_post_events("mofify");
237       }
238     } else {
239       $this->handle_post_events("add");
240     }
241   }
245 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
246 ?>