From da3f06d60d14a8a3c87382b8d4bcb9b67c108c25 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 30 Sep 2016 14:59:37 +0100 Subject: [PATCH] Include apps on the user control menu --- src/freedombone-app-irc | 4 + src/freedombone-app-syncthing | 172 ++++++++++++++++++++ src/freedombone-app-tox | 10 ++ src/freedombone-app-xmpp | 4 + src/freedombone-controlpanel | 7 +- src/freedombone-controlpanel-user | 260 +++++++----------------------- 6 files changed, 257 insertions(+), 200 deletions(-) diff --git a/src/freedombone-app-irc b/src/freedombone-app-irc index 60039368..d01c49ef 100755 --- a/src/freedombone-app-irc +++ b/src/freedombone-app-irc @@ -36,6 +36,10 @@ IRC_ONION_PORT=6697 # An optional password to log into IRC. This applies to all users IRC_PASSWORD= +function run_client_irc { + irssi +} + function irc_show_password { IRC_PASSWORD=$(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}') dialog --title $"IRC Password" \ diff --git a/src/freedombone-app-syncthing b/src/freedombone-app-syncthing index 9ad1558e..f936805a 100755 --- a/src/freedombone-app-syncthing +++ b/src/freedombone-app-syncthing @@ -39,6 +39,178 @@ SYNCTHING_PORT=22000 SYNCTHING_SHARED_DATA=/var/lib/syncthing/SyncShared SYNCTHING_USER_IDS_FILE='.syncthingids' +function syncthing_create_ids_file { + if [ ! -f ~/.syncthing-server-id ]; then + return + fi + + SYNCTHING_ID=$(cat ~/.syncthing-server-id) + if [ ! -f $SYNCTHING_CONFIG_FILE ]; then + echo $'# Your syncthing configuration file' > $SYNCTHING_CONFIG_FILE + echo '#' >> $SYNCTHING_CONFIG_FILE + echo $"# The ${PROJECT_NAME} syncthing ID is: $SYNCTHING_ID" >> $SYNCTHING_CONFIG_FILE + echo '#' >> $SYNCTHING_CONFIG_FILE + echo '# Paste the IDs of your devices below' >> $SYNCTHING_CONFIG_FILE + echo '#' >> $SYNCTHING_CONFIG_FILE + fi +} + +function syncthing_manual_edit { + if [ ! -f ~/.syncthing-server-id ]; then + return + fi + syncthing_create_ids_file + editor $SYNCTHING_CONFIG_FILE + + # force an update of the configuration + touch ~/.syncthing-update +} + +function syncthing_show_id { + if [ ! -f ~/.syncthing-server-id ]; then + return + fi + + SYNCTHING_ID=$(cat ~/.syncthing-server-id) + dialog --title $"Device ID for ${PROJECT_NAME}" \ + --backtitle $"Freedombone User Control Panel" \ + --msgbox $"In a desktop terminal press shift and select the ID below,\nthen right click and copy.\n\nWithin Connectbot select Menu/Copy and then highlight the ID below\n\n$SYNCTHING_ID" 12 78 +} + +function syncthing_add_id { + if [ ! -f ~/.syncthing-server-id ]; then + return + fi + + syncthing_create_ids_file + + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone User Control Panel" \ + --title $"Add a Syncthing device ID" \ + --form $"Paste the device ID for your laptop/desktop/netbook/phone/tablet below" 9 80 2 \ + $"Device ID:" 1 1 "" 1 26 80 80 \ + $"Description (optional):" 2 1 "" 2 26 80 80 \ + 2> $data + sel=$? + case $sel in + 1) return;; + 255) return;; + esac + SYNCTHING_DEVICE_ID=$(cat $data | sed -n 1p) + SYNCTHING_DESCRIPTION=$(cat $data | sed -n 2p) + + if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then + return + fi + + if [[ $SYNCTHING_DEVICE_ID == *"#"* || $SYNCTHING_DEVICE_ID == *"*"* || $SYNCTHING_DEVICE_ID == *'/'* || $SYNCTHING_DEVICE_ID != *"-"* ]]; then + dialog --title $"Add a Syncthing device ID" \ + --backtitle $"Freedombone User Control Panel" \ + --msgbox $"That doesn't look like a device ID" 6 50 + return + fi + + if grep -q "$SYNCTHING_DEVICE_ID" $SYNCTHING_CONFIG_FILE; then + dialog --title $"Add a Syncthing device ID" \ + --backtitle $"Freedombone User Control Panel" \ + --msgbox $"That ID has already been added" 6 50 + return + fi + + if [ ${#SYNCTHING_DESCRIPTION} -gt 0 ]; then + echo "# $SYNCTHING_DESCRIPTION" >> $SYNCTHING_CONFIG_FILE + fi + echo "$SYNCTHING_DEVICE_ID" >> $SYNCTHING_CONFIG_FILE + + # force an update of the configuration + touch ~/.syncthing-update + + dialog --title $"Add a Syncthing device ID" \ + --backtitle $"Freedombone User Control Panel" \ + --msgbox $"The ID was added" 6 50 +} + +function syncthing_remove_id { + if [ ! -f ~/.syncthing-server-id ]; then + return + fi + + syncthing_create_ids_file + + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone User Control Panel" \ + --title $"Remove a Syncthing device ID" \ + --form $"Paste the device ID which is to be removed below" 8 80 1 \ + $"Device ID:" 1 1 "" 1 14 80 80 \ + 2> $data + sel=$? + case $sel in + 1) return;; + 255) return;; + esac + SYNCTHING_DEVICE_ID=$(cat $data | sed -n 1p) + + if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then + return + fi + + if [[ $SYNCTHING_DEVICE_ID == *"#"* || $SYNCTHING_DEVICE_ID == *"*"* || $SYNCTHING_DEVICE_ID == *'/'* || $SYNCTHING_DEVICE_ID != *"-"* ]]; then + dialog --title $"Remove a Syncthing device ID" \ + --backtitle $"Freedombone User Control Panel" \ + --msgbox $"That doesn't look like a device ID" 6 50 + return + fi + + if ! grep -q "$SYNCTHING_DEVICE_ID" $SYNCTHING_CONFIG_FILE; then + dialog --title $"Remove a Syncthing device ID" \ + --backtitle $"Freedombone User Control Panel" \ + --msgbox $"That ID wasn't registered anyway" 6 50 + return + fi + + sed -i "/$SYNCTHING_DEVICE_ID/d" $SYNCTHING_CONFIG_FILE + + # force an update of the configuration + touch ~/.syncthing-update + + dialog --title $"Remove a Syncthing device ID" \ + --backtitle $"Freedombone User Control Panel" \ + --msgbox $"The ID was removed" 6 50 +} + +function run_client_syncthing { + SYNCTHING_CONFIG_FILE=~/.syncthingids + SYNCTHING_ID=$(cat ~/.syncthing-server-id) + + while true + do + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone User Control Panel" \ + --title $"File Synchronization" \ + --radiolist $"Choose an operation:" 12 70 6 \ + 1 $"Show device ID for ${PROJECT_NAME}" off \ + 2 $"Add an ID for another machine or device" off \ + 3 $"Remove an ID for another machine or device" off \ + 4 $"Manually edit device IDs" off \ + 5 $"Back to main menu" on 2> $data + sel=$? + case $sel in + 1) break;; + 255) break;; + esac + case $(cat $data) in + 1) syncthing_show_id;; + 2) syncthing_add_id;; + 3) syncthing_remove_id;; + 4) syncthing_manual_edit;; + 5) break;; + esac + done +} + function install_interactive_syncthing { echo -n '' } diff --git a/src/freedombone-app-tox b/src/freedombone-app-tox index de8e26db..40ac7a94 100755 --- a/src/freedombone-app-tox +++ b/src/freedombone-app-tox @@ -49,6 +49,16 @@ TOXIC_FILE=/usr/local/bin/toxic QTOX_REPO="https://github.com/bashrc/qTox" QTOX_COMMIT='27a628a3789fca4f31516c3982e580052dd3c773' +function run_client_tox { + # create a tox user + if [ ! -f /home/${USER}/.config/tox/data.tox ]; then + mkdir -p /home/${USER}/.config/tox + chown -R ${USER}:${USER} /home/${USER}/.config + toxid -u ${USER} -n data + fi + toxic -f /home/${USER}/.config/tox/data.tox --force-tcp --SOCKS5-proxy 127.0.0.1 9050 +} + function install_interactive_tox { echo -n '' } diff --git a/src/freedombone-app-xmpp b/src/freedombone-app-xmpp index 37f54a6b..0317b81c 100755 --- a/src/freedombone-app-xmpp +++ b/src/freedombone-app-xmpp @@ -37,6 +37,10 @@ XMPP_PASSWORD= XMPP_CIPHERS='"EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA"' XMPP_ECC_CURVE='"secp384r1"' +function run_client_xmpp { + torify profanity +} + function install_interactive_xmpp { echo -n '' } diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel index a948e128..2d373a54 100755 --- a/src/freedombone-controlpanel +++ b/src/freedombone-controlpanel @@ -1848,7 +1848,7 @@ function menu_wifi { done } -function app_settings { +function menu_app_settings { detect_installable_apps applist="" @@ -1866,6 +1866,9 @@ function app_settings { fi app_index=$[app_index+1] done + if [ $n -le 1 ]; then + return + fi backstr=$'Exit' applist="$applist $n $backstr on" appnames+=("Exit") @@ -1921,7 +1924,7 @@ function menu_top_level { 1) show_about;; 2) menu_backup_restore;; 3) reset_tripwire;; - 4) app_settings;; + 4) menu_app_settings;; 5) ${PROJECT_NAME}-addremove;; 6) logging_on_off;; 7) ping_enable_disable;; diff --git a/src/freedombone-controlpanel-user b/src/freedombone-controlpanel-user index 2c0be65c..1343505f 100755 --- a/src/freedombone-controlpanel-user +++ b/src/freedombone-controlpanel-user @@ -36,8 +36,17 @@ export TEXTDOMAINDIR="/usr/share/locale" MY_EMAIL_ADDRESS=$USER@$HOSTNAME GPG_ID=$(gpg --fingerprint $MY_EMAIL_ADDRESS | grep -i "pub" | head -n 1 | awk -F '/' '{print $2}' | awk -F ' ' '{print $1}') -SYNCTHING_CONFIG_FILE=~/.syncthingids -SYNCTHING_ID=$(cat ~/.syncthing-server-id) +UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-* +for f in $UTILS_FILES +do + source $f +done + +APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-* +for f in $APP_FILES +do + source $f +done function any_key { echo ' ' @@ -595,147 +604,6 @@ function smtp_proxy { fi } -function syncthing_create_ids_file { - if [ ! -f ~/.syncthing-server-id ]; then - return - fi - - SYNCTHING_ID=$(cat ~/.syncthing-server-id) - if [ ! -f $SYNCTHING_CONFIG_FILE ]; then - echo $'# Your syncthing configuration file' > $SYNCTHING_CONFIG_FILE - echo '#' >> $SYNCTHING_CONFIG_FILE - echo $"# The ${PROJECT_NAME} syncthing ID is: $SYNCTHING_ID" >> $SYNCTHING_CONFIG_FILE - echo '#' >> $SYNCTHING_CONFIG_FILE - echo '# Paste the IDs of your devices below' >> $SYNCTHING_CONFIG_FILE - echo '#' >> $SYNCTHING_CONFIG_FILE - fi -} - -function syncthing_manual_edit { - if [ ! -f ~/.syncthing-server-id ]; then - return - fi - syncthing_create_ids_file - editor $SYNCTHING_CONFIG_FILE - - # force an update of the configuration - touch ~/.syncthing-update -} - -function syncthing_show_id { - if [ ! -f ~/.syncthing-server-id ]; then - return - fi - - SYNCTHING_ID=$(cat ~/.syncthing-server-id) - dialog --title $"Device ID for ${PROJECT_NAME}" \ - --backtitle $"Freedombone User Control Panel" \ - --msgbox $"In a desktop terminal press shift and select the ID below,\nthen right click and copy.\n\nWithin Connectbot select Menu/Copy and then highlight the ID below\n\n$SYNCTHING_ID" 12 78 -} - -function syncthing_add_id { - if [ ! -f ~/.syncthing-server-id ]; then - return - fi - - syncthing_create_ids_file - - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone User Control Panel" \ - --title $"Add a Syncthing device ID" \ - --form $"Paste the device ID for your laptop/desktop/netbook/phone/tablet below" 9 80 2 \ - $"Device ID:" 1 1 "" 1 26 80 80 \ - $"Description (optional):" 2 1 "" 2 26 80 80 \ - 2> $data - sel=$? - case $sel in - 1) return;; - 255) return;; - esac - SYNCTHING_DEVICE_ID=$(cat $data | sed -n 1p) - SYNCTHING_DESCRIPTION=$(cat $data | sed -n 2p) - - if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then - return - fi - - if [[ $SYNCTHING_DEVICE_ID == *"#"* || $SYNCTHING_DEVICE_ID == *"*"* || $SYNCTHING_DEVICE_ID == *'/'* || $SYNCTHING_DEVICE_ID != *"-"* ]]; then - dialog --title $"Add a Syncthing device ID" \ - --backtitle $"Freedombone User Control Panel" \ - --msgbox $"That doesn't look like a device ID" 6 50 - return - fi - - if grep -q "$SYNCTHING_DEVICE_ID" $SYNCTHING_CONFIG_FILE; then - dialog --title $"Add a Syncthing device ID" \ - --backtitle $"Freedombone User Control Panel" \ - --msgbox $"That ID has already been added" 6 50 - return - fi - - if [ ${#SYNCTHING_DESCRIPTION} -gt 0 ]; then - echo "# $SYNCTHING_DESCRIPTION" >> $SYNCTHING_CONFIG_FILE - fi - echo "$SYNCTHING_DEVICE_ID" >> $SYNCTHING_CONFIG_FILE - - # force an update of the configuration - touch ~/.syncthing-update - - dialog --title $"Add a Syncthing device ID" \ - --backtitle $"Freedombone User Control Panel" \ - --msgbox $"The ID was added" 6 50 -} - -function syncthing_remove_id { - if [ ! -f ~/.syncthing-server-id ]; then - return - fi - - syncthing_create_ids_file - - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone User Control Panel" \ - --title $"Remove a Syncthing device ID" \ - --form $"Paste the device ID which is to be removed below" 8 80 1 \ - $"Device ID:" 1 1 "" 1 14 80 80 \ - 2> $data - sel=$? - case $sel in - 1) return;; - 255) return;; - esac - SYNCTHING_DEVICE_ID=$(cat $data | sed -n 1p) - - if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then - return - fi - - if [[ $SYNCTHING_DEVICE_ID == *"#"* || $SYNCTHING_DEVICE_ID == *"*"* || $SYNCTHING_DEVICE_ID == *'/'* || $SYNCTHING_DEVICE_ID != *"-"* ]]; then - dialog --title $"Remove a Syncthing device ID" \ - --backtitle $"Freedombone User Control Panel" \ - --msgbox $"That doesn't look like a device ID" 6 50 - return - fi - - if ! grep -q "$SYNCTHING_DEVICE_ID" $SYNCTHING_CONFIG_FILE; then - dialog --title $"Remove a Syncthing device ID" \ - --backtitle $"Freedombone User Control Panel" \ - --msgbox $"That ID wasn't registered anyway" 6 50 - return - fi - - sed -i "/$SYNCTHING_DEVICE_ID/d" $SYNCTHING_CONFIG_FILE - - # force an update of the configuration - touch ~/.syncthing-update - - dialog --title $"Remove a Syncthing device ID" \ - --backtitle $"Freedombone User Control Panel" \ - --msgbox $"The ID was removed" 6 50 -} - function sign_gpg_key { data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 @@ -854,34 +722,6 @@ function menu_email { done } -function menu_syncthing { - while true - do - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone User Control Panel" \ - --title $"File Synchronization" \ - --radiolist $"Choose an operation:" 12 70 6 \ - 1 $"Show device ID for ${PROJECT_NAME}" off \ - 2 $"Add an ID for another machine or device" off \ - 3 $"Remove an ID for another machine or device" off \ - 4 $"Manually edit device IDs" off \ - 5 $"Back to main menu" on 2> $data - sel=$? - case $sel in - 1) break;; - 255) break;; - esac - case $(cat $data) in - 1) syncthing_show_id;; - 2) syncthing_add_id;; - 3) syncthing_remove_id;; - 4) syncthing_manual_edit;; - 5) break;; - esac - done -} - function menu_admin { if [ ! -f /etc/sudoers ]; then clear @@ -905,14 +745,43 @@ function sign_keys { esac } -function run_tox_client { - # create a tox user - if [ ! -f /home/${USER}/.config/tox/data.tox ]; then - mkdir -p /home/${USER}/.config/tox - chown -R ${USER}:${USER} /home/${USER}/.config - toxid -u ${USER} -n data +function menu_run_client_app { + detect_installable_apps + + applist="" + appnames=() + n=1 + app_index=0 + for a in "${APPS_AVAILABLE[@]}" + do + if [[ ${APPS_INSTALLED[$app_index]} != "0" ]]; then + if [[ $(function_exists run_client_${a}) == "1" ]]; then + applist="$applist $n $a off" + n=$[n+1] + appnames+=("$a") + fi + fi + app_index=$[app_index+1] + done + if [ $n -le 1 ]; then + return + fi + backstr=$'Exit' + applist="$applist $n $backstr on" + appnames+=("Exit") + + choice=$(dialog --stdout --backtitle $"Freedombone" \ + --title $"Run an App" \ + --radiolist $'Choose:' \ + 16 40 20 $applist) + + if [ $? -eq 0 ]; then + app_index=$[choice-1] + chosen_app=${appnames[$app_index]} + if [[ $chosen_app != "Exit" ]]; then + run_client_${chosen_app} + fi fi - toxic -f /home/${USER}/.config/tox/data.tox --force-tcp --SOCKS5-proxy 127.0.0.1 9050 } function menu_top_level { @@ -925,16 +794,14 @@ function menu_top_level { --radiolist $"Choose an operation:" 19 50 12 \ 1 $"Use Email" off \ 2 $"Change Email Filtering Rules" off \ - 3 $"Use Tox Chat" off \ - 4 $"Use XMPP Chat" off \ - 5 $"Use IRC" off \ - 6 $"Browse the Web" off \ - 7 $"File Synchronization" off \ - 8 $"My Encryption Keys" off \ - 9 $"Set an outgoing email proxy" off \ - 10 $"Administrator controls" off \ - 11 $"Exit to the command line" off \ - 12 $"Log out" on 2> $data + 3 $"Run an App" off \ + 4 $"Browse the Web" off \ + 5 $"File Synchronization" off \ + 6 $"My Encryption Keys" off \ + 7 $"Set an outgoing email proxy" off \ + 8 $"Administrator controls" off \ + 9 $"Exit to the command line" off \ + 10 $"Log out" on 2> $data sel=$? case $sel in 1) exit 1;; @@ -943,16 +810,13 @@ function menu_top_level { case $(cat $data) in 1) mutt;; 2) menu_email;; - 3) run_tox_client;; - 4) torify profanity;; - 5) irssi;; - 6) torify elinks;; - 7) menu_syncthing;; - 8) menu_encryption_keys;; - 9) smtp_proxy;; - 10) menu_admin;; - 11) break;; - 12) kill -HUP `pgrep -s 0 -o`;; + 3) menu_run_client_app;; + 4) torify elinks;; + 5) menu_encryption_keys;; + 6) smtp_proxy;; + 7) menu_admin;; + 8) break;; + 9) kill -HUP `pgrep -s 0 -o`;; esac done }