aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Fripost/Panel
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Fripost/Panel')
-rw-r--r--lib/Fripost/Panel/Interface.pm85
-rw-r--r--lib/Fripost/Panel/Login.pm23
2 files changed, 63 insertions, 45 deletions
diff --git a/lib/Fripost/Panel/Interface.pm b/lib/Fripost/Panel/Interface.pm
index aee0df4..b0deeb0 100644
--- a/lib/Fripost/Panel/Interface.pm
+++ b/lib/Fripost/Panel/Interface.pm
@@ -40,17 +40,23 @@ sub ListDomains : StartRunmode {
my %CFG = $self->cfg;
my $fp = Fripost::Schema::->SASLauth( $self->authen->username, %CFG );
- my @domains = $fp->domain->search( -concat => "\n", -die => 403);
+ my @domains = $fp->domain->search( undef, -die => 403, -sort => 1,
+ -keys => [qw/name isActive isPending description/]);
+ my $canIAdd = $fp->domain->domain->canIAdd;
$fp->done;
- my $template = $self->load_tmpl( 'list-domains.html', cache => 1,
+ my $template = $self->load_tmpl( 'list-domains.html', cache => 1
, loop_context_vars => 1 );
$template->param( $self->userInfo );
- $template->param( domains => [ map { { &mkLink( domain => $_->{domain})
- , isactive => $_->{isactive}
- , ispending => $_->{ispending}
- , description => $_->{description} } }
- @domains ]
+ $template->param( canIAddDomain => $canIAdd );
+ $template->param( domains => [
+ map {
+ { &mkLink( domain => $_->{name})
+ , isActive => $_->{isActive}
+ , isPending => $_->{isPending}
+ , description => &mkDesc($_->{description})
+ } }
+ @domains ]
);
return $template->output;
}
@@ -67,7 +73,8 @@ sub ListLocals : Runmode {
my $q = $self->query;
if (defined $q->param('unlock')) {
- $fp->domain->unlock( $d, $q->param('unlock') )
+ my $error; # TODO
+ $fp->domain->unlock( $d, $q->param('unlock'), -error => \$error )
if $q->param('unlock') ne '';
$fp->done;
return $self->redirect('../');
@@ -158,7 +165,7 @@ sub ListLocals : Runmode {
# In this Run Mode authenticated users can edit the domain description
-# and catchalls, and toggle activation (if they have the permission).
+# and catch-alls, and toggle activation (if they have the permission).
sub EditDomain : Runmode {
my $self = shift;
my %CFG = $self->cfg;
@@ -173,28 +180,29 @@ sub EditDomain : Runmode {
my $error; # Tells whether the change submission has failed.
if (defined $q->param('submit')) {
# Changes have been submitted: process them
- $error = $fp->domain->replace({
- domain => $d,
- isactive => $q->param('isactive') // 1,
- description => $q->param('description') // undef,
- catchalls => $q->param('catchalls') // undef,
- canAddAlias => $q->param('canAddAlias') // undef,
- canAddList => $q->param('canAddList') // undef
- }, -concat => "(\n|\x{0D}\x{0A})");
+ $fp->domain->replace({
+ name => $d,
+ isActive => $q->param('isActive') // 1,
+ description => $q->param('description'),
+ catchAlls => [ split /\x{0D}\x{0A}/, ($q->param('catchAlls')//'') ],
+# canAddAlias => [ split /\x{0D}\x{0A}/, ($q->param('canAddAlias')//'') ],
+# canAddList => [ split /\x{0D}\x{0A}/, ($q->param('canAddList')//'') ]
+ # ^ TODO: if postmaster
+ }, -error => \$error);
}
- my %domain = $fp->domain->get( $d, -die => 404 );
+ my $domain = $fp->domain->search( $d, -die => 403, -filter => 'unlocked' ) // die "404\n";
$fp->done;
my $template = $self->load_tmpl( 'edit-domain.html', cache => 1,
, loop_context_vars => 1 );
$template->param( $self->userInfo );
$template->param( domain => encode_entities($d)
- , isPostmaster => $domain{permissions} eq 'p');
+ , isPostmaster => $domain->{permissions} eq 'p');
if ($error) {
# Preserve the (incorrect) form
- $template->param( isactive => $q->param('isactive') // 1
+ $template->param( isActive => $q->param('isActive') // 1
, description => $q->param('description') // undef
- , catchalls => $q->param('catchalls') // undef
+ , catchAlls => $q->param('catchAlls') // undef
, canAddAlias => $q->param('canAddAlias') // undef
, canAddList => $q->param('canAddList') // undef
, error => encode_entities ($error) );
@@ -371,16 +379,19 @@ sub AddDomain : Runmode {
and grep { $q->param('postmaster') eq $_ } @postmasters;
}
- $error = $fp->domain->add({
- domain => $domain,
- send_token_to => $q->param('postmaster') // undef,
- isactive => $q->param('isactive') // 1,
- description => $q->param('description') // undef,
- catchalls => $q->param('catchalls') // undef },
- -concat => "(\n|\x{0D}\x{0A})",
+ $fp->domain->add({
+ name => $domain,
+ isActive => $q->param('isActive') // 1,
+# description => $q->param('description') // undef,
+# catchAlls => [ split /\x{0D}\x{0A}/, $q->param('catchAlls') ]
+ },
+ '-send-confirmation-token' => $q->param('postmaster') // undef,
'-dry-run' => not (defined $q->param('postmaster')),
- -domainurl => $q->url.'/'.encode_entities($domain).'/' # TODO: try that in nginx
- ) unless $error;
+ -error => \$error,
+ webapp_url => $self->cfg('webapp_url'),
+ tmpl_path => $self->cfg('tmpl_path'),
+ email_from => $self->cfg('email_from')
+ );
}
$fp->done;
@@ -396,7 +407,10 @@ sub AddDomain : Runmode {
}
else {
$tmpl_file = 'add-domain-2.html';
- @postmasters = Fripost::Schema::Domain::->list_postmasters($domain);
+ @postmasters = Fripost::Schema::Domain::->list_admin_emails(
+ $domain, -error => \$error
+ );
+ $tmpl_file = 'add-domain-1.html' if $error;
}
my $template = $self->load_tmpl( $tmpl_file, cache => 1,
@@ -404,9 +418,9 @@ sub AddDomain : Runmode {
$template->param( $self->userInfo );
$template->param( error => encode_entities ($error) ) if $error;
- $template->param( isactive => $q->param('isactive') // 1
+ $template->param( isActive => $q->param('isActive') // 1
, description => $q->param('description') // undef
- , catchalls => $q->param('catchalls') // undef
+ , catchAlls => $q->param('catchAlls') // undef
);
$template->param( domain => encode_entities($domain) )
if defined $domain;
@@ -559,6 +573,11 @@ sub mkFormContent {
join ("\x{0D}\x{0A}", @_);
}
+sub mkDesc {
+ my $desc = shift // return '';
+ join '<br>', map {encode_entities($_)} @$desc;
+}
+
=head1 AUTHOR
Guilhem Moulin C<< <guilhem at fripost.org> >>
diff --git a/lib/Fripost/Panel/Login.pm b/lib/Fripost/Panel/Login.pm
index 00fff72..736207d 100644
--- a/lib/Fripost/Panel/Login.pm
+++ b/lib/Fripost/Panel/Login.pm
@@ -7,7 +7,7 @@ use utf8;
=head1 NAME
-Login.pm -
+Login.pm - Authentication subroutines for the Web Interface.
=cut
@@ -63,8 +63,6 @@ sub cgiapp_init {
$CFG{default_realm} // return 0;
$u .= '@'.$CFG{default_realm};
}
- Encode::_utf8_on($u);
- $u = email_to_ascii($u);
my $fp = Fripost::Schema::->auth($u, $p, %CFG, -die => 0);
return 0 unless defined $fp;
$fp->done;
@@ -105,16 +103,16 @@ sub setup {
# /domain/{user,alias,list}/?query_url
my ($null,$domain,$local,$crap) = $self->split_path;
- return 'ListDomains' if (defined $null) and $null ne '';
+ return 'ListDomains' if $null;
- unless (defined $domain and $domain ne '') {
+ unless ($domain) {
if (defined $a) {
return 'AddDomain' if $a eq 'add';
}
return 'ListDomains';
}
- unless (defined $local and $local ne '') {
+ unless ($local) {
if (defined $a) {
return 'EditDomain' if $a eq 'edit';
return 'AddLocal' if $a eq 'add';
@@ -131,8 +129,7 @@ sub setup {
# wanted to visit.
sub okay : Runmode {
my $self = shift;
- my $redirect = $self->query->param('redirect') //
- $self->query->url;
+ my $redirect = $self->query->param('redirect') // $self->query->url;
return $self->redirect($redirect);
}
@@ -219,18 +216,20 @@ sub error_rm : ErrorRunmode {
}
}
+# Split the URI; give the list of its components.
+# The facing CGI script and trailing query are not considered.
sub split_path {
my $self = shift;
my %options = @_;
my $script = $ENV{SCRIPT_NAME} // $self->cfg->{'cgi-bin'} // '';
- $script =~ s@/$@@s;
+ $script =~ s@/$@@s; # Strip the trailing '/' off the script name
my $uri = $self->query->request_uri;
- $uri =~ s/^$script//s;
- $uri =~ s/\?.*//s;
+ $uri =~ s/^$script//s; # Strip the facing CGI script name
+ $uri =~ s/\?.*//s; # Strip the query
- map { my $x = decodeURIComponent($_); Encode::_utf8_on($x); $x }
+ map { decodeURIComponent($_); Encode::_utf8_on($_); $_ }
(split /\//, $uri);
}