- wgctl hosts command (list, show, add, rm) with tags support - modules/resolve.module.sh — chain: hosts.json → services.json → raw IP - modules/hosts.module.sh — hosts::resolve_ip, hosts::lookup_ip - resolve::ip and resolve::dest used in watch, logs, activity - _WGCTL_RAW=true via --raw flag bypasses all resolution - json_helper.py: hosts_list, hosts_show, hosts_add, hosts_remove, hosts_lookup
86 lines
No EOL
2.7 KiB
Bash
86 lines
No EOL
2.7 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# ============================================
|
|
# Static Context — resolved once at source time
|
|
# ============================================
|
|
|
|
_CTX_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
_CTX_WG="/etc/wireguard"
|
|
_CTX_CORE="${_CTX_ROOT}/core"
|
|
_CTX_MODULES="${_CTX_ROOT}/modules"
|
|
_CTX_COMMANDS="${_CTX_ROOT}/commands"
|
|
_CTX_CLIENTS="${_CTX_WG}/clients"
|
|
_CTX_DATA="${_CTX_WG}/.wgctl"
|
|
|
|
# ============================================
|
|
# Artifacts
|
|
# ============================================
|
|
|
|
_CTX_RULES="${_CTX_DATA}/rules"
|
|
_CTX_RULES_BASE="${_CTX_RULES}/base"
|
|
_CTX_GROUPS="${_CTX_DATA}/groups"
|
|
_CTX_BLOCKS="${_CTX_DATA}/blocks"
|
|
_CTX_META="${_CTX_DATA}/meta"
|
|
_CTX_IDENTITY="${_CTX_DATA}/identities"
|
|
_CTX_DAEMON="${_CTX_DATA}/daemon"
|
|
_CTX_NET="${_CTX_DATA}/services.json"
|
|
|
|
# ============================================
|
|
|
|
function ctx::root() { echo "$_CTX_ROOT"; }
|
|
function ctx::core() { echo "$_CTX_CORE"; }
|
|
function ctx::modules() { echo "$_CTX_MODULES"; }
|
|
function ctx::commands() { echo "$_CTX_COMMANDS"; }
|
|
function ctx::blocks() { echo "$_CTX_BLOCKS"; }
|
|
function ctx::groups() { echo "$_CTX_GROUPS"; }
|
|
function ctx::rules() { echo "$_CTX_RULES"; }
|
|
function ctx::rules::base() { echo "$_CTX_RULES_BASE"; }
|
|
function ctx::clients() { echo "$_CTX_CLIENTS"; }
|
|
function ctx::wg() { echo "$_CTX_WG"; }
|
|
function ctx::data() { echo "$_CTX_DATA"; }
|
|
function ctx::rules() { echo "$_CTX_RULES"; }
|
|
function ctx::groups() { echo "$_CTX_GROUPS"; }
|
|
function ctx::blocks() { echo "$_CTX_BLOCKS"; }
|
|
function ctx::meta() { echo "$_CTX_META"; }
|
|
function ctx::daemon() { echo "$_CTX_DAEMON"; }
|
|
function ctx::net() { echo "$_CTX_NET"; }
|
|
function ctx::identities() { echo "${_CTX_IDENTITY}"; }
|
|
function ctx::subnets() { echo "${_CTX_DATA}/subnets.json"; }
|
|
function ctx::hosts() { echo "${_CTX_DATA}/hosts.json"; }
|
|
function ctx::events_log() { echo "$(ctx::daemon)/events.log"; }
|
|
function ctx::fw_events_log() { echo "$(ctx::daemon)/fw_events.log"; }
|
|
function ctx::json_helper() { echo "${_CTX_CORE}/json_helper.py"; }
|
|
|
|
# ============================================
|
|
# Path Helpers
|
|
# ============================================
|
|
|
|
function ctx::client::path() {
|
|
local IFS="/"
|
|
echo "$_CTX_CLIENTS/$*"
|
|
}
|
|
|
|
function ctx::meta::path() {
|
|
local IFS="/"
|
|
echo "$_CTX_META/$*"
|
|
}
|
|
|
|
function ctx::identity::path() {
|
|
local IFS="/"
|
|
echo "$_CTX_IDENTITY/$*"
|
|
}
|
|
|
|
function ctx::block::path() {
|
|
local IFS="/"
|
|
echo "$_CTX_BLOCKS/$*"
|
|
}
|
|
|
|
function ctx::group::path() {
|
|
local IFS="/"
|
|
echo "$_CTX_GROUPS/$*"
|
|
}
|
|
|
|
function ctx::rule::path() {
|
|
local IFS="/"
|
|
echo "$_CTX_RULES/$*"
|
|
} |