This commit is contained in:
ilya 2025-10-20 15:58:08 +02:00
parent 04e2034121
commit 3d28041460
2 changed files with 89 additions and 24 deletions

111
gw.sh
View File

@ -1,37 +1,102 @@
#!/bin/bash
. driglibash-base
if [ "$#" -ne 2 ] ; then
yell "Missing 2 parameters"
die "Usage: $0 <local_iface> <net_iface>"
declare -A usage
declare -A varia
version="beta 1.0"
sumary="$0 [options]"
usage[l]="Locale iface"
varia[l]=local_iface
usage[w]="wan iface (must be already configured)"
varia[w]=wan_iface
wan_iface=
usage[d]="dhcp on local iface"
varia[d]=enable_dhcp
enable_dhcp=false
usage[H]="hostapd on local iface"
varia[H]=enable_hostapd
enable_hostapd=false
usage[n]="Network part of ip (without last dot). ONLY classes A,B,C or D allowed"
varia[n]=net
net="192.168.99"
usage[i]="Host part of local_iface IP (without first dot)"
varia[i]=host_ip
host_ip=254
usage[s]="SSID of wifi network"
varia[s]=ssid
ssid="The candy cave charliiiiiiiie!"
usage[p]="PSK of wifi network"
varia[p]=psk
psk="Ho! They stole my kidney :("
. driglibash-args
dots=${net//[^.]}
netmask=$((${#dots}*8+8))
if [ -z "$local_iface" ] ; then
die "You muste provide a local iface (-l)"
fi
root_or_die
local_iface="$1"
net_iface="$2"
net="192.168.99"
run sysctl net.ipv4.ip_forward=1
#clean "sysctl net.ipv4.ip_forward=1"
run nmcli device set "$local_iface" managed no
clean "nmcli device set "$local_iface" managed yes"
run ip a add $net.254/24 dev "$local_iface"
clean "ip a del $net.254/24 dev $local_iface"
run ip a add "$net.$host_ip/$netmask" dev "$local_iface"
clean "ip a del "$net.$host_ip/$netmask" dev $local_iface"
# For dhcp offers
run iptables -A OUTPUT -d 255.255.255.255/32 -j ACCEPT
if [ -z "$wan_iface" ] ; then
run sysctl net.ipv4.ip_forward=1
clean "sysctl net.ipv4.ip_forward=0"
run iptables -A OUTPUT -d $net.0/24 -j ACCEPT
run iptables -A INPUT -s $net.0/24 -j ACCEPT
run iptables -A INPUT -s 255.255.255.255 -j ACCEPT
run iptables -A INPUT -i "$local_iface" -j ACCEPT
run iptables -A OUTPUT -d $net.0/$netmask -j ACCEPT
run iptables -A INPUT -s $net.0/$netmask -j ACCEPT
run iptables -A INPUT -s 255.255.255.255 -j ACCEPT
run iptables -A INPUT -i "$local_iface" -j ACCEPT
run iptables -t nat -A POSTROUTING -o "$net_iface" -j MASQUERADE
run iptables -A FORWARD -i $net_iface -o $local_iface -m state --state RELATED,ESTABLISHED -j ACCEPT
run iptables -A FORWARD -i $local_iface -o $net_iface -j ACCEPT
run dnsmasq --dhcp-range=$net.100,$net.199,10m -d --server=9.9.9.9 --listen-address $net.254 --interface "$local_iface" -p0
run iptables -t nat -A POSTROUTING -o "$wan_iface" -j MASQUERADE
run iptables -A FORWARD -i "$wan_iface" -o "$local_iface" -m state --state RELATED,ESTABLISHED -j ACCEPT
run iptables -A FORWARD -i "$local_iface" -o "$wan_iface" -j ACCEPT
fi
if $enable_dhcp ; then
# For dhcp offers
run iptables -A OUTPUT -d 255.255.255.255/32 -j ACCEPT
run dnsmasq "--dhcp-range=$net.100,$net.199,1m" --server=9.9.9.9 -q --listen-address "$net.$host_ip" --interface "$local_iface" -p0 -d &
clean "kill %1"
fi
if $enable_hostapd ; then
# Write config
hostapd_config="$(mktemp)"
echo >"$hostapd_config" <<-EOF
interface=$local_iface
ctrl_interface=/var/run/hostapd
hw_mode=g
channel=1
wpa=2
ssid=$ssid
wpa_passphrase=$psk
wpa_key_mgmt=WPA-PSK WPA-EAP
EOF
hostapd -d "$hostapd_config" &
clean "kill %2"
fi
echo "PRESS CTRL+C TO QUIT"
while true ; do
sleep 100000000
done
clean

View File

@ -26,7 +26,7 @@ echo -n '$auth' | base64 -d > ~/.Xauthority
if [ -n "\$(find ~/.mails/collected_addresses.txt -mtime +24)" ] ; then
echo 'Recollect mail addresses'
(notmuch address --output sender '*' ; notmuch address --output recipients '*') | grep -vP "<.*[\x00-\x1F\x7F-\xFF].*>" | grep -vP "[\x00-\x1F\x7F-\xFF]\S*@" | grep -vP "@\S*[\x00-\x1F\x7F-\xFF]" | sort -u > ~/.mails/collected_addresses.txt
(cat ~/.mails/collected_addresses.txt ; notmuch address --output sender '*' ; notmuch address --output recipients '*') | grep -vP "<.*[\x00-\x1F\x7F-\xFF].*>" | grep -vP "[\x00-\x1F\x7F-\xFF]\S*@" | grep -vP "@\S*[\x00-\x1F\x7F-\xFF]" | sort -u > ~/.mails/collected_addresses.txt
fi
birthday_reminder ~/.contacts/bdays/collection-root/dav/4702d4b7-8edd-7b56-ab9c-c11a64d883a3 >/dev/null
syncmails