58b26e7663f4159e4fd49fd2350da308bcde0766
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","goGlpiAdmin","goGlpiDatabase","goGlpiPassword");
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 "goGlpiServer" => array("goGlpiAdmin","goGlpiDatabase","goGlpiPassword"),
47 "goFonServer" => array("goFonAdmin", "goFonPassword",
48 "goFonAreaCode", "goFonCountryCode"));
50 function servdb ($config, $dn= NULL)
51 {
52 plugin::plugin ($config, $dn);
54 /* Make dynamic list of objectClasses */
55 foreach ($this->additionaloc as $oc => $dummy){
56 if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
57 $this->objectclasses[$oc]= $oc;
58 }
59 }
61 /* We need to save the historical state of goImapName for later checking */
62 $this->goImapName_old= $this->goImapName;
64 /* Always is account... */
65 $this->is_account= TRUE;
66 }
68 function execute()
69 {
70 /* Call parent execute */
71 plugin::execute();
73 /* Fill templating stuff */
74 $smarty= get_smarty();
76 /* Attributes... */
77 foreach ($this->attributes as $attr){
78 $smarty->assign("$attr", $this->$attr);
79 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
80 }
82 /* Don't show Asterisk for non-required attribute ipHostNumber and macAddress */
83 $smarty->assign("staticAddress", "");
85 /* Classes... */
86 foreach ($this->additionaloc as $oc => $dummy){
87 if (isset($this->objectclasses[$oc])){
88 $smarty->assign("$oc", "checked");
89 $smarty->assign("$oc"."State", "");
90 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
92 } else {
93 $smarty->assign("$oc", "");
94 $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
95 $smarty->assign("$oc"."State", "disabled");
96 }
97 }
99 return($smarty->fetch (get_template_path('servdb.tpl', TRUE)));
100 }
102 function remove_from_parent()
103 {
104 /* This cannot be removed... */
105 }
108 /* Save data to object */
109 function save_object()
110 {
111 if (isset($_POST['dbtab'])){
112 plugin::save_object();
114 /* Save checkbox state */
115 foreach ($this->additionaloc as $oc => $dummy){
116 if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
117 $this->objectclasses[$oc]= $oc;
118 } else {
119 unset($this->objectclasses[$oc]);
120 }
121 }
122 }
123 }
126 /* Check supplied data */
127 function check()
128 {
129 $message= array();
131 /* All fields are marked as *must* */
132 if (in_array("goImapServer", $this->objectclasses)){
133 foreach (array("goImapAdmin", "goImapName") as $attr){
134 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
135 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
136 }
137 }
139 /* Check connect string */
140 if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
141 $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
142 '{server-name:port/options}');
143 }
144 if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
145 $message[]= _("The sieve port needs to be numeric.");
146 }
147 }
148 if (in_array("goKrbServer", $this->objectclasses)){
149 foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
150 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
151 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
152 }
153 }
154 /* goKrbPassword is a must field, if goKrbServer is used as objectClass */
155 if ($this->goKrbPassword == "" ){
156 $message[]= sprintf(_("The specified kerberos password is empty."), $attr);
157 }
158 }
159 if (in_array("goFaxServer", $this->objectclasses)){
160 if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
161 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
162 }
163 }
164 if (in_array("goLogServer", $this->objectclasses)){
165 if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
166 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
167 }
168 }
169 if (in_array("goFonServer", $this->objectclasses)){
170 foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
171 if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
172 $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
173 }
174 }
175 }
176 if (in_array("goImapServer", $this->objectclasses) &&
177 $this->goImapName != $this->goImapName_old) {
178 // Attribute has changed
179 if(!preg_match("/^[a-z0-9.-]+$/", $this->goImapName)) {
180 $message[]= sprintf(_("The imap name string needs to be a hostname or an IP-address."));
181 }
182 }
184 return ($message);
185 }
188 /* Save to LDAP */
189 function save()
190 {
191 /* Normalize lazy objectclass arrays */
192 $objectclasses= array();
193 foreach($this->objectclasses as $oc){
194 $objectclasses[]= $oc;
195 }
197 /* Move cn to sieve server */
198 $this->goImapSieveServer= $this->cn;
200 plugin::save();
202 $test = $this->objectclasses;
203 $tmp = array_flip($this->attrs['objectClass']);
205 foreach($this->additionaloc as $key=>$val) {
206 unset($tmp[$key]);
207 }
209 $classes = (array_flip(array_merge(array_flip($test),$tmp)));
211 unset($this->attrs['objectClass']);
213 foreach($classes as $class){
214 $this->attrs['objectClass'][]=$class;
215 }
218 /* Remove unneeded attributes */
219 foreach ($this->additionaloc as $oc => $attrs){
220 if (!in_array($oc, $this->attrs['objectClass'])){
221 foreach ($attrs as $attr){
222 $this->attrs[$attr]= array();
223 }
224 }
225 }
226 $this->attrs = array_reverse($this->attrs);
228 /* Write to LDAP */
229 $ldap= $this->config->get_ldap_link();
230 $ldap->cd($this->dn);
231 $ldap->modify($this->attrs);
232 show_ldap_error($ldap->get_error());
234 /* Optionally execute a command after we're done */
235 if ($this->initially_was_account == $this->is_account){
236 if ($this->is_modified){
237 $this->handle_post_events("mofify");
238 }
239 } else {
240 $this->handle_post_events("add");
241 }
242 }
244 }
246 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
247 ?>