]>
git.ipfire.org Git - 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 ###############################################################################
25 $swroot = "/var/ipfire";
31 $proxysettings{'NCSA_MIN_PASS_LEN'} = 6;
33 ### Initialize environment
34 &readhash
("${swroot}/main/settings", \
%mainsettings);
35 &readhash
("${swroot}/proxy/advanced/settings", \
%proxysettings);
36 $language = $mainsettings{'LANGUAGE'};
38 ### Initialize language
39 if ($language =~ /^(\w+)$/) {$language = $1;}
41 # Uncomment this to force a certain language:
44 require "${swroot}/langs/en.pl";
45 require "${swroot}/langs/${language}.pl";
47 my $userdb = "$swroot/proxy/advanced/ncsa/passwd";
49 &readhash
("$swroot/ethernet/settings", \
%netsettings);
53 &getcgihash
(\
%cgiparams);
55 if ($cgiparams{'SUBMIT'} eq $tr{'advproxy chgwebpwd change password'})
57 if ($cgiparams{'USERNAME'} eq '')
59 $errormessage = $tr{'advproxy errmsg no username'};
62 if (($cgiparams{'OLD_PASSWORD'} eq '') || ($cgiparams{'NEW_PASSWORD_1'} eq '') || ($cgiparams{'NEW_PASSWORD_2'} eq ''))
64 $errormessage = $tr{'advproxy errmsg no password'};
67 if (!($cgiparams{'NEW_PASSWORD_1'} eq $cgiparams{'NEW_PASSWORD_2'}))
69 $errormessage = $tr{'advproxy errmsg passwords different'};
72 if (length($cgiparams{'NEW_PASSWORD_1'}) < $proxysettings{'NCSA_MIN_PASS_LEN'})
74 $errormessage = $tr{'advproxy errmsg password length 1'}.$proxysettings{'NCSA_MIN_PASS_LEN'}.$tr{'advproxy errmsg password length 2'};
89 @temp = split(/:/,$_);
90 if ($temp[0] =~ /^$cgiparams{'USERNAME'}$/i)
99 $errormessage = $tr{'advproxy errmsg invalid user'};
103 !(crypt($cgiparams{'OLD_PASSWORD'}, $cryptpwd) eq $cryptpwd) &&
104 !(apache_md5_crypt
($cgiparams{'OLD_PASSWORD'}, $cryptpwd) eq $cryptpwd)
107 $errormessage = $tr{'advproxy errmsg password incorrect'};
110 $returncode = system("/usr/sbin/htpasswd -b $userdb $username $cgiparams{'NEW_PASSWORD_1'}");
111 if ($returncode == 0)
116 $errormessage = $tr{'advproxy errmsg change fail'};
123 print "Pragma: no-cache\n";
124 print "Cache-control: no-cache\n";
125 print "Connection: close\n";
126 print "Content-type: text/html\n\n";
131 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
135 <body bgcolor="#FFFFFF">
139 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
141 <table width="80%" cellspacing="10" cellpadding="5">
144 <td bgcolor="#FFFFFF" align="center">
145 <table width="100%" cellspacing="10" cellpadding="10" bordercolor="#9A9A9A" border="1">
147 <td nowrap bgcolor="#993333" align="center" >
148 <font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="4">
149 <b>$tr{'advproxy chgwebpwd change web password'}</b>
155 <table width="50%" cellspacing="7" cellpadding="7">
157 <td nowrap bgcolor="#FFFFFF" align="left">
158 <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
159 <b>$tr{'advproxy chgwebpwd username'}:</b>
162 <td ><input type="text" name="USERNAME" value="$cgiparams{'USERNAME'}" size="30"></td>
165 <td nowrap bgcolor="#FFFFFF" align="left">
166 <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
167 <b>$tr{'advproxy chgwebpwd old password'}:</b>
170 <td><input type="password" name="OLD_PASSWORD" value="$cgiparams{'OLD_PASSWORD'}" size="30"></td>
173 <td nowrap bgcolor="#FFFFFF" align="left">
174 <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
175 <b>$tr{'advproxy chgwebpwd new password'}:</b>
178 <td><input type="password" name="NEW_PASSWORD_1" value="$cgiparams{'NEW_PASSWORD_1'}" size="30"></td>
181 <td nowrap bgcolor="#FFFFFF" align="left">
182 <font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
183 <b>$tr{'advproxy chgwebpwd new password confirm'}:</b>
186 <td><input type="password" name="NEW_PASSWORD_2" value="$cgiparams{'NEW_PASSWORD_2'}" size="30"></td>
189 <table width="100%" cellspacing="7" cellpadding="7">
191 <td align="center"><br><input type='submit' name='SUBMIT' value="$tr{'advproxy chgwebpwd change password'}"></td>
203 <td nowrap bgcolor="#FF0000" align="center">
204 <font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="2">
205 <b>$tr{'advproxy chgwebpwd ERROR'}</b> $errormessage
217 <td nowrap bgcolor="#00C000" align="center">
218 <font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="2">
219 <b>$tr{'advproxy chgwebpwd SUCCESS'}</b> $tr{'advproxy errmsg change success'}
246 # -------------------------------------------------------------------
250 my $filename = $_[0];
256 open(FILE
, $filename) or die "Unable to read file $filename";
260 ($var, $val) = split /=/, $_, 2;
266 # Untaint variables read from hash
267 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
268 $val =~ /([\w\W]*)/; $val = $1;
269 $hash->{$var} = $val;
276 # -------------------------------------------------------------------
280 my ($hash, $params) = @_;
281 my $cgi = CGI
->new ();
282 return if ($ENV{'REQUEST_METHOD'} ne 'POST');
283 if (!$params->{'wantfile'}) {
284 $CGI::DISABLE_UPLOADS
= 1;
285 $CGI::POST_MAX
= 512 * 1024;
287 $CGI::POST_MAX
= 10 * 1024 * 1024;
290 $cgi->referer() =~ m/^https?\:\/\
/([^\/]+)/;
292 $cgi->url() =~ m/^https?\:\/\
/([^\/]+)/;
294 return if ($referer ne $servername);
296 ### Modified for getting multi-vars, split by |
297 %temp = $cgi->Vars();
298 foreach my $key (keys %temp) {
299 $hash->{$key} = $temp{$key};
300 $hash->{$key} =~ s/\0/|/g;
301 $hash->{$key} =~ s/^\s*(.*?)\s*$/$1/;
304 if (($params->{'wantfile'})&&($params->{'filevar'})) {
305 $hash->{$params->{'filevar'}} = $cgi->upload
306 ($params->{'filevar'});
311 # -------------------------------------------------------------------