sslsshcpanelcrt

how to export cab crt , key from uapi command result


use custom setup that use nginx as web engine with cpanel need command to export ssl files to use it into nginx

cpanel now use AutoSSL powered by Comodo that give it free and will renew it automatic when any users domains ssl expire

at easyApache4

by this command

uapi --user=example SSL fetch_best_for_domain domain='example.com'

i can fetch ssl from cpanel for selected user

result

--- 
apiversion: 3
func: fetch_best_for_domain
module: SSL
result: 
  data: 
    cab: "-----BEGIN CERTIFICATE-----\nMIIF8TCCA9mgAwIBAgIRAPAdS+57fKN7PAVmrAWXJFgwDQYJKoZIhvcNAQEMBQAwgYUxCzAJBgNV\nBAYTAkdCMRswGQYDTE1MDUxODAwMDAwMFoXDTI1MDUxNzIzNTk1OVowcjELMAkGA2qXcmH5Qo\nk+kTPUXROjVIHpgNgnDAC1ooh6F4UT+1p1ymkSIAQky5gBWAKrEtiU/3uh4YxIxZHnNJo6h7vB/3\nVk1Qn2cWp8cXSOdtVFd2bpdYW3hkpO1itAA7Bn55uFhfboTWQ7xP2zmqKPDBiQnF++MYRLflsotd\nlfkjWgty92k61leL4en0YL7EUSsRrP5Is3JzyhNQcw0EdsoB4ULC1yHP+Q==\n-----END CERTIFICATE-----\n-----BEGIN CERTIFICATE-----\nMIIFfjCCBGagAwIBAgIQZ970PvF72uJP9ZQGBtLAhDANBgkqhkiG9w0BAQwFADB7MQswCQYDVQQG\nEwJHQjEbMBkGA1UECAwSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHDAdTYWxmb3JkMRowGAYD\nVQQKDBFDb21vgrBgEFBQcwAYYYaHR0cDovL29jc3AuY29tb2RvY2EuY29tMA0GCSqG\nSIb3DQEBDAUAA4IBAQB/8lY1sG2VSk50rzribwGLh9Myl+34QNJ3UxHXxxYuxp3mSFa+gKn4vHjS\nyGMXroztFjH6HxjJDsfuSHmfx8m5vMyIFeNoYdGfHUthgddWBGPCCGkm8PDlL9/ACiupBfQCWmqJ\n17SEQpXj6/d2IF412cDNJQgTTHE4joewM4SRmR6R8ayeP6cdYIEsNkFUoOJGBgusG8eZNoxeoQuk\nntlCRiTFxVuBrq2goNyfNriNwh0V+oitgRA5H0TwK5/dEFQMBzSxNtEU/QcCPf9yVasn1iyBQXEp\njUH0UFcafmVgr8vFKHaYrrOoU3aL5iFSa+oh0IQOSU6IU9qSLucdCGbX\n-----END CERTIFICATE-----"
    crt: "-----BEGIN CERTIFICATE-----\nMIIGYzCCBUugAwIBAgIQAxTDyiRh8b1+CgQUhztu1TANBgkqhkiG9w0BAQsFADBy\nMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVFgxEDAOBgNVBAcTB0hvdXN0b24xFTAT\nBgNVBAoTDGNQYW5lbCwgSW5jLjEtMCsGASchcwat43LiRWlaxA6\ne+xEjtg0WqTmZ+QulFzZo0c/mfsAkBJyICuoZ/poop2YPou9qgAN6WoemTO6HidoQQ3PlsVyZL\nqBrIW9kege5OPQUTAQIYvesHzdu5HIi00SJsGpnnq+HiFQ9tpcKBDPJiKQIxw6Ec\nYkk/aFbMa8wv577v5Fwo6EUihI7IFMIcoD2+QB7KZrUkl5Skrux7Z5vyyppssSRQ\ne30BKIWZMA1XikFWTKJNB4dN+XrAufc26GzHLmAsi5sTl+UDkqAJ9ubI1LUf9jGY\nwvtL1zy4eCslP4p83fCzB4dc/w7jlsQKaM7BDraSMfnYFDhBhx9QfdjDR8P03ZyG\n4XQJGMLHIA==\n-----END CERTIFICATE-----"
    crt_origin: example
    domain: example.com
    ip: 127.0.0.1
    key: "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAw2OGUfz3smlHcSYH7/ld6WZxk0j0dHK37BfIcVM4zkGcwXUC\nXCiMW3MfqQvA+pZ8AFEtQYLpSfdra/nRvFjvaRzgcbM2ORzUnIXMGreNy4kVpWsQ\nOnvsRI7YNFqk5mfkLpRc2aNHP5n7AJASciArqGf6aKKdmAKC3nNdlMvdWZiomglK\netnPfVLs/pZdXdPAVcIOuBwTzkc3xWFL9nD2YljWLX0IUtlgwCzo2io+Dv+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nr/5GBGnBO2YrvEOdIY6hcvAnYtnJWaCMGovgr+rd1eNfqUB72wcBP4nDLju83EMn\nvz2eyQKBgQDKXUrupETlv26uDRwumo1r+k6WAVRbQFDCc45K9PQT9aMY8bRQRhiN\n3r3jEZcygdDeyGD/x6MrApu9giFR2m8t/XOSvxPelY3WEdADFnkJyom/hUAG/zhp\nSL0byAyOzBv5ny6FiBdg9HrSZ6olYRDHVCFsS8+hQznVkGT84MzUjA==\n-----END RSA PRIVATE KEY-----"
    key_origin: example
    searched_users: 
      - example
    status: 1
    statusmsg: ok
    user: example
  errors: ~
  messages: ~
  metadata: {}

  status: 1
  warnings: ~

looking for way to export cab , crt and key as files after run this command


there old way with easyApache 3 at this url

Old steps


Solution

  • i have 11 hours searches and looking

    i build that script and working good with nginx

    am happy to share it with you

        RESULTS=$( uapi --user=example SSL fetch_best_for_domain domain='example.com' )
        
        FIRST=`echo $RESULTS| awk -F \" '{print $2}'`
        SECOND=`echo $RESULTS| awk -F \" '{print $4}'`
        THIRD=`echo $RESULTS| awk -F \" '{print $6}'`
    
    
    echo $FIRST | sed 's/\\n/\n/g' > /root/s.example.com.cab
    
    echo $SECOND | sed 's/\\n/\n/g' > /root/s.example.com.crt
    
    
    echo $THIRD | sed 's/\\n/\n/g' > /root/s.example.com.key
    
    
    cat /root/s.example.com.crt /root/s.example.com.cab > /root/s.example.com.cert
    
    
    rm -rf /root/s.example.com.cab /root/s.example.com.crt