Code

53e1688c46c55b0b0d9b8bd411c04a3a35185231
[gosa.git] / plugins / admin / systems / class_goImapServer.inc
1 <?php
3 class goImapServer extends plugin{
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 */
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       = "";
29   
30   var $goImapSieveServer    = "";
31   var $goImapSievePort      = "";
32   
33   var $goImapServerStatus   = "";
34   
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();
44  
45   function goImapServer($config,$dn)
46   {
47     plugin::plugin($config,$dn);
48   
49     $this->DisplayName = _("IMAP/POP3 service");
51     $this->Actions = array( SERVICE_STOPPED=>SERVICE_STOPPED,
52                             SERVICE_STARTED => SERVICE_STARTED,
53                             SERVICE_RESTARTED=>SERVICE_RESTARTED,
54                             "repair_database"=>_("Repair database"));
55     
56   }
58   function execute()
59   { 
60     $smarty = get_smarty();
61   
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     $smarty->assign("is_acc",$this->initially_was_account);
76     return($smarty->fetch(get_template_path("goImapServer.tpl",TRUE,dirname(__FILE__))));
77   }
79   function getListEntry()
80   {
81     $flag = $this->StatusFlag;
82     $fields['Status']     = $this->$flag;
83     $fields['Message']    = _("Cyrus service");
84     $fields['AllowStart'] = true;
85     $fields['AllowStop']  = true;
86     $fields['AllowRestart'] = true;
87     $fields['AllowRemove']= true;
88     $fields['AllowEdit']  = true;
89     return($fields);
90   }
92   function remove_from_parent()
93   {
94     plugin::remove_from_parent();
95     /* Check if this is a new entry ... add/modify */
96     $ldap = $this->config->get_ldap_link();
97     $ldap->cat($this->dn,array("objectClass"));
98     if($ldap->count()){
99       $ldap->cd($this->dn);
100       $ldap->modify($this->attrs);
101     }else{
102       $ldap->cd($this->dn);
103       $ldap->add($this->attrs);
104     }
105     show_ldap_error($ldap->get_error());
106     $this->handle_post_events("remove");
107   }
109   function save()
110   {
111     $this->goImapSieveServer = $this->cn;
112     plugin::save();
113     /* Check if this is a new entry ... add/modify */
114     $ldap = $this->config->get_ldap_link();
115     $ldap->cat($this->dn,array("objectClass"));
116     if($ldap->count()){
117       $ldap->cd($this->dn);
118       $ldap->modify($this->attrs);
119     }else{
120       $ldap->cd($this->dn);
121       $ldap->add($this->attrs);
122     }
123     show_ldap_error($ldap->get_error());
124     if($this->initially_was_account){
125       $this->handle_post_events("modify");
126     }else{
127       $this->handle_post_events("add");
128     }
130   }
133    /* Directly save new status flag */
134   function setStatus($value)
135   {
136     if($value == "none") return;
137     if(!$this->initially_was_account) return;
138     $ldap = $this->config->get_ldap_link();
139     $ldap->cd($this->dn);
140     $ldap->cat($this->dn,array("objectClass"));
141     if($ldap->count()){
143       $tmp = $ldap->fetch();
144       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
145         $attrs['objectClass'][] = $tmp['objectClass'][$i];
146       }
147       $flag = $this->StatusFlag;
148       $attrs[$flag] = $value;
149       $this->$flag = $value;
150       $ldap->modify($attrs);
151       show_ldap_error($ldap->get_error());
152       $this->action_hook();
153     }
154   }
157   function check()
158   { 
159     $message = plugin::check();
160     if(empty($this->goImapName)){
161       $message[] =_("Please specify a server identifier.");
162     }  
163     if(empty($this->goImapConnect)){
164       $message[] =_("Please specify a connect url.");
165     }  
166     if(empty($this->goImapAdmin)){
167       $message[] =_("Please specify an admin user.");
168     }  
169     if(empty($this->goImapPassword)){
170       $message[] =_("Please specify a password for the admin user.");
171     } 
173     /* Check connect string */
174     if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
175       $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
176           '{server-name:port/options}');
177     }
178     if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
179       $message[]= _("The sieve port needs to be numeric.");
180     }
181  
182     return ($message);
183   }
186   function save_object()
187   {
188     if(isset($_POST['goImapServerPosted'])){
189       plugin::save_object(); 
191       foreach(array("cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL") as $checkbox) { 
192         if(!isset($_POST[$checkbox])){
193           $this->$checkbox = false;
194         }else{
195           $this->$checkbox = true;
196         }
197       }
198     }
199   }
201    function action_hook($add_attrs= array())
202   {
203     /* Find postcreate entries for this class */
204     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
205     if ($command == "" && isset($this->config->data['TABS'])){
206       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
207     }
208     if ($command != ""){
209       /* Walk through attribute list */
210       foreach ($this->attributes as $attr){
211         if (!is_array($this->$attr)){
212           $command= preg_replace("/%$attr/", $this->$attr, $command);
213         }
214       }
215       $command= preg_replace("/%dn/", $this->dn, $command);
216       /* Additional attributes */
217       foreach ($add_attrs as $name => $value){
218         $command= preg_replace("/%$name/", $value, $command);
219       }
221       /* If there are still some %.. in our command, try to fill these with some other class vars */
222       if(preg_match("/%/",$command)){
223         $attrs = get_object_vars($this);
224         foreach($attrs as $name => $value){
225           if(!is_string($value)) continue;
226           $command= preg_replace("/%$name/", $value, $command);
227         }
228       }
230       if (check_command($command)){
231         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
232             $command, "Execute");
234         exec($command);
235       } else {
236         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
237         print_red ($message);
238       }
239     }
240   }
243 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
244 ?>