From 690673f38820630371fdc3e13aaa8ae9d1ed38c7 Mon Sep 17 00:00:00 2001 From: Santeri Kannisto Date: Sat, 2 Jun 2018 09:46:55 +0200 Subject: [PATCH] Bug fix for issue #1328 Added private bash function __urlencode to eliminate the php dependency which failed on godaddy due to multiple php instances and cron using the one without -r option. --- deploy/cpanel_uapi.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/deploy/cpanel_uapi.sh b/deploy/cpanel_uapi.sh index 4563b9c4..0df52763 100644 --- a/deploy/cpanel_uapi.sh +++ b/deploy/cpanel_uapi.sh @@ -2,11 +2,25 @@ # Here is the script to deploy the cert to your cpanel using the cpanel API. # Uses command line uapi. --user option is needed only if run as root. # Returns 0 when success. -# Written by Santeri Kannisto +# Written by Santeri Kannisto # Public domain, 2017 #export DEPLOY_CPANEL_USER=myusername +######## Private functions ##################### + +__urlencode() { + __length="${#1}" + for ((_offset = 0; _offset < __length; _offset++)); do + _print_offset="${1:_offset:1}" + case "${_print_offset}" in + [a-zA-Z0-9.~_-]) printf "${_print_offset}" ;; + ' ') printf + ;; + *) printf '%%%X' "'${_print_offset}" ;; + esac + done +} + ######## Public functions ##################### #domain keyfile certfile cafile fullchain @@ -35,8 +49,8 @@ cpanel_uapi_deploy() { # read cert and key files and urlencode both _certstr=$(cat "$_ccert") _keystr=$(cat "$_ckey") - _cert=$(php -r "echo urlencode(\"$_certstr\");") - _key=$(php -r "echo urlencode(\"$_keystr\");") + _cert=$(__urlencode "$_certstr") + _key=$(__urlencode "$_keystr") _debug _cert "$_cert" _debug _key "$_key"