2021-09-25 16:55:29 +02:00
#!/bin/bash
DIALOG_CANCEL = 1
DIALOG_ESC = 255
DIALOG_EXTRA = 3
pouncedir = "/var/lib/pounce"
menu( ) {
exec 3>& 1
selection = $( dialog \
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
--title "Welcome!" \
--clear \
--cancel-label "Exit" \
2021-09-26 01:40:56 +02:00
--menu "Configure your IRC bouncer:" 0 0 8 \
2021-09-26 09:11:47 +02:00
"1" "Edit active networks" \
"2" "Edit disabled networks" \
2021-09-25 16:55:29 +02:00
"3" "Add new network" \
2021-09-26 09:11:47 +02:00
"6" "Manage client certificates" \
2021-09-25 16:55:29 +02:00
2>& 1 1>& 3)
exit_status = $?
exec 3>& -
}
2021-09-26 13:50:07 +02:00
# "4" "Enable network (deprecated)" \
# "5" "Disable network (deprecated)" \
2021-09-25 16:55:29 +02:00
get_networks( ) {
exec 3>& 1
if [ $pouncedir = "" ] ; then
exit
fi
pouncedir = "/var/lib/pounce"
2021-09-26 09:11:47 +02:00
#if ! $(find $pouncedir/users/$USER/$1 -mindepth 0 -maxdepth 0 -empty | grep -q .); then
if [ " $( ls -A $pouncedir /users/$USER /$1 ) " ] ; then
2021-09-25 16:55:29 +02:00
COUNTER = 1
RADIOLIST = ""
user_choice = ""
for i in $pouncedir /users/$USER /$1 /*; do
FILENAME = $( basename " $i " )
RADIOLIST = " $RADIOLIST $FILENAME $FILENAME off "
let COUNTER = COUNTER+1
done
2021-09-25 21:19:48 +02:00
if [ $1 = "enabled" ] ; then
user_choice = $( dialog --ok-label "Edit" \
2021-09-26 01:40:56 +02:00
--extra-button \
--extra-label "Disable" \
2021-09-25 21:19:48 +02:00
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
--radiolist "Networks" 0 0 $COUNTER \
$RADIOLIST \
2>& 1 1>& 3)
2021-09-26 01:40:56 +02:00
exit_status = $?
case $exit_status in
2021-09-26 16:34:31 +02:00
0)
if [ ! $user_choice = "" ] ; then
edit_network "enabled"
fi
2021-09-26 01:40:56 +02:00
; ;
3) set_network "enabled"
; ;
2021-09-26 09:11:47 +02:00
esac
2021-09-25 21:19:48 +02:00
fi
if [ $1 = "disabled" ] ; then
user_choice = $( dialog --ok-label "Edit" \
2021-09-26 01:40:56 +02:00
--extra-button \
--extra-label "Enable" \
2021-09-25 21:19:48 +02:00
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
--radiolist "Networks" 0 0 $COUNTER \
$RADIOLIST \
2>& 1 1>& 3)
2021-09-26 01:40:56 +02:00
exit_status = $?
case $exit_status in
2021-09-26 16:34:31 +02:00
0)
if [ ! $user_choice = "" ] ; then
edit_network "disabled"
fi
2021-09-26 01:40:56 +02:00
; ;
3) set_network "disabled"
; ;
esac
2021-09-25 21:19:48 +02:00
fi
2021-09-25 16:55:29 +02:00
exec 3>& -
echo $user_choice > /tmp/userchoice
else
dialog --title "No entries found" \
--backtitle "LibertaCasa Pounce Configurator" \
--msgbox " There seem to be no $1 networks in your account. " \
10 60
user_choice = ""
fi
}
edit_network( ) {
tmpfile = $( mktemp /tmp/$USER .XXXXXXXXXXXXXXXXXXXX)
cp $pouncedir /users/$USER /$1 /$user_choice $tmpfile
nw_name = $user_choice
nw_hostname = $( egrep '(^|\s)host =' $tmpfile | sed 's/host = //' - )
2021-09-25 21:19:48 +02:00
nw_nickname = $( egrep '(^|\s)nick =' $tmpfile | sed 's/nick = //' - )
2021-09-26 16:34:31 +02:00
nw_password = $( egrep '(^|\s)sasl-plain =' $tmpfile | sed 's/^sasl-plain = [^:]*://' - )
2021-09-25 21:19:48 +02:00
nw_channels = $( egrep '(^|\s)join =' $tmpfile | sed 's/join = //' - )
2021-09-26 01:40:56 +02:00
nw_away = $( egrep '(^|\s)away =' $tmpfile | sed 's/away = //' -)
2021-09-25 21:19:48 +02:00
echo " $nw_hostname \n $nw_nickname \n $nw_password \n $nw_channels \n $nw_away " > /tmp/nwvars
2021-09-25 16:55:29 +02:00
exec 3>& 1
2021-09-25 21:19:48 +02:00
user_input = $( dialog --ok-label "Save" \
2021-09-25 16:55:29 +02:00
--extra-button \
--extra-label "Delete" \
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
2021-09-25 21:19:48 +02:00
--title "Edit IRC Network" \
--form " $USER / $nw_name : " \
15 60 0 \
"Hostname:" 1 1 " $nw_hostname " 1 18 33 0 \
"Nickname:" 2 1 " $nw_nickname " 2 18 33 0 \
2021-09-26 16:34:31 +02:00
"SASL Password:" 3 1 " $nw_password " 3 18 33 128 \
2021-09-25 21:19:48 +02:00
"Channels:" 4 1 " $nw_channels " 4 18 33 0 \
"Away message:" 5 1 " $nw_away " 5 18 33 0 \
2021-09-25 16:55:29 +02:00
2>& 1 1>& 3)
exit_status = $?
exec 3>& -
echo $user_input > /tmp/userinput
2021-09-25 21:19:48 +02:00
case $exit_status in
0)
2021-09-26 01:40:56 +02:00
#tmp_name=$(echo "$user_input" | sed -n 1p)
tmp_hostname = $( echo " $user_input " | sed -n 1p)
tmp_nickname = $( echo " $user_input " | sed -n 2p)
tmp_password = $( echo " $user_input " | sed -n 3p)
tmp_channels = $( echo " $user_input " | sed -n 4p)
tmp_away = $( echo " $user_input " | sed -n 5p)
2021-09-25 21:19:48 +02:00
echo " $tmp_name \n $tmp_nickname \n $tmp_password \n $tmp_channels \n $tmp_away " > /tmp/tmpvars
sed -e " s/ $( egrep '(^|\s)host =' $tmpfile ) /host = $tmp_hostname / " -i $tmpfile
sed -e " s/ $( egrep '(^|\s)nick =' $tmpfile ) /nick = $tmp_nickname / " -i $tmpfile
sed -e " s+ $( egrep '(^|\s)real =' $tmpfile ) +real = $tmp_nickname - https://liberta.casa/+ " -i $tmpfile
sed -e " s/ $( egrep '(^|\s)user =' $tmpfile ) /user = $tmp_nickname / " -i $tmpfile
2021-09-26 16:34:31 +02:00
sed -e " s/ $( egrep '(^|\s)sasl-plain =' $tmpfile ) /sasl-plain = $tmp_nickname : $tmp_password / " -i $tmpfile
2021-09-25 21:19:48 +02:00
sed -e " s/ $( egrep '(^|\s)join =' $tmpfile ) /join = $tmp_channels / " -i $tmpfile
2021-09-26 01:40:56 +02:00
sed -e " s+ $( egrep '(^|\s)away =' $tmpfile ) +away = $tmp_away + " -i $tmpfile
2021-09-25 21:19:48 +02:00
DIFF = $( diff $pouncedir /users/$USER /$1 /$user_choice $tmpfile )
if [ ! " $DIFF " = "" ] ; then
cp $tmpfile $pouncedir /users/$USER /$1 /$user_choice
fi
rm $tmpfile
; ;
2021-09-26 01:40:56 +02:00
3)
remove_network
; ;
2021-09-25 21:19:48 +02:00
esac
2021-09-25 16:55:29 +02:00
nw_name = ""
nw_hostname = ""
nw_nickname = ""
nw_password = ""
nw_channels = ""
nw_away = ""
2021-09-25 21:19:48 +02:00
tmp_name = ""
tmp_hostname = ""
tmp_nickname = ""
tmp_password = ""
tmp_channels = ""
tmp_away = ""
tmpfile = ""
DIFF = ""
2021-09-25 16:55:29 +02:00
}
set_network( ) {
2021-09-26 16:34:31 +02:00
if [ [ $1 = "disabled" ] ] && [ [ $user_choice != "" ] ] ; then
2021-09-25 16:55:29 +02:00
mv $pouncedir /users/$USER /disabled/$user_choice $pouncedir /users/$USER /enabled/$user_choice
2021-09-26 16:34:31 +02:00
systemctl --user enable --now pounce@$user_choice
2021-09-25 16:55:29 +02:00
fi
2021-09-26 16:34:31 +02:00
if [ [ $1 = "enabled" ] ] && [ [ $user_choice != "" ] ] ; then
systemctl --user disable --now pounce@$user_choice
2021-09-25 16:55:29 +02:00
mv $pouncedir /users/$USER /enabled/$user_choice $pouncedir /users/$USER /disabled/$user_choice
fi
2021-09-26 09:11:47 +02:00
$user_choice = ""
2021-09-25 16:55:29 +02:00
}
remove_network( ) {
dialog --title "Delete network" \
--backtitle "LibertaCasa Pounce Configurator" \
--yesno " This will permanently delete the network configuration $USER / $user_choice - Are you sure? " 7 60
exit_status = $?
case $exit_status in
0) rm -f $( find $pouncedir /users/$USER -type f -name " $user_choice " ) ; ;
esac
}
add_network( ) {
2021-09-26 13:50:07 +02:00
tmp_name = ""
tmp_hostname = ""
tmp_nickname = ""
tmp_password = ""
tmp_channels = ""
tmp_away = ""
2021-09-26 16:34:31 +02:00
initnew = ""
2021-09-26 13:50:07 +02:00
while [ [ -z $tmp_name || -z $tmp_hostname || -z $tmp_nickname || -z $tmp_password || -z $tmp_channels || -z $tmp_away ] ] ; do
exec 3>& 1
user_input = $( dialog --ok-label "Submit" \
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
--title "New IRC Network" \
--form "Network specific details:" \
20 50 0 \
"Arbitrary name:" 1 1 " $tmp_name " 1 18 33 0 \
"Hostname:" 2 1 " $tmp_hostname " 2 18 33 0 \
"Nickname:" 3 1 " $tmp_nickname " 3 18 33 0 \
2021-09-26 16:34:31 +02:00
"SASL Password:" 4 1 " $tmp_password " 4 18 33 128 \
2021-09-26 13:50:07 +02:00
"Channels:" 5 1 " $tmp_channels " 5 18 33 0 \
"Away message:" 6 1 " $tmp_away " 6 18 33 0 \
2>& 1 1>& 3)
#3>&1 1>&2 2>&3 3>&-)
2021-09-26 16:34:31 +02:00
if [ " $? " = "1" ] ; then
initnew = "false"
break
fi
2021-09-26 13:50:07 +02:00
exec 3>& -
echo $user_input > /tmp/userinput
tmp_name = $( echo " $user_input " | sed -n 1p)
tmp_hostname = $( echo " $user_input " | sed -n 2p)
tmp_nickname = $( echo " $user_input " | sed -n 3p)
tmp_password = $( echo " $user_input " | sed -n 4p)
tmp_channels = $( echo " $user_input " | sed -n 5p)
tmp_away = $( echo " $user_input " | sed -n 6p)
done
2021-09-26 16:34:31 +02:00
if [ [ $tmp_name != "TEMPLATE" ] ] && [ [ $initnew != "false" ] ] ; then
2021-09-25 16:55:29 +02:00
cp $pouncedir /TEMPLATE $pouncedir /users/$USER /disabled/$tmp_name
2021-09-26 01:40:56 +02:00
sed -e " s+%%POUNCEDIR%%+ $pouncedir + " -i $pouncedir /users/$USER /disabled/$tmp_name
2021-09-25 16:55:29 +02:00
sed -e " s/%%USER%%/ $USER / " -i $pouncedir /users/$USER /disabled/$tmp_name
sed -e " s/%%NAME%%/ $tmp_name / " -i $pouncedir /users/$USER /disabled/$tmp_name
2021-09-26 01:40:56 +02:00
sed -e " s:%%PASSWORD%%: $tmp_password : " -i $pouncedir /users/$USER /disabled/$tmp_name
2021-09-25 16:55:29 +02:00
sed -e " s/%%HOSTNAME%%/ $tmp_hostname / " -i $pouncedir /users/$USER /disabled/$tmp_name
sed -e " s/%%CHANNELS%%/ $tmp_channels / " -i $pouncedir /users/$USER /disabled/$tmp_name
sed -e " s/%%USERNAME%%/ $tmp_nickname / " -i $pouncedir /users/$USER /disabled/$tmp_name
sed -e " s/%%AWAY%%/ $tmp_away / " -i $pouncedir /users/$USER /disabled/$tmp_name
fi
}
2021-09-26 09:11:47 +02:00
certman( ) {
exec 3>& 1
certmansel = $( dialog \
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
--title "Certificate Manager" \
--clear \
--cancel-label "Exit" \
--menu "" 0 0 8 \
"1" "Manage Certificate Authority" \
"2" "Manage Client Certificates" \
2>& 1 1>& 3)
exec 3>& -
case $certmansel in
1 )
get_ca
; ;
2 )
get_certs
; ;
esac
}
get_ca( ) {
sha1 = $( openssl x509 -noout -fingerprint -sha1 -in $pouncedir /users/$USER /ca.pem)
sha256 = $( openssl x509 -noout -fingerprint -sha256 -in $pouncedir /users/$USER /ca.pem)
# exec 3>&1
dialog \
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
--title "Fingerprints" \
--extra-button \
--extra-label "New CA" \
--msgbox " $sha1 \n\n $sha256 " 10 90
exit_status = $?
case $exit_status in
0 )
certman
; ;
3 )
new_ca
; ;
esac
# exec 3>&1-
}
new_ca( ) {
dialog --title "Re-generate Certificate Authority" \
--backtitle "LibertaCasa Pounce Configurator" \
--yes-label "Proceed" \
--no-label "Cancel" \
--yesno "!WARNING!\nThis will REMOVE your existing CA certificate and generate a new one.\nALL existing client certificates will be INVALIDATED immediately.\nYou will need to generate and deploy new client certificates if you decide to continue." 10 90
exit_status = $?
case $exit_status in
0 )
rm -f $pouncedir /users/$USER /ca.pem
/usr/local/bin/pounce -g $pouncedir /users/$USER /ca.pem
get_ca
; ;
1 )
get_ca
; ;
esac
}
get_certs( ) {
exec 3>& 1
#if ! $(find $pouncedir/users/$USER/certs -mindepth 0 -maxdepth 0 -empty -type f | grep -q -); then
if [ " $( ls -A $pouncedir /users/$USER /certs) " ] ; then
CRTCOUNTER = 1
CRTRADIOLIST = ""
crt_choice = ""
for crt in $pouncedir /users/$USER /certs/*; do
CRTFILENAME = $( basename " $crt " )
CRTRADIOLIST = " $CRTRADIOLIST $CRTFILENAME $CRTFILENAME off "
let CRTCOUNTER = CRTCOUNTER+1
done
crt_choice = $( dialog --ok-label "Delete" \
--cancel-label "Back" \
--extra-button \
--extra-label "New Certificate" \
--title "Client Certificates" \
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
--radiolist "Manage your client certificates:" 0 0 $CRTCOUNTER \
$CRTRADIOLIST \
2>& 1 1>& 3)
exit_status = $?
case $exit_status in
0) remove_cert " $crt_choice "
; ;
3) add_cert
; ;
esac
exec 3>& -
echo $crt_choice > /tmp/crtchoice
else
dialog --title "No certificates found" \
--backtitle "LibertaCasa Pounce Configurator" \
--yesno "There seem to be no client certificates in your account. Create your first one?" \
10 60
exit_status = $?
case $exit_status in
0 )
add_cert
; ;
2021-09-26 13:50:07 +02:00
#1 )
# get_certs
# ;;
2021-09-26 09:11:47 +02:00
esac
crt_choice = ""
fi
exec 3>& -
}
add_cert( ) {
exec 3>& 1
crt_input = $( dialog --ok-label "Submit" \
--backtitle "LibertaCasa IRC Services - Pounce Division - https://liberta.casa/" \
--title "New Client Certificate" \
--inputbox "Certificate name:" \
10 60 \
2>& 1 1>& 3)
echo $crt_input > /tmp/crtinput
2021-09-26 13:50:07 +02:00
case $crt_input in
"" )
dialog --title "Error" \
--backtitle "LibertaCasa Pounce Configurator" \
--msgbox "Did you supply a name for the new certificate?" \
10 60
; ;
*)
/usr/local/bin/pounce -a $pouncedir /users/$USER /certs/ca.pem -g $pouncedir /users/$USER /certs/$crt_input .pem
; ;
esac
2021-09-26 09:11:47 +02:00
crt_input = ""
exec 3>& -
get_certs
}
remove_cert( ) {
dialog --title "Delete Certificate" \
--backtitle "LibertaCasa Pounce Configurator" \
--yesno " This will permanently delete the client certificate $USER / $1 .\nThis will BREAK all IRC connections utilizing it.\nAre you sure? " 10 50
exit_status = $?
case $exit_status in
0)
rm -f $pouncedir /users/$USER /certs/$1
get_certs
; ;
1)
get_certs
; ;
esac
}
2021-09-25 16:55:29 +02:00
while true; do
menu
case $exit_status in
$DIALOG_CANCEL )
clear
echo "Good bye!"
exit
; ;
$DIALOG_ESC )
clear
echo "See you!" >& 2
exit 1
; ;
esac
case $selection in
1 )
get_networks "enabled"
2021-09-26 01:40:56 +02:00
# if [ ! -z "$user_choice" ]; then
# edit_network "enabled"
# if [ $exit_status = $DIALOG_EXTRA ]; then
# remove_network
# fi
# fi
2021-09-25 16:55:29 +02:00
; ;
2 )
get_networks "disabled"
2021-09-26 01:40:56 +02:00
# if [ ! -z "$user_choice" ]; then
# edit_network "disabled"
# if [ $exit_status = $DIALOG_EXTRA ]; then
# remove_network
# fi
# fi
2021-09-25 16:55:29 +02:00
; ;
3 )
add_network
; ;
2021-09-26 13:50:07 +02:00
# 4 )
# get_networks "disabled"
# if [ ! -z "$user_choice" ]; then
# set_network "disabled"
# fi
# ;;
# 5 )
# get_networks "enabled"
# if [ ! -z "$user_choice" ]; then
# set_network "enabled"
# fi
# ;;
2021-09-26 09:11:47 +02:00
6 )
certman
; ;
2021-09-25 16:55:29 +02:00
esac
done