daily pastebin goal
67%
SHARE
TWEET

update cgp certificates

a guest Sep 27th, 2017 245 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2.  
  3. use CLI;
  4. use strict;
  5.  
  6. my $server = '127.0.0.1';
  7. my $port = 106;
  8. my $domain = 'maindomain';
  9. my $username = 'postmaster';
  10. my $password = 'password';
  11.  
  12. my $pkeyfile = 'path/to/private.key';
  13. my $certfile = 'path/to/certificate.crt';
  14. my $cafile = 'path/to/chain.crt';
  15.  
  16. my $cli = new CGP::CLI( { PeerAddr => $server,
  17.             PeerPort => $port,
  18.             login    => $username,
  19.             password => $password
  20.             } )
  21.     || die "Can't login to CGPro: ".$CGP::ERR_STRING."\n";
  22.  
  23.  
  24. open(PK, $pkeyfile);
  25. my $pk = join("", <PK>);
  26. close PK;
  27. $pk =~ s/-----BEGIN RSA PRIVATE KEY-----//;
  28. $pk =~ s/-----END RSA PRIVATE KEY-----//;
  29. $pk =~ s/[\r\n]//g;
  30. $pk = "[$pk]";
  31.  
  32. open(PK, $certfile);
  33. my $cert = join("", <PK>);
  34. close PK;
  35. $cert =~ s/-----BEGIN CERTIFICATE-----//;
  36. $cert =~ s/-----BEGIN CERTIFICATE-----//;
  37. $cert =~ s/[\r\n]//g;
  38. $cert = "[$cert]";
  39.  
  40. open(PK, $cafile);
  41. my $ca = join("", <PK>);
  42. close PK;
  43. $ca =~ s/-----BEGIN CERTIFICATE-----//;
  44. $ca =~ s/-----BEGIN CERTIFICATE-----//;
  45. $ca =~ s/[\r\n]//g;
  46. $ca = "[$ca]";
  47.  
  48.  
  49. my $newsettings = {
  50.    "PrivateSecureKey" => $pk,
  51.    "CAChain" => $ca,
  52.    "SecureCertificate" => $cert
  53. };
  54.  
  55. $cli->UpdateDomainSettings(domain=>$domain, settings=>$newsettings) || die "can't update settings: " . $cli->getErrMessage;
  56.  
  57. $cli->Logout;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top