Code

Added magic_quotes fix for Profile
[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     /* Fill templating stuff */
70     $smarty= get_smarty();
72     /* Attributes... */
73     foreach ($this->attributes as $attr){
74       $smarty->assign("$attr", $this->$attr);
75       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
76     }
78     /* Don't show Asterisk for non-required attribute ipHostNumber and macAddress */
79     $smarty->assign("staticAddress", "");
81     /* Classes... */
82     foreach ($this->additionaloc as $oc => $dummy){
83       if (isset($this->objectclasses[$oc])){
84         $smarty->assign("$oc", "checked");
85         $smarty->assign("$oc"."State", "");
86         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
87         
88       } else {
89         $smarty->assign("$oc", "");
90         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
91         $smarty->assign("$oc"."State", "disabled");
92       }
93     }
95     return($smarty->fetch (get_template_path('servdb.tpl', TRUE)));
96   }
98   function remove_from_parent()
99   {
100     /* This cannot be removed... */
101   }
104   /* Save data to object */
105   function save_object()
106   {
107     if (isset($_POST['dbtab'])){
108       plugin::save_object();
109       
110       /* Save checkbox state */
111       foreach ($this->additionaloc as $oc => $dummy){
112         if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
113           $this->objectclasses[$oc]= $oc;
114         } else {
115           unset($this->objectclasses[$oc]);
116         }
117       }
118     }
119   }
122   /* Check supplied data */
123   function check()
124   {
125     $message= array();
127     /* All fields are marked as *must* */
128     if (in_array("goImapServer", $this->objectclasses)){
129       foreach (array("goImapAdmin", "goImapName") as $attr){
130         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
131           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
132         }
133       }
135       /* Check connect string */
136       if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
137         $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
138                     '{server-name:port/options}');
139       }
140       if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
141         $message[]= _("The sieve port needs to be numeric.");
142       }
143     }
144     if (in_array("goKrbServer", $this->objectclasses)){
145       foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
146         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
147           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
148         }
149       }
150       /* goKrbPassword is a must field, if goKrbServer is used as objectClass */
151       if ($this->goKrbPassword == "" ){
152         $message[]= sprintf(_("The specified kerberos password is empty."), $attr);
153       }
154     }
155     if (in_array("goFaxServer", $this->objectclasses)){
156       if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
157         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
158       }
159     }
160     if (in_array("goLogServer", $this->objectclasses)){
161       if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
162         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
163       }
164     }
165     if (in_array("goFonServer", $this->objectclasses)){
166       foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
167         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
168           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
169         }
170       }
171     }
172     if (in_array("goImapServer", $this->objectclasses) && 
173         $this->goImapName != $this->goImapName_old) {
174       // Attribute has changed
175       if(!preg_match("/^[a-z0-9.-]+$/", $this->goImapName)) {
176         $message[]= sprintf(_("The imap name string needs to be a hostname or an IP-address."));
177       }
178     }
180     return ($message);
181   }
184   /* Save to LDAP */
185   function save()
186   {
187     /* Normalize lazy objectclass arrays */
188     $objectclasses= array();
189     foreach($this->objectclasses as $oc){
190       $objectclasses[]= $oc;
191     }
192   
193     plugin::save();
194   
197     $test = $this->objectclasses;
198     $tmp = array_flip($this->attrs['objectClass']);
200     foreach($this->additionaloc as $key=>$val) {
201       unset($tmp[$key]);
202       }
204     $classes = (array_flip(array_merge(array_flip($test),$tmp)));
206     unset($this->attrs['objectClass']);
208     foreach($classes as $class){
209       $this->attrs['objectClass'][]=$class;
210     }
213     /* Remove unneeded attributes */
214     foreach ($this->additionaloc as $oc => $attrs){
215       if (!in_array($oc, $this->attrs['objectClass'])){
216         foreach ($attrs as $attr){
217           $this->attrs[$attr]= array();
218         }
219       }
220     }
221     $this->attrs = array_reverse($this->attrs);
223     /* Write to LDAP */
224     $ldap= $this->config->get_ldap_link();
225     $ldap->cd($this->dn);
226     $ldap->modify($this->attrs);
227     show_ldap_error($ldap->get_error());
229     /* Optionally execute a command after we're done */
230     if ($this->initially_was_account == $this->is_account){
231       if ($this->is_modified){
232         $this->handle_post_events("mofify");
233       }
234     } else {
235       $this->handle_post_events("add");
236     }
237   }
241 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
242 ?>