added initial config files for mt300n

main
resneptacle 3 weeks ago
parent e4da81c96a
commit 75ae31bd0b

File diff suppressed because it is too large Load Diff

@ -0,0 +1 @@
[ "$ACTION" = "motion" ] && logger webcam motion event

@ -0,0 +1,22 @@
#!/bin/sh /etc/rc.common
# Init script for vmodem-cghmn
USE_PROCD=1
START=10
STOP=15
start_service () {
procd_open_instance vmodem-cghmn
procd_set_param command /bin/bash /opt/vmodem-cghmn/vmodem-cghmn.sh
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param pidfile /var/run/vmodem-cghmn.pid
procd_set_param term_timeout 3
procd_close_instance
}

@ -0,0 +1,3 @@
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
::askconsole:/usr/libexec/login.sh

@ -0,0 +1,8 @@
. /lib/functions.sh
. /lib/functions/migrations.sh
remove_devicename_leds "rt2800soc-phy0" "rt2800pci-phy0"
migrations_apply system
exit 0

@ -0,0 +1,25 @@
#
# Copyright (C) 2012 OpenWrt.org
#
. /lib/functions.sh
fix_checksum() {
local kernel_size=$(sed -n 's/mtd[0-9]*: \([0-9a-f]*\).*"kernel".*/\1/p' /proc/mtd)
[ "$kernel_size" ] && mtd -c 0x$kernel_size fix$1 firmware
}
board=$(board_name)
case "$board" in
dlink,dap-1522-a1)
fix_checksum wrg
;;
dlink,dch-m225|\
dlink,dir-645|\
dlink,dir-860l-b1|\
samsung,cy-swr1100)
fix_checksum seama
;;
esac

@ -0,0 +1,193 @@
#!/bin/sh
# Set router defaults runing first boot
# Ensure this script is only run once
if CONFIGED=$(uci get system.@system[0].cghmn_is_configured 2>/dev/null) && [ "$CONFIGED" = "1" ]; then
exit 0
fi
# Get last four letters of eth0 MAC
FULL_MAC=$(ip link show eth0 | awk '/link\/ether/ { gsub(":",""); print substr($2,0,4) ":" substr($2,5,4) ":" substr($2,9,4) }')
MAC_LASTFOUR=$(echo "${FULL_MAC}" | awk -F':' '{ print $3 }')
NEW_HOSTNAME="CGHMN-Node-$MAC_LASTFOUR"
# Turn last four letters of MAC into IPv4 address suffix
LOCAL_IP4_FROM_MAC=$(printf "%d.%d" $(echo "${MAC_LASTFOUR}" | awk '{ print "0x" substr($0,0,2) " 0x" substr($0,3,2) }'))
# Static variables used to configure the Wireguard tunnel
WG_PEER_ADDRESS="insert.target.server.domain"
WG_PEER_PUBKEY="VAVFX88DKGoO2naiWml1jepF7MVrIjDAbMhhYq5S1nQ="
# Wireguard IPv4 variables
WG_TUNNEL_INNER_SUBNET4="10.234."
WG_TUNNEL_INNER_SUBNET4_SIZE="16"
WG_TUNNEL_INNER_LOCAL_IP4="${WG_TUNNEL_INNER_SUBNET4}${LOCAL_IP4_FROM_MAC}"
WG_TUNNEL_INNER_PEER_IP4="${WG_TUNNEL_INNER_SUBNET4}.0.1"
WG_TUNNEL_REMOTE_SUBNET4="10.201.0.0/23"
# Wireguard IPv6 variables
WG_TUNNEL_INNER_SUBNET6="fd38:f85d:a2fd::"
WG_TUNNEL_INNER_SUBNET6_SIZE="64"
WG_TUNNEL_INNER_LOCAL_IP6="${WG_TUNNEL_INNER_SUBNET6}${FULL_MAC}"
WG_TUNNEL_INNER_PEER_IP6="${WG_TUNNEL_INNER_SUBNET6}ffff:ffff:ffff:ffff"
WG_TUNNEL_REMOTE_SUBNET6="2001:470:5168:201::/64"
# Generate new Wireguard private key for this node
WG_PRIVKEY="$(wg genkey)"
# Static variables used to configure the VXLAN interface
VXLAN_LOCAL_IP="${WG_TUNNEL_INNER_LOCAL_IP6}"
VXLAN_PEER_IP="${WG_TUNNEL_INNER_PEER_IP6}"
VXLAN_ID="101"
# Before adding new config, clear old firewall zones and rules
while uci -q delete firewall.@rule[0]; do :; done
while uci -q delete firewall.@zone[0]; do :; done
while uci -q delete firewall.@forwarding[0]; do :; done
# Batch-add most UCI configuration next
uci -q batch <<EOUCI
set system.@system[0].hostname='${NEW_HOSTNAME}'
# -- Create firewall zones -- #
# WAN zone (allow input for management from regular home network)
add firewall zone
set firewall.@zone[-1].name='wan'
set firewall.@zone[-1].input='ACCEPT'
set firewall.@zone[-1].output='ACCEPT'
set firewall.@zone[-1].forward='REJECT'
add_list firewall.@zone[-1].network='wan'
# Retro LAN zone (default deny any traffic and add firewall rule for forwardings)
add firewall zone
set firewall.@zone[-1].name='retro_lan'
set firewall.@zone[-1].input='REJECT'
set firewall.@zone[-1].output='REJECT'
set firewall.@zone[-1].forward='REJECT'
add_list firewall.@zone[-1].network='cghmn_vxlan'
add_list firewall.@zone[-1].network='retro_lan'
# Outer transport tunnel zone outside of Retro LAN
add firewall zone
set firewall.@zone[-1].name='tunnel'
set firewall.@zone[-1].input='REJECT'
set firewall.@zone[-1].output='ACCEPT'
set firewall.@zone[-1].forward='REJECT'
add_list firewall.@zone[-1].network='cghmn_wg'
add_list firewall.@zone[-1].network='cghmn_vxlan'
# PPP client zone
add firewall zone
set firewall.@zone[-1].name='ppp_client'
set firewall.@zone[-1].input='ACCEPT'
set firewall.@zone[-1].output='ACCEPT'
set firewall.@zone[-1].forward='REJECT'
set firewall.@zone[-1].masq='1'
add_list firewall.@zone[-1].network='ppp_daemon'
# -- Create network forwarding -- #
# Allow forwarding from local PPP clients to the Retro LAN and WAN
add firewall forwarding
set firewall.@forwarding[-1].src='ppp_client'
add_list firewall.@forwarding[-1].dest='retro_lan'
add_list firewall.@forwarding[-1].dest='wan'
# -- Create firewall rules -- #
# Allow VXLAN packages on transport network
add firewall rule
set firewall.@rule[-1].name='Allow incoming VXLAN packets'
set firewall.@rule[-1].proto='udp'
set firewall.@rule[-1].src='tunnel'
set firewall.@rule[-1].target='ACCEPT'
set firewall.@rule[-1].family='ipv6'
set firewall.@rule[-1].dest_port='4789'
set firewall.@rule[-1].src_ip='${WG_TUNNEL_INNER_PEER_IP6}'
# -- Create interfaces -- #
# Delete predefined interfaces
delete network.wan
delete network.wan6
delete network.lan
# Create WAN interface on default WAN network port
set network.wan=interface
set network.wan.proto='dhcp'
set network.wan.device='eth0.2'
# Create Wireguard tunnel interface
set network.cghmn_wg=interface
set network.cghmn_wg.proto='wireguard'
set network.cghmn_wg.private_key='${WG_PRIVKEY}'
set network.cghmn_wg.mtu='1634'
add_list network.cghmn_wg.addresses='${WG_TUNNEL_INNER_LOCAL_IP6}/${WG_TUNNEL_INNER_SUBNET6_SIZE}'
add_list network.cghmn_wg.addresses='${WG_TUNNEL_INNER_LOCAL_IP4}/${WG_TUNNEL_INNER_SUBNET4_SIZE}'
# Create VXLAN interface on Wireguard tunnel
set network.cghmn_vxlan=interface
set network.cghmn_vxlan.proto='vxlan6'
set network.cghmn_vxlan.srcportmin='4789'
set network.cghmn_vxlan.mtu='1500'
set network.cghmn_vxlan.learning='0'
set network.cghmn_vxlan.ip6addr='${VXLAN_LOCAL_IP}'
set network.cghmn_vxlan.peer6addr='${VXLAN_PEER_IP}'
set network.cghmn_vxlan.vid='${VXLAN_ID}'
# Create unmanaged Retro LAN bridge interface
set network.retro_lan=interface
set network.retro_lan.proto='none'
set network.retro_lan.device='br-retrolan'
# Create PPP interface for local vmodem dialin
set network.ppp_daemon=interface
set network.ppp_daemon.proto='none'
set network.ppp_daemon.device='ppp0'
# -- Configure actual network interfaces -- #
# Create and configure Retro LAN Linux bridge spanning the VXLAN and default LAN network port
add network device
set network.@device[-1].type='bridge'
set network.@device[-1].name='br-retrolan'
add_list network.@device[-1].ports='cghmn_vxlan'
add_list network.@device[-1].ports='eth0.1'
# -- Add Wireguard remote peer -- #
# Remote CGHMN Wireguard peer
add network wireguard_cghmn_wg
set network.@wireguard_cghmn_wg[-1].description='CGHMN Server'
set network.@wireguard_cghmn_wg[-1].persistent_keepalive='15'
set network.@wireguard_cghmn_wg[-1].route_allowed_ips='1'
set network.@wireguard_cghmn_wg[-1].public_key='${WG_PEER_PUBKEY}'
set network.@wireguard_cghmn_wg[-1].endpoint_host='${WG_PEER_ADDRESS}'
add_list network.@wireguard_cghmn_wg[-1].allowed_ips='${WG_TUNNEL_INNER_SUBNET6}/${WG_TUNNEL_INNER_SUBNET6_SIZE}'
add_list network.@wireguard_cghmn_wg[-1].allowed_ips='${WG_TUNNEL_INNER_SUBNET4}/${WG_TUNNEL_INNER_SUBNET4_SIZE}'
add_list network.@wireguard_cghmn_wg[-1].allowed_ips='${WG_TUNNEL_REMOTE_SUBNET6}'
add_list network.@wireguard_cghmn_wg[-1].allowed_ips='${WG_TUNNEL_REMOTE_SUBNET4}'
# -- Set some WiFi defaults -- #
delete wireless.default_radio0
set wireless.radio0.band='2g'
set wireless.radio0.channel='1'
set wireless.radio0.legacy_rates='1'
set wireless.wifinet0=wifi-iface
set wireless.wifinet0.device='radio0'
set wireless.wifinet0.mode='ap'
set wireless.wifinet0.ssid='retronet'
set wireless.wifinet0.encryption='psk-mixed'
set wireless.wifinet0.key='${FULL_MAC}'
set wireless.wifinet0.network='retro_lan'
set wireless.wifinet0.disabled='1'
# -- DNSmasq config -- #
set dhcp.@dnsmasq[0].localservice='0'
set system.@system[0].cghmn_is_configured=1
EOUCI
# Enable the vmodem init script
service vmodem-cghmn enable || true

@ -0,0 +1,14 @@
#!/bin/bash
echo "Hello World Demo Box!"
echo "---------------------"
echo
echo "You have just successfully dialed this virtual box!"
echo
echo "Please enter your name: "
read -r -e -p "User? " username
echo
echo "Hello, $username!"
echo
echo "Thank you for visiting! Bye!"
sleep 1

@ -0,0 +1,45 @@
#!/bin/bash
# RUN PPPD DAEMON
#
# Original by Oliver Molini 2021
# http://www.steptail.com/guides:virtual_modem:script
#
# Billy Stoughton II for bug fixes and contributions
#
# Modified and partially rewritten by Snep (contact-snep@diskcat.com) 2025
# for the CGHMN project
#
# Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
# https://creativecommons.org/licenses/by-nc-sa/4.0/
#
# Note on PPPD settings:
# - Make sure the noauth option is set (instead of auth)
# - Make sure DNS servers are defined (add ms-dns 1.2.3.4 twice)
#
# Variable: lcpidle
# Specifies the idle timeout period in seconds for lcp-echo-interval.
# This is to ensure that pppd will not run indefinitely after sudden
# hangup and will relinquish control back to the vmodem.sh.
#
# Default: lcpidle=5
lcpidle=5
#
# Trumpet Winsock 3.0 revision D for Windows 3.1
# by default requires a fake login shell.
#
# Windows 95 and 98 will not care for a login shell
# unless specifically told to expect one.
#
printf "\n%s****\n" "$(uname -sn)"
printf "\nUsername: "; sleep 1
printf "\nPassword: "; sleep 1
printf "\nStarting pppd..."
printf "\nPPP>"
# End of fake login prompt.
# Run PPP daemon and establish a link.
pppd noauth nodetach local lock lcp-echo-interval $lcpidle lcp-echo-failure 3 proxyarp ms-dns 100.64.0.1 100.64.0.1:100.64.0.2 "/dev/${SERIAL_PORT}" "${BAUD}"
printf "\nPPP link terminated.\n"

@ -0,0 +1,368 @@
#!/bin/bash
#
# --------------------------------
# VMODEM - Virtual Modem bootstrap
# --------------------------------
# Original by Oliver Molini 2021
# http://www.steptail.com/guides:virtual_modem:script
#
# Billy Stoughton II for bug fixes and contributions
#
# Modified and partially rewritten by Snep (contact-snep@diskcat.com) 2025
# for the CGHMN project
#
# Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
# https://creativecommons.org/licenses/by-nc-sa/4.0/
# Move to directory of script
cd "$(dirname "$0")" || exit
# Script version
vmodver=cghmn-1.0
# CONFIGURATION
# -----------------------
# Variable: SERIAL_PORT
# SERIAL_PORT specifies which local serial device to use.
# For example, "ttyUSB0" will tell the script to use
# to use /dev/ttyUSB0 for communication.
# Common values: ttyUSB0 or ttyAMA0
#
SERIAL_PORT="${SERIAL_PORT:-ttyUSB0}"
# Variable: BAUD
# BAUD will tell the script to open the serial port at
# specified symbol rate. When connecting, make sure
# your client computer uses the same BAUD than what
# has been specified here.
# Common BAUD rates: 9600, 19200, 38400, 57600
#
# Default:
# BAUD=57600
#
BAUD="${BAUD:-57600}"
# Variable: LOGIN_ENABLED
# If set to "yes", the LOGIN command is enabled,
# which allows remote users to log in to this
# machine with their Unix username and password
LOGIN_ENABLED="no"
# Variable: PPP_NUMBER
# If set to a number, when this number is called
# by the computer on the serial line, a PPP daemon
# will be spawned
PPP_DIAL_NUMBER="1"
# Variable: TERM
# Tells the script and environment which type of terminal to emulate.
# It is only useful to change this, if you're using a serial
# terminal to connect to this script. If you're connecting form a ANSI
# cabable machine such as DOS, you may want to use TERM="ansi"
#
TERM="vt100"
# EXPORT SHELL VARS
# -----------------
export SERIAL_PORT
export BAUD
export TERM
# FUNCTIONS
# ---------
#
#INITIALIZE SERIAL SETTINGS
ttyinit () {
exec 99>&-
stty -F "/dev/${SERIAL_PORT}" "${BAUD}"
stty -F "/dev/${SERIAL_PORT}" sane
stty -F "/dev/${SERIAL_PORT}" raw
stty -F "/dev/${SERIAL_PORT}" -echo -icrnl clocal
exec 99<>"/dev/${SERIAL_PORT}"
}
# SEND MESSAGE ON SCREEN AND OVER SERIAL
sendtty () {
NEWLINE_STR_CONSOLE="\n"
NEWLINE_STR_SERIAL="\x0d\x0a"
if [ "${1}" = "-n" ]; then
NEWLINE_STR_CONSOLE=""
NEWLINE_STR_SERIAL=""
shift
fi
echo -en "${1}${NEWLINE_STR_CONSOLE}";
echo -en "${1}${NEWLINE_STR_SERIAL}" > "/dev/${SERIAL_PORT}"
}
# Sends an AT status message or status code as reply
sendstatus () {
# Default to ERROR if not code given
RESULT_CODE="${1:-ERROR}"
if [ "${VERBOSITY:-verbose}" = "verbose" ]; then
sendtty "${RESULT_CODE}";
elif [ "${VERBOSITY}" = "numeric" ]; then
# Translate readable result codes into numeric ones if requested
if [ "${RESULT_CODE}" == "OK" ]; then sendtty 0
elif [ "${RESULT_CODE}" == "CONNECT" ]; then sendtty 1
elif [ "${RESULT_CODE}" == "RING" ]; then sendtty 2
elif [ "${RESULT_CODE}" == "NO CARRIER" ]; then sendtty 3
elif [ "${RESULT_CODE}" == "ERROR" ]; then sendtty 4
elif [ "${RESULT_CODE}" == "CONNECT 1200" ]; then sendtty 5
elif [ "${RESULT_CODE}" == "NO DIALTONE" ]; then sendtty 6
elif [ "${RESULT_CODE}" == "BUSY" ]; then sendtty 7
elif [ "${RESULT_CODE}" == "NO ANSWER" ]; then sendtty 8
else
echo "> Unspecified result code '${RESULT_CODE}'" >&2
sendtty "${RESULT_CODE}"
fi
fi
}
# Launch a script with getty
exec_with_getty () {
/sbin/getty -L "${SERIAL_PORT}" "${BAUD}" "${TERM}" -n -l "${1}"
return $?
}
# Dials a number (calls a number) from an ATD* command
dial () {
AT_COMMAND="${1}"
NUMBER="$( grep -Eo "[0-9]+" <<< "${AT_COMMAND}" )"
# Ensure number is not blank
if [ -z "${NUMBER}" ]; then
echo "> Blank number dialed" >&2
sendstatus "ERROR"
return 1
fi
DIAL_SCRIPT=""
# Show ringing status if verbose dialing is enabled
if [ "${VERBOSE_DIALING:-yes}" = "yes" ]; then
sendtty "RINGING"
sleep 1
fi
# Check if number is PPP dial number
if [ "${NUMBER}" = "${PPP_DIAL_NUMBER}" ]; then
if [ -f "${PWD}/ppp-cghmn.sh" ]; then
DIAL_SCRIPT="${PWD}/ppp-cghmn.sh"
elif [ -f "${PWD}/ppp.sh" ]; then
DIAL_SCRIPT="${PWD}/ppp.sh"
else
echo "> No pppd handler script found in '${PWD}'" >&2
sendstatus "NO CARRIER"
return
fi
else
# If not a PPP dial number, find script with called number
if [ -f "${PWD}/DIAL_${NUMBER}.sh" ]; then
DIAL_SCRIPT="${PWD}/DIAL_${NUMBER}.sh"
elif [ -f "${PWD}/${NUMBER}.sh" ]; then
DIAL_SCRIPT="${PWD}/${NUMBER}.sh"
else
sendstatus "NO CARRIER"
return
fi
fi
# For compatibility, explicitly tell the terminal to default to CR/LF
# when pressing enter, to avoid cases where the terminal just sends CR.
echo -en "\x1b[20h" > "/dev/${SERIAL_PORT}"
echo "> Executing dial script '${DIAL_SCRIPT}' for number '${NUMBER}'" >&2
# Show connect message
if [ "${VERBOSITY}" = "numeric" ]; then
sendtty "1"
elif [ "${VERBOSE_DIALING:-yes}" = "yes" ]; then
sendtty "CONNECT ${BAUD}"
else
sendtty "CONNECT"
fi
# Call script with getty
exec_with_getty "${DIAL_SCRIPT}"
echo "> Dial script returned with exit code ${?}" >&2
ttyinit
sendstatus "NO CARRIER"
}
export -f sendtty
export -f ttyinit
export -f sendstatus
# Open serial port for use. Allocate file descriptor
# and treat the serial port as a file.
ttyinit
#exec 99<>"/dev/${SERIAL_PORT}"
# Init message
sendtty ""
sendtty "VMODEM - Virtual Modem bootstrap for PPP link v${vmodver}"
sendtty "Connection speed set to ${BAUD} baud"
sendtty ""
sendtty "TYPE HELP FOR COMMANDS"
sendtty "READY."
# Main script loop
while true; do
CHARHEX="$(head -c 1 "/dev/${SERIAL_PORT}" | xxd -p -)"
CHAR="$(echo -e "\x${CHARHEX}")"
# Echo recevied CHARacter to console
echo -n "${CHAR}"
# Echo recevied CHARacter back to serial
if [ "${ECHO_SERIAL:-yes}" = "yes" ]; then
echo -n "${CHAR}" > "/dev/${SERIAL_PORT}"
fi
# Check for end of line on CR or LF
if [ "$CHARHEX" = "0d" ] || [ "$CHARHEX" = "0a" ]; then
# Upper-case entire line
cmd="${BUFFER^^}"
# Clear temporary BUFFERs
BUFFER=
CHAR=
# Write new line to console and serial
if [ "${ECHO_SERIAL:-yes}" = "yes" ]; then
sendtty ""
else
echo ""
fi
#
# --- HAYES EMULATION ---
#
if [[ $cmd == AT* ]]; then
# Handle known AT commands
case "$cmd" in
# Commands that do nothing but return OK
# <Blank line> shall also return OK
# ATA = Answer incoming call
# ATH0 = Modem Hang up (Go On-Hook)
# ATH1 = Modem Pick up (Go Off-Hook)
# ATM0 = Modem speaker always off
# ATM1 = Modem speaker on until carrier detected
# ATM2 = Modem speaker always on
# ATM3 = Modem speaker only on whilst answering
# AT&C0 = Force Carrier-Detect high
# AT&C1 = Let Modem set Carrier-Detect signal
# AT&D0 = Modem ignores DTR line from computer
# AT&D1 = Modem switches to AT mode on DTR on->off transition
# AT&D1 = Modem hangs up and switches to AT mode on DTR on->off transition
# AT&D3 = Modem resets itself on DTR on->off transition
# AT&S0 = Force DSR line high
# AT&S1 = Modem will set DSR high during connected state
# ATSn = Change current register to n
# ATSn=i = Change current register to n and store value i
""|AT|ATA|ATH*|ATM*|AT\&C*|AT\&S*|ATS*) ;;
# ATZ = Restore modem
# ATZn = Restore modem to profile n
# AT&F = Restore modem to factory settings
# AT&Fn = Restore modem to factory settings in profile n
ATZ*|AT\&F*)
ECHO_SERIAL="yes"
VERBOSITY="verbose"
;;
# ATE0 = Disable echo
# ATE1 = Enable echo
ATE|ATE0) ECHO_SERIAL="no" ;;
ATE1) ECHO_SERIAL="yes" ;;
# ATV0 = Disable verbose responses
# ATV1 = Enable verbose responses
ATV|ATV0) VERBOSITY="numeric" ;;
ATV1) VERBOSITY="verbose" ;;
# ATQ0 = Modem returns result codes
# ATQ1 = Modem is quiet, returns no result codes
ATQ|ATQ0) VERBOSITY="verbose" ;;
ATQ1) VERBOSITY="quiet" ;;
# ATX0 = Blind dial, no busy detection, CONNECT when connection established (Hayes Smartmodem 300 compatible result code)
# ATX1 = Blind dial, no busy detection, CONNECT with BAUD rate appended when connection established
# ATX2 = Dial tone detection, no busy detection, CONNECT with BAUD rate appened when connection established
# ATX3 = Blind dial, busy detection, CONNECT with BAUD rate appended when connection established
# ATX4 = Dial tone detection, busy detection, CONNECT with BAUD rate appended when connection established
ATX|ATX0) VERBOSE_DIALING="no" ;;
ATX1|ATX2|ATX3|ATX4) VERBOSE_DIALING="yes" ;;
# ATDn = Dial number
ATD*)
dial "${cmd}"
continue
;;
# Return ERROR on all other (unknown) commands
*)
sendstatus "ERROR"
continue
;;
esac
# Send OK if no other status code was returned earlier
sendstatus "OK"
elif [ "${cmd}" = "HELP" ]; then
sendtty "Command Reference for Virtual Modem Bootstrap v$vmodver"
sendtty ""
sendtty "AT......Tests modem link, prints OK if successful"
sendtty "ATE0....Switch terminal echo off"
sendtty "ATE1....Switch terminal echo on"
sendtty "ATD?....Fork program ?.sh and output on terminal"
sendtty "ATDT1...Open PPPD connection"
sendtty "ATZ.....Reset modem settings"
sendtty "HELP....Display command reference"
[ "${LOGIN_ENABLED}" = "yes" ] && \
sendtty "LOGIN...Fork a new linux login on serial"
sendtty "EXIT....End this script"
sendtty ""
sendtty "To establish connection over PPP, dial 1 using tone dialing (ATDT1)"
sendtty ""
sendtty "READY."
elif [ "${cmd}" = "LOGIN" ]; then
if [ "${LOGIN_ENABLED:-no}" = "yes" ]; then
# Spawn login command on serial if enabled above
exec 99>&-
/sbin/getty -L "${SERIAL_PORT}" "${BAUD}" "${TERM}"
# Reset tty after logout
ttyinit
sendtty ""
sendtty "READY."
else
sendtty "LOGIN is not enabled on this connection."
sendstatus "ERROR"
fi
elif [ "${cmd}" = "EXIT" ] || [ "${cmd}" = "QUIT" ]; then
# Exit script
# If managed by an init-system, this script *should* restart to serve the next connection
sendstatus "OK"
sendtty "BYE"
# Close serial port
exec 99>&-
exit 0
fi
else
# If not CR or LF, append CHARacter to BUFFER
BUFFER="${BUFFER}${CHAR}"
fi
done
# Close serial port
exec 99>&-

@ -0,0 +1,63 @@
#!/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
Loading…
Cancel
Save