Skip to content

Commit

Permalink
[curl] Added curl_interface option #30
Browse files Browse the repository at this point in the history
Improves #30
  • Loading branch information
nemesifier committed Apr 11, 2017
1 parent e5ffac2 commit c553549
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ UCI configuration options must go in ``/etc/config/openwisp``.
- ``connect_timeout``: value passed to curl ``--connect-timeout`` argument, defaults to ``15``; see `curl connect-timeout argument <https://curl.haxx.se/docs/manpage.html#--connect-timeout>`_
- ``max_time``: value passed to curl ``--max-time`` argument, defaults to ``30``; see `curl connect-timeout argument <https://curl.haxx.se/docs/manpage.html#-m>`_
- ``mac_interface``: the interface from which the MAC address is taken when performing automatic registration, defaults to ``eth0``
- ``curl_interface``: the value passed to curl ``--interface`` argument, it may have 3 different type of values:
- ``0``: disabled (default value)
- ``1``: enabled and automatically uses the value of the ``interface`` option
- ``<interface_name>``: explicit interface name, eg: ``br-wan``
- ``pre_reload_hook``: path to custom executable script, see `pre-reload-hook`_

Automatic registration
Expand Down
1 change: 1 addition & 0 deletions openwisp-config/files/openwisp-nossl.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ config controller 'http'
#option max_time '30'
#option capath '/etc/ssl/certs'
#option cacert '/etc/ssl/certs/ca-certificates.crt'
#option curl_interface '0'
# hooks
#option pre_reload_hook '/usr/sbin/my_pre_reload_hook'
1 change: 1 addition & 0 deletions openwisp-config/files/openwisp-ssl.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ config controller 'http'
#option max_time '30'
#option capath '/etc/ssl/certs'
#option cacert '/etc/ssl/certs/ca-certificates.crt'
#option curl_interface '0'
# hooks
#option pre_reload_hook '/usr/sbin/my_pre_reload_hook'
10 changes: 9 additions & 1 deletion openwisp-config/files/openwisp.agent
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ while [ -n "$1" ]; do
--capath) export CAPATH="$2"; shift;;
--cacert) export CACERT="$2"; shift;;
--mac-interface) export MAC_INTERFACE="$2"; shift;;
--curl-interface) export CURL_INTERFACE="$2"; shift;;
--pre-reload-hook) export PRE_RELOAD_HOOK="$2"; shift;;
-*)
echo "Invalid option: $1"
Expand Down Expand Up @@ -69,7 +70,7 @@ STATUS_REPORT="$WORKING_DIR/status_report"
APPLYING_CONF="$WORKING_DIR/applying_conf"
REGISTRATION_URL="$URL/controller/register/"
UNMANAGED_DIR="$WORKING_DIR/unmanaged"
FETCH_COMMAND="curl -s --connect-timeout $CONNECT_TIMEOUT --max-time $MAX_TIME --interface $MAC_INTERFACE"
FETCH_COMMAND="curl -s --connect-timeout $CONNECT_TIMEOUT --max-time $MAX_TIME"
mkdir -p $WORKING_DIR
mkdir -p $UNMANAGED_DIR

Expand All @@ -84,6 +85,13 @@ else
fi
fi

if [ "$CURL_INTERFACE" == "1" ]; then
CURL_INTERFACE="$MAC_INTERFACE"
fi
if [ -n "$CURL_INTERFACE" ] && [ "$CURL_INTERFACE" != "0" ]; then
FETCH_COMMAND="$FETCH_COMMAND --interface $CURL_INTERFACE"
fi

if [ -n "$UNMANAGED" ]; then
# replace commas with spaces
UNMANAGED=$(echo $UNMANAGED | tr ',' ' ')
Expand Down
4 changes: 3 additions & 1 deletion openwisp-config/files/openwisp.init
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ start_service() {
capath=$(config_get http capath)
cacert=$(config_get http cacert)
mac_interface=$(config_get http mac_interface)
curl_interface=$(config_get http curl_interface)
pre_reload_hook=$(config_get http pre_reload_hook)
if [ $url ]; then url="--url $url"; fi
if [ $interval ]; then interval="--interval $interval"; fi
Expand All @@ -46,6 +47,7 @@ start_service() {
if [ $capath ]; then capath="--capath $capath"; fi
if [ $cacert ]; then cacert="--cacert $cacert"; fi
if [ $mac_interface ]; then mac_interface="--mac-interface $mac_interface"; fi
if [ $curl_interface ]; then curl_interface="--curl-interface $curl_interface"; fi
if [ $pre_reload_hook ]; then pre_reload_hook="--pre-reload-hook $pre_reload_hook"; fi

if [ -z "$url" ]; then
Expand All @@ -66,7 +68,7 @@ start_service() {
procd_set_param command $PROG $url $interval $verify_ssl $uuid $key $shared_secret \
$consistent_key $unmanaged $merge_config $test_config \
$test_script $connect_timeout $max_time $capath $cacert \
$mac_interface $pre_reload_hook
$mac_interface $curl_interface $pre_reload_hook
procd_set_param respawn
procd_close_instance
logger -s "$PROG_NAME started" \
Expand Down

0 comments on commit c553549

Please sign in to comment.