1 <?php
3 class goImapServer extends plugin{
5 var $cli_summary = "This pluign is used within the ServerService Pluign \nand indicates that this server supports mailqueue listings and so on.";
6 var $cli_description = "Some longer text\nfor help";
7 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* This plugin only writes its objectClass */
10 var $objectclasses = array("goImapServer");
12 /* This class can't be assigned twice so it conflicts with itsself */
13 var $conflicts = array("goImapServer");
15 var $DisplayName = "";
16 var $dn = NULL;
17 var $StatusFlag = "goImapServerStatus";
18 var $attributes = array("goImapServerStatus",
19 "goImapName","goImapConnect","goImapAdmin","goImapPassword",
20 "goImapSieveServer","goImapSievePort",
21 "cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL");
23 var $cn;
25 var $goImapName = "";
26 var $goImapConnect = "";
27 var $goImapAdmin = "";
28 var $goImapPassword = "";
30 var $goImapSieveServer = "";
31 var $goImapSievePort = "";
33 var $goImapServerStatus = "";
35 var $cyrusImap = false;
36 var $cyrusImapSSL = false;
37 var $cyrusPop3 = false;
38 var $cyrusPop3SSL = false;
39 var $is_account = false;
41 var $acl;
43 var $Actions = array();
45 function goImapServer($config,$dn)
46 {
47 plugin::plugin($config,$dn);
49 $this->DisplayName = _("Cyrus service");
51 $this->Actions = array( SERVICE_STOPPED=>SERVICE_STOPPED,
52 SERVICE_STARTED => SERVICE_STARTED,
53 SERVICE_RESETTED=>SERVICE_RESETTED,
54 "repair_database"=>_("Repair database"));
56 }
58 function execute()
59 {
60 $smarty = get_smarty();
62 /* set new status */
63 if(isset($_POST['ExecAction'])){
64 if(isset($this->Actions[$_POST['action']])){
65 $this->setStatus($_POST['action']);
66 }
67 }
69 foreach($this->attributes as $attr){
70 $smarty->assign($attr,$this->$attr);
71 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
72 }
73 $smarty->assign("Actions",$this->Actions);
74 $smarty->assign("is_new",$this->dn);
75 return($smarty->fetch(get_template_path("goImapServer.tpl",TRUE,dirname(__FILE__))));
76 }
78 function getListEntry()
79 {
80 $flag = $this->StatusFlag;
81 $fields['Status'] = $this->$flag;
82 $fields['Message'] = _("Cyrus service");
83 $fields['AllowStart'] = true;
84 $fields['AllowStop'] = true;
85 $fields['AllowReset'] = true;
86 $fields['AllowRemove']= true;
87 $fields['AllowEdit'] = true;
88 return($fields);
89 }
91 function remove_from_parent()
92 {
93 plugin::remove_from_parent();
94 /* Check if this is a new entry ... add/modify */
95 $ldap = $this->config->get_ldap_link();
96 $ldap->cat($this->dn,array("objectClass"));
97 if($ldap->count()){
98 $ldap->cd($this->dn);
99 $ldap->modify($this->attrs);
100 }else{
101 $ldap->cd($this->dn);
102 $ldap->add($this->attrs);
103 }
104 show_ldap_error($ldap->get_error());
105 }
107 function save()
108 {
109 $this->goImapSieveServer = $this->cn;
110 plugin::save();
111 /* Check if this is a new entry ... add/modify */
112 $ldap = $this->config->get_ldap_link();
113 $ldap->cat($this->dn,array("objectClass"));
114 if($ldap->count()){
115 $ldap->cd($this->dn);
116 $ldap->modify($this->attrs);
117 }else{
118 $ldap->cd($this->dn);
119 $ldap->add($this->attrs);
120 }
121 show_ldap_error($ldap->get_error());
122 }
125 /* Directly save new status flag */
126 function setStatus($value)
127 {
128 if($value == "none") return;
129 $ldap = $this->config->get_ldap_link();
130 $ldap->cd($this->dn);
131 $ldap->cat($this->dn,array("objectClass","goImapName","goImapConnect","goImapAdmin","goImapPassword"));
133 if($ldap->count()){
135 $attrs =array();
136 foreach(array("goImapName","goImapConnect","goImapAdmin","goImapPassword") as $required){
137 if(!isset($attrs[$required])){
138 if(empty($this->$required)){
139 print_red(_("Can't set new status while there are blank option within generic configuration part."));
140 return;
141 }else{
142 $attrs[$required] = $this->$required;
143 }
144 }else{
145 $attrs[$required] = $attrs[$required][0];
146 }
147 }
149 $tmp = $ldap->fetch();
150 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
151 $attrs['objectClass'][] = $tmp['objectClass'][$i];
152 }
153 if(!in_array("goImapServer",$attrs['objectClass'])){
154 $attrs['objectClass'][] = "goImapServer";
155 }
156 $flag = $this->StatusFlag;
157 $attrs[$flag] = $value;
158 $this->$flag = $value;
159 $ldap->modify($attrs);
160 show_ldap_error($ldap->get_error());
161 }
162 }
165 function check()
166 {
167 $message = plugin::check();
168 if(empty($this->goImapName)){
169 $message[] =_("Please specify a server identifier.");
170 }
171 if(empty($this->goImapConnect)){
172 $message[] =_("Please specify a connect url.");
173 }
174 if(empty($this->goImapAdmin)){
175 $message[] =_("Please specify an admin user.");
176 }
177 if(empty($this->goImapPassword)){
178 $message[] =_("Please specify a password for the admin user.");
179 }
181 /* Check connect string */
182 if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
183 $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
184 '{server-name:port/options}');
185 }
186 if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
187 $message[]= _("The sieve port needs to be numeric.");
188 }
190 return ($message);
191 }
194 function save_object()
195 {
196 if(isset($_POST['goImapServerPosted'])){
197 plugin::save_object();
199 foreach(array("cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL") as $checkbox) {
200 if(!isset($_POST[$checkbox])){
201 $this->$checkbox = false;
202 }else{
203 $this->$checkbox = true;
204 }
205 }
206 }
207 }
208 }
209 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
210 ?>