diff options
Diffstat (limited to 'lib/FPanel')
-rw-r--r-- | lib/FPanel/Interface.pm | 69 | ||||
-rw-r--r-- | lib/FPanel/Login.pm | 24 |
2 files changed, 80 insertions, 13 deletions
diff --git a/lib/FPanel/Interface.pm b/lib/FPanel/Interface.pm index 6781ae5..b1b7fe5 100644 --- a/lib/FPanel/Interface.pm +++ b/lib/FPanel/Interface.pm @@ -20,9 +20,9 @@ sub cgiapp_init { } -# This is the first page an authenticated user sees. It lists the known +# This is the first page seen by authenticated users. It lists the known # domains. -sub DomainList : StartRunmode { +sub ListDomains : StartRunmode { my $self = shift; my %CFG = $self->cfg; my $suffix = join ',', @{$CFG{ldap_suffix}}; @@ -37,9 +37,10 @@ sub DomainList : StartRunmode { , deref => 'never' ); die $domains->error if $domains->code; + $ldap->unbind; - my $template = $self->load_tmpl( 'domain-list.html', cache => 1, utf8 => 1 + my $template = $self->load_tmpl( 'list-domains.html', cache => 1, utf8 => 1 , loop_context_vars => 1 , global_vars => 1 ); $template->param( URL => $self->query->url ); @@ -56,6 +57,67 @@ sub DomainList : StartRunmode { return $template->output; } +# This is the page used to edit domains. +sub EditDomain : Runmode { + my $self = shift; + my %CFG = $self->cfg; + my $suffix = join ',', @{$CFG{ldap_suffix}}; + + my ($l,$d) = split /@/, $self->authen->username, 2; + my $authzDN = "fvu=$l,fvd=$d,". $suffix; + my $ldap = $self->ldap_from_auth_user($authzDN); + + my $domain = (split /\//, $ENV{PATH_INFO}, 3)[1]; + + if (defined $self->query->param('submit') or + defined $self->query->param('active')) { + # Changes have been submitted: process them + my %changes; + if (defined $self->query->param('active')) { + $changes{fripostIsStatusActive} = $self->query->param('active'); + } + if (defined $self->query->param('description')) { + my @desc; + foreach my $d (split /\n/, $self->query->param('description')) { + push @desc, $d; + } + $changes{description} = [ @desc ]; + } + if (defined $self->query->param('maildrop')) { + my @maildrop; + foreach my $d (split /\n/, $self->query->param('maildrop')) { + $d =~ s/\s//g; + push @maildrop, (lc $d) unless $d =~ /^$/; + } + $changes{fripostOptionalMaildrop} = [ @maildrop ]; + } + + my $mesg = $ldap->modify( "fvd=$domain,$suffix", replace => \%changes ); + die $mesg->error if $mesg->code; + } + + my $answer = $ldap->search( base => 'fvd='.$domain .','. $suffix + , scope => 'base' + , filter => 'objectClass=FripostVirtualDomain' + , deref => 'never' + ); + die $answer->error if $answer->code; + $answer = $answer->entry('0'); + $ldap->unbind; + + my $template = $self->load_tmpl( 'edit-domain.html', cache => 1, utf8 => 1 + , loop_context_vars => 1 + , global_vars => 1 ); + $template->param( URL => $self->query->url ); + $template->param( USER_LOCALPART => $l, USER_DOMAINPART => $d); + $template->param( DOMAIN => $domain ); + $template->param( DESCRIPTION => join ("\n",$answer->get_value('description')) ); + $template->param( MAILDROP => join ("\n",$answer->get_value('fripostOptionalMaildrop')) ); + $template->param( ISACTIVE => $answer->get_value('fripostIsStatusActive') eq 'TRUE' ? 1 : 0 ); + $template->param( NEWCHANGES => defined $self->query->param('submit') ); + return $template->output; +} + # This subroutine displays the access that the given DN has on the entry. # Possible values are : @@ -124,4 +186,3 @@ sub ldap_from_auth_user { 1; - diff --git a/lib/FPanel/Login.pm b/lib/FPanel/Login.pm index 506a7b8..173a34f 100644 --- a/lib/FPanel/Login.pm +++ b/lib/FPanel/Login.pm @@ -59,6 +59,7 @@ sub cgiapp_init { my $ldap = Net::LDAP->new( $CFG{ldap_uri} ); my $mesg = $ldap->bind ( $bind_dn, password => $p ); + $ldap->unbind; $mesg->code ? 0 : $u; } ], STORE => 'Session', @@ -87,23 +88,22 @@ sub setup { print STDERR $ENV{PATH_INFO} . '?' . $q->query_string, "\n"; # The user just logged in - return 'okay' if (defined $q->param('authen_username')) and - (defined $q->param('authen_password')); + return 'okay' if defined $q->param('login'); my $a = $q->param('a'); return 'login' if defined $a and $a eq 'login'; return 'logout' if defined $a and $a eq 'logout'; - # /domain/{user,alias,list}/?requests + # /domain/{user,alias,list}/?query_url my ($null,$domain,$local,$crap) = split /\//, $ENV{PATH_INFO}; - return 'DomainList' unless (defined $null) and $null eq ''; + return 'ListDomains' unless (defined $null) and $null eq ''; unless (defined $domain and $domain ne '') { if (defined $a) { return 'AddDomain' if $a eq 'AddDomain'; } - return 'DomainList'; + return 'ListDomains'; } unless (defined $local and $local ne '') { @@ -111,15 +111,16 @@ sub setup { return 'EditDomain' if $a eq 'edit'; return 'AddAccount' if $a eq 'AddAccount'; return 'AddAlias' if $a eq 'AddAlias'; + return 'AddList' if $a eq 'AddList'; } - return 'LocalList'; + return 'ListLocals'; } unless (defined $crap and $crap ne '') { - return 'LocalEdit'; + return 'EditLocal'; } - return 'DomainList'; + return 'error_404'; }); } @@ -193,11 +194,16 @@ sub error_rm : ErrorRunmode { my $template = $self->load_tmpl( 'error.html', cache => 1, utf8 => 1 ); $template->param( EMAIL => $self->cfg('report_email') ); $template->param( MESSAGE => $error ); - $template->param( URL => $self->query->url ); + $template->param( URL => $self->query->url . '/'); return $template->output; } +sub error_404 : Runmode { + my $self = shift; + $self->header_props ( -status => '404 Not found' ); + return ''; +} 1; |