4244e40dd8252b298da643c4aa7a55578883a098
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();
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 }
168 plugin::save();
172 $test = $this->objectclasses;
173 $tmp = array_flip($this->attrs['objectClass']);
175 foreach($this->additionaloc as $key=>$val) {
176 unset($tmp[$key]);
177 }
179 foreach($tmp as $val){
180 if(in_array($val,$test)){
181 $tmp[$val];
182 }
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);
205 /* Write to LDAP */
206 $ldap= $this->config->get_ldap_link();
207 $ldap->cd($this->dn);
208 $ldap->modify($this->attrs);
209 show_ldap_error($ldap->get_error());
211 /* Optionally execute a command after we're done */
212 if ($this->initially_was_account == $this->is_account){
213 if ($this->is_modified){
214 $this->handle_post_events("mofify");
215 }
216 } else {
217 $this->handle_post_events("add");
218 }
219 }
221 }
223 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
224 ?>