Compare commits
No commits in common. "a7b05547f59ca447ac8a9ce1caeff43710939223" and "74644e547cb58d070ff75a2a8f5e5efa56685e30" have entirely different histories.
a7b05547f5
...
74644e547c
23 changed files with 57 additions and 385 deletions
|
|
@ -143,12 +143,7 @@ function cmd::activity::run() {
|
||||||
|
|
||||||
log::section "Activity Monitor (last ${hours_display})"
|
log::section "Activity Monitor (last ${hours_display})"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
if display::is_table "activity"; then
|
|
||||||
cmd::activity::_render_table "$data"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
local first_peer=true skip_peer=false
|
local first_peer=true skip_peer=false
|
||||||
|
|
||||||
while IFS='|' read -r record_type rest; do
|
while IFS='|' read -r record_type rest; do
|
||||||
|
|
@ -200,34 +195,6 @@ function cmd::activity::run() {
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmd::activity::_render_table() {
|
|
||||||
local data="${1:-}"
|
|
||||||
[[ -z "$data" ]] && return 0
|
|
||||||
|
|
||||||
ui::activity::header_table
|
|
||||||
local skip_peer=false
|
|
||||||
while IFS='|' read -r record_type rest; do
|
|
||||||
case "$record_type" in
|
|
||||||
peer)
|
|
||||||
local name rx tx drops
|
|
||||||
IFS='|' read -r name rx tx drops <<< "$rest"
|
|
||||||
skip_peer=false
|
|
||||||
local rx_fmt tx_fmt
|
|
||||||
rx_fmt=$(fmt::bytes "$rx")
|
|
||||||
tx_fmt=$(fmt::bytes "$tx")
|
|
||||||
ui::activity::peer_row_table "$name" "$rx_fmt" "$tx_fmt" "$drops" ""
|
|
||||||
;;
|
|
||||||
service)
|
|
||||||
$skip_peer && continue
|
|
||||||
local peer dest count
|
|
||||||
IFS='|' read -r peer dest count <<< "$rest"
|
|
||||||
ui::activity::service_row_table "$dest" "$count" "drops"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done <<< "$data"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function cmd::activity::_output_json() {
|
function cmd::activity::_output_json() {
|
||||||
local hours="${1:-24}"
|
local hours="${1:-24}"
|
||||||
local data
|
local data
|
||||||
|
|
|
||||||
|
|
@ -147,11 +147,6 @@ function cmd::group::list() {
|
||||||
log::section "Groups"
|
log::section "Groups"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
if display::is_table "group_list"; then
|
|
||||||
cmd::group::_render_table "$data" "$w_name" "$w_desc"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
while IFS="|" read -r name desc total blocked; do
|
while IFS="|" read -r name desc total blocked; do
|
||||||
[[ -z "$name" ]] && continue
|
[[ -z "$name" ]] && continue
|
||||||
ui::group::list_row "$name" "$desc" "$total" "$blocked" "$w_name" "$w_desc"
|
ui::group::list_row "$name" "$desc" "$total" "$blocked" "$w_name" "$w_desc"
|
||||||
|
|
@ -228,17 +223,6 @@ function cmd::group::show() {
|
||||||
printf "\n"
|
printf "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmd::group::_render_table() {
|
|
||||||
local data="${1:-}" w_name="${2:-20}" w_desc="${3:-20}"
|
|
||||||
[[ -z "$data" ]] && return 0
|
|
||||||
|
|
||||||
ui::group::list_header_table
|
|
||||||
while IFS='|' read -r name desc total blocked; do
|
|
||||||
[[ -z "$name" ]] && continue
|
|
||||||
ui::group::list_row_table "$name" "$desc" "$total" "$blocked"
|
|
||||||
done <<< "$data"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# Add
|
# Add
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|
|
||||||
|
|
@ -146,11 +146,6 @@ function cmd::hosts::list() {
|
||||||
log::section "Host Mappings"
|
log::section "Host Mappings"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
if display::is_table "hosts_list"; then
|
|
||||||
cmd::hosts::_render_table "$data"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
local last_type="" found=false
|
local last_type="" found=false
|
||||||
while IFS='|' read -r type key name desc tags; do
|
while IFS='|' read -r type key name desc tags; do
|
||||||
[[ -z "$type" ]] && continue
|
[[ -z "$type" ]] && continue
|
||||||
|
|
@ -172,15 +167,19 @@ function cmd::hosts::list() {
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmd::hosts::_render_table() {
|
# Table version (kept for future display config)
|
||||||
local data="${1:-}"
|
function cmd::hosts::_list_table() {
|
||||||
[[ -z "$data" ]] && return 0
|
local hosts_file="${1:-}"
|
||||||
|
printf "\n %-6s %-18s %-16s %-30s %s\n" \
|
||||||
ui::hosts::list_header_table
|
"TYPE" "KEY" "NAME" "DESCRIPTION" "TAGS"
|
||||||
|
printf " %s\n" "$(printf '─%.0s' {1..80})"
|
||||||
|
|
||||||
while IFS='|' read -r type key name desc tags; do
|
while IFS='|' read -r type key name desc tags; do
|
||||||
[[ -z "$type" ]] && continue
|
[[ -z "$type" ]] && continue
|
||||||
ui::hosts::list_row_table "$type" "$key" "$name" "$desc" "$tags"
|
printf " %-6s %-18s %-16s %-30s %s\n" \
|
||||||
done <<< "$data"
|
"$type" "$key" "$name" "${desc:-—}" "${tags:-—}"
|
||||||
|
done < <(json::hosts_list "$hosts_file" 2>/dev/null)
|
||||||
|
printf "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|
|
||||||
|
|
@ -111,12 +111,7 @@ function cmd::identity::_list() {
|
||||||
log::info "No identities found. Run 'wgctl identity migrate' to create from existing peers."
|
log::info "No identities found. Run 'wgctl identity migrate' to create from existing peers."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if display::is_table "identity_list"; then
|
|
||||||
cmd::identity::_render_table "$data"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
while IFS='|' read -r name peer_count types rules policy; do
|
while IFS='|' read -r name peer_count types rules policy; do
|
||||||
local rules_display
|
local rules_display
|
||||||
|
|
@ -190,21 +185,6 @@ function cmd::identity::_show() {
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmd::identity::_render_table() {
|
|
||||||
local data="${1:-}"
|
|
||||||
[[ -z "$data" ]] && return 0
|
|
||||||
|
|
||||||
printf "\n %-20s %-8s %-20s %s\n" "NAME" "PEERS" "RULES" "POLICY"
|
|
||||||
printf " %s\n" "$(printf '─%.0s' {1..65})"
|
|
||||||
while IFS='|' read -r name peer_count types rules policy; do
|
|
||||||
[[ -z "$name" ]] && continue
|
|
||||||
local rules_display
|
|
||||||
rules_display=$(echo "$rules" | sed 's/,/, /g')
|
|
||||||
ui::identity::list_row_table "$name" "$peer_count" "$rules_display" "$policy"
|
|
||||||
done <<< "$data"
|
|
||||||
printf " %s\n\n" "$(printf '─%.0s' {1..65})"
|
|
||||||
}
|
|
||||||
|
|
||||||
function cmd::identity::_device_status() {
|
function cmd::identity::_device_status() {
|
||||||
local peer_name="${1:-}"
|
local peer_name="${1:-}"
|
||||||
local -n _handshakes="${2:-__empty_map}"
|
local -n _handshakes="${2:-__empty_map}"
|
||||||
|
|
|
||||||
|
|
@ -226,11 +226,8 @@ function cmd::list::run() {
|
||||||
|
|
||||||
case "$style" in
|
case "$style" in
|
||||||
table) cmd::list::_render_table ;;
|
table) cmd::list::_render_table ;;
|
||||||
compact) display::render "peer_list" "$collected_rows" \
|
compact) cmd::list::_render_compact "$collected_rows" ;;
|
||||||
"cmd::list::_render_compact" "cmd::list::_render_table" ;;
|
*) cmd::list::_render_compact "$collected_rows" ;;
|
||||||
|
|
||||||
*) display::render "peer_list" "$collected_rows" \
|
|
||||||
"cmd::list::_render_compact" "cmd::list::_render_table" ;;
|
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -349,63 +346,19 @@ function cmd::list::_render_compact() {
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|
||||||
function cmd::list::_render_table() {
|
function cmd::list::_render_table() {
|
||||||
local rows="${1:-}"
|
declare -A rule_counts=() group_counts=()
|
||||||
[[ -z "$rows" ]] && log::wg_warning "No results found" && return 0
|
_list_header_printed=false
|
||||||
|
|
||||||
# Measure column widths from data (same as compact)
|
cmd::list::_iter_confs_table
|
||||||
local w_name=16 w_ip=13 w_type=8 w_rule=10 w_group=10 w_status=10 w_last=20
|
|
||||||
while IFS='|' read -r name ip type rule group status last_seen is_blocked is_restricted; do
|
|
||||||
[[ -z "$name" ]] && continue
|
|
||||||
(( ${#name} > w_name )) && w_name=${#name}
|
|
||||||
(( ${#ip} > w_ip )) && w_ip=${#ip}
|
|
||||||
(( ${#type} > w_type )) && w_type=${#type}
|
|
||||||
(( ${#rule} > w_rule )) && w_rule=${#rule}
|
|
||||||
(( ${#group} > w_group )) && w_group=${#group}
|
|
||||||
(( ${#last_seen} > w_last )) && w_last=${#last_seen}
|
|
||||||
local cs
|
|
||||||
cs=$(printf "%s" "$status" | sed 's/\x1b\[[0-9;]*m//g')
|
|
||||||
(( ${#cs} > w_status )) && w_status=${#cs}
|
|
||||||
done <<< "$rows"
|
|
||||||
(( w_name += 2 )); (( w_ip += 2 ))
|
|
||||||
(( w_type += 2 )); (( w_rule += 2 ))
|
|
||||||
(( w_group += 2 )); (( w_last += 2 ))
|
|
||||||
|
|
||||||
# Header
|
if [[ "$_list_header_printed" == "true" ]]; then
|
||||||
printf "\n %-${w_name}s %-${w_ip}s %-${w_type}s %-${w_rule}s %-${w_group}s %-${w_status}s %s\n" \
|
cmd::list::_render_footer $has_groups
|
||||||
"NAME" "IP" "TYPE" "RULE" "GROUP" "STATUS" "LAST SEEN"
|
local group_summary=""
|
||||||
printf " %s\n" "$(printf '─%.0s' {1..115})"
|
cmd::list::_build_group_summary
|
||||||
|
printf "\n Showing peers\n\n"
|
||||||
# Rows
|
else
|
||||||
while IFS='|' read -r name ip type rule group status last_seen is_blocked is_restricted; do
|
log::wg_warning "No results found"
|
||||||
[[ -z "$name" ]] && continue
|
fi
|
||||||
local clean_status
|
|
||||||
clean_status=$(echo "$status" | sed 's/\x1b\[[0-9;]*m//g')
|
|
||||||
local status_pad_n=$(( w_status - ${#clean_status} ))
|
|
||||||
[[ $status_pad_n -lt 0 ]] && status_pad_n=0
|
|
||||||
|
|
||||||
local row_color status_color
|
|
||||||
row_color=$(ui::peer::_row_color "$is_blocked" "$is_restricted" "$clean_status")
|
|
||||||
status_color=$(ui::peer::status_color "$is_blocked" "$is_restricted" "$clean_status")
|
|
||||||
|
|
||||||
local status_colored="${status_color}${clean_status}\033[0m"
|
|
||||||
|
|
||||||
local last_seen_colored="$last_seen"
|
|
||||||
[[ -n "$row_color" ]] && last_seen_colored="${row_color}${last_seen}\033[0m" \
|
|
||||||
|| last_seen_colored="${status_color}${last_seen}\033[0m"
|
|
||||||
|
|
||||||
if [[ -n "$row_color" ]]; then
|
|
||||||
printf " %b%-${w_name}s %-${w_ip}s %-${w_type}s %-${w_rule}s %-${w_group}s %-${w_status}s %s\033[0m\n" \
|
|
||||||
"$row_color" "$name" "$ip" "$type" "$rule" "$group" "$clean_status" "$last_seen"
|
|
||||||
else
|
|
||||||
printf " %-${w_name}s %-${w_ip}s %-${w_type}s %-${w_rule}s %-${w_group}s %b%*s\033[0m %b\n" \
|
|
||||||
"$name" "$ip" "$type" "$rule" "$group" \
|
|
||||||
"$status_color${clean_status}" "$status_pad_n" "" \
|
|
||||||
"$last_seen_colored"
|
|
||||||
fi
|
|
||||||
done <<< "$rows"
|
|
||||||
|
|
||||||
printf " %s\n" "$(printf '─%.0s' {1..115})"
|
|
||||||
cmd::list::_render_summary_from_rows "$rows"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmd::list::_iter_confs_table() {
|
function cmd::list::_iter_confs_table() {
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ function cmd::net::list() {
|
||||||
log::wg_warning "No services configured"
|
log::wg_warning "No services configured"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Measure column widths
|
# Measure column widths
|
||||||
local w_name=12 w_ip=13 w_ports=16
|
local w_name=12 w_ip=13 w_ports=16
|
||||||
while IFS="|" read -r name ip desc tags ports; do
|
while IFS="|" read -r name ip desc tags ports; do
|
||||||
|
|
@ -144,11 +144,6 @@ function cmd::net::list() {
|
||||||
|
|
||||||
log::section "Network Services"
|
log::section "Network Services"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
if display::is_table "net_list"; then
|
|
||||||
cmd::net::_render_table "$filtered_data"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
while IFS="|" read -r name ip desc tags ports; do
|
while IFS="|" read -r name ip desc tags ports; do
|
||||||
[[ -z "$name" ]] && continue
|
[[ -z "$name" ]] && continue
|
||||||
|
|
@ -167,17 +162,6 @@ function cmd::net::list() {
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmd::net::_render_table() {
|
|
||||||
local data="${1:-}"
|
|
||||||
[[ -z "$data" ]] && return 0
|
|
||||||
|
|
||||||
ui::net::list_header_table
|
|
||||||
while IFS='|' read -r name ip desc tags port_count; do
|
|
||||||
[[ -z "$name" ]] && continue
|
|
||||||
ui::net::list_row_table "$name" "$ip" "$desc" "$tags" "$port_count"
|
|
||||||
done <<< "$data"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# Show
|
# Show
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|
|
||||||
|
|
@ -113,11 +113,6 @@ function cmd::policy::_list() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if display::is_table "policy_list"; then
|
|
||||||
cmd::policy::_render_table "$data"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
while IFS='|' read -r name tunnel default_rule strict auto desc; do
|
while IFS='|' read -r name tunnel default_rule strict auto desc; do
|
||||||
ui::policy::list_row "$name" "$default_rule" "$strict" "$auto"
|
ui::policy::list_row "$name" "$default_rule" "$strict" "$auto"
|
||||||
|
|
@ -125,19 +120,6 @@ function cmd::policy::_list() {
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmd::policy::_render_table() {
|
|
||||||
local data="${1:-}"
|
|
||||||
[[ -z "$data" ]] && return 0
|
|
||||||
|
|
||||||
ui::policy::list_header_table
|
|
||||||
while IFS='|' read -r name tunnel default_rule strict auto desc; do
|
|
||||||
[[ -z "$name" ]] && continue
|
|
||||||
ui::policy::list_row_table "$name" "$tunnel" "$default_rule" "$strict" "$auto"
|
|
||||||
done <<< "$data"
|
|
||||||
printf "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function cmd::policy::_show() {
|
function cmd::policy::_show() {
|
||||||
local name=""
|
local name=""
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
|
|
|
||||||
|
|
@ -181,11 +181,6 @@ function cmd::rule::list() {
|
||||||
log::section "Firewall Rules"
|
log::section "Firewall Rules"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
if display::is_table "rule_list"; then
|
|
||||||
cmd::rule::_render_table "$data"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
local current_group="" printing_base=false found_any=false
|
local current_group="" printing_base=false found_any=false
|
||||||
|
|
||||||
while IFS="|" read -r name desc n_allows n_blocks \
|
while IFS="|" read -r name desc n_allows n_blocks \
|
||||||
|
|
@ -245,18 +240,6 @@ function cmd::rule::list() {
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmd::rule::_render_table() {
|
|
||||||
local data="${1:-}"
|
|
||||||
[[ -z "$data" ]] && return 0
|
|
||||||
|
|
||||||
ui::rule::list_header_table
|
|
||||||
while IFS='|' read -r name desc n_allows n_blocks peer_count extends is_base group; do
|
|
||||||
[[ -z "$name" ]] && continue
|
|
||||||
ui::rule::list_row_table "$name" "$n_allows" "$n_blocks" "$peer_count" "$extends" "$group"
|
|
||||||
done <<< "$data"
|
|
||||||
printf "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# Show
|
# Show
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|
|
||||||
|
|
@ -99,11 +99,6 @@ function cmd::subnet::_list() {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if display::is_table "subnet_list"; then
|
|
||||||
cmd::subnet::_render_table "$data"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
local prev_group=""
|
local prev_group=""
|
||||||
while IFS='|' read -r display_name subnet type_key tunnel_mode desc is_group group_parent; do
|
while IFS='|' read -r display_name subnet type_key tunnel_mode desc is_group group_parent; do
|
||||||
|
|
@ -125,18 +120,6 @@ function cmd::subnet::_list() {
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function cmd::subnet::_render_table() {
|
|
||||||
local data="${1:-}"
|
|
||||||
[[ -z "$data" ]] && return 0
|
|
||||||
|
|
||||||
ui::subnet::list_header_table
|
|
||||||
while IFS='|' read -r type cidr display_name tunnel desc is_group group_parent; do
|
|
||||||
[[ -z "$type" ]] && continue
|
|
||||||
ui::subnet::list_row_table "$type" "$cidr" "$tunnel" "$desc"
|
|
||||||
done <<< "$data"
|
|
||||||
printf "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
function cmd::subnet::_maybe_group_separator() {
|
function cmd::subnet::_maybe_group_separator() {
|
||||||
local is_group="${1:-}" group_parent="${2:-}" prev_group="${3:-}"
|
local is_group="${1:-}" group_parent="${2:-}" prev_group="${3:-}"
|
||||||
if [[ "$is_group" == "true" && "$group_parent" != "$prev_group" && -n "$prev_group" ]]; then
|
if [[ "$is_group" == "true" && "$group_parent" != "$prev_group" && -n "$prev_group" ]]; then
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,6 @@ function ctx::policies() { echo "$_CTX_POLICIES"; }
|
||||||
|
|
||||||
# Config files
|
# Config files
|
||||||
function ctx::config_file() { echo "$_CTX_CONFIG_FILE"; }
|
function ctx::config_file() { echo "$_CTX_CONFIG_FILE"; }
|
||||||
function ctx::display() { echo "${_CTX_CONFIG}/display.json"; }
|
|
||||||
|
|
||||||
# Daemon files
|
# Daemon files
|
||||||
function ctx::events_log() { echo "${_CTX_DAEMON}/events.log"; }
|
function ctx::events_log() { echo "${_CTX_DAEMON}/events.log"; }
|
||||||
|
|
|
||||||
|
|
@ -1611,22 +1611,6 @@ def config_load(file):
|
||||||
print(f"Error: {e}", file=sys.stderr)
|
print(f"Error: {e}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def display_load(file):
|
|
||||||
"""
|
|
||||||
Load display.json and output view=style pairs.
|
|
||||||
Output: view_name=style per line
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
with open(file) as f:
|
|
||||||
d = json.load(f)
|
|
||||||
views = d.get('views', {})
|
|
||||||
for view_name, view_config in views.items():
|
|
||||||
style = view_config.get('style', 'compact')
|
|
||||||
print(f"{view_name}={style}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error: {e}", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# ======================================================
|
# ======================================================
|
||||||
|
|
||||||
def _net_read(file):
|
def _net_read(file):
|
||||||
|
|
@ -1997,7 +1981,6 @@ commands = {
|
||||||
'batch_resolve': lambda args: batch_resolve(args[0], args[1], *args[2:]),
|
'batch_resolve': lambda args: batch_resolve(args[0], args[1], *args[2:]),
|
||||||
'peer_history_lookup': lambda args: peer_history_lookup(args[0], args[1]),
|
'peer_history_lookup': lambda args: peer_history_lookup(args[0], args[1]),
|
||||||
'config_load': lambda args: config_load(args[0]),
|
'config_load': lambda args: config_load(args[0]),
|
||||||
'display_load': lambda args: display_load(args[0]),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── Main ─────────────────────────────────────────────────────────────────────
|
# ── Main ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"phone-fred": "176.223.61.130",
|
"phone-fred": "176.223.61.130",
|
||||||
"phone-helena": "148.69.46.73",
|
"phone-helena": "148.69.46.73",
|
||||||
"phone-nuno": "148.69.48.20",
|
"phone-nuno": "148.69.50.62",
|
||||||
"tablet-nuno": "148.69.202.5",
|
"tablet-nuno": "148.69.202.5",
|
||||||
"guest-zephyr": "86.120.152.74",
|
"guest-zephyr": "86.120.152.74",
|
||||||
"guest-zephyr-test": "94.63.0.129",
|
"guest-zephyr-test": "94.63.0.129",
|
||||||
"desktop-roboclean": "46.189.215.231",
|
"desktop-roboclean": "46.189.215.231",
|
||||||
"laptop-nuno": "94.63.0.129",
|
"laptop-nuno": "94.63.0.129",
|
||||||
"phone-luis": "176.223.61.15",
|
"phone-luis": "176.223.61.15",
|
||||||
"phone-helena-2": "148.69.202.234",
|
"phone-helena-2": "148.69.203.225",
|
||||||
"desktop-zephyr": "86.120.152.74"
|
"desktop-zephyr": "86.120.152.74"
|
||||||
}
|
}
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
# modules/display.module.sh
|
|
||||||
# Display configuration — controls layout style per view
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# State — loaded once on first access
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
_DISPLAY_LOADED=false
|
|
||||||
declare -gA _DISPLAY_STYLES=()
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# Load display config
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
function display::_load() {
|
|
||||||
$_DISPLAY_LOADED && return 0
|
|
||||||
_DISPLAY_LOADED=true
|
|
||||||
|
|
||||||
local display_file
|
|
||||||
display_file="$(ctx::display)"
|
|
||||||
[[ ! -f "$display_file" ]] && return 0
|
|
||||||
|
|
||||||
# Load styles per view via json_helper
|
|
||||||
local view style
|
|
||||||
while IFS='=' read -r view style; do
|
|
||||||
[[ -n "$view" && -n "$style" ]] && _DISPLAY_STYLES["$view"]="$style"
|
|
||||||
done < <(python3 "$(ctx::json_helper)" display_load "$display_file" 2>/dev/null)
|
|
||||||
}
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# Accessors
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
# display::style <view>
|
|
||||||
# Returns: compact | table | minimal (default: compact)
|
|
||||||
function display::style() {
|
|
||||||
local view="${1:-}"
|
|
||||||
display::_load
|
|
||||||
echo "${_DISPLAY_STYLES[$view]:-compact}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# display::is_compact <view>
|
|
||||||
function display::is_compact() {
|
|
||||||
[[ "$(display::style "$1")" == "compact" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
# display::is_table <view>
|
|
||||||
function display::is_table() {
|
|
||||||
[[ "$(display::style "$1")" == "table" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
# ============================================
|
|
||||||
# display::render <view> <data> <compact_fn> <table_fn> [extra_args...]
|
|
||||||
# Generic dispatcher — calls compact or table render function
|
|
||||||
# ============================================
|
|
||||||
|
|
||||||
function display::render() {
|
|
||||||
local view="${1:-}" data="${2:-}" compact_fn="${3:-}" table_fn="${4:-}"
|
|
||||||
shift 4 || true
|
|
||||||
|
|
||||||
case "$(display::style "$view")" in
|
|
||||||
table)
|
|
||||||
declare -f "$table_fn" >/dev/null 2>&1 && \
|
|
||||||
"$table_fn" "$data" "$@" || \
|
|
||||||
"$compact_fn" "$data" "$@" # fallback to compact if no table fn
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
"$compact_fn" "$data" "$@"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
@ -31,7 +31,7 @@ function ui::peer::status_color() {
|
||||||
elif [[ "$status" == "online"* ]]; then
|
elif [[ "$status" == "online"* ]]; then
|
||||||
echo "\033[1;32m"
|
echo "\033[1;32m"
|
||||||
else
|
else
|
||||||
echo "\033[2m"
|
echo "\033[2;37m"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
function ui::policy::list_row() {
|
|
||||||
local name="${1:-}" default_rule="${2:-}" strict="${3:-}" auto="${4:-}"
|
|
||||||
|
|
||||||
local rule_val="-"
|
|
||||||
[[ -n "$default_rule" ]] && rule_val="$default_rule"
|
|
||||||
|
|
||||||
local rule_padded
|
|
||||||
rule_padded=$(printf "%-16s" "$rule_val")
|
|
||||||
|
|
||||||
local strict_display
|
|
||||||
[[ "$strict" == "true" ]] && strict_display="yes" || strict_display="no"
|
|
||||||
local strict_padded
|
|
||||||
strict_padded=$(printf "%-4s" "$strict_display")
|
|
||||||
|
|
||||||
local auto_display=""
|
|
||||||
[[ "$auto" == "false" ]] && auto_display=" \033[2mauto:\033[0m no"
|
|
||||||
|
|
||||||
printf " %-14s \033[2mrule:\033[0m %s \033[2mstrict:\033[0m %s%s\n" \
|
|
||||||
"$name" "$rule_padded" "$strict_padded" "$auto_display"
|
|
||||||
}
|
|
||||||
|
|
||||||
function ui::policy::detail_field() {
|
|
||||||
local key="${1:-}" value="${2:-}"
|
|
||||||
ui::row "$key" "$value"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ======================================================
|
|
||||||
# Table view
|
|
||||||
# ======================================================
|
|
||||||
|
|
||||||
function ui::policy::list_header_table() {
|
|
||||||
printf "\n %-16s %-8s %-14s %-8s %s\n" \
|
|
||||||
"NAME" "TUNNEL" "DEFAULT RULE" "STRICT" "AUTO"
|
|
||||||
printf " %s\n" "$(printf '─%.0s' {1..60})"
|
|
||||||
}
|
|
||||||
|
|
||||||
function ui::policy::list_row_table() {
|
|
||||||
local name="${1:-}" tunnel="${2:-}" default_rule="${3:-}" \
|
|
||||||
strict="${4:-}" auto="${5:-}"
|
|
||||||
printf " %-16s %-8s %-14s %-8s %s\n" \
|
|
||||||
"$name" "$tunnel" "${default_rule:--}" "$strict" "$auto"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -392,24 +392,6 @@ function ui::rule::list_extends_detailed() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# ======================================================
|
|
||||||
# Table view
|
|
||||||
# ======================================================
|
|
||||||
|
|
||||||
function ui::rule::list_header_table() {
|
|
||||||
printf "\n %-20s %-6s %-6s %-8s %-20s %s\n" \
|
|
||||||
"NAME" "ALLOW" "BLOCK" "PEERS" "EXTENDS" "GROUP"
|
|
||||||
printf " %s\n" "$(printf '─%.0s' {1..75})"
|
|
||||||
}
|
|
||||||
|
|
||||||
function ui::rule::list_row_table() {
|
|
||||||
local name="${1:-}" n_allows="${2:-0}" n_blocks="${3:-0}" \
|
|
||||||
peer_count="${4:-0}" extends="${5:-}" group="${6:-}"
|
|
||||||
printf " %-20s %-6s %-6s %-8s %-20s %s\n" \
|
|
||||||
"$name" "+${n_allows}" "-${n_blocks}" "$peer_count" \
|
|
||||||
"${extends:--}" "${group:--}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ======================================================
|
# ======================================================
|
||||||
# Show helpers
|
# Show helpers
|
||||||
# ======================================================
|
# ======================================================
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,33 @@ function ui::subnet::header() {
|
||||||
ui::divider 70
|
ui::divider 70
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ui::policy::list_row() {
|
||||||
|
local name="${1:-}" default_rule="${2:-}" strict="${3:-}" auto="${4:-}"
|
||||||
|
|
||||||
|
local rule_val="-"
|
||||||
|
[[ -n "$default_rule" ]] && rule_val="$default_rule"
|
||||||
|
|
||||||
|
local rule_padded
|
||||||
|
rule_padded=$(printf "%-16s" "$rule_val")
|
||||||
|
|
||||||
|
local strict_display
|
||||||
|
[[ "$strict" == "true" ]] && strict_display="yes" || strict_display="no"
|
||||||
|
local strict_padded
|
||||||
|
strict_padded=$(printf "%-4s" "$strict_display")
|
||||||
|
|
||||||
|
local auto_display=""
|
||||||
|
[[ "$auto" == "false" ]] && auto_display=" \033[2mauto:\033[0m no"
|
||||||
|
|
||||||
|
printf " %-14s \033[2mrule:\033[0m %s \033[2mstrict:\033[0m %s%s\n" \
|
||||||
|
"$name" "$rule_padded" "$strict_padded" "$auto_display"
|
||||||
|
}
|
||||||
|
|
||||||
|
function ui::policy::detail_field() {
|
||||||
|
local key="${1:-}" value="${2:-}"
|
||||||
|
ui::row "$key" "$value"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function ui::subnet::row() {
|
function ui::subnet::row() {
|
||||||
local display_name="${1:-}" subnet="${2:-}" type_key="${3:-}" \
|
local display_name="${1:-}" subnet="${2:-}" type_key="${3:-}" \
|
||||||
tunnel_mode="${4:-}" desc="${5:-}" is_group="${6:-false}"
|
tunnel_mode="${4:-}" desc="${5:-}" is_group="${6:-false}"
|
||||||
|
|
@ -183,20 +210,4 @@ function ui::subnet::show_peers_annotated() {
|
||||||
for peer in "${no_identity[@]}"; do
|
for peer in "${no_identity[@]}"; do
|
||||||
printf " · %b\n" "$peer"
|
printf " · %b\n" "$peer"
|
||||||
done
|
done
|
||||||
}
|
|
||||||
|
|
||||||
# ======================================================
|
|
||||||
# Table view
|
|
||||||
# ======================================================
|
|
||||||
|
|
||||||
function ui::subnet::list_header_table() {
|
|
||||||
printf "\n %-14s %-20s %-8s %s\n" \
|
|
||||||
"TYPE" "CIDR" "TUNNEL" "DESCRIPTION"
|
|
||||||
printf " %s\n" "$(printf '─%.0s' {1..65})"
|
|
||||||
}
|
|
||||||
|
|
||||||
function ui::subnet::list_row_table() {
|
|
||||||
local type="${1:-}" cidr="${2:-}" tunnel="${3:-}" desc="${4:-}"
|
|
||||||
printf " %-14s %-20s %-8s %s\n" \
|
|
||||||
"$type" "$cidr" "$tunnel" "${desc:--}"
|
|
||||||
}
|
}
|
||||||
1
wgctl
1
wgctl
|
|
@ -11,7 +11,6 @@ LOG_LEVEL=DEBUG
|
||||||
|
|
||||||
load_module ip
|
load_module ip
|
||||||
load_module ui
|
load_module ui
|
||||||
load_module display
|
|
||||||
load_module config
|
load_module config
|
||||||
load_module keys
|
load_module keys
|
||||||
load_module peers
|
load_module peers
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue