#!/usr/bin/perl
-
-#
-# $Id: chpasswd.cgi,v 1.0 2005/01/25 00:00:00 marco Exp $
-#
+###############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
use CGI qw(param);
+use Apache::Htpasswd;
+use Crypt::PasswdMD5;
-$swroot = "/var/ipcop";
+$swroot = "/var/ipfire";
my %cgiparams;
my %mainsettings;
$errormessage = $tr{'advproxy errmsg password length 1'}.$proxysettings{'NCSA_MIN_PASS_LEN'}.$tr{'advproxy errmsg password length 2'};
goto ERROR;
}
- if (! -z $userdb)
- {
- open FILE, $userdb;
- @users = <FILE>;
- close FILE;
- $username = '';
- $cryptpwd = '';
+ my $htpasswd = new Apache::Htpasswd("$userdb");
- foreach (@users)
- {
- chomp;
- @temp = split(/:/,$_);
- if ($temp[0] =~ /^$cgiparams{'USERNAME'}$/i)
- {
- $username = $temp[0];
- $cryptpwd = $temp[1];
- }
- }
- }
- if ($username eq '')
- {
+ # Check if a user with this name exists
+ my $old_password = $htpasswd->fetchPass($cgiparams{'USERNAME'});
+ if (!$old_password) {
$errormessage = $tr{'advproxy errmsg invalid user'};
goto ERROR;
}
- if (!(crypt($cgiparams{'OLD_PASSWORD'}, $cryptpwd) eq $cryptpwd))
- {
+
+ # Reset password
+ if (!$htpasswd->htpasswd($cgiparams{'USERNAME'}, $cgiparams{'NEW_PASSWORD_1'},
+ $cgiparams{'OLD_PASSWORD'})) {
$errormessage = $tr{'advproxy errmsg password incorrect'};
goto ERROR;
}
- $returncode = system("/usr/bin/htpasswd -b $userdb $username $cgiparams{'NEW_PASSWORD_1'}");
- if ($returncode == 0)
- {
- $success = 1;
- undef %cgiparams;
- } else {
- $errormessage = $tr{'advproxy errmsg change fail'};
- goto ERROR;
- }
+
+ $success = 1;
+ undef %cgiparams;
}
ERROR:
<form method='post' action='$ENV{'SCRIPT_NAME'}'>
-<table width="80%" cellspacing="10" cellpadding="5" border="0">
+<table width="80%" cellspacing="10" cellpadding="5">
<tr>
- <td bgcolor="#C0C0C0">
- <font face="verdana, arial, sans serif" color="#000000" size="2">
- <b> </b>
- </font>
- </td>
-</tr>
-<tr>
- <td bgcolor="#F4F4F4" align="center">
- <table width="100%" cellspacing="10" cellpadding="10">
+ <td bgcolor="#FFFFFF" align="center">
+ <table width="100%" cellspacing="10" cellpadding="10" bordercolor="#9A9A9A" border="1">
<tr>
- <td nowrap bgcolor="#0050C0" align="center">
- <font face="verdana, arial, sans serif" color="#FFFFFF" size="3">
+ <td nowrap bgcolor="#993333" align="center" >
+ <font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="4">
<b>$tr{'advproxy chgwebpwd change web password'}</b>
</font>
</td>
</tr>
<tr>
<td align="center">
- <table width="70%" cellspacing="7" cellpadding="7">
+ <table width="50%" cellspacing="7" cellpadding="7">
<tr>
- <td nowrap bgcolor="#F4F4F4" align="left">
- <font face="verdana, arial, sans serif" color="#000000" size="2">
+ <td nowrap bgcolor="#FFFFFF" align="left">
+ <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
<b>$tr{'advproxy chgwebpwd username'}:</b>
</font>
</td>
- <td><input type="text" name="USERNAME" value="$cgiparams{'USERNAME'}" size="15"></td>
+ <td ><input type="text" name="USERNAME" value="$cgiparams{'USERNAME'}" size="30"></td>
</tr>
<tr>
- <td nowrap bgcolor="#F4F4F4" align="left">
- <font face="verdana, arial, sans serif" color="#000000" size="2">
+ <td nowrap bgcolor="#FFFFFF" align="left">
+ <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
<b>$tr{'advproxy chgwebpwd old password'}:</b>
</font>
</td>
- <td><input type="password" name="OLD_PASSWORD" value="$cgiparams{'OLD_PASSWORD'}" size="15"></td>
+ <td><input type="password" name="OLD_PASSWORD" value="$cgiparams{'OLD_PASSWORD'}" size="30"></td>
</tr>
<tr>
- <td nowrap bgcolor="#F4F4F4" align="left">
- <font face="verdana, arial, sans serif" color="#000000" size="2">
+ <td nowrap bgcolor="#FFFFFF" align="left">
+ <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
<b>$tr{'advproxy chgwebpwd new password'}:</b>
</font>
</td>
- <td><input type="password" name="NEW_PASSWORD_1" value="$cgiparams{'NEW_PASSWORD_1'}" size="15"></td>
+ <td><input type="password" name="NEW_PASSWORD_1" value="$cgiparams{'NEW_PASSWORD_1'}" size="30"></td>
</tr>
<tr>
- <td nowrap bgcolor="#F4F4F4" align="left">
- <font face="verdana, arial, sans serif" color="#000000" size="2">
+ <td nowrap bgcolor="#FFFFFF" align="left">
+ <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
<b>$tr{'advproxy chgwebpwd new password confirm'}:</b>
</font>
</td>
- <td><input type="password" name="NEW_PASSWORD_2" value="$cgiparams{'NEW_PASSWORD_2'}" size="15"></td>
+ <td><input type="password" name="NEW_PASSWORD_2" value="$cgiparams{'NEW_PASSWORD_2'}" size="30"></td>
</tr>
</table>
<table width="100%" cellspacing="7" cellpadding="7">
print <<END
<tr>
<td nowrap bgcolor="#FF0000" align="center">
- <font face="verdana, arial, sans serif" color="#FFFFFF" size="2">
+ <font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="2">
<b>$tr{'advproxy chgwebpwd ERROR'}</b> $errormessage
</font>
</td>
print <<END
<tr>
<td nowrap bgcolor="#00C000" align="center">
- <font face="verdana, arial, sans serif" color="#FFFFFF" size="2">
+ <font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="2">
<b>$tr{'advproxy chgwebpwd SUCCESS'}</b> $tr{'advproxy errmsg change success'}
</font>
</td>
</tr>
</table>
-<tr>
- <td bgcolor="#C0C0C0" align="right">
- <a href="http://www.advproxy.net" target="_blank"><b>
- <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">Advanced Proxy</b></a> running on</font>
- <a href="http://www.ipcop.org" target="_blank"><b>
- <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">IPCop</b></a></font>
- </td>
-</tr>
-
</table>
</form>