options.php 19 KB

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