freedombone-controlpanel-user 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # User control panel for email
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. PROJECT_NAME='freedombone'
  31. export TEXTDOMAIN=${PROJECT_NAME}-controlpanel-user
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. MY_EMAIL_ADDRESS=$USER@$HOSTNAME
  34. GPG_ID=$(gpg --fingerprint $MY_EMAIL_ADDRESS | grep -i "pub" | head -n 1 | awk -F '/' '{print $2}' | awk -F ' ' '{print $1}')
  35. function any_key {
  36. echo ' '
  37. read -n1 -r -p $"Press any key to continue..." key
  38. }
  39. function remove_user_from_mailing_list {
  40. USER_MAILING_LISTS=$(cat "/home/$USER/.procmailrc" | grep '\[' | grep '\]' | awk -F '\[' '{print $2}' | awk -F '\\' '{print $1}')
  41. i=0
  42. W=()
  43. list_name=()
  44. while read -r listname; do
  45. i=$((i+1))
  46. W+=($i "$listname")
  47. list_name+=("$listname")
  48. echo $listname
  49. done <<< "$USER_MAILING_LISTS"
  50. i=$((i+1))
  51. W+=($i $"Exit back to user mainenance")
  52. list_selected=$(dialog --default-item "$i" --backtitle $"Freedombone User Control Panel" --title $"Remove yourself from a mailing list" --menu $"Select one of the following:" 24 50 17 "${W[@]}" 3>&2 2>&1 1>&3)
  53. if [ $? -eq 0 ]; then # Exit with OK
  54. if [ ${list_selected} -ne ${i} ]; then
  55. remove_list_name="${list_name[$((list_selected-1))]}"
  56. # find the line number where the list is defined
  57. line_number=0
  58. i=0
  59. while read -r line
  60. do
  61. if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
  62. line_number=${i}
  63. fi
  64. i=$((i+1))
  65. done < "/home/$USER/.procmailrc"
  66. if [ ${line_number} -eq 0 ]; then
  67. # no match was found
  68. return
  69. fi
  70. # recreate the file
  71. if [ -f /home/${USER}/.procmailrc_new ]; then
  72. rm /home/${USER}/.procmailrc_new
  73. fi
  74. i=0
  75. clip=0
  76. while read -r line
  77. do
  78. i=$((i+1))
  79. if [ ${i} -gt $((line_number-1)) ]; then
  80. if [ ${clip} -eq 0 ]; then
  81. clip=1
  82. fi
  83. if [ ${clip} -eq 1 ]; then
  84. if [ ${i} -lt $((line_number+2)) ]; then
  85. continue
  86. else
  87. if [ ${#line} -lt 1 ]; then
  88. clip=2
  89. continue
  90. fi
  91. if [[ "$line" == ":"* || "$line" == "#"* ]]; then
  92. clip=2
  93. else
  94. continue
  95. fi
  96. fi
  97. fi
  98. fi
  99. echo "$line" >> /home/${USER}/.procmailrc_new
  100. if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
  101. line_number=${i}
  102. fi
  103. done < "/home/$USER/.procmailrc"
  104. cp /home/${USER}/.procmailrc_new /home/${USER}/.procmailrc
  105. rm /home/${USER}/.procmailrc_new
  106. chown ${USER}:${USER} /home/${USER}/.procmailrc
  107. dialog --title $"Remove yourself from mailing list" \
  108. --msgbox $"You have been removed from ${remove_list_name}" 6 50
  109. fi
  110. fi
  111. }
  112. function add_to_mailing_list {
  113. data=$(tempfile 2>/dev/null)
  114. trap "rm -f $data" 0 1 2 5 15
  115. dialog --backtitle $"Freedombone User Control Panel" \
  116. --title $"Subscribe to a mailing list" \
  117. --form $"You can either enter a subject or an email address\n" 11 68 4 \
  118. $"List folder name:" 1 1 "" 1 35 26 25 \
  119. $"Name between [] on subject line:" 2 1 "" 2 35 26 25 \
  120. $"List email address:" 3 1 "" 3 35 26 25 \
  121. $"Public:" 4 1 $"yes" 4 35 4 25 \
  122. 2> $data
  123. sel=$?
  124. case $sel in
  125. 1) return;;
  126. 255) return;;
  127. esac
  128. LIST_NAME=$(cat $data | sed -n 1p)
  129. LIST_SUBJECT=$(cat $data | sed -n 2p)
  130. LIST_EMAIL=$(cat $data | sed -n 3p)
  131. LIST_PUBLIC=$(cat $data | sed -n 4p)
  132. if [ ${#LIST_PUBLIC} -lt 1 ]; then
  133. LIST_PUBLIC='no'
  134. fi
  135. if [[ $LIST_PUBLIC == $'y' || $LIST_PUBLIC == $'Y' || $LIST_PUBLIC == $'true' || $LIST_PUBLIC == $'True' || $LIST_PUBLIC == $'yes' || $LIST_PUBLIC == $'Yes' || $LIST_PUBLIC == $'YES' ]]; then
  136. LIST_PUBLIC='yes'
  137. else
  138. LIST_PUBLIC='no'
  139. fi
  140. if [ ${#LIST_NAME} -lt 2 ]; then
  141. dialog --title $"Add mailing list" \
  142. --msgbox $"No mailing list name was given" 6 40
  143. return
  144. fi
  145. if [ ${#LIST_SUBJECT} -lt 2 ]; then
  146. if [ ${#LIST_EMAIL} -lt 2 ]; then
  147. dialog --title $"Add mailing list" \
  148. --msgbox $"No mailing list subject or address was given" 6 40
  149. return
  150. fi
  151. fi
  152. if [ ${#LIST_SUBJECT} -gt 1 ]; then
  153. ${PROJECT_NAME}-addlist -u $USER -l "$LIST_NAME" \
  154. -s "$LIST_SUBJECT" --public $LIST_PUBLIC
  155. else
  156. if [[ "$LIST_EMAIL" != *"@"* || "$LIST_EMAIL" != *"."* ]]; then
  157. dialog --title $"Add mailing list" \
  158. --msgbox $"Unrecognised email address" 6 40
  159. return
  160. else
  161. ${PROJECT_NAME}-addlist -u $USER -l "$LIST_NAME" \
  162. -e "$LIST_EMAIL" --public $LIST_PUBLIC
  163. fi
  164. fi
  165. dialog --title $"Add mailing list" \
  166. --msgbox $"$LIST_NAME list was added" 6 40
  167. }
  168. function email_rule_address {
  169. data=$(tempfile 2>/dev/null)
  170. trap "rm -f $data" 0 1 2 5 15
  171. dialog --backtitle $"Freedombone User Control Panel" \
  172. --title $"Create an email rule" \
  173. --form "\n" 9 65 4 \
  174. $"When email arrives from address:" 1 1 "" 1 35 24 28 \
  175. $"Move to folder:" 2 1 "" 2 35 24 28 \
  176. $"Public:" 3 1 $"no" 3 35 4 25 \
  177. 2> $data
  178. sel=$?
  179. case $sel in
  180. 1) return;;
  181. 255) return;;
  182. esac
  183. RULE_EMAIL=$(cat $data | sed -n 1p)
  184. RULE_FOLDER=$(cat $data | sed -n 2p)
  185. RULE_PUBLIC=$(cat $data | sed -n 3p)
  186. if [ ${#RULE_PUBLIC} -lt 1 ]; then
  187. RULE_PUBLIC='no'
  188. fi
  189. if [[ $RULE_PUBLIC == $'y' || $RULE_PUBLIC == $'Y' || $RULE_PUBLIC == $'true' || $RULE_PUBLIC == $'True' || $RULE_PUBLIC == $'yes' || $RULE_PUBLIC == $'Yes' || $RULE_PUBLIC == $'YES' ]]; then
  190. RULE_PUBLIC='yes'
  191. else
  192. RULE_PUBLIC='no'
  193. fi
  194. if [ ${#RULE_EMAIL} -lt 2 ]; then
  195. dialog --title $"Create an email rule" \
  196. --msgbox $"No email address was given" 6 40
  197. return
  198. fi
  199. if [ ${#RULE_FOLDER} -lt 2 ]; then
  200. dialog --title $"Create an email rule" \
  201. --msgbox $"No folder name was given" 6 40
  202. return
  203. fi
  204. if [[ "$RULE_EMAIL" != *"@"* || "$RULE_EMAIL" != *"."* ]]; then
  205. dialog --title $"Create an email rule" \
  206. --msgbox $"Unrecognised email address" 6 40
  207. return
  208. fi
  209. ${PROJECT_NAME}-addemail -u $USER -e "$RULE_EMAIL" \
  210. -g "$RULE_FOLDER" --public $RULE_PUBLIC
  211. dialog --title $"Create an email rule" \
  212. --msgbox $"Email rule for $RULE_EMAIL was added" 6 40
  213. }
  214. function email_rule_subject {
  215. data=$(tempfile 2>/dev/null)
  216. trap "rm -f $data" 0 1 2 5 15
  217. dialog --backtitle $"Freedombone User Control Panel" \
  218. --title $"Create an email rule" \
  219. --form "\n" 9 75 4 \
  220. $"When email arrives with subject containing:" 1 1 "" 1 45 24 28 \
  221. $"Move to folder:" 2 1 "" 2 45 24 28 \
  222. $"Public:" 3 1 $"no" 3 45 4 25 \
  223. 2> $data
  224. sel=$?
  225. case $sel in
  226. 1) return;;
  227. 255) return;;
  228. esac
  229. RULE_SUBJECT=$(cat $data | sed -n 1p)
  230. RULE_FOLDER=$(cat $data | sed -n 2p)
  231. RULE_PUBLIC=$(cat $data | sed -n 3p)
  232. if [ ${#RULE_PUBLIC} -lt 1 ]; then
  233. RULE_PUBLIC='no'
  234. fi
  235. if [[ $RULE_PUBLIC == $'y' || $RULE_PUBLIC == $'Y' || $RULE_PUBLIC == $'true' || $RULE_PUBLIC == $'True' || $RULE_PUBLIC == $'yes' || $RULE_PUBLIC == $'Yes' || $RULE_PUBLIC == $'YES' ]]; then
  236. RULE_PUBLIC='yes'
  237. else
  238. RULE_PUBLIC='no'
  239. fi
  240. if [ ${#RULE_SUBJECT} -lt 2 ]; then
  241. dialog --title $"Create an email rule" \
  242. --msgbox $"No subject text was given" 6 40
  243. return
  244. fi
  245. if [ ${#RULE_FOLDER} -lt 2 ]; then
  246. dialog --title $"Create an email rule" \
  247. --msgbox $"No folder name was given" 6 40
  248. return
  249. fi
  250. ${PROJECT_NAME}-addemail -u $USER -s "$RULE_SUBJECT" \
  251. -g "$RULE_FOLDER" --public $RULE_PUBLIC
  252. dialog --title $"Create an email rule" \
  253. --msgbox $"Email rule for subject '$RULE_SUBJECT' was added" 6 40
  254. }
  255. function block_unblock_email {
  256. blockstr=$"Block or unblock emails from a given address"
  257. data=$(tempfile 2>/dev/null)
  258. trap "rm -f $data" 0 1 2 5 15
  259. dialog --backtitle $"Freedombone User Control Panel" \
  260. --title "$blockstr" \
  261. --form "\n" 8 65 3 \
  262. $"When email arrives from address:" 1 1 "" 1 35 24 100 \
  263. $"Block it:" 2 1 "yes" 2 35 4 4 \
  264. 2> $data
  265. sel=$?
  266. case $sel in
  267. 1) return;;
  268. 255) return;;
  269. esac
  270. BLOCK_EMAIL=$(cat $data | sed -n 1p)
  271. BLOCK=$(cat $data | sed -n 2p)
  272. if [ ${#BLOCK_EMAIL} -lt 2 ]; then
  273. dialog --title "$blockstr" \
  274. --msgbox $"No email address was given" 6 40
  275. return
  276. fi
  277. if [[ "$BLOCK_EMAIL" != *"@"* || "$BLOCK_EMAIL" != *"."* ]]; then
  278. dialog --title "$blockstr" \
  279. --msgbox $"Unrecognised email address" 6 40
  280. return
  281. fi
  282. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  283. ${PROJECT_NAME}-ignore -u $USER -e "$BLOCK_EMAIL"
  284. dialog --title $"Block an email" \
  285. --msgbox "Email from $BLOCK_EMAIL is now blocked" 6 75
  286. else
  287. ${PROJECT_NAME}-unignore -u $USER -e "$BLOCK_EMAIL"
  288. dialog --title $"Unblock an email" \
  289. --msgbox "Email from $BLOCK_EMAIL is now unblocked" 6 75
  290. fi
  291. }
  292. function block_unblock_subject {
  293. blockstr=$"Block or unblock emails with text in the subject line"
  294. data=$(tempfile 2>/dev/null)
  295. trap "rm -f $data" 0 1 2 5 15
  296. dialog --backtitle $"Freedombone User Control Panel" \
  297. --title "$blockstr" \
  298. --form "\n" 8 70 3 \
  299. $"When email arrives with subject text:" 1 1 "" 1 40 24 28 \
  300. $"Block it:" 2 1 "yes" 2 40 4 4 \
  301. 2> $data
  302. sel=$?
  303. case $sel in
  304. 1) return;;
  305. 255) return;;
  306. esac
  307. BLOCK_SUBJECT=$(cat $data | sed -n 1p)
  308. BLOCK=$(cat $data | sed -n 2p)
  309. if [ ${#BLOCK_SUBJECT} -lt 2 ]; then
  310. dialog --title "$blockstr" \
  311. --msgbox $"No subject was given" 6 40
  312. return
  313. fi
  314. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  315. ${PROJECT_NAME}-ignore -u $USER -t "$BLOCK_SUBJECT"
  316. dialog --title $"Block an email" \
  317. --msgbox $"Email with subject $BLOCK_SUBJECT is now blocked" 6 40
  318. else
  319. ${PROJECT_NAME}-unignore -u $USER -t "$BLOCK_SUBJECT"
  320. dialog --title $"Unblock an email" \
  321. --msgbox $"Email with subject $BLOCK_SUBJECT is now unblocked" 6 40
  322. fi
  323. }
  324. function show_gpg_key {
  325. GPG_FINGERPRINT=$(gpg --fingerprint $MY_EMAIL_ADDRESS | grep -i "key fingerprint" | head -n 1 | awk -F '= ' '{print $2}')
  326. GPG_DATE=$(gpg --fingerprint $MY_EMAIL_ADDRESS | grep -i "pub" | head -n 1 | awk -F '/' '{print $2}' | awk -F ' ' '{print $2}')
  327. dialog --title $"Your PGP/GPG Key" \
  328. --backtitle $"Freedombone User Control Panel" \
  329. --msgbox $"Email Address: $MY_EMAIL_ADDRESS\n\nKey ID: $GPG_ID\n\nFingerprint: $GPG_FINGERPRINT\n\nCreated: $GPG_DATE" 12 70
  330. }
  331. function publish_gpg_key {
  332. gpg --send-key $GPG_ID
  333. dialog --title $"Publish your PGP/GPG key" \
  334. --msgbox $"Your key has now been published" 6 40
  335. }
  336. function add_gpg_key {
  337. data=$(tempfile 2>/dev/null)
  338. trap "rm -f $data" 0 1 2 5 15
  339. dialog --title $"Add someone's PGP/GPG key" \
  340. --backtitle $"Freedombone User Control Panel" \
  341. --inputbox $"Enter their email address below" 8 60 2>$data
  342. sel=$?
  343. case $sel in
  344. 0)
  345. ADD_EMAIL_ADDRESS=$(<$data)
  346. if [ ${#ADD_EMAIL_ADDRESS} -gt 2 ]; then
  347. if [[ $ADD_EMAIL_ADDRESS == *"@"* && $ADD_EMAIL_ADDRESS == *"."* ]]; then
  348. clear
  349. gpg --search-keys $ADD_EMAIL_ADDRESS
  350. else
  351. dialog --title $"Unrecognised email address" \
  352. --backtitle $"Freedombone User Control Panel" \
  353. --msgbox $"This doesn't look like an email address" 6 50
  354. fi
  355. fi
  356. ;;
  357. esac
  358. }
  359. function remove_gpg_key {
  360. data=$(tempfile 2>/dev/null)
  361. trap "rm -f $data" 0 1 2 5 15
  362. dialog --title $"Remove someone's PGP/GPG key" \
  363. --backtitle $"Freedombone User Control Panel" \
  364. --inputbox $"Enter their email address below" 8 60 2>$data
  365. sel=$?
  366. case $sel in
  367. 0)
  368. REMOVE_EMAIL_ADDRESS=$(<$data)
  369. if [ ${#REMOVE_EMAIL_ADDRESS} -gt 2 ]; then
  370. if [[ $REMOVE_EMAIL_ADDRESS == *"@"* && $REMOVE_EMAIL_ADDRESS == *"."* ]]; then
  371. if [[ $REMOVE_EMAIL_ADDRESS != $MY_EMAIL_ADDRESS ]]; then
  372. clear
  373. gpg --delete-key $REMOVE_EMAIL_ADDRESS
  374. else
  375. dialog --title $"Remove someone's PGP/GPG key" \
  376. --backtitle $"Freedombone User Control Panel" \
  377. --msgbox $"It's not a good idea to remove your own encryption key" 6 65
  378. fi
  379. else
  380. dialog --title $"Unrecognised email address" \
  381. --backtitle $"Freedombone User Control Panel" \
  382. --msgbox $"This doesn't look like an email address" 6 50
  383. fi
  384. fi
  385. ;;
  386. esac
  387. }
  388. function add_ssh_key {
  389. data=$(tempfile 2>/dev/null)
  390. trap "rm -f $data" 0 1 2 5 15
  391. dialog --title $"Add an ssh key for logging in" \
  392. --backtitle $"Freedombone User Control Panel" \
  393. --inputbox $"This will allow you to log into ${PROJECT_NAME} if you have an ssh key on your system, and provides much stronger security than simply using a login password.\n\nWARNING: If you make any mistakes here then you may not be able to log in and will need to get the administrator to clear your ssh authorized_keys file." 15 60 2>$data
  394. sel=$?
  395. case $sel in
  396. 0)
  397. SSH_PUBLIC_KEY=$(<$data)
  398. if [ ${#SSH_PUBLIC_KEY} -gt 20 ]; then
  399. if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
  400. if [ ! -d /home/$USER/.ssh ]; then
  401. mkdir /home/$USER/.ssh
  402. fi
  403. if [ ! -f /home/$USER/.ssh/authorized_keys ]; then
  404. touch /home/$USER/.ssh/authorized_keys
  405. fi
  406. if ! grep -q "$SSH_PUBLIC_KEY" /home/$USER/.ssh/authorized_keys; then
  407. echo "$SSH_PUBLIC_KEY" >> /home/$USER/.ssh/authorized_keys
  408. dialog --title $"New ssh key added" \
  409. --backtitle $"Freedombone User Control Panel" \
  410. --msgbox $"Your ssh key has now been added" 6 50
  411. else
  412. dialog --title $"ssh key already added" \
  413. --backtitle $"Freedombone User Control Panel" \
  414. --msgbox $"That ssh key has already been added" 6 50
  415. fi
  416. else
  417. dialog --title $"Unrecognised ssh public key" \
  418. --backtitle $"Freedombone User Control Panel" \
  419. --msgbox $"This doesn't look like an ssh key" 6 50
  420. fi
  421. fi
  422. ;;
  423. esac
  424. }
  425. function remove_ssh_key {
  426. data=$(tempfile 2>/dev/null)
  427. trap "rm -f $data" 0 1 2 5 15
  428. dialog --title $"Remove an ssh key for logging in" \
  429. --backtitle $"Freedombone User Control Panel" \
  430. --inputbox $"Enter the ssh public key which is to be removed. This can be just the address at the end.\n\nWARNING: If you make any mistakes here then you may not be able to log in and will need to get the administrator to clear your ssh authorized_keys file." 15 60 2>$data
  431. sel=$?
  432. case $sel in
  433. 0)
  434. SSH_PUBLIC_KEY=$(<$data)
  435. if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
  436. if [ -f /home/$USER/.ssh/authorized_keys ]; then
  437. sed -i "s|.*${SSH_PUBLIC_KEY}.*||g" /home/$USER/.ssh/authorized_keys
  438. dialog --title $"Remove an ssh public key" \
  439. --backtitle $"Freedombone User Control Panel" \
  440. --msgbox $"The ssh key has been removed" 6 50
  441. fi
  442. fi
  443. ;;
  444. esac
  445. }
  446. function menu_encryption_keys {
  447. while true
  448. do
  449. data=$(tempfile 2>/dev/null)
  450. trap "rm -f $data" 0 1 2 5 15
  451. dialog --backtitle $"Freedombone User Control Panel" \
  452. --title $"Your Encryption Keys" \
  453. --radiolist $"Choose an operation:" 15 70 7 \
  454. 1 $"Show your PGP/GPG key" off \
  455. 2 $"Publish your PGP/GPG key so that others can find it" off \
  456. 3 $"Add someone's PGP/GPG key" off \
  457. 4 $"Remove someone's PGP/GPG key" off \
  458. 5 $"Add an ssh key for logging in" off \
  459. 6 $"Remove an ssh key for logging in" off \
  460. 7 $"Back to main menu" on 2> $data
  461. sel=$?
  462. case $sel in
  463. 1) break;;
  464. 255) break;;
  465. esac
  466. case $(cat $data) in
  467. 1) show_gpg_key;;
  468. 2) publish_gpg_key;;
  469. 3) add_gpg_key;;
  470. 4) remove_gpg_key;;
  471. 5) add_ssh_key;;
  472. 6) remove_ssh_key;;
  473. 7) break;;
  474. esac
  475. done
  476. }
  477. function menu_email {
  478. while true
  479. do
  480. data=$(tempfile 2>/dev/null)
  481. trap "rm -f $data" 0 1 2 5 15
  482. dialog --backtitle $"Freedombone User Control Panel" \
  483. --title $"Change Email Filtering Rules" \
  484. --radiolist $"Choose an operation:" 14 70 7 \
  485. 1 $"Add yourself to a mailing list" off \
  486. 2 $"Remove yourself from a mailing list" off \
  487. 3 $"Add an email rule for an address" off \
  488. 4 $"Add an email rule for a subject" off \
  489. 5 $"Block or unblock an email address" off \
  490. 6 $"Block or unblock email with subject text" off \
  491. 7 $"Back to main menu" on 2> $data
  492. sel=$?
  493. case $sel in
  494. 1) break;;
  495. 255) break;;
  496. esac
  497. case $(cat $data) in
  498. 1) add_to_mailing_list;;
  499. 2) remove_user_from_mailing_list;;
  500. 3) email_rule_address;;
  501. 4) email_rule_subject;;
  502. 5) block_unblock_email;;
  503. 6) block_unblock_subject;;
  504. 7) break;;
  505. esac
  506. done
  507. }
  508. function menu_admin {
  509. if [ ! -f /etc/sudoers ]; then
  510. clear
  511. exit 0
  512. fi
  513. if grep -q "$USER ALL=(ALL) ALL" /etc/sudoers; then
  514. sudo freedombone-controlpanel
  515. else
  516. clear
  517. exit 0
  518. fi
  519. }
  520. function menu_top_level {
  521. while true
  522. do
  523. data=$(tempfile 2>/dev/null)
  524. trap "rm -f $data" 0 1 2 5 15
  525. dialog --backtitle $"Freedombone User Control Panel" \
  526. --title $"User Control Panel" \
  527. --radiolist $"Choose an operation:" 16 50 9 \
  528. 1 $"Use Email" off \
  529. 2 $"Change Email Filtering Rules" off \
  530. 3 $"Use Tox Chat" off \
  531. 4 $"Use XMPP Chat" off \
  532. 5 $"Use IRC" off \
  533. 6 $"Your Encryption Keys" off \
  534. 7 $"Administrator controls" off \
  535. 8 $"Exit to the command line" off \
  536. 9 $"Log out" on 2> $data
  537. sel=$?
  538. case $sel in
  539. 1) exit 1;;
  540. 255) exit 1;;
  541. esac
  542. case $(cat $data) in
  543. 1) mutt;;
  544. 2) menu_email;;
  545. 3) toxic --force-tcp --SOCKS5-proxy 127.0.0.1 9050;;
  546. 4) torify profanity;;
  547. 5) torify irssi;;
  548. 6) menu_encryption_keys;;
  549. 7) menu_admin;;
  550. 8) break;;
  551. 9) kill -HUP `pgrep -s 0 -o`;;
  552. esac
  553. done
  554. }
  555. menu_top_level
  556. clear
  557. . ~/.bashrc
  558. exit 0