version 1.2, 2025/02/16 03:14:50
|
version 1.4, 2025/02/17 15:55:49
|
Line 10
|
Line 10
|
# Licensed AGPL-3.0 |
# Licensed AGPL-3.0 |
# |
# |
# $Log$ |
# $Log$ |
|
# Revision 1.4 2025/02/17 15:55:49 snw |
|
# Fix password change form action URL |
|
# |
|
# Revision 1.3 2025/02/17 15:54:19 snw |
|
# Add password change capability |
|
# |
# Revision 1.2 2025/02/16 03:14:50 snw |
# Revision 1.2 2025/02/16 03:14:50 snw |
# Add background image |
# Add background image |
# |
# |
Line 21
|
Line 27
|
use CGI qw(:standard); |
use CGI qw(:standard); |
use CGI::Session; |
use CGI::Session; |
|
|
$portolis_version = '0.0.4'; |
|
$session = CGI::Session->new(); |
$session = CGI::Session->new(); |
|
|
sub init |
sub init |
Line 99 END_HDR
|
Line 104 END_HDR
|
if($session->param("~logged-in")) { |
if($session->param("~logged-in")) { |
my $email = $session->param("~email"); |
my $email = $session->param("~email"); |
$navbar = <<"END_NAVL"; |
$navbar = <<"END_NAVL"; |
<A HREF=/cgi-bin/portolis.cgi?exec=home>$email</A> | <A HREF=https://webmail.coherent-logic.com>WebMail</A> | <A HREF=/cgi-bin/portolis.cgi?exec=logout>Log out</A> |
<A HREF=/cgi-bin/portolis.cgi?exec=home>$email</A> | <A HREF=https://webmail.coherent-logic.com>WebMail</A> | <A HREF=/cgi-bin/portolis.cgi?exec=pw>Change Password</A> | <A HREF=/cgi-bin/portolis.cgi?exec=logout>Log out</A> |
<HR> |
<HR> |
END_NAVL |
END_NAVL |
} |
} |
Line 303 END_DANOF
|
Line 308 END_DANOF
|
|
|
} |
} |
|
|
|
sub exec_pw { |
|
|
|
if($session->param("~logged-in") == 0) { |
|
render_header "Access Denied"; |
|
$html = <<"END_BADDAF"; |
|
<H1>Access Denied</H1> |
|
<P>You are not logged in.</P> |
|
END_BADDAF |
|
|
|
print $html; |
|
return; |
|
} |
|
|
|
my $html = ''; |
|
render_header "Change Password"; |
|
|
|
if(request_method() eq 'GET') { |
|
$html = <<"END_EPW"; |
|
<CENTER> |
|
<H1>Change Password</H1> |
|
<FORM METHOD=POST ACTION=/cgi-bin/portolis.cgi?exec=pw> |
|
<TABLE CELLPADDING=3 CELLSPACING=0 BORDER=1> |
|
<TR> |
|
<TD><B>Password:</B></TD> |
|
<TD><INPUT TYPE=PASSWORD NAME=password></TD> |
|
</TR> |
|
<TR> |
|
<TD><B>Enter again to confirm:</B></TD> |
|
<TD><INPUT TYPE=PASSWORD NAME=password_confirm></TD> |
|
</TR> |
|
<TR> |
|
<TD COLSPAN=2 ALIGN=RIGHT> |
|
<INPUT TYPE=SUBMIT NAME=submit VALUE=Submit> |
|
</TD> |
|
</TR> |
|
</TABLE> |
|
</FORM> |
|
END_EPW |
|
} |
|
elsif(request_method() eq 'POST') { |
|
my $password = param('password'); |
|
my $password_confirm = param('password_confirm'); |
|
my $email = $session->param("~email"); |
|
my @parts = split('@', $email); |
|
my $localpart = $parts[0]; |
|
my $domainpart = $parts[1]; |
|
if($password eq $password_confirm) { |
|
my $hash = `/usr/pkg/bin/doveadm pw -p \"$password\"`; |
|
$hash =~s/\R//g; |
|
my $str = "$email:$hash:1007:1007:/home/maildeliverer/$domainpart/$localpart\n"; |
|
|
|
open(FH, '<', '/usr/pkg/etc/dovecot/users'); |
|
flock FH, 2; |
|
|
|
my @lines = (); |
|
|
|
while(<FH>) { |
|
my $line = $_; |
|
my @pwent = split(':', $line); |
|
if($pwent[0] ne $email) { |
|
push @lines, $line; |
|
} |
|
} |
|
push @lines, $str; |
|
|
|
flock FH, 8; |
|
close FH; |
|
|
|
open(FH, '>', '/tmp/users.new'); |
|
flock(FH, 2); |
|
seek(FH, 0, 0); |
|
truncate(FH, 0); |
|
print FH @lines; |
|
flock FH, 8; |
|
close(FH); |
|
$html = <<"END_PWCPOST"; |
|
<CENTER> |
|
<H1>Password Changed</H1> |
|
<A HREF=/cgi-bin/portolis.cgi?exec=home>Home</A> |
|
</CENTER> |
|
END_PWCPOST |
|
|
|
} |
|
else { |
|
$html = <<"END_PWCNM"; |
|
<CENTER> |
|
<H1>Submission Error</H1> |
|
<P>Passwords did not match. <A HREF=/cgi-bin/portolis.cgi?exec=pw>Try again</A>.</P> |
|
</CENTER> |
|
END_PWCNM |
|
} |
|
} |
|
|
|
print $html; |
|
|
|
} |
|
|
sub exec_login { |
sub exec_login { |
|
|
render_header "Login"; |
render_header "Login"; |
Line 400 sub main {
|
Line 502 sub main {
|
elsif($exec eq 'delalias') { |
elsif($exec eq 'delalias') { |
$funcref = \&exec_delalias; |
$funcref = \&exec_delalias; |
} |
} |
|
elsif($exec eq 'pw') { |
|
$funcref = \&exec_pw; |
|
} |
else { |
else { |
$funcref = \&exec_unknown; |
$funcref = \&exec_unknown; |
} |
} |