@ -12,11 +12,6 @@ slacksitename="" # Title of site "Example Site
slackchannel = "" # Slack Channel #example
slackuri = "" # URI for Slack WebHook "https://hooks.slack.com/services/xxxxx"
#tolerant_is_set=0
top_exit_code = -1;
#argument_total=$#
#tolerant_is_set=false;
debug_output_echo ( ) {
if [ ! -z $debug_mode_active ] ; then
if [ $debug_mode_active -eq 1 ] ; then
@ -24,7 +19,11 @@ debug_output_echo () {
fi
fi
}
exit_code ( ) {
if [ -z $top_exit_code ] ; then
top_exit_code = -999
fi
if [ $top_exit_code -lt $excode ] ; then
top_exit_code = $excode
fi
@ -32,7 +31,7 @@ exit_code () {
if [ $tolerant_is_set -eq 1 ] ; then
# Only when tolerent mode is active, it will not stop for error
logger_output = " DDNS Updater: in tolerant mode - exit [ $excode ] "
debug_output += $logger_output "\n"
debug_output += $logger_output "\n"
logger $logger_output
else
#It strict mode it will stap instantly on error
@ -57,7 +56,7 @@ cf_ddns_ip () {
fi
}
cf_ddns_authheader ( ) {
cf_ddns_authheader ( ) {
###########################################
## Check and set the proper auth header
###########################################
@ -179,20 +178,30 @@ cf_ddns() {
fi
fi
}
cf_parameter_commands ( ) {
case " $parameter_current " in
"-debug" )
debug_mode_active = 1
; ;
"-help" )
echo "# crontab\n"
echo "*/5 * * * * /bin/bash /home/user/cloudflare-ddns-updater/cloudflare-init.sh"
echo '*/5 * * * * /bin/bash /home/user/cloudflare-ddns-updater/cloudflare-init.sh mydomain.com example.com www.example.com x1.example.com'
echo -e $output_help
; ;
*)
echo "Unknown ***************************"
; ;
case ${ parameter_current : 1 } in
"debug" )
debug_mode_active = 1
; ;
"help" )
echo "# crontab\n"
echo "*/5 * * * * /bin/bash /home/user/cloudflare-ddns-updater/cloudflare-init.sh"
echo '*/5 * * * * /bin/bash /home/user/cloudflare-ddns-updater/cloudflare-init.sh mydomain.com example.com www.example.com x1.example.com'
echo -e "\nAdd in -tolerant option that get continue if when reason to exit, this should be first parameter\n"
echo -e $output_help
; ;
"tolerant" )
tolerant_is_set = 1
logger_output = "DDNS Updater: Been set as being tolerant"
debug_output += $logger_output "\n"
logger $logger_output
; ;
*)
logger_output = " DDNS Updater: invalid parameter option been defined [ ${ parameter_current } ] "
debug_output += $logger_output "\n"
logger -s $logger_output
; ;
esac
}
@ -202,35 +211,30 @@ cf_err_human () {
if [ ${# auth_email } -eq 0 ] ; then
err_is_human = 1
logger_output = "DDNS Updater: ERROR [auth_email] record not been defined"
debug_output += $logger_output "\n"
logger -s $logger_output
fi
if [ $auth_method != "token" ] && [ $auth_method != "global" ] ; then
err_is_human = 1
logger_output = 'DDNS Updater: ERROR [auth_method] is invaled it has to be defined "token" "global" defined'
debug_output += $logger_output "\n"
logger -s $logger_output
fi
if [ ${# auth_key } -eq 0 ] ; then
err_is_human = 1
logger_output = "DDNS Updater: ERROR [auth_key] record not been defined"
debug_output += $logger_output "\n"
logger -s $logger_output
fi
if [ ${# zone_identifier } -eq 0 ] ; then
err_is_human = 1
logger_output = "DDNS Updater: ERROR [zone_identifier] record has not been defined"
debug_output += $logger_output "\n"
logger -s $logger_output
fi
if [ ${# record_name } -eq 0 ] && [ $argument_total -eq 0 ] ; then
err_is_human = 1
logger_output = "DDNS Updater: ERROR [record_name] record not has been defined"
debug_output += $logger_output "\n"
logger -s $logger_output
fi
@ -242,31 +246,26 @@ cf_err_human () {
if [ $tolerant_is_set -lt 0 ] || [ $tolerant_is_set -gt 1 ] ; then
err_is_human = 1
logger_output = "DDNS Updater: ERROR [tolerant_is_set] can only by 0 or 1"
debug_output += $logger_output "\n"
logger -s $logger_output
fi
if [ $err_is_human -eq 1 ] ; then
#It is done this way so all errors get disclosed
debug_output_echo
#It is done if there is error detected above
exit 1
fi
}
argument_total = $#
tolerant_is_set = 1
#top_exit_code=-999
debug_output = ""
cf_err_human
if [ $# -ne 0 ] ; then
# If a parameter has been defined in will ignore any setting in [record_name]
parameter = ( " $@ " )
for ( ( argument_depth = 0 ; argument_depth < argument_total ; argument_depth++ ) ) ; do
parameter_current = ${ parameter [argument_depth] }
first_character = ${ parameter_current : 0 : 1 }
first_character = ${ parameter_current : 0 : 1 }
if [ $first_character = "-" ] ; then
cf_parameter_commands
else
@ -278,5 +277,6 @@ else
# If no parameter been used it will use one above [record_name]
cf_ddns
fi
debug_output_echo
exit $err_is_human