freedombone-controlpanel-user 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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 $"Add someone's PGP/GPG key" \
  405. --backtitle $"Freedombone User Control Panel" \
  406. --inputbox $"Enter their email address or Key ID below" 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. else
  416. if [[ $ADD_EMAIL_ADDRESS == "0x"* ]]; then
  417. address_is_valid=1
  418. fi
  419. fi
  420. if [ $address_is_valid ]; then
  421. clear
  422. gpg --search-keys "$ADD_EMAIL_ADDRESS"
  423. gpg_set_trust "$ADD_EMAIL_ADDRESS"
  424. else
  425. dialog --title $"Unrecognised email address" \
  426. --backtitle $"Freedombone User Control Panel" \
  427. --msgbox $"This doesn't look like an email address or key ID" 6 50
  428. fi
  429. fi
  430. ;;
  431. esac
  432. }
  433. function remove_gpg_key {
  434. data=$(tempfile 2>/dev/null)
  435. trap "rm -f $data" 0 1 2 5 15
  436. dialog --title $"Remove someone's PGP/GPG key" \
  437. --backtitle $"Freedombone User Control Panel" \
  438. --inputbox $"Enter their email address or key ID below" 8 60 2>$data
  439. sel=$?
  440. case $sel in
  441. 0)
  442. REMOVE_EMAIL_ADDRESS=$(<$data)
  443. if [ ${#REMOVE_EMAIL_ADDRESS} -gt 2 ]; then
  444. if [[ $REMOVE_EMAIL_ADDRESS == *"@"* && $REMOVE_EMAIL_ADDRESS == *"."* ]]; then
  445. if [[ $REMOVE_EMAIL_ADDRESS != $MY_EMAIL_ADDRESS ]]; then
  446. clear
  447. gpg --delete-key $REMOVE_EMAIL_ADDRESS
  448. else
  449. dialog --title $"Remove someone's PGP/GPG key" \
  450. --backtitle $"Freedombone User Control Panel" \
  451. --msgbox $"It's not a good idea to remove your own encryption key" 6 65
  452. fi
  453. else
  454. if [[ $REMOVE_EMAIL_ADDRESS == "0x"* ]]; then
  455. clear
  456. gpg --delete-key $REMOVE_EMAIL_ADDRESS
  457. else
  458. dialog --title $"Unrecognised email address" \
  459. --backtitle $"Freedombone User Control Panel" \
  460. --msgbox $"This doesn't look like an email address" 6 50
  461. fi
  462. fi
  463. fi
  464. ;;
  465. esac
  466. }
  467. function add_ssh_key {
  468. data=$(tempfile 2>/dev/null)
  469. trap "rm -f $data" 0 1 2 5 15
  470. dialog --title $"Add an ssh key for logging in" \
  471. --backtitle $"Freedombone User Control Panel" \
  472. --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
  473. sel=$?
  474. case $sel in
  475. 0)
  476. SSH_PUBLIC_KEY=$(<$data)
  477. if [ ${#SSH_PUBLIC_KEY} -gt 20 ]; then
  478. if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
  479. if [ ! -d /home/$USER/.ssh ]; then
  480. mkdir /home/$USER/.ssh
  481. fi
  482. if [ ! -f /home/$USER/.ssh/authorized_keys ]; then
  483. touch /home/$USER/.ssh/authorized_keys
  484. fi
  485. if ! grep -q "$SSH_PUBLIC_KEY" /home/$USER/.ssh/authorized_keys; then
  486. echo "$SSH_PUBLIC_KEY" >> /home/$USER/.ssh/authorized_keys
  487. dialog --title $"New ssh key added" \
  488. --backtitle $"Freedombone User Control Panel" \
  489. --msgbox $"Your ssh key has now been added" 6 50
  490. else
  491. dialog --title $"ssh key already added" \
  492. --backtitle $"Freedombone User Control Panel" \
  493. --msgbox $"That ssh key has already been added" 6 50
  494. fi
  495. else
  496. dialog --title $"Unrecognised ssh public key" \
  497. --backtitle $"Freedombone User Control Panel" \
  498. --msgbox $"This doesn't look like an ssh key" 6 50
  499. fi
  500. fi
  501. ;;
  502. esac
  503. }
  504. function remove_ssh_key {
  505. data=$(tempfile 2>/dev/null)
  506. trap "rm -f $data" 0 1 2 5 15
  507. dialog --title $"Remove an ssh key for logging in" \
  508. --backtitle $"Freedombone User Control Panel" \
  509. --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
  510. sel=$?
  511. case $sel in
  512. 0)
  513. SSH_PUBLIC_KEY=$(<$data)
  514. if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
  515. if [ -f /home/$USER/.ssh/authorized_keys ]; then
  516. sed -i "s|.*${SSH_PUBLIC_KEY}.*||g" /home/$USER/.ssh/authorized_keys
  517. dialog --title $"Remove an ssh public key" \
  518. --backtitle $"Freedombone User Control Panel" \
  519. --msgbox $"The ssh key has been removed" 6 50
  520. fi
  521. fi
  522. ;;
  523. esac
  524. }
  525. function smtp_proxy {
  526. MUTTRC_FILE=/home/$USER/.muttrc
  527. if [ ! -f $MUTTRC_FILE ]; then
  528. return
  529. fi
  530. SMTP_PROXY_ENABLE=$'no'
  531. SMTP_PROXY_PROTOCOL='smtps'
  532. SMTP_PROXY_SERVER='mail.myispdomain'
  533. SMTP_PROXY_PORT=465
  534. SMTP_PROXY_USERNAME=''
  535. SMTP_PROXY_PASSWORD=''
  536. if grep -q "set smtp_url" $MUTTRC_FILE; then
  537. if grep -q "#set smtp_url" $MUTTRC_FILE; then
  538. SMTP_PROXY_ENABLE=$'no'
  539. else
  540. SMTP_PROXY_ENABLE=$'yes'
  541. fi
  542. SMTP_PROXY_PROTOCOL=$(cat $MUTTRC_FILE | grep "set smtp_url" | awk -F '"' '{print $2}' | awk -F ':' '{print $1}')
  543. 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}')
  544. SMTP_PROXY_PORT=$(cat $MUTTRC_FILE | grep "set smtp_url" | awk -F ':' '{print $4}' | awk -F '/' '{print $1}')
  545. SMTP_PROXY_USERNAME=$(cat $MUTTRC_FILE | grep "set smtp_url" | awk -F '"' '{print $2}' | awk -F '/' '{print $3}' | awk -F ':' '{print $1}')
  546. 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}')
  547. fi
  548. data=$(tempfile 2>/dev/null)
  549. trap "rm -f $data" 0 1 2 5 15
  550. dialog --backtitle $"Freedombone Control Panel" \
  551. --title $"SMTP Proxy for $USER" \
  552. --form $"You may need to proxy outgoing email via your ISP's mail server. If so enter the details below." 14 75 6 \
  553. $"Enable proxy:" 1 1 "$SMTP_PROXY_ENABLE" 1 24 5 5 \
  554. $"Protocol (smtp/smtps):" 2 1 "$SMTP_PROXY_PROTOCOL" 2 24 5 5 \
  555. $"ISP mail server:" 3 1 "$SMTP_PROXY_SERVER" 3 24 40 10000 \
  556. $"Port:" 4 1 "$SMTP_PROXY_PORT" 4 24 5 5 \
  557. $"Username:" 5 1 "$SMTP_PROXY_USERNAME" 5 24 40 10000 \
  558. $"Password:" 6 1 "$SMTP_PROXY_PASSWORD" 6 24 40 10000 \
  559. 2> $data
  560. sel=$?
  561. case $sel in
  562. 1) return;;
  563. 255) return;;
  564. esac
  565. SMTP_PROXY_ENABLE=$(cat $data | sed -n 1p)
  566. SMTP_PROXY_PROTOCOL=$(cat $data | sed -n 2p)
  567. SMTP_PROXY_SERVER=$(cat $data | sed -n 3p)
  568. SMTP_PROXY_PORT=$(cat $data | sed -n 4p)
  569. SMTP_PROXY_USERNAME=$(cat $data | sed -n 5p)
  570. SMTP_PROXY_PASSWORD=$(cat $data | sed -n 6p)
  571. # change muttrc
  572. if [ $SMTP_PROXY_ENABLE != $'no' ]; then
  573. if ! grep -q "set smtp_url" $MUTTRC_FILE; then
  574. echo "set smtp_url=\"${SMTP_PROXY_PROTOCOL}://${SMTP_PROXY_USERNAME}:${SMTP_PROXY_PASSWORD}@${SMTP_PROXY_SERVER}:${SMTP_PROXY_PORT}/\"" >> $MUTTRC_FILE
  575. else
  576. 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
  577. fi
  578. sed -i 's|#set smtp_url|set smtp_url|g' $MUTTRC_FILE
  579. else
  580. if grep -q "set smtp_url" $MUTTRC_FILE; then
  581. sed -i 's|set smtp_url|#set smtp_url|g' $MUTTRC_FILE
  582. fi
  583. fi
  584. }
  585. function sign_gpg_key {
  586. data=$(tempfile 2>/dev/null)
  587. trap "rm -f $data" 0 1 2 5 15
  588. dialog --title $"Sign a PGP/GPG key or website domain" \
  589. --backtitle $"Freedombone User Control Panel" \
  590. --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
  591. sel=$?
  592. case $sel in
  593. 0)
  594. SIGN_ADDRESS=$(<$data)
  595. if [ ${#SIGN_ADDRESS} -gt 2 ]; then
  596. clear
  597. gpg --search "$SIGN_ADDRESS"
  598. fpr=$(gpg --with-colons --fingerprint "$SIGN_ADDRESS" | grep fpr | head -n 1 | awk -F ':' '{print $10}')
  599. if [ ${#fpr} -gt 2 ]; then
  600. gpg --sign-key $fpr
  601. if [ "$?" = "0" ]; then
  602. gpg --update-trustdb
  603. dialog --title $"Sign a PGP/GPG key" \
  604. --backtitle $"Freedombone User Control Panel" \
  605. --msgbox $"$SIGN_ADDRESS was signed" 6 50
  606. fi
  607. fi
  608. fi
  609. ;;
  610. esac
  611. }
  612. function gpg_key_trust {
  613. data=$(tempfile 2>/dev/null)
  614. trap "rm -f $data" 0 1 2 5 15
  615. dialog --title $"Trust a PGP/GPG key or website domain" \
  616. --backtitle $"Freedombone User Control Panel" \
  617. --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
  618. sel=$?
  619. case $sel in
  620. 0)
  621. TRUST_ADDRESS=$(<$data)
  622. if [ ${#TRUST_ADDRESS} -gt 2 ]; then
  623. clear
  624. gpg --search "$TRUST_ADDRESS"
  625. gpg_set_trust "$TRUST_ADDRESS"
  626. fi
  627. ;;
  628. esac
  629. }
  630. function menu_encryption_keys {
  631. while true
  632. do
  633. data=$(tempfile 2>/dev/null)
  634. trap "rm -f $data" 0 1 2 5 15
  635. dialog --backtitle $"Freedombone User Control Panel" \
  636. --title $"My Encryption Keys" \
  637. --radiolist $"Choose an operation:" 19 70 11 \
  638. 1 $"Show your PGP/GPG key" off \
  639. 2 $"Show your full PGP/GPG key, including private key" off \
  640. 3 $"Publish your PGP/GPG key so that others can find it" off \
  641. 4 $"Add someone's PGP/GPG key" off \
  642. 5 $"Remove someone's PGP/GPG key" off \
  643. 6 $"Sign a PGP/GPG key or website domain" off \
  644. 7 $"Refresh your PGP/GPG keys" off \
  645. 8 $"Add an ssh key for logging in" off \
  646. 9 $"Remove an ssh key for logging in" off \
  647. 10 $"Set the trust level for a PGP/GPG key" off \
  648. 11 $"Back to main menu" on 2> $data
  649. sel=$?
  650. case $sel in
  651. 1) break;;
  652. 255) break;;
  653. esac
  654. case $(cat $data) in
  655. 1) show_gpg_key;;
  656. 2) show_full_gpg_key;;
  657. 3) publish_gpg_key;;
  658. 4) add_gpg_key;;
  659. 5) remove_gpg_key;;
  660. 6) sign_gpg_key;;
  661. 7) refresh_gpg_keys;;
  662. 8) add_ssh_key;;
  663. 9) remove_ssh_key;;
  664. 10) gpg_key_trust;;
  665. 11) break;;
  666. esac
  667. done
  668. }
  669. function menu_email {
  670. while true
  671. do
  672. data=$(tempfile 2>/dev/null)
  673. trap "rm -f $data" 0 1 2 5 15
  674. dialog --backtitle $"Freedombone User Control Panel" \
  675. --title $"Change Email Filtering Rules" \
  676. --radiolist $"Choose an operation:" 14 70 7 \
  677. 1 $"Add yourself to a mailing list" off \
  678. 2 $"Remove yourself from a mailing list" off \
  679. 3 $"Add an email rule for an address" off \
  680. 4 $"Add an email rule for a subject" off \
  681. 5 $"Block or unblock an email address" off \
  682. 6 $"Block or unblock email with subject text" off \
  683. 7 $"Back to main menu" on 2> $data
  684. sel=$?
  685. case $sel in
  686. 1) break;;
  687. 255) break;;
  688. esac
  689. case $(cat $data) in
  690. 1) add_to_mailing_list;;
  691. 2) remove_user_from_mailing_list;;
  692. 3) email_rule_address;;
  693. 4) email_rule_subject;;
  694. 5) block_unblock_email;;
  695. 6) block_unblock_subject;;
  696. 7) break;;
  697. esac
  698. done
  699. }
  700. function menu_admin {
  701. if [ ! -f /etc/sudoers ]; then
  702. clear
  703. exit 0
  704. fi
  705. sudo /usr/local/bin/control
  706. }
  707. function sign_keys {
  708. if [ ! -f /home/$USER/.monkeysphere/server_keys ]; then
  709. return
  710. fi
  711. dialog --title $"Monkeysphere sign server keys" \
  712. --backtitle $"Freedombone Security Configuration" \
  713. --defaultno \
  714. --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
  715. sel=$?
  716. case $sel in
  717. 0) ${PROJECT_NAME}-sec --sign yes;;
  718. esac
  719. }
  720. function menu_run_client_app {
  721. detect_installable_apps
  722. applist=""
  723. appnames=()
  724. n=1
  725. app_index=0
  726. for a in "${APPS_AVAILABLE[@]}"
  727. do
  728. if [[ ${APPS_INSTALLED[$app_index]} != "0" ]]; then
  729. if [[ $(function_exists run_client_${a}) == "1" ]]; then
  730. applist="$applist $n $a off"
  731. n=$[n+1]
  732. appnames+=("$a")
  733. fi
  734. fi
  735. app_index=$[app_index+1]
  736. done
  737. if [ $n -le 1 ]; then
  738. return
  739. fi
  740. backstr=$'Exit'
  741. applist="$applist $n $backstr on"
  742. appnames+=("Exit")
  743. choice=$(dialog --stdout --backtitle $"Freedombone" \
  744. --title $"Run an App" \
  745. --radiolist $'Choose:' \
  746. 16 40 20 $applist)
  747. if [ $? -eq 0 ]; then
  748. app_index=$[choice-1]
  749. chosen_app=${appnames[$app_index]}
  750. if [[ $chosen_app != "Exit" ]]; then
  751. run_client_${chosen_app}
  752. fi
  753. fi
  754. }
  755. function menu_top_level {
  756. while true
  757. do
  758. data=$(tempfile 2>/dev/null)
  759. trap "rm -f $data" 0 1 2 5 15
  760. dialog --backtitle $"Freedombone User Control Panel" \
  761. --title $"User Control Panel" \
  762. --radiolist $"Choose an operation:" 19 50 12 \
  763. 1 $"Use Email" off \
  764. 2 $"Change Email Filtering Rules" off \
  765. 3 $"Run an App" off \
  766. 4 $"Browse the Web" off \
  767. 5 $"My Encryption Keys" off \
  768. 6 $"Set an outgoing email proxy" off \
  769. 7 $"Administrator controls" off \
  770. 8 $"Exit to the command line" off \
  771. 9 $"Log out" on 2> $data
  772. sel=$?
  773. case $sel in
  774. 1) exit 1;;
  775. 255) exit 1;;
  776. esac
  777. case $(cat $data) in
  778. 1) mutt;;
  779. 2) menu_email;;
  780. 3) menu_run_client_app;;
  781. 4) torify elinks;;
  782. 5) menu_encryption_keys;;
  783. 6) smtp_proxy;;
  784. 7) menu_admin;;
  785. 8) break;;
  786. 9) kill -HUP `pgrep -s 0 -o`;;
  787. esac
  788. done
  789. }
  790. sign_keys
  791. menu_top_level
  792. clear
  793. . ~/.bashrc
  794. exit 0