Code

Added check for goImapName.
[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     }
151     if (in_array("goFaxServer", $this->objectclasses)){
152       if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
153         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
154       }
155     }
156     if (in_array("goLogServer", $this->objectclasses)){
157       if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
158         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
159       }
160     }
161     if (in_array("goFonServer", $this->objectclasses)){
162       foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
163         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
164           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
165         }
166       }
167     }
168     if (in_array("goImapServer", $this->objectclasses) && 
169         $this->goImapName != $this->goImapName_old) {
170       // Attribute has changed
171       if(!preg_match("/^[a-z0-9\.]+$/", $this->goImapName)) {
172         $message[]= sprintf(_("The imap name string needs to be a hostname or an IP-address."));
173       }
174     }
176     return ($message);
177   }
180   /* Save to LDAP */
181   function save()
182   {
183     /* Normalize lazy objectclass arrays */
184     $objectclasses= array();
185     foreach($this->objectclasses as $oc){
186       $objectclasses[]= $oc;
187     }
188   
189     plugin::save();
190   
193     $test = $this->objectclasses;
194     $tmp = array_flip($this->attrs['objectClass']);
196     foreach($this->additionaloc as $key=>$val) {
197       unset($tmp[$key]);
198       }
200     $classes = (array_flip(array_merge(array_flip($test),$tmp)));
202     unset($this->attrs['objectClass']);
204     foreach($classes as $class){
205       $this->attrs['objectClass'][]=$class;
206     }
209     /* Remove unneeded attributes */
210     foreach ($this->additionaloc as $oc => $attrs){
211       if (!in_array($oc, $this->attrs['objectClass'])){
212         foreach ($attrs as $attr){
213           $this->attrs[$attr]= array();
214         }
215       }
216     }
217     $this->attrs = array_reverse($this->attrs);
221     /* Write to LDAP */
222     $ldap= $this->config->get_ldap_link();
223     $ldap->cd($this->dn);
224     $ldap->modify($this->attrs);
225     show_ldap_error($ldap->get_error());
227     /* Optionally execute a command after we're done */
228     if ($this->initially_was_account == $this->is_account){
229       if ($this->is_modified){
230         $this->handle_post_events("mofify");
231       }
232     } else {
233       $this->handle_post_events("add");
234     }
235   }
239 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
240 ?>