Added language support for chpasswd.cgi

Message ID 1507122180-16347-1-git-send-email-erik.kapfer@ipfire.org
State Dropped
Headers show
Series Added language support for chpasswd.cgi | expand

Commit Message

ummeegge Oct. 5, 2017, 12:03 a.m. UTC
---
 html/cgi-bin/chpasswd.cgi | 57 +++++++++++++++++++++++++++--------------------
 1 file changed, 33 insertions(+), 24 deletions(-)

Comments

ummeegge Oct. 7, 2017, 1:13 a.m. UTC | #1
Hi Michael,
sorry for the two patches, the 'general::swroot' part has been missing by accident :-| . Hope this is OK now.

Greetings,

UE

Am 04.10.2017 um 17:51 schrieb Michael Tremer:

> Hi,
> 
> good patch.
> 
> You could have dropped the $swroot variable and use $General::swroot like you
> did with many other variables.
> 
> Would you send an updated patch?
> 
> -Michael

Patch

diff --git a/html/cgi-bin/chpasswd.cgi b/html/cgi-bin/chpasswd.cgi
index 0a66062..00494f2 100644
--- a/html/cgi-bin/chpasswd.cgi
+++ b/html/cgi-bin/chpasswd.cgi
@@ -19,15 +19,26 @@ 
 #                                                                             #
 ###############################################################################
 
+use strict;
+
+#usable only the following on debugging purpose
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
+
 use CGI qw(param);
 use Apache::Htpasswd;
 use Crypt::PasswdMD5;
 
-$swroot = "/var/ipfire";
-
 my %cgiparams;
 my %mainsettings;
 my %proxysettings;
+my %netsettings;
+my %temp;
+my $swroot;
+my $errormessage;
+my $language;
+
+$swroot = "/var/ipfire";
 
 $proxysettings{'NCSA_MIN_PASS_LEN'} = 6;
 
@@ -38,12 +49,10 @@  $language = $mainsettings{'LANGUAGE'};
 
 ### Initialize language
 if ($language =~ /^(\w+)$/) {$language = $1;}
- #
- # Uncomment this to force a certain language:
- # $language='en';
- #
-require "${swroot}/langs/en.pl";
-require "${swroot}/langs/${language}.pl";
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/header.pl";
 
 my $userdb = "$swroot/proxy/advanced/ncsa/passwd";
 
@@ -53,26 +62,26 @@  my $success = 0;
 
 &getcgihash(\%cgiparams);
 
-if ($cgiparams{'SUBMIT'} eq $tr{'advproxy chgwebpwd change password'})
+if ($cgiparams{'SUBMIT'} eq $Lang::tr{'advproxy chgwebpwd change password'})
 {
 	if ($cgiparams{'USERNAME'} eq '')
 	{
-		$errormessage = $tr{'advproxy errmsg no username'};
+		$errormessage = $Lang::tr{'advproxy errmsg no username'};
 		goto ERROR;
 	}
 	if (($cgiparams{'OLD_PASSWORD'} eq '') || ($cgiparams{'NEW_PASSWORD_1'} eq '') || ($cgiparams{'NEW_PASSWORD_2'} eq ''))
 	{
-		$errormessage = $tr{'advproxy errmsg no password'};
+		$errormessage = $Lang::tr{'advproxy errmsg no password'};
 		goto ERROR;
 	}
 	if (!($cgiparams{'NEW_PASSWORD_1'} eq $cgiparams{'NEW_PASSWORD_2'}))
 	{
-		$errormessage = $tr{'advproxy errmsg passwords different'};
+		$errormessage = $Lang::tr{'advproxy errmsg passwords different'};
 		goto ERROR;
 	}
 	if (length($cgiparams{'NEW_PASSWORD_1'}) < $proxysettings{'NCSA_MIN_PASS_LEN'})
 	{
-		$errormessage = $tr{'advproxy errmsg password length 1'}.$proxysettings{'NCSA_MIN_PASS_LEN'}.$tr{'advproxy errmsg password length 2'};
+		$errormessage = $Lang::tr{'advproxy errmsg password length 1'}.$proxysettings{'NCSA_MIN_PASS_LEN'}.$Lang::tr{'advproxy errmsg password length 2'};
 		goto ERROR;
 	}
 
@@ -81,14 +90,14 @@  if ($cgiparams{'SUBMIT'} eq $tr{'advproxy chgwebpwd change password'})
 	# Check if a user with this name exists
 	my $old_password = $htpasswd->fetchPass($cgiparams{'USERNAME'});
 	if (!$old_password) {
-		$errormessage = $tr{'advproxy errmsg invalid user'};
+		$errormessage = $Lang::tr{'advproxy errmsg invalid user'};
 		goto ERROR;
 	}
 
 	# Reset password
 	if (!$htpasswd->htpasswd($cgiparams{'USERNAME'}, $cgiparams{'NEW_PASSWORD_1'},
 			$cgiparams{'OLD_PASSWORD'})) {
-		$errormessage = $tr{'advproxy errmsg password incorrect'};
+		$errormessage = $Lang::tr{'advproxy errmsg password incorrect'};
 		goto ERROR;
 	}
 
@@ -103,7 +112,7 @@  print "Cache-control: no-cache\n";
 print "Connection: close\n";
 print "Content-type: text/html\n\n";
 
-print <<END
+print <<END;
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
@@ -124,7 +133,7 @@  print <<END
 		<tr>
 			<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>
+			<b>$Lang::tr{'advproxy chgwebpwd change web password'}</b>
 			</font>
 			</td>
 		</tr>
@@ -134,7 +143,7 @@  print <<END
 				<tr>
 					<td nowrap bgcolor="#FFFFFF" align="left">
 					<font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
-					<b>$tr{'advproxy chgwebpwd username'}:</b>
+					<b>$Lang::tr{'advproxy chgwebpwd username'}:</b>
 					</font>
 					</td>
 					<td ><input type="text" name="USERNAME" value="$cgiparams{'USERNAME'}" size="30"></td>
@@ -142,7 +151,7 @@  print <<END
 				<tr>
 					<td nowrap bgcolor="#FFFFFF" align="left">
 					<font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
-					<b>$tr{'advproxy chgwebpwd old password'}:</b>
+					<b>$Lang::tr{'advproxy chgwebpwd old password'}:</b>
 					</font>
 					</td>
 					<td><input type="password" name="OLD_PASSWORD" value="$cgiparams{'OLD_PASSWORD'}" size="30"></td>
@@ -150,7 +159,7 @@  print <<END
 				<tr>
 					<td nowrap bgcolor="#FFFFFF" align="left">
 					<font face="trebuchet ms, helvetica, sans-serif" color="#666666" size="2">
-					<b>$tr{'advproxy chgwebpwd new password'}:</b>
+					<b>$Lang::tr{'advproxy chgwebpwd new password'}:</b>
 					</font>
 					</td>
 					<td><input type="password" name="NEW_PASSWORD_1" value="$cgiparams{'NEW_PASSWORD_1'}" size="30"></td>
@@ -158,7 +167,7 @@  print <<END
 				<tr>
 					<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>
+					<b>$Lang::tr{'advproxy chgwebpwd new password confirm'}:</b>
 					</font>
 					</td>
 					<td><input type="password" name="NEW_PASSWORD_2" value="$cgiparams{'NEW_PASSWORD_2'}" size="30"></td>
@@ -166,7 +175,7 @@  print <<END
 				</table>
 				<table width="100%" cellspacing="7" cellpadding="7">
 				<tr>
-					<td align="center"><br><input type='submit' name='SUBMIT' value="$tr{'advproxy chgwebpwd change password'}"></td>
+					<td align="center"><br><input type='submit' name='SUBMIT' value="$Lang::tr{'advproxy chgwebpwd change password'}"></td>
 				</tr>
 				</table>
 			</td>
@@ -180,7 +189,7 @@  if ($errormessage)
 	<tr>
 		<td nowrap bgcolor="#FF0000" align="center">
 		<font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="2">
-		<b>$tr{'advproxy chgwebpwd ERROR'}</b> $errormessage
+		<b>$Lang::tr{'advproxy chgwebpwd ERROR'}</b> $errormessage
 		</font>
 		</td>
 	</tr>
@@ -194,7 +203,7 @@  if ($success)
 	<tr>
 		<td nowrap bgcolor="#00C000" align="center">
 		<font face="trebuchet ms, helvetica, sans-serif" color="#FFFFFF" size="2">
-		<b>$tr{'advproxy chgwebpwd SUCCESS'}</b> $tr{'advproxy errmsg change success'}
+		<b>$Lang::tr{'advproxy chgwebpwd SUCCESS'}</b> $Lang::tr{'advproxy errmsg change success'}
 		</font>
 		</td>
 	</tr>