%PDF- %PDF-
Direktori : /usr/share/ |
Current File : //usr/share/installssl.pl |
#!/usr/local/cpanel/3rdparty/bin/perl use LWP::UserAgent; use LWP::Protocol::https; use MIME::Base64; use IO::Socket::SSL; use URI::Escape; my $accesshash; my $access_hash_file = '/root/.accesshash'; sysopen (my $access_hash_file_fh, $access_hash_file, O_RDONLY) or die "unable to open root_access_hash_file $!\n"; while (<$access_hash_file_fh>) { $accesshash .= $_; } close ($access_hash_file_fh); $accesshash =~ s/\n//g; my $user = "WHM root"; my $auth = $user . ":" . $accesshash; my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0, SSL_verify_mode => 'SSL_VERIFY_NONE', SSL_use_cert => 0 }, ); my ($dom, $domdir) = @ARGV; if (not defined $dom) { die "Please specify domain\n"; } if (not defined $domdir) { $domdir = $dom; } my $certfile = "/etc/letsencrypt/live/$domdir/cert.pem"; my $keyfile = "/etc/letsencrypt/live/$domdir/privkey.pem"; my $cafile = "/etc/letsencrypt/live/$domdir/chain.pem"; my $certdata; my $keydata; my $cadata; open(my $certfh, '<', $certfile) or die "cannot open file $certfile\n"; { local $/; $certdata = <$certfh>; } close($certfh); open(my $keyfh, '<', $keyfile) or die "cannot open file $keyfile\n"; { local $/; $keydata = <$keyfh>; } close($keyfh); open(my $cafh, '<', $cafile) or die "cannot open file $cafile\n"; { local $/; $cadata = <$cafh>; } close($cafh); my $cert = uri_escape($certdata); my $key = uri_escape($keydata); my $ca = uri_escape($cadata); print "Installing SSL on cPanel services ...\n"; # Install the SSL cert print "Attempting to install the SSL certificate to WHM...\n"; my $request = HTTP::Request->new( POST => "https://127.0.0.1:2087/json-api/installssl?api.version=1&domain=$dom&crt=$cert&key=$key&cab=$ca" ); $request->header( Authorization => $auth ); my $response = $ua->request($request); #print $response->content; # Install the SSL certificate for the FTP service print "\n\nAttempting to install the SSL certificate for the FTP service...\n"; my $request = HTTP::Request->new( POST => "https://127.0.0.1:2087/json-api/install_service_ssl_certificate?api.version=1&service=ftp&crt=$cert&cabundle=$ca&key=$key" ); $request->header( Authorization => $auth ); my $response = $ua->request($request); #print $response->content; # Install the SSL certificate for the exim service print "\n\nAttempting to install the SSL certificate for the exim service...\n"; my $request = HTTP::Request->new( POST => "https://127.0.0.1:2087/json-api/install_service_ssl_certificate?api.version=1&service=exim&crt=$cert&cabundle=$ca&key=$key" ); $request->header( Authorization => $auth ); my $response = $ua->request($request); #print $response->content; # Install the SSL certificate for the dovecot service print "\n\nAttempting to install the SSL certificate for the dovecot service...\n"; my $request = HTTP::Request->new( POST => "https://127.0.0.1:2087/json-api/install_service_ssl_certificate?api.version=1&service=dovecot&crt=$cert&cabundle=$ca&key=$key" ); $request->header( Authorization => $auth ); my $response = $ua->request($request); #print $response->content; # Install the SSL certificate for the cpanel service print "\n\nAttempting to install the SSL certificate for the cpanel service...\n"; my $request = HTTP::Request->new( POST => "https://127.0.0.1:2087/json-api/install_service_ssl_certificate?api.version=1&service=cpanel&crt=$cert&cabundle=$ca&key=$key" ); $request->header( Authorization => $auth ); my $response = $ua->request($request); #print $response->content; system("service cpanel restart") # Install the SSL certificate for the courier service # NOTE: They removed the Courier mail server in cPanel & WHM version 54. # The Courier mail server only exists for cPanel & WHM version 11.52 and earlier. # If we try install the SSL cert for courier on a cPanel & WHM version 54 server, # the system returns the following message: # courier is not a known service. # This script should not cause any problems though, even if courier isn't installed. #print "\n\nAttempting to install the SSL certificate for the courier service...\n"; #my $request = HTTP::Request->new( POST => "https://127.0.0.1:2087/json-api/install_service_ssl_certificate?api.version=1&service=courier&crt=$cert&cabundle=$ca&key=$key" ); #$request->header( Authorization => $auth ); #my $response = $ua->request($request); #print $response->content;