[RFC,2/2] Use new vpn-show-cert.cgi in vpnmain.cgi

Message ID 20210218162427.11327-2-jonatan.schlag@ipfire.org
State New
Headers show
Series [RFC,1/2] Add a cgi page to show a vpn certificate | expand

Commit Message

Jonatan Schlag Feb. 18, 2021, 4:24 p.m. UTC
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 html/cgi-bin/vpnmain.cgi | 81 ++++------------------------------------
 1 file changed, 8 insertions(+), 73 deletions(-)

Patch

diff --git a/html/cgi-bin/vpnmain.cgi b/html/cgi-bin/vpnmain.cgi
index db442e111..55993e852 100644
--- a/html/cgi-bin/vpnmain.cgi
+++ b/html/cgi-bin/vpnmain.cgi
@@ -638,28 +638,6 @@  END
 
 	UPLOADCA_ERROR:
 
-###
-### Display ca certificate
-###
-} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) {
-	&General::readhasharray("${General::swroot}/vpn/caconfig", \%cahash);
-
-	if ( -f "${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") {
-		&Header::showhttpheaders();
-		&Header::openpage($Lang::tr{'ipsec'}, 1, '');
-		&Header::openbigbox('100%', 'left', '', '');
-		&Header::openbox('100%', 'left', "$Lang::tr{'ca certificate'}:");
-		my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`;
-		$output = &Header::cleanhtml($output,"y");
-		print "<pre>$output</pre>\n";
-		&Header::closebox();
-		print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>";
-		&Header::closebigbox();
-		&Header::closepage();
-		exit(0);
-	} else {
-		$errormessage = $Lang::tr{'invalid key'};
-	}
 
 ###
 ### Export ca certificate to browser
@@ -759,29 +737,6 @@  END
 		$errormessage = $Lang::tr{'invalid key'};
 	}
 
-###
-### Display root certificate
-###
-} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} ||
-	$cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) {
-	my $output;
-	&Header::showhttpheaders();
-	&Header::openpage($Lang::tr{'ipsec'}, 1, '');
-	&Header::openbigbox('100%', 'left', '', '');
-	if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) {
-		&Header::openbox('100%', 'left', "$Lang::tr{'root certificate'}:");
-		$output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ca/cacert.pem`;
-	} else {
-		&Header::openbox('100%', 'left', "$Lang::tr{'host certificate'}:");
-		$output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/hostcert.pem`;
-	}
-	$output = &Header::cleanhtml($output,"y");
-	print "<pre>$output</pre>\n";
-	&Header::closebox();
-	print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>";
-	&Header::closebigbox();
-	&Header::closepage();
-	exit(0);
 
 ###
 ### Export root certificate to browser
@@ -1178,26 +1133,6 @@  END
 	print `/bin/cat ${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1].p12`;
 	exit (0);
 
-###
-### Display certificate
-###
-} elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) {
-	&General::readhasharray("${General::swroot}/vpn/config", \%confighash);
-
-	if ( -f "${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") {
-		&Header::showhttpheaders();
-		&Header::openpage($Lang::tr{'ipsec'}, 1, '');
-		&Header::openbigbox('100%', 'left', '', '');
-		&Header::openbox('100%', 'left', "$Lang::tr{'cert'}:");
-		my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`;
-		$output = &Header::cleanhtml($output,"y");
-		print "<pre>$output</pre>\n";
-		&Header::closebox();
-		print "<div align='center'><a href='/cgi-bin/vpnmain.cgi'>$Lang::tr{'back'}</a></div>";
-		&Header::closebigbox();
-		&Header::closepage();
-		exit(0);
-	}
 
 ###
 ### Export Certificate to browser
@@ -3047,9 +2982,9 @@  END
 	if (($confighash{$key}[4] eq 'cert') && ($confighash{$key}[2] ne '%auth-dn')) {
 		print <<END
 		<td align='center' $col>
-		<form method='post' action='$ENV{'SCRIPT_NAME'}'>
+		<form method='post' action='/cgi-bin/vpn-show-cert.cgi'>
 		<input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' />
-		<input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' />
+		<input type='hidden' name='ACTION' value='showCert' />
 		<input type='hidden' name='KEY' value='$key' />
 		</form>
 		</td>
@@ -3173,8 +3108,8 @@  EOF
 		<td class='base' $col1>$Lang::tr{'root certificate'}</td>
 		<td class='base' $col1>$casubject</td>
 		<td width='3%' align='center' $col1>
-			<form method='post' action='$ENV{'SCRIPT_NAME'}'>
-			<input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' />
+			<form method='post' action='/cgi-bin/vpn-show-cert.cgi'>
+			<input type='hidden' name='ACTION' value='showRootCert' />
 			<input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show root certificate'}' title='$Lang::tr{'show root certificate'}' />
 			</form>
 		</td>
@@ -3206,8 +3141,8 @@  END
 		<td class='base' $col2>$Lang::tr{'host certificate'}</td>
 		<td class='base' $col2>$hostsubject</td>
 		<td width='3%' align='center' $col2>
-			<form method='post' action='$ENV{'SCRIPT_NAME'}'>
-			<input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' />
+			<form method='post' action='/cgi-bin/vpn-show-cert.cgi'>
+			<input type='hidden' name='ACTION' value='showHostCert' />
 			<input type='image' name='$Lang::tr{'show host certificate'}' src='/images/info.gif' alt='$Lang::tr{'show host certificate'}' title='$Lang::tr{'show host certificate'}' />
 			</form>
 		</td>
@@ -3245,9 +3180,9 @@  END
 			print "<td class='base' $col>$cahash{$key}[1]</td>\n";
 			print <<END
 			<td align='center' $col>
-			<form method='post' name='cafrm${key}a' action='$ENV{'SCRIPT_NAME'}'>
+			<form method='post' name='cafrm${key}a' action='/cgi-bin/vpn-show-cert.cgi'>
 			<input type='image' name='$Lang::tr{'show ca certificate'}' src='/images/info.gif' alt='$Lang::tr{'show ca certificate'}' title='$Lang::tr{'show ca certificate'}' />
-			<input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' />
+			<input type='hidden' name='ACTION' value='showCaCert' />
 			<input type='hidden' name='KEY' value='$key' />
 			</form>
 			</td>