]>
git.ipfire.org Git - people/ms/ipfire-2.x.git/blob - html/cgi-bin/chpasswd.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
26 $swroot = "/var/ipfire";
32 $proxysettings{'NCSA_MIN_PASS_LEN'} = 6;
34 ### Initialize environment
35 &readhash
("${swroot}/main/settings", \
%mainsettings);
36 &readhash
("${swroot}/proxy/advanced/settings", \
%proxysettings);
37 $language = $mainsettings{'LANGUAGE'};
39 ### Initialize language
40 if ($language =~ /^(\w+)$/) {$language = $1;}
42 # Uncomment this to force a certain language:
45 require "${swroot}/langs/en.pl";
46 require "${swroot}/langs/${language}.pl";
48 my $userdb = "$swroot/proxy/advanced/ncsa/passwd";
50 &readhash
("$swroot/ethernet/settings", \
%netsettings);
54 &getcgihash
(\
%cgiparams);
56 if ($cgiparams{'SUBMIT'} eq $tr{'advproxy chgwebpwd change password'})
58 if ($cgiparams{'USERNAME'} eq '')
60 $errormessage = $tr{'advproxy errmsg no username'};
63 if (($cgiparams{'OLD_PASSWORD'} eq '') || ($cgiparams{'NEW_PASSWORD_1'} eq '') || ($cgiparams{'NEW_PASSWORD_2'} eq ''))
65 $errormessage = $tr{'advproxy errmsg no password'};
68 if (!($cgiparams{'NEW_PASSWORD_1'} eq $cgiparams{'NEW_PASSWORD_2'}))
70 $errormessage = $tr{'advproxy errmsg passwords different'};
73 if (length($cgiparams{'NEW_PASSWORD_1'}) < $proxysettings{'NCSA_MIN_PASS_LEN'})
75 $errormessage = $tr{'advproxy errmsg password length 1'}.$proxysettings{'NCSA_MIN_PASS_LEN'}.$tr{'advproxy errmsg password length 2'};
79 my $htpasswd = new Apache
::Htpasswd
("$userdb");
81 # Check if a user with this name exists
82 my $old_password = $htpasswd->fetchPass($cgiparams{'USERNAME'});
84 $errormessage = $tr{'advproxy errmsg invalid user'};
89 if (!$htpasswd->htpasswd($cgiparams{'USERNAME'}, $cgiparams{'NEW_PASSWORD_1'},
90 $cgiparams{'OLD_PASSWORD'})) {
91 $errormessage = $tr{'advproxy errmsg password incorrect'};
101 print "Pragma: no-cache\n";
102 print "Cache-control: no-cache\n";
103 print "Connection: close\n";
104 print "Content-type: text/html\n\n";
109 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
113 <body bgcolor="#FFFFFF">
117 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
119 <table width="80%" cellspacing="10" cellpadding="5">
122 <td bgcolor="#FFFFFF" align="center">
123 <table width="100%" cellspacing="10" cellpadding="10" bordercolor="#9A9A9A" border="1">
125 <td nowrap bgcolor="#993333" align="center" >
126 <font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="4">
127 <b>$tr{'advproxy chgwebpwd change web password'}</b>
133 <table width="50%" cellspacing="7" cellpadding="7">
135 <td nowrap bgcolor="#FFFFFF" align="left">
136 <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
137 <b>$tr{'advproxy chgwebpwd username'}:</b>
140 <td ><input type="text" name="USERNAME" value="$cgiparams{'USERNAME'}" size="30"></td>
143 <td nowrap bgcolor="#FFFFFF" align="left">
144 <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
145 <b>$tr{'advproxy chgwebpwd old password'}:</b>
148 <td><input type="password" name="OLD_PASSWORD" value="$cgiparams{'OLD_PASSWORD'}" size="30"></td>
151 <td nowrap bgcolor="#FFFFFF" align="left">
152 <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
153 <b>$tr{'advproxy chgwebpwd new password'}:</b>
156 <td><input type="password" name="NEW_PASSWORD_1" value="$cgiparams{'NEW_PASSWORD_1'}" size="30"></td>
159 <td nowrap bgcolor="#FFFFFF" align="left">
160 <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
161 <b>$tr{'advproxy chgwebpwd new password confirm'}:</b>
164 <td><input type="password" name="NEW_PASSWORD_2" value="$cgiparams{'NEW_PASSWORD_2'}" size="30"></td>
167 <table width="100%" cellspacing="7" cellpadding="7">
169 <td align="center"><br><input type='submit' name='SUBMIT' value="$tr{'advproxy chgwebpwd change password'}"></td>
181 <td nowrap bgcolor="#FF0000" align="center">
182 <font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="2">
183 <b>$tr{'advproxy chgwebpwd ERROR'}</b> $errormessage
195 <td nowrap bgcolor="#00C000" align="center">
196 <font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="2">
197 <b>$tr{'advproxy chgwebpwd SUCCESS'}</b> $tr{'advproxy errmsg change success'}
224 # -------------------------------------------------------------------
228 my $filename = $_[0];
234 open(FILE
, $filename) or die "Unable to read file $filename";
238 ($var, $val) = split /=/, $_, 2;
244 # Untaint variables read from hash
245 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
246 $val =~ /([\w\W]*)/; $val = $1;
247 $hash->{$var} = $val;
254 # -------------------------------------------------------------------
258 my ($hash, $params) = @_;
259 my $cgi = CGI
->new ();
260 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
261 if (!$params->{'wantfile'}) {
262 $CGI::DISABLE_UPLOADS
= 1;
263 $CGI::POST_MAX
= 512 * 1024;
265 $CGI::POST_MAX
= 10 * 1024 * 1024;
268 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
270 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
272 return if ($referer ne $servername);
274 ### Modified for getting multi-vars, split by |
275 %temp = $cgi->Vars();
276 foreach my $key (keys %temp) {
277 $hash->{$key} = $temp{$key};
278 $hash->{$key} =~ s/\0/|/g;
279 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
282 if (($params->{'wantfile'})&&($params->{'filevar'})) {
283 $hash->{$params->{'filevar'}} = $cgi->upload
284 ($params->{'filevar'});
289 # -------------------------------------------------------------------