From: Tomas K. <to...@us...> - 2006-08-05 07:38:09
|
Update of /cvsroot/squirrelmail/squirrelmail/config In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv23964/config Modified Files: conf.pl config_default.php Log Message: moved smtp sitewide configuration to main configuration utility added quote_single subroutine, that is used to sanitize single quoted php strings removed obsolete command18() subroutine Index: conf.pl =================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/config/conf.pl,v retrieving revision 1.251 retrieving revision 1.252 diff -u -w -r1.251 -r1.252 --- conf.pl 2 Aug 2006 18:05:33 -0000 1.251 +++ conf.pl 5 Aug 2006 07:38:01 -0000 1.252 @@ -424,6 +424,8 @@ # since 1.5.2 $abook_file_line_length = 2048 if ( !$abook_file_line_length ); $config_location_base = '' if ( !$config_location_base ); +$smtp_sitewide_user = '' if ( !$smtp_sitewide_user ); +$smtp_sitewide_pass = '' if ( !$smtp_sitewide_pass ); if ( $ARGV[0] eq '--install-plugin' ) { print "Activating plugin " . $ARGV[1] . "\n"; @@ -525,7 +527,7 @@ print "4. SMTP Server : $WHT$smtpServerAddress$NRM\n"; print "5. SMTP Port : $WHT$smtpPort$NRM\n"; print "6. POP before SMTP : $WHT$pop_before_smtp$NRM\n"; - print "7. SMTP Authentication : $WHT$smtp_auth_mech$NRM\n"; + print "7. SMTP Authentication : $WHT$smtp_auth_mech" . display_smtp_sitewide_userpass() ."$NRM\n"; print "8. Secure SMTP (TLS) : $WHT" . display_use_tls($use_smtp_tls) . "$NRM\n"; print "9. Header encryption key : $WHT$encode_header_key$NRM\n"; print "\n"; @@ -1172,26 +1174,6 @@ return $new_smtpPort; } -# authenticated server -sub command18 { - return; - # This sub disabled by tassium - it has been replaced with smtp_auth_mech - print "Do you wish to use an authenticated SMTP server? Your server must\n"; - print "support this in order for SquirrelMail to work with it. We implemented\n"; - print "it according to RFC 2554.\n"; - - $YesNo = 'n'; - $YesNo = 'y' if ( lc($use_authenticated_smtp) eq 'true' ); - - print "Use authenticated SMTP server (y/n) [$WHT$YesNo$NRM]: $WHT"; - - $new_use_authenticated_smtp = <STDIN>; - $new_use_authenticated_smtp =~ tr/yn//cd; - return 'true' if ( $new_use_authenticated_smtp eq "y" ); - return 'false' if ( $new_use_authenticated_smtp eq "n" ); - return $use_authenticated_smtp; -} - # pop before SMTP sub command18a { print "Do you wish to use POP3 before SMTP? Your server must\n"; @@ -1441,18 +1423,99 @@ $inval=<STDIN>; chomp($inval); if ($inval =~ /^none\b/i) { + # remove sitewide smtp authentication information + $smtp_sitewide_user = ''; + $smtp_sitewide_pass = ''; # SMTP doesn't necessarily require logins return "none"; - } - if ( ($inval =~ /^cram-md5\b/i) || ($inval =~ /^digest-md5\b/i) || + } elsif ( ($inval =~ /^cram-md5\b/i) || ($inval =~ /^digest-md5\b/i) || ($inval =~ /^login\b/i) || ($inval =~/^plain\b/i)) { + command_smtp_sitewide_userpass($inval); return lc($inval); + } elsif (trim($inval) eq '') { + # user selected default value + command_smtp_sitewide_userpass($smtp_auth_mech); + return $smtp_auth_mech; } else { - # user entered garbage, or default value so nothing needs to be set + # user entered garbage return $smtp_auth_mech; } } +sub command_smtp_sitewide_userpass($) { + # get first function argument + my $auth_mech = shift(@_); + my $default, $tmp; + $auth_mech = lc(trim($auth_mech)); + if ($auth_mech ne 'cram-md5' && + $auth_mech ne 'digest-md5' && + $auth_mech ne 'login' && + $auth_mech ne 'plain') { + return; + } + print "SMTP authentication uses IMAP username and password by default.\n"; + print "\n"; + print "Would you like to use other login and password for all SquirrelMail \n"; + print "SMTP connections?"; + if ($smtp_sitewide_user ne '') { + $default = 'y'; + print " [Yn]:"; + } else { + $default = 'n'; + print " [yN]:"; + } + $tmp=<STDIN>; + $tmp = trim($tmp); + + if ($tmp eq '') { + $tmp = $default; + } else { + $tmp = lc($tmp); + } + + if ($tmp eq 'n') { + $smtp_sitewide_user = ''; + $smtp_sitewide_pass = ''; + } elsif ($tmp eq 'y') { + print "Enter username [$smtp_sitewide_user]:"; + my $new_user = <STDIN>; + $new_user = trim($new_user); + if ($new_user ne '') { + $smtp_sitewide_user = $new_user; + } + if ($smtp_sitewide_user ne '') { + print "If you don't enter any password, current sitewide password will be used.\n"; + print "If you enter space, password will be set to empty string.\n"; + print "Enter password:"; + my $new_pass = <STDIN>; + if ($new_pass ne "\n") { + $smtp_sitewide_pass = trim($new_pass); + } + } else { + print "Invalid input. You must set username used for SMTP authentication.\n"; + print "Click any key to continue\n"; + $tmp = <STDIN>; + } + } else { + print "Invalid input\n"; + print "Click any key to continue\n"; + $tmp = <STDIN>; + } +} + +# Sub adds information about SMTP authentication type to menu +sub display_smtp_sitewide_userpass() { + my $ret = ''; + if ($smtp_auth_mech ne 'none') { + if ($smtp_sitewide_user ne '') { + $ret = ' (with custom username and password)'; + } else { + $ret = ' (with IMAP username and password)'; + } + } + return $ret; +} + # TLS # This sub is reused for IMAP and SMTP # Args: service name, default value @@ -4176,6 +4239,8 @@ # string print CF "\$smtp_auth_mech = '$smtp_auth_mech';\n"; + print CF "\$smtp_sitewide_user = '". quote_single($smtp_sitewide_user) ."';\n"; + print CF "\$smtp_sitewide_pass = '". quote_single($smtp_sitewide_pass) ."';\n"; # string print CF "\$imap_auth_mech = '$imap_auth_mech';\n"; # boolean @@ -4628,3 +4693,10 @@ return 1; } } + +# quotes string written in single quotes +sub quote_single($) { + my $string = shift(@_); + $string =~ s/\'/\\'/g; + return $string; +} Index: config_default.php =================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/config/config_default.php,v retrieving revision 1.141 retrieving revision 1.142 diff -u -w -r1.141 -r1.142 --- config_default.php 2 Aug 2006 18:05:33 -0000 1.141 +++ config_default.php 5 Aug 2006 07:38:01 -0000 1.142 @@ -268,6 +268,28 @@ $smtp_auth_mech = 'none'; /** + * Custom SMTP authentication username + * + * IMAP username is used if variable is set to empty string. + * Variable is included in main configuration file only from 1.5.2 version. + * Older versions stored it in config_local.php. + * @global string $smtp_sitewide_user + * @since 1.5.0 + */ +$smtp_sitewide_user = ''; + +/** + * Custom SMTP authentication password + * + * IMAP password is used if $smtp_sitewide_user global is set to empty string. + * Variable is included in main configuration file only from 1.5.2 version. + * Older versions stored it in config_local.php. + * @global string $smtp_sitewide_pass + * @since 1.5.0 + */ +$smtp_sitewide_pass = ''; + +/** * IMAP authentication mechanism * * auth_mech can be either 'login','plain', 'cram-md5', or 'digest-md5' |