This commit is contained in:
Eliezer Croitoru 2021-07-19 14:02:36 +03:00
parent 5eb0cc7d72
commit 9c9f7f373e
9 changed files with 113 additions and 32 deletions

7
add-autogen-crons.sh Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
CRON_FILE="/pfrm2.0/etc/crontabs/root"
bash remove-autogen-crons.sh
bash gen-cron-line.sh |tee -a "${CRON_FILE}" >/dev/null

View File

@ -1 +1 @@
https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/020-BlockList.dstdom
http://gogs.ngtech.home/elicro/cp-tls-inspection-application-update-cron/raw/master/020-BlockList.dstdom

View File

@ -1,47 +1,104 @@
#!/usr/bin/env bash
SCRIPT_MD5_SUM=$(md5sum cron-example-with-diff-dstdom.sh|awk '{print $1}')
SCRIPT_URL="https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/cron-example-with-diff-dstdom.sh"
DST_DOMAIN_LIST_URL=$(head -1 dst-domain-url)
APP_NAME="NgTechBypassDstDomain"
SCRIPT_PATH="/storage/cron-example-with-diff-dstdom.sh"
function printTopHeader() {
echo "####### NFGW Auto Genereated CRONS START MARK $(date)"
}
export CA_CERT_BUNDLE_PATH="/pfrm2.0/opt/fw1/bin/ca-bundle.crt"
export SSL_CERT_FILE="${CA_CERT_BUNDLE_PATH}"
#alias curl_cli="curl_cli --cacert ${CA_CERT_BUNDLE_PATH}"
function printButtomHeader() {
echo "####### NFGW Auto Genereated CRONS END MARK $(date)"
}
CA_CERT_BUNDLE_PATH="/pfrm2.0/opt/fw1/bin/ca-bundle.crt"
SSL_CERT_FILE="${CA_CERT_BUNDLE_PATH}"
echo "####"
echo
export CA_CERT_BUNDLE_PATH
export SSL_CERT_FILE
SCRIPT_TMP_PATH="/tmp/cron-example-with-diff-dstdom.sh_73ffe3f6-b85a-46ed-9e11-07865339759c"
echo "*/5 * * * * (/usr/bin/md5sum ${SCRIPT_PATH} | /bin/grep \"^${SCRIPT_MD5_SUM} \") || (curl_cli --cacert ${CA_CERT_BUNDLE_PATH} -s ${SCRIPT_URL} -o ${SCRIPT_TMP_PATH} >/dev/null 2>&1 && /usr/bin/md5sum ${SCRIPT_TMP_PATH} |/bin/grep \"^${SCRIPT_MD5_SUM} \" && mv ${SCRIPT_TMP_PATH} ${SCRIPT_PATH} )"
GOGS_GIT_PREFIX=$( cat gogs_url_prefix )
GITHUB_GIT_PREFIX=$( cat github_url_prefix )
GIT_PREFIX=""
if [ -f "use-gogs" ];then
GIT_PREFIX="${GOGS_GIT_PREFIX}"
else
GIT_PREFIX="${GITHUB_GIT_PREFIX}"
fi
echo "####"
echo
echo "*/5 * * * * su - admin -c \"/bin/bash ${SCRIPT_PATH} ${APP_NAME} ${DST_DOMAIN_LIST_URL} >/dev/null 2>&1\""
DST_DOM_SCRIPT_URL="${GIT_PREFIX}/cron-example-with-diff-dstdom.sh"
DST_DOM_SCRIPT_MD5_SUM=$(md5sum cron-example-with-diff-dstdom.sh|awk '{print $1}')
DST_DOM_SCRIPT_PATH="/storage/cron-example-with-diff-dstdom.sh"
DST_SCRIPT_TMP_PATH="/tmp/cron-example-with-diff-dstdom.sh_73ffe3f6-b85a-46ed-9e11-07865339759c"
echo "####"
echo
function createScriptUpdateCron() {
SCRIPT_PATH="$1"
SCRIPT_MD5_SUM="$2"
SCRIPT_URL="$3"
SCRIPT_TMP_PATH="$4"
echo "#### Update Cron for the script: \"${SCRIPT_PATH}\""
echo
DST_DOMAIN_LIST_URL=$(head -1 block-list-dst-domain-url)
APP_NAME="NgTechBlockListDstDomain"
echo "*/1 * * * * su - admin -c \"/bin/bash ${SCRIPT_PATH} ${APP_NAME} ${DST_DOMAIN_LIST_URL} >/dev/null 2>&1\""
echo "*/5 * * * * (/usr/bin/md5sum ${SCRIPT_PATH} | /bin/grep \"^${SCRIPT_MD5_SUM} \") || (curl_cli --cacert ${CA_CERT_BUNDLE_PATH} -s ${SCRIPT_URL} -o ${SCRIPT_TMP_PATH} >/dev/null 2>&1 && /usr/bin/md5sum ${SCRIPT_TMP_PATH} |/bin/grep \"^${SCRIPT_MD5_SUM} \" && mv ${SCRIPT_TMP_PATH} ${SCRIPT_PATH} )"
echo
echo "####"
echo
}
SCRIPT_MD5_SUM=$(md5sum collect-clish-scripts.sh|awk '{print $1}')
SCRIPT_URL="https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/collect-clish-scripts.sh"
SCRIPT_PATH="/storage/collect-clish-scripts.sh"
SCRIPT_TMP_PATH="/tmp/collect-clish-scripts.sh_73ffe3f6-b85a-46ed-9e11-07865339759c"
function createListUpdateCron() {
SCRIPT_PATH="$1"
APP_NAME="$2"
DST_DOMAIN_LIST_URL="$3"
echo "####"
echo
echo "#### Update Cron for the FW APP: \"${APP_NAME}\""
echo
echo "*/5 * * * * (/usr/bin/md5sum ${SCRIPT_PATH} | /bin/grep \"^${SCRIPT_MD5_SUM} \") || (curl_cli --cacert ${CA_CERT_BUNDLE_PATH} -s ${SCRIPT_URL} -o ${SCRIPT_TMP_PATH} >/dev/null 2>&1 && /usr/bin/md5sum ${SCRIPT_TMP_PATH} |/bin/grep \"^${SCRIPT_MD5_SUM} \" && mv ${SCRIPT_TMP_PATH} ${SCRIPT_PATH} )"
echo "*/5 * * * * su - admin -c \"/bin/bash ${SCRIPT_PATH} ${APP_NAME} ${DST_DOMAIN_LIST_URL} >/dev/null 2>&1\""
echo "####"
echo
echo
echo "####"
echo
}
echo "*/30 * * * * su - admin -c \"/bin/bash ${SCRIPT_PATH} >/dev/null 2>&1\""
function createRunScriptAsCron() {
USER="$1"
SCRIPT_PATH="$2"
ALLOW_STDOUT="$3"
echo "#### Run Cron AS USER: ${USER}"
echo
if [ "${ALLOW_STDOUT}" -gt "0" ];then
echo "*/30 * * * * su - ${USER} -c \"/bin/bash ${SCRIPT_PATH} >/dev/null 2>&1\""
else
echo "*/30 * * * * su - ${USER} -c \"/bin/bash ${SCRIPT_PATH}\""
fi
echo
echo "####"
echo
}
printTopHeader
createScriptUpdateCron "${DST_DOM_SCRIPT_PATH}" "${DST_DOM_SCRIPT_MD5_SUM}" "${DST_DOM_SCRIPT_URL}" "${DST_SCRIPT_TMP_PATH}"
COLLECT_CLISH_SCRIPT_PATH="/storage/collect-clish-scripts.sh"
COLLECT_CLISH_SCRIPT_MD5_SUM=$(md5sum collect-clish-scripts.sh|awk '{print $1}')
COLLECT_CLISH_SCRIPT_URL="${GIT_PREFIX}collect-clish-scripts.sh"
COLLECT_CLISH_SCRIPT_TMP_PATH="/tmp/collect-clish-scripts.sh_73ffe3f6-b85a-46ed-9e11-07865339759c"
createScriptUpdateCron "${COLLECT_CLISH_SCRIPT_PATH}" "${COLLECT_CLISH_SCRIPT_MD5_SUM}" "${COLLECT_CLISH_SCRIPT_URL}" "${COLLECT_CLISH_SCRIPT_TMP_PATH}"
NgTechBypassDstDomain_APP_NAME="NgTechBypassDstDomain"
NgTechBypassDstDomain_LIST_URL=$( head -1 ngtech-bypass-dstdomains-list-url )
createListUpdateCron "${DST_DOM_SCRIPT_PATH}" "${NgTechBypassDstDomain_APP_NAME}" "${NgTechBypassDstDomain_LIST_URL}"
NgTechBlockListDstDomain_APP_NAME="NgTechBlockListDstDomain"
NgTechBlockListDstDomain_LIST_URL=$(head -1 block-list-dst-domain-url)
createListUpdateCron "${DST_DOM_SCRIPT_PATH}" "${NgTechBlockListDstDomain_APP_NAME}" "${NgTechBlockListDstDomain_LIST_URL}"
printButtomHeader

View File

@ -1,7 +1,16 @@
#!/usr/bin/env bash
SCRIPT_MD5_SUM=$( md5sum collect-clish-scripts-daemon.sh |awk '{print $1}' )
SCRIPT_URL="https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/collect-clish-scripts-daemon.sh"
GOGS_GIT_PREFIX=$( cat gogs_url_prefix )
GITHUB_GIT_PREFIX=$( github_url_prefix )
if [ -f "use-gogs" ];then
SCRIPT_URL="${GOGS_GIT_PREFIX}collect-clish-scripts-daemon.sh"
else
SCRIPT_URL="${GITHUB_GIT_PREFIX}collect-clish-scripts-daemon.sh"
fi
SCRIPT_PATH="/storage/collect-clish-scripts-daemon.sh"
USERSCRIPT_PATH="/pfrm2.0/etc/userScript"
LOCK_FILE="/tmp/clish-scripts-collector-cron-lockfile"

1
github_url_prefix Normal file
View File

@ -0,0 +1 @@
https://raw.githubusercontent.com/elico/cp-tls-inspection-application-update-cron/master/

1
gogs_url_prefix Normal file
View File

@ -0,0 +1 @@
http://gogs.ngtech.home/elicro/cp-tls-inspection-application-update-cron/raw/master/

View File

@ -0,0 +1 @@
http://gogs.ngtech.home/elicro/cp-tls-inspection-application-update-cron/raw/master/010-GeneralTLSInspectionBypass.dstdom

5
remove-autogen-crons.sh Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
CRON_FILE="/pfrm2.0/etc/crontabs/root"
sed -i -n '/^####### NFGW Auto Genereated CRONS START MARK/{p; :a; N; /####### NFGW Auto Genereated CRONS END MARK/!ba; s/.*\n//}; p' |sed -e "s@^####### NFGW Auto Genereated CRONS START MARK.*@@g" -e "s@^####### NFGW Auto Genereated CRONS END MARK.*@@g" "${CRON_FILE}"

0
use-gogs Normal file
View File