From 14fc4fbdf59efc5626b5508780ebe3477cc9366a Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Wed, 3 Oct 2012 19:08:47 +0200 Subject: Make the configuration map a dynamic variable. --- www/common.pl | 11 +++++++---- www/logged_in_p.pl | 5 ++--- www/login.pl | 15 +++++++-------- www/sign.pl | 6 +++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/www/common.pl b/www/common.pl index 7590fba..aa86e47 100644 --- a/www/common.pl +++ b/www/common.pl @@ -7,15 +7,18 @@ use Modern::Perl; use Mail::ExpandAliases; +sub load_config() { + $::MULKONF = { }; + do "config.pl"; +} -sub email_users($$) { - ($config, $email) = @_; +sub email_users($) { + my ($email) = @_; my $alias; if ($email =~ /^(.*?)@/) { $alias = $1; } - my $aliases_file = $config->{aliases}; + my $aliases_file = $::MULKONF->{aliases}; if (not ($aliases_file eq ".")) { my $aliases = Mail::ExpandAliases->new($aliases_file); - my $session_user = $session->param('user'); my $email_users = $aliases->expand($alias) or die "User not found"; return @$email_users; } else { diff --git a/www/logged_in_p.pl b/www/logged_in_p.pl index 61b06c5..cbbb936 100755 --- a/www/logged_in_p.pl +++ b/www/logged_in_p.pl @@ -17,8 +17,7 @@ do "common.pl"; while (my $cgi = new CGI::Fast) { - local $::MULKONF = { }; - do "config.pl"; + load_config(); print $cgi->header(-content_type => 'application/json; charset=UTF-8'); @@ -36,7 +35,7 @@ while (my $cgi = new CGI::Fast) { my $email = $cgi->param('email') or die "No email address supplied"; my $session_user = $session->param('user'); - if ($session_user ~~ email_users($::MULKONF, $email)) { + if ($session_user ~~ email_users($email)) { say encode_json({logged_in_p => 1}); } else { say encode_json({logged_in_p => 0}); diff --git a/www/login.pl b/www/login.pl index 9f6831d..9e0467e 100755 --- a/www/login.pl +++ b/www/login.pl @@ -16,14 +16,14 @@ use Mail::IMAPTalk ; do "common.pl"; -sub check_password($$$) { - my ($config, $user, $password) = @_; +sub check_password($$) { + my ($user, $password) = @_; #my $socket = IO::Socket::SSL->new('imap.googlemail.com:imaps'); my $imap = Mail::IMAPTalk->new( # Socket => $socket, - Server => $config->{imap_server}, - Port => $config->{imap_port}, + Server => $::MULKONF->{imap_server}, + Port => $::MULKONF->{imap_port}, Username => $user, Password => $password, Uid => 1 @@ -38,8 +38,7 @@ sub check_password($$$) { while (my $cgi = new CGI::Fast) { - local $::MULKONF = { }; - do "config.pl"; + load_config(); my $cookie = $cgi->cookie('mulkid_session'); my $session; @@ -62,9 +61,9 @@ while (my $cgi = new CGI::Fast) { my $email = $cgi->param('email') or die "No email address provided"; my $password = $cgi->param('password') or die "Empty password"; - for my $user (email_users($::MULKONF, $email)) { + for my $user (email_users($email)) { #say STDERR "Trying user: $user"; - if (check_password($::MULKONF, $user, $password)) { + if (check_password($user, $password)) { $session->param('user', $user); say encode_json({user => $user}); exit 0; diff --git a/www/sign.pl b/www/sign.pl index d936303..53d7015 100755 --- a/www/sign.pl +++ b/www/sign.pl @@ -66,8 +66,8 @@ sub sign($$$$$) { while (my $cgi = new CGI::Fast) { - local $::MULKONF = { }; - do "config.pl"; + $::MULKONF = {}; # to silence a warning + load_config(); my $cookie = $cgi->cookie('mulkid_session') or die "No session cookie"; my $session = new CGI::Session("driver:File", $cookie, {Directory=>"/tmp"}) or die "Invalid session cookie"; @@ -86,7 +86,7 @@ while (my $cgi = new CGI::Fast) { if ($email =~ /^(.*?)@(.*)/) { $domain = $2; } die "User is not authorized to use this email address" - unless ($session_user ~~ email_users($::MULKONF, $email)); + unless ($session_user ~~ email_users($email)); my $sig = sign $key, decode_json($user_pubkey), $email, $duration, $domain; say encode_json({signature => $sig}); -- cgit v1.2.3