init (wip)
This commit is contained in:
15
conf/dhcpd.conf
Normal file
15
conf/dhcpd.conf
Normal file
@@ -0,0 +1,15 @@
|
||||
option domain-name-servers <TPL:IP4_DNS0>, <TPL:IP4_DNS1>;
|
||||
default-lease-time 14440;
|
||||
ddns-update-style none;
|
||||
deny bootp;
|
||||
|
||||
shared-network <TPL:WIFI_DEVICE> {
|
||||
subnet <TPL:IP4_NAT_PREFIX>.0
|
||||
netmask 255.255.255.0 {
|
||||
option routers <TPL:IP4_NAT_PREFIX>.1;
|
||||
option subnet-mask 255.255.255.0;
|
||||
pool {
|
||||
range <TPL:IP4_NAT_PREFIX>.2 <TPL:IP4_NAT_PREFIX>.254;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
conf/hostapd.conf
Normal file
12
conf/hostapd.conf
Normal file
@@ -0,0 +1,12 @@
|
||||
interface=<TPL:WIFI_DEVICE>
|
||||
ssid=<TPL:WIFI_SSID>
|
||||
hw_mode=g
|
||||
channel=6
|
||||
macaddr_acl=0
|
||||
auth_algs=1
|
||||
ignore_broadcast_ssid=0
|
||||
wpa=2
|
||||
wpa_passphrase=<TPL:WIFI_PASSPHRASE>
|
||||
wpa_key_mgmt=WPA-PSK
|
||||
wpa_pairwise=TKIP
|
||||
rsn_pairwise=CCMP
|
||||
6
conf/radvd.conf
Normal file
6
conf/radvd.conf
Normal file
@@ -0,0 +1,6 @@
|
||||
interface <TPL:WIFI_DEVICE>
|
||||
{
|
||||
AdvSendAdvert on;
|
||||
prefix <TPL:IP6_NET>/64 { };
|
||||
RDNSS <TPL:IP6_DNS0> <TPL:IP6_DNS1> { };
|
||||
};
|
||||
215
conf/ynh-hotspot
Normal file
215
conf/ynh-hotspot
Normal file
@@ -0,0 +1,215 @@
|
||||
#!/bin/bash
|
||||
### BEGIN INIT INFO
|
||||
# Provides: ynh-hotspot
|
||||
# Required-Start: $network $remote_fs $syslog
|
||||
# Required-Stop: $network $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Set prerequisites for wifi hotspot.
|
||||
# Description: Set prerequisites for wifi hotspot.
|
||||
### END INIT INFO
|
||||
|
||||
is_ndproxy_set() {
|
||||
proxy=$(ip -6 neigh show proxy)
|
||||
[ ! -z "${proxy}" ]
|
||||
}
|
||||
|
||||
is_nat_set() {
|
||||
iptables -nt nat -L POSTROUTING | grep -q MASQUERADE
|
||||
}
|
||||
|
||||
is_ip4nataddr_set() {
|
||||
ip a s dev <TPL:WIFI_DEVICE> | grep -q <TPL:IP4_NAT_PREFIX>.1/24
|
||||
}
|
||||
|
||||
is_ip6addr_set() {
|
||||
ip a s dev <TPL:WIFI_DEVICE> | grep -q <TPL:IP6_ADDR>/64
|
||||
}
|
||||
|
||||
is_forwarding_set() {
|
||||
ip6=$(sysctl net.ipv6.conf.all.forwarding | awk '{ print $NF; }')
|
||||
ip4=$(sysctl net.ipv4.conf.all.forwarding | awk '{ print $NF; }')
|
||||
[ ${ip6} -eq 1 -a ${ip4} -eq 1 ]
|
||||
}
|
||||
|
||||
is_hostapd_running() {
|
||||
service hostapd status &> /dev/null
|
||||
}
|
||||
|
||||
is_radvd_running() {
|
||||
service radvd status &> /dev/null
|
||||
}
|
||||
|
||||
is_dhcpd_running() {
|
||||
service isc-dhcp-server status &> /dev/null
|
||||
}
|
||||
|
||||
is_running() {
|
||||
is_ndproxy_set && is_nat_set && is_forwarding_set\
|
||||
&& is_hostapd_running && is_radvd_running && is_dhcpd_running
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
if is_running; then
|
||||
echo "Already correctly set"
|
||||
else
|
||||
if ! is_ndproxy_set; then
|
||||
echo "Set NDP proxy"
|
||||
ip -6 neigh add proxy <TPL:IP6_ADDR> dev <TPL:WIFI_DEVICE>
|
||||
fi
|
||||
|
||||
if ! is_nat_set; then
|
||||
echo "Set NAT"
|
||||
iptables -t nat -A POSTROUTING -o <TPL:WIRED_DEVICE> -j MASQUERADE
|
||||
fi
|
||||
|
||||
if ! is_ip4nataddr_set; then
|
||||
echo "Set IPv4 NAT address"
|
||||
ip a a <TPL:IP4_NAT_PREFIX>.1/24 dev <TPL:WIFI_DEVICE>
|
||||
fi
|
||||
|
||||
if ! is_ip6addr_set; then
|
||||
echo "Set IPv6 address"
|
||||
ip a a <TPL:IP6_ADDR>/64 dev <TPL:WIFI_DEVICE>
|
||||
fi
|
||||
|
||||
if ! is_forwarding_set; then
|
||||
echo "Set forwarding"
|
||||
sysctl -w net.ipv6.conf.all.forwarding=1 &> /dev/null
|
||||
sysctl -w net.ipv4.conf.all.forwarding=1 &> /dev/null
|
||||
fi
|
||||
|
||||
if ! is_hostapd_running; then
|
||||
echo "Run hostapd"
|
||||
service hostapd start
|
||||
fi
|
||||
|
||||
# must be running after hostapd
|
||||
if ! is_radvd_running; then
|
||||
echo "Run radvd"
|
||||
sleep 1
|
||||
service radvd start
|
||||
fi
|
||||
|
||||
# "options routers" addr (is_ip6addr_set) must be set before
|
||||
if ! is_dhcpd_running; then
|
||||
echo "Run dhcpd"
|
||||
service isc-dhcp-server start
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
if is_ndproxy_set; then
|
||||
echo "Unset NDP proxy"
|
||||
ip -6 neigh del proxy <TPL:IP6_ADDR> dev <TPL:WIFI_DEVICE>
|
||||
fi
|
||||
|
||||
if is_nat_set; then
|
||||
echo "Unset NAT"
|
||||
iptables -t nat -D POSTROUTING -o <TPL:WIRED_DEVICE> -j MASQUERADE
|
||||
fi
|
||||
|
||||
if is_ip4nataddr_set; then
|
||||
echo "Unset IPv4 NAT address"
|
||||
ip a d <TPL:IP4_NAT_PREFIX>.1/24 dev <TPL:WIFI_DEVICE>
|
||||
fi
|
||||
|
||||
if is_ip6addr_set; then
|
||||
echo "Unset IPv6 address"
|
||||
ip a d <TPL:IP6_ADDR>/64 dev <TPL:WIFI_DEVICE>
|
||||
fi
|
||||
|
||||
if is_forwarding_set; then
|
||||
echo "Unset forwarding"
|
||||
sysctl -w net.ipv6.conf.all.forwarding=0 &> /dev/null
|
||||
sysctl -w net.ipv4.conf.all.forwarding=0 &> /dev/null
|
||||
fi
|
||||
|
||||
if is_hostapd_running; then
|
||||
echo "Stop hostapd"
|
||||
service hostapd stop
|
||||
fi
|
||||
|
||||
if is_radvd_running; then
|
||||
echo "Stop radvd"
|
||||
service radvd stop
|
||||
fi
|
||||
|
||||
if is_dhcpd_running; then
|
||||
echo "Stop dhcpd"
|
||||
service isc-dhcp-server stop
|
||||
fi
|
||||
;;
|
||||
restart)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
status)
|
||||
exitcode=0
|
||||
|
||||
if is_ndproxy_set; then
|
||||
echo "NDP proxy is correctly set"
|
||||
else
|
||||
echo "NDP proxy is NOT set"
|
||||
exitcode=1
|
||||
fi
|
||||
|
||||
if is_nat_set; then
|
||||
echo "NAT is correctly set"
|
||||
else
|
||||
echo "NAT is NOT set"
|
||||
exitcode=1
|
||||
fi
|
||||
|
||||
if is_ip4nataddr_set; then
|
||||
echo "IPv4 NAT address is correctly set"
|
||||
else
|
||||
echo "IPv4 NAT address is NOT set"
|
||||
exitcode=1
|
||||
fi
|
||||
|
||||
if is_ip6addr_set; then
|
||||
echo "IPv6 address is correctly set"
|
||||
else
|
||||
echo "IPv6 address is NOT set"
|
||||
exitcode=1
|
||||
fi
|
||||
|
||||
if is_forwarding_set; then
|
||||
echo "Forwarding is correctly set"
|
||||
else
|
||||
echo "Forwarding is NOT set"
|
||||
exitcode=1
|
||||
fi
|
||||
|
||||
if is_hostapd_running; then
|
||||
echo "Hostapd is running"
|
||||
else
|
||||
echo "Hostapd is NOT running"
|
||||
exitcode=1
|
||||
fi
|
||||
|
||||
if is_radvd_running; then
|
||||
echo "Radvd is running"
|
||||
else
|
||||
echo "Radvd is NOT running"
|
||||
exitcode=1
|
||||
fi
|
||||
|
||||
if is_dhcpd_running; then
|
||||
echo "Dhcpd is running"
|
||||
else
|
||||
echo "Dhcpd is NOT running"
|
||||
exitcode=1
|
||||
fi
|
||||
|
||||
exit ${exitcode}
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|status}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user