freedombone-app-tahoelafs 23KB

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