freedombone-controlpanel-user 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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 28 \
  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 40
  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 40
  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. any_key
  334. dialog --title $"Publish your PGP/GPG key" \
  335. --msgbox $"Your key has now been published" 6 40
  336. }
  337. function add_gpg_key {
  338. data=$(tempfile 2>/dev/null)
  339. trap "rm -f $data" 0 1 2 5 15
  340. dialog --title $"Add someone's PGP/GPG key" \
  341. --backtitle $"Freedombone User Control Panel" \
  342. --inputbox $"Enter their email address below" 8 60 2>$data
  343. sel=$?
  344. case $sel in
  345. 0)
  346. ADD_EMAIL_ADDRESS=$(<$data)
  347. if [ ${#ADD_EMAIL_ADDRESS} -gt 2 ]; then
  348. if [[ $ADD_EMAIL_ADDRESS == *"@"* && $ADD_EMAIL_ADDRESS == *"."* ]]; then
  349. clear
  350. gpg --search-keys $ADD_EMAIL_ADDRESS
  351. else
  352. dialog --title $"Unrecognised email address" \
  353. --backtitle $"Freedombone User Control Panel" \
  354. --msgbox $"This doesn't look like an email address" 6 50
  355. fi
  356. fi
  357. ;;
  358. esac
  359. }
  360. function remove_gpg_key {
  361. data=$(tempfile 2>/dev/null)
  362. trap "rm -f $data" 0 1 2 5 15
  363. dialog --title $"Remove someone's PGP/GPG key" \
  364. --backtitle $"Freedombone User Control Panel" \
  365. --inputbox $"Enter their email address below" 8 60 2>$data
  366. sel=$?
  367. case $sel in
  368. 0)
  369. REMOVE_EMAIL_ADDRESS=$(<$data)
  370. if [ ${#REMOVE_EMAIL_ADDRESS} -gt 2 ]; then
  371. if [[ $REMOVE_EMAIL_ADDRESS == *"@"* && $REMOVE_EMAIL_ADDRESS == *"."* ]]; then
  372. if [[ $REMOVE_EMAIL_ADDRESS != $MY_EMAIL_ADDRESS ]]; then
  373. clear
  374. gpg --delete-key $REMOVE_EMAIL_ADDRESS
  375. else
  376. dialog --title $"Remove someone's PGP/GPG key" \
  377. --backtitle $"Freedombone User Control Panel" \
  378. --msgbox $"It's not a good idea to remove your own encryption key" 6 65
  379. fi
  380. else
  381. dialog --title $"Unrecognised email address" \
  382. --backtitle $"Freedombone User Control Panel" \
  383. --msgbox $"This doesn't look like an email address" 6 50
  384. fi
  385. fi
  386. ;;
  387. esac
  388. }
  389. function add_ssh_key {
  390. data=$(tempfile 2>/dev/null)
  391. trap "rm -f $data" 0 1 2 5 15
  392. dialog --title $"Add an ssh key for logging in" \
  393. --backtitle $"Freedombone User Control Panel" \
  394. --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
  395. sel=$?
  396. case $sel in
  397. 0)
  398. SSH_PUBLIC_KEY=$(<$data)
  399. if [ ${#SSH_PUBLIC_KEY} -gt 20 ]; then
  400. if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
  401. if [ ! -d /home/$USER/.ssh ]; then
  402. mkdir /home/$USER/.ssh
  403. fi
  404. if [ ! -f /home/$USER/.ssh/authorized_keys ]; then
  405. touch /home/$USER/.ssh/authorized_keys
  406. fi
  407. if ! grep -q "$SSH_PUBLIC_KEY" /home/$USER/.ssh/authorized_keys; then
  408. echo "$SSH_PUBLIC_KEY" >> /home/$USER/.ssh/authorized_keys
  409. dialog --title $"New ssh key added" \
  410. --backtitle $"Freedombone User Control Panel" \
  411. --msgbox $"Your ssh key has now been added" 6 50
  412. else
  413. dialog --title $"ssh key already added" \
  414. --backtitle $"Freedombone User Control Panel" \
  415. --msgbox $"That ssh key has already been added" 6 50
  416. fi
  417. else
  418. dialog --title $"Unrecognised ssh public key" \
  419. --backtitle $"Freedombone User Control Panel" \
  420. --msgbox $"This doesn't look like an ssh key" 6 50
  421. fi
  422. fi
  423. ;;
  424. esac
  425. }
  426. function remove_ssh_key {
  427. data=$(tempfile 2>/dev/null)
  428. trap "rm -f $data" 0 1 2 5 15
  429. dialog --title $"Remove an ssh key for logging in" \
  430. --backtitle $"Freedombone User Control Panel" \
  431. --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
  432. sel=$?
  433. case $sel in
  434. 0)
  435. SSH_PUBLIC_KEY=$(<$data)
  436. if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
  437. if [ -f /home/$USER/.ssh/authorized_keys ]; then
  438. sed -i "s|.*${SSH_PUBLIC_KEY}.*||g" /home/$USER/.ssh/authorized_keys
  439. dialog --title $"Remove an ssh public key" \
  440. --backtitle $"Freedombone User Control Panel" \
  441. --msgbox $"The ssh key has been removed" 6 50
  442. fi
  443. fi
  444. ;;
  445. esac
  446. }
  447. function menu_encryption_keys {
  448. while true
  449. do
  450. data=$(tempfile 2>/dev/null)
  451. trap "rm -f $data" 0 1 2 5 15
  452. dialog --backtitle $"Freedombone User Control Panel" \
  453. --title $"Your Encryption Keys" \
  454. --radiolist $"Choose an operation:" 15 70 7 \
  455. 1 $"Show your PGP/GPG key" off \
  456. 2 $"Publish your PGP/GPG key so that others can find it" off \
  457. 3 $"Add someone's PGP/GPG key" off \
  458. 4 $"Remove someone's PGP/GPG key" off \
  459. 5 $"Add an ssh key for logging in" off \
  460. 6 $"Remove an ssh key for logging in" off \
  461. 7 $"Back to main menu" on 2> $data
  462. sel=$?
  463. case $sel in
  464. 1) break;;
  465. 255) break;;
  466. esac
  467. case $(cat $data) in
  468. 1) show_gpg_key;;
  469. 2) publish_gpg_key;;
  470. 3) add_gpg_key;;
  471. 4) remove_gpg_key;;
  472. 5) add_ssh_key;;
  473. 6) remove_ssh_key;;
  474. 7) break;;
  475. esac
  476. done
  477. }
  478. function menu_email {
  479. while true
  480. do
  481. data=$(tempfile 2>/dev/null)
  482. trap "rm -f $data" 0 1 2 5 15
  483. dialog --backtitle $"Freedombone User Control Panel" \
  484. --title $"Change Email Filtering Rules" \
  485. --radiolist $"Choose an operation:" 14 70 7 \
  486. 1 $"Add yourself to a mailing list" off \
  487. 2 $"Remove yourself from a mailing list" off \
  488. 3 $"Add an email rule for an address" off \
  489. 4 $"Add an email rule for a subject" off \
  490. 5 $"Block or unblock an email address" off \
  491. 6 $"Block or unblock email with subject text" off \
  492. 7 $"Back to main menu" on 2> $data
  493. sel=$?
  494. case $sel in
  495. 1) break;;
  496. 255) break;;
  497. esac
  498. case $(cat $data) in
  499. 1) add_to_mailing_list;;
  500. 2) remove_user_from_mailing_list;;
  501. 3) email_rule_address;;
  502. 4) email_rule_subject;;
  503. 5) block_unblock_email;;
  504. 6) block_unblock_subject;;
  505. 7) break;;
  506. esac
  507. done
  508. }
  509. function menu_top_level {
  510. while true
  511. do
  512. data=$(tempfile 2>/dev/null)
  513. trap "rm -f $data" 0 1 2 5 15
  514. dialog --backtitle $"Freedombone User Control Panel" \
  515. --title $"User Control Panel" \
  516. --radiolist $"Choose an operation:" 14 50 7 \
  517. 1 $"Use Email" off \
  518. 2 $"Change Email Filtering Rules" off \
  519. 3 $"Use Chat" off \
  520. 4 $"Use IRC" off \
  521. 5 $"Your Encryption Keys" off \
  522. 6 $"Exit to the command line" off \
  523. 7 $"Log out" on 2> $data
  524. sel=$?
  525. case $sel in
  526. 1) exit 1;;
  527. 255) exit 1;;
  528. esac
  529. case $(cat $data) in
  530. 1) mutt;;
  531. 2) menu_email;;
  532. 3) toxic;;
  533. 4) irssi;;
  534. 5) menu_encryption_keys;;
  535. 6) break;;
  536. 7) kill -HUP `pgrep -s 0 -o`;;
  537. esac
  538. done
  539. }
  540. menu_top_level
  541. clear
  542. . ~/.bashrc
  543. exit 0