You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.1 KiB

#!/bin/sh
set -e
# Quick and dirty command line interface for the most useful commands
# Show help for this script
usage () {
echo "$(basename "${0}") - Helper script for the CGHMN"
echo ""
echo "Usage: $(basename "${0}") <command> [<args>]"
echo ""
echo "Available commands:"
echo " help Show this help"
echo " coninfo Show info required to connect to the CGHMN"
echo " toggle-ppp-internet Toggle internet access for PPP clients on or off"
echo ""
}
# Show info required to connect to the CGHMN
coninfo () {
MY_WG_PUBKEY="$(uci get network.cghmnd_wg.private_key | wg pubkey)"
ETH0_MAC="$(ip link show eth0 | awk '/link\/ether/{ print $2 }')"
echo "[> The following information is required or at least helpful to know when connecting to the CGHMN <]"
echo ""
echo "My primary Ethernet address: ${ETH0_MAC}"
echo "My Wireguard public key: ${MY_WG_PUBKEY}"
echo -n "My Wireguard IP addresses: "
for IP in $(uci get network.cghmnd_wg.addresses); do
echo -ne "${IP}\n "
done
echo ""
}
toggle_ppp_internet () {
PPP_FOWARD_ID="$(uci show firewall.@forwarding[] | awk -F. "/src='ppp_client'/{ print \$2 }")"
if uci -d ";" get "firewall.${PPP_FOWARD_ID}.dest" | grep -qE '^wan;|;wan;|;wan$'; then
uci del_list firewall."${PPP_FOWARD_ID}".dest='wan'
echo "OK, internet is now OFF for PPP clients"
else
uci add_list firewall."${PPP_FOWARD_ID}".dest='wan'
echo "OK, internet is now ON for PPP clients"
fi
}
# Parse command selector
case "${1}" in
-h|--help|help|"")
usage
;;
coninfo)
coninfo
;;
toggle-ppp-internet)
toggle_ppp_internet
;;
*)
echo "Unknown command '${1}'"
echo ""
usage
exit 1
esac