Code

dfa0f784fbbb2260a9edd3577c684bfe814bebe0
[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 $goImapConnect= "";
13   var $goImapAdmin= "";
14   var $goImapPassword= "";
15   var $goImapSieveServer= "";
16   var $goImapSievePort= "";
17   var $goKrbRealm= "";
18   var $goKrbAdmin= "";
19   var $goKrbPassword= "";
20   var $goFaxAdmin= "";
21   var $goFaxPassword= "";
22   var $goLogAdmin= "";
23   var $goLogPassword= "";
24   var $goFonAdmin= "";
25   var $goFonPassword= "";
26   var $goFonAreaCode= "";
27   var $goFonCountryCode= "";
29   /* attribute list for save action */
30   var $attributes= array("goImapName", "goImapConnect", "goImapAdmin", "goImapPassword",
31                          "goImapSieveServer", "goImapSievePort", "goKrbRealm", 
32                          "goKrbAdmin", "goKrbPassword", "goFaxAdmin", "goFaxPassword",
33                          "goLogAdmin", "goLogPassword", "goFonAdmin", "goFonPassword",
34                          "goFonAreaCode", "goFonCountryCode");
35   var $objectclasses= array("top", "goServer");
36   var $additionaloc= array("goImapServer" => array("goImapName", "goImapConnect",
37                                                 "goImapAdmin", "goImapPassword",
38                                                 "goImapSieveServer", 
39                                                 "goImapSievePort"),
40                           "goKrbServer" => array("goKrbRealm", "goKrbAdmin",
41                                                 "goKrbPassword"),
42                           "goFaxServer" => array("goFaxAdmin", "goFaxPassword"),
43                           "goLogDBServer" => array("goLogAdmin", "goLogPassword"),
44                           "goFonServer" => array("goFonAdmin", "goFonPassword",
45                                                 "goFonAreaCode", "goFonCountryCode"));
47   function servdb ($config, $dn= NULL)
48   {
49     plugin::plugin ($config, $dn);
51     /* Make dynamic list of objectClasses */
52     foreach ($this->additionaloc as $oc => $dummy){
53       if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
54         $this->objectclasses[$oc]= $oc;
55       }
56     }
58     /* Always is account... */
59     $this->is_account= TRUE;
60   }
62   function execute()
63   {
64     /* Fill templating stuff */
65     $smarty= get_smarty();
67     /* Attributes... */
68     foreach ($this->attributes as $attr){
69       $smarty->assign("$attr", $this->$attr);
70       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
71     }
73     /* Classes... */
74     foreach ($this->additionaloc as $oc => $dummy){
75       if (isset($this->objectclasses[$oc])){
76         $smarty->assign("$oc", "checked");
77         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
78       } else {
79         $smarty->assign("$oc"."State", "disabled");
80       }
81     }
83     return($smarty->fetch (get_template_path('servdb.tpl', TRUE)));
84   }
86   function remove_from_parent()
87   {
88     /* This cannot be removed... */
89   }
92   /* Save data to object */
93   function save_object()
94   {
95     plugin::save_object();
96     
97     /* Save checkbox state */
98     foreach ($this->additionaloc as $oc => $dummy){
99       if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
100         $this->objectclasses[$oc]= $oc;
101       } else {
102         unset($this->objectclasses[$oc]);
103       }
104     }
105   }
108   /* Check supplied data */
109   function check()
110   {
111     $message= array();
113     /* All fields are marked as *must* */
114     if (in_array("goImapServer", $this->objectclasses)){
115       foreach (array("goImapAdmin", "goImapName") as $attr){
116         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
117           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
118         }
119       }
121       /* Check connect string */
122       if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
123         $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
124                     '{server-name:port/options}');
125       }
126       if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
127         $message[]= _("The sieve port needs to be numeric.");
128       }
129     }
130     if (in_array("goKrbServer", $this->objectclasses)){
131       foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
132         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
133           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
134         }
135       }
136     }
137     if (in_array("goFaxServer", $this->objectclasses)){
138       if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
139         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
140       }
141     }
142     if (in_array("goLogServer", $this->objectclasses)){
143       if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
144         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
145       }
146     }
147     if (in_array("goFonServer", $this->objectclasses)){
148       foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") 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     }
155     return ($message);
156   }
159   /* Save to LDAP */
160   function save()
161   {
162     /* Normalize lazy objectclass arrays */
163     $objectclasses= array();
164     foreach($this->objectclasses as $oc){
165       $objectclasses[]= $oc;
166     }
167     $this->objectclasses= $objectclasses;
168     plugin::save();
169     
170     /* Remove objectclasses */
171     unset ($this->attrs['objectClass']);
172     foreach($this->objectclasses as $oc){
173       $this->attrs['objectClass'][]= $oc;
174     }
176     /* Adapt sieve server if needed */
177     if (in_array('goImapServer', $this->objectclasses)){
178       $this->attrs['goImapSieveServer']= preg_replace('/:.*$/', '',
179                                          preg_replace('/^{([^}]+)}$/', '\\1', 
180                                          $this->attrs['goImapConnect']));
181     }
183     /* Remove unneeded attributes */
184     foreach ($this->additionaloc as $oc => $attrs){
185       if (!in_array($oc, $this->objectclasses)){
186         foreach ($attrs as $attr){
187           $this->attrs[$attr]= array();
188         }
189       }
190     }
192     /* Write to LDAP */
193     $ldap= $this->config->get_ldap_link();
194     $ldap->cd($this->dn);
195     $ldap->modify($this->attrs);
196     show_ldap_error($ldap->get_error());
198     /* Optionally execute a command after we're done */
199     if ($this->initially_was_account == $this->is_account){
200       if ($this->is_modified){
201         $this->handle_post_events("mofify");
202       }
203     } else {
204       $this->handle_post_events("add");
205     }
206   }
210 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
211 ?>