8f37bc5d3053c2191aebdd74bff59718f53f45df
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();
71 /* Fill templating stuff */
72 $smarty= get_smarty();
74 /* Attributes... */
75 foreach ($this->attributes as $attr){
76 $smarty->assign("$attr", $this->$attr);
77 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
78 }
80 /* Don't show Asterisk for non-required attribute ipHostNumber and macAddress */
81 $smarty->assign("staticAddress", "");
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));
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();
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 $message= array();
129 /* All fields are marked as *must* */
130 if (in_array("goImapServer", $this->objectclasses)){
131 foreach (array("goImapAdmin", "goImapName") 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 }
137 /* Check connect string */
138 if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
139 $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
140 '{server-name:port/options}');
141 }
142 if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
143 $message[]= _("The sieve port needs to be numeric.");
144 }
145 }
146 if (in_array("goKrbServer", $this->objectclasses)){
147 foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
148 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
149 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
150 }
151 }
152 /* goKrbPassword is a must field, if goKrbServer is used as objectClass */
153 if ($this->goKrbPassword == "" ){
154 $message[]= sprintf(_("The specified kerberos password is empty."), $attr);
155 }
156 }
157 if (in_array("goFaxServer", $this->objectclasses)){
158 if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
159 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
160 }
161 }
162 if (in_array("goLogServer", $this->objectclasses)){
163 if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
164 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
165 }
166 }
167 if (in_array("goFonServer", $this->objectclasses)){
168 foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
169 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
170 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
171 }
172 }
173 }
174 if (in_array("goImapServer", $this->objectclasses) &&
175 $this->goImapName != $this->goImapName_old) {
176 // Attribute has changed
177 if(!preg_match("/^[a-z0-9.-]+$/", $this->goImapName)) {
178 $message[]= sprintf(_("The imap name string needs to be a hostname or an IP-address."));
179 }
180 }
182 return ($message);
183 }
186 /* Save to LDAP */
187 function save()
188 {
189 /* Normalize lazy objectclass arrays */
190 $objectclasses= array();
191 foreach($this->objectclasses as $oc){
192 $objectclasses[]= $oc;
193 }
195 plugin::save();
199 $test = $this->objectclasses;
200 $tmp = array_flip($this->attrs['objectClass']);
202 foreach($this->additionaloc as $key=>$val) {
203 unset($tmp[$key]);
204 }
206 $classes = (array_flip(array_merge(array_flip($test),$tmp)));
208 unset($this->attrs['objectClass']);
210 foreach($classes as $class){
211 $this->attrs['objectClass'][]=$class;
212 }
215 /* Remove unneeded attributes */
216 foreach ($this->additionaloc as $oc => $attrs){
217 if (!in_array($oc, $this->attrs['objectClass'])){
218 foreach ($attrs as $attr){
219 $this->attrs[$attr]= array();
220 }
221 }
222 }
223 $this->attrs = array_reverse($this->attrs);
225 /* Write to LDAP */
226 $ldap= $this->config->get_ldap_link();
227 $ldap->cd($this->dn);
228 $ldap->modify($this->attrs);
229 show_ldap_error($ldap->get_error());
231 /* Optionally execute a command after we're done */
232 if ($this->initially_was_account == $this->is_account){
233 if ($this->is_modified){
234 $this->handle_post_events("mofify");
235 }
236 } else {
237 $this->handle_post_events("add");
238 }
239 }
241 }
243 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
244 ?>