Skip to content

Commit

Permalink
Adds the ability to activate and deactivate networks
Browse files Browse the repository at this point in the history
  • Loading branch information
ogarcia committed Sep 19, 2024
1 parent ddf9b49 commit 43973b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions zerotier/files/etc/config/zerotier
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

config zerotier 'global'
# Sets whether ZeroTier is enabled or not
option enabled 0
option enabled '0'
# Sets the ZeroTier listening port (default 9993; set to 0 for random)
#option port '9993'
# Client secret (leave blank to generate a secret on first run)
Expand All @@ -18,9 +18,12 @@ config zerotier 'global'

# Network configuration, you can have as many configurations as networks you
# want to join (the network name is optional)
config network 'mynet'
config network 'earth'
# Identifier of the network you wish to join
option id '8056c2e21c000001'
# Sets whether this network is enabled or disabled. If it is not
# enabled ZeroTier will not join it.
option enabled '1'
# Network configuration parameters (all are optional, if not indicated the
# default values are set, see documentation at
# https://docs.zerotier.com/config/#network-specific-configuration)
Expand All @@ -32,6 +35,7 @@ config network 'mynet'
# Example of a second network (unnamed as it is optional)
#config network
# option id '1234567890123456'
# option enabled '0'
# option allow_managed '1'
# option allow_global '0'
# option allow_default '0'
Expand Down
6 changes: 4 additions & 2 deletions zerotier/files/etc/init.d/zerotier
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ CONFIG_PATH=/var/lib/zerotier-one

join_network() {
local section="${1}"
local id allow_managed allow_global allow_default allow_dns
local id enabled allow_managed allow_global allow_default allow_dns

config_get id "${section}" 'id'
config_get_bool enabled "${section}" 'enabled' 1
config_get_bool allow_managed "${section}" 'allow_managed' 1
config_get_bool allow_global "${section}" 'allow_global' 0
config_get_bool allow_default "${section}" 'allow_default' 0
config_get_bool allow_dns "${section}" 'allow_dns' 0

if [ -n "${id}" ]; then
if [ -n "${id}" -a ${enabled} -eq 1 ]; then
# an (empty) config file will cause ZT to join a network
touch "${CONFIG_PATH}"/networks.d/"${id}".conf
echo "allowManaged=${allow_managed}" > "${CONFIG_PATH}"/networks.d/"${id}".local.conf
Expand All @@ -41,6 +42,7 @@ start_service() {

if [ ${enabled} -eq 0 ]; then
echo "disabled in /etc/config/zerotier"
return
fi

# Remove existing link or folder
Expand Down

0 comments on commit 43973b8

Please sign in to comment.