Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public function setAction($uuid = null)
$mdlZerotier->serializeToConfig();
Config::getInstance()->save();
$result["result"] = "saved";
$this->setZerotierNetwork($network->networkId, 'allowManaged', $network->allowManaged);
$this->setZerotierNetwork($network->networkId, 'allowGlobal', $network->allowGlobal);
$this->setZerotierNetwork($network->networkId, 'allowDefault', $network->allowDefault);
$this->setZerotierNetwork($network->networkId, 'allowDNS', $network->allowDNS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks rather odd, but the controller is also quite old

what is your goal here to directly apply this after config save?

}
}
}
Expand Down Expand Up @@ -192,8 +196,10 @@ public function toggleAction($uuid = null)

private function toggleZerotierNetwork($networkId, $enabled)
{
$backend = new Backend();
$backend->configdRun("template reload OPNsense/zerotier");
$action = $enabled ? 'join' : 'leave';
return trim((new Backend())->configdRun("zerotier $action $networkId"));
return trim($backend->configdRun("zerotier $action $networkId"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this already was an unsafe call, check out configdpRun()

}

private function listZerotierNetwork($networkId)
Expand All @@ -207,4 +213,9 @@ private function listZerotierNetwork($networkId)
}
return gettext("Unable to obtain Zerotier information for network") . " " . $networkId . "! " . gettext("Is the network enabled?");
}

private function setZerotierNetwork($networkId, $setting, $value)
{
return trim((new Backend())->configdRun("zerotier set $networkId $setting $value"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also unsafe, check configdpRun()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,48 @@
<type>text</type>
<help>Local Description to help identify this network</help>
</field>
<field>
<id>network.allowManaged</id>
<label>Allow Managed</label>
<type>checkbox</type>
<help>Allow ZeroTier to set IP Addresses and Routes (local/private ranges only)</help>
<grid_view>
<visible>false</visible>
<type>boolean</type>
<formatter>boolean</formatter>
</grid_view>
</field>
<field>
<id>network.allowGlobal</id>
<label>Allow Global</label>
<type>checkbox</type>
<help>Allow ZeroTier to set Global/Public/Not-Private range IPs and Routes</help>
<grid_view>
<visible>false</visible>
<type>boolean</type>
<formatter>boolean</formatter>
</grid_view>
</field>
<field>
<id>network.allowDefault</id>
<label>Allow Default</label>
<type>checkbox</type>
<help>Allow ZeroTier to set the Default Route on the system</help>
<grid_view>
<visible>false</visible>
<type>boolean</type>
<formatter>boolean</formatter>
</grid_view>
</field>
<field>
<id>network.allowDNS</id>
<label>Allow DNS</label>
<type>checkbox</type>
<help>Allow ZeroTier to set DNS servers</help>
<grid_view>
<visible>false</visible>
<type>boolean</type>
<formatter>boolean</formatter>
</grid_view>
</field>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@
<default></default>
<Required>N</Required>
</description>
<allowManaged type="BooleanField">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you add new required values with defaults the model version at the beginning of this file needs to be increased

<default>1</default>
<Required>Y</Required>
</allowManaged>
<allowGlobal type="BooleanField">
<default>0</default>
<Required>Y</Required>
</allowGlobal>
<allowDefault type="BooleanField">
<default>0</default>
<Required>Y</Required>
</allowDefault>
<allowDNS type="BooleanField">
<default>0</default>
<Required>Y</Required>
</allowDNS>
</network>
</networks>
</items>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ parameters: leave %s
type:script_output
message:Leaving Zerotier Network

[set]
command:/usr/local/bin/zerotier-cli
parameters: set %s %s=%s
type:script_output
message:Setting Zerotier Network

[info]
command:/usr/local/bin/zerotier-cli info
parameters:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
zerotier:/etc/rc.conf.d/zerotier
local.conf:/var/db/zerotier-one/local.conf
networks-local.conf:/var/db/zerotier-one/networks.d/[OPNsense.zerotier.networks.network.%.networkId].local.conf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note these files generated with dynamic names can not be deleted...

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% if helpers.exists('OPNsense.zerotier.networks') %}
{% for network in helpers.toList('OPNsense.zerotier.networks.network') %}
{% if TARGET_FILTERS['OPNsense.zerotier.networks.network.' ~ loop.index0] or TARGET_FILTERS['OPNsense.zerotier.networks.network'] %}
allowManaged={{ network.allowManaged }}
allowGlobal={{ network.allowGlobal }}
allowDefault={{ network.allowDefault }}
allowDNS={{ network.allowDNS }}
{% endif %}
{% endfor %}
{% endif %}