Code

Added new service management
[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;
30   var $goGlpiAdmin="";
31   var $goGlpiDatabase = "";
32   var $goGlpiPassword ="";
33   
35   /* attribute list for save action */
36   var $attributes= array("goImapName", "goImapConnect", "goImapAdmin", "goImapPassword",
37                          "goImapSieveServer", "goImapSievePort", "goKrbRealm", 
38                          "goKrbAdmin", "goKrbPassword", "goFaxAdmin", "goFaxPassword",
39                          "goLogAdmin", "goLogPassword", "goFonAdmin", "goFonPassword",
40                          "goFonAreaCode", "goFonCountryCode","goGlpiAdmin","goGlpiDatabase","goGlpiPassword");
41   var $objectclasses= array("top", "goServer");
42   var $additionaloc= array(
43                          "goKrbServer" => array("goKrbRealm", "goKrbAdmin",
44                                                 "goKrbPassword"),
45                           "goFaxServer" => array("goFaxAdmin", "goFaxPassword"),
46                           "goLogDBServer" => array("goLogAdmin", "goLogPassword"),
47                           "goGlpiServer" => array("goGlpiAdmin","goGlpiDatabase","goGlpiPassword"),
48                           "goFonServer" => array("goFonAdmin", "goFonPassword",
49                                                 "goFonAreaCode", "goFonCountryCode"));
51   function servdb ($config, $dn= NULL)
52   {
53     plugin::plugin ($config, $dn);
55     /* Make dynamic list of objectClasses */
56     foreach ($this->additionaloc as $oc => $dummy){
57       if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
58         $this->objectclasses[$oc]= $oc;
59       }
60     }
62     /* We need to save the historical state of goImapName for later checking */
63     $this->goImapName_old= $this->goImapName;
65     /* Always is account... */
66     $this->is_account= TRUE;
67   }
69   function execute()
70   {
71         /* Call parent execute */
72         plugin::execute();
74     /* Fill templating stuff */
75     $smarty= get_smarty();
77     /* Attributes... */
78     foreach ($this->attributes as $attr){
79       $smarty->assign("$attr", $this->$attr);
80       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
81     }
83     /* Classes... */
84     foreach ($this->additionaloc as $oc => $dummy){
85       if (isset($this->objectclasses[$oc])){
86         $smarty->assign("$oc", "checked");
87         $smarty->assign("$oc"."State", "");
88         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
89         
90       } else {
91         $smarty->assign("$oc", "");
92         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
93         $smarty->assign("$oc"."State", "disabled");
94       }
95     }
97     return($smarty->fetch (get_template_path('servdb.tpl', TRUE)));
98   }
100   function remove_from_parent()
101   {
102     /* This cannot be removed... */
103   }
106   /* Save data to object */
107   function save_object()
108   {
109     if (isset($_POST['dbtab'])){
110       plugin::save_object();
111       
112       /* Save checkbox state */
113       foreach ($this->additionaloc as $oc => $dummy){
114         if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
115           $this->objectclasses[$oc]= $oc;
116         } else {
117           unset($this->objectclasses[$oc]);
118         }
119       }
120     }
121   }
124   /* Check supplied data */
125   function check()
126   {
127     /* Call common method to give check the hook */
128     $message= plugin::check();
130     if(in_array("goGlpiServer",$this->objectclasses)){
131       foreach(array("goGlpiAdmin","goGlpiDatabase") as $attr){
132         if(empty($this->$attr)){
133           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
134         }
135       }
136     }
138     /* All fields are marked as *must* */
139     if (1 == 0 && in_array("goImapServer", $this->objectclasses)){
140       foreach (array("goImapAdmin", "goImapName") as $attr){
141         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
142           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
143         }
144       }
147       /* Check connect string */
148       if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
149         $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
150                     '{server-name:port/options}');
151       }
152       if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
153         $message[]= _("The sieve port needs to be numeric.");
154       }
155     }
156     if (in_array("goKrbServer", $this->objectclasses)){
157       foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
158         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
159           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
160         }
161       }
162       /* goKrbPassword is a must field, if goKrbServer is used as objectClass */
163       if ($this->goKrbPassword == "" ){
164         $message[]= sprintf(_("The specified kerberos password is empty."), $attr);
165       }
166     }
167     if (in_array("goFaxServer", $this->objectclasses)){
168       if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
169         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
170       }
171     }
172     if (in_array("goLogServer", $this->objectclasses)){
173       if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
174         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
175       }
176     }
177     if (in_array("goFonServer", $this->objectclasses)){
178       foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
179         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
180           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
181         }
182       }
183     }
184     if (in_array("goImapServer", $this->objectclasses) && 
185         $this->goImapName != $this->goImapName_old) {
186       // Attribute has changed
187       if(!preg_match("/^[a-z0-9.-]+$/", $this->goImapName)) {
188         $message[]= sprintf(_("The imap name string needs to be a hostname or an IP-address."));
189       }
190     }
192     return ($message);
193   }
196   /* Save to LDAP */
197   function save()
198   {
199     /* Normalize lazy objectclass arrays */
200     $objectclasses= array();
201     foreach($this->objectclasses as $oc){
202       $objectclasses[]= $oc;
203     }
204     
205     /* Move cn to sieve server */
206     $this->goImapSieveServer= $this->cn;
207     
208     plugin::save();
209   
210     $test = $this->objectclasses;
211     $tmp = array_flip($this->attrs['objectClass']);
213     foreach($this->additionaloc as $key=>$val) {
214       unset($tmp[$key]);
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);
236     /* Write to LDAP */
237     $ldap= $this->config->get_ldap_link();
238     $ldap->cd($this->dn);
239     $this->cleanup();
240     $ldap->modify ($this->attrs); 
242     show_ldap_error($ldap->get_error(), _("Saving server db settings failed"));
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     }
252   }
256 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
257 ?>