freedombone-utils-mesh 19KB

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