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"."State", "");
78 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
80 } else {
81 $smarty->assign("$oc", "");
82 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
83 $smarty->assign("$oc"."State", "disabled");
84 }
85 }
87 return($smarty->fetch (get_template_path('servdb.tpl', TRUE)));
88 }
90 function remove_from_parent()
91 {
92 /* This cannot be removed... */
93 }
96 /* Save data to object */
97 function save_object()
98 {
99 if (isset($_POST['dbtab'])){
100 plugin::save_object();
102 /* Save checkbox state */
103 foreach ($this->additionaloc as $oc => $dummy){
104 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
105 $this->objectclasses[$oc]= $oc;
106 } else {
107 unset($this->objectclasses[$oc]);
108 }
109 }
110 }
111 }
114 /* Check supplied data */
115 function check()
116 {
117 $message= array();
119 /* All fields are marked as *must* */
120 if (in_array("goImapServer", $this->objectclasses)){
121 foreach (array("goImapAdmin", "goImapName") as $attr){
122 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
123 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
124 }
125 }
127 /* Check connect string */
128 if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
129 $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
130 '{server-name:port/options}');
131 }
132 if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
133 $message[]= _("The sieve port needs to be numeric.");
134 }
135 }
136 if (in_array("goKrbServer", $this->objectclasses)){
137 foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
138 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
139 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
140 }
141 }
142 }
143 if (in_array("goFaxServer", $this->objectclasses)){
144 if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
145 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
146 }
147 }
148 if (in_array("goLogServer", $this->objectclasses)){
149 if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
150 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
151 }
152 }
153 if (in_array("goFonServer", $this->objectclasses)){
154 foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
155 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
156 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
157 }
158 }
159 }
161 return ($message);
162 }
165 /* Save to LDAP */
166 function save()
167 {
168 /* Normalize lazy objectclass arrays */
169 $objectclasses= array();
170 foreach($this->objectclasses as $oc){
171 $objectclasses[]= $oc;
172 }
174 plugin::save();
178 $test = $this->objectclasses;
179 $tmp = array_flip($this->attrs['objectClass']);
181 foreach($this->additionaloc as $key=>$val) {
182 unset($tmp[$key]);
183 }
185 $classes = (array_flip(array_merge(array_flip($test),$tmp)));
187 unset($this->attrs['objectClass']);
189 foreach($classes as $class){
190 $this->attrs['objectClass'][]=$class;
191 }
194 /* Remove unneeded attributes */
195 foreach ($this->additionaloc as $oc => $attrs){
196 if (!in_array($oc, $this->attrs['objectClass'])){
197 foreach ($attrs as $attr){
198 $this->attrs[$attr]= array();
199 }
200 }
201 }
202 $this->attrs = array_reverse($this->attrs);
206 /* Write to LDAP */
207 $ldap= $this->config->get_ldap_link();
208 $ldap->cd($this->dn);
209 $ldap->modify($this->attrs);
210 show_ldap_error($ldap->get_error());
212 /* Optionally execute a command after we're done */
213 if ($this->initially_was_account == $this->is_account){
214 if ($this->is_modified){
215 $this->handle_post_events("mofify");
216 }
217 } else {
218 $this->handle_post_events("add");
219 }
220 }
222 }
224 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
225 ?>