Code

Updated services.
[gosa.git] / gosa-plugins / mail / admin / systems / services / imap / class_goImapServer.inc
1 <?php
3 class goImapServer extends goService {
4         
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");
11   
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       = "";
27   
28   var $goImapSieveServer    = "";
29   var $goImapSievePort      = "";
30   var $goImapServerStatus   = "";
31   
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","kolab");
43  
44   function goImapServer(&$config,$dn)
45   {
46     goService::goService($config,$dn);
47   
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"));
54     
55   }
57   function execute()
58   { 
59     $smarty = get_smarty();
60  
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     }  
112     if(empty($this->goImapConnect)){
113       $message[] = msgPool::required(_("Connect URL"));
114     }elseif(!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
115       $message[]= msgPool::invalid(_("Connect URL"),"","","{server-name:port/options}");
116     } 
118     if(empty($this->goImapSieveServer)){
119       $message[] = msgPool::required(_("Sieve connect URL"));
120     }elseif(!preg_match('/^\{[^:]+:[0-9]*\/(no|)tls\}$/', $this->goImapSieveServer)){
121       $message[]= msgPool::invalid(_("Sieve connect URL"),"","","{server-name:port/options}"."&nbsp;".
122           sprintf(_("Valid options are: %s"),"tls,notls"));
123     } 
125     if(empty($this->goImapAdmin)){
126       $message[] = msgPool::required(_("Admin user"));
127     }  
128     if(empty($this->goImapPassword)){
129       $message[] = msgPool::required(_("Password"));
130     } 
132 #   if(empty($this->goImapSievePort)){
133 #     $message[] = msgPool::required(_("Sieve port"));
134 #   }elseif (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
135 #     $message[]= msgPool::invalid(_("Sieve port"),$this->goImapSievePort,"/[0-9]/");
136 #   }
137  
138     return ($message);
139   }
142   function save_object()
143   {
144     if(isset($_POST['goImapServerPosted'])){
145       plugin::save_object(); 
147       foreach(array("cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL") as $checkbox) { 
149         if($this->acl_is_writeable($checkbox)){
150           if(!isset($_POST[$checkbox])){
151             $this->$checkbox = false;
152           }else{
153             $this->$checkbox = true;
154           }
155         }
156       }
157     }
158   }
161   /* Save service */
162   function save()
163   {
164     
165     plugin::save();
167     $this->attrs['goImapSievePort']  = preg_replace("/^\{[^:]+:([0-9]*)\/.*$/","\\1",$this->goImapSieveServer);
168  
169     /* Check if this is a new entry ... add/modify */
170     $ldap = $this->config->get_ldap_link();
171     $ldap->cat($this->dn,array("objectClass"));
172     if($ldap->count()){
173       $ldap->cd($this->dn);
174       $ldap->modify($this->attrs);
175     }else{
176       $ldap->cd($this->dn);
177       $ldap->add($this->attrs);
178     }
179     if($this->initially_was_account){
180       new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
181       $this->handle_post_events("modify");
182     }else{
183       $this->handle_post_events("add");
184       new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
185     }
186     if (!$ldap->success()){
187       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
188     }
189   }
192   /* Return plugin informations for acl handling */
193   static function plInfo()
194   {
195     return (array(
196           "plShortName"   => _("IMAP/POP3"),
197           "plDescription" => _("IMAP/POP3")." ("._("Services").")",
198           "plSelfModify"  => FALSE,
199           "plDepends"     => array(),
200           "plPriority"    => 94,
201           "plSection"     => array("administration"),
202           "plCategory"    => array("server"),
204           "plProvidedAcls"=> array(
206             "start"           => _("Start"),
207             "stop"            => _("Stop"),
208             "restart"         => _("Restart"),
209             "repair_database" => _("Repair database"),
211             "goImapName"        =>_("Server identifier"),
212             "goImapConnect"     =>_("Connect URL"),
213             "goImapAdmin"       =>_("Admin user"),
214             "goImapPassword"    =>_("Admin password"),
215 //            "goImapSievePort"   =>_("Sieve port"),
216             "goImapSieveServer"=>_("Sieve connect URL"),
217             "cyrusImap"         =>_("Start IMAP service"),
218             "cyrusImapSSL"      =>_("Start IMAP SSL service"),
219             "cyrusPop3"         =>_("Start POP3 service"),
220             "cyrusPop3SSL"      =>_("Start POP3 SSL service"))
221           ));
222   }
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>