Code

3b794ecb5faf9788f4842af58b320d6b0b37eee7
[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 = _("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"));
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     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     $ldap = $this->config->get_ldap_link();
129     $ldap->cd($this->dn);
130     $ldap->cat($this->dn,array("objectClass","goImapName","goImapConnect","goImapAdmin","goImapPassword"));
132     if($ldap->count()){
134       $attrs =array();
135       foreach(array("goImapName","goImapConnect","goImapAdmin","goImapPassword") as $required){
136         if(!isset($attrs[$required])){
137           if(empty($this->$required)){
138             print_red(_("Can't set new status while there are blank option within generic configuration part."));
139             return;
140           }else{
141             $attrs[$required] = $this->$required;
142           }
143         }else{
144           $attrs[$required] = $attrs[$required][0];
145         }
146       }
148       $tmp = $ldap->fetch();
149       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
150         $attrs['objectClass'][] = $tmp['objectClass'][$i];
151       }
152       if(!in_array("goImapServer",$attrs['objectClass'])){
153         $attrs['objectClass'][] = "goImapServer";
154       }
155       $flag = $this->StatusFlag;
156       $attrs[$flag] = $value;
157       $this->$flag = $value;
158       $ldap->modify($attrs);
159       show_ldap_error($ldap->get_error());
160     }
161   }
164   function check()
165   { 
166     $message = plugin::check();
167     if(empty($this->goImapName)){
168       $message[] =_("Please specify a server identifier.");
169     }  
170     if(empty($this->goImapConnect)){
171       $message[] =_("Please specify a connect url.");
172     }  
173     if(empty($this->goImapAdmin)){
174       $message[] =_("Please specify an admin user.");
175     }  
176     if(empty($this->goImapPassword)){
177       $message[] =_("Please specify a password for the admin user.");
178     } 
180     /* Check connect string */
181     if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
182       $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
183           '{server-name:port/options}');
184     }
185     if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
186       $message[]= _("The sieve port needs to be numeric.");
187     }
188  
189     return ($message);
190   }
193   function save_object()
194   {
195     if(isset($_POST['goImapServerPosted'])){
196       plugin::save_object(); 
198       foreach(array("cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL") as $checkbox) { 
199         if(!isset($_POST[$checkbox])){
200           $this->$checkbox = false;
201         }else{
202           $this->$checkbox = true;
203         }
204       }
205     }
206   }
208 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
209 ?>