1df3e2251d610642e9a2c44e02ec25e155238f1e
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", "");
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 plugin::save_object();
101 /* Save checkbox state */
102 foreach ($this->additionaloc as $oc => $dummy){
103 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
104 $this->objectclasses[$oc]= $oc;
105 } else {
106 unset($this->objectclasses[$oc]);
107 }
108 }
109 }
112 /* Check supplied data */
113 function check()
114 {
115 $message= array();
117 /* All fields are marked as *must* */
118 if (in_array("goImapServer", $this->objectclasses)){
119 foreach (array("goImapAdmin", "goImapName") as $attr){
120 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
121 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
122 }
123 }
125 /* Check connect string */
126 if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
127 $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
128 '{server-name:port/options}');
129 }
130 if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
131 $message[]= _("The sieve port needs to be numeric.");
132 }
133 }
134 if (in_array("goKrbServer", $this->objectclasses)){
135 foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
136 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
137 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
138 }
139 }
140 }
141 if (in_array("goFaxServer", $this->objectclasses)){
142 if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
143 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
144 }
145 }
146 if (in_array("goLogServer", $this->objectclasses)){
147 if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
148 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
149 }
150 }
151 if (in_array("goFonServer", $this->objectclasses)){
152 foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
153 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
154 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
155 }
156 }
157 }
159 return ($message);
160 }
163 /* Save to LDAP */
164 function save()
165 {
166 /* Normalize lazy objectclass arrays */
167 $objectclasses= array();
168 foreach($this->objectclasses as $oc){
169 $objectclasses[]= $oc;
170 }
172 plugin::save();
176 $test = $this->objectclasses;
177 $tmp = array_flip($this->attrs['objectClass']);
179 foreach($this->additionaloc as $key=>$val) {
180 unset($tmp[$key]);
181 }
183 $classes = (array_flip(array_merge(array_flip($test),$tmp)));
185 unset($this->attrs['objectClass']);
187 foreach($classes as $class){
188 $this->attrs['objectClass'][]=$class;
189 }
192 /* Remove unneeded attributes */
193 foreach ($this->additionaloc as $oc => $attrs){
194 if (!in_array($oc, $this->attrs['objectClass'])){
195 foreach ($attrs as $attr){
196 $this->attrs[$attr]= array();
197 }
198 }
199 }
200 $this->attrs = array_reverse($this->attrs);
203 /* Write to LDAP */
204 $ldap= $this->config->get_ldap_link();
205 $ldap->cd($this->dn);
206 // print_a($this->attrs);
207 $ldap->modify($this->attrs);
208 show_ldap_error($ldap->get_error());
210 /* Optionally execute a command after we're done */
211 if ($this->initially_was_account == $this->is_account){
212 if ($this->is_modified){
213 $this->handle_post_events("mofify");
214 }
215 } else {
216 $this->handle_post_events("add");
217 }
218 }
220 }
222 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
223 ?>