freedombone-app-tahoelafs 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Tahow-LAFS data storage grid implemented via Tor
  12. # https://k0rx.com/blog/2017/01/lafs.html
  13. # http://tahoe-lafs.readthedocs.io/en/latest/anonymity-configuration.html
  14. #
  15. # License
  16. # =======
  17. #
  18. # Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
  19. #
  20. # This program is free software: you can redistribute it and/or modify
  21. # it under the terms of the GNU Affero General Public License as published by
  22. # the Free Software Foundation, either version 3 of the License, or
  23. # (at your option) any later version.
  24. #
  25. # This program is distributed in the hope that it will be useful,
  26. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. # GNU Affero General Public License for more details.
  29. #
  30. # You should have received a copy of the GNU Affero General Public License
  31. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  32. VARIANTS='full full-vim cloud'
  33. IN_DEFAULT_INSTALL=0
  34. SHOW_ON_ABOUT=1
  35. SHOW_ICANN_ADDRESS_ON_ABOUT=0
  36. TAHOELAFS_PORT=50213
  37. TAHOELAFS_STORAGE_PORT=50214
  38. TAHOELAFS_ONION_PORT=8096
  39. TAHOELAFS_STORAGE_ONION_PORT=8097
  40. TAHOE_DIR=/home/tahoelafs
  41. TAHOE_COMMAND='/usr/bin/tahoe'
  42. tahoelafs_storage_file=$TAHOE_DIR/client/private/servers.yaml
  43. TAHOELAFS_SHARES_NEEDED=3
  44. TAHOELAFS_SHARES_HAPPY=7
  45. TAHOELAFS_SHARES_TOTAL=10
  46. tahoelafs_variables=(ONION_ONLY
  47. MY_USERNAME
  48. TAHOELAFS_PORT
  49. TAHOELAFS_SHARES_NEEDED
  50. TAHOELAFS_SHARES_HAPPY
  51. TAHOELAFS_SHARES_TOTAL)
  52. function add_user_tahoelafs {
  53. if [[ $(app_is_installed tahoelafs) == "0" ]]; then
  54. echo '0'
  55. return
  56. fi
  57. new_username="$1"
  58. new_user_password="$2"
  59. ${PROJECT_NAME}-pass -u $new_username -a tahoelafs -p "$new_user_password"
  60. if grep -q "${new_username}:" /etc/nginx/.htpasswd-tahoelafs; then
  61. sed -i '/${new_username}:/d' /etc/nginx/.htpasswd-tahoelafs
  62. fi
  63. echo "${new_user_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${new_username}
  64. echo '0'
  65. }
  66. function remove_user_tahoelafs {
  67. remove_username="$1"
  68. ${PROJECT_NAME}-pass -u $remove_username --rmapp tahoelafs
  69. if grep -q "${remove_username}:" /etc/nginx/.htpasswd-tahoelafs; then
  70. sed -i '/${remove_username}:/d' /etc/nginx/.htpasswd-tahoelafs
  71. fi
  72. }
  73. function change_password_tahoelafs {
  74. change_username="$1"
  75. change_password="$2"
  76. ${PROJECT_NAME}-pass -u $change_username -a tahoelafs -p "$change_password"
  77. if grep -q "${change_username}:" /etc/nginx/.htpasswd-tahoelafs; then
  78. sed -i '/tahoe-${change_username}:/d' /etc/nginx/.htpasswd-tahoelafs
  79. fi
  80. echo "${change_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${change_username}
  81. }
  82. function add_tahoelafs_storage_node_interactive {
  83. data=$(tempfile 2>/dev/null)
  84. trap "rm -f $data" 0 1 2 5 15
  85. dialog --backtitle $"Freedombone Configuration" \
  86. --title $"Add Tahoe-LAFS storage node" \
  87. --form $"\nEnter the storage node details which can be found on the About screen of another server" 13 75 5 \
  88. $"Hostname:" 1 1 "" 1 14 53 40 \
  89. $"Public Key:" 2 1 "" 2 14 53 255 \
  90. $"Nickname:" 3 1 "" 3 14 53 255 \
  91. $"FURL:" 4 1 "" 4 14 53 255 \
  92. 2> $data
  93. sel=$?
  94. case $sel in
  95. 1) return;;
  96. 255) return;;
  97. esac
  98. storage_hostname=$(cat $data | sed -n 1p)
  99. public_key="$(cat $data | sed -n 2p)"
  100. nick=$(cat $data | sed -n 3p)
  101. furl=$(cat $data | sed -n 4p)
  102. if [ ${#public_key} -eq 0 ]; then
  103. return
  104. fi
  105. add_tahoelafs_server "${storage_hostname}" "${public_key}" "${nick}" "${furl}"
  106. if grep -q "$public_key" ${tahoelafs_storage_file}; then
  107. dialog --title $"Add Tahoe-LAFS storage node" \
  108. --msgbox $"Storage node added" 6 40
  109. fi
  110. }
  111. function edit_tahoelafs_nodes {
  112. editor $tahoelafs_storage_file
  113. chown tahoelafs:debian-tor $tahoelafs_storage_file
  114. systemctl restart tahoelafs-client
  115. }
  116. function edit_tahoelafs_shares {
  117. read_config_param TAHOELAFS_SHARES_NEEDED
  118. read_config_param TAHOELAFS_SHARES_HAPPY
  119. read_config_param TAHOELAFS_SHARES_TOTAL
  120. data=$(tempfile 2>/dev/null)
  121. trap "rm -f $data" 0 1 2 5 15
  122. dialog --backtitle $"Freedombone Configuration" \
  123. --title $"Tahoe-LAFS shares" \
  124. --form $"\nEnter the storage node details which can be found on the About screen of another server" 13 40 3 \
  125. $"Needed:" 1 1 "${TAHOELAFS_SHARES_NEEDED}" 1 14 4 4 \
  126. $"Happy:" 2 1 "${TAHOELAFS_SHARES_HAPPY}" 2 14 4 4 \
  127. $"Total:" 3 1 "${TAHOELAFS_SHARES_TOTAL}" 3 14 4 4 \
  128. 2> $data
  129. sel=$?
  130. case $sel in
  131. 1) return;;
  132. 255) return;;
  133. esac
  134. tl_needed="$(cat $data | sed -n 1p)"
  135. tl_happy="$(cat $data | sed -n 2p)"
  136. tl_total="$(cat $data | sed -n 3p)"
  137. if [ ${#tl_needed} -gt 0 ]; then
  138. TAHOELAFS_SHARES_NEEDED=${tl_needed}
  139. fi
  140. if [ ${#tl_happy} -gt 0 ]; then
  141. TAHOELAFS_SHARES_HAPPY=${tl_happy}
  142. fi
  143. if [ ${#tl_total} -gt 0 ]; then
  144. TAHOELAFS_SHARES_TOTAL=${tl_total}
  145. fi
  146. sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
  147. sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
  148. sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
  149. sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
  150. sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
  151. sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
  152. systemctl restart tahoelafs-storage
  153. systemctl restart tahoelafs-client
  154. dialog --title $"Tahoe-LAFS shares" \
  155. --msgbox $"Shares settings changed" 6 40
  156. }
  157. function configure_interactive_tahoelafs {
  158. data=$(tempfile 2>/dev/null)
  159. trap "rm -f $data" 0 1 2 5 15
  160. dialog --backtitle $"Freedombone Configuration" \
  161. --title $"Tahoe-LAFS" \
  162. --radiolist $"The least authority is always the best" 11 50 5 \
  163. 1 "Add a storage node" off \
  164. 2 "Manually edit storage nodes" off \
  165. 3 "Shares settings" off \
  166. 4 "Back to main menu" on 2> $data
  167. sel=$?
  168. case $sel in
  169. 1) exit 1;;
  170. 255) exit 1;;
  171. esac
  172. case $(cat $data) in
  173. 1) add_tahoelafs_storage_node_interactive;;
  174. 2) edit_tahoelafs_nodes;;
  175. 3) edit_tahoelafs_shares;;
  176. esac
  177. }
  178. function tahoelafs_setup_client_config {
  179. config_file=$1
  180. nick="$2"
  181. echo '[node]' > $config_file
  182. echo "nickname = $nick" >> $config_file
  183. echo 'reveal-IP-address = false' >> $config_file
  184. echo "web.port = tcp:${TAHOELAFS_PORT}:interface=127.0.0.1" >> $config_file
  185. echo 'web.static = public_html' >> $config_file
  186. echo 'tub.port = disabled' >> $config_file
  187. echo 'tub.location = disabled' >> $config_file
  188. echo '' >> $config_file
  189. echo '[client]' >> $config_file
  190. echo 'introducer.furl =' >> $config_file
  191. echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}" >> $config_file
  192. echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}" >> $config_file
  193. echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}" >> $config_file
  194. echo '' >> $config_file
  195. echo '[storage]' >> $config_file
  196. echo 'enabled = false' >> $config_file
  197. echo 'reserved_space = 3G' >> $config_file
  198. echo '' >> $config_file
  199. echo '[helper]' >> $config_file
  200. echo 'enabled = false' >> $config_file
  201. echo '' >> $config_file
  202. echo '[connections]' >> $config_file
  203. echo 'tcp = tor' >> $config_file
  204. }
  205. function tahoelafs_setup_storage_config {
  206. config_file=$1
  207. nick="$2"
  208. echo '[node]' > $config_file
  209. echo "nickname = $nick" >> $config_file
  210. echo 'reveal-IP-address = false' >> $config_file
  211. echo 'web.port =' >> $config_file
  212. echo 'web.static = public_html' >> $config_file
  213. echo "tub.port = tcp:${TAHOELAFS_STORAGE_ONION_PORT}:interface=127.0.0.1" >> $config_file
  214. echo "tub.location = tor:${TAHOELAFS_STORAGE_ONION_HOSTNAME}:${TAHOELAFS_STORAGE_PORT}" >> $config_file
  215. echo '' >> $config_file
  216. echo '[client]' >> $config_file
  217. echo 'introducer.furl =' >> $config_file
  218. echo 'helper.furl =' >> $config_file
  219. echo '' >> $config_file
  220. echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}" >> $config_file
  221. echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}" >> $config_file
  222. echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}" >> $config_file
  223. echo '' >> $config_file
  224. echo '[storage]' >> $config_file
  225. echo 'enabled = true' >> $config_file
  226. echo 'reserved_space = 3G' >> $config_file
  227. echo 'expire.enabled = true' >> $config_file
  228. echo 'expire.mode = age' >> $config_file
  229. echo 'expire.override_lease_duration = 3 months' >> $config_file
  230. echo '' >> $config_file
  231. echo '[helper]' >> $config_file
  232. echo 'enabled = false' >> $config_file
  233. echo '' >> $config_file
  234. echo '[connections]' >> $config_file
  235. echo 'tcp = tor' >> $config_file
  236. chown -R tahoelafs:debian-tor $TAHOE_DIR
  237. }
  238. function install_interactive_tahoelafs {
  239. echo -n ''
  240. APP_INSTALLED=1
  241. }
  242. function upgrade_tahoelafs {
  243. echo -n ''
  244. }
  245. function backup_local_tahoelafs {
  246. source_directory=$TAHOE_DIR
  247. if [ ! -d $source_directory ]; then
  248. return
  249. fi
  250. systemctl stop tahoelafs
  251. dest_directory=tahoelafs
  252. function_check backup_directory_to_usb
  253. backup_directory_to_usb $source_directory $dest_directory
  254. systemctl start tahoelafs
  255. }
  256. function restore_local_tahoelafs {
  257. echo $"Restoring Tahoe-LAFS"
  258. systemctl stop tahoelafs-storage
  259. systemctl stop tahoelafs-client
  260. temp_restore_dir=/root/temptahoelafs
  261. restore_directory_from_usb $temp_restore_dir tahoelafs
  262. mv $TAHOE_DIR ${TAHOE_DIR}-old
  263. cp -r $temp_restore_dir$TAHOE_DIR $TAHOE_DIR
  264. if [ ! "$?" = "0" ]; then
  265. mv ${TAHOE_DIR}-old $TAHOE_DIR
  266. exit 246833
  267. fi
  268. rm -rf ${TAHOE_DIR}-old
  269. chown -R tahoelafs:debian-tor $TAHOE_DIR
  270. systemctl start tahoelafs-client
  271. systemctl start tahoelafs-storage
  272. echo $"Restore complete"
  273. }
  274. function backup_remote_tahoelafs {
  275. source_directory=$TAHOE_DIR
  276. if [ ! -d $source_directory ]; then
  277. return
  278. fi
  279. systemctl stop tahoelafs-storage
  280. systemctl stop tahoelafs-client
  281. dest_directory=tahoelafs
  282. function_check backup_directory_to_usb
  283. backup_directory_to_friend $source_directory $dest_directory
  284. systemctl start tahoelafs-client
  285. systemctl start tahoelafs-storage
  286. }
  287. function restore_remote_tahoelafs {
  288. echo $"Restoring Tahoe-LAFS"
  289. systemctl stop tahoelafs-storage
  290. systemctl stop tahoelafs-client
  291. temp_restore_dir=/root/temptahoelafs
  292. restore_directory_from_friend $temp_restore_dir tahoelafs
  293. mv $TAHOE_DIR ${TAHOE_DIR}-old
  294. cp -r $temp_restore_dir$TAHOE_DIR $TAHOE_DIR
  295. if [ ! "$?" = "0" ]; then
  296. mv ${TAHOE_DIR}old $TAHOE_DIR
  297. exit 623925
  298. fi
  299. rm -rf ${$TAHOE_DIR}-old
  300. chown -R tahoelafs:debian-tor $TAHOE_DIR
  301. systemctl start tahoelafs-client
  302. systemctl start tahoelafs-storage
  303. echo $"Restore complete"
  304. }
  305. function reconfigure_tahoelafs {
  306. if [ -f $tahoelafs_storage_file ]; then
  307. shred -zu $tahoelafs_storage_file
  308. fi
  309. sed -i '/HidServAuth /d' /etc/tor/torrc
  310. }
  311. function remove_tahoelafs {
  312. if [ -f /etc/nginx/sites-available/tahoelafs ]; then
  313. nginx_dissite tahoelafs
  314. rm /etc/nginx/sites-available/tahoelafs
  315. if [ -d /var/www/tahoelafs ]; then
  316. rm -rf /var/www/tahoelafs
  317. fi
  318. systemctl reload nginx
  319. fi
  320. systemctl stop tahoelafs-storage
  321. systemctl disable tahoelafs-storage
  322. rm /etc/systemd/system/tahoelafs-storage.service
  323. systemctl daemon-reload
  324. systemctl stop tahoelafs-client
  325. systemctl disable tahoelafs-client
  326. rm /etc/systemd/system/tahoelafs-client.service
  327. systemctl daemon-reload
  328. pip uninstall tahoe-lafs[tor]
  329. apt-get -yq remove tahoe-lafs
  330. if [ -d /var/lib/tahoelafs ]; then
  331. rm -rf /var/lib/tahoelafs
  332. fi
  333. remove_completion_param install_tahoelafs
  334. function_check remove_onion_service
  335. remove_onion_service tahoelafs ${TAHOELAFS_ONION_PORT}
  336. remove_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_ONION_PORT} $(get_tahoelafs_nick)
  337. sed -i '/HidServAuth /d' /etc/tor/torrc
  338. groupdel -f tahoelafs
  339. userdel -r tahoelafs
  340. if [ -d $TAHOE_DIR ]; then
  341. rm -rf $TAHOE_DIR
  342. fi
  343. remove_app tahoelafs
  344. if [ -f /etc/nginx/.htpasswd-tahoelafs ]; then
  345. shred -zu /etc/nginx/.htpasswd-tahoelafs
  346. fi
  347. onion_update
  348. }
  349. function create_tahoelafs_stealth_node {
  350. node_dir="$1"
  351. client_dir="$2"
  352. node_nick="$3"
  353. client_nick="$4"
  354. if [ ${#node_dir} -eq 0 ]; then
  355. echo $'No tahoe-LAFS storage node directory given'
  356. exit 783522
  357. fi
  358. if [ ${#client_dir} -eq 0 ]; then
  359. echo $'No tahoe-LAFS client directory given'
  360. exit 368935
  361. fi
  362. if [ ${#node_nick} -eq 0 ]; then
  363. echo $'No tahoe-LAFS node nick given'
  364. exit 672351
  365. fi
  366. if [ ${#client_nick} -eq 0 ]; then
  367. echo $'No tahoe-LAFS client nick given'
  368. exit 682362
  369. fi
  370. if [ ! -f ${node_dir}/tahoe.cfg ]; then
  371. su -c "mkdir ${node_dir}" - tahoelafs
  372. su -c "$TAHOE_COMMAND create-node -C ${node_dir} --hostname=fixme" - tahoelafs
  373. tahoelafs_setup_storage_config ${node_dir}/tahoe.cfg ${node_nick}
  374. fi
  375. if [ ! -f ${client_dir}/tahoe.cfg ]; then
  376. su -c "mkdir ${client_dir}" - tahoelafs
  377. su -c "$TAHOE_COMMAND create-client -C ${client_dir}" - tahoelafs
  378. tahoelafs_setup_client_config ${client_dir}/tahoe.cfg ${client_nick}
  379. fi
  380. }
  381. function create_tahoelafs_introducer {
  382. introducer_dir="$1"
  383. if [ -f ${introducer_dir}/tahoe.cfg ]; then
  384. return
  385. fi
  386. su -c "mkdir ${introducer_dir}" - tahoelafs
  387. su -c "$TAHOE_COMMAND create-introducer -C ${introducer_dir} --hide-ip --hostname=127.0.0.1" - tahoelafs
  388. }
  389. function create_tahoelafs_storage_node {
  390. # Nodes can store data
  391. node_dir="$1"
  392. furl="$2"
  393. if [ ${#furl} -eq 0 ]; then
  394. return
  395. fi
  396. if [ -f ${node_dir}/tahoe.cfg ]; then
  397. return
  398. fi
  399. su -c "mkdir ${node_dir}" - tahoelafs
  400. su -c "$TAHOE_COMMAND create-node -C ${node_dir} --introducer=\"$furl\" --listen=tor --hide-ip" - tahoelafs
  401. }
  402. function create_tahoelafs_client {
  403. # Clients have no storage
  404. client_dir="$1"
  405. furl="$2"
  406. if [ ${#furl} -eq 0 ]; then
  407. return
  408. fi
  409. if [ -f ${client_dir}/tahoe.cfg ]; then
  410. return
  411. fi
  412. su -c "mkdir ${client_dir}" - tahoelafs
  413. su -c "$TAHOE_COMMAND create-client -C ${client_dir} --introducer=\"$furl\" --listen=tor --hide-ip --hostname=127.0.0.1" - tahoelafs
  414. sed -i 's|reveal-IP-address =.*|reveal-IP-address = False|g' $client_dir/tahoe.cfg
  415. sed -i 's|tub.port =.*|tub.port = disabled|g' $client_dir/tahoe.cfg
  416. sed -i 's|tub.location =.*|tub.location = disabled|g' $client_dir/tahoe.cfg
  417. }
  418. function get_tahoelafs_furl {
  419. furl=$(cat $TAHOE_DIR/storage/private/storage.furl)
  420. furl_1=$(echo "${furl}" | awk -F ' ' '{print $1}')
  421. furl_2=$(echo "${furl}" | awk -F ':' '{print $5}')
  422. echo "${furl_1}:${furl_2}"
  423. }
  424. function get_tahoelafs_nick {
  425. echo "${MY_USERNAME}-node"
  426. }
  427. function get_tahoelafs_storage_hostname {
  428. echo "$(cat /var/lib/tor/hidden_service_storage-tahoelafs/hostname)"
  429. }
  430. function get_tahoelafs_public_key {
  431. echo "$(cat $TAHOE_DIR/storage/node.pubkey | grep 'v0-' | sed 's|pub-||g')"
  432. }
  433. function add_tahoelafs_server {
  434. storage_hostname="$1"
  435. public_key="$2"
  436. nick="$3"
  437. furl="$4"
  438. if [ ${#storage_hostname} -eq 0 ]; then
  439. echo $'No storage hostname'
  440. return
  441. fi
  442. if [ ${#public_key} -eq 0 ]; then
  443. echo $'No public key'
  444. return
  445. fi
  446. if [ ${#nick} -eq 0 ]; then
  447. echo $'No nick'
  448. return
  449. fi
  450. if [ ${#furl} -eq 0 ]; then
  451. echo $'No furl'
  452. return
  453. fi
  454. if [ ! -f ${tahoelafs_storage_file} ]; then
  455. echo 'storage:' > ${tahoelafs_storage_file}
  456. else
  457. if grep -q "${public_key}" ${tahoelafs_storage_file}; then
  458. echo $'Public key already exists'
  459. return
  460. fi
  461. echo '# storage' >> ${tahoelafs_storage_file}
  462. fi
  463. echo " ${public_key}:" >> ${tahoelafs_storage_file}
  464. echo " ann:" >> ${tahoelafs_storage_file}
  465. echo " nickname: ${nick}" >> ${tahoelafs_storage_file}
  466. echo " anonymous-storage-FURL: ${furl}" >> ${tahoelafs_storage_file}
  467. chown tahoelafs:debian-tor ${tahoelafs_storage_file}
  468. if ! grep -q "HidServAuth ${storage_hostname}" /etc/tor/torrc; then
  469. echo "HidServAuth ${storage_hostname}" >> /etc/tor/torrc
  470. fi
  471. }
  472. function create_tahoelafs_daemon {
  473. daemon_name=$1
  474. TAHOELAFS_DAEMON_FILE=/etc/systemd/system/tahoelafs-${daemon_name}.service
  475. echo "Creating daemon: $TAHOELAFS_DAEMON_FILE"
  476. echo '[Unit]' > $TAHOELAFS_DAEMON_FILE
  477. echo "Description=Tahoe-LAFS ${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
  478. echo 'After=syslog.target' >> $TAHOELAFS_DAEMON_FILE
  479. echo 'After=network.target' >> $TAHOELAFS_DAEMON_FILE
  480. echo '' >> $TAHOELAFS_DAEMON_FILE
  481. echo '[Service]' >> $TAHOELAFS_DAEMON_FILE
  482. echo 'Type=simple' >> $TAHOELAFS_DAEMON_FILE
  483. echo "User=tahoelafs" >> $TAHOELAFS_DAEMON_FILE
  484. echo "Group=debian-tor" >> $TAHOELAFS_DAEMON_FILE
  485. echo "WorkingDirectory=${TAHOE_DIR}" >> $TAHOELAFS_DAEMON_FILE
  486. echo "ExecStart=/usr/bin/tahoe run ${TAHOE_DIR}/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
  487. echo "ExecStop=/usr/bin/tahoe stop ${TAHOE_DIR}/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
  488. echo 'Restart=on-failure' >> $TAHOELAFS_DAEMON_FILE
  489. echo 'RestartSec=10' >> $TAHOELAFS_DAEMON_FILE
  490. echo "Environment=\"USER=tahoelafs\" \"HOME=${TAHOE_DIR}\"" >> $TAHOELAFS_DAEMON_FILE
  491. echo '' >> $TAHOELAFS_DAEMON_FILE
  492. echo '[Install]' >> $TAHOELAFS_DAEMON_FILE
  493. echo 'WantedBy=multi-user.target' >> $TAHOELAFS_DAEMON_FILE
  494. systemctl enable tahoelafs-${daemon_name}
  495. systemctl daemon-reload
  496. systemctl start tahoelafs-${daemon_name}
  497. }
  498. function create_tahoelafs_web {
  499. if [ ! -d /var/www/tahoelafs/htdocs ]; then
  500. mkdir -p /var/www/tahoelafs/htdocs
  501. fi
  502. TAHOELAFS_LOGIN_TEXT=$'Tahoe-LAFS login'
  503. tahoelafs_nginx_site=/etc/nginx/sites-available/tahoelafs
  504. echo 'server {' > $tahoelafs_nginx_site
  505. echo " listen 127.0.0.1:$TAHOELAFS_ONION_PORT default_server;" >> $tahoelafs_nginx_site
  506. echo " server_name $TAHOELAFS_ONION_HOSTNAME;" >> $tahoelafs_nginx_site
  507. echo '' >> $tahoelafs_nginx_site
  508. function_check nginx_disable_sniffing
  509. nginx_disable_sniffing tahoelafs
  510. echo '' >> $tahoelafs_nginx_site
  511. echo ' # Logs' >> $tahoelafs_nginx_site
  512. echo ' access_log /dev/null;' >> $tahoelafs_nginx_site
  513. echo ' error_log /dev/null;' >> $tahoelafs_nginx_site
  514. echo '' >> $tahoelafs_nginx_site
  515. echo ' # Root' >> $tahoelafs_nginx_site
  516. echo " root /var/www/tahoelafs/htdocs;" >> $tahoelafs_nginx_site
  517. echo '' >> $tahoelafs_nginx_site
  518. echo ' location / {' >> $tahoelafs_nginx_site
  519. echo " auth_basic \"${TAHOELAFS_LOGIN_TEXT}\";" >> $tahoelafs_nginx_site
  520. echo ' auth_basic_user_file /etc/nginx/.htpasswd-tahoelafs;' >> $tahoelafs_nginx_site
  521. function_check nginx_limits
  522. nginx_limits tahoelafs '15m'
  523. echo ' rewrite /(.*) /$1 break;' >> $tahoelafs_nginx_site
  524. echo ' proxy_set_header X-Real-IP $remote_addr;' >> $tahoelafs_nginx_site
  525. echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $tahoelafs_nginx_site
  526. echo ' proxy_set_header Host $http_host;' >> $tahoelafs_nginx_site
  527. echo ' proxy_set_header X-NginX-Proxy true;' >> $tahoelafs_nginx_site
  528. echo " proxy_pass http://localhost:${TAHOELAFS_PORT};" >> $tahoelafs_nginx_site
  529. echo ' proxy_redirect off;' >> $tahoelafs_nginx_site
  530. echo ' }' >> $tahoelafs_nginx_site
  531. echo '}' >> $tahoelafs_nginx_site
  532. TAHOELAFS_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  533. ${PROJECT_NAME}-pass -u $MY_USERNAME -a tahoelafs -p "$TAHOELAFS_ADMIN_PASSWORD"
  534. if [ ! -f /etc/nginx/.htpasswd-tahoelafs ]; then
  535. touch /etc/nginx/.htpasswd-tahoelafs
  536. fi
  537. if grep -q "${MY_USERNAME}:" /etc/nginx/.htpasswd-tahoelafs; then
  538. sed -i '/${MY_USERNAME}:/d' /etc/nginx/.htpasswd-tahoelafs
  539. fi
  540. echo "${TAHOELAFS_ADMIN_PASSWORD}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${MY_USERNAME}
  541. function_check nginx_ensite
  542. nginx_ensite tahoelafs
  543. systemctl reload nginx
  544. }
  545. function install_tahoelafs {
  546. if [ $INSTALLING_MESH ]; then
  547. return
  548. fi
  549. apt-get -yq install build-essential python-pip python-dev libffi-dev libssl-dev
  550. apt-get -yq install libcrypto++-dev python-pycryptopp python-cffi
  551. apt-get -yq install python-virtualenv apache2-utils
  552. if [ -d $TAHOE_DIR ]; then
  553. groupdel -f tahoelafs
  554. userdel -r tahoelafs
  555. rm -rf $TAHOE_DIR
  556. fi
  557. # create a user
  558. adduser --disabled-login --gecos 'tahoe-lafs' tahoelafs
  559. if [ ! -d $TAHOE_DIR ]; then
  560. echo $"$TAHOE_DIR directory was not created"
  561. exit 879335
  562. fi
  563. adduser tahoelafs debian-tor
  564. groupadd tahoelafs
  565. apt-get -yq install tahoe-lafs
  566. pip install tahoe-lafs[tor]
  567. if [ -d $TAHOE_DIR/Maildir ]; then
  568. rm -rf $TAHOE_DIR/Maildir
  569. fi
  570. # remove files we don't need
  571. rm -rf $TAHOE_DIR/.mutt
  572. rm $TAHOE_DIR/.emacs-mutt
  573. rm $TAHOE_DIR/.muttrc
  574. rm $TAHOE_DIR/.mutt-alias
  575. rm $TAHOE_DIR/.procmailrc
  576. # set permissions
  577. chown -R tahoelafs:debian-tor $TAHOE_DIR
  578. node_nick=$(get_tahoelafs_nick)
  579. client_nick=${MY_USERNAME}-client
  580. # create an onion address for storage node
  581. TAHOELAFS_STORAGE_ONION_HOSTNAME=$(add_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_PORT} ${TAHOELAFS_STORAGE_ONION_PORT} ${node_nick})
  582. # create an onion address for client node
  583. TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs 80 ${TAHOELAFS_ONION_PORT})
  584. create_tahoelafs_stealth_node $TAHOE_DIR/storage $TAHOE_DIR/client ${node_nick} ${client_nick}
  585. # start the storage node
  586. su -c "/usr/bin/python2 /usr/bin/tahoe start $TAHOE_DIR/storage" - tahoelafs
  587. create_tahoelafs_daemon "storage"
  588. # start the client
  589. su -c "/usr/bin/python2 /usr/bin/tahoe start $TAHOE_DIR/client" - tahoelafs
  590. add_tahoelafs_server "$(get_tahoelafs_storage_hostname)" "$(get_tahoelafs_public_key)" "${node_nick}" "$(get_tahoelafs_furl)"
  591. if ! grep -q "HidServAuth $(get_tahoelafs_storage_hostname)" /etc/tor/torrc; then
  592. echo $'Unable to create tahoelafs server'
  593. exit 738752
  594. fi
  595. if [ ! -f ${tahoelafs_storage_file} ]; then
  596. echo $'tahoelafs server file missing'
  597. exit 529362
  598. fi
  599. create_tahoelafs_daemon "client"
  600. set_completion_param "tahoelafs onion domain" "$TAHOELAFS_ONION_HOSTNAME"
  601. create_tahoelafs_web
  602. onion_update
  603. APP_INSTALLED=1
  604. }
  605. # NOTE: deliberately no exit 0