MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //proc/self/root/scripts.20110531.215904.25158/gencrt
#!/usr/bin/perl
# cpanel - gencrt                                 Copyright(c) 2010 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

BEGIN { unshift @INC, '/usr/local/cpanel'; }

use strict;
use IPC::Open3      ();
use Sys::Hostname   ();
use Cpanel::Config  ();
use Cpanel::SSLInfo ();

alarm(1200);

my $hostname = Sys::Hostname::hostname();
my $sslroot  = Cpanel::SSLInfo::getsslroot();

my $now     = time();
my $gendate = localtime($now);
my $xemail  = $ARGV[0];
my $host    = $ARGV[1];
my $country = $ARGV[2];
my $state   = $ARGV[3];
my $city    = $ARGV[4];
my $co      = $ARGV[5];
my $cod     = $ARGV[6];
my $email   = $ARGV[7];
my $pass    = $ARGV[8];

if ( !-t STDIN && ( !$xemail || !$host || !$country || !$state || !$city || !$co || !$cod || !$email || !$pass ) ) {
    die "Can't get vars ... did you forget one of them ?";
}

my $contactemail = Cpanel::Config::get_public_contact();

my @SSLLOC = ( "/usr/bin/ssleay", "/usr/bin/openssl", "/usr/local/ssl/bin/ssleay", "/usr/local/ssl/bin/openssl" );
my $ssl;
foreach my $sslloc (@SSLLOC) {
    if ( -e $sslloc ) { $ssl = $sslloc; }
}

#GenCRT script by cPanel, Inc.

if ( -t STDIN ) {
    print "[==========Generating a SSL Certif for a HTTPS=================]\n";
    print "Before we begin please tell me where to e-mail the csr and key too-";
    $xemail = <STDIN>;
    $xemail =~ s/\n//g;
    print "Enter the domainname to make a cert for? ";
    $host = <STDIN>;
    $host =~ s/\n//g;
    print "=*=*=Cert info=*=*=\n";
    print "Enter the Country Code (2 letters ie. US)? ";
    $country = <STDIN>;
    $country =~ s/\n//g;
    print "Enter the State? ";
    $state = <STDIN>;
    $state =~ s/\n//g;
    print "Enter the City? ";
    $city = <STDIN>;
    $city =~ s/\n//g;
    print "Enter the Company Name? ";
    $co = <STDIN>;
    $co =~ s/\n//g;
    print "Enter the Company Division? ";
    $cod = <STDIN>;
    $cod =~ s/\n//g;
    print "Enter the Contact Email Address? ";
    $email = <STDIN>;
    $email =~ s/\n//g;
    print "Enter a challenge password? ";
    $pass = <STDIN>;
    $pass =~ s/\n//g;

}

#-------------------------------------------

$host = lc($host);

if ( !-t STDIN ) {
    print "<table border=1><tr><td><b>KEY (RSA Key)</b><pre>";
    print qq{<textarea name=key cols=66 rows=23>};
}
chdir("$sslroot/private");
if ( -e "$host.key" ) {
    system( 'mv', '-f', "$host.key", "$host.key.${now}" );
}

open( KEY,   ">$host.key" );
open( WNULL, ">/dev/null" );
open( RNULL, "</dev/null" );
IPC::Open3::open3( "<&RNULL", \*SSL, ">&WNULL", "$ssl", "genrsa", "1024" );
while (<SSL>) {
    print;
    print KEY $_;
}
close(SSL);
close(KEY);
close(WNULL);
close(RNULL);
if ( !-t STDIN ) {
    print qq{</textarea>};
    print "</td></tr></table>";
}

open( SENDMAIL, "|/usr/sbin/sendmail -t" );
print SENDMAIL "To: $contactemail\n";
print SENDMAIL "To: $xemail\n";
print SENDMAIL "From: ssl\@$hostname\n";
print SENDMAIL "Subject: SSL RSA PRIVATE KEY for $host ($gendate)\n\n";
print SENDMAIL<<EOM;
$country
$state
$city
$co
$cod
$host
$email

challenge password: $pass
========================================================
EOM
open( KEY, "$host.key" );
while (<KEY>) { print SENDMAIL $_ }
close(KEY);
close(SENDMAIL);

#---------------------------
chdir("$sslroot/certs");
if ( -e "$host.csr" ) {
    system( "mv", "$host.csr", "$host.csr.${now}" );
}

open( WNULL, ">/dev/null" );
IPC::Open3::open3( \*SSL, ">&WNULL", ">&WNULL", "$ssl", "req", "-new", "-key", "../private/$host.key", "-out", "$host.csr" );
print SSL<<EOM;
$country
$state
$city
$co
$cod
$host
$email
$pass
$co
EOM
close(SSL);
close(CERT);
close(WNULL);
sleep(2);

if ( !-t STDIN ) {
    print "<table border=1><tr><td><b>CSR (Certificate Signing Request)</b><pre>";
    print qq{<textarea name=csr cols=66 rows=23>};
}
open( CSR, "$host.csr" );
while (<CSR>) {
    print $_;
}
close(CSR);
if ( !-t STDIN ) {
    print qq{</textarea>};
    print "</td></tr></table>";
}

open( SENDMAIL, "|/usr/sbin/sendmail -t" );
print SENDMAIL "To: $contactemail\n";
print SENDMAIL "To: $xemail\n";
print SENDMAIL "From: ssl\@$hostname\n";
print SENDMAIL "Subject: SSL CERTIFICATE SIGNING REQUEST for $host ($gendate)\n\n";
open( KEY, "$host.csr" );
while (<KEY>) { print SENDMAIL $_ }
close(KEY);
close(SENDMAIL);

#--------------------------------------
if ( -e "$host.crt" ) {
    system( 'mv', '-f', "$host.crt", "$host.crt.${now}" );
}

open( WNULL, ">", "/dev/null" );
IPC::Open3::open3( \*SSL, \*CERT, ">&WNULL", "$ssl", "req", "-new", "-x509", "-days", "365", "-key", "../private/$host.key" );
print SSL<<EOM;
$country
$state
$city
$co
$cod
$host
$email
EOM

my $crtdata;
while (<CERT>) { $crtdata .= $_; }
close(SSL);
close(CERT);
close(WNULL);

open( CRT, '>', "$host.crt" );
print CRT $crtdata;
close(CRT);

if ( !-t STDIN ) {
    print "<table border=1><tr><td><b>CRT (Self Signed Certificate)</b><pre>";
    print qq{<textarea name=crt cols=66 rows=23>};
}
print $crtdata;
if ( !-t STDIN ) {
    print qq{</textarea>};
    print "</td></tr></table>";
}