freedombone-utils-mesh 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # mesh utilities used by the batman and bmx commands
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. # File which contains the current protocol in use
  29. MESH_CURRENT_PROTOCOL=/root/.mesh_protocol
  30. MESH_DEFAULT_PROTOCOL=/root/.mesh_protocol_default
  31. function mesh_generate_ipv6_address {
  32. network=fd66:66:66
  33. if [ "$1" ]; then
  34. search_ipv6=$(ifconfig "$1" | grep "$network")
  35. if [ "$search_ipv6" ]; then
  36. result=$(ifconfig "$1" | grep "$network" | awk -F ' ' '{print $2}')
  37. ip -6 addr add "${result}/128" dev "$1"
  38. return
  39. fi
  40. fi
  41. ipv6_array=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
  42. a=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}
  43. b=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}
  44. c=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}
  45. d=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}
  46. e=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}
  47. result=$network:$a:$b:$c:$d:$e
  48. ip -6 addr add "${result}/128" dev "$1"
  49. }
  50. function mesh_protocol_init {
  51. if [[ $1 == "start" ]]; then
  52. # install avahi
  53. sed -i "s|#host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf
  54. sed -i "s|host-name=.*|host-name=$(hostname)|g" /etc/avahi/avahi-daemon.conf
  55. sed -i "s|use-ipv4=.*|use-ipv4=no|g" /etc/avahi/avahi-daemon.conf
  56. sed -i "s|use-ipv6=.*|use-ipv6=yes|g" /etc/avahi/avahi-daemon.conf
  57. sed -i "s|#disallow-other-stacks=.*|disallow-other-stacks=yes|g" /etc/avahi/avahi-daemon.conf
  58. sed -i "s|hosts:.*|hosts: files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf
  59. fi
  60. # Mesh definition
  61. WIFI_SSID='mesh'
  62. if [ -f "$COMPLETION_FILE" ]; then
  63. if grep -q "WIFI_SSID:" "$COMPLETION_FILE"; then
  64. WIFI_SSID=$(grep "WIFI_SSID:" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
  65. fi
  66. sed -i "s|WIFI_SSID:.*|WIFI_SSID:${WIFI_SSID}|g" "$COMPLETION_FILE"
  67. fi
  68. CELLID='any'
  69. CHANNEL=2
  70. HOTSPOT_CHANNEL=6
  71. if [ -f "$COMPLETION_FILE" ]; then
  72. if grep -q "Wifi channel:" "$COMPLETION_FILE"; then
  73. CHANNEL=$(grep "Wifi channel:" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
  74. fi
  75. sed -i "s|Wifi channel:.*|Wifi channel:${CHANNEL}|g" "$COMPLETION_FILE"
  76. fi
  77. ZERONET_PORT=15441
  78. IPFS_PORT=4001
  79. TOX_PORT=33445
  80. TRACKER_PORT=6969
  81. LIBREVAULT_PORT=42345
  82. TAHOELAFS_PORT=50213
  83. GIT_SSB_PORT=7718
  84. NGINX_GIT_SSB_PORT=7719
  85. # Ethernet bridge definition (bridged to bat0)
  86. BRIDGE=br-mesh
  87. BRIDGE_HOTSPOT=br-hotspot
  88. IFACE=
  89. IFACE_SECONDARY=
  90. EIFACE=eth0
  91. if [[ "$MESH_INTERFACE_TYPE" == 'wlan'* ]]; then
  92. WLAN_ADAPTORS=$(count_wlan)
  93. if [ "$WLAN_ADAPTORS" -eq 0 ]; then
  94. echo $'No wlan adaptors found'
  95. exit 0
  96. fi
  97. fi
  98. }
  99. function get_ipv6_wlan {
  100. ifconfig "${IFACE}" | grep inet6 | awk -F ' ' '{print $2}'
  101. }
  102. function mesh_hotspot_ip_address {
  103. ifconfig "${BRIDGE}" | grep inet6 | awk -F ' ' '{print $2}'
  104. }
  105. function global_rate_limit {
  106. if ! grep -q "tcp_challenge_ack_limit" /etc/sysctl.conf; then
  107. echo 'net.ipv4.tcp_challenge_ack_limit = 999999999' >> /etc/sysctl.conf
  108. echo 'net.ipv6.tcp_challenge_ack_limit = 999999999' >> /etc/sysctl.conf
  109. else
  110. sed -i 's|net.ipv4.tcp_challenge_ack_limit.*|net.ipv4.tcp_challenge_ack_limit = 999999999|g' /etc/sysctl.conf
  111. sed -i 's|net.ipv6.tcp_challenge_ack_limit.*|net.ipv6.tcp_challenge_ack_limit = 999999999|g' /etc/sysctl.conf
  112. fi
  113. sysctl -p -q
  114. }
  115. function assign_peer_address {
  116. for i in {1..6}; do
  117. number=$RANDOM
  118. (( "number %= 255" ))
  119. octet=$(echo "obase=16;$number" | bc)
  120. if [ ${#octet} -lt 2 ]; then
  121. octet="0${octet}"
  122. fi
  123. if [ $i -gt 1 ]; then
  124. echo -n ":"
  125. fi
  126. echo -n "${octet}"
  127. done
  128. }
  129. function mesh_create_app_downloads_page {
  130. if [ ! -d "/root/$PROJECT_NAME/image_build/mesh_apps" ]; then
  131. return
  132. fi
  133. if [ ! -d /var/www/html ]; then
  134. return
  135. fi
  136. # Don't go straight to cryptpad when navigating to the peer's IP address
  137. if [ -L /etc/nginx/sites-enabled/cryptpad ]; then
  138. rm /etc/nginx/sites-enabled/cryptpad
  139. ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
  140. if [ -d /etc/cryptpad ]; then
  141. systemctl stop cryptpad
  142. systemctl disable cryptpad
  143. fi
  144. systemctl restart nginx
  145. fi
  146. # Don't show the cryptpad icon on the desktop
  147. if [ -f /home/fbone/Desktop/cryptpad.desktop ]; then
  148. mv /home/fbone/Desktop/cryptpad.desktop /home/fbone/.cryptpad.desktop
  149. fi
  150. cp "/root/$PROJECT_NAME/website/EN/meshindex.html" /var/www/html/index.html
  151. if [ ! -f /var/www/html/ssb.apk ]; then
  152. cp "/root/$PROJECT_NAME/image_build/mesh_apps/ssb.apk" /var/www/html/ssb.apk
  153. fi
  154. if [ ! -f /var/www/html/trifa.apk ]; then
  155. cp "/root/$PROJECT_NAME/image_build/mesh_apps/trifa.apk" /var/www/html/trifa.apk
  156. fi
  157. if [ ! -d /var/www/html/images ]; then
  158. mkdir /var/www/html/images
  159. fi
  160. if [ ! -f /var/www/html/images/logo.png ]; then
  161. cp "/root/$PROJECT_NAME/img/logo.png" /var/www/html/images/logo.png
  162. fi
  163. if [ ! -f /var/www/html/images/ssb.png ]; then
  164. cp "/root/$PROJECT_NAME/img/icon_patchwork.png" /var/www/html/images/ssb.png
  165. fi
  166. if [ ! -f /var/www/html/images/trifa.png ]; then
  167. cp "/root/$PROJECT_NAME/img/trifa.png" /var/www/html/images/trifa.png
  168. fi
  169. if [ ! -f "/var/www/html/${PROJECT_NAME}.css" ]; then
  170. cp "/root/$PROJECT_NAME/website/${PROJECT_NAME}.css" "/var/www/html/${PROJECT_NAME}.css"
  171. fi
  172. chown -R www-data:www-data /var/www/html/*
  173. }
  174. function enable_mesh_firewall {
  175. iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
  176. iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  177. iptables -A INPUT -p tcp --dport "$TRACKER_PORT" -j ACCEPT
  178. iptables -A INPUT -p udp --dport "$TRACKER_PORT" -j ACCEPT
  179. iptables -A INPUT -p udp --dport 6240 -j ACCEPT
  180. iptables -A INPUT -p tcp --dport 6240 -j ACCEPT
  181. iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  182. iptables -A INPUT -p udp --dport 80 -j ACCEPT
  183. iptables -A INPUT -p tcp --dport 548 -j ACCEPT
  184. iptables -A INPUT -p udp --dport 548 -j ACCEPT
  185. iptables -A INPUT -p tcp --dport 5353 -j ACCEPT
  186. iptables -A INPUT -p udp --dport 5353 -j ACCEPT
  187. iptables -A INPUT -p tcp --dport 5354 -j ACCEPT
  188. iptables -A INPUT -p udp --dport 5354 -j ACCEPT
  189. iptables -A INPUT -p tcp --dport "$ZERONET_PORT" -j ACCEPT
  190. iptables -A INPUT -p udp --dport "$ZERONET_PORT" -j ACCEPT
  191. iptables -A INPUT -p tcp --dport "$IPFS_PORT" -j ACCEPT
  192. iptables -A INPUT -p tcp --dport "$TOX_PORT" -j ACCEPT
  193. iptables -A INPUT -p udp --dport "$TOX_PORT" -j ACCEPT
  194. iptables -A INPUT -p tcp --dport "$LIBREVAULT_PORT" -j ACCEPT
  195. iptables -A INPUT -p udp --dport "$LIBREVAULT_PORT" -j ACCEPT
  196. iptables -A INPUT -p tcp --dport "$TAHOELAFS_PORT" -j ACCEPT
  197. # SSB/Scuttlebot/Patchwork
  198. iptables -A INPUT -p tcp --dport "$GIT_SSB_PORT" -j ACCEPT
  199. iptables -A INPUT -p udp --dport 8008 -j ACCEPT
  200. iptables -A INPUT -p tcp --dport 8008 -j ACCEPT
  201. iptables -A INPUT -p udp --dport 8010 -j ACCEPT
  202. iptables -A INPUT -p tcp --dport 8010 -j ACCEPT
  203. # OLSR2/MANET
  204. iptables -A INPUT -p udp --dport 269 -j ACCEPT
  205. iptables -A INPUT -p tcp --dport 138 -j ACCEPT
  206. # Babel
  207. iptables -A INPUT -p udp --dport 6696 -j ACCEPT
  208. ip6tables -A INPUT -p udp --dport 6696 -j ACCEPT
  209. ip6tables -A INPUT -p ipv6-icmp -j ACCEPT
  210. ip6tables -A OUTPUT -p ipv6-icmp -j ACCEPT
  211. ip6tables -A INPUT -p tcp --dport "$TRACKER_PORT" -j ACCEPT
  212. ip6tables -A INPUT -p udp --dport "$TRACKER_PORT" -j ACCEPT
  213. ip6tables -A INPUT -p udp --dport 6240 -j ACCEPT
  214. ip6tables -A INPUT -p tcp --dport 6240 -j ACCEPT
  215. ip6tables -A INPUT -p tcp --dport 80 -j ACCEPT
  216. ip6tables -A INPUT -p udp --dport 80 -j ACCEPT
  217. ip6tables -A INPUT -p tcp --dport 548 -j ACCEPT
  218. ip6tables -A INPUT -p udp --dport 548 -j ACCEPT
  219. ip6tables -A INPUT -p tcp --dport 5353 -j ACCEPT
  220. ip6tables -A INPUT -p udp --dport 5353 -j ACCEPT
  221. ip6tables -A INPUT -p tcp --dport 5354 -j ACCEPT
  222. ip6tables -A INPUT -p udp --dport 5354 -j ACCEPT
  223. ip6tables -A INPUT -p tcp --dport "$ZERONET_PORT" -j ACCEPT
  224. ip6tables -A INPUT -p udp --dport "$ZERONET_PORT" -j ACCEPT
  225. ip6tables -A INPUT -p tcp --dport "$IPFS_PORT" -j ACCEPT
  226. ip6tables -A INPUT -p tcp --dport "$TOX_PORT" -j ACCEPT
  227. ip6tables -A INPUT -p udp --dport "$TOX_PORT" -j ACCEPT
  228. ip6tables -A INPUT -p tcp --dport "$LIBREVAULT_PORT" -j ACCEPT
  229. ip6tables -A INPUT -p udp --dport "$LIBREVAULT_PORT" -j ACCEPT
  230. ip6tables -A INPUT -p tcp --dport "$TAHOELAFS_PORT" -j ACCEPT
  231. # SSB/Scuttlebot/Patchwork
  232. ip6tables -A INPUT -p tcp --dport "$GIT_SSB_PORT" -j ACCEPT
  233. ip6tables -A INPUT -p udp --dport 8008 -j ACCEPT
  234. ip6tables -A INPUT -p tcp --dport 8008 -j ACCEPT
  235. ip6tables -A INPUT -p udp --dport 8010 -j ACCEPT
  236. ip6tables -A INPUT -p tcp --dport 8010 -j ACCEPT
  237. # OLSR2/MANET
  238. ip6tables -A INPUT -p udp --dport 269 -j ACCEPT
  239. ip6tables -A INPUT -p tcp --dport 138 -j ACCEPT
  240. # Babel
  241. iptables -A INPUT -p udp --dport 6696 -j ACCEPT
  242. ip6tables -A INPUT -p udp --dport 6696 -j ACCEPT
  243. # vpn over the internet
  244. # Note: the vpn firewall settings are needed in order for Patchwork
  245. # to discover local peers
  246. iptables -A INPUT -p tcp --dport 653 -j ACCEPT
  247. iptables -A INPUT -p udp --dport 653 -j ACCEPT
  248. iptables -A INPUT -i "${EIFACE}" -m state --state NEW -p tcp --dport 1194 -j ACCEPT
  249. iptables -A INPUT -i tun+ -j ACCEPT
  250. iptables -A FORWARD -i tun+ -j ACCEPT
  251. iptables -A FORWARD -i tun+ -o "${EIFACE}" -m state --state RELATED,ESTABLISHED -j ACCEPT
  252. iptables -A FORWARD -i "${EIFACE}" -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
  253. iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o "${EIFACE}" -j MASQUERADE
  254. iptables -A OUTPUT -o tun+ -j ACCEPT
  255. echo 1 > /proc/sys/net/ipv4/ip_forward
  256. sed -i 's|# net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf
  257. sed -i 's|#net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf
  258. sed -i 's|net.ipv4.ip_forward.*|net.ipv4.ip_forward=1|g' /etc/sysctl.conf
  259. }
  260. function disable_mesh_firewall {
  261. iptables -D INPUT -p tcp --dport "$TRACKER_PORT" -j ACCEPT
  262. iptables -D INPUT -p udp --dport "$TRACKER_PORT" -j ACCEPT
  263. iptables -D INPUT -p udp --dport 6240 -j ACCEPT
  264. iptables -D INPUT -p tcp --dport 6240 -j ACCEPT
  265. iptables -D INPUT -p tcp --dport 80 -j ACCEPT
  266. iptables -D INPUT -p udp --dport 80 -j ACCEPT
  267. iptables -D INPUT -p tcp --dport 548 -j ACCEPT
  268. iptables -D INPUT -p udp --dport 548 -j ACCEPT
  269. iptables -D INPUT -p tcp --dport 5353 -j ACCEPT
  270. iptables -D INPUT -p udp --dport 5353 -j ACCEPT
  271. iptables -D INPUT -p tcp --dport 5354 -j ACCEPT
  272. iptables -D INPUT -p udp --dport 5354 -j ACCEPT
  273. iptables -D INPUT -p tcp --dport "$ZERONET_PORT" -j ACCEPT
  274. iptables -D INPUT -p udp --dport "$ZERONET_PORT" -j ACCEPT
  275. iptables -D INPUT -p tcp --dport "$IPFS_PORT" -j ACCEPT
  276. iptables -D INPUT -p udp --dport "$IPFS_PORT" -j ACCEPT
  277. iptables -D INPUT -p tcp --dport "$TOX_PORT" -j ACCEPT
  278. iptables -D INPUT -p udp --dport "$TOX_PORT" -j ACCEPT
  279. iptables -D INPUT -p tcp --dport "$LIBREVAULT_PORT" -j ACCEPT
  280. iptables -D INPUT -p udp --dport "$LIBREVAULT_PORT" -j ACCEPT
  281. iptables -D INPUT -p tcp --dport "$TAHOELAFS_PORT" -j ACCEPT
  282. # SSB/Scuttlebot/Patchwork
  283. iptables -D INPUT -p tcp --dport "$GIT_SSB_PORT" -j ACCEPT
  284. iptables -D INPUT -p udp --dport 8008 -j ACCEPT
  285. iptables -D INPUT -p tcp --dport 8008 -j ACCEPT
  286. iptables -D INPUT -p udp --dport 8010 -j ACCEPT
  287. iptables -D INPUT -p tcp --dport 8010 -j ACCEPT
  288. # OLSR2/MANET
  289. iptables -D INPUT -p udp --dport 269 -j ACCEPT
  290. iptables -D INPUT -p tcp --dport 138 -j ACCEPT
  291. # Babel
  292. iptables -D INPUT -p udp --dport 6696 -j ACCEPT
  293. ip6tables -D INPUT -p udp --dport 6696 -j ACCEPT
  294. ip6tables -D INPUT -p tcp --dport "$TRACKER_PORT" -j ACCEPT
  295. ip6tables -D INPUT -p udp --dport "$TRACKER_PORT" -j ACCEPT
  296. ip6tables -D INPUT -p udp --dport 6240 -j ACCEPT
  297. ip6tables -D INPUT -p tcp --dport 6240 -j ACCEPT
  298. ip6tables -D INPUT -p tcp --dport 80 -j ACCEPT
  299. ip6tables -D INPUT -p udp --dport 80 -j ACCEPT
  300. ip6tables -D INPUT -p tcp --dport 548 -j ACCEPT
  301. ip6tables -D INPUT -p udp --dport 548 -j ACCEPT
  302. ip6tables -D INPUT -p tcp --dport 5353 -j ACCEPT
  303. ip6tables -D INPUT -p udp --dport 5353 -j ACCEPT
  304. ip6tables -D INPUT -p tcp --dport 5354 -j ACCEPT
  305. ip6tables -D INPUT -p udp --dport 5354 -j ACCEPT
  306. ip6tables -D INPUT -p tcp --dport "$ZERONET_PORT" -j ACCEPT
  307. ip6tables -D INPUT -p udp --dport "$ZERONET_PORT" -j ACCEPT
  308. ip6tables -D INPUT -p tcp --dport "$IPFS_PORT" -j ACCEPT
  309. ip6tables -D INPUT -p udp --dport "$IPFS_PORT" -j ACCEPT
  310. ip6tables -D INPUT -p tcp --dport "$TOX_PORT" -j ACCEPT
  311. ip6tables -D INPUT -p udp --dport "$TOX_PORT" -j ACCEPT
  312. ip6tables -D INPUT -p tcp --dport "$LIBREVAULT_PORT" -j ACCEPT
  313. ip6tables -D INPUT -p udp --dport "$LIBREVAULT_PORT" -j ACCEPT
  314. ip6tables -D INPUT -p tcp --dport "$TAHOELAFS_PORT" -j ACCEPT
  315. # SSB/Scuttlebot/Patchwork
  316. ip6tables -D INPUT -p tcp --dport "$GIT_SSB_PORT" -j ACCEPT
  317. ip6tables -D INPUT -p udp --dport 8008 -j ACCEPT
  318. ip6tables -D INPUT -p tcp --dport 8008 -j ACCEPT
  319. ip6tables -D INPUT -p udp --dport 8010 -j ACCEPT
  320. ip6tables -D INPUT -p tcp --dport 8010 -j ACCEPT
  321. # OLSR2/MANET
  322. ip6tables -D INPUT -p udp --dport 269 -j ACCEPT
  323. ip6tables -D INPUT -p tcp --dport 138 -j ACCEPT
  324. # Babel
  325. iptables -D INPUT -p udp --dport 6696 -j ACCEPT
  326. ip6tables -D INPUT -p udp --dport 6696 -j ACCEPT
  327. # vpn over the internet
  328. iptables -D INPUT -p tcp --dport 653 -j ACCEPT
  329. iptables -D INPUT -p udp --dport 653 -j ACCEPT
  330. iptables -D INPUT -i "${EIFACE}" -m state --state NEW -p tcp --dport 1194 -j ACCEPT
  331. iptables -D INPUT -i tun+ -j ACCEPT
  332. iptables -D FORWARD -i tun+ -j ACCEPT
  333. iptables -D FORWARD -i tun+ -o "${EIFACE}" -m state --state RELATED,ESTABLISHED -j ACCEPT
  334. iptables -D FORWARD -i "${EIFACE}" -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
  335. iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -o "${EIFACE}" -j MASQUERADE
  336. iptables -D OUTPUT -o tun+ -j ACCEPT
  337. echo 0 > /proc/sys/net/ipv4/ip_forward
  338. sed -i 's|net.ipv4.ip_forward=.*|net.ipv4.ip_forward=0|g' /etc/sysctl.conf
  339. }
  340. function enable_mesh_scuttlebot {
  341. if [ -f /etc/scuttlebot/.ssb/config ]; then
  342. ethernet_connected=$(cat /sys/class/net/eth0/carrier)
  343. if [[ "$ethernet_connected" != "0" ]]; then
  344. sed -i "s|\"host\": .*|\"host\": \"$(get_ipv6_wlan)\",|g" /etc/scuttlebot/.ssb/config
  345. systemctl restart scuttlebot
  346. else
  347. if [ ! -f /etc/nginx/sites-available/git_ssb ]; then
  348. systemctl stop scuttlebot
  349. else
  350. systemctl restart scuttlebot
  351. fi
  352. fi
  353. fi
  354. sed -i "s|\"host\":.*|\"host\": \"${HOSTNAME}.local\",|g" /etc/scuttlebot/.ssb/config
  355. systemctl restart scuttlebot
  356. }
  357. function enable_mesh_tor {
  358. # if we have an ethernet connection to an internet router then create
  359. # an onion address for this peer
  360. if [[ "$ethernet_connected" != "0" ]]; then
  361. systemctl enable tor
  362. systemctl start tor
  363. HIDDEN_SERVICE_PATH=/var/lib/tor/hidden_service_
  364. if [ ! -f ${HIDDEN_SERVICE_PATH}mesh/hostname ]; then
  365. echo "HiddenServiceDir ${HIDDEN_SERVICE_PATH}mesh/" >> /etc/tor/torrc
  366. echo "HiddenServicePort 653 127.0.0.1:653" >> /etc/tor/torrc
  367. systemctl restart tor
  368. fi
  369. else
  370. systemctl stop tor
  371. systemctl disable tor
  372. fi
  373. }
  374. function enable_mesh_seconary_wifi {
  375. if [ "$secondary_wifi_available" ]; then
  376. sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
  377. mesh_hotspot_address=$(mesh_hotspot_ip_address)
  378. if [[ "$mesh_hotspot_address" == *'.'* ]]; then
  379. { echo "interface=${IFACE_SECONDARY}";
  380. echo "bridge=${BRIDGE}";
  381. echo 'driver=nl80211';
  382. echo "country_code=UK";
  383. echo "ssid=${WIFI_SSID}-${mesh_hotspot_address}";
  384. echo 'hw_mode=g';
  385. echo "channel=${HOTSPOT_CHANNEL}";
  386. echo 'wpa=2';
  387. echo "wpa_passphrase=$HOTSPOT_PASSPHRASE";
  388. echo 'wpa_key_mgmt=WPA-PSK';
  389. echo 'wpa_pairwise=TKIP';
  390. echo 'rsn_pairwise=CCMP';
  391. echo 'auth_algs=1';
  392. echo 'macaddr_acl=0'; } > /etc/hostapd/hostapd.conf
  393. sed -i "s|#interface=.*|interface=${IFACE_SECONDARY}|g" /etc/dnsmasq.conf
  394. sed -i "s|interface=.*|interface=${IFACE_SECONDARY}|g" /etc/dnsmasq.conf
  395. sed -i "s|listen-address=.*|listen-address=127.0.0.1,$mesh_hotspot_address|g" /etc/dnsmasq.conf
  396. sed -i 's|#listen-address|listen-address|g' /etc/dnsmasq.conf
  397. systemctl enable dnsmasq
  398. systemctl restart dnsmasq
  399. systemctl enable hostapd
  400. systemctl restart hostapd
  401. mesh_create_app_downloads_page
  402. else
  403. secondary_wifi_available=
  404. echo $'WARNING: No IP address could be obtained for the hotspot'
  405. fi
  406. fi
  407. if [ ! "$secondary_wifi_available" ]; then
  408. systemctl stop hostapd
  409. systemctl disable hostapd
  410. # Recreate the cryptpad symlink
  411. if [ -f /etc/nginx/sites-available/cryptpad ]; then
  412. if [ -L /etc/nginx/sites-enabled/cryptpad ]; then
  413. rm /etc/nginx/sites-enabled/default
  414. fi
  415. systemctl enable cryptpad
  416. systemctl start cryptpad
  417. if [ ! -L /etc/nginx/sites-enabled/cryptpad ]; then
  418. ln -s /etc/nginx/sites-available/cryptpad /etc/nginx/sites-enabled/cryptpad
  419. systemctl restart nginx
  420. fi
  421. fi
  422. if [ -f /home/fbone/.cryptpad.desktop ]; then
  423. mv /home/fbone/.cryptpad.desktop /home/fbone/Desktop/cryptpad.desktop
  424. fi
  425. fi
  426. }
  427. # NOTE: deliberately there is no "exit 0"