From 53bb0cb56f580b7115b874fe40d9011efe6dd8ed Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 14:57:50 +0100 Subject: Fix encoding of welcome message --- INSTALL | 2 +- fripost-adduser | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/INSTALL b/INSTALL index 95a169a..74be19a 100644 --- a/INSTALL +++ b/INSTALL @@ -4,4 +4,4 @@ If you use Debian GNU/Linux, you can install them like so: aptitude install -R libdatetime-format-mysql-perl libdatetime-perl \ libdbix-class-perl libemail-valid-perl libfile-slurp-perl libio-prompt-perl \ -libmime-lite-perl libstring-mkpasswd-perl libyaml-syck-perl +libmime-base64-perl libmime-lite-perl libstring-mkpasswd-perl libyaml-syck-perl diff --git a/fripost-adduser b/fripost-adduser index 73ff70b..192a691 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -16,13 +16,16 @@ use FindBin qw($Bin); use lib "$Bin/lib"; use Data::Dumper; +use Encode qw(encode); use File::Slurp qw(slurp); use Fripost::Password; use Fripost::Prompt; use Fripost::Schema; -use IO::Prompt; use Getopt::Long; +use IO::Prompt; +use MIME::Base64; use MIME::Lite; +use MIME::QuotedPrint; use YAML::Syck; # Prompt for user info @@ -86,14 +89,20 @@ say "New account $user->{username} added."; ## Send email my $msg = MIME::Lite->new( From => 'admin@fripost.org', - To => $user->{username}, - Subject => 'Välkommen till Fripost!', + To => 'test@example.com', + Subject => "=?UTF-8?B?" . + encode_base64(encode("utf8", 'Välkommen till Fripost!'), "") . "?=", Data => scalar slurp('templ/new_user_mail.tt'), # TODO: actually use TT + Encoding => 'quoted-printable', ); + +$msg->attr('content-type.charset' => 'utf-8'); $msg->send(); say "Sent welcome message: "; say $msg->as_string; +#say decode_qp($msg->as_string); + =head1 AUTHOR -- cgit v1.2.3 From 02fd9f27bb2f580c88a28d963ce27dcff210bf73 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 15:06:23 +0100 Subject: WIP: send login information to address when adding user --- fripost-adduser | 5 +++- lib/Fripost/Prompt.pm | 63 ++++++++++++++++++++++++++++----------------------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/fripost-adduser b/fripost-adduser index 192a691..0fd534c 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -30,7 +30,7 @@ use YAML::Syck; # Prompt for user info sub read_user_info { - my $username = prompt_username("New username: "); + my $username = prompt_email("New username: ", 'is_user'); my $name = prompt "Full (real) name: "; my $domain = (split /\@/, $username)[1]; my $maildir = "$domain/". (split /\@/, $username)[0] . "/Maildir/"; # trailing slash important @@ -103,6 +103,9 @@ say "Sent welcome message: "; say $msg->as_string; #say decode_qp($msg->as_string); +ask_if_ok_or_abort("Send email with login information? "); + +prompt_email("Where should the email be sent? "); =head1 AUTHOR diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index 514a0b7..4b11a19 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -20,6 +20,16 @@ use String::MkPasswd qw/mkpasswd/; our @EXPORT = qw(prompt_password prompt_username); +sub ask_if_ok_or_abort { + my ($msg) = @_; + $msg //= "Is this OK? [no will abort] "; + my $confirmed = prompt $msg, -ynt; + unless ($confirmed) { + say "User aborted"; + exit 1; + } +} + sub fix_username { my ($nam) = @_; if ($nam !~ /\@/) { @@ -29,15 +39,35 @@ sub fix_username { return $nam; } +sub prompt_email { + my ($msg, $is_username) = @_; + $msg //= "Enter email: "; + my $email; + while (not defined $email) { + $email = prompt $msg; + + if ($is_username) { + $email = fix_username($email) + } + + if (!Email::Valid->address($email)) { + undef $email; + say "This is not a valid e-mail address. Try again." + } + } + return $email; + +} + sub prompt_password { - my ($prompt, $prompt2) = @_; - $prompt //= "Enter new password (blank for random): "; - $prompt2 //= "Enter new password again (blank for random): "; + my ($msg, $msg2) = @_; + $msg //= "Enter new password (blank for random): "; + $msg2 //= "Enter new password again (blank for random): "; my $password; while (not defined $password) { - $password = prompt $prompt, -e => '*'; - my $confirm = prompt $prompt2, -e => '*'; + $password = prompt $msg, -e => '*'; + my $confirm = prompt $msg2, -e => '*'; unless ($password eq $confirm) { undef $password; say "Passwords do not match"; @@ -55,29 +85,6 @@ sub prompt_password { return smd5($password); } -sub prompt_username { - my $prompt = shift; - $prompt //= "Enter username: "; - my $nam; - while (not defined $nam) { - $nam = prompt $prompt; - $nam = fix_username($nam); - if (!Email::Valid->address($nam)) { - undef $nam; - say "This is not a valid e-mail address. Try again." - } - } - return $nam; -} - -sub ask_if_ok_or_abort { - my $confirmed = prompt "Is this OK? [no will abort]", -ynt; - unless ($confirmed) { - say "User aborted"; - exit 1; - } -} - =head1 AUTHOR Stefan Kangas C<< >> -- cgit v1.2.3 From 65590a4ed002ebcecdec5fb5286895e9ecbc6209 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 15:11:29 +0100 Subject: Simplify adduser script --- fripost-adduser | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/fripost-adduser b/fripost-adduser index 0fd534c..89a4031 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -28,29 +28,6 @@ use MIME::Lite; use MIME::QuotedPrint; use YAML::Syck; -# Prompt for user info -sub read_user_info { - my $username = prompt_email("New username: ", 'is_user'); - my $name = prompt "Full (real) name: "; - my $domain = (split /\@/, $username)[1]; - my $maildir = "$domain/". (split /\@/, $username)[0] . "/Maildir/"; # trailing slash important - my $active = 1; - my $password = prompt_password(); - - # Show the information that will be inserted - my $user = { - username => $username, - name => $name, - domain => $domain, - maildir => $maildir, - active => $active, - password => $password, - }; - print Dumper $user; - - return $user; -} - ## Get command line options our $conf = LoadFile('default.yml'); @@ -67,20 +44,32 @@ my $schema = Fripost::Schema->connect( ); say "Adding a new virtual user."; +{ + my $user = { + username => prompt_email("New username: ", 'is_user'), + name => prompt "Full (real) name: ", + domain => (split /\@/, $username)[1], + maildir => "$domain/". (split /\@/, $username)[0] . "/Maildir/", # trailing slash important + active => 1, + password => prompt_password(), + }; -my $user = read_user_info(); - -ask_if_ok_or_abort(); + say "Username: $user->{username}"; + say "Name: $user->{name}"; + say "Password: (hidden)"; -if ($conf->{pretend}) { - say "Nothing to do since we are pretending..."; - exit 0; + ask_if_ok_or_abort(); } die "User already exists" if ($schema->resultset('Mailbox')->search({ username => $user->{username} })->count); +if ($conf->{pretend}) { + say "Nothing to do since we are pretending..."; + exit 0; +} + ## Insert user into database my $db_user = $schema->resultset('Mailbox')->new($user); $db_user->insert; -- cgit v1.2.3 From 6238a0b2d98b59a99c5eab89b15d5686ba6858f3 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 15:14:06 +0100 Subject: Fix bug --- fripost-adduser | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fripost-adduser b/fripost-adduser index 89a4031..5153a18 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -44,8 +44,9 @@ my $schema = Fripost::Schema->connect( ); say "Adding a new virtual user."; +my $user; { - my $user = { + $user = { username => prompt_email("New username: ", 'is_user'), name => prompt "Full (real) name: ", domain => (split /\@/, $username)[1], @@ -78,7 +79,7 @@ say "New account $user->{username} added."; ## Send email my $msg = MIME::Lite->new( From => 'admin@fripost.org', - To => 'test@example.com', + To => $user->{username}, Subject => "=?UTF-8?B?" . encode_base64(encode("utf8", 'Välkommen till Fripost!'), "") . "?=", Data => scalar slurp('templ/new_user_mail.tt'), # TODO: actually use TT -- cgit v1.2.3 From 5d3d384a5bf1e08951ed37ec5111314c1cce82dc Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 15:17:13 +0100 Subject: Better name: confirm_or_abort --- fripost-adduser | 4 ++-- fripost-newalias | 2 +- lib/Fripost/Prompt.pm | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fripost-adduser b/fripost-adduser index 5153a18..c8bfc84 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -59,7 +59,7 @@ my $user; say "Name: $user->{name}"; say "Password: (hidden)"; - ask_if_ok_or_abort(); + confirm_or_abort(); } die "User already exists" @@ -93,7 +93,7 @@ say "Sent welcome message: "; say $msg->as_string; #say decode_qp($msg->as_string); -ask_if_ok_or_abort("Send email with login information? "); +confirm_or_abort("Send email with login information? "); prompt_email("Where should the email be sent? "); diff --git a/fripost-newalias b/fripost-newalias index 162f787..cf7f563 100755 --- a/fripost-newalias +++ b/fripost-newalias @@ -71,7 +71,7 @@ if (@addr == 0) { exit 1; } say "dest adress: " . (join " ", @addr); -ask_if_ok_or_abort(); +confirm_or_abort(); ## Insert alias into database for my $addr (@addr) { diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index 4b11a19..ac40411 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -20,7 +20,7 @@ use String::MkPasswd qw/mkpasswd/; our @EXPORT = qw(prompt_password prompt_username); -sub ask_if_ok_or_abort { +sub confirm_or_abort { my ($msg) = @_; $msg //= "Is this OK? [no will abort] "; my $confirmed = prompt $msg, -ynt; -- cgit v1.2.3 From 2b7ec90b448c01266f6b5b5bf7ce87d66df7733d Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 16:30:13 +0100 Subject: Improve output --- lib/Fripost/Prompt.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index ac40411..a7e517c 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -34,7 +34,7 @@ sub fix_username { my ($nam) = @_; if ($nam !~ /\@/) { $nam .= '@fripost.org'; - say "Using $nam"; + say "Using username: $nam"; } return $nam; } @@ -80,7 +80,7 @@ sub prompt_password { -minnum => 2, -minspecial => 2, ); - say "Generated password: $password"; + say "Using password: $password"; } return smd5($password); } -- cgit v1.2.3 From d04c66ffea981891c7c27d539ed8fe45cd9de307 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 16:30:33 +0100 Subject: Revert one simplification --- fripost-adduser | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/fripost-adduser b/fripost-adduser index c8bfc84..9a2fa00 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -46,18 +46,25 @@ my $schema = Fripost::Schema->connect( say "Adding a new virtual user."; my $user; { + my $username = prompt_email("New username: ", 'is_user'); + my $name = prompt "Full (real) name: "; + my $domain = (split /\@/, $username)[1]; + my $maildir = "$domain/". (split /\@/, $username)[0] . "/Maildir/"; # trailing slash important + my $active = 1; + my $password = prompt_password(); + $user = { - username => prompt_email("New username: ", 'is_user'), - name => prompt "Full (real) name: ", - domain => (split /\@/, $username)[1], - maildir => "$domain/". (split /\@/, $username)[0] . "/Maildir/", # trailing slash important - active => 1, - password => prompt_password(), + username => $username, + name => $name, + domain => $domain, + maildir => $maildir, + active => $active, + password => $password, }; - say "Username: $user->{username}"; - say "Name: $user->{name}"; - say "Password: (hidden)"; + say "Username: $user->{username}"; + say "Real name: $user->{name}"; + say "Password: (hidden)"; confirm_or_abort(); } -- cgit v1.2.3 From b197defa26836ed7eb3052bf5ef82e52078825e6 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 16:31:26 +0100 Subject: WIP: send credentials --- INSTALL | 5 ++-- fripost-adduser | 80 ++++++++++++++++++++++++++++++++++++++++++------------ templ/user_info.tt | 28 +++++++++++++++++++ 3 files changed, 94 insertions(+), 19 deletions(-) create mode 100644 templ/user_info.tt diff --git a/INSTALL b/INSTALL index 74be19a..cfbaa4d 100644 --- a/INSTALL +++ b/INSTALL @@ -2,6 +2,7 @@ You need several cpan modules to use these scripts. If you use Debian GNU/Linux, you can install them like so: -aptitude install -R libdatetime-format-mysql-perl libdatetime-perl \ +sudo aptitude install -R libdatetime-format-mysql-perl libdatetime-perl \ libdbix-class-perl libemail-valid-perl libfile-slurp-perl libio-prompt-perl \ -libmime-base64-perl libmime-lite-perl libstring-mkpasswd-perl libyaml-syck-perl +libmime-base64-perl libmime-lite-perl libstring-mkpasswd-perl \ +libtemplate-perl libyaml-syck-perl diff --git a/fripost-adduser b/fripost-adduser index 9a2fa00..e71de69 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -26,6 +26,7 @@ use IO::Prompt; use MIME::Base64; use MIME::Lite; use MIME::QuotedPrint; +use Template; use YAML::Syck; ## Get command line options @@ -73,36 +74,81 @@ die "User already exists" if ($schema->resultset('Mailbox')->search({ username => $user->{username} })->count); +## Insert user into database if ($conf->{pretend}) { - say "Nothing to do since we are pretending..."; - exit 0; + say "Did not create user since we are pretending." +} +else { + $schema->resultset('Mailbox')->new($user)->insert; + say "New account $user->{username} added."; } -## Insert user into database -my $db_user = $schema->resultset('Mailbox')->new($user); -$db_user->insert; -say "New account $user->{username} added."; +### Prepare sending emails + +my $tt = Template->new({ + INCLUDE_PATH => "$Bin/templ", + INTERPOLATE => 1, +}) || die "$Template::ERROR\n"; -## Send email my $msg = MIME::Lite->new( - From => 'admin@fripost.org', - To => $user->{username}, + From => 'Friposts administratörer ', Subject => "=?UTF-8?B?" . encode_base64(encode("utf8", 'Välkommen till Fripost!'), "") . "?=", - Data => scalar slurp('templ/new_user_mail.tt'), # TODO: actually use TT Encoding => 'quoted-printable', ); $msg->attr('content-type.charset' => 'utf-8'); -$msg->send(); - -say "Sent welcome message: "; -say $msg->as_string; -#say decode_qp($msg->as_string); -confirm_or_abort("Send email with login information? "); +### Send welcome email to new user +{ + my ($vars, $data); + $vars = {}; + $tt->process('new_user_mail.tt', $vars, \$data) + || die $tt->error(), '\n'; + + $msg->replace(To => $user->{username}); + $msg->data($data); + + + unless ($conf->{pretend}) { + $msg->send() unless $conf->{pretend};; + say "Sent welcome message."; + } + say "----------------------------------- Welcome"; + say decode_qp($msg->as_string); + say "-----------------------------------"; +} -prompt_email("Where should the email be sent? "); +### Send login credentials to new user +{ + my ($vars, $data); + $vars = { + user => $user->{username}, + pass => $user->{password}, + real => $user->{name}, + }; + $tt->process('user_info.tt', $vars, \$data) + || die $tt->error(), '\n'; + + $msg->data($data); + + say "Login information mail:"; + say "----------------------------------- Credentials"; + say decode_qp($msg->as_string); + say "-----------------------------------"; + + + confirm_or_abort("Send email with login information? "); + my $to = prompt_email("Where should the email be sent? "); + $msg->replace(To => $to); + if (!$conf->{pretend}) { + $msg->send; + say "Credentials sent."; + } + else { + say "Pretending, will not send credentials."; + } +} =head1 AUTHOR diff --git a/templ/user_info.tt b/templ/user_info.tt new file mode 100644 index 0000000..e6b778f --- /dev/null +++ b/templ/user_info.tt @@ -0,0 +1,28 @@ +Hej [% real %], + +Du är nu tillagd på Friposts system. + +Användarnamn: [% user %] +Lösenord [% pass %] + +Tänk på att vara försiktig med dina uppgifter. Spara en kopia av det här mailet +på en säker plats. + +Du kan logga in på: + + https://mail.fripost.org/ + +Frågor gällande ditt konto kan du ta direkt med administratörerna. + + admin@fripost.org + +Du kan hitta information om hur du konfigurerar din e-postklient för Fripost på +vår wiki. Vi försöker bygga upp medlemswikin till att bli den bästa resursen +för intern information kring föreningen. Du får gärna hjälpa till! + + http://wiki.fripost.org/ + +Ha kul! + +Med vänliga hälsningar, +Administratörerna -- cgit v1.2.3 From 6a541a75d37cb1ef63bc2289a3114882efe38190 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 16:51:05 +0100 Subject: adduser: Add verbosity options --- fripost-adduser | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/fripost-adduser b/fripost-adduser index e71de69..0c6f587 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -36,15 +36,19 @@ GetOptions( 'dbi_dsn' => \$conf->{dbi_dsn}, 'admuser=s' => \$conf->{admuser}, 'admpass=s' => \$conf->{admpass}, + 'debug' => \$conf->{debug}, 'pretend' => \$conf->{pretend}, + 'verbose' => \$conf->{verbose}, ) or die "Unable to get command line options."; +sub dsay { say @_ if $conf->{debug}; } +sub vsay { say @_ if $conf->{verbose} || $conf->{debug}; } + # Connect to the database my $schema = Fripost::Schema->connect( $conf->{dbi_dsn}, $conf->{admuser}, $conf->{admpass}, {} #\%dbi_params ); -say "Adding a new virtual user."; my $user; { my $username = prompt_email("New username: ", 'is_user'); @@ -63,7 +67,7 @@ my $user; password => $password, }; - say "Username: $user->{username}"; + say "User name: $user->{username}"; say "Real name: $user->{name}"; say "Password: (hidden)"; @@ -76,7 +80,7 @@ die "User already exists" ## Insert user into database if ($conf->{pretend}) { - say "Did not create user since we are pretending." + vsay "Did not create user since we are pretending." } else { $schema->resultset('Mailbox')->new($user)->insert; @@ -114,9 +118,11 @@ $msg->attr('content-type.charset' => 'utf-8'); $msg->send() unless $conf->{pretend};; say "Sent welcome message."; } - say "----------------------------------- Welcome"; - say decode_qp($msg->as_string); - say "-----------------------------------"; + dsay "-----------------------------------"; + dsay "| Welcome mail |"; + dsay "-----------------------------------"; + dsay decode_qp($msg->as_string); + dsay "-----------------------------------"; } ### Send login credentials to new user @@ -132,11 +138,11 @@ $msg->attr('content-type.charset' => 'utf-8'); $msg->data($data); - say "Login information mail:"; - say "----------------------------------- Credentials"; - say decode_qp($msg->as_string); - say "-----------------------------------"; - + dsay "-----------------------------------"; + dsay "| Login credentials mail |"; + dsay "-----------------------------------"; + dsay decode_qp($msg->as_string); + dsay "-----------------------------------"; confirm_or_abort("Send email with login information? "); my $to = prompt_email("Where should the email be sent? "); -- cgit v1.2.3 From 3c84e11c460289b4906dd8add66a036e9287d7e6 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 17:01:52 +0100 Subject: Fix subject encoding --- fripost-adduser | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fripost-adduser b/fripost-adduser index 0c6f587..a4ab077 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -16,7 +16,6 @@ use FindBin qw($Bin); use lib "$Bin/lib"; use Data::Dumper; -use Encode qw(encode); use File::Slurp qw(slurp); use Fripost::Password; use Fripost::Prompt; @@ -96,8 +95,7 @@ my $tt = Template->new({ my $msg = MIME::Lite->new( From => 'Friposts administratörer ', - Subject => "=?UTF-8?B?" . - encode_base64(encode("utf8", 'Välkommen till Fripost!'), "") . "?=", + Subject => "=?UTF-8?B?" . encode_base64('Välkommen till Fripost!' . "?=", Encoding => 'quoted-printable', ); -- cgit v1.2.3 From daad29e615acdb0f3778f5b9e120f2b1df0ac302 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 17:16:27 +0100 Subject: alias: improve output --- fripost-newalias | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fripost-newalias b/fripost-newalias index cf7f563..fb9acec 100755 --- a/fripost-newalias +++ b/fripost-newalias @@ -70,7 +70,7 @@ if (@addr == 0) { say "No valid destination adresses. Aborting..."; exit 1; } -say "dest adress: " . (join " ", @addr); +say "from adress: " . (join " ", @addr); confirm_or_abort(); ## Insert alias into database -- cgit v1.2.3 From bad3c7cdf557c76f05bfee0b07257264b3c5d04e Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 17:20:32 +0100 Subject: Fix package statements --- lib/Fripost/Logger.pm | 3 +-- lib/Fripost/Password.pm | 3 +-- lib/Fripost/Prompt.pm | 3 +-- lib/Fripost/Schema.pm | 1 - 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/Fripost/Logger.pm b/lib/Fripost/Logger.pm index c515a5c..0aacf2c 100755 --- a/lib/Fripost/Logger.pm +++ b/lib/Fripost/Logger.pm @@ -1,7 +1,6 @@ -#!/usr/bin/perl +package Fripost::Logger; use 5.010_000; -use warnings; use strict; =head1 NAME diff --git a/lib/Fripost/Password.pm b/lib/Fripost/Password.pm index 767bee1..12be42f 100755 --- a/lib/Fripost/Password.pm +++ b/lib/Fripost/Password.pm @@ -1,7 +1,6 @@ -#!/usr/bin/perl +package Fripost::Password; use 5.010_000; -use warnings; use strict; =head1 NAME diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index a7e517c..76529ec 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -1,7 +1,6 @@ -#!/usr/bin/perl +package Fripost::Prompt; use 5.010_000; -use warnings; use strict; =head1 NAME diff --git a/lib/Fripost/Schema.pm b/lib/Fripost/Schema.pm index 440d2ed..c9cc832 100755 --- a/lib/Fripost/Schema.pm +++ b/lib/Fripost/Schema.pm @@ -1,7 +1,6 @@ package Fripost::Schema; use 5.010_000; -use warnings; use strict; use base qw/DBIx::Class::Schema/; -- cgit v1.2.3 From c6d17eebc6f40188a33fa8aca863129ed57868e9 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 17:40:45 +0100 Subject: Fix export --- lib/Fripost/Password.pm | 1 + lib/Fripost/Prompt.pm | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Fripost/Password.pm b/lib/Fripost/Password.pm index 12be42f..038d835 100755 --- a/lib/Fripost/Password.pm +++ b/lib/Fripost/Password.pm @@ -17,6 +17,7 @@ use Exporter; use MIME::Base64; our @EXPORT = qw/smd5 make_salt/; +our @ISA = qw(Exporter); sub smd5 { my $pw = shift; diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index 76529ec..03c5fc4 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -17,7 +17,8 @@ use Exporter; use IO::Prompt; use String::MkPasswd qw/mkpasswd/; -our @EXPORT = qw(prompt_password prompt_username); +our @EXPORT = qw(confirm_or_abort fix_username prompt_email prompt_password); +our @ISA = qw(Exporter); sub confirm_or_abort { my ($msg) = @_; -- cgit v1.2.3 From 68708cd2430d4da548673fd612c891413448fddf Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 14 Mar 2011 20:54:51 +0100 Subject: Send password with credentials mail --- fripost-adduser | 2 +- fripost-passwd | 21 +++++---------------- lib/Fripost/Prompt.pm | 2 +- lib/Fripost/Schema/Result/Mailbox.pm | 18 ++++++++++++++++++ templ/new_user_mail.tt | 4 ++-- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/fripost-adduser b/fripost-adduser index a4ab077..ba97cdf 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -66,7 +66,7 @@ my $user; password => $password, }; - say "User name: $user->{username}"; + say "User name: $user->{username}"; say "Real name: $user->{name}"; say "Password: (hidden)"; diff --git a/fripost-passwd b/fripost-passwd index ad835b0..c01ca4b 100755 --- a/fripost-passwd +++ b/fripost-passwd @@ -13,22 +13,12 @@ fripost-passwd - Change password of user use FindBin qw($Bin); use lib "$Bin/lib"; -our $VERSION = '0.01'; - use Fripost::Password; use Fripost::Prompt; use Fripost::Schema; use Getopt::Long; use YAML::Syck; -my $username = $ARGV[0]; -$username //= prompt_username(); -my $password = prompt_password(); - -# Show the information that will be inserted -say "Password: $password"; -say "Salted MD5: " . smd5($password); - ## Get command line options our $conf = LoadFile('default.yml'); @@ -39,6 +29,10 @@ GetOptions( 'pretend' => \$conf->{pretend}, ) or die "Unable to get command line options."; +my $username = $ARGV[0]; +$username //= prompt_email("New username: ", 'is_user'); +my $password = prompt_password(); + if ($conf->{pretend}) { say "Nothing to do since we are pretending..."; exit 0; @@ -48,17 +42,12 @@ if ($conf->{pretend}) { my $schema = Fripost::Schema->connect( $conf->{dbi_dsn}, $conf->{admuser}, $conf->{admpass}, {} #\%dbi_params ); - my $row = $schema->resultset('Mailbox')->find($username); - -$row->password(smd5($password)); - +$row->password($password); $row->update; say "Updated password for $username."; -# TODO: ändra changedate vid varje insert - =head1 AUTHOR Stefan Kangas C<< >> diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index 03c5fc4..b41f806 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -82,7 +82,7 @@ sub prompt_password { ); say "Using password: $password"; } - return smd5($password); + return $password; } =head1 AUTHOR diff --git a/lib/Fripost/Schema/Result/Mailbox.pm b/lib/Fripost/Schema/Result/Mailbox.pm index f12e1f7..48d81fb 100644 --- a/lib/Fripost/Schema/Result/Mailbox.pm +++ b/lib/Fripost/Schema/Result/Mailbox.pm @@ -6,6 +6,8 @@ use strict; use base qw/DBIx::Class::Core/; +use Fripost::Password; + # mysql> describe mailbox; # +-------------+--------------+------+-----+---------------------+-------+ # | Field | Type | Null | Key | Default | Extra | @@ -32,6 +34,22 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key('username'); +=head2 store_column + +override store_column to encrypt the password when stored + +=cut + +sub store_column { + my ($self, $col, $val) = @_; + + if ($col eq 'password') { + $val = smd5($val); + } + + return $self->next::method($col,$val); +} + =head1 NAME Fripost::Schema::Result::Mailbox - diff --git a/templ/new_user_mail.tt b/templ/new_user_mail.tt index ba72c57..82eeac6 100644 --- a/templ/new_user_mail.tt +++ b/templ/new_user_mail.tt @@ -4,11 +4,11 @@ Allmänna frågor kring programmen, webmailen eller konfiguration av e-postprogram tas bäst på e-postlistan så att svaren kan komma alla till del. -Du kan bli medlem genom att skicka ett mail till +Du kan bli medlem på e-postlistan genom att skicka ett mail till: members-subscribe@lists.fripost.org -Frågor gällande specifikt ditt konto kan du ta direkt med administratörerna. +Frågor gällande specifikt ditt konto kan du ta direkt med administratörerna: admin@fripost.org -- cgit v1.2.3