103 lines
2.3 KiB
Bash
Executable File
103 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
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
|
|
|
|
run nmcli device set "$local_iface" managed no
|
|
clean "nmcli device set "$local_iface" managed yes"
|
|
|
|
run ip a add "$net.$host_ip/$netmask" dev "$local_iface"
|
|
clean "ip a del "$net.$host_ip/$netmask" dev $local_iface"
|
|
|
|
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/$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 "$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
|