# HTTPS POST MADE NOT-SO-EASY # Command line HTTPS POST for installing a certificate and key using cPanel 'install_ssl' # # NOTE: While it is possible to HTTP/HTTPS POST from the command line, it is highly recommended to use a script instead. # Below is one example, using the Perl HTTP::Request::Common object: # http://search.cpan.org/~ether/HTTP-Message-6.11/lib/HTTP/Request/Common.pm # ... # POST '/execute/SSL/install_ssl', # Host: ${CPANEL_HOST}\ # Authorization: Basic ${CPANEL_USERPW} # Content_Type => 'form-data', # Content => [ # domain => $domain, # cert => $cert, # key => $key, # ] # ... # # When we HTTP/HTTPS POST from the command line, we have to calculate the Content-Length manually. # To get the Content-Length using Emacs: # # 1. Set Emacs cursor on the blank line below the last HTTP Header field (the line after Content-Type in our example) # Content-Type: multipart/form-data # <--- # # 2. Mark region # # 3. Go to end of line of last line (after last character in last separator text) # M-x count-words-region # 5554 # # 4. Fill in the value: Content-Length: 5554 # # -------------------------------------------------------------------------------------- # 1. Copy the text below the separator line to a new text file. # 2. Replace YOUR-CPANEL-HOSTNAME, YOUR-CPANEL-USERNAME, YOUR-CPANEL-PASSWORD, YOUR-DOMAIN, YOUR-CERT, YOUR-KEY # 3. Calculate the Content-Length as described above, and replace YOUR-CONTENT-LENGTH with the calculated number # 4. Type the text "as is" in a sh/bash compatible shell. # 5. Check the output, saved in 'install_ssl.response.txt'. # -------------------------------------------------------------------------------------- export PERL_LWP_SSL_VERIFY_HOSTNAME=0 export CPANEL_HOST=YOUR-CPANEL-HOSTNAME export CPANEL_USERPW=`echo -n YOUR-CPANEL-USERNAME:YOUR-CPANEL-PASSWORD | openssl base64 -A` printf "POST /execute/SSL/install_ssl HTTP/1.1 Host: ${CPANEL_HOST} Authorization: Basic ${CPANEL_USERPW} Content-Length: YOUR-CONTENT-LENGTH Content-Type: multipart/form-data; boundary="6G+f" --6G+f Content-Disposition: form-data; name="domain" YOUR-DOMAIN --6G+f Content-Disposition: form-data; name="cert" -----BEGIN CERTIFICATE----- YOUR-CERT -----END CERTIFICATE----- --6G+f Content-Disposition: form-data; name="key" -----BEGIN RSA PRIVATE KEY----- YOUR-KEY -----END RSA PRIVATE KEY----- --6G+f --6G+f--" | \ openssl s_client -connect ${CPANEL_HOST}:2083 -ign_eof 2>/dev/null > install_ssl.response.txt