Skip to content

Commit

Permalink
custom EP
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyperTHC committed Sep 25, 2024
1 parent 1677eb1 commit 2fff85b
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 5 deletions.
17 changes: 12 additions & 5 deletions contrib/sfwg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Variables:
#
# SF_DEBUG=1 Enable debug information and start WT in the foreground
# EP=ip:port Specify custom Wireguard Endpoint
# TYPE="wireguard:wiretap" Force WireGuard or Wiretap or both

# Test IPv6:
Expand Down Expand Up @@ -68,8 +69,7 @@ x2data()
local str
local ip

IFS="-"
CONF=($X)
IFS="-" read -r -a CONF <<< "$X"

[[ ${#CONF[@]} -lt 4 ]] && ERREXIT 255 "X= is not a valid configuration string."
[[ ${#CONF[1]} -ne 44 ]] && ERREXIT 255 "X= does not contain a valid private key."
Expand All @@ -78,7 +78,11 @@ x2data()
[[ -z $SF_VER ]] && SF_VER=${CONF[0]//[^0-9]}
PRIV=${CONF[1]}
PEER=${CONF[2]}
EP=${CONF[3]}
if [ -z "$EP" ]; then
EP="${CONF[3]}"
else
WARN "Using ${CDY}${EP}${CN} as Endpoint. Use ${CDC}unset EP${CN} to disable."
fi

[[ -z $SF_VER ]] && ERREXIT 255 "X= contains a bad version number."

Expand Down Expand Up @@ -367,11 +371,14 @@ wt_up()
addenv WIRETAP_RELAY_PEER_ENDPOINT "${EP}"
addenv WIRETAP_SIMPLE "true"

local cmd=()
command -v nice >/dev/null && cmd=("nice" "-n19")
cmd+=("wiretap")
if [[ -z $SF_DEBUG ]]; then
PATH=".:$PATH" exec -a '[updated]' wiretap serve -q --allowed "${peer_addr}" &>/dev/null &
PATH=".:$PATH" exec -a '[updated]' "${cmd[@]}" serve -q --allowed "${peer_addr}" &>/dev/null &
pid=$!
else
PATH=".:$PATH" ./wiretap serve --allowed "${peer_addr}"
PATH=".:$PATH" "${cmd[@]}" serve --allowed "${peer_addr}"
fi
[[ ${#cmd_checkrunning[@]} -gt 0 ]] && {
n=0
Expand Down
8 changes: 8 additions & 0 deletions guest/fs-root/sf/bin/addfileextension
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

#source /sf/bin/funcs.sh
source /sf/bin/funcs_extra.sh 2>/dev/null

_func="${0##*/}"
declare -F "${_func}" &>/dev/null || { echo -e >&2 "Function ${CDY}$_func${CN} not found."; exit 255; }
"${_func}" "$@"
8 changes: 8 additions & 0 deletions guest/fs-root/sf/bin/crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

#source /sf/bin/funcs.sh
source /sf/bin/funcs_extra.sh 2>/dev/null

_func="${0##*/}"
declare -F "${_func}" &>/dev/null || { echo -e >&2 "Function ${CDY}$_func${CN} not found."; exit 255; }
"${_func}" "$@"
8 changes: 8 additions & 0 deletions guest/fs-root/sf/bin/dns
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

source /sf/bin/funcs.sh
source /sf/bin/funcs_ip.sh 2>/dev/null

_func="${0##*/}"
declare -F "${_func}" &>/dev/null || { echo -e >&2 "Function ${CDY}$_func${CN} not found."; exit 255; }
"${_func}" "$@"
17 changes: 17 additions & 0 deletions guest/fs-root/sf/bin/find_subdomains
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /bin/bash

# find_subdomain .foobar.com | anew | resolv
# find_subdomain @gmail.com | anew

_find_subdomains() {
local d="${1//./\\.}"
local rexf='[0-9a-zA-Z_.-]{0,64}'"${d}"
local rex="$rexf"'([^0-9a-zA-Z_]{1}|$)'
[ $# -le 0 ] && { echo -en >&2 "Extract sub-domains from all files (or stdin)\nUsage : find_subdomains <apex-domain> <file>\nExample: find_subdomain .com | anew"; return; }
shift 1
[ $# -le 0 ] && [ -t 0 ] && set -- .
command -v rg >/dev/null && { rg -oaIN --no-heading "$rex" "$@" | grep -Eao "$rexf"; return; }
grep -Eaohr "$rex" "$@" | grep -Eo "$rexf"
}

_find_subdomains "$@"
47 changes: 47 additions & 0 deletions guest/fs-root/sf/bin/funcs_extra.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#! /bin/bash

addfileextension() {
local fn="${1:?}"
local r

r=$(file -b --extension "$fn")
r="${r%%\/*}"

[[ "$r" == "???" ]] && {
r=$(file -b "$fn")
if [[ "$r" == *Zip* ]]; then
r="zip"
elif [[ "$r" == *MIME* ]]; then
r="mime"
elif [[ "$r" == *"very long lines"* ]]; then
r="csv"
elif [[ "$r" == *"OOXML"* ]]; then
r="docx"
elif [[ "$r" == *"Office Word"* ]]; then
r="doc"
elif [[ "$r" == *"Excel"* ]]; then
r="xlsx"
elif [[ "$r" == *"MP4"* ]]; then
r="mp4"
elif [[ "$r" == *"HTML"* ]]; then
r="html"
elif [[ "$r" == *"HEIF"* ]]; then
r="heif"
elif [[ "$r" == *"EMF"* ]]; then
r="emf"
elif [[ "$r" == *" text"* ]]; then
r="txt"
else
unset r
fi
}
[[ -z $r ]] && { echo >&2 "Unknown file type: $fn"; return; }

[[ "$fn" =~ .*$r$ ]] && return
mv "$fn" "$fn.$r"
}

crt() {
[ $# -ne 1 ] && { echo >&2 "crt <domain-name>"; return 255; }
curl -s "https://crt.sh/?q=${1:?}&output=json" --compressed | jq -r '.[].common_name,.[].name_value' | anew | sed 's/^\*\.//g' | tr '[:upper:]' '[:lower:]'
}
8 changes: 8 additions & 0 deletions guest/fs-root/sf/bin/io2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

source /sf/bin/funcs.sh
source /sf/bin/funcs_ip.sh 2>/dev/null

_func="${0##*/}"
declare -F "${_func}" &>/dev/null || { echo -e >&2 "Function ${CDY}$_func${CN} not found."; exit 255; }
"${_func}" "$@"
8 changes: 8 additions & 0 deletions guest/fs-root/sf/bin/ptr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

source /sf/bin/funcs.sh
source /sf/bin/funcs_ip.sh 2>/dev/null

_func="${0##*/}"
declare -F "${_func}" &>/dev/null || { echo -e >&2 "Function ${CDY}$_func${CN} not found."; exit 255; }
"${_func}" "$@"
8 changes: 8 additions & 0 deletions guest/fs-root/sf/bin/rdns
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

source /sf/bin/funcs.sh
source /sf/bin/funcs_ip.sh 2>/dev/null

_func="${0##*/}"
declare -F "${_func}" &>/dev/null || { echo -e >&2 "Function ${CDY}$_func${CN} not found."; exit 255; }
"${_func}" "$@"
8 changes: 8 additions & 0 deletions guest/fs-root/sf/bin/resolv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

source /sf/bin/funcs.sh
source /sf/bin/funcs_ip.sh 2>/dev/null

_func="${0##*/}"
declare -F "${_func}" &>/dev/null || { echo -e >&2 "Function ${CDY}$_func${CN} not found."; exit 255; }
"${_func}" "$@"

0 comments on commit 2fff85b

Please sign in to comment.