rendered paste body#!/usr/bin/perl -T
use lib '/usr/local/cpanel';
use Cpanel::Sys ();
my $rdhost = $ENV{'HTTP_HOST'};
open( CPCONF, "/var/cpanel/cpanel.config" );
while (<CPCONF>) {
next if (/^#/);
s/\n//g;
( $var, $value ) = split( /=/, $_ );
$CPCONF{$var} = $value;
}
close(CPCONF);
my $port = $CPCONF{port};
my $sslport = $CPCONF{sslport};
if ( ( $ENV{'HTTPS'} eq "on" || $CPCONF{'alwaysredirecttossl'} )
&& $CPCONF{'cpredirecthostname'} )
{
$rdhost = Cpanel::Sys::gethostname();
}
if ( $port eq "" ) { $port = '2082'; }
if ( $sslport eq "" ) { $sslport = '2083'; }
if ( $ENV{'HTTPS'} eq "on" || $CPCONF{'alwaysredirecttossl'} ) {
if ( -s "/var/cpanel/ssl/cpanel-CN" ) {
my $sslhost;
open( my $cp_fh, '<', '/var/cpanel/ssl/cpanel-CN' );
local ($/);
$sslhost = readline($cp_fh);
close($cp_fh);
if ($sslhost !~ /\*/) { $rdhost = $sslhost; }
}
if ( ${rdhost} ne "" ) {
print "Location: https://${rdhost}:${sslport}\n\n";
exit;
}
print "Location: https://$ENV{REMOTE_ADDR}:${sslport}\n\n";
}
else {
if ( ${rdhost} ne "" ) {
print "Location: http://${rdhost}:${port}\n\n";
exit;
}
print "Location: http://$ENV{REMOTE_ADDR}:${port}\n\n";
}