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