diff options
author | Gustav Eek <gustav.eek@fripost.org> | 2011-05-14 13:41:47 +0200 |
---|---|---|
committer | Gustav Eek <gustav.eek@fripost.org> | 2011-05-14 13:41:47 +0200 |
commit | e14bd8eea4ad519e36a56dc868ed2e9effe1295e (patch) | |
tree | 1f4e6441be3602fa596b8564cc893b464580c503 | |
parent | 16ed1260dd2433d9c25cd550a06c175093416f58 (diff) | |
parent | ab34b78c7b247436a3d10d89b5f029fbe093ffe5 (diff) |
Merge branch 'master' of https://github.com/skangas/fripost-tools
-rwxr-xr-x | fripost-adduser | 33 | ||||
-rwxr-xr-x | fripost-newalias | 61 | ||||
-rwxr-xr-x | fripost-newdomain | 10 | ||||
-rwxr-xr-x | fripost-passwd | 4 | ||||
-rwxr-xr-x | lib/Fripost/Prompt.pm | 6 | ||||
-rw-r--r-- | templ/new_alias.tt | 12 | ||||
-rw-r--r-- | templ/user_info.tt | 22 |
7 files changed, 102 insertions, 46 deletions
diff --git a/fripost-adduser b/fripost-adduser index ba97cdf..db312a2 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -1,8 +1,9 @@ #!/usr/bin/perl use 5.010_000; -use warnings; use strict; +use warnings; +use utf8; =head1 NAME @@ -10,12 +11,11 @@ fripost-adduser - Add a new mailbox to the system =cut -our $VERSION = '0.02'; - 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; @@ -51,7 +51,6 @@ my $schema = Fripost::Schema->connect( 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; @@ -59,7 +58,6 @@ my $user; $user = { username => $username, - name => $name, domain => $domain, maildir => $maildir, active => $active, @@ -67,7 +65,6 @@ my $user; }; say "User name: $user->{username}"; - say "Real name: $user->{name}"; say "Password: (hidden)"; confirm_or_abort(); @@ -94,8 +91,8 @@ my $tt = Template->new({ }) || die "$Template::ERROR\n"; my $msg = MIME::Lite->new( - From => 'Friposts administratörer <admin@fripost.org>', - Subject => "=?UTF-8?B?" . encode_base64('Välkommen till Fripost!' . "?=", + From => encode('MIME-Q', 'Friposts administratörer') . ' <admin@fripost.org>', + Subject => encode('MIME-Q', 'Välkommen till Fripost!'), Encoding => 'quoted-printable', ); @@ -105,15 +102,15 @@ $msg->attr('content-type.charset' => 'utf-8'); { my ($vars, $data); $vars = {}; + $tt->process('new_user_mail.tt', $vars, \$data) || die $tt->error(), '\n'; - - $msg->replace(To => $user->{username}); $msg->data($data); + $msg->replace(To => $user->{username}); unless ($conf->{pretend}) { - $msg->send() unless $conf->{pretend};; + $msg->send() unless $conf->{pretend}; say "Sent welcome message."; } dsay "-----------------------------------"; @@ -129,11 +126,10 @@ $msg->attr('content-type.charset' => 'utf-8'); $vars = { user => $user->{username}, pass => $user->{password}, - real => $user->{name}, }; + $tt->process('user_info.tt', $vars, \$data) || die $tt->error(), '\n'; - $msg->data($data); dsay "-----------------------------------"; @@ -145,6 +141,7 @@ $msg->attr('content-type.charset' => 'utf-8'); 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."; @@ -154,6 +151,16 @@ $msg->attr('content-type.charset' => 'utf-8'); } } +### Subscribe user to announce-list +{ + confirm_or_abort("Subscribe user to announce mailing list? "); + $msg->replace(From => $user->{username}); + $msg->replace(To => 'announce-subscribe@lists.fripost.org'); + $msg->replace(Subject => ''); + $msg->replace(Data => ''); + $msg->send(); +} + =head1 AUTHOR Stefan Kangas C<< <skangas at skangas.se> >> diff --git a/fripost-newalias b/fripost-newalias index fb9acec..4592522 100755 --- a/fripost-newalias +++ b/fripost-newalias @@ -1,8 +1,9 @@ #!/usr/bin/perl use 5.010_000; -use warnings; use strict; +use warnings; +use utf8; =head1 NAME @@ -18,13 +19,17 @@ fripost-newalias GOTO FROM... use FindBin qw($Bin); use lib "$Bin/lib"; -use Data::Dumper; +use Encode qw(encode); use Email::Valid; use Fripost::Password; use Fripost::Prompt; use Fripost::Schema; use IO::Prompt; use Getopt::Long; +use MIME::Base64; +use MIME::Lite; +use MIME::QuotedPrint; +use Template; use YAML::Syck; ## Get command line options @@ -45,13 +50,8 @@ my $schema = Fripost::Schema->connect( # Get information my $goto = fix_username(shift @ARGV); my @addr = @ARGV; -$goto //= prompt_username("Alias goto address: "); -@addr || push @addr, prompt "Alias address: "; - -if ($conf->{pretend}) { - say "Nothing to do since we are pretending..."; - exit 0; -} +$goto //= prompt_email("Alias goto address: ", 'is_user'); +@addr || push @addr, prompt "Alias from address: "; # Show goto adress say "goto adress: $goto"; @@ -84,15 +84,52 @@ for my $addr (@addr) { goto => $goto, domain => (split /\@/, $addr)[1], }); - $db_alias->insert; - - say "New alias added from $addr to $goto."; + if (!$conf->{pretend}) { + $db_alias->insert; + say "New alias added from $addr to $goto."; + } else { + say "Pretending, will not add alias." + } } else { say "There already exists an alias for $addr."; } } +### Prepare sending emails +my $tt = Template->new({ + INCLUDE_PATH => "$Bin/templ", + INTERPOLATE => 1, +}) || die "$Template::ERROR\n"; + +my $msg = MIME::Lite->new( + From => encode('MIME-Q', 'Friposts administratörer') . ' <admin@fripost.org>', + Subject => encode('MIME-Q', 'Nya alias till din inkorg'), + Encoding => 'quoted-printable', +); + +{ + my ($vars, $data); + $vars = { + addrs => \@addr, + }; + + $tt->process('new_alias.tt', $vars, \$data) + || die $tt->error(), '\n'; + $msg->data($data); + + $msg->replace(To => $goto); + + if (!$conf->{pretend}) { + confirm_or_abort("Send confirmation? "); + $msg->send; + say "Sent verification."; + } + else { + say "Pretending, will not send verification."; + } +} + =head1 AUTHOR Stefan Kangas C<< <skangas at skangas.se> >> diff --git a/fripost-newdomain b/fripost-newdomain index cf781ed..99c2ce3 100755 --- a/fripost-newdomain +++ b/fripost-newdomain @@ -3,6 +3,7 @@ use 5.010_000; use warnings; use strict; +use utf8; =head1 NAME @@ -10,8 +11,6 @@ fripost-newdomain - Add a new domain to the system =cut -our $VERSION = '0.01'; - use FindBin qw($Bin); use lib "$Bin/lib"; @@ -27,7 +26,7 @@ use YAML::Syck; our $conf = LoadFile('default.yml'); GetOptions( - 'dbi_dsn' => \$conf->{dbi_dsn}, + 'dbi_dsn' => \$conf->{dbi_dsn}, 'admuser=s' => \$conf->{admuser}, 'admpass=s' => \$conf->{admpass}, 'pretend' => \$conf->{pretend}, @@ -38,13 +37,12 @@ my $schema = Fripost::Schema->connect( $conf->{dbi_dsn}, $conf->{admuser}, $conf->{admpass}, {} #\%dbi_params ); -say "Adding a new domain."; - my %domain; $domain{domain} = prompt "Domain name: "; -$domain{description} = prompt_username("User to associate domain with: "); +$domain{description} = prompt_email("Belongs to user: ", 'is_user'); ## TODO: Make sure the user does exists +## TODO: Warn if the user has a domain already if ($conf->{pretend}) { say "Nothing to do since we are only pretending..."; diff --git a/fripost-passwd b/fripost-passwd index c01ca4b..bb67e44 100755 --- a/fripost-passwd +++ b/fripost-passwd @@ -23,13 +23,13 @@ use YAML::Syck; our $conf = LoadFile('default.yml'); GetOptions( - 'dbi_dsn' => \$conf->{dbi_dsn}, + 'dbi_dsn' => \$conf->{dbi_dsn}, 'admuser=s' => \$conf->{admuser}, 'admpass=s' => \$conf->{admpass}, 'pretend' => \$conf->{pretend}, ) or die "Unable to get command line options."; -my $username = $ARGV[0]; +my $username = fix_username($ARGV[0]); $username //= prompt_email("New username: ", 'is_user'); my $password = prompt_password(); diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index b41f806..0a9d5c6 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -32,9 +32,9 @@ sub confirm_or_abort { sub fix_username { my ($nam) = @_; - if ($nam !~ /\@/) { + if (defined $nam && $nam !~ /\@/) { $nam .= '@fripost.org'; - say "Using username: $nam"; + say "Using $nam"; } return $nam; } @@ -47,7 +47,7 @@ sub prompt_email { $email = prompt $msg; if ($is_username) { - $email = fix_username($email) + $email = fix_username($email); } if (!Email::Valid->address($email)) { diff --git a/templ/new_alias.tt b/templ/new_alias.tt new file mode 100644 index 0000000..969e6ad --- /dev/null +++ b/templ/new_alias.tt @@ -0,0 +1,12 @@ +Hej, + +Följande adresser går nu till den här inkorgen: + +[% FOREACH addr IN addrs -%] + [% addr %] +[% END -%] + +Hör av dig om något är fel eller annars är oklart. + +Med vänliga hälsningar, +Administratörerna diff --git a/templ/user_info.tt b/templ/user_info.tt index e6b778f..6a375e5 100644 --- a/templ/user_info.tt +++ b/templ/user_info.tt @@ -1,14 +1,11 @@ -Hej [% real %], +Hej, -Du är nu tillagd på Friposts system. +Här kommer dina inloggningsuppgifter till Friposts system. Användarnamn: [% user %] -Lösenord [% pass %] +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å: +Du kan logga in direkt på: https://mail.fripost.org/ @@ -16,12 +13,17 @@ 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! +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/ +Tänk på att vara försiktig med dina uppgifter. Spara gärna en kopia av det här +mailet på en säker plats. + +Tyvärr finns det just nu inget smidigt sätt att byta sitt lösenord på. Vi jobbar +på det. + Ha kul! Med vänliga hälsningar, |