Code

Fixed save_object
[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   }
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   }
126    /* Directly save new status flag */
127   function setStatus($value)
128   {
129     if($value == "none") return;
130     if(!$this->initially_was_account) return;
131     $ldap = $this->config->get_ldap_link();
132     $ldap->cd($this->dn);
133     $ldap->cat($this->dn,array("objectClass"));
134     if($ldap->count()){
136       $tmp = $ldap->fetch();
137       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
138         $attrs['objectClass'][] = $tmp['objectClass'][$i];
139       }
140       $flag = $this->StatusFlag;
141       $attrs[$flag] = $value;
142       $this->$flag = $value;
143       $ldap->modify($attrs);
144       show_ldap_error($ldap->get_error());
145       $this->action_hook();
146     }
147   }
150   function check()
151   { 
152     $message = plugin::check();
153     if(empty($this->goImapName)){
154       $message[] =_("Please specify a server identifier.");
155     }  
156     if(empty($this->goImapConnect)){
157       $message[] =_("Please specify a connect url.");
158     }  
159     if(empty($this->goImapAdmin)){
160       $message[] =_("Please specify an admin user.");
161     }  
162     if(empty($this->goImapPassword)){
163       $message[] =_("Please specify a password for the admin user.");
164     } 
166     /* Check connect string */
167     if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
168       $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
169           '{server-name:port/options}');
170     }
171     if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
172       $message[]= _("The sieve port needs to be numeric.");
173     }
174  
175     return ($message);
176   }
179   function save_object()
180   {
181     if(isset($_POST['goImapServerPosted'])){
182       plugin::save_object(); 
184       foreach(array("cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL") as $checkbox) { 
185         if(!isset($_POST[$checkbox])){
186           $this->$checkbox = false;
187         }else{
188           $this->$checkbox = true;
189         }
190       }
191     }
192   }
194    function action_hook($add_attrs= array())
195   {
196     /* Find postcreate entries for this class */
197     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
198     if ($command == "" && isset($this->config->data['TABS'])){
199       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
200     }
201     if ($command != ""){
202       /* Walk through attribute list */
203       foreach ($this->attributes as $attr){
204         if (!is_array($this->$attr)){
205           $command= preg_replace("/%$attr/", $this->$attr, $command);
206         }
207       }
208       $command= preg_replace("/%dn/", $this->dn, $command);
209       /* Additional attributes */
210       foreach ($add_attrs as $name => $value){
211         $command= preg_replace("/%$name/", $value, $command);
212       }
213       if (check_command($command)){
214         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
215             $command, "Execute");
217         exec($command);
218       } else {
219         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
220         print_red ($message);
221       }
222     }
223   }
226 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
227 ?>