aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Fripost
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2012-09-23 20:57:43 +0200
committerGuilhem Moulin <guilhem.moulin@fripost.org>2012-09-23 20:57:43 +0200
commit06a4de26e05b74e3ed5493cef205af91462678a1 (patch)
treea6d6f009b3792f838fb4d9a2ff24d3d866cbf201 /lib/Fripost
parent0a4b5d24845fb86bade3ab3c38a6202862d6caad (diff)
Making the list creation method.
Diffstat (limited to 'lib/Fripost')
-rw-r--r--lib/Fripost/Panel/Interface.pm22
-rw-r--r--lib/Fripost/Panel/Login.pm16
-rw-r--r--lib/Fripost/Schema/List.pm27
-rw-r--r--lib/Fripost/Schema/Misc.pm1
4 files changed, 50 insertions, 16 deletions
diff --git a/lib/Fripost/Panel/Interface.pm b/lib/Fripost/Panel/Interface.pm
index 46d4058..e253ca0 100644
--- a/lib/Fripost/Panel/Interface.pm
+++ b/lib/Fripost/Panel/Interface.pm
@@ -37,7 +37,7 @@ sub ListDomains : StartRunmode {
my ($ul,$ud) = split /\@/, email_to_unicode($self->authen->username), 2;
- my $fp = Fripost::Schema->SASLauth( $self->authen->username, %CFG );
+ my $fp = Fripost::Schema::->SASLauth( $self->authen->username, %CFG );
my @domains = $fp->domain->search( -concat => "\n", -die => 403);
$fp->done;
@@ -139,6 +139,7 @@ sub ListLocals : Runmode {
, description => join ("\n", @{$_->{description}})
, isactive => $_->{isactive}
, transport => $_->{transport}
+ , listurl => $CFG{'listurl_'.$_->{transport}}.$_->{list}.'@'.$d
};
}
@lists
@@ -360,6 +361,7 @@ sub AddLocal : Runmode {
if (defined $q->param('submit')) {
# Changes have been submitted: process them
my %entry;
+ my %rest;
if ($t eq 'mailbox') {
$entry{user} = $q->param('user').'@'.$du;
$entry{forwards} = $q->param('forwards');
@@ -383,6 +385,22 @@ sub AddLocal : Runmode {
elsif ($t eq 'list') {
$entry{list} = $q->param('list').'@'.$du;
$entry{transport} = $q->param('transport');
+ if ($q->param('password') ne $q->param('password2')) {
+ $error = "Passwords do not match";
+ }
+ elsif (length $q->param('password') < $CFG{password_min_length}) {
+ $error = "Password should be at least "
+ .$CFG{password_min_length}
+ ." characters long.";
+ }
+ else {
+ $rest{gpg} = { use_agent => 0
+ , keydir => $CFG{gpghome}
+ , key => $CFG{gpg_private_key_id}
+ , passphrase => $CFG{gpg_private_key_passphrase}
+ };
+ $entry{password} = $q->param('password');
+ }
}
else {
# Unknown type
@@ -393,7 +411,7 @@ sub AddLocal : Runmode {
unless ($error) {
my $fp = Fripost::Schema::->SASLauth( $self->authen->username, %CFG );
- $error = $fp->$t->add( \%entry, -concat => "(\n|\x{0D}\x{0A})");
+ $error = $fp->$t->add( \%entry, -concat => "(\n|\x{0D}\x{0A})", %rest);
$fp->done;
return $self->redirect($q->url.'/'.$d.'/') unless $error;
}
diff --git a/lib/Fripost/Panel/Login.pm b/lib/Fripost/Panel/Login.pm
index a147371..1483e06 100644
--- a/lib/Fripost/Panel/Login.pm
+++ b/lib/Fripost/Panel/Login.pm
@@ -20,7 +20,6 @@ use CGI::Application::Plugin::Redirect;
use CGI::Application::Plugin::ConfigAuto 'cfg';
use Fripost::Schema;
-use File::Spec::Functions qw/catfile catdir/;
use HTML::Entities;
use Net::IDN::Encode qw/email_to_ascii/;
@@ -92,12 +91,11 @@ sub setup {
my $self = shift;
$self->header_props( -charset=>'utf-8' );
- $self->tmpl_path( catdir ( $self->cfg('pwd'), $self->cfg('tmpl_path') ) );
+ $self->tmpl_path( $self->cfg('tmpl_path') );
$self->mode_param( sub {
my $self = shift;
my $q = $self->query;
- print STDERR $ENV{PATH_INFO} . '?' . $q->query_string, "\n";
# The user just logged in
return 'okay' if defined $q->param('login');
@@ -135,9 +133,9 @@ sub setup {
# wanted to visit.
sub okay : Runmode {
my $self = shift;
- my $destination = $self->query->param('destination') //
- $self->query->url;
- return $self->redirect($destination);
+ my $redirect = $self->query->param('redirect') //
+ $self->query->url;
+ return $self->redirect($redirect);
}
@@ -154,8 +152,8 @@ sub login : Runmode {
$self->query->param('a') eq 'login';
# Where the users wants to go
- $self->query->param( destination => $self->query->self_url)
- unless defined $self->query->param('destination');
+ $self->query->param( redirect => $self->query->self_url)
+ unless defined $self->query->param('redirect');
return $self->login_box;
}
@@ -167,7 +165,7 @@ sub login_box {
my $template = $self->load_tmpl( 'login.html', cache => 1, utf8 => 1 );
$template->param( error => $self->authen->login_attempts );
- $template->param( destination => $self->query->param('destination') );
+ $template->param( redirect => $self->query->param('redirect') );
return $template->output;
}
diff --git a/lib/Fripost/Schema/List.pm b/lib/Fripost/Schema/List.pm
index 69317b1..edf9d24 100644
--- a/lib/Fripost/Schema/List.pm
+++ b/lib/Fripost/Schema/List.pm
@@ -20,6 +20,8 @@ use parent 'Fripost::Schema';
use Fripost::Schema::Misc qw/concat explode must_attrs email_valid/;
use Net::IDN::Encode qw/domain_to_ascii
email_to_ascii email_to_unicode/;
+use Mail::GnuPG;
+use MIME::Entity;
=head1 METHODS
@@ -105,6 +107,7 @@ sub add {
my $l = shift;
my %options = @_;
+ my $lname = $l->{list};
$l->{description} = explode ($options{'-concat'}, $l->{description})
if defined $l->{description};
@@ -114,7 +117,7 @@ sub add {
die "Missing list name\n" if $l eq '';
must_attrs( $l, 'transport' );
&_is_valid($l);
- die "‘".$l->{list}."‘ alread exists\n"
+ die "‘".$l->{list}."‘ already exists\n"
if $self->local->exists($l->{list},%options);
my %attrs = ( objectClass => 'FripostVirtualList'
@@ -134,8 +137,24 @@ sub add {
die $mesg->error."\n";
}
};
- return $@;
- # TODO: send email to mklist-$transport to finalize
+ return $@ if $@;
+
+ # Ask the list manager to create the list now.
+ my $member = $self->whoami;
+ $member =~ s/^fvu=([^,]+),fvd=([^,]+),.*$/$1\@$2/;
+ my $mail = MIME::Entity::->build(
+ From => 'Fripost Admin Panel <AdminWebPanel@fripost.org>',
+ To => 'mklist+'.$l->{transport}.'@fripost.org',
+ Subject => "New ".$l->{transport}." list",
+ Encoding => 'quoted-printable',
+ Charset => 'utf-8',
+ Data => [ map { $_ . "\n"} ($lname, $member, $l->{password}) ]
+ );
+ my $gpg = Mail::GnuPG::->new( %{$options{gpg}} );
+ my $ret = $gpg->mime_sign( $mail );
+ return join ("\n", @{$gpg->{last_message}}) if $ret;
+ $mail->send;
+ return 0;
}
@@ -166,7 +185,7 @@ sub is_pending {
die "Error: Multiple matching entries found." if $mesg->count > 1;
my $list = $mesg->pop_entry;
-
+
die "Error: No matching entry found." unless defined $list;
my $r = $list->get_value('fripostIsStatusPending');
return (defined $r and $r eq 'TRUE');
diff --git a/lib/Fripost/Schema/Misc.pm b/lib/Fripost/Schema/Misc.pm
index 39fa3b7..745a20b 100644
--- a/lib/Fripost/Schema/Misc.pm
+++ b/lib/Fripost/Schema/Misc.pm
@@ -10,7 +10,6 @@ use 5.010_000;
use strict;
use warnings;
use utf8;
-use feature "unicode_strings";
use Exporter 'import';
our @EXPORT_OK = qw /concat get_perms explode