Mofify a Server -> Modify a Server
[squirrelmail.git] / plugins / mail_fetch / options.php
1 <?php
2
3 /**
4 * mail_fetch/options.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Setup of the mailfetch plugin.
10 *
11 * $Id$
12 */
13
14 define('SM_PATH','../../');
15
16 require_once(SM_PATH . 'include/validate.php');
17 require_once(SM_PATH . 'functions/imap.php');
18 require_once(SM_PATH . 'include/load_prefs.php');
19
20 /* globals */
21 sqgetGlobalVar('username', $username, SQ_SESSION);
22 sqgetGlobalVar('key', $key, SQ_COOKIE);
23 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
24 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
25
26 if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST)) {
27 $mf_cypher = '';
28 }
29 if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST) ) {
30 if (sqgetGlobalVar('mf_action_mod', $mf_action_mod, SQ_POST)) {
31 $mf_action = 'Modify';
32 }
33 elseif (sqgetGlobalVar('mf_action_del', $mf_action_del, SQ_POST)) {
34 $mf_action = 'Delete';
35 }
36 else {
37 $mf_action = 'config';
38 }
39 }
40
41 sqgetGlobalVar('mf_sn', $mf_sn, SQ_POST);
42 sqgetGlobalVar('mf_server', $mf_server, SQ_POST);
43 sqgetGlobalVar('mf_port', $mf_port, SQ_POST);
44 sqgetGlobalVar('mf_alias', $mf_alias, SQ_POST);
45 sqgetGlobalVar('mf_user', $mf_user, SQ_POST);
46 sqgetGlobalVar('mf_pass', $mf_pass, SQ_POST);
47 sqgetGlobalVar('mf_subfolder', $mf_subfolder, SQ_POST);
48 sqgetGlobalVar('mf_login', $mf_login, SQ_POST);
49 sqgetGlobalVar('mf_fref', $mf_fref, SQ_POST);
50 sqgetGlobalVar('mf_lmos', $mf_lmos, SQ_POST);
51 sqgetGlobalVar('submit_mailfetch', $submit_mailfetch, SQ_POST);
52
53
54 /* end globals */
55
56 displayPageHeader( $color, 'None' );
57
58 switch( $mf_action ) {
59 case 'add':
60 if ($mf_sn<1) $mf_sn=0;
61 if (!isset($mf_server)) return;
62 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
63 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
64 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
65 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
66 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
67 if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on');
68 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
69 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
70 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
71 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
72 $mf_sn++;
73 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
74 $mf_action = 'config';
75 break;
76 case 'confirm_modify':
77 //modify a server
78 if (!isset($mf_server)) return;
79 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
80 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
81 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
82 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
83 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
84 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
85 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
86 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
87 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
88 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
89 $mf_action = 'config';
90 break;
91 case 'confirm_delete':
92 //delete a server
93 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
94 if ($mf_sn+1==$mailfetch_server_number) {
95 //is the last server, whe can only decrase $mailfetch_server_number
96 $mailfetch_server_number--;
97 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
98 } else {
99 //if not the last, all the sequel server come up one step
100 //then whe decrase $mailfetch_server_number
101 $mailfetch_server_number--;
102 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++) {
103 $tmp=$i+1;
104 setPref($data_dir,$username,'mailfetch_server_'.$i,
105 getPref($data_dir,$username, 'mailfetch_server_'.$tmp));
106 setPref($data_dir,$username,'mailfetch_port_'.$i,
107 getPref($data_dir,$username, 'mailfetch_port_'.$tmp));
108 setPref($data_dir,$username,'mailfetch_alias_'.$i,
109 getPref($data_dir,$username, 'mailfetch_alias_'.$tmp));
110 setPref($data_dir,$username,'mailfetch_user_'.$i,
111 getPref($data_dir,$username, 'mailfetch_user_'.$tmp));
112 setPref($data_dir,$username,'mailfetch_pass_'.$i,
113 getPref($data_dir,$username, 'mailfetch_pass_'.$tmp));
114 setPref($data_dir,$username,'mailfetch_lmos_'.$i,
115 getPref($data_dir,$username, 'mailfetch_lmos_'.$tmp));
116 setPref($data_dir,$username,'mailfetch_login_'.$i,
117 getPref($data_dir,$username, 'mailfetch_login_'.$tmp));
118 setPref($data_dir,$username,'mailfetch_fref_'.$i,
119 getPref($data_dir,$username, 'mailfetch_fref_'.$tmp));
120 setPref($data_dir,$username,'mailfetch_subfolder_'.$i,
121 getPref($data_dir,$username, 'mailfetch_subfolder_'.$tmp));
122 setPref($data_dir,$username,'mailfetch_uidl_'.$i,
123 getPref($data_dir,$username, 'mailfetch_uidl_'.$tmp));
124 }
125 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
126 }
127 $mf_action = 'config';
128 break;
129 }
130
131 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
132 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
133 if ($mailfetch_server_number<1) {
134 $mailfetch_server_number=0;
135 }
136 for ($i=0;$i<$mailfetch_server_number;$i++) {
137 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
138 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
139 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
140 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
141 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
142 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
143 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
144 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
145 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
146 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
147 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
148 }
149
150
151 echo '<br><form method="post" action="'.$PHP_SELF.'">' .
152 html_tag( 'table',
153 html_tag( 'tr',
154 html_tag( 'td',
155 '<b>' . _("Remote POP server settings") . '</b>',
156 'center', $color[0] )
157 ),
158 'center', '', 'width="95%"' ) .
159 html_tag( 'table',
160 html_tag( 'tr',
161 html_tag( 'td',
162 _("You should be aware that the encryption used to store your password is not perfectly secure. However, if you are using pop, there is inherently no encryption anyway. Additionally, the encryption that we do to save it on the server can be undone by a hacker reading the source to this file." ) ,
163 'left' )
164 ) .
165 html_tag( 'tr',
166 html_tag( 'td',
167 _("If you leave password empty, it will be required when you fetch mail.") ,
168 'left' )
169 ) .
170 html_tag( 'tr',
171 html_tag( 'td',
172 '<input type=checkbox name=mf_cypher ' .
173 (($mailfetch_cypher=='on')?'checked>':'>') .
174 _("Encrypt passwords (informative only)") ,
175 'right' )
176 ) ,
177 'center', '', 'width="95%"' );
178
179 switch( $mf_action ) {
180 case 'config':
181 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
182 html_tag( 'tr',
183 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
184 ) .
185 html_tag( 'tr' ) .
186 html_tag( 'td', '', 'center', $color[0] ) .
187
188 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
189 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
190 html_tag( 'table' ) .
191 html_tag( 'tr',
192 html_tag( 'th', _("Server:"), 'right' ) .
193 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
194 ) .
195 html_tag( 'tr',
196 html_tag( 'th', _("Port:"), 'right') .
197 html_tag( 'td', '<input type=text name=mf_port value="110" size=20>', 'left')
198 ) .
199 html_tag( 'tr',
200 html_tag( 'th', _("Alias:"), 'right' ) .
201 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
202 ) .
203 html_tag( 'tr',
204 html_tag( 'th', _("Username:"), 'right' ) .
205 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
206 ) .
207 html_tag( 'tr',
208 html_tag( 'th', _("Password:"), 'right' ) .
209 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
210 ) .
211 html_tag( 'tr' ) .
212 html_tag( 'th', _("Store in Folder:"), 'right' ) .
213 html_tag( 'td', '', 'left' );
214 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
215 $boxes = sqimap_mailbox_list($imapConnection);
216 echo '<select name="mf_subfolder">';
217
218 $selected = 0;
219 if ( isset($mf_subfolder) )
220 $selected = array(strtolower($mf_subfolder));
221 echo sqimap_mailbox_option_list($imapConnection, $selected);
222 echo '</select></td></tr>' .
223 html_tag( 'tr',
224 html_tag( 'th', '&nbsp;', 'right' ) .
225 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
226 ) .
227 html_tag( 'tr',
228 html_tag( 'th', '&nbsp;', 'right' ) .
229 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
230 ) .
231 html_tag( 'tr',
232 html_tag( 'th', '&nbsp;', 'right' ) .
233 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
234 ) .
235 html_tag( 'tr',
236 html_tag( 'td',
237 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
238 'center', '', 'colspan="2"' )
239 ) .
240 '</table></td></tr></table></form>';
241
242 // Modify Server
243 echo '<font size=-5><BR></font>' .
244 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
245 html_tag( 'tr',
246 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
247 ) .
248 html_tag( 'tr' ) .
249 html_tag( 'td', '', 'center', $color[0] );
250 if ($mailfetch_server_number>0) {
251 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
252 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
253 for ($i=0;$i<$mailfetch_server_number;$i++) {
254 echo "<option value=\"$i\">" .
255 htmlspecialchars( (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>";
256 }
257 echo '</select>'.
258 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action_mod value="' . _("Modify") . '">'.
259 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action_del value="' . _("Delete") . '">'.
260 '</form>';
261 } else {
262 echo _("No-one server in use. Try to add.");
263 }
264 echo '</td></tr></table>';
265 break;
266 case 'Delete': //erase confirmation about a server
267 echo html_tag( 'table',
268 html_tag( 'tr',
269 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
270 ) ,
271 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
272 '<br>' .
273 html_tag( 'table',
274 html_tag( 'tr',
275 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
276 ) .
277 html_tag( 'tr',
278 html_tag( 'td',
279 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
280 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
281 '<br>' . _("Selected Server:") . " <b>" . htmlentities($mailfetch_server_[$mf_sn]) . "</b><br>" .
282 _("Confirm delete of selected server?") . '<br><br>' .
283 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
284 '<br></form>' ,
285 'center', $color[9] )
286 ) ,
287 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' );
288 break; //modify a server
289 case 'Modify':
290 echo html_tag( 'table',
291 html_tag( 'tr',
292 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
293 ) ,
294 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
295 '<br>' .
296 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
297 html_tag( 'tr',
298 html_tag( 'td', '<b>' . _("Modify a Server") . '</b>', 'center', $color[9] )
299 ) .
300 html_tag( 'tr' ) .
301 html_tag( 'td', '', 'center', $color[0] ) .
302
303 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
304 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
305 html_tag( 'table' ) .
306 html_tag( 'tr',
307 html_tag( 'th', _("Server:"), 'right' ) .
308 html_tag( 'td', '<input type="text" name="mf_server" value="' . htmlentities($mailfetch_server_[$mf_sn]) . '" size="40">', 'left' )
309 ) .
310 html_tag( 'tr',
311 html_tag( 'th', _("Port:"), 'right' ) .
312 html_tag( 'td', '<input type="text" name="mf_port" value="' . $mailfetch_port_[$mf_sn] . '" size="40">', 'left' )
313 ) .
314 html_tag( 'tr',
315 html_tag( 'th', _("Alias:"), 'right' ) .
316 html_tag( 'td', '<input type="text" name="mf_alias" value="' . htmlentities($mailfetch_alias_[$mf_sn]) . '" size="40">', 'left' )
317 ) .
318 html_tag( 'tr',
319 html_tag( 'th', _("Username:"), 'right' ) .
320 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
321 ) .
322 html_tag( 'tr',
323 html_tag( 'th', _("Password:"), 'right' ) .
324 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
325 ) .
326 html_tag( 'tr' ) .
327 html_tag( 'th', _("Store in Folder:"), 'right' ) .
328 html_tag( 'td', '', 'left' );
329
330 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
331 $boxes = sqimap_mailbox_list($imapConnection);
332 echo '<select name="mf_subfolder">';
333 $selected = 0;
334 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
335 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
336 }
337 echo sqimap_mailbox_option_list($imapConnection, $selected) .
338 '</select></td></tr>' .
339
340 html_tag( 'tr',
341 html_tag( 'th', '&nbsp;', 'right' ) .
342 html_tag( 'td',
343 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
344 '>' . _("Leave Mail on Server") ,
345 'left' )
346 ) .
347 html_tag( 'tr',
348 html_tag( 'th', '&nbsp;', 'right' ) .
349 html_tag( 'td',
350 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
351 '>' . _("Check mail during login"),
352 'left' )
353 ) .
354 html_tag( 'tr',
355 html_tag( 'th', '&nbsp;', 'right' ) .
356 html_tag( 'td',
357 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
358 '>' . _("Check mail during folder refresh") ,
359 'left' )
360 ) .
361 html_tag( 'tr',
362 html_tag( 'td',
363 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
364 'center', '', 'colspan="2"' )
365 ) .
366
367 '</table></form></td></tr></table>';
368 break;
369 default: //unsupported action
370 echo '</form>' .
371 html_tag( 'table',
372 html_tag( 'tr',
373 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
374 ) ,
375 'center', '', 'width="95%"' ) .
376 '<br>' .
377 html_tag( 'table',
378 html_tag( 'tr',
379 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
380 html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
381 ) ,
382 'center', '', 'width="70%"' );
383 }
384
385 ?>
386 </body></html>