59d9436e3c803b6cc4804defbd36072fa4b20a12
1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003-2007 - Fabian Hickert <hickert@gonicus.de>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
22 /* The sieve management class displays a list of sieve
23 * scripts for the given mail account.
24 * The account is identified by the parents uid attribute.
25 *
26 * $config The config object
27 * $dn The object edited
28 * $parent The parent object that provides the uid attribute
29 */
30 class sieveManagement extends plugin
31 {
32 var $parent = NULL;
33 var $scripts= array();
35 var $current_handler = NULL;
37 /* Initialize the class and load all sieve scripts
38 * try to parse them and display errors
39 */
40 function sieveManagement($config,$dn,$parent)
41 {
42 $this->parent = $parent;
43 plugin::plugin($config,$dn);
46 /* Connect to sieve class and try to get all available sieve scripts */
47 $cfg= $this->config->data['SERVERS']['IMAP'][$this->parent->gosaMailServer];
49 /* Log into the mail server */
50 $sieve= new sieve($cfg["sieve_server"], $cfg["sieve_port"], $this->parent->uid,
51 $cfg["password"], $cfg["admin"]);
53 /* Try to login */
54 if (!$sieve->sieve_login()){
55 print_red(sprintf(_("Can't log into SIEVE server. Server says '%s'."),
56 to_string($sieve->error_raw)));
57 return;
58 }
60 /* Get all sieve scripts names */
61 if($sieve->sieve_listscripts()){
62 if (is_array($sieve->response)){
63 foreach($sieve->response as $key => $name){
64 $this->scripts[$key]['NAME'] = $name;
65 }
66 }
67 }
69 /* Get script contents */
70 foreach($this->scripts as $key => $script){
71 $p = new My_Parser;
72 $sieve->sieve_getscript($script['NAME']);
74 $script = "";
75 foreach($sieve->response as $line){
76 $script.=$line;
77 }
79 $this->scripts[$key]['SCRIPT'] = $script;
80 $this->scripts[$key]['MSG'] = "";
81 $ret = $p->parse($script);
82 if(!$ret){
83 $this->scripts[$key]['MSG'] = "<font color='red'>".$p->status_text."</font>";
84 $this->scripts[$key]['STATUS'] = FALSE;
85 }else{
86 $this->scripts[$key]['STATUS'] = TRUE;
87 }
88 $this->scripts[$key]['PARSER'] = $p;
89 }
90 }
93 /* Handle sieve list
94 */
95 function execute()
96 {
97 $once = TRUE;
98 foreach($_POST as $name => $value){
99 if(preg_match("/^editscript_/",$name) && $once && !$this->current_handler){
100 $script = preg_replace("/^editscript_/","",$name);
101 $script = preg_replace("/_(x|y)/","",$script);
102 $once = FALSE;
104 $this->current_handler = $this->scripts[$script]['PARSER'];
105 }
106 }
108 if(isset($_GET['xx'])){
109 $this->current_handler = NULL;
110 }
112 if($this->current_handler){
113 return($this->current_handler->execute());
114 }
116 /* Create list of available sieve scripts
117 */
118 $List = new divSelectBox("sieveManagement");
119 foreach($this->scripts as $key => $script){
120 $field1 = array("string" => $script['NAME']);
121 if($script['STATUS']){
122 $field2 = array("string" => _("Parse successful"));
123 }else{
124 $field2 = array("string" => _("Parse failed") .$script['MSG']);
125 }
126 $field3 = array("string" => _("Script length")." : ".strlen($script['SCRIPT']));
127 $field4 = array("string" => "<input type='image' name='editscript_".$key."' src='images/edit.png'>");
128 $List ->AddEntry(array($field1,$field2,$field3,$field4));
129 }
131 return($List->DrawList());
132 }
134 function save_object()
135 {
136 if($this->current_handler){
137 $this->current_handler->save_object();
138 }
139 }
140 }
142 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
143 ?>