freedombone-controlpanel-user 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # User control panel
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
  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 --list-keys $MY_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//')
  35. GPG_BACKUP_ID=$(gpg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
  36. # Start including files
  37. UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
  38. for f in $UTILS_FILES
  39. do
  40. source $f
  41. done
  42. APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  43. for f in $APP_FILES
  44. do
  45. source $f
  46. done
  47. # End including files
  48. function any_key {
  49. echo ' '
  50. read -n1 -r -p $"Press any key to continue..." key
  51. }
  52. function remove_user_from_mailing_list {
  53. USER_MAILING_LISTS=$(cat "/home/$USER/.procmailrc" | grep '\[' | grep '\]' | awk -F '\[' '{print $2}' | awk -F '\\' '{print $1}')
  54. i=0
  55. W=()
  56. list_name=()
  57. while read -r listname; do
  58. i=$((i+1))
  59. if [[ "$listname" != *']'* && "$listname" != *'['* ]]; then
  60. W+=($i "$listname")
  61. list_name+=("$listname")
  62. echo $listname
  63. fi
  64. done <<< "$USER_MAILING_LISTS"
  65. i=$((i+1))
  66. W+=($i $"Exit back to filtering rules menu")
  67. 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)
  68. if [ $? -eq 0 ]; then # Exit with OK
  69. if [ ${list_selected} -ne ${i} ]; then
  70. remove_list_name="${list_name[$((list_selected-1))]}"
  71. # find the line number where the list is defined
  72. line_number=0
  73. i=0
  74. while read -r line
  75. do
  76. if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
  77. line_number=${i}
  78. fi
  79. i=$((i+1))
  80. done < "/home/$USER/.procmailrc"
  81. if [ ${line_number} -eq 0 ]; then
  82. # no match was found
  83. return
  84. fi
  85. # recreate the file
  86. if [ -f /home/${USER}/.procmailrc_new ]; then
  87. rm /home/${USER}/.procmailrc_new
  88. fi
  89. i=0
  90. clip=0
  91. while read -r line
  92. do
  93. i=$((i+1))
  94. if [ ${i} -gt $((line_number-1)) ]; then
  95. if [ ${clip} -eq 0 ]; then
  96. clip=1
  97. fi
  98. if [ ${clip} -eq 1 ]; then
  99. if [ ${i} -lt $((line_number+2)) ]; then
  100. continue
  101. else
  102. if [ ${#line} -lt 1 ]; then
  103. clip=2
  104. continue
  105. fi
  106. if [[ "$line" == ":"* || "$line" == "#"* ]]; then
  107. clip=2
  108. else
  109. continue
  110. fi
  111. fi
  112. fi
  113. fi
  114. echo "$line" >> /home/${USER}/.procmailrc_new
  115. if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
  116. line_number=${i}
  117. fi
  118. done < "/home/$USER/.procmailrc"
  119. cp /home/${USER}/.procmailrc_new /home/${USER}/.procmailrc
  120. rm /home/${USER}/.procmailrc_new
  121. chown ${USER}:${USER} /home/${USER}/.procmailrc
  122. dialog --title $"Remove yourself from mailing list" \
  123. --msgbox $"You have been removed from ${remove_list_name}" 6 50
  124. fi
  125. fi
  126. }
  127. function add_to_mailing_list {
  128. data=$(tempfile 2>/dev/null)
  129. trap "rm -f $data" 0 1 2 5 15
  130. dialog --backtitle $"Freedombone User Control Panel" \
  131. --title $"Subscribe to a mailing list" \
  132. --form $"You can either enter a subject or an email address\n" 11 68 4 \
  133. $"List folder name:" 1 1 "" 1 35 26 25 \
  134. $"Name between [] on subject line:" 2 1 "" 2 35 26 25 \
  135. $"List email address:" 3 1 "" 3 35 26 25 \
  136. $"Public:" 4 1 $"yes" 4 35 4 25 \
  137. 2> $data
  138. sel=$?
  139. case $sel in
  140. 1) return;;
  141. 255) return;;
  142. esac
  143. LIST_NAME=$(cat $data | sed -n 1p)
  144. LIST_SUBJECT=$(cat $data | sed -n 2p)
  145. LIST_EMAIL=$(cat $data | sed -n 3p)
  146. LIST_PUBLIC=$(cat $data | sed -n 4p)
  147. if [ ${#LIST_PUBLIC} -lt 1 ]; then
  148. LIST_PUBLIC='no'
  149. fi
  150. if [[ $LIST_PUBLIC == $'y' || $LIST_PUBLIC == $'Y' || $LIST_PUBLIC == $'true' || $LIST_PUBLIC == $'True' || $LIST_PUBLIC == $'yes' || $LIST_PUBLIC == $'Yes' || $LIST_PUBLIC == $'YES' ]]; then
  151. LIST_PUBLIC='yes'
  152. else
  153. LIST_PUBLIC='no'
  154. fi
  155. if [ ${#LIST_NAME} -lt 2 ]; then
  156. dialog --title $"Add mailing list" \
  157. --msgbox $"No mailing list name was given" 6 40
  158. return
  159. fi
  160. if [ ${#LIST_SUBJECT} -lt 2 ]; then
  161. if [ ${#LIST_EMAIL} -lt 2 ]; then
  162. dialog --title $"Add mailing list" \
  163. --msgbox $"No mailing list subject or address was given" 6 40
  164. return
  165. fi
  166. fi
  167. if [ ${#LIST_SUBJECT} -gt 1 ]; then
  168. ${PROJECT_NAME}-addlist -u $USER -l "$LIST_NAME" \
  169. -s "$LIST_SUBJECT" --public $LIST_PUBLIC
  170. else
  171. if [[ "$LIST_EMAIL" != *"@"* || "$LIST_EMAIL" != *"."* ]]; then
  172. dialog --title $"Add mailing list" \
  173. --msgbox $"Unrecognised email address" 6 40
  174. return
  175. else
  176. ${PROJECT_NAME}-addlist -u $USER -l "$LIST_NAME" \
  177. -e "$LIST_EMAIL" --public $LIST_PUBLIC
  178. fi
  179. fi
  180. dialog --title $"Add mailing list" \
  181. --msgbox $"$LIST_NAME list was added" 6 40
  182. }
  183. function email_rule_address {
  184. data=$(tempfile 2>/dev/null)
  185. trap "rm -f $data" 0 1 2 5 15
  186. dialog --backtitle $"Freedombone User Control Panel" \
  187. --title $"Create an email rule" \
  188. --form "\n" 9 65 4 \
  189. $"When email arrives from address:" 1 1 "" 1 35 24 28 \
  190. $"Move to folder:" 2 1 "" 2 35 24 28 \
  191. $"Public:" 3 1 $"no" 3 35 4 25 \
  192. 2> $data
  193. sel=$?
  194. case $sel in
  195. 1) return;;
  196. 255) return;;
  197. esac
  198. RULE_EMAIL=$(cat $data | sed -n 1p)
  199. RULE_FOLDER=$(cat $data | sed -n 2p)
  200. RULE_PUBLIC=$(cat $data | sed -n 3p)
  201. if [ ${#RULE_PUBLIC} -lt 1 ]; then
  202. RULE_PUBLIC='no'
  203. fi
  204. if [[ $RULE_PUBLIC == $'y' || $RULE_PUBLIC == $'Y' || $RULE_PUBLIC == $'true' || $RULE_PUBLIC == $'True' || $RULE_PUBLIC == $'yes' || $RULE_PUBLIC == $'Yes' || $RULE_PUBLIC == $'YES' ]]; then
  205. RULE_PUBLIC='yes'
  206. else
  207. RULE_PUBLIC='no'
  208. fi
  209. if [ ${#RULE_EMAIL} -lt 2 ]; then
  210. dialog --title $"Create an email rule" \
  211. --msgbox $"No email address was given" 6 40
  212. return
  213. fi
  214. if [ ${#RULE_FOLDER} -lt 2 ]; then
  215. dialog --title $"Create an email rule" \
  216. --msgbox $"No folder name was given" 6 40
  217. return
  218. fi
  219. if [[ "$RULE_EMAIL" != *"@"* || "$RULE_EMAIL" != *"."* ]]; then
  220. dialog --title $"Create an email rule" \
  221. --msgbox $"Unrecognised email address" 6 40
  222. return
  223. fi
  224. ${PROJECT_NAME}-addemail -u $USER -e "$RULE_EMAIL" \
  225. -g "$RULE_FOLDER" --public $RULE_PUBLIC
  226. dialog --title $"Create an email rule" \
  227. --msgbox $"Email rule for $RULE_EMAIL was added" 6 40
  228. }
  229. function gpg_set_trust {
  230. TRUST_ADDRESS=$1
  231. fpr=$(gpg --with-colons --fingerprint "$TRUST_ADDRESS" | grep fpr | head -n 1 | awk -F ':' '{print $10}')
  232. if [ ${#fpr} -gt 2 ]; then
  233. data=$(tempfile 2>/dev/null)
  234. trap "rm -f $data" 0 1 2 5 15
  235. dialog --backtitle $"Freedombone User Control Panel" \
  236. --title $"Trust a PGP/GPG key or website domain" \
  237. --radiolist $"Set the trust level for $TRUST_ADDRESS:" 18 70 10 \
  238. 1 $"I don't know or won't say" off \
  239. 2 $"I do NOT trust" off \
  240. 3 $"I trust marginally" on \
  241. 4 $"I trust fully" off \
  242. 5 $"I trust ultimately" off 2> $data
  243. sel=$?
  244. case $sel in
  245. 1) return;;
  246. 255) return;;
  247. esac
  248. TRUST_LEVEL=$(cat $data)
  249. if [ ${TRUST_LEVEL} -ge 1 ] ; then
  250. if [ ${TRUST_LEVEL} -le 5 ] ; then
  251. echo -e "trust\n${TRUST_LEVEL}\ny\nsave\n" | gpg --command-fd 0 --edit-key $fpr
  252. if [ "$?" = "0" ]; then
  253. gpg --update-trustdb
  254. dialog --title $"Trust a PGP/GPG key or website domain" \
  255. --backtitle $"Freedombone User Control Panel" \
  256. --msgbox $"$TRUST_ADDRESS was set to trust level ${TRUST_LEVEL}" 6 50
  257. fi
  258. fi
  259. fi
  260. fi
  261. }
  262. function email_rule_subject {
  263. data=$(tempfile 2>/dev/null)
  264. trap "rm -f $data" 0 1 2 5 15
  265. dialog --backtitle $"Freedombone User Control Panel" \
  266. --title $"Create an email rule" \
  267. --form "\n" 9 75 4 \
  268. $"When email arrives with subject containing:" 1 1 "" 1 45 24 28 \
  269. $"Move to folder:" 2 1 "" 2 45 24 28 \
  270. $"Public:" 3 1 $"no" 3 45 4 25 \
  271. 2> $data
  272. sel=$?
  273. case $sel in
  274. 1) return;;
  275. 255) return;;
  276. esac
  277. RULE_SUBJECT=$(cat $data | sed -n 1p)
  278. RULE_FOLDER=$(cat $data | sed -n 2p)
  279. RULE_PUBLIC=$(cat $data | sed -n 3p)
  280. if [ ${#RULE_PUBLIC} -lt 1 ]; then
  281. RULE_PUBLIC='no'
  282. fi
  283. if [[ $RULE_PUBLIC == $'y' || $RULE_PUBLIC == $'Y' || $RULE_PUBLIC == $'true' || $RULE_PUBLIC == $'True' || $RULE_PUBLIC == $'yes' || $RULE_PUBLIC == $'Yes' || $RULE_PUBLIC == $'YES' ]]; then
  284. RULE_PUBLIC='yes'
  285. else
  286. RULE_PUBLIC='no'
  287. fi
  288. if [ ${#RULE_SUBJECT} -lt 2 ]; then
  289. dialog --title $"Create an email rule" \
  290. --msgbox $"No subject text was given" 6 40
  291. return
  292. fi
  293. if [ ${#RULE_FOLDER} -lt 2 ]; then
  294. dialog --title $"Create an email rule" \
  295. --msgbox $"No folder name was given" 6 40
  296. return
  297. fi
  298. ${PROJECT_NAME}-addemail -u $USER -s "$RULE_SUBJECT" \
  299. -g "$RULE_FOLDER" --public $RULE_PUBLIC
  300. dialog --title $"Create an email rule" \
  301. --msgbox $"Email rule for subject '$RULE_SUBJECT' was added" 6 40
  302. }
  303. function block_unblock_email {
  304. blockstr=$"Block or unblock emails from a given address"
  305. data=$(tempfile 2>/dev/null)
  306. trap "rm -f $data" 0 1 2 5 15
  307. dialog --backtitle $"Freedombone User Control Panel" \
  308. --title "$blockstr" \
  309. --form "\n" 8 65 3 \
  310. $"When email arrives from address:" 1 1 "" 1 35 24 100 \
  311. $"Block it:" 2 1 "yes" 2 35 4 4 \
  312. 2> $data
  313. sel=$?
  314. case $sel in
  315. 1) return;;
  316. 255) return;;
  317. esac
  318. BLOCK_EMAIL=$(cat $data | sed -n 1p)
  319. BLOCK=$(cat $data | sed -n 2p)
  320. if [ ${#BLOCK_EMAIL} -lt 2 ]; then
  321. dialog --title "$blockstr" \
  322. --msgbox $"No email address was given" 6 40
  323. return
  324. fi
  325. if [[ "$BLOCK_EMAIL" != *"@"* || "$BLOCK_EMAIL" != *"."* ]]; then
  326. dialog --title "$blockstr" \
  327. --msgbox $"Unrecognised email address" 6 40
  328. return
  329. fi
  330. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  331. ${PROJECT_NAME}-ignore -u $USER -e "$BLOCK_EMAIL"
  332. dialog --title $"Block an email" \
  333. --msgbox "Email from $BLOCK_EMAIL is now blocked" 6 75
  334. else
  335. ${PROJECT_NAME}-unignore -u $USER -e "$BLOCK_EMAIL"
  336. dialog --title $"Unblock an email" \
  337. --msgbox "Email from $BLOCK_EMAIL is now unblocked" 6 75
  338. fi
  339. }
  340. function block_unblock_subject {
  341. blockstr=$"Block or unblock emails with text in the subject line"
  342. data=$(tempfile 2>/dev/null)
  343. trap "rm -f $data" 0 1 2 5 15
  344. dialog --backtitle $"Freedombone User Control Panel" \
  345. --title "$blockstr" \
  346. --form "\n" 8 70 3 \
  347. $"When email arrives with subject text:" 1 1 "" 1 40 24 28 \
  348. $"Block it:" 2 1 "yes" 2 40 4 4 \
  349. 2> $data
  350. sel=$?
  351. case $sel in
  352. 1) return;;
  353. 255) return;;
  354. esac
  355. BLOCK_SUBJECT=$(cat $data | sed -n 1p)
  356. BLOCK=$(cat $data | sed -n 2p)
  357. if [ ${#BLOCK_SUBJECT} -lt 2 ]; then
  358. dialog --title "$blockstr" \
  359. --msgbox $"No subject was given" 6 40
  360. return
  361. fi
  362. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  363. ${PROJECT_NAME}-ignore -u $USER -t "$BLOCK_SUBJECT"
  364. dialog --title $"Block an email" \
  365. --msgbox $"Email with subject $BLOCK_SUBJECT is now blocked" 6 40
  366. else
  367. ${PROJECT_NAME}-unignore -u $USER -t "$BLOCK_SUBJECT"
  368. dialog --title $"Unblock an email" \
  369. --msgbox $"Email with subject $BLOCK_SUBJECT is now unblocked" 6 40
  370. fi
  371. }
  372. function show_gpg_key {
  373. GPG_FINGERPRINT=$(gpg --fingerprint $MY_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//')
  374. GPG_DATE=$(gpg --fingerprint $MY_EMAIL_ADDRESS | grep -i "pub" | head -n 1 | awk -F ' ' '{print $3}')
  375. dialog --title $"My PGP/GPG Key" \
  376. --backtitle $"Freedombone User Control Panel" \
  377. --msgbox $"Email Address: $MY_EMAIL_ADDRESS\n\nKey ID: $GPG_ID\n\nFingerprint: $GPG_FINGERPRINT\n\nCreated: $GPG_DATE" 12 70
  378. }
  379. function show_full_gpg_key {
  380. clear
  381. echo ''
  382. echo ''
  383. echo ''
  384. gpg --armor --export $GPG_ID
  385. gpg --armor --export-secret-key $GPG_ID
  386. any_key
  387. }
  388. function publish_gpg_key {
  389. gpg --send-key $GPG_ID
  390. if [ $GPG_BACKUP_ID ]; then
  391. gpg --send-key $GPG_BACKUP_ID
  392. fi
  393. dialog --title $"Publish your PGP/GPG key" \
  394. --msgbox $"Your key has now been published" 6 40
  395. }
  396. function refresh_gpg_keys {
  397. gpg --refresh-keys
  398. dialog --title $"Refresh PGP/GPG keys" \
  399. --msgbox $"Your keys have been refreshed" 6 40
  400. }
  401. function add_gpg_key {
  402. data=$(tempfile 2>/dev/null)
  403. trap "rm -f $data" 0 1 2 5 15
  404. dialog --title $"Enter email address, Key ID or full key below" \
  405. --backtitle $"Freedombone User Control Panel" \
  406. --editbox $data 8 60 2>$data
  407. sel=$?
  408. case $sel in
  409. 0)
  410. ADD_EMAIL_ADDRESS=$(<$data)
  411. if [ ${#ADD_EMAIL_ADDRESS} -gt 2 ]; then
  412. address_is_valid=
  413. if [[ "$ADD_EMAIL_ADDRESS" == *"@"* && "$ADD_EMAIL_ADDRESS" == *"."* ]]; then
  414. address_is_valid=1
  415. fi
  416. if [[ "$ADD_EMAIL_ADDRESS" == "0x"* ]]; then
  417. address_is_valid=1
  418. fi
  419. publicstr=$"BEGIN PGP PUBLIC KEY BLOCK"
  420. if [[ "$ADD_EMAIL_ADDRESS" == *"$publicstr"* ]]; then
  421. address_is_valid=1
  422. fi
  423. if [ $address_is_valid ]; then
  424. clear
  425. if [[ "$ADD_EMAIL_ADDRESS" == *"$publicstr"* ]]; then
  426. echo "$ADD_EMAIL_ADDRESS" | gpg --import
  427. dialog --title $"Add someone's PGP/GPG key" \
  428. --backtitle $"Freedombone User Control Panel" \
  429. --msgbox $"GPG public key was imported" 6 50
  430. else
  431. gpg --search-keys "$ADD_EMAIL_ADDRESS"
  432. gpg_set_trust "$ADD_EMAIL_ADDRESS"
  433. fi
  434. else
  435. dialog --title $"Unrecognised email address" \
  436. --backtitle $"Freedombone User Control Panel" \
  437. --msgbox $"This doesn't look like an email address or key ID" 6 50
  438. fi
  439. fi
  440. ;;
  441. esac
  442. rm $data
  443. }
  444. function remove_gpg_key {
  445. data=$(tempfile 2>/dev/null)
  446. trap "rm -f $data" 0 1 2 5 15
  447. dialog --title $"Remove someone's PGP/GPG key" \
  448. --backtitle $"Freedombone User Control Panel" \
  449. --inputbox $"Enter their email address or key ID below" 8 60 2>$data
  450. sel=$?
  451. case $sel in
  452. 0)
  453. REMOVE_EMAIL_ADDRESS=$(<$data)
  454. if [ ${#REMOVE_EMAIL_ADDRESS} -gt 2 ]; then
  455. if [[ $REMOVE_EMAIL_ADDRESS == *"@"* && $REMOVE_EMAIL_ADDRESS == *"."* ]]; then
  456. if [[ $REMOVE_EMAIL_ADDRESS != $MY_EMAIL_ADDRESS ]]; then
  457. clear
  458. gpg --delete-key $REMOVE_EMAIL_ADDRESS
  459. else
  460. dialog --title $"Remove someone's PGP/GPG key" \
  461. --backtitle $"Freedombone User Control Panel" \
  462. --msgbox $"It's not a good idea to remove your own encryption key" 6 65
  463. fi
  464. else
  465. if [[ $REMOVE_EMAIL_ADDRESS == "0x"* ]]; then
  466. clear
  467. gpg --delete-key $REMOVE_EMAIL_ADDRESS
  468. else
  469. dialog --title $"Unrecognised email address" \
  470. --backtitle $"Freedombone User Control Panel" \
  471. --msgbox $"This doesn't look like an email address" 6 50
  472. fi
  473. fi
  474. fi
  475. ;;
  476. esac
  477. }
  478. function add_ssh_key {
  479. data=$(tempfile 2>/dev/null)
  480. trap "rm -f $data" 0 1 2 5 15
  481. dialog --title $"Add an ssh key for logging in" \
  482. --backtitle $"Freedombone User Control Panel" \
  483. --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
  484. sel=$?
  485. case $sel in
  486. 0)
  487. SSH_PUBLIC_KEY=$(<$data)
  488. if [ ${#SSH_PUBLIC_KEY} -gt 20 ]; then
  489. if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
  490. if [ ! -d /home/$USER/.ssh ]; then
  491. mkdir /home/$USER/.ssh
  492. fi
  493. if [ ! -f /home/$USER/.ssh/authorized_keys ]; then
  494. touch /home/$USER/.ssh/authorized_keys
  495. fi
  496. if ! grep -q "$SSH_PUBLIC_KEY" /home/$USER/.ssh/authorized_keys; then
  497. echo "$SSH_PUBLIC_KEY" >> /home/$USER/.ssh/authorized_keys
  498. dialog --title $"New ssh key added" \
  499. --backtitle $"Freedombone User Control Panel" \
  500. --msgbox $"Your ssh key has now been added" 6 50
  501. else
  502. dialog --title $"ssh key already added" \
  503. --backtitle $"Freedombone User Control Panel" \
  504. --msgbox $"That ssh key has already been added" 6 50
  505. fi
  506. else
  507. dialog --title $"Unrecognised ssh public key" \
  508. --backtitle $"Freedombone User Control Panel" \
  509. --msgbox $"This doesn't look like an ssh key" 6 50
  510. fi
  511. fi
  512. ;;
  513. esac
  514. }
  515. function remove_ssh_key {
  516. data=$(tempfile 2>/dev/null)
  517. trap "rm -f $data" 0 1 2 5 15
  518. dialog --title $"Remove an ssh key for logging in" \
  519. --backtitle $"Freedombone User Control Panel" \
  520. --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
  521. sel=$?
  522. case $sel in
  523. 0)
  524. SSH_PUBLIC_KEY=$(<$data)
  525. if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
  526. if [ -f /home/$USER/.ssh/authorized_keys ]; then
  527. sed -i "s|.*${SSH_PUBLIC_KEY}.*||g" /home/$USER/.ssh/authorized_keys
  528. dialog --title $"Remove an ssh public key" \
  529. --backtitle $"Freedombone User Control Panel" \
  530. --msgbox $"The ssh key has been removed" 6 50
  531. fi
  532. fi
  533. ;;
  534. esac
  535. }
  536. function smtp_proxy {
  537. MUTTRC_FILE=/home/$USER/.muttrc
  538. if [ ! -f $MUTTRC_FILE ]; then
  539. return
  540. fi
  541. SMTP_PROXY_ENABLE=$'no'
  542. SMTP_PROXY_PROTOCOL='smtps'
  543. SMTP_PROXY_SERVER='mail.myispdomain'
  544. SMTP_PROXY_PORT=465
  545. SMTP_PROXY_USERNAME=''
  546. SMTP_PROXY_PASSWORD=''
  547. if grep -q "set smtp_url" $MUTTRC_FILE; then
  548. if grep -q "#set smtp_url" $MUTTRC_FILE; then
  549. SMTP_PROXY_ENABLE=$'no'
  550. else
  551. SMTP_PROXY_ENABLE=$'yes'
  552. fi
  553. SMTP_PROXY_PROTOCOL=$(cat $MUTTRC_FILE | grep "set smtp_url" | awk -F '"' '{print $2}' | awk -F ':' '{print $1}')
  554. SMTP_PROXY_SERVER=$(cat $MUTTRC_FILE | grep "set smtp_url" | awk -F '"' '{print $2}' | awk -F '/' '{print $3}' | awk -F ':' '{print $2}' | awk -F '@' '{print $2}')
  555. SMTP_PROXY_PORT=$(cat $MUTTRC_FILE | grep "set smtp_url" | awk -F ':' '{print $4}' | awk -F '/' '{print $1}')
  556. SMTP_PROXY_USERNAME=$(cat $MUTTRC_FILE | grep "set smtp_url" | awk -F '"' '{print $2}' | awk -F '/' '{print $3}' | awk -F ':' '{print $1}')
  557. SMTP_PROXY_PASSWORD=$(cat $MUTTRC_FILE | grep "set smtp_url" | awk -F '"' '{print $2}' | awk -F '/' '{print $3}' | awk -F ':' '{print $2}' | awk -F '@' '{print $1}')
  558. fi
  559. data=$(tempfile 2>/dev/null)
  560. trap "rm -f $data" 0 1 2 5 15
  561. dialog --backtitle $"Freedombone Control Panel" \
  562. --title $"SMTP Proxy for $USER" \
  563. --form $"You may need to proxy outgoing email via your ISP's mail server. If so enter the details below." 14 75 6 \
  564. $"Enable proxy:" 1 1 "$SMTP_PROXY_ENABLE" 1 24 5 5 \
  565. $"Protocol (smtp/smtps):" 2 1 "$SMTP_PROXY_PROTOCOL" 2 24 5 5 \
  566. $"ISP mail server:" 3 1 "$SMTP_PROXY_SERVER" 3 24 40 10000 \
  567. $"Port:" 4 1 "$SMTP_PROXY_PORT" 4 24 5 5 \
  568. $"Username:" 5 1 "$SMTP_PROXY_USERNAME" 5 24 40 10000 \
  569. $"Password:" 6 1 "$SMTP_PROXY_PASSWORD" 6 24 40 10000 \
  570. 2> $data
  571. sel=$?
  572. case $sel in
  573. 1) return;;
  574. 255) return;;
  575. esac
  576. SMTP_PROXY_ENABLE=$(cat $data | sed -n 1p)
  577. SMTP_PROXY_PROTOCOL=$(cat $data | sed -n 2p)
  578. SMTP_PROXY_SERVER=$(cat $data | sed -n 3p)
  579. SMTP_PROXY_PORT=$(cat $data | sed -n 4p)
  580. SMTP_PROXY_USERNAME=$(cat $data | sed -n 5p)
  581. SMTP_PROXY_PASSWORD=$(cat $data | sed -n 6p)
  582. # change muttrc
  583. if [ $SMTP_PROXY_ENABLE != $'no' ]; then
  584. if ! grep -q "set smtp_url" $MUTTRC_FILE; then
  585. echo "set smtp_url=\"${SMTP_PROXY_PROTOCOL}://${SMTP_PROXY_USERNAME}:${SMTP_PROXY_PASSWORD}@${SMTP_PROXY_SERVER}:${SMTP_PROXY_PORT}/\"" >> $MUTTRC_FILE
  586. else
  587. sed -i "s|set smtp_url=.*|set smtp_url=\"${SMTP_PROXY_PROTOCOL}://${SMTP_PROXY_USERNAME}:${SMTP_PROXY_PASSWORD}@${SMTP_PROXY_SERVER}:${SMTP_PROXY_PORT}/\"|g" $MUTTRC_FILE
  588. fi
  589. sed -i 's|#set smtp_url|set smtp_url|g' $MUTTRC_FILE
  590. else
  591. if grep -q "set smtp_url" $MUTTRC_FILE; then
  592. sed -i 's|set smtp_url|#set smtp_url|g' $MUTTRC_FILE
  593. fi
  594. fi
  595. }
  596. function sign_gpg_key {
  597. data=$(tempfile 2>/dev/null)
  598. trap "rm -f $data" 0 1 2 5 15
  599. dialog --title $"Sign a PGP/GPG key or website domain" \
  600. --backtitle $"Freedombone User Control Panel" \
  601. --inputbox $"Enter the Key ID, address or domain to be signed.\n\nIf you are signing a website domain then include the https:// at the beginning.\n\nIf you are signing an ssh key then include ssh:// before the domain name." 14 75 2>$data
  602. sel=$?
  603. case $sel in
  604. 0)
  605. SIGN_ADDRESS=$(<$data)
  606. if [ ${#SIGN_ADDRESS} -gt 2 ]; then
  607. clear
  608. gpg --search "$SIGN_ADDRESS"
  609. fpr=$(gpg --with-colons --fingerprint "$SIGN_ADDRESS" | grep fpr | head -n 1 | awk -F ':' '{print $10}')
  610. if [ ${#fpr} -gt 2 ]; then
  611. gpg --sign-key $fpr
  612. if [ "$?" = "0" ]; then
  613. gpg --update-trustdb
  614. dialog --title $"Sign a PGP/GPG key" \
  615. --backtitle $"Freedombone User Control Panel" \
  616. --msgbox $"$SIGN_ADDRESS was signed" 6 50
  617. fi
  618. fi
  619. fi
  620. ;;
  621. esac
  622. }
  623. function gpg_key_trust {
  624. data=$(tempfile 2>/dev/null)
  625. trap "rm -f $data" 0 1 2 5 15
  626. dialog --title $"Trust a PGP/GPG key or website domain" \
  627. --backtitle $"Freedombone User Control Panel" \
  628. --inputbox $"Enter the Key ID, address or domain to be trusted.\n\nIf you are trusting a website domain then include the https:// at the beginning.\n\nIf you are trusting an ssh key then include ssh:// before the domain name." 14 75 2>$data
  629. sel=$?
  630. case $sel in
  631. 0)
  632. TRUST_ADDRESS=$(<$data)
  633. if [ ${#TRUST_ADDRESS} -gt 2 ]; then
  634. clear
  635. gpg --search "$TRUST_ADDRESS"
  636. gpg_set_trust "$TRUST_ADDRESS"
  637. fi
  638. ;;
  639. esac
  640. }
  641. function menu_encryption_keys {
  642. while true
  643. do
  644. data=$(tempfile 2>/dev/null)
  645. trap "rm -f $data" 0 1 2 5 15
  646. dialog --backtitle $"Freedombone User Control Panel" \
  647. --title $"My Encryption Keys" \
  648. --radiolist $"Choose an operation:" 19 70 11 \
  649. 1 $"Show your PGP/GPG key" off \
  650. 2 $"Show your full PGP/GPG key, including private key" off \
  651. 3 $"Publish your PGP/GPG key so that others can find it" off \
  652. 4 $"Add someone's PGP/GPG key" off \
  653. 5 $"Remove someone's PGP/GPG key" off \
  654. 6 $"Sign a PGP/GPG key or website domain" off \
  655. 7 $"Refresh your PGP/GPG keys" off \
  656. 8 $"Add an ssh key for logging in" off \
  657. 9 $"Remove an ssh key for logging in" off \
  658. 10 $"Set the trust level for a PGP/GPG key" off \
  659. 11 $"Back to main menu" on 2> $data
  660. sel=$?
  661. case $sel in
  662. 1) break;;
  663. 255) break;;
  664. esac
  665. case $(cat $data) in
  666. 1) show_gpg_key;;
  667. 2) show_full_gpg_key;;
  668. 3) publish_gpg_key;;
  669. 4) add_gpg_key;;
  670. 5) remove_gpg_key;;
  671. 6) sign_gpg_key;;
  672. 7) refresh_gpg_keys;;
  673. 8) add_ssh_key;;
  674. 9) remove_ssh_key;;
  675. 10) gpg_key_trust;;
  676. 11) break;;
  677. esac
  678. done
  679. }
  680. function menu_email {
  681. while true
  682. do
  683. data=$(tempfile 2>/dev/null)
  684. trap "rm -f $data" 0 1 2 5 15
  685. dialog --backtitle $"Freedombone User Control Panel" \
  686. --title $"Change Email Filtering Rules" \
  687. --radiolist $"Choose an operation:" 14 70 7 \
  688. 1 $"Add yourself to a mailing list" off \
  689. 2 $"Remove yourself from a mailing list" off \
  690. 3 $"Add an email rule for an address" off \
  691. 4 $"Add an email rule for a subject" off \
  692. 5 $"Block or unblock an email address" off \
  693. 6 $"Block or unblock email with subject text" off \
  694. 7 $"Back to main menu" on 2> $data
  695. sel=$?
  696. case $sel in
  697. 1) break;;
  698. 255) break;;
  699. esac
  700. case $(cat $data) in
  701. 1) add_to_mailing_list;;
  702. 2) remove_user_from_mailing_list;;
  703. 3) email_rule_address;;
  704. 4) email_rule_subject;;
  705. 5) block_unblock_email;;
  706. 6) block_unblock_subject;;
  707. 7) break;;
  708. esac
  709. done
  710. }
  711. function menu_admin {
  712. if [ ! -f /etc/sudoers ]; then
  713. clear
  714. exit 0
  715. fi
  716. sudo /usr/local/bin/control
  717. }
  718. function sign_keys {
  719. if [ ! -f /home/$USER/.monkeysphere/server_keys ]; then
  720. return
  721. fi
  722. dialog --title $"Monkeysphere sign server keys" \
  723. --backtitle $"Freedombone Security Configuration" \
  724. --defaultno \
  725. --yesno $"\nMonkeysphere has been enabled and you will need to sign and trust the server keys. Do you want to do that now?" 8 60
  726. sel=$?
  727. case $sel in
  728. 0) ${PROJECT_NAME}-sec --sign yes;;
  729. esac
  730. }
  731. function menu_run_client_app {
  732. detect_installable_apps
  733. applist=""
  734. appnames=()
  735. n=1
  736. app_index=0
  737. for a in "${APPS_AVAILABLE[@]}"
  738. do
  739. if [[ ${APPS_INSTALLED[$app_index]} != "0" ]]; then
  740. if [[ $(function_exists run_client_${a}) == "1" ]]; then
  741. applist="$applist $n $a off"
  742. n=$[n+1]
  743. appnames+=("$a")
  744. fi
  745. fi
  746. app_index=$[app_index+1]
  747. done
  748. if [ $n -le 1 ]; then
  749. return
  750. fi
  751. backstr=$'Exit'
  752. applist="$applist $n $backstr on"
  753. appnames+=("Exit")
  754. choice=$(dialog --stdout --backtitle $"Freedombone" \
  755. --title $"Run an App" \
  756. --radiolist $'Choose:' \
  757. 16 40 20 $applist)
  758. if [ $? -eq 0 ]; then
  759. app_index=$[choice-1]
  760. chosen_app=${appnames[$app_index]}
  761. if [[ $chosen_app != "Exit" ]]; then
  762. run_client_${chosen_app}
  763. fi
  764. fi
  765. }
  766. function menu_top_level {
  767. while true
  768. do
  769. data=$(tempfile 2>/dev/null)
  770. trap "rm -f $data" 0 1 2 5 15
  771. dialog --backtitle $"Freedombone User Control Panel" \
  772. --title $"User Control Panel" \
  773. --radiolist $"Choose an operation:" 19 50 12 \
  774. 1 $"Use Email" off \
  775. 2 $"Change Email Filtering Rules" off \
  776. 3 $"Run an App" off \
  777. 4 $"Browse the Web" off \
  778. 5 $"My Encryption Keys" off \
  779. 6 $"Set an outgoing email proxy" off \
  780. 7 $"Administrator controls" off \
  781. 8 $"Exit to the command line" off \
  782. 9 $"Log out" on 2> $data
  783. sel=$?
  784. case $sel in
  785. 1) exit 1;;
  786. 255) exit 1;;
  787. esac
  788. case $(cat $data) in
  789. 1) mutt;;
  790. 2) menu_email;;
  791. 3) menu_run_client_app;;
  792. 4) torify elinks -no-home;;
  793. 5) menu_encryption_keys;;
  794. 6) smtp_proxy;;
  795. 7) menu_admin;;
  796. 8) break;;
  797. 9) kill -HUP `pgrep -s 0 -o`;;
  798. esac
  799. done
  800. }
  801. sign_keys
  802. menu_top_level
  803. clear
  804. . ~/.bashrc
  805. exit 0