Code

removed debug output
[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 */
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   
31   var $goImapServerStatus   = "";
32   
33   var $cyrusImap            = false;
34   var $cyrusImapSSL         = false;
35   var $cyrusPop3            = false;
36   var $cyrusPop3SSL         = false;
37   var $is_account           = false;
39   var $acl; 
41   var $Actions              = array();  
42   var $conflicts            = array("goImapServer","kolab");
43  
44   function goImapServer($config,$dn)
45   {
46     plugin::plugin($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     /* set new status */
62     if(isset($_POST['ExecAction'])){
63       if(isset($this->Actions[$_POST['action']])){
64         $this->setStatus($_POST['action']);
65       }
66     }
68     foreach($this->attributes as $attr){
69       $smarty->assign($attr,$this->$attr);  
70       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));  
71     }
72     $smarty->assign("Actions",$this->Actions);
73     $smarty->assign("is_new",$this->dn);
74     $smarty->assign("is_acc",$this->initially_was_account);
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['AllowRestart'] = 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     $this->handle_post_events("remove");
106   }
108   function save()
109   {
110     $this->goImapSieveServer = $this->cn;
111     plugin::save();
112     /* Check if this is a new entry ... add/modify */
113     $ldap = $this->config->get_ldap_link();
114     $ldap->cat($this->dn,array("objectClass"));
115     if($ldap->count()){
116       $ldap->cd($this->dn);
117       $ldap->modify($this->attrs);
118     }else{
119       $ldap->cd($this->dn);
120       $ldap->add($this->attrs);
121     }
122     show_ldap_error($ldap->get_error());
123     if($this->initially_was_account){
124       $this->handle_post_events("modify");
125     }else{
126       $this->handle_post_events("add");
127     }
129   }
132    /* Directly save new status flag */
133   function setStatus($value)
134   {
135     if($value == "none") return;
136     if(!$this->initially_was_account) return;
137     $ldap = $this->config->get_ldap_link();
138     $ldap->cd($this->dn);
139     $ldap->cat($this->dn,array("objectClass"));
140     if($ldap->count()){
142       $tmp = $ldap->fetch();
143       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
144         $attrs['objectClass'][] = $tmp['objectClass'][$i];
145       }
146       $flag = $this->StatusFlag;
147       $attrs[$flag] = $value;
148       $this->$flag = $value;
149       $ldap->modify($attrs);
150       show_ldap_error($ldap->get_error());
151       $this->action_hook();
152     }
153   }
156   function check()
157   { 
158     $message = plugin::check();
159     if(empty($this->goImapName)){
160       $message[] =_("Please specify a server identifier.");
161     }  
162     if(empty($this->goImapConnect)){
163       $message[] =_("Please specify a connect url.");
164     }  
165     if(empty($this->goImapAdmin)){
166       $message[] =_("Please specify an admin user.");
167     }  
168     if(empty($this->goImapPassword)){
169       $message[] =_("Please specify a password for the admin user.");
170     } 
172     /* Check connect string */
173     if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
174       $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
175           '{server-name:port/options}');
176     }
177     if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
178       $message[]= _("The sieve port needs to be numeric.");
179     }
180  
181     return ($message);
182   }
185   function save_object()
186   {
187     if(isset($_POST['goImapServerPosted'])){
188       plugin::save_object(); 
190       foreach(array("cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL") as $checkbox) { 
191         if(!isset($_POST[$checkbox])){
192           $this->$checkbox = false;
193         }else{
194           $this->$checkbox = true;
195         }
196       }
197     }
198   }
200    function action_hook($add_attrs= array())
201   {
202     /* Find postcreate entries for this class */
203     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
204     if ($command == "" && isset($this->config->data['TABS'])){
205       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
206     }
207     if ($command != ""){
208       /* Walk through attribute list */
209       foreach ($this->attributes as $attr){
210         if (!is_array($this->$attr)){
211           $command= preg_replace("/%$attr/", $this->$attr, $command);
212         }
213       }
214       $command= preg_replace("/%dn/", $this->dn, $command);
215       /* Additional attributes */
216       foreach ($add_attrs as $name => $value){
217         $command= preg_replace("/%$name/", $value, $command);
218       }
220       /* If there are still some %.. in our command, try to fill these with some other class vars */
221       if(preg_match("/%/",$command)){
222         $attrs = get_object_vars($this);
223         foreach($attrs as $name => $value){
224           if(!is_string($value)) continue;
225           $command= preg_replace("/%$name/", $value, $command);
226         }
227       }
229       if (check_command($command)){
230         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
231             $command, "Execute");
233         exec($command);
234       } else {
235         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
236         print_red ($message);
237       }
238     }
239   }
242 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
243 ?>