freedombone/src/freedombone-app-tahoelafs

726 lines
22 KiB
Plaintext
Raw Permalink Normal View History

2016-08-28 00:40:21 +02:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2016-08-28 00:40:21 +02:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2016-08-28 00:40:21 +02:00
#
2017-03-07 00:59:18 +01:00
# Tahow-LAFS data storage grid implemented via Tor
# https://k0rx.com/blog/2017/01/lafs.html
2017-03-04 00:25:38 +01:00
# http://tahoe-lafs.readthedocs.io/en/latest/anonymity-configuration.html
2016-08-28 00:40:21 +02:00
#
# License
# =======
#
2018-01-25 19:35:39 +01:00
# Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
2016-08-28 00:40:21 +02:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-03-03 19:48:33 +01:00
VARIANTS='full full-vim cloud'
2016-08-28 00:40:21 +02:00
IN_DEFAULT_INSTALL=0
2017-03-07 01:02:05 +01:00
SHOW_ON_ABOUT=1
2017-03-10 00:33:41 +01:00
SHOW_ICANN_ADDRESS_ON_ABOUT=0
2016-08-28 00:40:21 +02:00
TAHOELAFS_PORT=50213
2017-03-07 00:59:18 +01:00
TAHOELAFS_STORAGE_PORT=50214
2017-03-04 00:25:38 +01:00
TAHOELAFS_ONION_PORT=8096
2017-03-07 00:59:18 +01:00
TAHOELAFS_STORAGE_ONION_PORT=8097
2017-03-03 19:56:32 +01:00
2017-06-10 13:08:06 +02:00
TAHOE_DIR=/home/tahoelafs
2017-06-10 14:00:01 +02:00
TAHOE_COMMAND='/usr/bin/tahoe'
2017-06-10 13:08:06 +02:00
tahoelafs_storage_file=$TAHOE_DIR/client/private/servers.yaml
2016-08-28 00:40:21 +02:00
2017-03-07 11:15:06 +01:00
TAHOELAFS_SHARES_NEEDED=3
TAHOELAFS_SHARES_HAPPY=7
TAHOELAFS_SHARES_TOTAL=10
2017-03-04 00:25:38 +01:00
tahoelafs_variables=(ONION_ONLY
2017-03-07 00:59:18 +01:00
MY_USERNAME
2017-03-07 11:15:06 +01:00
TAHOELAFS_PORT
TAHOELAFS_SHARES_NEEDED
TAHOELAFS_SHARES_HAPPY
TAHOELAFS_SHARES_TOTAL)
2016-10-05 23:33:41 +02:00
function logging_on_tahoelafs {
echo -n ''
}
function logging_off_tahoelafs {
echo -n ''
}
function add_user_tahoelafs {
if [[ $(app_is_installed tahoelafs) == "0" ]]; then
echo '0'
return
fi
new_username="$1"
new_user_password="$2"
2018-03-01 12:45:51 +01:00
"${PROJECT_NAME}-pass" -u "$new_username" -a tahoelafs -p "$new_user_password"
2017-06-10 17:12:07 +02:00
if grep -q "${new_username}:" /etc/nginx/.htpasswd-tahoelafs; then
2018-03-01 12:45:51 +01:00
sed -i "'/${new_username}:/d" /etc/nginx/.htpasswd-tahoelafs
fi
2018-03-01 12:45:51 +01:00
echo "${new_user_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs "${new_username}"
echo '0'
}
function remove_user_tahoelafs {
remove_username="$1"
2018-03-01 12:45:51 +01:00
"${PROJECT_NAME}-pass" -u "$remove_username" --rmapp tahoelafs
2017-06-10 17:12:07 +02:00
if grep -q "${remove_username}:" /etc/nginx/.htpasswd-tahoelafs; then
2018-03-01 12:45:51 +01:00
sed -i "/${remove_username}:/d" /etc/nginx/.htpasswd-tahoelafs
fi
}
function change_password_tahoelafs {
change_username="$1"
change_password="$2"
2018-03-01 12:45:51 +01:00
"${PROJECT_NAME}-pass" -u "$change_username" -a tahoelafs -p "$change_password"
2017-06-10 17:12:07 +02:00
if grep -q "${change_username}:" /etc/nginx/.htpasswd-tahoelafs; then
2018-03-01 12:45:51 +01:00
sed -i "/tahoe-${change_username}:/d" /etc/nginx/.htpasswd-tahoelafs
fi
2018-03-01 12:45:51 +01:00
echo "${change_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs "${change_username}"
}
2017-03-07 00:59:18 +01:00
function add_tahoelafs_storage_node_interactive {
2018-03-01 12:45:51 +01:00
data=$(mktemp 2>/dev/null)
2017-03-07 00:59:18 +01:00
dialog --backtitle $"Freedombone Configuration" \
--title $"Add Tahoe-LAFS storage node" \
2018-03-01 12:45:51 +01:00
--form $"\\nEnter the storage node details which can be found on the About screen of another server" 13 75 5 \
2017-03-07 00:59:18 +01:00
$"Hostname:" 1 1 "" 1 14 53 40 \
$"Public Key:" 2 1 "" 2 14 53 255 \
$"Nickname:" 3 1 "" 3 14 53 255 \
$"FURL:" 4 1 "" 4 14 53 255 \
2018-03-01 12:45:51 +01:00
2> "$data"
2017-03-07 00:59:18 +01:00
sel=$?
case $sel in
1) return;;
255) return;;
esac
2018-03-01 12:45:51 +01:00
storage_hostname=$(sed -n 1p < "$data")
public_key=$(sed -n 2p < "$data")
nick=$(sed -n 3p < "$data")
furl=$(sed -n 4p < "$data")
rm -f "$data"
2017-03-07 00:59:18 +01:00
if [ ${#public_key} -eq 0 ]; then
return
2017-03-04 00:25:38 +01:00
fi
2017-03-07 00:59:18 +01:00
add_tahoelafs_server "${storage_hostname}" "${public_key}" "${nick}" "${furl}"
2017-03-04 00:25:38 +01:00
2017-03-07 11:15:06 +01:00
if grep -q "$public_key" ${tahoelafs_storage_file}; then
2017-03-07 00:59:18 +01:00
dialog --title $"Add Tahoe-LAFS storage node" \
--msgbox $"Storage node added" 6 40
2017-03-04 00:25:38 +01:00
fi
2017-03-07 00:59:18 +01:00
}
2017-03-04 00:25:38 +01:00
2017-03-07 00:59:18 +01:00
function edit_tahoelafs_nodes {
editor $tahoelafs_storage_file
chown tahoelafs:debian-tor $tahoelafs_storage_file
systemctl restart tahoelafs-client
}
2017-03-04 00:25:38 +01:00
2017-03-07 11:15:06 +01:00
function edit_tahoelafs_shares {
read_config_param TAHOELAFS_SHARES_NEEDED
read_config_param TAHOELAFS_SHARES_HAPPY
read_config_param TAHOELAFS_SHARES_TOTAL
2018-03-01 12:45:51 +01:00
data=$(mktemp 2>/dev/null)
2017-03-07 11:15:06 +01:00
dialog --backtitle $"Freedombone Configuration" \
--title $"Tahoe-LAFS shares" \
2018-03-01 12:45:51 +01:00
--form $"\\nEnter the storage node details which can be found on the About screen of another server" 13 40 3 \
2017-03-07 11:15:06 +01:00
$"Needed:" 1 1 "${TAHOELAFS_SHARES_NEEDED}" 1 14 4 4 \
$"Happy:" 2 1 "${TAHOELAFS_SHARES_HAPPY}" 2 14 4 4 \
$"Total:" 3 1 "${TAHOELAFS_SHARES_TOTAL}" 3 14 4 4 \
2018-03-01 12:45:51 +01:00
2> "$data"
2017-03-07 11:15:06 +01:00
sel=$?
case $sel in
2018-03-01 12:45:51 +01:00
1) rm -f "$data"
return;;
255) rm -f "$data"
return;;
2017-03-07 11:15:06 +01:00
esac
2018-03-01 12:45:51 +01:00
tl_needed=$(sed -n 1p < "$data")
tl_happy=$(sed -n 2p < "$data")
tl_total=$(sed -n 3p < "$data")
rm -f "$data"
2017-03-07 11:15:06 +01:00
if [ ${#tl_needed} -gt 0 ]; then
TAHOELAFS_SHARES_NEEDED=${tl_needed}
fi
if [ ${#tl_happy} -gt 0 ]; then
TAHOELAFS_SHARES_HAPPY=${tl_happy}
fi
if [ ${#tl_total} -gt 0 ]; then
TAHOELAFS_SHARES_TOTAL=${tl_total}
fi
2017-06-10 13:08:06 +02:00
sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
2017-03-07 11:15:06 +01:00
2017-06-10 13:08:06 +02:00
sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
2017-03-07 11:15:06 +01:00
systemctl restart tahoelafs-storage
systemctl restart tahoelafs-client
dialog --title $"Tahoe-LAFS shares" \
--msgbox $"Shares settings changed" 6 40
}
2017-03-07 00:59:18 +01:00
function configure_interactive_tahoelafs {
2018-04-04 14:16:41 +02:00
W=(1 $"Add a storage node"
2 $"Manually edit storage nodes"
3 $"Shares settings")
while true
do
# shellcheck disable=SC2068
selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Tahoe-LAFS" --menu $"Choose an operation, or ESC to exit:" 12 60 3 "${W[@]}" 3>&2 2>&1 1>&3)
if [ ! "$selection" ]; then
break
fi
case $selection in
1) add_tahoelafs_storage_node_interactive;;
2) edit_tahoelafs_nodes;;
3) edit_tahoelafs_shares;;
esac
done
2017-03-07 00:59:18 +01:00
}
function tahoelafs_setup_client_config {
2018-03-01 12:45:51 +01:00
config_file="$1"
2017-03-07 00:59:18 +01:00
nick="$2"
2018-03-01 12:45:51 +01:00
{ echo '[node]';
echo "nickname = $nick";
echo 'reveal-IP-address = false';
echo "web.port = tcp:${TAHOELAFS_PORT}:interface=127.0.0.1";
echo 'web.static = public_html';
echo 'tub.port = disabled';
echo 'tub.location = disabled';
echo '';
echo '[client]';
echo 'introducer.furl =';
echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}";
echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}";
echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}";
echo '';
echo '[storage]';
echo 'enabled = false';
echo 'reserved_space = 3G';
echo '';
echo '[helper]';
echo 'enabled = false';
echo '';
echo '[connections]';
echo 'tcp = tor'; } > "$config_file"
2017-03-07 00:59:18 +01:00
}
function tahoelafs_setup_storage_config {
2018-03-01 12:45:51 +01:00
config_file="$1"
2017-03-07 00:59:18 +01:00
nick="$2"
2017-03-04 00:25:38 +01:00
2018-03-01 12:45:51 +01:00
{ echo '[node]';
echo "nickname = $nick";
echo 'reveal-IP-address = false';
echo 'web.port =';
echo 'web.static = public_html';
echo "tub.port = tcp:${TAHOELAFS_STORAGE_ONION_PORT}:interface=127.0.0.1";
echo "tub.location = tor:${TAHOELAFS_STORAGE_ONION_HOSTNAME}:${TAHOELAFS_STORAGE_PORT}";
echo '';
echo '[client]';
echo 'introducer.furl =';
echo 'helper.furl =';
echo '';
echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}";
echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}";
echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}";
echo '';
echo '[storage]';
echo 'enabled = true';
echo 'reserved_space = 3G';
echo 'expire.enabled = true';
echo 'expire.mode = age';
echo 'expire.override_lease_duration = 3 months';
echo '';
echo '[helper]';
echo 'enabled = false';
echo '';
echo '[connections]';
echo 'tcp = tor'; } > "$config_file"
2017-03-04 00:25:38 +01:00
2017-06-10 13:08:06 +02:00
chown -R tahoelafs:debian-tor $TAHOE_DIR
2017-03-04 00:25:38 +01:00
}
function install_interactive_tahoelafs {
echo -n ''
APP_INSTALLED=1
}
2016-08-28 00:40:21 +02:00
function upgrade_tahoelafs {
2017-06-10 14:00:01 +02:00
echo -n ''
2016-08-28 00:40:21 +02:00
}
function backup_local_tahoelafs {
2017-06-10 13:08:06 +02:00
source_directory=$TAHOE_DIR
2016-08-29 12:04:37 +02:00
if [ ! -d $source_directory ]; then
return
fi
systemctl stop tahoelafs
dest_directory=tahoelafs
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
systemctl start tahoelafs
2016-08-28 00:40:21 +02:00
}
function restore_local_tahoelafs {
echo $"Restoring Tahoe-LAFS"
2017-03-05 20:49:18 +01:00
systemctl stop tahoelafs-storage
systemctl stop tahoelafs-client
2016-08-29 12:04:37 +02:00
temp_restore_dir=/root/temptahoelafs
restore_directory_from_usb $temp_restore_dir tahoelafs
if [ -d $temp_restore_dir$TAHOE_DIR ]; then
mv $TAHOE_DIR ${TAHOE_DIR}-old
cp -r $temp_restore_dir$TAHOE_DIR $TAHOE_DIR
else
cp -r $temp_restore_dir/* $TAHOE_DIR/
fi
2018-03-01 12:45:51 +01:00
# shellcheck disable=SC2181
2016-08-29 12:21:39 +02:00
if [ ! "$?" = "0" ]; then
if [ -d ${TAHOE_DIR}-old ]; then
mv ${TAHOE_DIR}-old $TAHOE_DIR
fi
2016-08-29 12:21:39 +02:00
exit 246833
fi
if [ -d ${TAHOE_DIR}-old ]; then
rm -rf ${TAHOE_DIR}-old
fi
rm -rf $temp_restore_dir
2017-06-10 13:08:06 +02:00
chown -R tahoelafs:debian-tor $TAHOE_DIR
systemctl start tahoelafs-client
2017-03-05 20:49:18 +01:00
systemctl start tahoelafs-storage
2016-08-29 12:21:39 +02:00
echo $"Restore complete"
2016-08-28 00:40:21 +02:00
}
function backup_remote_tahoelafs {
2017-06-10 13:08:06 +02:00
source_directory=$TAHOE_DIR
2016-08-29 12:21:39 +02:00
if [ ! -d $source_directory ]; then
return
fi
2017-03-05 20:49:18 +01:00
systemctl stop tahoelafs-storage
systemctl stop tahoelafs-client
2016-08-29 12:21:39 +02:00
dest_directory=tahoelafs
function_check backup_directory_to_usb
backup_directory_to_friend $source_directory $dest_directory
systemctl start tahoelafs-client
2017-03-05 20:49:18 +01:00
systemctl start tahoelafs-storage
2016-08-28 00:40:21 +02:00
}
function restore_remote_tahoelafs {
echo $"Restoring Tahoe-LAFS"
2017-03-05 20:49:18 +01:00
systemctl stop tahoelafs-storage
systemctl stop tahoelafs-client
2016-08-29 12:21:39 +02:00
temp_restore_dir=/root/temptahoelafs
restore_directory_from_friend $temp_restore_dir tahoelafs
if [ -d $temp_restore_dir$TAHOE_DIR ]; then
mv $TAHOE_DIR ${TAHOE_DIR}-old
cp -r $temp_restore_dir$TAHOE_DIR $TAHOE_DIR
else
cp -r $temp_restore_dir/* $TAHOE_DIR/
fi
2018-03-01 12:45:51 +01:00
# shellcheck disable=SC2181
2016-08-29 12:21:39 +02:00
if [ ! "$?" = "0" ]; then
2018-03-01 12:45:51 +01:00
if [ -d "${TAHOE_DIR}-old" ]; then
# shellcheck disable=SC2086
mv ${TAHOE_DIR}-old $TAHOE_DIR
fi
2016-08-29 12:21:39 +02:00
exit 623925
fi
2018-03-01 12:45:51 +01:00
if [ -d "${TAHOE_DIR}-old" ]; then
rm -rf "${TAHOE_DIR}-old"
fi
rm -rf $temp_restore_dir
2017-06-10 13:08:06 +02:00
chown -R tahoelafs:debian-tor $TAHOE_DIR
systemctl start tahoelafs-client
2017-03-05 20:49:18 +01:00
systemctl start tahoelafs-storage
2016-08-29 12:21:39 +02:00
echo $"Restore complete"
2016-08-28 00:40:21 +02:00
}
2017-03-04 00:30:55 +01:00
function reconfigure_tahoelafs {
2017-03-07 00:59:18 +01:00
if [ -f $tahoelafs_storage_file ]; then
rm $tahoelafs_storage_file
2017-03-07 00:59:18 +01:00
fi
sed -i '/HidServAuth /d' /etc/tor/torrc
2017-03-04 00:30:55 +01:00
}
2016-08-28 00:40:21 +02:00
function remove_tahoelafs {
2017-03-05 13:09:45 +01:00
if [ -f /etc/nginx/sites-available/tahoelafs ]; then
nginx_dissite tahoelafs
rm /etc/nginx/sites-available/tahoelafs
if [ -d /var/www/tahoelafs ]; then
rm -rf /var/www/tahoelafs
fi
systemctl reload nginx
fi
2017-03-05 20:49:18 +01:00
systemctl stop tahoelafs-storage
systemctl disable tahoelafs-storage
2017-03-08 18:26:37 +01:00
rm /etc/systemd/system/tahoelafs-storage.service
2017-06-10 22:22:54 +02:00
systemctl daemon-reload
2017-03-04 18:52:15 +01:00
2017-03-07 00:59:18 +01:00
systemctl stop tahoelafs-client
systemctl disable tahoelafs-client
2017-03-08 18:26:37 +01:00
rm /etc/systemd/system/tahoelafs-client.service
2017-06-10 22:22:54 +02:00
systemctl daemon-reload
2017-03-05 20:49:18 +01:00
2017-06-10 14:17:25 +02:00
pip uninstall tahoe-lafs[tor]
2017-06-10 14:00:01 +02:00
apt-get -yq remove tahoe-lafs
2017-03-07 00:59:18 +01:00
if [ -d /var/lib/tahoelafs ]; then
rm -rf /var/lib/tahoelafs
fi
2016-10-17 15:44:49 +02:00
remove_completion_param install_tahoelafs
2017-03-04 00:25:38 +01:00
function_check remove_onion_service
remove_onion_service tahoelafs ${TAHOELAFS_ONION_PORT}
2018-03-01 12:45:51 +01:00
remove_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_ONION_PORT} "$(get_tahoelafs_nick)"
2017-03-07 00:59:18 +01:00
sed -i '/HidServAuth /d' /etc/tor/torrc
2017-06-12 12:33:54 +02:00
groupdel -f tahoelafs
userdel -r tahoelafs
2017-06-10 13:08:06 +02:00
if [ -d $TAHOE_DIR ]; then
rm -rf $TAHOE_DIR
2017-03-04 18:52:15 +01:00
fi
2017-03-04 00:28:52 +01:00
remove_app tahoelafs
if [ -f /etc/nginx/.htpasswd-tahoelafs ]; then
rm /etc/nginx/.htpasswd-tahoelafs
fi
2017-06-10 15:13:43 +02:00
onion_update
2016-08-28 00:40:21 +02:00
}
2017-03-07 00:59:18 +01:00
function create_tahoelafs_stealth_node {
node_dir="$1"
client_dir="$2"
node_nick="$3"
client_nick="$4"
if [ ${#node_dir} -eq 0 ]; then
echo $'No tahoe-LAFS storage node directory given'
exit 783522
fi
if [ ${#client_dir} -eq 0 ]; then
echo $'No tahoe-LAFS client directory given'
exit 368935
fi
if [ ${#node_nick} -eq 0 ]; then
echo $'No tahoe-LAFS node nick given'
exit 672351
fi
if [ ${#client_nick} -eq 0 ]; then
echo $'No tahoe-LAFS client nick given'
exit 682362
fi
2018-03-01 12:45:51 +01:00
if [ ! -f "${node_dir}/tahoe.cfg" ]; then
2017-03-07 00:59:18 +01:00
su -c "mkdir ${node_dir}" - tahoelafs
su -c "$TAHOE_COMMAND create-node -C ${node_dir} --hostname=fixme" - tahoelafs
2018-03-01 12:45:51 +01:00
tahoelafs_setup_storage_config "${node_dir}/tahoe.cfg" "${node_nick}"
2017-03-07 00:59:18 +01:00
fi
2018-03-01 12:45:51 +01:00
if [ ! -f "${client_dir}/tahoe.cfg" ]; then
2017-03-07 00:59:18 +01:00
su -c "mkdir ${client_dir}" - tahoelafs
su -c "$TAHOE_COMMAND create-client -C ${client_dir}" - tahoelafs
2018-03-01 12:45:51 +01:00
tahoelafs_setup_client_config "${client_dir}/tahoe.cfg" "${client_nick}"
2017-03-07 00:59:18 +01:00
fi
}
2017-03-05 20:49:18 +01:00
function create_tahoelafs_introducer {
introducer_dir="$1"
2018-03-01 12:45:51 +01:00
if [ -f "${introducer_dir}/tahoe.cfg" ]; then
2017-03-05 20:49:18 +01:00
return
fi
2017-03-05 21:46:53 +01:00
su -c "mkdir ${introducer_dir}" - tahoelafs
2017-03-05 20:49:18 +01:00
su -c "$TAHOE_COMMAND create-introducer -C ${introducer_dir} --hide-ip --hostname=127.0.0.1" - tahoelafs
}
2017-03-05 14:07:45 +01:00
2017-03-05 20:49:18 +01:00
function create_tahoelafs_storage_node {
# Nodes can store data
2017-03-05 20:49:18 +01:00
node_dir="$1"
furl="$2"
if [ ${#furl} -eq 0 ]; then
return
2017-03-05 14:07:45 +01:00
fi
2017-03-05 20:49:18 +01:00
2018-03-01 12:45:51 +01:00
if [ -f "${node_dir}/tahoe.cfg" ]; then
2017-03-05 20:49:18 +01:00
return
fi
2017-03-05 21:46:53 +01:00
su -c "mkdir ${node_dir}" - tahoelafs
2017-03-05 22:23:14 +01:00
su -c "$TAHOE_COMMAND create-node -C ${node_dir} --introducer=\"$furl\" --listen=tor --hide-ip" - tahoelafs
2017-03-05 20:49:18 +01:00
}
function create_tahoelafs_client {
# Clients have no storage
client_dir="$1"
furl="$2"
if [ ${#furl} -eq 0 ]; then
return
fi
2018-03-01 12:45:51 +01:00
if [ -f "${client_dir}/tahoe.cfg" ]; then
2017-03-05 20:49:18 +01:00
return
fi
2017-03-05 21:46:53 +01:00
su -c "mkdir ${client_dir}" - tahoelafs
2017-03-05 20:49:18 +01:00
su -c "$TAHOE_COMMAND create-client -C ${client_dir} --introducer=\"$furl\" --listen=tor --hide-ip --hostname=127.0.0.1" - tahoelafs
2018-03-01 12:45:51 +01:00
sed -i 's|reveal-IP-address =.*|reveal-IP-address = False|g' "$client_dir/tahoe.cfg"
sed -i 's|tub.port =.*|tub.port = disabled|g' "$client_dir/tahoe.cfg"
sed -i 's|tub.location =.*|tub.location = disabled|g' "$client_dir/tahoe.cfg"
2017-03-05 20:49:18 +01:00
}
2017-03-07 00:59:18 +01:00
function get_tahoelafs_furl {
2017-06-10 13:08:06 +02:00
furl=$(cat $TAHOE_DIR/storage/private/storage.furl)
2017-03-08 19:45:40 +01:00
furl_1=$(echo "${furl}" | awk -F ' ' '{print $1}')
furl_2=$(echo "${furl}" | awk -F ':' '{print $5}')
2017-03-08 19:41:24 +01:00
echo "${furl_1}:${furl_2}"
2017-03-07 00:59:18 +01:00
}
function get_tahoelafs_nick {
echo "${MY_USERNAME}-node"
}
function get_tahoelafs_storage_hostname {
2018-03-01 12:45:51 +01:00
cat /var/lib/tor/hidden_service_storage-tahoelafs/hostname
2017-03-07 00:59:18 +01:00
}
function get_tahoelafs_public_key {
2018-03-01 12:45:51 +01:00
grep 'v0-' "$TAHOE_DIR/storage/node.pubkey" | sed 's|pub-||g'
2017-03-07 00:59:18 +01:00
}
function add_tahoelafs_server {
storage_hostname="$1"
public_key="$2"
nick="$3"
furl="$4"
if [ ${#storage_hostname} -eq 0 ]; then
2017-03-07 16:16:45 +01:00
echo $'No storage hostname'
2017-03-07 00:59:18 +01:00
return
fi
if [ ${#public_key} -eq 0 ]; then
2017-03-07 16:16:45 +01:00
echo $'No public key'
2017-03-07 00:59:18 +01:00
return
fi
if [ ${#nick} -eq 0 ]; then
2017-03-07 16:16:45 +01:00
echo $'No nick'
2017-03-07 00:59:18 +01:00
return
fi
if [ ${#furl} -eq 0 ]; then
2017-03-07 16:16:45 +01:00
echo $'No furl'
2017-03-07 00:59:18 +01:00
return
fi
2017-03-07 15:48:18 +01:00
if [ ! -f ${tahoelafs_storage_file} ]; then
echo 'storage:' > ${tahoelafs_storage_file}
2017-03-07 00:59:18 +01:00
else
2017-03-07 15:48:18 +01:00
if grep -q "${public_key}" ${tahoelafs_storage_file}; then
2017-03-07 16:16:45 +01:00
echo $'Public key already exists'
2017-03-07 15:48:18 +01:00
return
fi
echo '# storage' >> ${tahoelafs_storage_file}
2017-03-07 00:59:18 +01:00
fi
2018-03-01 12:45:51 +01:00
{ echo " ${public_key}:";
echo " ann:";
echo " nickname: ${nick}";
echo " anonymous-storage-FURL: ${furl}"; } >> "${tahoelafs_storage_file}"
2017-03-07 15:48:18 +01:00
chown tahoelafs:debian-tor ${tahoelafs_storage_file}
2017-03-07 00:59:18 +01:00
if ! grep -q "HidServAuth ${storage_hostname}" /etc/tor/torrc; then
echo "HidServAuth ${storage_hostname}" >> /etc/tor/torrc
fi
2017-03-05 20:49:18 +01:00
}
function create_tahoelafs_daemon {
daemon_name=$1
2017-03-05 22:11:15 +01:00
TAHOELAFS_DAEMON_FILE=/etc/systemd/system/tahoelafs-${daemon_name}.service
2017-03-05 22:05:03 +01:00
echo "Creating daemon: $TAHOELAFS_DAEMON_FILE"
2017-03-05 20:49:18 +01:00
2018-03-01 12:45:51 +01:00
{ echo '[Unit]';
echo "Description=Tahoe-LAFS ${daemon_name}";
echo 'After=syslog.target';
echo 'After=network.target';
echo '';
echo '[Service]';
echo 'Type=simple';
echo "User=tahoelafs";
echo "Group=debian-tor";
echo "WorkingDirectory=${TAHOE_DIR}";
echo "ExecStart=/usr/bin/tahoe run ${TAHOE_DIR}/${daemon_name}";
echo "ExecStop=/usr/bin/tahoe stop ${TAHOE_DIR}/${daemon_name}";
echo 'Restart=on-failure';
echo 'RestartSec=10';
echo "Environment=\"USER=tahoelafs\" \"HOME=${TAHOE_DIR}\"";
echo '';
echo '[Install]';
echo 'WantedBy=multi-user.target'; } > "$TAHOELAFS_DAEMON_FILE"
systemctl enable "tahoelafs-${daemon_name}"
2017-03-05 20:49:18 +01:00
systemctl daemon-reload
2018-03-01 12:45:51 +01:00
systemctl start "tahoelafs-${daemon_name}"
2017-03-05 14:07:45 +01:00
}
2017-03-07 00:59:18 +01:00
function create_tahoelafs_web {
if [ ! -d /var/www/tahoelafs/htdocs ]; then
mkdir -p /var/www/tahoelafs/htdocs
fi
2017-03-08 18:33:06 +01:00
TAHOELAFS_LOGIN_TEXT=$'Tahoe-LAFS login'
2017-03-07 00:59:18 +01:00
tahoelafs_nginx_site=/etc/nginx/sites-available/tahoelafs
2018-03-01 12:45:51 +01:00
{ echo 'server {';
echo " listen 127.0.0.1:$TAHOELAFS_ONION_PORT default_server;";
echo " server_name $TAHOELAFS_ONION_HOSTNAME;";
echo ''; } > "$tahoelafs_nginx_site"
2018-03-05 19:15:29 +01:00
function_check nginx_security_options
nginx_security_options tahoelafs
2018-03-01 12:45:51 +01:00
{ echo '';
echo ' # Logs';
echo ' access_log /dev/null;';
echo ' error_log /dev/null;';
echo '';
echo ' # Root';
echo " root /var/www/tahoelafs/htdocs;";
echo '';
echo ' location / {';
echo " auth_basic \"${TAHOELAFS_LOGIN_TEXT}\";";
echo ' auth_basic_user_file /etc/nginx/.htpasswd-tahoelafs;'; } >> "$tahoelafs_nginx_site"
2017-03-07 00:59:18 +01:00
function_check nginx_limits
nginx_limits tahoelafs '15m'
2018-03-01 12:45:51 +01:00
{ echo " rewrite /(.*) /\$1 break;";
echo " proxy_set_header X-Real-IP \$remote_addr;";
echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
echo " proxy_set_header Host \$http_host;";
echo ' proxy_set_header X-NginX-Proxy true;';
echo " proxy_pass http://localhost:${TAHOELAFS_PORT};";
echo ' proxy_redirect off;';
echo ' }';
echo '}'; } >> "$tahoelafs_nginx_site"
TAHOELAFS_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
"${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a tahoelafs -p "$TAHOELAFS_ADMIN_PASSWORD"
if [ ! -f /etc/nginx/.htpasswd-tahoelafs ]; then
touch /etc/nginx/.htpasswd-tahoelafs
fi
2017-06-10 17:11:30 +02:00
if grep -q "${MY_USERNAME}:" /etc/nginx/.htpasswd-tahoelafs; then
2018-03-01 12:45:51 +01:00
sed -i "/${MY_USERNAME}:/d" /etc/nginx/.htpasswd-tahoelafs
fi
2018-03-01 12:45:51 +01:00
echo "${TAHOELAFS_ADMIN_PASSWORD}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs "${MY_USERNAME}"
2017-03-07 00:59:18 +01:00
function_check nginx_ensite
nginx_ensite tahoelafs
systemctl reload nginx
}
2016-08-28 00:40:21 +02:00
function install_tahoelafs {
2018-03-01 12:45:51 +01:00
if [ "$INSTALLING_MESH" ]; then
2016-08-28 00:40:21 +02:00
return
fi
2017-03-04 18:49:44 +01:00
apt-get -yq install build-essential python-pip python-dev libffi-dev libssl-dev
2017-06-10 17:08:01 +02:00
apt-get -yq install libcrypto++-dev python-pycryptopp python-cffi
apt-get -yq install python-virtualenv apache2-utils
2017-06-10 16:11:22 +02:00
if [ -d $TAHOE_DIR ]; then
2017-06-12 12:33:54 +02:00
groupdel -f tahoelafs
userdel -r tahoelafs
2017-06-10 16:11:22 +02:00
rm -rf $TAHOE_DIR
fi
2017-06-10 16:11:22 +02:00
# create a user
adduser --disabled-login --gecos 'tahoe-lafs' tahoelafs
2017-06-10 21:27:23 +02:00
if [ ! -d $TAHOE_DIR ]; then
echo $"$TAHOE_DIR directory was not created"
exit 879335
fi
2017-06-10 16:11:22 +02:00
adduser tahoelafs debian-tor
groupadd tahoelafs
2017-06-10 15:57:42 +02:00
apt-get -yq install tahoe-lafs
pip install tahoe-lafs[tor]
2017-06-10 13:08:06 +02:00
if [ -d $TAHOE_DIR/Maildir ]; then
rm -rf $TAHOE_DIR/Maildir
fi
2017-03-04 21:45:19 +01:00
# remove files we don't need
2017-06-10 13:08:06 +02:00
rm -rf $TAHOE_DIR/.mutt
rm $TAHOE_DIR/.emacs-mutt
rm $TAHOE_DIR/.muttrc
rm $TAHOE_DIR/.mutt-alias
rm $TAHOE_DIR/.procmailrc
2017-03-04 21:45:19 +01:00
# set permissions
2017-06-10 13:08:06 +02:00
chown -R tahoelafs:debian-tor $TAHOE_DIR
2017-03-04 21:45:19 +01:00
2017-03-07 00:59:18 +01:00
node_nick=$(get_tahoelafs_nick)
client_nick=${MY_USERNAME}-client
2017-03-07 00:59:18 +01:00
# create an onion address for storage node
2018-03-02 21:20:58 +01:00
TAHOELAFS_STORAGE_ONION_HOSTNAME=$(add_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_PORT} ${TAHOELAFS_STORAGE_ONION_PORT} "${node_nick}")
2017-03-07 00:59:18 +01:00
# create an onion address for client node
2017-03-08 17:09:34 +01:00
TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs 80 ${TAHOELAFS_ONION_PORT})
2018-03-01 12:45:51 +01:00
create_tahoelafs_stealth_node "$TAHOE_DIR/storage" "$TAHOE_DIR/client" "${node_nick}" "${client_nick}"
2017-03-05 15:01:44 +01:00
# start the storage node
2017-06-10 14:00:01 +02:00
su -c "/usr/bin/python2 /usr/bin/tahoe start $TAHOE_DIR/storage" - tahoelafs
create_tahoelafs_daemon "storage"
2017-03-07 16:50:14 +01:00
# start the client
2017-06-10 14:00:01 +02:00
su -c "/usr/bin/python2 /usr/bin/tahoe start $TAHOE_DIR/client" - tahoelafs
2017-03-07 00:59:18 +01:00
add_tahoelafs_server "$(get_tahoelafs_storage_hostname)" "$(get_tahoelafs_public_key)" "${node_nick}" "$(get_tahoelafs_furl)"
2017-03-07 15:48:18 +01:00
if ! grep -q "HidServAuth $(get_tahoelafs_storage_hostname)" /etc/tor/torrc; then
echo $'Unable to create tahoelafs server'
exit 738752
fi
2017-03-07 15:59:17 +01:00
if [ ! -f ${tahoelafs_storage_file} ]; then
echo $'tahoelafs server file missing'
exit 529362
fi
2017-03-07 00:59:18 +01:00
create_tahoelafs_daemon "client"
set_completion_param "tahoelafs onion domain" "$TAHOELAFS_ONION_HOSTNAME"
2017-03-05 13:09:45 +01:00
2017-03-07 00:59:18 +01:00
create_tahoelafs_web
2017-06-10 15:13:43 +02:00
onion_update
APP_INSTALLED=1
2016-08-28 00:40:21 +02:00
}
# NOTE: deliberately no exit 0