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