Source for file options.php

Documentation is available at options.php

  1. <?php
  2.  
  3. /**
  4.  * mail_fetch/options.php
  5.  *
  6.  * Setup of the mailfetch plugin.
  7.  *
  8.  * @copyright 1999-2018 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: options.php 14749 2018-01-16 23:36:07Z pdontthink $
  11.  * @package plugins
  12.  * @subpackage mail_fetch
  13.  */
  14.  
  15. define('SM_PATH','../../');
  16.  
  17. require_once(SM_PATH 'include/validate.php');
  18. require_once(SM_PATH 'functions/imap.php');
  19. require_once(SM_PATH 'include/load_prefs.php');
  20.  
  21. // don't load this page if this plugin is not enabled
  22. //
  23. global $plugins;
  24. if (!in_array('mail_fetch'$plugins)) exit;
  25.  
  26. /* globals */
  27. sqgetGlobalVar('username',   $username,   SQ_SESSION);
  28. sqgetGlobalVar('key',        $key,        SQ_COOKIE);
  29. sqgetGlobalVar('onetimepad'$onetimepadSQ_SESSION);
  30. sqgetGlobalVar('delimiter',  $delimiter,  SQ_SESSION);
  31. global $imap_stream_options// in case not defined in config
  32.     
  33. if(!sqgetGlobalVar('mf_cypher'$mf_cypherSQ_POST)) {
  34.     $mf_cypher '';
  35. }
  36. if(sqgetGlobalVar('mf_action'$mf_actionSQ_POST) ) {
  37.     if (sqgetGlobalVar('mf_action_mod'$mf_action_modSQ_POST)) {
  38.         $mf_action 'Modify';
  39.     }
  40.     elseif (sqgetGlobalVar('mf_action_del'$mf_action_delSQ_POST)) {
  41.         $mf_action 'Delete';
  42.     }
  43.     else {
  44.         $mf_action 'config';
  45.     }
  46. }
  47.  
  48. sqgetGlobalVar('mf_sn',            $mf_sn,            SQ_POST);
  49. sqgetGlobalVar('mf_server',        $mf_server,        SQ_POST);
  50. sqgetGlobalVar('mf_port',          $mf_port,          SQ_POST);
  51. sqgetGlobalVar('mf_alias',         $mf_alias,         SQ_POST);
  52. sqgetGlobalVar('mf_user',          $mf_user,          SQ_POST);
  53. sqgetGlobalVar('mf_pass',          $mf_pass,          SQ_POST);
  54. sqgetGlobalVar('mf_subfolder',     $mf_subfolder,     SQ_POST);
  55. sqgetGlobalVar('mf_login',         $mf_login,         SQ_POST);
  56. sqgetGlobalVar('mf_fref',          $mf_fref,          SQ_POST);
  57. sqgetGlobalVar('mf_lmos',          $mf_lmos,          SQ_POST);
  58. sqgetGlobalVar('submit_mailfetch'$submit_mailfetchSQ_POST);
  59. $mf_port trim($mf_port);
  60. $mf_server trim($mf_server);
  61.  
  62.  
  63. /* end globals */
  64.  
  65.     displayPageHeader$color'None' );
  66.  
  67.     switch$mf_action {
  68.     case 'add':
  69.  
  70.         $mf_action 'config';
  71.  
  72.         // restrict port number if necessary
  73.         //
  74.         $message validate_mail_fetch_port_number($mf_port);
  75.         if (!empty($message)) break;
  76.  
  77.         // restrict server address if necessary
  78.         //
  79.         $message validate_mail_fetch_server_address($mf_server);
  80.         if (!empty($message)) break;
  81.  
  82.         if ($mf_sn<1$mf_sn=0;
  83.         if (!isset($mf_server)) return;
  84.         setPref($data_dir,$username,"mailfetch_server_$mf_sn"(isset($mf_server)?$mf_server:""));
  85.         setPref($data_dir,$username,"mailfetch_port_$mf_sn"(isset($mf_port)?$mf_port:110));
  86.         setPref($data_dir,$username,"mailfetch_alias_$mf_sn"(isset($mf_alias)?$mf_alias:""));
  87.         setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
  88.         $pass "";
  89.         if isset($mf_pass) ) {
  90.             if isset($mf_cypher&& $mf_cypher == 'on' {
  91.                 setPref($data_dir,$username,"mailfetch_cypher"($mf_cypher == 'on' 'on' ''));
  92.                 $pass encrypt($mf_pass);
  93.             else {
  94.                 $pass $mf_pass;
  95.             }
  96.         }
  97.         setPref($data_dir,$username,"mailfetch_pass_$mf_sn",$pass);
  98.         setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
  99.         setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
  100.         setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
  101.         setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
  102.         $mf_sn++;
  103.         setPref($data_dir,$username,'mailfetch_server_number'$mf_sn);
  104.         break;
  105.  
  106.     // modify a server
  107.     //
  108.     case 'confirm_modify':
  109.  
  110.         // restrict port number if necessary
  111.         //
  112.         $message validate_mail_fetch_port_number($mf_port);
  113.         if (!empty($message)) {
  114.             $mf_action 'Modify';
  115.             break;
  116.         }
  117.  
  118.         // restrict server address if necessary
  119.         //
  120.         $message validate_mail_fetch_server_address($mf_server);
  121.         if (!empty($message)) {
  122.             $mf_action 'Modify';
  123.             break;
  124.         }
  125.  
  126.         if (!isset($mf_server)) return;
  127.         setPref($data_dir,$username,"mailfetch_server_$mf_sn"(isset($mf_server)?$mf_server:""));
  128.         setPref($data_dir,$username,"mailfetch_port_$mf_sn"(isset($mf_port)?$mf_port:110));
  129.         setPref($data_dir,$username,"mailfetch_alias_$mf_sn"(isset($mf_alias)?$mf_alias:""));
  130.         setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
  131.         $pass "";
  132.         if isset($mf_pass) ) {
  133.            if isset($mf_cypher&& $mf_cypher == 'on' {
  134.                setPref($data_dir,$username,"mailfetch_cypher"'on');
  135.                $pass encrypt($mf_pass);
  136.            else {
  137.                setPref($data_dir,$username,"mailfetch_cypher"'');
  138.                $pass $mf_pass;
  139.            }
  140.         }
  141.         setPref($data_dir,$username,"mailfetch_pass_$mf_sn",$pass);
  142.         setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
  143.         setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
  144.         setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
  145.         setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
  146.         $mf_action 'config';
  147.         break;
  148.     case 'confirm_delete':
  149.         //delete    a server
  150.         $mailfetch_server_number    getPref($data_dir$username"mailfetch_server_number");
  151.         if ($mf_sn+1==$mailfetch_server_number{
  152.             //is the last server, whe can only decrase $mailfetch_server_number
  153.             $mailfetch_server_number--;
  154.             setPref($data_dir,$username,"mailfetch_server_number"$mailfetch_server_number);
  155.         else {
  156.             //if not the last, all the sequel server come up one step
  157.             //then whe decrase $mailfetch_server_number
  158.             $mailfetch_server_number--;
  159.             for ($i=$mf_sn;$i<$mailfetch_server_number;$i++{
  160.                 $tmp=$i+1;
  161.                 setPref($data_dir,$username,'mailfetch_server_'.$i,
  162.                     getPref($data_dir,$username'mailfetch_server_'.$tmp));
  163.                 setPref($data_dir,$username,'mailfetch_port_'.$i,
  164.                     getPref($data_dir,$username'mailfetch_port_'.$tmp));
  165.                 setPref($data_dir,$username,'mailfetch_alias_'.$i,
  166.                     getPref($data_dir,$username'mailfetch_alias_'.$tmp));
  167.                 setPref($data_dir,$username,'mailfetch_user_'.$i,
  168.                     getPref($data_dir,$username'mailfetch_user_'.$tmp));
  169.                 setPref($data_dir,$username,'mailfetch_pass_'.$i,
  170.                     getPref($data_dir,$username'mailfetch_pass_'.$tmp));
  171.                 setPref($data_dir,$username,'mailfetch_lmos_'.$i,
  172.                     getPref($data_dir,$username'mailfetch_lmos_'.$tmp));
  173.                 setPref($data_dir,$username,'mailfetch_login_'.$i,
  174.                     getPref($data_dir,$username'mailfetch_login_'.$tmp));
  175.                 setPref($data_dir,$username,'mailfetch_fref_'.$i,
  176.                     getPref($data_dir,$username'mailfetch_fref_'.$tmp));
  177.                 setPref($data_dir,$username,'mailfetch_subfolder_'.$i,
  178.                     getPref($data_dir,$username'mailfetch_subfolder_'.$tmp));
  179.         setPref($data_dir,$username,'mailfetch_uidl_'.$i,
  180.                     getPref($data_dir,$username'mailfetch_uidl_'.$tmp));
  181.             }
  182.             setPref($data_dir,$username,"mailfetch_server_number"$mailfetch_server_number);
  183.         }
  184.         $mf_action 'config';
  185.         break;
  186.     }
  187.  
  188.     $mailfetch_server_number getPref($data_dir$username'mailfetch_server_number'0);
  189.     $mailfetch_cypher getPref$data_dir$username'mailfetch_cypher' );
  190.     if ($mailfetch_server_number<1{
  191.         $mailfetch_server_number=0;
  192.     }
  193.     for ($i=0;$i<$mailfetch_server_number;$i++{
  194.         $mailfetch_server_[$igetPref($data_dir$username"mailfetch_server_$i");
  195.         $mailfetch_port_[$igetPref($data_dir$username"mailfetch_port_$i");
  196.         $mailfetch_alias_[$igetPref($data_dir$username"mailfetch_alias_$i");
  197.         $mailfetch_user_[$igetPref($data_dir$username"mailfetch_user_$i");
  198.         $mailfetch_pass_[$igetPref($data_dir$username"mailfetch_pass_$i");
  199.         $mailfetch_lmos_[$igetPref($data_dir$username"mailfetch_lmos_$i");
  200.         $mailfetch_login_[$igetPref($data_dir$username"mailfetch_login_$i");
  201.         $mailfetch_fref_[$igetPref($data_dir$username"mailfetch_fref_$i");
  202.         $mailfetch_uidl_[$igetPref($data_dir$username"mailfetch_uidl_$i");
  203.         $mailfetch_subfolder_[$igetPref($data_dir$username"mailfetch_subfolder_$i");
  204.         if$mailfetch_cypher == 'on' $mailfetch_pass_[$idecrypt$mailfetch_pass_[$i);
  205.     }
  206.  
  207.  
  208.     echo '<br><form method="post" action="'.$PHP_SELF.'">' .
  209.             html_tag'table',
  210.                 html_tag'tr',
  211.                     html_tag'td',
  212.                         '<b>' _("Remote POP server settings"'</b>',
  213.                     'center'$color[0)
  214.                 ),
  215.             'center''''width="95%"' .
  216.             html_tag'table',
  217.                 html_tag'tr',
  218.                     html_tag'td',
  219.                         _("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." ,
  220.                     'left' )
  221.                 .
  222.                 html_tag'tr',
  223.                     html_tag'td',
  224.                         _("If you leave password empty, it will be asked when you fetch mail.",
  225.                     'left' )
  226.                 .
  227.                 html_tag'tr',
  228.                     html_tag'td',
  229.                         '<input type=checkbox name=mf_cypher ' .
  230.                         (($mailfetch_cypher=='on')?'checked>':'>'.
  231.                         _("Encrypt passwords (informative only)",
  232.                     'right' )
  233.                 ,
  234.             'center''''width="95%"' );
  235.  
  236.     // display error or other messages if necessary
  237.     //
  238.     if (!empty($message)) {
  239.         echo html_tag'table''''center''''width="70%" cellpadding="5" cellspacing="1"' .
  240.              html_tag'tr',
  241.              html_tag'td''<b>' $message '</b>''center'$color[2));
  242.     }
  243.  
  244.     switch$mf_action {
  245.     case 'config':
  246.         echo html_tag'table''''center''''width="70%" cellpadding="5" cellspacing="1"' .
  247.                     html_tag'tr',
  248.                         html_tag'td''<b>' _("Add Server"'</b>''center'$color[9)
  249.                     .
  250.                     html_tag'tr' .
  251.                         html_tag'td''''center'$color[0.
  252.  
  253.             "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">.
  254.             '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
  255.             html_tag'table' .
  256.                 html_tag'tr',
  257.                     html_tag'th'_("Server:")'right' .
  258.                     html_tag'td''<input type=text name=mf_server value="" size=40>''left' )
  259.                 .
  260.                 html_tag'tr',
  261.                     html_tag'th'_("Port:")'right'.
  262.                     html_tag'td''<input type=text name=mf_port value="110" size=20>''left')
  263.                 .
  264.                 html_tag'tr',
  265.                     html_tag'th'_("Alias:")'right' .
  266.                     html_tag'td''<input type=text name=mf_alias value="" size=20>''left' )
  267.                 .
  268.                 html_tag'tr',
  269.                     html_tag'th'_("Username:")'right' .
  270.                     html_tag'td''<input type=text name=mf_user value="" size=20>''left' )
  271.                 .
  272.                 html_tag'tr',
  273.                     html_tag'th'_("Password:")'right' .
  274.                     html_tag'td''<input type=password name=mf_pass value="" size=20>''left' )
  275.                 .
  276.                 html_tag'tr' .
  277.                     html_tag'th'_("Store in Folder:")'right' .
  278.                     html_tag'td''''left' );
  279.         $imapConnection sqimap_login ($username$key$imapServerAddress$imapPort0$imap_stream_options);
  280.         $boxes sqimap_mailbox_list($imapConnection);
  281.         echo '<select name="mf_subfolder">';
  282.  
  283.         $selected 0;
  284.         if isset($mf_subfolder) )
  285.           $selected array(strtolower($mf_subfolder));
  286.         echo sqimap_mailbox_option_list($imapConnection$selected);
  287.         echo '</select></td></tr>' .
  288.                 html_tag'tr',
  289.                     html_tag'th''&nbsp;''right' .
  290.                     html_tag'td''<input type="checkbox" name="mf_lmos" checked>' _("Leave mail on server")'left' )
  291.                 .
  292.                 html_tag'tr',
  293.                     html_tag'th''&nbsp;''right' .
  294.                     html_tag'td''<input type="checkbox" name="mf_login">' _("Check mail at login")'left' )
  295.                 .
  296.                 html_tag'tr',
  297.                     html_tag'th''&nbsp;''right' .
  298.                     html_tag'td''<input type="checkbox" name="mf_fref">' _("Check mail at folder refresh")'left' )
  299.                 .
  300.                 html_tag'tr',
  301.                     html_tag'td',
  302.                         '<input type=submit name="submit_mailfetch" value="' _("Add Server"'">',
  303.                     'center''''colspan="2"' )
  304.                 .
  305.             '</table></td></tr></table></form>';
  306.  
  307.         // Modify Server
  308.         echo '<font size=-5><BR></font>' .
  309.             html_tag'table''''center''''width="70%" cellpadding="5" cellspacing="1"' .
  310.                 html_tag'tr',
  311.                     html_tag'td''<b>' _("Modify Server"'</b>''center'$color[9)
  312.                 .
  313.                 html_tag'tr' .
  314.                     html_tag'td''''center'$color[0);
  315.         if ($mailfetch_server_number>0{
  316.             echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
  317.             echo '<b>' _("Server Name:"'</b> <select name="mf_sn">';
  318.             for ($i=0;$i<$mailfetch_server_number;$i++{
  319.                 echo "<option value=\"$i\">.
  320.                     sm_encode_html_special_chars( (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) "</option>";
  321.             }
  322.             echo '</select>'.
  323.                  '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action_mod value="' _("Modify"'">'.
  324.                  '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action_del value="' _("Delete"'">'.
  325.                  '</form>';
  326.         else {
  327.             echo _("No servers known.");
  328.         }
  329.         echo '</td></tr></table>';
  330.         break;
  331.     case 'Delete':                                     //erase confirmation about a server
  332.         echo html_tag'table',
  333.                     html_tag'tr',
  334.                         html_tag'td''<b>' _("Fetching Servers"'</b>''center'$color[0)
  335.                     ,
  336.                 'center''''width="95%" cellpadding="5" cellspacing="1"' .
  337.             '<br>' .
  338.             html_tag'table',
  339.                 html_tag'tr',
  340.                     html_tag'td''<b>' _("Confirm Deletion of a Server"'</b>''center'$color[9)
  341.                 .
  342.                 html_tag'tr',
  343.                     html_tag'td',
  344.                         "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">.
  345.                         '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
  346.                         '<br>' _("Selected Server:"" <b>" sm_encode_html_special_chars($mailfetch_server_[$mf_sn]"</b><br>" .
  347.                         _("Confirm delete of selected server?"'<br><br>' .
  348.                         '<input type=submit name=submit_mailfetch value="' _("Confirm Delete"'">' .
  349.                         '<br></form>' ,
  350.                     'center'$color[9)
  351.                 ,
  352.             'center''''width="70%" cellpadding="5" cellspacing="1"' );
  353.         break;                                  //modify a server
  354.     case 'Modify':
  355.         echo html_tag'table',
  356.                     html_tag'tr',
  357.                         html_tag'td''<b>' _("Fetching Servers"'</b>''center'$color[0)
  358.                     ,
  359.                 'center''''width="95%" cellpadding="5" cellspacing="1"' .
  360.             '<br>' .
  361.             html_tag'table''''center''''width="70%" cellpadding="5" cellspacing="1"' .
  362.                 html_tag'tr',
  363.                     html_tag'td''<b>' _("Modify Server"'</b>''center'$color[9)
  364.                 .
  365.                 html_tag'tr' .
  366.                     html_tag'td''''center'$color[0.
  367.  
  368.             "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">.
  369.             '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
  370.             html_tag'table' .
  371.                 html_tag'tr',
  372.                     html_tag'th'_("Server:")'right' .
  373.                     html_tag'td''<input type="text" name="mf_server" value="' sm_encode_html_special_chars($mailfetch_server_[$mf_sn]'" size="40">''left' )
  374.                 .
  375.                 html_tag'tr',
  376.                     html_tag'th'_("Port:")'right' .
  377.                     html_tag'td''<input type="text" name="mf_port" value="' sm_encode_html_special_chars($mailfetch_port_[$mf_sn]'" size="40">''left' )
  378.                 .
  379.                 html_tag'tr',
  380.                     html_tag'th'_("Alias:")'right' .
  381.                     html_tag'td''<input type="text" name="mf_alias" value="' sm_encode_html_special_chars($mailfetch_alias_[$mf_sn]'" size="40">''left' )
  382.                 .
  383.                 html_tag'tr',
  384.                     html_tag'th'_("Username:")'right' .
  385.                     html_tag'td''<input type="text" name="mf_user" value="' sm_encode_html_special_chars($mailfetch_user_[$mf_sn]'" size="20">''left' )
  386.                 .
  387.                 html_tag'tr',
  388.                     html_tag'th'_("Password:")'right' .
  389.                     html_tag'td''<input type="password" name="mf_pass" value="' sm_encode_html_special_chars($mailfetch_pass_[$mf_sn]'" size="20">''left' )
  390.                 .
  391.                 html_tag'tr' .
  392.                     html_tag'th'_("Store in Folder:")'right' .
  393.                     html_tag'td''''left' );
  394.  
  395.         $imapConnection sqimap_login ($username$key$imapServerAddress$imapPort0$imap_stream_options);
  396.         $boxes sqimap_mailbox_list($imapConnection);
  397.         echo '<select name="mf_subfolder">';
  398.         $selected 0;
  399.         if isset($mailfetch_subfolder_[$mf_sn]) ) {
  400.             $selected array(strtolower($mailfetch_subfolder_[$mf_sn]));
  401.     
  402.         echo sqimap_mailbox_option_list($imapConnection$selected.
  403.              '</select></td></tr>' .
  404.  
  405.                 html_tag'tr',
  406.                     html_tag'th''&nbsp;''right' .
  407.                     html_tag'td',
  408.                         '<input type=checkbox name=mf_lmos ' (($mailfetch_lmos_[$mf_sn== 'on')?'checked':''.
  409.                         '>' _("Leave Mail on Server",
  410.                     'left' )
  411.                 .
  412.                 html_tag'tr',
  413.                     html_tag'th''&nbsp;''right' .
  414.                     html_tag'td',
  415.                         '<input type=checkbox name=mf_login ' ( ($mailfetch_login_[$mf_sn== 'on')?'checked':''.
  416.                         '>' _("Check mail at login"),
  417.                     'left' )
  418.                 .
  419.                 html_tag'tr',
  420.                     html_tag'th''&nbsp;''right' .
  421.                     html_tag'td',
  422.                         '<input type=checkbox name=mf_fref ' ( ($mailfetch_fref_[$mf_sn== 'on')?'checked':''.
  423.                         '>' _("Check mail at folder refresh",
  424.                     'left' )
  425.                 .
  426.                 html_tag'tr',
  427.                     html_tag'td',
  428.                         '<input type=submit name="submit_mailfetch" value="' _("Modify Server"'">',
  429.                     'center''''colspan="2"' )
  430.                 .
  431.  
  432.             '</table></form></td></tr></table>';
  433.         break;
  434.     default:                                    //unsupported action
  435.         echo '</form>' .
  436.         html_tag'table',
  437.             html_tag'tr',
  438.                 html_tag'td''<b>' _("Fetching Servers"'</b>''center'$color[0)
  439.             ,
  440.         'center''''width="95%"' .
  441.         '<br>' .
  442.         html_tag'table',
  443.             html_tag'tr',
  444.                 html_tag'td''<b>' _("Undefined Function"'</b>''center'$color[9.
  445.                 html_tag'td''<b>' .  _("The function you requested is unknown."'</b>''center'$color[0)
  446.             ,
  447.         'center''''width="70%"' );
  448.     }
  449.  
  450.     ?>
  451. </body></html>

Documentation generated on Tue, 17 Apr 2018 04:26:37 +0200 by phpDocumentor 1.4.3