Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement] Add curl cacert capath options #134 #135

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions openwisp-monitoring/files/monitoring.agent
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ show_help() {
printf " --uuid <uuid>\t\t\t\t: UUID of the device.\n"
printf " --key <key>\t\t\t\t: Key for the device.\n"
printf " --verify_ssl <0, 1>\t\t\t: Whether SSL Authentication should be enabled or not.\n"
printf " --cacert <file>\t\t\t: Value passed to curl --cacert argument.\n"
printf " --capath <directory>\t\t\t: Value passed to curl --capath argument.\n"
printf "OpenWISP Monitoring Config options:\n"
printf " --interval <time>\t\t\t: Time in seconds after which data should be sent/collected.\n"
printf " --monitored-interfaces <interfaces>\t: Interfaces that needs to be monitored.\n"
Expand Down Expand Up @@ -86,6 +88,8 @@ set_url_and_curl() {
# shellcheck disable=SC1083
CURL_COMMAND="curl -s -w "%{http_code}" --output $RESPONSE_FILE"
[ "$VERIFY_SSL" -eq "0" ] && CURL_COMMAND="$CURL_COMMAND -k"
[ -n "$CACERT" ] && CURL_COMMAND="$CURL_COMMAND --cacert $CACERT"
[ -n "$CAPATH" ] && CURL_COMMAND="$CURL_COMMAND --capath $CAPATH"
[ "$VERBOSE_MODE" -eq "1" ] && CURL_COMMAND="$CURL_COMMAND -v"
MAX_RETRIES=${MAX_RETRIES:-5}
FAILING=0
Expand Down Expand Up @@ -281,6 +285,14 @@ main() {
export VERIFY_SSL="$2"
shift
;;
--capath)
export CAPATH="$2"
shift
;;
--cacert)
export CACERT="$2"
shift
;;
--interval)
export INTERVAL="$2"
shift
Expand Down
6 changes: 5 additions & 1 deletion openwisp-monitoring/files/monitoring.init
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ start_service() {
config_get base_url http url
config_get uuid http uuid
config_get key http key
config_get cacert http cacert
config_get capath http capath
config_get_bool verify_ssl http verify_ssl "1"
config_get respawn_threshold http respawn_threshold
config_get respawn_timeout http respawn_timeout
Expand All @@ -37,6 +39,8 @@ start_service() {
[ -n "$base_url" ] && base_url="--url $base_url"
[ -n "$uuid" ] && uuid="--uuid $uuid"
[ -n "$key" ] && key="--key $key"
[ -n "$cacert" ] && cacert="--cacert $cacert"
[ -n "$capath" ] && capath="--capath $capath"
[ -n "$verify_ssl" ] && verify_ssl="--verify_ssl $verify_ssl"

if [ -z "$base_url" ]; then
Expand Down Expand Up @@ -77,7 +81,7 @@ start_service() {

procd_open_instance "openwisp-monitoring_send_data"
# shellcheck disable=SC2086
procd_set_param command $PROG $base_url $uuid $key $verify_ssl $interval $verbose $max_retries $bootup_delay --mode send
procd_set_param command $PROG $base_url $uuid $key $cacert $capath $verify_ssl $interval $verbose $max_retries $bootup_delay --mode send
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
[ "$verbose_mode" -eq "1" ] && procd_set_param stdout 1 && procd_set_param stderr 1
procd_close_instance
Expand Down
Loading