2016-07-03 17:13:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# IRC server application
|
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2016-10-12 11:49:12 +02:00
|
|
|
VARIANTS='full full-vim chat'
|
2016-07-06 17:47:55 +02:00
|
|
|
|
2016-10-19 22:52:59 +02:00
|
|
|
IN_DEFAULT_INSTALL=1
|
2016-10-19 22:23:11 +02:00
|
|
|
SHOW_ON_ABOUT=1
|
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
IRC_BOUNCER_PORT=6697
|
|
|
|
IRC_ONION_PORT=$IRC_BOUNCER_PORT
|
|
|
|
IRC_PORT=6698
|
2016-07-03 17:13:34 +02:00
|
|
|
|
|
|
|
# An optional password to log into IRC. This applies to all users
|
|
|
|
IRC_PASSWORD=
|
|
|
|
|
2016-10-05 23:33:41 +02:00
|
|
|
irc_variables=(MY_USERNAME
|
|
|
|
MY_NAME
|
|
|
|
IRC_PORT
|
2016-10-25 21:59:03 +02:00
|
|
|
IRC_BOUNCER_PORT
|
2016-10-05 23:33:41 +02:00
|
|
|
IRC_PASSWORD
|
2016-10-28 16:58:34 +02:00
|
|
|
IRC_ONION_HOSTNAME
|
2016-10-25 21:59:03 +02:00
|
|
|
IRC_OPERATOR_PASSWORD
|
2016-10-05 23:33:41 +02:00
|
|
|
DEFAULT_DOMAIN_NAME
|
|
|
|
INSTALLED_WITHIN_DOCKER
|
|
|
|
ONION_ONLY)
|
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
function start_irc_bouncer {
|
2016-10-28 16:47:08 +02:00
|
|
|
update_default_domain
|
|
|
|
su -c 'znc' - znc
|
2016-10-25 21:59:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function stop_irc_bouncer {
|
|
|
|
pkill znc
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove_user_irc_bouncer {
|
|
|
|
remove_username="$1"
|
|
|
|
|
2016-10-28 17:24:03 +02:00
|
|
|
if [ -f /home/znc/.znc/configs/znc.conf ]; then
|
2016-10-25 21:59:03 +02:00
|
|
|
stop_irc_bouncer
|
2016-10-28 17:24:03 +02:00
|
|
|
sed -i "/<User ${remove_username}>/,/</User>/d" /home/znc/.znc/configs/znc.conf
|
2016-10-25 21:59:03 +02:00
|
|
|
start_irc_bouncer
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-10-02 12:17:01 +02:00
|
|
|
function remove_user_irc {
|
|
|
|
remove_username="$1"
|
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
remove_user_irc_bouncer ${remove_username}
|
2016-10-05 23:33:41 +02:00
|
|
|
if [ -d /home/${remove_username}/.irssi ]; then
|
|
|
|
rm -rf /home/${remove_username}/.irssi
|
2016-10-02 00:39:56 +02:00
|
|
|
fi
|
2016-10-05 23:33:41 +02:00
|
|
|
if [ -d /home/${remove_username}/irclogs ]; then
|
|
|
|
rm -rf /home/${remove_username}/irclogs
|
2016-10-02 12:17:01 +02:00
|
|
|
fi
|
|
|
|
}
|
2016-10-02 00:39:56 +02:00
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
function add_user_irc_bouncer {
|
|
|
|
new_username="$1"
|
|
|
|
new_user_password="$2"
|
|
|
|
is_admin='true'
|
|
|
|
if [ ! $3 ]; then
|
|
|
|
is_admin='false'
|
|
|
|
fi
|
|
|
|
|
2016-10-28 17:15:14 +02:00
|
|
|
if [[ $(is_valid_user "$new_username") == "0" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
read_config_param IRC_PORT
|
|
|
|
read_config_param DEFAULT_DOMAIN_NAME
|
2016-10-28 17:15:14 +02:00
|
|
|
read_config_param IRC_PASSWORD
|
2016-10-25 21:59:03 +02:00
|
|
|
|
|
|
|
stop_irc_bouncer
|
|
|
|
|
2016-10-28 18:05:50 +02:00
|
|
|
new_user_salt_base2=$(echo "$IRC_PASSWORD" | sed "s|#|.|g")
|
2016-10-25 21:59:03 +02:00
|
|
|
new_user_salt=$(echo "$new_user_salt_base2" | sed "s|#|.|g")
|
|
|
|
new_user_hash=$(echo "${new_user_password}${new_user_salt}" | sha256sum)
|
|
|
|
new_user_pass="sha256#${new_user_hash}#${new_user_salt}#"
|
|
|
|
|
2016-10-28 17:24:03 +02:00
|
|
|
echo "<User ${new_username}>" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo " Pass = ${new_user_pass}" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo " Admin = ${is_admin}" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo " Nick = ${new_username}" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo " AltNick = ${new_username}_" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo " Ident = ${new_username}" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo " RealName = ${new_username}" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' Buffer = 100' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' AutoClearChanBuffer = true' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' ChanModes = +stn' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo '' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' LoadModule = chansaver' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' LoadModule = controlpanel' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' LoadModule = perform' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo '' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo " <Network ${PROJECT_NAME}>" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' LoadModule = chansaver' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' LoadModule = keepnick' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' LoadModule = perform' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' LoadModule = simple_away' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo '' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo " Server = ${DEFAULT_DOMAIN_NAME} +${IRC_PORT}" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo " Server = ${IRC_ONION_HOSTNAME} +${IRC_PORT}" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo '' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo " <Chan ${PROJECT_NAME}>" >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' </Chan>' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' </Network>' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo '</User>' >> /home/znc/.znc/configs/znc.conf
|
2016-10-25 21:59:03 +02:00
|
|
|
|
2016-10-28 16:19:22 +02:00
|
|
|
mkdir -p /home/znc/.znc/users/${new_username}/moddata
|
|
|
|
mkdir -p /home/znc/.znc/users/${new_username}/networks
|
|
|
|
mkdir /home/znc/.znc/users/${new_username}/moddata/chanserver
|
|
|
|
mkdir /home/znc/.znc/users/${new_username}/moddata/controlpanel
|
|
|
|
mkdir /home/znc/.znc/users/${new_username}/moddata/perform
|
|
|
|
mkdir /home/znc/.znc/users/${new_username}/moddata/webadmin
|
|
|
|
mkdir -p /home/znc/.znc/users/${new_username}/networks/${PROJECT_NAME}/moddata/chansaver
|
|
|
|
mkdir -p /home/znc/.znc/users/${new_username}/networks/${PROJECT_NAME}/moddata/simple_away
|
|
|
|
|
2016-10-28 17:15:14 +02:00
|
|
|
mkdir -p /home/znc/.znc/moddata/webadmin
|
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
chown -R znc:znc /home/znc/.znc
|
|
|
|
|
|
|
|
start_irc_bouncer
|
|
|
|
}
|
|
|
|
|
2016-10-02 12:17:01 +02:00
|
|
|
function add_user_irc {
|
2016-10-02 00:39:56 +02:00
|
|
|
new_username="$1"
|
|
|
|
new_user_password="$2"
|
|
|
|
|
|
|
|
IRC_PASSWORD=$(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
|
|
|
|
if [ ${#IRC_PASSWORD} -lt 2 ]; then
|
|
|
|
IRC_PASSWORD=
|
|
|
|
fi
|
|
|
|
|
2016-10-05 23:33:41 +02:00
|
|
|
if [ ! -d /home/${new_username}/.irssi ]; then
|
|
|
|
mkdir /home/${new_username}/.irssi
|
2016-10-02 00:39:56 +02:00
|
|
|
fi
|
|
|
|
|
2016-10-05 23:33:41 +02:00
|
|
|
echo 'servers = (' > /home/${new_username}/.irssi/config
|
|
|
|
echo ' {' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' address = "chat.freenode.net";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' chatnet = "Freenode";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' port = "6667";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' autoconnect = "no";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' },' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' {' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' address = "irc.oftc.net";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' chatnet = "OFTC";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' port = "6667";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' autoconnect = "yes";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' },' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' {' >> /home/${new_username}/.irssi/config
|
|
|
|
echo " address = \"${HOSTNAME}\";" >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' chatnet = "Freedombone";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo " port = \"${IRC_PORT}\";" >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' use_ssl = "yes";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' ssl_verify = "no";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' autoconnect = "yes";' >> /home/${new_username}/.irssi/config
|
|
|
|
|
|
|
|
echo ' }' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ');' >> /home/${new_username}/.irssi/config
|
|
|
|
echo '' >> /home/${new_username}/.irssi/config
|
|
|
|
echo 'chatnets = {' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' Freedombone = {' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' type = "IRC";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' max_kicks = "1";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' max_msgs = "4";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' max_whois = "1";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' };' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' Freenode = {' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' type = "IRC";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' max_kicks = "1";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' max_msgs = "4";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' max_whois = "1";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' };' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' OFTC = {' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' type = "IRC";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' max_kicks = "1";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' max_msgs = "1";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' max_whois = "1";' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' };' >> /home/${new_username}/.irssi/config
|
|
|
|
echo '};' >> /home/${new_username}/.irssi/config
|
|
|
|
echo '' >> /home/${new_username}/.irssi/config
|
|
|
|
echo 'channels = (' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/${new_username}/.irssi/config
|
|
|
|
echo ');' >> /home/${new_username}/.irssi/config
|
|
|
|
echo '' >> /home/${new_username}/.irssi/config
|
|
|
|
echo 'settings = {' >> /home/${new_username}/.irssi/config
|
|
|
|
echo " core = { real_name = \"$MY_NAME\"; user_name = \"$new_username\"; nick = \"$new_username\"; };" >> /home/${new_username}/.irssi/config
|
|
|
|
echo ' "fe-text" = { actlist_sort = "refnum"; };' >> /home/${new_username}/.irssi/config
|
2016-10-02 00:39:56 +02:00
|
|
|
echo '};' >> /home/$new_username/.irssi/config
|
2016-10-05 23:33:41 +02:00
|
|
|
echo 'ignores = ( { level = "CTCPS"; } );' >> /home/${new_username}/.irssi/config
|
2016-10-02 00:39:56 +02:00
|
|
|
|
2016-10-05 23:33:41 +02:00
|
|
|
chown -R ${new_username}:${new_username} /home/${new_username}/.irssi
|
2016-10-02 00:39:56 +02:00
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
add_user_irc_bouncer "${new_username}" "${IRC_PASSWORD}"
|
2016-10-02 00:39:56 +02:00
|
|
|
echo '0'
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:59:37 +02:00
|
|
|
function run_client_irc {
|
|
|
|
irssi
|
|
|
|
}
|
|
|
|
|
2016-09-30 14:34:09 +02:00
|
|
|
function irc_show_password {
|
|
|
|
IRC_PASSWORD=$(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
|
|
|
|
dialog --title $"IRC Password" \
|
|
|
|
--msgbox "$IRC_PASSWORD" 6 40
|
|
|
|
}
|
|
|
|
|
|
|
|
function irc_set_global_password {
|
|
|
|
dialog --title $"IRC Password" \
|
|
|
|
--clear \
|
|
|
|
--backtitle $"Freedombone Control Panel" \
|
|
|
|
--passwordbox $"Password for all IRC users, or press Enter for no password" 10 50 2> $data
|
|
|
|
sel=$?
|
|
|
|
case $sel in
|
|
|
|
0)
|
|
|
|
EXISTING_IRC_PASSWORD=$(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
|
|
|
|
NEW_IRC_PASSWORD=$(<$data)
|
|
|
|
sed -i "0,/RE/s/Password =.*/Password =$NEW_IRC_PASSWORD/" /etc/ngircd/ngircd.conf
|
|
|
|
|
|
|
|
# replace the password for all users
|
|
|
|
for d in /home/*/ ; do
|
|
|
|
IRC_USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
2016-10-01 11:48:07 +02:00
|
|
|
if [[ $(is_valid_user "$IRC_USERNAME") == "1" ]]; then
|
2016-10-05 23:33:41 +02:00
|
|
|
if [ -f /home/${IRC_USERNAME}/.irssi/config ]; then
|
|
|
|
sed -i "s|$EXISTING_IRC_PASSWORD|$NEW_IRC_PASSWORD|g" /home/${IRC_USERNAME}/.irssi/config
|
|
|
|
chown -R ${IRC_USERNAME}:${IRC_USERNAME} /home/${IRC_USERNAME}/.irssi
|
2016-09-30 14:34:09 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# restart the daemon for the new password to take effect
|
|
|
|
systemctl restart ngircd
|
|
|
|
|
|
|
|
dialog --title $"IRC Password" \
|
|
|
|
--msgbox $"The IRC password was changed" 6 40
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
function configure_interactive_irc {
|
|
|
|
if [ ! -d /etc/ngircd ]; then
|
|
|
|
dialog --title $"IRC Menu" \
|
|
|
|
--msgbox $"No IRC server is installed" 6 70
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
data=$(tempfile 2>/dev/null)
|
|
|
|
trap "rm -f $data" 0 1 2 5 15
|
|
|
|
dialog --backtitle $"Freedombone Control Panel" \
|
|
|
|
--title $"IRC Menu" \
|
|
|
|
--radiolist $"Choose an operation:" 14 70 4 \
|
|
|
|
1 $"Set a password for all IRC users" off \
|
|
|
|
2 $"Show current IRC login password" off \
|
|
|
|
3 $"Exit" on 2> $data
|
|
|
|
sel=$?
|
|
|
|
case $sel in
|
|
|
|
1) break;;
|
|
|
|
255) break;;
|
|
|
|
esac
|
|
|
|
case $(cat $data) in
|
|
|
|
1) irc_set_global_password;;
|
|
|
|
2) irc_show_password;;
|
|
|
|
3) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-09-30 12:34:39 +02:00
|
|
|
function install_interactive_irc {
|
|
|
|
echo -n ''
|
2016-10-10 20:11:33 +02:00
|
|
|
APP_INSTALLED=1
|
2016-09-30 12:34:39 +02:00
|
|
|
}
|
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
function change_password_irc {
|
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
2016-07-09 12:36:12 +02:00
|
|
|
function reconfigure_irc {
|
2016-09-25 12:20:41 +02:00
|
|
|
echo -n ''
|
2016-07-09 12:36:12 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 16:01:28 +02:00
|
|
|
function upgrade_irc {
|
2016-09-25 12:20:41 +02:00
|
|
|
echo -n ''
|
2016-07-06 16:01:28 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 15:55:09 +02:00
|
|
|
function backup_local_irc {
|
2016-09-25 12:20:41 +02:00
|
|
|
echo -n ''
|
2016-07-06 15:55:09 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 12:15:41 +02:00
|
|
|
function restore_local_irc {
|
2016-09-25 12:20:41 +02:00
|
|
|
echo -n ''
|
2016-07-09 12:15:41 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 15:55:09 +02:00
|
|
|
function backup_remote_irc {
|
2016-09-25 12:20:41 +02:00
|
|
|
echo -n ''
|
2016-07-04 22:02:22 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 12:15:41 +02:00
|
|
|
function restore_remote_irc {
|
2016-09-25 12:20:41 +02:00
|
|
|
echo -n ''
|
2016-07-09 12:15:41 +02:00
|
|
|
}
|
|
|
|
|
2016-07-05 21:07:43 +02:00
|
|
|
function remove_irc {
|
2016-10-01 17:28:32 +02:00
|
|
|
remove_watchdog_daemon ngircd
|
2016-09-25 12:20:41 +02:00
|
|
|
systemctl stop ngircd
|
2016-10-23 20:38:14 +02:00
|
|
|
apt-get -yq remove --purge ngircd
|
|
|
|
apt-get -yq remove --purge irssi
|
2016-09-25 12:20:41 +02:00
|
|
|
if [ -d /etc/ngircd ]; then
|
|
|
|
rm -rf /etc/ngircd
|
|
|
|
fi
|
2016-10-22 11:39:34 +02:00
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
iptables -D INPUT -p tcp --dport 1024:65535 --sport ${IRC_BOUNCER_PORT} -j ACCEPT
|
2016-09-25 12:20:41 +02:00
|
|
|
function_check save_firewall_settings
|
|
|
|
save_firewall_settings
|
2016-10-25 21:59:03 +02:00
|
|
|
firewall_remove ${IRC_BOUNCER_PORT} tcp
|
2016-10-22 11:39:34 +02:00
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
function_check remove_onion_service
|
|
|
|
remove_onion_service irc ${IRC_ONION_PORT}
|
2016-10-17 15:44:49 +02:00
|
|
|
remove_completion_param install_irc
|
|
|
|
remove_completion_param configure_firewall_for_irc
|
2016-10-05 23:33:41 +02:00
|
|
|
sed -i '/IRC /d' ${COMPLETION_FILE}
|
2016-10-28 17:18:13 +02:00
|
|
|
sed -i '/znc 2> /d' /etc/crontab
|
2016-10-28 17:21:19 +02:00
|
|
|
if [ -d /home/znc ]; then
|
|
|
|
userdel -r znc
|
|
|
|
fi
|
2016-10-28 18:02:13 +02:00
|
|
|
sed -i '/IRC login/d' /home/$MY_USERNAME/README
|
2016-07-03 23:21:50 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 19:52:57 +02:00
|
|
|
function configure_firewall_for_irc {
|
2016-09-25 12:20:41 +02:00
|
|
|
if [ ! -d /etc/ngircd ]; then
|
|
|
|
return
|
|
|
|
fi
|
2016-10-16 21:00:20 +02:00
|
|
|
if [[ $(is_completed $FUNCNAME) == "1" ]]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
return
|
|
|
|
fi
|
2016-10-05 23:33:41 +02:00
|
|
|
if [[ ${INSTALLED_WITHIN_DOCKER} == "yes" ]]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
# docker does its own firewalling
|
|
|
|
return
|
|
|
|
fi
|
2016-10-05 23:33:41 +02:00
|
|
|
if [[ ${ONION_ONLY} != "no" ]]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
return
|
|
|
|
fi
|
2016-10-25 21:59:03 +02:00
|
|
|
iptables -I INPUT -p tcp --dport 1024:65535 --sport ${IRC_BOUNCER_PORT} -j ACCEPT
|
2016-09-25 12:20:41 +02:00
|
|
|
function_check save_firewall_settings
|
|
|
|
save_firewall_settings
|
2016-07-03 19:52:57 +02:00
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
firewall_add IRC ${IRC_BOUNCER_PORT} tcp
|
2016-10-05 23:33:41 +02:00
|
|
|
echo 'configure_firewall_for_irc' >> ${COMPLETION_FILE}
|
2016-07-03 19:52:57 +02:00
|
|
|
}
|
|
|
|
|
2016-07-05 22:50:11 +02:00
|
|
|
function install_irc_server {
|
2016-10-01 20:52:39 +02:00
|
|
|
if [[ $(app_is_installed irc_server) == "1" ]]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
return
|
|
|
|
fi
|
2016-10-23 20:38:14 +02:00
|
|
|
apt-get -yq install ngircd
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
if [ ! -d /etc/ngircd ]; then
|
|
|
|
echo $"ERROR: ngircd does not appear to have installed. $CHECK_MESSAGE"
|
|
|
|
exit 53
|
|
|
|
fi
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-10-26 19:16:41 +02:00
|
|
|
# obtain a cert for the default domain
|
|
|
|
if [[ $(cert_exists ${DEFAULT_DOMAIN_NAME} pem) == "0" ]]; then
|
|
|
|
echo $'Obtaining certificate for the main domain'
|
|
|
|
create_site_certificate ${DEFAULT_DOMAIN_NAME} 'yes'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $(cert_exists ${DEFAULT_DOMAIN_NAME}) == "0" ]]; then
|
2016-10-05 23:33:41 +02:00
|
|
|
${PROJECT_NAME}-addcert -h ngircd --dhkey ${DH_KEYLENGTH}
|
2016-09-25 12:20:41 +02:00
|
|
|
function_check check_certificates
|
|
|
|
check_certificates ngircd
|
|
|
|
fi
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-10-05 23:33:41 +02:00
|
|
|
DEFAULTDOMAIN=${DEFAULT_DOMAIN_NAME}
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
# create a login password if needed
|
2016-10-05 23:33:41 +02:00
|
|
|
if [ ! ${IRC_PASSWORD} ]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
IRC_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
|
|
|
|
fi
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-10-28 18:02:13 +02:00
|
|
|
if ! grep -q "IRC login password: $IRC_PASSWORD" /home/$MY_USERNAME/README; then
|
|
|
|
echo '' >> /home/$MY_USERNAME/README
|
|
|
|
echo "IRC login password: $IRC_PASSWORD" >> /home/$MY_USERNAME/README
|
|
|
|
else
|
|
|
|
sed -i "s|IRC login password.*|IRC login password: $IRC_PASSWORD|g" /home/$MY_USERNAME/README
|
|
|
|
fi
|
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
echo '**************************************************' > /etc/ngircd/motd
|
|
|
|
echo $'* F R E E D O M B O N E I R C *' >> /etc/ngircd/motd
|
|
|
|
echo '* *' >> /etc/ngircd/motd
|
|
|
|
echo $'* Freedom in the Cloud *' >> /etc/ngircd/motd
|
|
|
|
echo '**************************************************' >> /etc/ngircd/motd
|
|
|
|
sed -i 's|MotdFile = /etc/ngircd/ngircd.motd|MotdFile = /etc/ngircd/motd|g' /etc/ngircd/ngircd.conf
|
|
|
|
sed -i "s/irc@irc.example.com/$MY_EMAIL_ADDRESS/g" /etc/ngircd/ngircd.conf
|
|
|
|
sed -i "s/irc.example.net/$DEFAULTDOMAIN/g" /etc/ngircd/ngircd.conf
|
|
|
|
sed -i "s|Yet another IRC Server running on Debian GNU/Linux|IRC Server of $DEFAULTDOMAIN|g" /etc/ngircd/ngircd.conf
|
|
|
|
sed -i 's/;Password = wealllikedebian/Password =/g' /etc/ngircd/ngircd.conf
|
2016-10-26 19:16:41 +02:00
|
|
|
if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
|
|
|
|
sed -i "s|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/ngircd/ngircd.conf
|
|
|
|
else
|
|
|
|
sed -i "s|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt|g" /etc/ngircd/ngircd.conf
|
|
|
|
fi
|
|
|
|
sed -i "s|;DHFile = /etc/ngircd/dhparams.pem|DHFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam|g" /etc/ngircd/ngircd.conf
|
|
|
|
sed -i "s|;KeyFile = /etc/ssl/private/server.key|KeyFile = /etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key|g" /etc/ngircd/ngircd.conf
|
2016-10-05 23:33:41 +02:00
|
|
|
sed -i "s/;Ports =.*/Ports = ${IRC_PORT}/1" /etc/ngircd/ngircd.conf
|
|
|
|
sed -i "s/;Ports =.*/Ports = ${IRC_PORT}/2" /etc/ngircd/ngircd.conf
|
2016-09-25 12:20:41 +02:00
|
|
|
sed -i "s/;Name = #ngircd/Name = #${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
|
|
|
|
sed -i "s/;Topic = Our ngircd testing channel/Topic = ${PROJECT_NAME} chat channel/g" /etc/ngircd/ngircd.conf
|
|
|
|
sed -i 's/;MaxUsers = 23/MaxUsers = 23/g' /etc/ngircd/ngircd.conf
|
2016-10-28 15:05:14 +02:00
|
|
|
sed -i "s|;KeyFile = /etc/ngircd/#chan.key|KeyFile = /etc/ngircd/${PROJECT_NAME}.key|g" /etc/ngircd/ngircd.conf
|
2016-09-25 12:20:41 +02:00
|
|
|
sed -i "s/;CloakHost = cloaked.host/CloakHost = ${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
|
|
|
|
IRC_SALT="$(create_password 30)"
|
2016-10-05 23:33:41 +02:00
|
|
|
if [ -f ${IMAGE_PASSWORD_FILE} ]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
IRC_OPERATOR_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
|
|
|
|
else
|
|
|
|
IRC_OPERATOR_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
|
|
|
|
fi
|
|
|
|
sed -i "s|;CloakHostSalt = abcdefghijklmnopqrstuvwxyz|CloakHostSalt = $IRC_SALT|g" /etc/ngircd/ngircd.conf
|
|
|
|
sed -i 's/;ConnectIPv4 = yes/ConnectIPv4 = yes/g' /etc/ngircd/ngircd.conf
|
|
|
|
sed -i 's/;MorePrivacy = no/MorePrivacy = yes/g' /etc/ngircd/ngircd.conf
|
|
|
|
sed -i 's/;RequireAuthPing = no/RequireAuthPing = no/g' /etc/ngircd/ngircd.conf
|
|
|
|
sed -i "s/;Name = TheOper/Name = $MY_USERNAME/g" /etc/ngircd/ngircd.conf
|
|
|
|
sed -i "s/;Password = ThePwd/Password = $IRC_OPERATOR_PASSWORD/g" /etc/ngircd/ngircd.conf
|
|
|
|
sed -i 's|;Listen =.*|Listen = 0.0.0.0,0.0.0.0:9050,127.0.0.1,127.0.0.1:9050|g' /etc/ngircd/ngircd.conf
|
2016-10-05 23:33:41 +02:00
|
|
|
if [ ${IRC_PASSWORD} ]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
sed -i "0,/RE/s/Password =.*/Password =$IRC_PASSWORD/" /etc/ngircd/ngircd.conf
|
|
|
|
fi
|
|
|
|
# upgrade a cypher
|
|
|
|
sed -i 's|SECURE128|SECURE256|g' /etc/ngircd/ngircd.conf
|
|
|
|
mkdir /var/run/ircd
|
|
|
|
chown -R irc:irc /var/run/ircd
|
|
|
|
mkdir /var/run/ngircd
|
|
|
|
touch /var/run/ngircd/ngircd.pid
|
|
|
|
chown -R irc:irc /var/run/ngircd
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
IRC_ONION_HOSTNAME=$(add_onion_service irc ${IRC_PORT} ${IRC_ONION_PORT})
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
systemctl restart ngircd
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-10-01 17:28:32 +02:00
|
|
|
add_watchdog_daemon ngircd
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-09-25 12:20:41 +02:00
|
|
|
function_check configure_firewall_for_irc
|
|
|
|
configure_firewall_for_irc
|
2016-10-05 23:33:41 +02:00
|
|
|
install_completed irc_server
|
2016-07-03 17:13:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function install_irc_client {
|
2016-10-01 20:52:39 +02:00
|
|
|
if [[ $(app_is_installed irc_client) == "1" ]]; then
|
2016-09-25 12:20:41 +02:00
|
|
|
return
|
|
|
|
fi
|
2016-10-23 20:38:14 +02:00
|
|
|
apt-get -yq install irssi
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-10-05 23:33:41 +02:00
|
|
|
if [ ! -d /home/${MY_USERNAME}/.irssi ]; then
|
|
|
|
mkdir /home/${MY_USERNAME}/.irssi
|
2016-09-25 12:20:41 +02:00
|
|
|
fi
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-10-05 23:33:41 +02:00
|
|
|
echo 'servers = (' > /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' {' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' address = "chat.freenode.net";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' chatnet = "Freenode";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' port = "6667";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' autoconnect = "no";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' },' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' {' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' address = "irc.oftc.net";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' chatnet = "OFTC";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' port = "6667";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' autoconnect = "yes";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' },' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' {' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo " address = \"127.0.0.1\";" >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
if [[ ${ONION_ONLY} == 'no' ]]; then
|
|
|
|
echo " port = \"${IRC_PORT}\";" >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' use_ssl = "yes";' >> /home/${MY_USERNAME}/.irssi/config
|
2016-09-25 12:20:41 +02:00
|
|
|
else
|
2016-10-18 11:43:08 +02:00
|
|
|
IRC_ONION_HOSTNAME=$(cat ${COMPLETION_FILE} | grep "irc onion domain" | head -n 1 | awk -F ':' '{print $2}')
|
2016-10-05 23:33:41 +02:00
|
|
|
echo " port = \"${IRC_ONION_PORT}\";" >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' use_ssl = "no";' >> /home/${MY_USERNAME}/.irssi/config
|
2016-09-25 12:20:41 +02:00
|
|
|
fi
|
2016-10-05 23:33:41 +02:00
|
|
|
echo ' chatnet = "Freedombone";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' ssl_verify = "no";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' autoconnect = "yes";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
if [ ${IRC_PASSWORD} ]; then
|
|
|
|
echo " password = \"${IRC_PASSWORD}\";" >> /home/${MY_USERNAME}/.irssi/config
|
2016-09-25 12:20:41 +02:00
|
|
|
fi
|
2016-10-05 23:33:41 +02:00
|
|
|
echo ' }' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ');' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo '' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo 'chatnets = {' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' Freedombone = {' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' type = "IRC";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' max_kicks = "1";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' max_msgs = "4";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' max_whois = "1";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' };' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' Freenode = {' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' type = "IRC";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' max_kicks = "1";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' max_msgs = "4";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' max_whois = "1";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' };' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' OFTC = {' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' type = "IRC";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' max_kicks = "1";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' max_msgs = "1";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' max_whois = "1";' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' };' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo '};' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo '' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo 'channels = (' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ');' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo '' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo 'settings = {' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo " core = { real_name = \"$MY_NAME\"; user_name = \"$MY_USERNAME\"; nick = \"$MY_USERNAME\"; };" >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo ' "fe-text" = { actlist_sort = "refnum"; };' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo '};' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
echo 'ignores = ( { level = "CTCPS"; } );' >> /home/${MY_USERNAME}/.irssi/config
|
|
|
|
|
|
|
|
chown -R ${MY_USERNAME}:${MY_USERNAME} /home/${MY_USERNAME}/.irssi
|
|
|
|
|
|
|
|
install_completed irc_client
|
2016-07-03 17:13:34 +02:00
|
|
|
}
|
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
function install_irc_bouncer {
|
|
|
|
if [[ $(app_is_installed irc_bouncer) == "1" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
apt-get -yq install znc
|
|
|
|
|
|
|
|
adduser --disabled-login --gecos 'znc' znc
|
|
|
|
|
|
|
|
mkdir -p /home/znc/.znc/configs
|
|
|
|
mkdir -p /home/znc/.znc/users
|
|
|
|
|
|
|
|
echo 'Version = 1.4' > /home/znc/.znc/configs/znc.conf
|
|
|
|
echo '<Listener l>' >> /home/znc/.znc/configs/znc.conf
|
2016-10-28 16:19:22 +02:00
|
|
|
echo " Port = $IRC_BOUNCER_PORT" >> /home/znc/.znc/configs/znc.conf
|
2016-10-25 21:59:03 +02:00
|
|
|
echo ' IPv4 = true' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' IPv6 = true' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo ' SSL = true' >> /home/znc/.znc/configs/znc.conf
|
|
|
|
echo '</Listener>' >> /home/znc/.znc/configs/znc.conf
|
2016-10-28 16:19:22 +02:00
|
|
|
echo 'LoadModule = webadmin' >> /home/znc/.znc/configs/znc.conf
|
2016-10-25 21:59:03 +02:00
|
|
|
|
|
|
|
chown -R znc:znc /home/znc/.znc
|
|
|
|
|
2016-10-28 16:19:22 +02:00
|
|
|
add_user_irc_bouncer "${MY_USERNAME}" "${IRC_PASSWORD}" true
|
|
|
|
|
2016-10-25 21:59:03 +02:00
|
|
|
# certificate for use with SSL
|
|
|
|
start_irc_bouncer
|
|
|
|
|
|
|
|
function_check cron_add_mins
|
|
|
|
cron_add_mins 10 "/usr/bin/znc 2> /dev/null" znc
|
|
|
|
|
|
|
|
install_completed irc_bouncer
|
|
|
|
}
|
|
|
|
|
2016-07-05 22:50:11 +02:00
|
|
|
function install_irc {
|
2016-09-25 12:20:41 +02:00
|
|
|
install_irc_server
|
|
|
|
install_irc_client
|
2016-10-25 21:59:03 +02:00
|
|
|
install_irc_bouncer
|
2016-10-10 20:11:33 +02:00
|
|
|
APP_INSTALLED=1
|
2016-07-05 22:50:11 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 17:13:34 +02:00
|
|
|
# NOTE: deliberately no exit 0
|