d622d38a |
1 | <?php |
4b4abf93 |
2 | |
8d6a115b |
3 | /** |
4 | * mail_fetch/options.php |
5 | * |
8d6a115b |
6 | * Setup of the mailfetch plugin. |
7 | * |
4b4abf93 |
8 | * @copyright © 1999-2005 The SquirrelMail Project Team |
9 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
4f51df66 |
10 | * @version $Id$ |
ea5f4b8e |
11 | * @package plugins |
12 | * @subpackage mail_fetch |
8d6a115b |
13 | */ |
d622d38a |
14 | |
ea5f4b8e |
15 | /** @ignore */ |
8d6a115b |
16 | define('SM_PATH','../../'); |
aa7fb30c |
17 | |
8d6a115b |
18 | require_once(SM_PATH . 'include/validate.php'); |
5c89bd63 |
19 | include_once(SM_PATH . 'functions/imap.php'); |
d622d38a |
20 | |
3c66c567 |
21 | /* globals */ |
22 | sqgetGlobalVar('username', $username, SQ_SESSION); |
23 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
24 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
25 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
91e0dccc |
26 | |
3c66c567 |
27 | if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST)) { |
28 | $mf_cypher = ''; |
29 | } |
30 | if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST) ) { |
a747d971 |
31 | if (sqgetGlobalVar('mf_action_mod', $mf_action_mod, SQ_POST)) { |
32 | $mf_action = 'Modify'; |
33 | } |
34 | elseif (sqgetGlobalVar('mf_action_del', $mf_action_del, SQ_POST)) { |
35 | $mf_action = 'Delete'; |
36 | } |
37 | else { |
38 | $mf_action = 'config'; |
39 | } |
3c66c567 |
40 | } |
86bb8549 |
41 | |
162cd2c6 |
42 | sqgetGlobalVar('mf_sn', $mf_sn, SQ_POST); |
3c66c567 |
43 | sqgetGlobalVar('mf_server', $mf_server, SQ_POST); |
44 | sqgetGlobalVar('mf_port', $mf_port, SQ_POST); |
45 | sqgetGlobalVar('mf_alias', $mf_alias, SQ_POST); |
46 | sqgetGlobalVar('mf_user', $mf_user, SQ_POST); |
47 | sqgetGlobalVar('mf_pass', $mf_pass, SQ_POST); |
48 | sqgetGlobalVar('mf_subfolder', $mf_subfolder, SQ_POST); |
49 | sqgetGlobalVar('mf_login', $mf_login, SQ_POST); |
50 | sqgetGlobalVar('mf_fref', $mf_fref, SQ_POST); |
51 | sqgetGlobalVar('mf_lmos', $mf_lmos, SQ_POST); |
52 | sqgetGlobalVar('submit_mailfetch', $submit_mailfetch, SQ_POST); |
d622d38a |
53 | |
a747d971 |
54 | |
3c66c567 |
55 | /* end globals */ |
56 | |
60683821 |
57 | displayPageHeader( $color, 'None' ); |
d622d38a |
58 | |
60683821 |
59 | switch( $mf_action ) { |
60 | case 'add': |
61 | if ($mf_sn<1) $mf_sn=0; |
62 | if (!isset($mf_server)) return; |
63 | setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:"")); |
64 | setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110)); |
65 | setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:"")); |
66 | setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:"")); |
67 | setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :"")); |
68 | if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on'); |
69 | setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:"")); |
70 | setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:"")); |
71 | setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:"")); |
72 | setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:"")); |
73 | $mf_sn++; |
74 | setPref($data_dir,$username,'mailfetch_server_number', $mf_sn); |
75 | $mf_action = 'config'; |
76 | break; |
77 | case 'confirm_modify': |
78 | //modify a server |
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( $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_action = 'config'; |
91 | break; |
92 | case 'confirm_delete': |
93 | //delete a server |
94 | $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number"); |
95 | if ($mf_sn+1==$mailfetch_server_number) { |
96 | //is the last server, whe can only decrase $mailfetch_server_number |
97 | $mailfetch_server_number--; |
98 | setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number); |
99 | } else { |
100 | //if not the last, all the sequel server come up one step |
101 | //then whe decrase $mailfetch_server_number |
102 | $mailfetch_server_number--; |
103 | for ($i=$mf_sn;$i<$mailfetch_server_number;$i++) { |
104 | $tmp=$i+1; |
105 | setPref($data_dir,$username,'mailfetch_server_'.$i, |
106 | getPref($data_dir,$username, 'mailfetch_server_'.$tmp)); |
107 | setPref($data_dir,$username,'mailfetch_port_'.$i, |
108 | getPref($data_dir,$username, 'mailfetch_port_'.$tmp)); |
109 | setPref($data_dir,$username,'mailfetch_alias_'.$i, |
110 | getPref($data_dir,$username, 'mailfetch_alias_'.$tmp)); |
111 | setPref($data_dir,$username,'mailfetch_user_'.$i, |
112 | getPref($data_dir,$username, 'mailfetch_user_'.$tmp)); |
113 | setPref($data_dir,$username,'mailfetch_pass_'.$i, |
114 | getPref($data_dir,$username, 'mailfetch_pass_'.$tmp)); |
115 | setPref($data_dir,$username,'mailfetch_lmos_'.$i, |
116 | getPref($data_dir,$username, 'mailfetch_lmos_'.$tmp)); |
117 | setPref($data_dir,$username,'mailfetch_login_'.$i, |
118 | getPref($data_dir,$username, 'mailfetch_login_'.$tmp)); |
119 | setPref($data_dir,$username,'mailfetch_fref_'.$i, |
120 | getPref($data_dir,$username, 'mailfetch_fref_'.$tmp)); |
121 | setPref($data_dir,$username,'mailfetch_subfolder_'.$i, |
122 | getPref($data_dir,$username, 'mailfetch_subfolder_'.$tmp)); |
123 | setPref($data_dir,$username,'mailfetch_uidl_'.$i, |
124 | getPref($data_dir,$username, 'mailfetch_uidl_'.$tmp)); |
125 | } |
126 | setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number); |
127 | } |
128 | $mf_action = 'config'; |
129 | break; |
130 | } |
4cf43843 |
131 | |
60683821 |
132 | $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0); |
133 | $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' ); |
134 | if ($mailfetch_server_number<1) { |
135 | $mailfetch_server_number=0; |
136 | } |
137 | for ($i=0;$i<$mailfetch_server_number;$i++) { |
138 | $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i"); |
139 | $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i"); |
140 | $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i"); |
141 | $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i"); |
142 | $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i"); |
143 | $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i"); |
144 | $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i"); |
145 | $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i"); |
146 | $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i"); |
147 | $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i"); |
148 | if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] ); |
149 | } |
ae8a7931 |
150 | |
60683821 |
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 asked 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="checked" />':' />') . |
174 | _("Encrypt passwords (informative only)") , |
175 | 'right' ) |
176 | ) , |
177 | 'center', '', 'width="95%"' ); |
d622d38a |
178 | |
60683821 |
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] ) . |
4cf43843 |
187 | |
60683821 |
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">'; |
4cf43843 |
217 | |
60683821 |
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', ' ', 'right' ) . |
225 | html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked="checked" />' . _("Leave Mail on Server"), 'left' ) |
226 | ) . |
227 | html_tag( 'tr', |
228 | html_tag( 'th', ' ', 'right' ) . |
229 | html_tag( 'td', '<input type="checkbox" name="mf_login" />' . _("Check mail at login"), 'left' ) |
230 | ) . |
231 | html_tag( 'tr', |
232 | html_tag( 'th', ' ', 'right' ) . |
233 | html_tag( 'td', '<input type="checkbox" name="mf_fref" />' . _("Check mail at 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>'; |
4cf43843 |
241 | |
60683821 |
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 | ' <input type="submit" name="mf_action_mod" value="' . _("Modify") . '" />'. |
259 | ' <input type="submit" name="mf_action_del" value="' . _("Delete") . '" />'. |
260 | '</form>'; |
261 | } else { |
262 | echo _("No servers known."); |
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>" . htmlspecialchars($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 Server") . '</b>', 'center', $color[9] ) |
299 | ) . |
300 | html_tag( 'tr' ) . |
301 | html_tag( 'td', '', 'center', $color[0] ) . |
4cf43843 |
302 | |
60683821 |
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="' . |
309 | htmlspecialchars($mailfetch_server_[$mf_sn]) . '" size="40" />', 'left' ) |
310 | ) . |
311 | html_tag( 'tr', |
312 | html_tag( 'th', _("Port:"), 'right' ) . |
313 | html_tag( 'td', '<input type="text" name="mf_port" value="' . |
314 | htmlspecialchars($mailfetch_port_[$mf_sn]) . '" size="40" />', 'left' ) |
315 | ) . |
316 | html_tag( 'tr', |
317 | html_tag( 'th', _("Alias:"), 'right' ) . |
318 | html_tag( 'td', '<input type="text" name="mf_alias" value="' . |
319 | htmlspecialchars($mailfetch_alias_[$mf_sn]) . '" size="40" />', 'left' ) |
320 | ) . |
321 | html_tag( 'tr', |
322 | html_tag( 'th', _("Username:"), 'right' ) . |
323 | html_tag( 'td', '<input type="text" name="mf_user" value="' . |
324 | htmlspecialchars($mailfetch_user_[$mf_sn]) . '" size="20" />', 'left' ) |
325 | ) . |
326 | html_tag( 'tr', |
327 | html_tag( 'th', _("Password:"), 'right' ) . |
328 | html_tag( 'td', '<input type="password" name="mf_pass" value="' . |
329 | htmlspecialchars($mailfetch_pass_[$mf_sn]) . '" size="20" />', 'left' ) |
330 | ) . |
331 | html_tag( 'tr' ) . |
332 | html_tag( 'th', _("Store in Folder:"), 'right' ) . |
333 | html_tag( 'td', '', 'left' ); |
dcc1cc82 |
334 | |
60683821 |
335 | $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0); |
336 | $boxes = sqimap_mailbox_list($imapConnection); |
337 | echo '<select name="mf_subfolder">'; |
338 | $selected = 0; |
339 | if ( isset($mailfetch_subfolder_[$mf_sn]) ) { |
340 | $selected = array(strtolower($mailfetch_subfolder_[$mf_sn])); |
341 | } |
342 | echo sqimap_mailbox_option_list($imapConnection, $selected) . |
343 | '</select></td></tr>' . |
344 | html_tag( 'tr', |
345 | html_tag( 'th', ' ', 'right' ) . |
346 | html_tag( 'td', |
347 | '<input type="checkbox" name="mf_lmos" ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked="checked"':'') . |
348 | ' />' . _("Leave Mail on Server") , |
349 | 'left' ) |
350 | ) . |
351 | html_tag( 'tr', |
352 | html_tag( 'th', ' ', 'right' ) . |
353 | html_tag( 'td', |
354 | '<input type="checkbox" name="mf_login" ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked="checked"':'') . |
355 | ' />' . _("Check mail at login"), |
356 | 'left' ) |
357 | ) . |
358 | html_tag( 'tr', |
359 | html_tag( 'th', ' ', 'right' ) . |
360 | html_tag( 'td', |
361 | '<input type="checkbox" name="mf_fref" ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked="checked"':'') . |
362 | ' />' . _("Check mail at folder refresh") , |
363 | 'left' ) |
364 | ) . |
365 | html_tag( 'tr', |
366 | html_tag( 'td', |
367 | '<input type="submit" name="submit_mailfetch" value="' . _("Modify Server") . '" />', |
368 | 'center', '', 'colspan="2"' ) |
369 | ) . |
370 | '</table></form></td></tr></table>'; |
371 | break; |
372 | default: //unsupported action |
373 | echo '</form>' . |
374 | html_tag( 'table', |
375 | html_tag( 'tr', |
376 | html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] ) |
377 | ) , |
378 | 'center', '', 'width="95%"' ) . |
379 | '<br />' . |
380 | html_tag( 'table', |
381 | html_tag( 'tr', |
382 | html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) . |
383 | html_tag( 'td', '<b>' . _("The function you requested is unknown.") . '</b>', 'center', $color[0] ) |
384 | ) , |
385 | 'center', '', 'width="70%"' ); |
386 | } |
5c89bd63 |
387 | ?> |
4f51df66 |
388 | </body></html> |