diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..968b0dd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,74 @@ +name: Release + +on: + push: + tags: + - "v*" + branches: + - main + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || github.actor_id }} + cancel-in-progress: true + +jobs: + release: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build + id: build + uses: vmactions/freebsd-vm@v1 + with: + usesh: true + copyback: true + release: "15.0" + prepare: | + pkg install -y git go124 ca_root_nss poudriere + git clone -b devel --depth 1 --single-branch https://github.com/pfsense/FreeBSD-ports.git /usr/ports + run: | + set -ex + cd pfSense-pkg-NetBird + make + make package + cd ../netbird + make makesum + make package + + - name: Upload pfSense package artifact + uses: actions/upload-artifact@v4 + with: + name: pfSense-package + path: pfSense-pkg-NetBird/work/pkg/pfSense-pkg-NetBird-*.pkg + retention-days: 3 + + - name: Upload FreeBSD package artifact + uses: actions/upload-artifact@v4 + with: + name: FreeBSD-package + path: netbird/work/pkg/netbird-*.pkg + retention-days: 3 + + - name: Create Release + if: startsWith(github.ref, 'refs/tags/') + uses: actions/create-release@v1 + with: + tag_name: ${{ github.ref_name }} + release_name: Release ${{ github.ref_name }} + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload packages to release page + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: | + pfSense-pkg-NetBird/work/pkg/pfSense-pkg-NetBird-*.pkg + netbird/work/pkg/netbird-*.pkg + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/assets/netbird.png b/assets/netbird.png index a55f8c7..09c502c 100644 Binary files a/assets/netbird.png and b/assets/netbird.png differ diff --git a/netbird/Makefile b/netbird/Makefile new file mode 100644 index 0000000..4d01611 --- /dev/null +++ b/netbird/Makefile @@ -0,0 +1,30 @@ +PORTNAME= netbird +DISTVERSIONPREFIX= v +DISTVERSION= 0.49.0 +CATEGORIES= security net net-vpn + +MAINTAINER= hakan.external@netbird.io +COMMENT= Peer-to-peer VPN that seamlessly connects your devices +WWW= https://netbird.io/ + +LICENSE= BSD3CLAUSE +LICENSE_FILE= ${WRKSRC}/LICENSE + +NOT_FOR_ARCHS= i386 +NOT_FOR_ARCHS_REASON= "no 32-bit builds supported" + +RUN_DEPENDS= ca_root_nss>0:security/ca_root_nss + +USES= go:modules +USE_RC_SUBR= netbird + +GO_MODULE= github.com/netbirdio/netbird +GO_TARGET= ./client:netbird +GO_BUILDFLAGS= -tags freebsd -o ${PORTNAME} -ldflags \ + "-s -w -X github.com/netbirdio/netbird/version.version=${DISTVERSION}" + +WRKSRC= ${WRKDIR}/netbird-${DISTVERSION} + +PLIST_FILES= bin/netbird + +.include \ No newline at end of file diff --git a/netbird/files/netbird.in b/netbird/files/netbird.in new file mode 100644 index 0000000..191491e --- /dev/null +++ b/netbird/files/netbird.in @@ -0,0 +1,18 @@ +#!/bin/sh +# +# PROVIDE: netbird +# REQUIRE: SERVERS +# KEYWORD: shutdown +# + +. /etc/rc.subr + +name="netbird" +netbird_env="IS_DAEMON=1" +pidfile="/var/run/${name}.pid" +command="/usr/sbin/daemon" +daemon_args="-P ${pidfile} -r -t \"${name}: daemon\"" +command_args="${daemon_args} /usr/local/bin/netbird service run --config /var/db/netbird/config.json --log-level info --daemon-addr unix:///var/run/netbird.sock --log-file /var/log/netbird/client.log" + +run_rc_command "$1" + diff --git a/netbird/pkg-descr b/netbird/pkg-descr new file mode 100644 index 0000000..e3c155b --- /dev/null +++ b/netbird/pkg-descr @@ -0,0 +1,18 @@ +NetBird is an open-source WireGuard-based overlay network combined with +Zero Trust Network Access, providing secure and reliable connectivity +to internal resources. + +Key features: +- Zero-config VPN: Easily create secure connections between devices without +manual network setup. +- Built on WireGuard: Leverages WireGuard's high-performance encryption for +fast and secure communication. +- Self-hosted or Cloud-managed: Users can deploy their own NetBird management +server or use NetBird Cloud for centralized control. +- Access Control & Routing: Fine-grained access control policies and automatic +network routing simplify connectivity. +- This FreeBSD port provides the NetBird client daemon and CLI tools, allowing +FreeBSD systems to join a NetBird mesh network and securely communicate with +other peers. + +For more details, visit: https://netbird.io diff --git a/netbird/pkg-message b/netbird/pkg-message new file mode 100644 index 0000000..c8b893f --- /dev/null +++ b/netbird/pkg-message @@ -0,0 +1,11 @@ +[ +{ type: install + message: <NetBird
VPN
netbird.xml - /pkg_edit.php?xml=netbird/netbird_auth.xml + /netbird_auth.php NetBird @@ -42,10 +42,16 @@ netbird.xml /netbird_status.php + + netbird + netbird.sh + netbird + NetBird secure overlay network + Authentication - pkg_edit.php?xml=netbird/netbird_auth.xml + netbird_auth.php Settings @@ -250,6 +256,12 @@ ]]> + + + + + + diff --git a/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird.inc b/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird.inc index 9fceac3..0e3b994 100644 --- a/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird.inc +++ b/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird.inc @@ -20,47 +20,56 @@ */ require_once('service-utils.inc'); +require_once("config.inc"); +require_once("util.inc"); define('NETBIRD_BIN', '/usr/local/bin/netbird'); +define('NETBIRD_CONFIG', '/var/db/netbird/config.json'); define('PKG_BIN', '/usr/sbin/pkg'); function netbird_resync_config() { + $json = file_get_contents(NETBIRD_CONFIG); + $config = json_decode($json, true); + + if (!is_array($config)) { + log_error("Invalid netbird configuration"); + return; + } + + if (!empty($_POST['wireguardport'])) { + $config['WgPort'] = (int)$_POST['wireguardport']; + } + + $config_map = [ + 'enablessh' => ['ServerSSHAllowed', true], + 'blockinboundconn' => ['BlockInbound', true], + 'allowfirewallconfig' => ['DisableFirewall', false], + 'enabledns' => ['DisableDNS', false], + 'accesslan' => ['BlockLANAccess', false], + 'allowclientroutes' => ['DisableClientRoutes', false], + 'allowserverroutes' => ['DisableServerRoutes', false], + 'enablerosenpass' => ['RosenpassEnabled', true], + 'rosenpasspermissive' => ['RosenpassPermissive', true], + ]; + + foreach ($config_map as $post_key => [$json_key, $enabled_val]) { + $checked = ($_POST[$post_key] ?? '') === 'on'; + $config[$json_key] = ($checked === $enabled_val); + } + + file_put_contents(NETBIRD_CONFIG, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + + if (netbird_is_connected()) { if (!netbird_disconnect()) { return; } + + $cmd = implode(' ', [NETBIRD_BIN, 'up']); + exec($cmd); } - - - $cmd = [NETBIRD_BIN, 'up']; - - if (!empty($_POST['wireguardport'])) { - $cmd[] = '--wireguard-port=' . escapeshellarg((int)$_POST['wireguardport']); - } - if (!empty($_POST['loglevel'])) { - $cmd[] = '--log-level=' . escapeshellarg($_POST['loglevel']); - } - - $options = [ - 'enablessh' => ['--allow-server-ssh', true], - 'blockinboundconn' => ['--block-inbound', true], - 'allowfirewallconfig' => ['--disable-firewall', false], - 'enabledns' => ['--disable-dns', false], - 'accesslan' => ['--block-lan-access', false], - 'allowclientroutes' => ['--disable-client-routes', false], - 'allowserverroutes' => ['--disable-server-routes', false], - 'enablerosenpass' => ['--enable-rosenpass', true], - 'rosenpasspermissive' => ['--rosenpass-permissive', true], - ]; - - foreach ($options as $key => [$flag, $enabled_value]) { - $is_checked = ($_POST[$key] ?? '') === 'on'; - $cmd[] = $flag . '=' . ($is_checked === $enabled_value ? 'true' : 'false'); - } - - exec(implode(' ', $cmd)); } @@ -114,7 +123,7 @@ function netbird_display_connection_info(): void $type = 'danger'; $closable = false; } elseif (!netbird_is_connected()) { - $message = gettext('NetBird is not connected. Refresh or check the NetBird status page.'); + $message = gettext('NetBird is not connected.'); $type = 'warning'; $closable = false; } else { @@ -125,4 +134,38 @@ function netbird_display_connection_info(): void print_info_box($message, $type, $closable ? 'close' : false); } + +function netbird_write_rcfile() { + $rc['file'] = 'netbird.sh'; + $rc['start'] .= "/usr/local/bin/netbird service start\n\t"; + $rc['stop'] .= "/usr/local/bin/netbird service stop\n\t"; + $rc['restart'] .= "/usr/local/bin/netbird service restart\n\t"; + write_rcfile($rc); +} + +function netbird_install() +{ + netbird_write_rcfile(); + + if (!netbird_is_running()){ + $cmd = implode(' ', [NETBIRD_BIN, 'service', 'start']); + exec($cmd); + } +} + +function netbird_deinstall() +{ + global $config; + + if (netbird_is_running()) { + stop_service("netbird"); + } + + unlink_if_exists(NETBIRD_CONFIG); + + if (isset($config['installedpackages']['netbird'])) { + unset($config['installedpackages']['netbird']); + write_config("Removed netbird configuration"); + } +} ?> \ No newline at end of file diff --git a/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird_auth.inc b/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird_auth.inc deleted file mode 100644 index a26b95d..0000000 --- a/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird_auth.inc +++ /dev/null @@ -1,65 +0,0 @@ - - diff --git a/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird_auth.xml b/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird_auth.xml deleted file mode 100644 index 0c80a75..0000000 --- a/pfSense-pkg-NetBird/files/usr/local/pkg/netbird/netbird_auth.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - netbird_auth - %%PKGVERSION%% - VPN/NetBird - /usr/local/pkg/netbird/netbird_auth.inc - /pkg_edit.php?xml=netbird/netbird_auth.xml - - - Authentication - pkg_edit.php?xml=netbird/netbird_auth.xml - - - - Settings - pkg_edit.php?xml=netbird.xml - - - Status - netbird_status.php - - - - - Authentication - listtopic - - - Management URL - managementurl - - - - input - https://api.netbird.io:443 - - - - Setup Key - setupkey - - - - input - - - - Disconnect - disconnect - button - fa-solid fa-right-from-bracket - btn-danger - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pfSense-pkg-NetBird/files/usr/local/www/netbird_auth.php b/pfSense-pkg-NetBird/files/usr/local/www/netbird_auth.php new file mode 100644 index 0000000..f97338e --- /dev/null +++ b/pfSense-pkg-NetBird/files/usr/local/www/netbird_auth.php @@ -0,0 +1,165 @@ +addInput(new Form_Input( + 'managementurl', + 'Management URL', + 'text', + $management_url +))->setHelp('Base URL of the management service'); + +$section->addInput(new Form_Input( + 'setupkey', + 'Setup Key', + 'text', + $masked_key +))->setHelp('Set the authentication setup key'); + +if (netbird_is_connected()) { + $button = new Form_Button( + 'disconnect', + 'Disconnect', + null, + 'fa-solid fa-right-from-bracket' + ); + $button->setAttribute('type', 'submit')->addClass('btn-danger'); + + $section->addInput(new Form_StaticText( + null, + $button + ))->setHelp('Disconnect from the management service'); +} else { + $button = new Form_Button( + 'connect', + 'Connect', + null, + 'fa-solid fa-right-to-bracket' + ); + $button->setAttribute('type', 'submit')->addClass('btn-primary'); + + $section->addInput(new Form_StaticText( + null, + $button + ))->setHelp('Connect to the management service'); +} + +$form->add($section); +print $form; + +include('foot.inc'); + + diff --git a/pfSense-pkg-NetBird/files/usr/local/www/netbird_status.php b/pfSense-pkg-NetBird/files/usr/local/www/netbird_status.php index 090ac8a..ce9f411 100644 --- a/pfSense-pkg-NetBird/files/usr/local/www/netbird_status.php +++ b/pfSense-pkg-NetBird/files/usr/local/www/netbird_status.php @@ -23,8 +23,10 @@ require_once('guiconfig.inc'); require_once('util.inc'); require_once('netbird/netbird_status.inc'); +$shortcut_section = 'netbird'; + $tabs = [ - [gettext('Authentication'), false, 'pkg_edit.php?xml=netbird/netbird_auth.xml'], + [gettext('Authentication'), false, '/netbird_auth.php'], [gettext('Settings'), false, 'pkg_edit.php?xml=netbird.xml'], [gettext('Status'), true, '/netbird_status.php'], ]; diff --git a/pfSense-pkg-NetBird/files/usr/local/www/shortcuts/pkg_netbird.inc b/pfSense-pkg-NetBird/files/usr/local/www/shortcuts/pkg_netbird.inc new file mode 100644 index 0000000..f1bfbbb --- /dev/null +++ b/pfSense-pkg-NetBird/files/usr/local/www/shortcuts/pkg_netbird.inc @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/pfSense-pkg-NetBird/pkg-plist b/pfSense-pkg-NetBird/pkg-plist index 30edb8c..17a8ec9 100644 --- a/pfSense-pkg-NetBird/pkg-plist +++ b/pfSense-pkg-NetBird/pkg-plist @@ -1,7 +1,7 @@ pkg/netbird.xml pkg/netbird/netbird.inc pkg/netbird/netbird_status.inc -pkg/netbird/netbird_auth.inc -pkg/netbird/netbird_auth.xml %%DATADIR%%/info.xml www/netbird_status.php +www/netbird_auth.php +www/shortcuts/pkg_netbird.inc