1 <?php
3 class goImapServer extends goService {
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 */
14 var $DisplayName = "";
15 var $dn = NULL;
16 var $StatusFlag = "goImapServerStatus";
17 var $attributes = array("goImapName","goImapConnect","goImapAdmin","goImapPassword",
18 "goImapSieveServer","goImapSievePort",
19 "cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL");
21 var $cn = "";
23 var $goImapName = "";
24 var $goImapConnect = "";
25 var $goImapAdmin = "";
26 var $goImapPassword = "";
28 var $goImapSieveServer = "";
29 var $goImapSievePort = "";
30 var $goImapServerStatus = "";
32 var $cyrusImap = false;
33 var $cyrusImapSSL = false;
34 var $cyrusPop3 = false;
35 var $cyrusPop3SSL = false;
36 var $is_account = false;
37 var $view_logged =FALSE;
39 var $acl;
41 var $Actions = array();
42 var $conflicts = array("goImapServer");
44 function goImapServer(&$config,$dn)
45 {
46 goService::goService($config,$dn);
48 $this->DisplayName = _("IMAP/POP3 service");
50 $this->Actions = array( SERVICE_STOPPED=>SERVICE_STOPPED,
51 SERVICE_STARTED => SERVICE_STARTED,
52 SERVICE_RESTARTED=>SERVICE_RESTARTED,
53 "repair_database"=>_("Repair database"));
55 }
57 function execute()
58 {
59 $smarty = get_smarty();
61 if($this->is_account && !$this->view_logged){
62 $this->view_logged = TRUE;
63 new log("view","server/".get_class($this),$this->dn);
64 }
66 /* set new status */
67 if(isset($_POST['ExecAction'])){
68 if(isset($this->Actions[$_POST['action']])){
70 $tmp = $this->plInfo();
71 foreach($tmp['plProvidedAcls'] as $name => $translation) {
72 if(preg_match("/^".$_POST['action']."$/i",$name)){
73 if($this->acl_is_writeable($name)){
74 $this->setStatus($_POST['action']);
75 }
76 }
77 }
79 }
80 }
82 foreach($this->attributes as $attr){
83 $smarty->assign($attr,$this->$attr);
84 }
86 $tmp = $this->plInfo();
87 foreach($tmp['plProvidedAcls'] as $name => $translation){
88 $smarty->assign($name."ACL",$this->getacl($name));
89 }
91 $smarty->assign("Actions",$this->Actions);
92 $smarty->assign("is_new",$this->dn);
93 $smarty->assign("is_acc",$this->initially_was_account);
94 return($smarty->fetch(get_template_path("goImapServer.tpl",TRUE,dirname(__FILE__))));
95 }
97 function getListEntry()
98 {
99 $fields = goService::getListEntry();
100 $fields['Message'] = _("IMAP/POP3 (Cyrus) service");
101 #$fields['AllowRemove']= true;
102 #$fields['AllowEdit'] = true;
103 return($fields);
104 }
106 function check()
107 {
108 $message = plugin::check();
109 if(empty($this->goImapName)){
110 $message[] = msgPool::required(_("Server identifier"));
111 }
113 if(empty($this->goImapConnect)){
114 $message[] = msgPool::required(_("Connect URL"));
115 }elseif(!preg_match('/^\{[^:]+:[0-9]*\/.*\}$/', $this->goImapConnect)){
116 $message[]= msgPool::invalid(_("Connect URL"),"","","{server-name:port/options}");
117 }
119 if(empty($this->goImapSieveServer)){
120 $message[] = msgPool::required(_("Sieve connect URL"));
121 }elseif(!preg_match('/^\{[^:]+:[0-9]*\/(no|)tls\}$/', $this->goImapSieveServer)){
122 $message[]= msgPool::invalid(_("Sieve connect URL"),"","","{server-name:port/options}"." ".
123 sprintf(_("Valid options are: %s"),"tls,notls"));
124 }
126 if(empty($this->goImapAdmin)){
127 $message[] = msgPool::required(_("Admin user"));
128 }
129 if(empty($this->goImapPassword)){
130 $message[] = msgPool::required(_("Password"));
131 }
133 # if(empty($this->goImapSievePort)){
134 # $message[] = msgPool::required(_("Sieve port"));
135 # }elseif (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
136 # $message[]= msgPool::invalid(_("Sieve port"),$this->goImapSievePort,"/[0-9]/");
137 # }
139 return ($message);
140 }
143 function save_object()
144 {
145 if(isset($_POST['goImapServerPosted'])){
146 plugin::save_object();
148 foreach(array("cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL") as $checkbox) {
150 if($this->acl_is_writeable($checkbox)){
151 if(!isset($_POST[$checkbox])){
152 $this->$checkbox = false;
153 }else{
154 $this->$checkbox = true;
155 }
156 }
157 }
158 $this->goImapConnect = trim($this->goImapConnect);
159 $this->goImapSieveServer = trim($this->goImapSieveServer);
160 }
161 }
164 /* Save service */
165 function save()
166 {
168 plugin::save();
170 $this->attrs['goImapSievePort'] = preg_replace("/^\{[^:]+:([0-9]*)\/.*$/","\\1",$this->goImapSieveServer);
172 /* Check if this is a new entry ... add/modify */
173 $ldap = $this->config->get_ldap_link();
174 $ldap->cat($this->dn,array("objectClass"));
175 if($ldap->count()){
176 $ldap->cd($this->dn);
177 $ldap->modify($this->attrs);
178 }else{
179 $ldap->cd($this->dn);
180 $ldap->add($this->attrs);
181 }
182 if($this->initially_was_account){
183 new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
184 $this->handle_post_events("modify");
185 }else{
186 $this->handle_post_events("add");
187 new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
188 }
189 if (!$ldap->success()){
190 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
191 }
192 }
195 /* Return plugin informations for acl handling */
196 static function plInfo()
197 {
198 return (array(
199 "plShortName" => _("IMAP/POP3"),
200 "plDescription" => _("IMAP/POP3")." ("._("Services").")",
201 "plSelfModify" => FALSE,
202 "plDepends" => array(),
203 "plPriority" => 94,
204 "plSection" => array("administration"),
205 "plCategory" => array("server"),
207 "plProvidedAcls"=> array(
209 "start" => _("Start"),
210 "stop" => _("Stop"),
211 "restart" => _("Restart"),
212 "repair_database" => _("Repair database"),
214 "goImapName" =>_("Server identifier"),
215 "goImapConnect" =>_("Connect URL"),
216 "goImapAdmin" =>_("Admin user"),
217 "goImapPassword" =>_("Admin password"),
218 // "goImapSievePort" =>_("Sieve port"),
219 "goImapSieveServer"=>_("Sieve connect URL"),
220 "cyrusImap" =>_("Start IMAP service"),
221 "cyrusImapSSL" =>_("Start IMAP SSL service"),
222 "cyrusPop3" =>_("Start POP3 service"),
223 "cyrusPop3SSL" =>_("Start POP3 SSL service"))
224 ));
225 }
227 }
228 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
229 ?>