From af197cb559bfc86b8eba332bcf20d17aa2dc70f8 Mon Sep 17 00:00:00 2001 From: Stuart Cardall Date: Wed, 20 Sep 2017 13:36:15 +0000 Subject: [PATCH 1/4] update-ngxblocker: detect /bin/mail in centos / add -m cmd line switch for mail * also detect /bin/mail in centos * adds -m command line switch to specify an email address (to avoid confusion with -e used in setup-ngxblocker to specify vhost file extensions) -e can still be used to specify an email address to avoid breakage with current cron jobs --- update-ngxblocker | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/update-ngxblocker b/update-ngxblocker index 186a513d7..0f15af31d 100755 --- a/update-ngxblocker +++ b/update-ngxblocker @@ -53,7 +53,7 @@ Usage: $script [OPTIONS] [ -b ] : NGINX bots directory (default: $BOTS_DIR) [ -i ] : Change installer path (default: $INSTALLER) [ -r ] : Change repo url (default: $REPO) - [ -e ] : Change email address (default: $EMAIL) + [ -m ] : Change email address (default: $EMAIL) [ -n ] : Do not send email report (default: $SEND_EMAIL) [ -v ] : Print blacklist version [ -h ] : this help message @@ -194,8 +194,8 @@ check_args() { } check_mail_depends() { - if [ ! -f /usr/bin/mail ]; then # mailx + ssmtp are enough to send emails - printf "${BOLDYELLOW}WARN${RESET}: missing /usr/bin/mail => ${BOLDWHITE}disabling emails${RESET}.\n\n" + if [ ! -f /usr/bin/mail ] && [ ! -f /bin/mail ]; then # mailx + ssmtp are enough to send emails + printf "${BOLDYELLOW}WARN${RESET}: missing mail command => ${BOLDWHITE}disabling emails${RESET}.\n\n" SEND_EMAIL="N" fi } @@ -223,7 +223,7 @@ check_depends() { get_options() { local arg= opts= - while getopts :c:b:u:r:e:nvh opts "$@" + while getopts :c:b:u:r:e:m:nvh opts "$@" do if [ -n "${OPTARG}" ]; then case "$opts" in @@ -239,6 +239,7 @@ get_options() { i) INSTALLER=$arg; check_args $opts script $arg ;; r) REPO=$arg; check_args $opts url $arg ;; e) EMAIL=$arg; check_args $opts email $arg ;; + m) EMAIL=$arg; check_args $opts email $arg ;; n) SEND_EMAIL=N ;; v) check_depends; check_version ;; h) usage ;; From 0b3dcbe86d38d4a50b56da18b5c6e38e66eb27ac Mon Sep 17 00:00:00 2001 From: Stuart Cardall Date: Wed, 20 Sep 2017 13:40:47 +0000 Subject: [PATCH 2/4] update-ngxblocker: remove wget check from check_depends() * downloads are now via curl so remove wget check from check_depends() --- update-ngxblocker | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/update-ngxblocker b/update-ngxblocker index 0f15af31d..6f00937c9 100755 --- a/update-ngxblocker +++ b/update-ngxblocker @@ -201,13 +201,7 @@ check_mail_depends() { } check_depends() { - # centos does not have wget installed by default - if ! wget --help >/dev/null 2>&1; then - printf "${BOLDRED}ERROR${RESET}: $0 requires: 'wget' => ${BOLDWHITE}cannot download files.${RESET}\n" - exit 1 - fi - - # centos also does not have which by default + # centos does not have which by default if [ ! -x /usr/bin/curl ]; then printf "${BOLDRED}ERROR${RESET}: $0 requires: 'curl' => ${BOLDWHITE}cannot check remote version.${RESET}\n" exit 1 From a4e9d4dcdceee87256a0151d8542e3531c183608 Mon Sep 17 00:00:00 2001 From: Stuart Cardall Date: Wed, 20 Sep 2017 13:44:39 +0000 Subject: [PATCH 3/4] install-ngxblocker: add set_mode() * ensure all $SCRIPT_FILES are executable --- install-ngxblocker | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/install-ngxblocker b/install-ngxblocker index 4ebb34a12..2ca0f621c 100755 --- a/install-ngxblocker +++ b/install-ngxblocker @@ -141,6 +141,16 @@ download_files() { fi } +set_mode() { + local mode=$1 dir=$2 file= + local file_list="$(echo $@ | awk '{$1=$2=""; print}' | sed -e 's/^[ \t]*//')" + + for file in $file_list; do + printf "Setting mode: $mode => $dir/$file\n" + chmod $mode $dir/$file + done +} + check_config() { local x= dirs="$*" @@ -283,6 +293,11 @@ main() { download_files conf.d $CONF_DIR $CONF_FILES download_files bots.d $BOTS_DIR $BOT_FILES download_files / $SCRIPT_DIR $SCRIPT_FILES + + # ensures scripts are executable + if [ "$DRY_RUN" = "N" ]; then + set_mode 700 $SCRIPT_DIR $SCRIPT_FILES + fi } ## START ## From 863bf14bab331974379141660a6e67dd18afe407 Mon Sep 17 00:00:00 2001 From: Stuart Cardall Date: Wed, 20 Sep 2017 13:45:25 +0000 Subject: [PATCH 4/4] setup-ngxblocker: improve find_line() detection * adds regex to ignore commented lines in vhost files --- setup-ngxblocker | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup-ngxblocker b/setup-ngxblocker index c84e5527f..366f1b1ad 100755 --- a/setup-ngxblocker +++ b/setup-ngxblocker @@ -186,8 +186,9 @@ find_line() { local file=$1 find_str=$2 first_last=$3 case "$first_last" in - first) awk "/$find_str/{ print NR; exit }" $file;; - last) awk "/$find_str/{ print NR }" $file | tail -n1;; + # ignore file #comments + first) grep -nE "^[ ]+$find_str" $file | head -n1 | awk -F: '{print $1}';; + last) grep -nE "^[ ]+$find_str" $file | tail -n1 | awk -F: '{print $1}';; esac }