ynh-hotspot 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. #!/bin/bash
  2. #
  3. # Wifi Hotspot app for YunoHost
  4. # Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  5. # Contribute at https://github.com/labriqueinternet/hotspot_ynh
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. # Functions
  20. ## State functions
  21. has_vpnclient_app() {
  22. [ -e /tmp/.ynh-vpnclient-started ]
  23. }
  24. has_ip6delegatedprefix() {
  25. i=${1}
  26. [[ -n "${ynh_ip6_net[${i}]}" ]] && [[ "${ynh_ip6_net[${i}]}" != "none" ]]
  27. }
  28. ip6addrfromdelegatedprefix() {
  29. i=${1}
  30. echo "${ynh_ip6_net[${i}]}${i}001"
  31. }
  32. is_nat_set() {
  33. internet_device=${1}
  34. iptables -w -nvt nat -L POSTROUTING | grep MASQUERADE | grep -q "${internet_device}"
  35. }
  36. is_ip4nataddr_set() {
  37. i=${1}
  38. dev=$(devfromid "${i}")
  39. ip address show dev "${dev}" 2> /dev/null | grep -q "${ynh_ip4_nat_prefix[${i}]}.1/24"
  40. }
  41. is_ip6addr_set() {
  42. i=${1}
  43. dev=$(devfromid "${i}")
  44. ip address show dev "${dev}" 2> /dev/null | grep -q "$(ip6addrfromdelegatedprefix $i)/64"
  45. }
  46. is_ip6firewall_set() {
  47. i=${1}
  48. dev=$(devfromid "${i}")
  49. ip6tables -w -nvL FORWARD | grep DROP | grep -q "${dev}"
  50. }
  51. is_forwarding_set() {
  52. ip6=$(sysctl net.ipv6.conf.all.forwarding | awk '{ print $NF; }')
  53. ip4=$(sysctl net.ipv4.conf.all.forwarding | awk '{ print $NF; }')
  54. [ "${ip6}" -eq 1 -a "${ip4}" -eq 1 ]
  55. }
  56. is_dhcpd6_running() {
  57. i=${1}
  58. $(ps aux | grep "dhcpdv6-ssid${i}" | grep -qv grep)
  59. }
  60. is_dhcpd4_running() {
  61. i=${1}
  62. $(ps aux | grep "dhcpdv4-ssid${i}" | grep -qv grep)
  63. }
  64. is_hostapd_running() {
  65. systemctl is-active hostapd &> /dev/null
  66. }
  67. is_running() {
  68. for i in $(seq 0 $((${ynh_multissid} - 1))); do
  69. ( has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}\
  70. && ( [ "${ynh_ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i} || [ "${ynh_ip6_firewall[${i}]}" -eq 0 ] )\
  71. && is_dhcpd6_running ${i} || ! has_ip6delegatedprefix ${i} )\
  72. && is_ip4nataddr_set ${i} && is_dhcpd4_running ${i}
  73. if [ ! $? -eq 0 ]; then
  74. return 1
  75. fi
  76. done
  77. is_hostapd_running && is_forwarding_set && ( [ -z "${new_internet_device}" ] || is_nat_set "${new_internet_device}" )
  78. }
  79. ## Setters
  80. set_nat() {
  81. internet_device=${1}
  82. iptables -w -t nat -A POSTROUTING -o "${internet_device}" -j MASQUERADE
  83. }
  84. set_ip4nataddr() {
  85. i=${1}
  86. dev=$(devfromid "${i}")
  87. ip address add "${ynh_ip4_nat_prefix[${i}]}.1/24" dev "${dev}"
  88. }
  89. set_ip6addr() {
  90. i=${1}
  91. dev=$(devfromid "${i}")
  92. ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev tun0 &> /dev/null
  93. ip address add "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}"
  94. }
  95. set_ip6firewall() {
  96. i=${1}
  97. dev=$(devfromid "${i}")
  98. ip6tables -w -A FORWARD -i "${dev}" -j ACCEPT
  99. ip6tables -w -A FORWARD -o "${dev}" -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
  100. ip6tables -w -A FORWARD -o "${dev}" -j DROP
  101. }
  102. set_forwarding() {
  103. sysctl -w net.ipv6.conf.all.forwarding=1 > /dev/null
  104. sysctl -w net.ipv4.conf.all.forwarding=1 > /dev/null
  105. }
  106. start_dhcpd6() {
  107. i=${1}
  108. dev=$(devfromid "${i}")
  109. cp /etc/dnsmasq.dhcpd/dhcpdv6{.conf.tpl,-ssid${i}.conf}
  110. sed "s|__WIFI_DEVICE__|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
  111. sed "s|__IP6_NET__|${ynh_ip6_net[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
  112. sed "s|__IP6_DNS__|${ynh_ip6_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf
  113. dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv6-ssid${i}.conf -p0
  114. }
  115. start_dhcpd4() {
  116. i=${1}
  117. dev=$(devfromid "${i}")
  118. cp /etc/dnsmasq.dhcpd/dhcpdv4{.conf.tpl,-ssid${i}.conf}
  119. sed "s|__IP4_DNS__|${ynh_ip4_dns[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
  120. sed "s|__WIFI_DEVICE__|${dev}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
  121. sed "s|__IP4_NAT_PREFIX__|${ynh_ip4_nat_prefix[${i}]}|g" -i /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf
  122. dnsmasq -C /etc/dnsmasq.dhcpd/dhcpdv4-ssid${i}.conf -p0
  123. }
  124. start_hostapd() {
  125. cp /etc/hostapd/hostapd.conf{.tpl1,}
  126. ethaddr=$(ip link show dev "${ynh_wifi_device}" | grep link/ether | awk -F: '{ printf "02:%s:%s:%s:%s:00", $2, $3, $4, $5 }')
  127. ip link set addr "${ethaddr}" dev "${ynh_wifi_device}"
  128. sed "s|__WIFI_DEVICE__|${ynh_wifi_device}|g" -i /etc/hostapd/hostapd.conf
  129. sed "s|__WIFI_CHANNEL__|${ynh_wifi_channel}|g" -i /etc/hostapd/hostapd.conf
  130. sed "s|__N_COMMENT__||g" -i /etc/hostapd/hostapd.conf
  131. for i in $(seq 0 $((${ynh_multissid} - 1))); do
  132. cp /etc/hostapd/hostapd.conf{.tpl2,.tmp}
  133. sed "s|__WIFI_INTERFACE__|hotspot${i}|g" -i /etc/hostapd/hostapd.conf.tmp
  134. sed "s|__WIFI_SSID__|${ynh_wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp
  135. sed "s|__WIFI_PASSPHRASE__|${ynh_wifi_passphrase[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp
  136. if [ "${ynh_wifi_secure[${i}]}" -eq 1 ]; then
  137. sed "s|__SEC_COMMENT__||g" -i /etc/hostapd/hostapd.conf.tmp
  138. else
  139. sed "s|__SEC_COMMENT__|#|g" -i /etc/hostapd/hostapd.conf.tmp
  140. fi
  141. if [ "${i}" -eq 0 ]; then
  142. sed "s|__BSS_COMMENT__|#|g" -i /etc/hostapd/hostapd.conf.tmp
  143. else
  144. sed "s|__BSS_COMMENT__||g" -i /etc/hostapd/hostapd.conf.tmp
  145. fi
  146. cat /etc/hostapd/hostapd.conf.tmp >> /etc/hostapd/hostapd.conf
  147. rm /etc/hostapd/hostapd.conf.tmp
  148. done
  149. systemctl start hostapd
  150. }
  151. ## Unsetters
  152. unset_nat() {
  153. internet_device=${1}
  154. iptables -w -t nat -D POSTROUTING -o "${internet_device}" -j MASQUERADE
  155. }
  156. unset_ip4nataddr() {
  157. i=${1}
  158. dev=$(devfromid "${i}")
  159. ip address delete "${ynh_ip4_nat_prefix[${i}]}.1/24" dev "${dev}"
  160. }
  161. unset_ip6addr() {
  162. i=${1}
  163. dev=$(devfromid "${i}")
  164. ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}"
  165. }
  166. unset_ip6firewall() {
  167. i=${1}
  168. dev=$(devfromid "${i}")
  169. ip6tables -w -D FORWARD -i "${dev}" -j ACCEPT
  170. ip6tables -w -D FORWARD -o "${dev}" -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
  171. ip6tables -w -D FORWARD -o "${dev}" -j DROP
  172. }
  173. unset_forwarding() {
  174. sysctl -w net.ipv6.conf.all.forwarding=0 > /dev/null
  175. sysctl -w net.ipv4.conf.all.forwarding=0 > /dev/null
  176. }
  177. stop_dhcpd6() {
  178. kill $(ps aux | grep 'dhcpdv6-ssid' | grep -v grep | awk '{ print $2 }')
  179. rm -f /etc/dnsmasq.d/dhcpdv6-ssid*.conf
  180. }
  181. stop_dhcpd4() {
  182. kill $(ps aux | grep 'dhcpdv4-ssid' | grep -v grep | awk '{ print $2 }')
  183. rm -f /etc/dnsmasq.d/dhcpdv4-ssid*.conf
  184. }
  185. stop_hostapd() {
  186. systemctl stop hostapd
  187. }
  188. ## Tools
  189. ynh_setting_get() {
  190. APP="$1" KEY="$2" python3 - <<EOF
  191. import os, yaml, sys
  192. app = os.environ['APP']
  193. key = os.environ['KEY']
  194. setting_file = "/etc/yunohost/apps/%s/settings.yml" % app
  195. assert os.path.exists(setting_file), "Setting file %s does not exists ?" % setting_file
  196. with open(setting_file) as f:
  197. settings = yaml.safe_load(f)
  198. if key in settings:
  199. print(settings[key])
  200. EOF
  201. }
  202. ynh_setting_set() {
  203. # This is a partial copypasta of the official ynh_app_setting internal helper
  204. # In particular, we do this instead of relying on 'yunohost app setting' for
  205. # performance reasons (it takes a few second to run every yunohost commands)
  206. # and to remove the need for the infamous '--need-lock' option/issue.
  207. APP="$1" KEY="$2" VALUE="${3:-}" python3 - <<EOF
  208. import os, yaml, sys
  209. app = os.environ['APP']
  210. key, value = os.environ['KEY'], os.environ.get('VALUE', None)
  211. setting_file = "/etc/yunohost/apps/%s/settings.yml" % app
  212. assert os.path.exists(setting_file), "Setting file %s does not exists ?" % setting_file
  213. with open(setting_file) as f:
  214. settings = yaml.load(f)
  215. settings[key] = value
  216. with open(setting_file, "w") as f:
  217. yaml.safe_dump(settings, f, default_flow_style=False)
  218. EOF
  219. }
  220. devfromid() {
  221. i=${1}
  222. if [ "${i}" -eq 0 ]; then
  223. echo "${ynh_wifi_device}"
  224. else
  225. echo "hotspot${i}"
  226. fi
  227. }
  228. if [ "$1" != restart ]; then
  229. # Variables
  230. echo -n "Retrieving Yunohost settings... "
  231. ynh_service_enabled=$(systemctl is-enabled ynh-hotspot)
  232. ynh_wifi_device=$(ynh_setting_get hotspot wifi_device)
  233. ynh_wifi_channel=$(ynh_setting_get hotspot wifi_channel)
  234. ynh_multissid=$(ynh_setting_get hotspot multissid)
  235. IFS='|' read -a ynh_wifi_ssid <<< "$(ynh_setting_get hotspot wifi_ssid)"
  236. IFS='|' read -a ynh_wifi_secure <<< "$(ynh_setting_get hotspot wifi_secure)"
  237. IFS='|' read -a ynh_wifi_passphrase <<< "$(ynh_setting_get hotspot wifi_passphrase)"
  238. IFS='|' read -a ynh_ip6_firewall <<< "$(ynh_setting_get hotspot ip6_firewall)"
  239. IFS='|' read -a ynh_ip6_net <<< "$(ynh_setting_get hotspot ip6_net)"
  240. IFS='|' read -a ynh_dns <<< "$(ynh_setting_get hotspot dns)"
  241. IFS='|' read -a ynh_ip4_nat_prefix <<< "$(ynh_setting_get hotspot ip4_nat_prefix)"
  242. for i in $(seq 0 $((${ynh_multissid} - 1))); do
  243. ynh_ip6_dns[${i}]=""
  244. ynh_ip4_dns[${i}]=""
  245. for ip in $(echo "${ynh_dns[${i}]}" | tr ',' ' '); do
  246. if [[ "$ip" == *":"* ]]
  247. then
  248. ynh_ip6_dns[${i}]+="[$ip],"
  249. else
  250. ynh_ip4_dns[${i}]+="$ip,"
  251. fi
  252. done
  253. # Remove trailing ,
  254. ynh_ip6_dns[${i}]="${ynh_ip6_dns[${i}]%%,}"
  255. ynh_ip4_dns[${i}]="${ynh_ip4_dns[${i}]%%,}"
  256. done
  257. old_internet_device=$(ynh_setting_get hotspot internet_device)
  258. new_internet_device=$(ip route get 1.2.3.4 | awk '{ print $5; }')
  259. # Switch the NAT interface if there is a VPN
  260. ip link show dev tun0 &> /dev/null
  261. if [ "$?" -eq 0 ]; then
  262. new_internet_device=tun0
  263. fi
  264. echo "OK"
  265. fi
  266. # Script
  267. case "$1" in
  268. start)
  269. if is_running; then
  270. echo "Already started"
  271. elif [ "${ynh_service_enabled}" != "enabled" ]; then
  272. echo "Disabled service"
  273. else
  274. if [ -z "${ynh_wifi_device}" ]; then
  275. echo "[ERR] No wifi device selected. Make sure your wifi antenna is plugged-in / available and select it in the Hotspot admin"
  276. exitcode=1
  277. fi
  278. echo "[hotspot] Starting..."
  279. touch /tmp/.ynh-hotspot-started
  280. if [ "${new_internet_device}" == tun0 ]; then
  281. ynh_setting_set hotspot vpnclient yes
  282. else
  283. ynh_setting_set hotspot vpnclient no
  284. fi
  285. # Check old state of the ipv4 NAT settings
  286. if [ ! -z "${old_internet_device}" -a "${new_internet_device}" != "${old_internet_device}" ]\
  287. && is_nat_set "${old_internet_device}"; then
  288. unset_nat "${old_internet_device}"
  289. fi
  290. # Set ipv4 NAT
  291. if [ ! -z "${new_internet_device}" ] && ! is_nat_set "${new_internet_device}"; then
  292. echo "Set NAT"
  293. set_nat "${new_internet_device}"
  294. fi
  295. # Set forwarding for ipv6 and ipv4
  296. if ! is_forwarding_set; then
  297. echo "Set forwarding"
  298. set_forwarding
  299. fi
  300. # Run hostapd
  301. if ! is_hostapd_running; then
  302. echo "Run hostapd"
  303. start_hostapd ${i}
  304. if [ ! $? -eq 0 ]; then
  305. journalctl -u hostapd -n 100 --no-hostname --no-pager
  306. exit 1
  307. fi
  308. if [ "${ynh_multissid}" -gt 1 ]; then
  309. i=0; false || while [ $? -ne 0 ]; do
  310. sleep 1 && (( i++ ))
  311. [ ${i} -gt 20 ] && stop_hostapd
  312. [ ${i} -gt 20 ] && exit 1
  313. ip link show dev hotspot1 &> /dev/null
  314. done
  315. else
  316. sleep 1
  317. fi
  318. fi
  319. # For each registred ssid
  320. for i in $(seq 0 $((${ynh_multissid} - 1))); do
  321. # Set ipv4 NAT address
  322. if ! is_ip4nataddr_set ${i}; then
  323. echo "hotspot${i}: Set IPv4 NAT address"
  324. set_ip4nataddr ${i}
  325. fi
  326. # Set the ipv6 address
  327. if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then
  328. echo "hotspot${i}: Set IPv6 address"
  329. set_ip6addr ${i}
  330. fi
  331. # Set ipv6 firewalling
  332. if has_ip6delegatedprefix ${i} && [ "${ynh_ip6_firewall[${i}]}" -eq 1 ] && ! is_ip6firewall_set ${i}; then
  333. echo "hotspot${i}: Set IPv6 firewalling"
  334. set_ip6firewall ${i}
  335. fi
  336. # Run DHCPv6 server
  337. if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then
  338. echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)"
  339. start_dhcpd6 ${i}
  340. fi
  341. # Run DHCPv4 server
  342. if ! is_dhcpd4_running ${i}; then
  343. echo "hotspot${i}: Start the DHCPv4 server (dnsmasq)"
  344. start_dhcpd4 ${i}
  345. fi
  346. done
  347. # Update dynamic settings
  348. ynh_setting_set hotspot internet_device "${new_internet_device}"
  349. fi
  350. ;;
  351. stop)
  352. echo "[hotspot] Stopping..."
  353. rm -f /tmp/.ynh-hotspot-started
  354. if [ ! -z "${old_internet_device}" ] && is_nat_set "${old_internet_device}"; then
  355. echo "Unset NAT"
  356. unset_nat "${old_internet_device}"
  357. fi
  358. if is_forwarding_set; then
  359. echo "Unset forwarding"
  360. unset_forwarding
  361. fi
  362. for i in $(seq 0 $((${ynh_multissid} - 1))); do
  363. if is_ip4nataddr_set ${i}; then
  364. echo "hotspot${i}: Unset IPv4 NAT address"
  365. unset_ip4nataddr ${i}
  366. fi
  367. if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then
  368. echo "hotspot${i}: Unset IPv6 address"
  369. unset_ip6addr ${i}
  370. fi
  371. if has_ip6delegatedprefix ${i} && [ "${ynh_ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i}; then
  372. echo "hotspot${i}: Unset IPv6 firewalling"
  373. unset_ip6firewall ${i}
  374. fi
  375. if is_dhcpd6_running ${i}; then
  376. echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)"
  377. stop_dhcpd6 ${i}
  378. fi
  379. if is_dhcpd4_running ${i}; then
  380. echo "hotspot${i}: Stop the DHCPv4 server (dnsmasq)"
  381. stop_dhcpd4 ${i}
  382. fi
  383. done
  384. if is_hostapd_running; then
  385. echo "Stop hostapd"
  386. stop_hostapd
  387. fi
  388. # Fix configuration
  389. if has_vpnclient_app; then
  390. ynh-vpnclient start
  391. fi
  392. ;;
  393. restart)
  394. $0 stop
  395. $0 start
  396. ;;
  397. status)
  398. exitcode=0
  399. if [ "${ynh_service_enabled}" != "enabled" ]; then
  400. echo "[ERR] Hotspot Service disabled"
  401. exitcode=1
  402. fi
  403. if [ -z "${ynh_wifi_device}" ]; then
  404. echo "[ERR] No wifi device selected. Make sure your wifi antenna is plugged-in / available and select it in the Hotspot admin"
  405. exitcode=1
  406. fi
  407. echo "[INFO] Autodetected internet interface: ${new_internet_device} (last start: ${old_internet_device})"
  408. if is_nat_set "${new_internet_device}"; then
  409. echo "[OK] IPv4 NAT set"
  410. else
  411. if [ -z "${new_internet_device}" ]; then
  412. echo "[INFO] No IPv4 NAT set (no internet interface)"
  413. else
  414. echo "[ERR] No IPv4 NAT set"
  415. fi
  416. exitcode=1
  417. fi
  418. if is_forwarding_set; then
  419. echo "[OK] IPv6/IPv4 forwarding set"
  420. else
  421. echo "[ERR] No IPv6/IPv4 forwarding set"
  422. exitcode=1
  423. fi
  424. if is_hostapd_running; then
  425. echo "[OK] Hostapd is running"
  426. else
  427. echo "[ERR] Hostapd is not running"
  428. exitcode=1
  429. fi
  430. for i in $(seq 0 $((${ynh_multissid} - 1))); do
  431. if has_ip6delegatedprefix ${i}; then
  432. echo "[INFO] hotspot${i}: IPv6 delegated prefix found"
  433. echo "[INFO] hotspot${i}: IPv6 address computed from the delegated prefix: $(ip6addrfromdelegatedprefix $i)"
  434. if is_ip6addr_set ${i}; then
  435. echo "[OK] hotspot${i}: IPv6 address set"
  436. else
  437. echo "[ERR] hotspot${i}: No IPv6 address set"
  438. exitcode=1
  439. fi
  440. if is_ip6firewall_set ${i}; then
  441. echo "[OK] hotspot${i}: IPv6 firewalling set"
  442. else
  443. if [ "${ynh_ip6_firewall[${i}]}" -eq 1 ]; then
  444. echo "[ERR] hotspot${i}: No IPv6 firewalling set"
  445. else
  446. echo "[INFO] hotspot${i}: No IPv6 firewalling set"
  447. fi
  448. exitcode=1
  449. fi
  450. if is_dhcpd6_running ${i}; then
  451. echo "[OK] hotspot${i}: NDP and DHCPv6 server (dnsmasq) are running"
  452. else
  453. echo "[ERR] hotspot${i}: NDP and DHCPv6 server (dnsmasq) are not running"
  454. exitcode=1
  455. fi
  456. else
  457. echo "[INFO] hotspot${i}: No IPv6 delegated prefix found"
  458. fi
  459. if is_dhcpd4_running ${i}; then
  460. echo "[OK] hotspot${i}: DHCPv4 server (dnsmasq) is running"
  461. else
  462. echo "[ERR] hotspot${i}: DHCPv4 (dnsmasq) is not running"
  463. exitcode=1
  464. fi
  465. if is_ip4nataddr_set ${i}; then
  466. echo "[OK] hotspot${i}: IPv4 NAT address set"
  467. else
  468. echo "[ERR] hotspot${i}: No IPv4 NAT address set"
  469. exitcode=1
  470. fi
  471. done
  472. exit ${exitcode}
  473. ;;
  474. *)
  475. echo "Usage: $0 {start|stop|restart|status}"
  476. exit 1
  477. ;;
  478. esac
  479. exit 0