freedombone-controlpanel 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Administrator control panel for the Freedombone system
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2015 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 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 General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU 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
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. COMPLETION_FILE=$HOME/freedombone-completed.txt
  34. SELECTED_USERNAME=
  35. SIP_CONFIG_FILE=/etc/sipwitch.conf
  36. ADMIN_USER=
  37. UPGRADE_SCRIPT_NAME="${PROJECT_NAME}-upgrade"
  38. function any_key {
  39. echo ' '
  40. read -n1 -r -p "Press any key to continue..." key
  41. }
  42. function check_for_updates {
  43. if [ ! -f /etc/cron.weekly/$UPGRADE_SCRIPT_NAME ]; then
  44. dialog --title $"Check for updates" \
  45. --msgbox $"Upgrade script was not found" 6 40
  46. return
  47. fi
  48. clear
  49. . /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
  50. any_key
  51. }
  52. function add_user {
  53. data=$(tempfile 2>/dev/null)
  54. trap "rm -f $data" 0 1 2 5 15
  55. dialog --backtitle $"Freedombone Control Panel" \
  56. --title $"Add new user" \
  57. --form "\n" 8 40 3 \
  58. $"Username:" 1 1 "" 1 11 16 15 \
  59. $"ssh public key (optional):" 2 1 "" 3 1 40 10000 \
  60. 2> $data
  61. sel=$?
  62. case $sel in
  63. 1) return;;
  64. 255) return;;
  65. esac
  66. new_user_username=$(cat $data | sed -n 1p)
  67. new_user_ssh_public_key=$(cat $data | sed -n 2p)
  68. if [ ${#new_user_username} -lt 2 ]; then
  69. dialog --title $"New username" \
  70. --msgbox $"No username was given" 6 40
  71. return
  72. fi
  73. if [[ "$new_user_username" == *" "* ]]; then
  74. dialog --title $"Invalid username" \
  75. --msgbox $"The username should not contain any spaces" 6 40
  76. return
  77. fi
  78. if [ ${#new_user_ssh_public_key} -lt 20 ]; then
  79. clear
  80. freedombone-adduser "$new_user_username"
  81. any_key
  82. else
  83. if [[ "$new_user_ssh_public_key" == "ssh-"* ]]; then
  84. clear
  85. freedombone-adduser "$new_user_username" "$new_user_ssh_public_key"
  86. any_key
  87. else
  88. dialog --title $"ssh public key" \
  89. --msgbox $"This does not look like an ssh public key" 6 40
  90. fi
  91. fi
  92. }
  93. function show_sip_extensions {
  94. if [ ! -f $SIP_CONFIG_FILE ]; then
  95. return;
  96. fi
  97. clear
  98. echo $"SIP phone extensions:"
  99. echo " "
  100. while read ext; do
  101. if [[ $ext == *"user id"* ]]; then
  102. echo -n " "
  103. echo -n $(echo "$ext" | awk -F '"' '{print $2}' | awk -F '"' '{print $1}')
  104. echo -n " "
  105. fi
  106. if [[ $ext == *"extension"* ]]; then
  107. echo $(echo "$ext" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
  108. fi
  109. done < $SIP_CONFIG_FILE
  110. any_key
  111. }
  112. function select_user {
  113. SELECTED_USERNAME=
  114. data=$(tempfile 2>/dev/null)
  115. trap "rm -f $data" 0 1 2 5 15
  116. dialog --title "Select a user" \
  117. --backtitle $"Freedombone Control Panel" \
  118. --dselect "/home/" 14 40 2> $data
  119. sel=$?
  120. case $sel in
  121. 0) SELECTED_USERNAME=$(cat $data | awk -F '/' '{print $3}');;
  122. 1) return;;
  123. 255) return;;
  124. esac
  125. if [ ${#SELECTED_USERNAME} -lt 2 ]; then
  126. SELECTED_USERNAME=
  127. fi
  128. if [ ! -d /home/$SELECTED_USERNAME/Maildir ]; then
  129. dialog --title $"User directory check" \
  130. --msgbox $"This does not look like a user directory" 6 40
  131. SELECTED_USERNAME=
  132. fi
  133. }
  134. function delete_user {
  135. select_user
  136. if [ ! $SELECTED_USERNAME ]; then
  137. return
  138. fi
  139. if grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
  140. dialog --title $"Administrator user" \
  141. --msgbox $"You can't delete the administrator user" 6 40
  142. return
  143. fi
  144. clear
  145. freedombone-rmuser $SELECTED_USERNAME
  146. any_key
  147. }
  148. function configure_remote_backups {
  149. if ! grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
  150. dialog --title $"Administrator user" \
  151. --msgbox $"No Administrator user found. Check $COMPLETION_FILE" 6 40
  152. return
  153. fi
  154. if [ ${#ADMIN} -lt 2 ]; then
  155. dialog --title $"Administrator user" \
  156. --msgbox $"Username not found" 6 40
  157. return
  158. fi
  159. if [ ! -d /home/$ADMIN_USER ]; then
  160. dialog --title $"Administrator user" \
  161. --msgbox $"Home directory not found" 6 40
  162. return
  163. fi
  164. freedombone-remote -u $ADMIN_USER
  165. }
  166. function change_password {
  167. select_user
  168. if [ ! $SELECTED_USERNAME ]; then
  169. return
  170. fi
  171. clear
  172. echo -n $"Change password for"
  173. echo " $SELECTED_USERNAME"
  174. echo ""
  175. su -c "passwd" - $SELECTED_USERNAME
  176. any_key
  177. }
  178. function change_ssh_public_key {
  179. select_user
  180. if [ ! $SELECTED_USERNAME ]; then
  181. return
  182. fi
  183. if grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
  184. dialog --title $"Change ssh public key" \
  185. --backtitle $"Freedombone Control Panel" \
  186. --defaultno \
  187. --yesno $"\nThis is the administrator user.\n\nAre you sure you want to change the ssh public key for the administrator?" 10 60
  188. sel=$?
  189. case $sel in
  190. 1) return;;
  191. 255) return;;
  192. esac
  193. fi
  194. data=$(tempfile 2>/dev/null)
  195. trap "rm -f $data" 0 1 2 5 15
  196. dialog --title $"Change ssh public key for $SELECTED_USERNAME" \
  197. --backtitle $"Freedombone Control Panel" \
  198. --inputbox $"Paste the ssh public key below" 8 60 2>$data
  199. sel=$?
  200. case $sel in
  201. 0)
  202. SSH_PUBLIC_KEY=$(<$data)
  203. if [ "$SSH_PUBLIC_KEY" ]; then
  204. if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
  205. if [ -f "$SSH_PUBLIC_KEY" ]; then
  206. if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
  207. mkdir /home/$SELECTED_USERNAME/.ssh
  208. fi
  209. cp $SSH_PUBLIC_KEY \
  210. /home/$SELECTED_USERNAME/.ssh/authorized_keys
  211. chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
  212. /home/$SELECTED_USERNAME/.ssh
  213. dialog --title $"Change ssh public key" \
  214. --msgbox $"ssh public key was installed" 6 40
  215. else
  216. if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
  217. if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
  218. mkdir /home/$SELECTED_USERNAME/.ssh
  219. fi
  220. echo "$SSH_PUBLIC_KEY" > \
  221. /home/$SELECTED_USERNAME/.ssh/authorized_keys
  222. chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
  223. /home/$SELECTED_USERNAME/.ssh
  224. dialog --title $"Change ssh public key" \
  225. --msgbox $"ssh public key was installed" 6 40
  226. fi
  227. fi
  228. fi
  229. fi
  230. ;;
  231. esac
  232. }
  233. function add_to_mailing_list {
  234. select_user
  235. if [ ! $SELECTED_USERNAME ]; then
  236. return
  237. fi
  238. data=$(tempfile 2>/dev/null)
  239. trap "rm -f $data" 0 1 2 5 15
  240. dialog --backtitle $"Freedombone Control Panel" \
  241. --title $"Subscribe $SELECTED_USERNAME to a mailing list" \
  242. --form "\n" 8 68 4 \
  243. $"List folder name:" 1 1 "" 1 35 26 25 \
  244. $"Name between [] on subject line:" 2 1 "" 2 35 26 25 \
  245. $"List email address:" 3 1 "" 3 35 26 25 \
  246. 2> $data
  247. sel=$?
  248. case $sel in
  249. 1) return;;
  250. 255) return;;
  251. esac
  252. LIST_NAME=$(cat $data | sed -n 1p)
  253. LIST_SUBJECT=$(cat $data | sed -n 2p)
  254. LIST_EMAIL=$(cat $data | sed -n 3p)
  255. if [ ${#LIST_NAME} -lt 2 ]; then
  256. dialog --title $"Add mailing list" \
  257. --msgbox $"No mailing list name was given" 6 40
  258. return
  259. fi
  260. if [ ${#LIST_SUBJECT} -lt 2 ]; then
  261. dialog --title $"Add mailing list" \
  262. --msgbox $"No mailing list subject was given" 6 40
  263. return
  264. fi
  265. if [ ${#LIST_EMAIL} -lt 2 ]; then
  266. dialog --title $"Add mailing list" \
  267. --msgbox $"No mailing list email address was given" 6 40
  268. return
  269. fi
  270. if [[ "$LIST_EMAIL" != *"@"* || "$LIST_EMAIL" != *"."* ]]; then
  271. dialog --title $"Add mailing list" \
  272. --msgbox $"Unrecognised email address" 6 40
  273. return
  274. fi
  275. freedombone-addlist -u $SELECTED_USERNAME -l "$LIST_NAME" \
  276. -s "$LIST_SUBJECT" -e "$LIST_EMAIL"
  277. dialog --title $"Add mailing list" \
  278. --msgbox $"$LIST_NAME list was added" 6 40
  279. }
  280. function email_rule {
  281. select_user
  282. if [ ! $SELECTED_USERNAME ]; then
  283. return
  284. fi
  285. data=$(tempfile 2>/dev/null)
  286. trap "rm -f $data" 0 1 2 5 15
  287. dialog --backtitle $"Freedombone Control Panel" \
  288. --title $"Email rule for user $SELECTED_USERNAME" \
  289. --form "\n" 8 65 3 \
  290. $"When email arrives from address:" 1 1 "" 1 35 24 28 \
  291. $"Move to folder:" 2 1 "" 2 35 24 28 \
  292. 2> $data
  293. sel=$?
  294. case $sel in
  295. 1) return;;
  296. 255) return;;
  297. esac
  298. RULE_EMAIL=$(cat $data | sed -n 1p)
  299. RULE_FOLDER=$(cat $data | sed -n 2p)
  300. if [ ${#RULE_EMAIL} -lt 2 ]; then
  301. dialog --title $"Add email rule" \
  302. --msgbox $"No email address was given" 6 40
  303. return
  304. fi
  305. if [ ${#RULE_FOLDER} -lt 2 ]; then
  306. dialog --title $"Add email rule" \
  307. --msgbox $"No folder name was given" 6 40
  308. return
  309. fi
  310. if [[ "$RULE_EMAIL" != *"@"* || "$RULE_EMAIL" != *"."* ]]; then
  311. dialog --title $"Add email rule" \
  312. --msgbox $"Unrecognised email address" 6 40
  313. return
  314. fi
  315. freedombone-addemail -u $SELECTED_USERNAME -e "$RULE_EMAIL" \
  316. -g "$RULE_FOLDER"
  317. dialog --title $"Add email rule" \
  318. --msgbox $"Email rule for $RULE_EMAIL was added" 6 40
  319. }
  320. function block_unblock_email {
  321. select_user
  322. if [ ! $SELECTED_USERNAME ]; then
  323. return
  324. fi
  325. blockstr=$"Block/Unblock email going to"
  326. data=$(tempfile 2>/dev/null)
  327. trap "rm -f $data" 0 1 2 5 15
  328. dialog --backtitle $"Freedombone Control Panel" \
  329. --title "$blockstr $SELECTED_USERNAME" \
  330. --form "\n" 8 65 3 \
  331. $"When email arrives from address:" 1 1 "" 1 35 24 28 \
  332. $"Block it:" 2 1 "yes" 2 35 4 4 \
  333. 2> $data
  334. sel=$?
  335. case $sel in
  336. 1) return;;
  337. 255) return;;
  338. esac
  339. BLOCK_EMAIL=$(cat $data | sed -n 1p)
  340. BLOCK=$(cat $data | sed -n 2p)
  341. if [ ${#BLOCK_EMAIL} -lt 2 ]; then
  342. dialog --title $"Block/Unblock an email" \
  343. --msgbox $"No email address was given" 6 40
  344. return
  345. fi
  346. if [[ "$BLOCK_EMAIL" != *"@"* || "$BLOCK_EMAIL" != *"."* ]]; then
  347. dialog --title $"Block/Unblock an email" \
  348. --msgbox $"Unrecognised email address" 6 40
  349. return
  350. fi
  351. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  352. freedombone-ignore -u $SELECTED_USERNAME -e "$BLOCK_EMAIL"
  353. dialog --title $"Block an email" \
  354. --msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME blocked" 6 40
  355. else
  356. freedombone-unignore -u $SELECTED_USERNAME -e "$BLOCK_EMAIL"
  357. dialog --title $"Unblock an email" \
  358. --msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME unblocked" 6 40
  359. fi
  360. }
  361. function block_unblock_subject {
  362. select_user
  363. if [ ! $SELECTED_USERNAME ]; then
  364. return
  365. fi
  366. blockstr=$"Block/Unblock email going to"
  367. data=$(tempfile 2>/dev/null)
  368. trap "rm -f $data" 0 1 2 5 15
  369. dialog --backtitle $"Freedombone Control Panel" \
  370. --title "$blockstr $SELECTED_USERNAME" \
  371. --form "\n" 8 70 3 \
  372. $"When email arrives with subject text:" 1 1 "" 1 40 24 28 \
  373. $"Block it:" 2 1 "yes" 2 40 4 4 \
  374. 2> $data
  375. sel=$?
  376. case $sel in
  377. 1) return;;
  378. 255) return;;
  379. esac
  380. BLOCK_SUBJECT=$(cat $data | sed -n 1p)
  381. BLOCK=$(cat $data | sed -n 2p)
  382. if [ ${#BLOCK_SUBJECT} -lt 2 ]; then
  383. dialog --title $"Block/Unblock an email" \
  384. --msgbox $"No subject was given" 6 40
  385. return
  386. fi
  387. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  388. freedombone-ignore -u $SELECTED_USERNAME -t "$BLOCK_SUBJECT"
  389. dialog --title $"Block an email" \
  390. --msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME blocked" 6 40
  391. else
  392. freedombone-unignore -u $SELECTED_USERNAME -t "$BLOCK_SUBJECT"
  393. dialog --title $"Unblock an email" \
  394. --msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME unblocked" 6 40
  395. fi
  396. }
  397. function create_keydrive_master {
  398. select_user
  399. if [ ! $SELECTED_USERNAME ]; then
  400. return
  401. fi
  402. dialog --title $"USB Master Keydrive" \
  403. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  404. clear
  405. freedombone-keydrive -u $SELECTED_USERNAME --master 'yes'
  406. any_key
  407. }
  408. function create_keydrive_fragment {
  409. select_user
  410. if [ ! $SELECTED_USERNAME ]; then
  411. return
  412. fi
  413. dialog --title $"USB Fragment Keydrive" \
  414. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  415. clear
  416. freedombone-keydrive -u $SELECTED_USERNAME
  417. any_key
  418. }
  419. function backup_data {
  420. dialog --title $"Backup data to USB" \
  421. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  422. clear
  423. echo ' '
  424. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  425. backup
  426. any_key
  427. }
  428. function restore_data {
  429. dialog --title $"Restore data from USB" \
  430. --msgbox $"Plug in your backup USB drive" 6 40
  431. clear
  432. echo ' '
  433. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  434. restore
  435. any_key
  436. }
  437. function restore_data_remote {
  438. if [ ! $ADMIN_USER ]; then
  439. dialog --title $"Restore data from remote server" \
  440. --msgbox $"Unknown admin user" 6 40
  441. return
  442. fi
  443. data=$(tempfile 2>/dev/null)
  444. trap "rm -f $data" 0 1 2 5 15
  445. dialog --title $"Restore from remote server" \
  446. --backtitle $"Freedombone Control Panel" \
  447. --inputbox $"Enter the domain name of the server from which you wish to restore" 8 60 2>$data
  448. sel=$?
  449. case $sel in
  450. 0)
  451. friend_server_domain_name=$(<$data)
  452. if [ ${#friend_server_domain_name} -lt 2 ]; then
  453. return
  454. fi
  455. if [[ $friend_server_domain_name != *"."* ]]; then
  456. dialog --title $"Remote server domain name" \
  457. --msgbox $"Invalid domain name" 6 40
  458. return
  459. fi
  460. restorefromfriend $friend_server_domain_name
  461. any_key
  462. ;;
  463. esac
  464. }
  465. function logging_on_off {
  466. logging="no"
  467. dialog --title $"Logging" \
  468. --backtitle $"Freedombone Control Panel" \
  469. --yesno $"\nDo you want to turn logging on?" 7 60
  470. sel=$?
  471. case $sel in
  472. 0) logging="yes";;
  473. 255) return;;
  474. esac
  475. clear
  476. echo ''
  477. echo $'This may take a few seconds. Please wait...'
  478. if [[ $logging == "no" ]]; then
  479. freedombone-logging off
  480. else
  481. freedombone-logging on
  482. fi
  483. }
  484. function restore_gpg_key {
  485. select_user
  486. if [ ! $SELECTED_USERNAME ]; then
  487. return
  488. fi
  489. restorestr=$"Restore GPG key for user"
  490. dialog --title "$restorestr $SELECTED_USERNAME" \
  491. --msgbox $"Plug in your USB keydrive" 6 40
  492. clear
  493. freedombone-recoverkey -u $SELECTED_USERNAME
  494. any_key
  495. }
  496. function security_settings {
  497. freedombone-sec
  498. any_key
  499. }
  500. function reset_tripwire {
  501. clear
  502. echo $'Resetting the Tripwire...'
  503. echo ' '
  504. echo '
  505. ' | reset-tripwire
  506. any_key
  507. }
  508. function hubzilla_renew_cert {
  509. dialog --title $"Renew SSL certificate" \
  510. --backtitle $"Freedombone Control Panel" \
  511. --yesno $"\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60
  512. sel=$?
  513. case $sel in
  514. 1) return;;
  515. 255) return;;
  516. esac
  517. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  518. if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs ]; then
  519. dialog --title $"Renew SSL certificate" \
  520. --msgbox $"Hubzilla install directory not found" 6 40
  521. return
  522. fi
  523. freedombone-renew-cert -h $HUBZILLA_DOMAIN_NAME -p 'letsencrypt'
  524. if [ ! "$?" = "0" ]; then
  525. any_key
  526. else
  527. dialog --title $"Renew SSL certificate" \
  528. --msgbox $"Hubzilla certificate has been renewed" 6 40
  529. fi
  530. }
  531. function hubzilla_restore {
  532. dialog --title $"Restore hubzilla from USB backup" \
  533. --backtitle $"Freedombone Control Panel" \
  534. --yesno $"\nInsert your USB backup drive and select 'yes' to continue" 16 60
  535. sel=$?
  536. case $sel in
  537. 1) return;;
  538. 255) return;;
  539. esac
  540. clear
  541. echo $'Enter your backup drive password:'
  542. restorehubzilla
  543. }
  544. function hubzilla_channel_directory_server {
  545. if ! grep -q "Hubzilla domain" $COMPLETION_FILE; then
  546. dialog --title $"Hubzilla channel directory server" \
  547. --msgbox $"Hubzilla is not installed on this system" 6 40
  548. return
  549. fi
  550. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  551. if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs ]; then
  552. dialog --title $"Hubzilla channel directory server" \
  553. --msgbox $"Hubzilla install directory not found" 6 40
  554. return
  555. fi
  556. data=$(tempfile 2>/dev/null)
  557. trap "rm -f $data" 0 1 2 5 15
  558. dialog --title $"Hubzilla channel directory server" \
  559. --backtitle $"Freedombone Control Panel" \
  560. --inputbox $"When you click on 'channel directory' this is where Hubzilla will obtain its list from" 8 60 2>$data
  561. sel=$?
  562. case $sel in
  563. 0)
  564. hubzilla_domain_server=$(<$data)
  565. if [[ $hubzilla_domain_server != *"."* ]]; then
  566. return
  567. fi
  568. if [[ $hubzilla_domain_server != "https"* ]]; then
  569. dialog --title $"Hubzilla channel directory server" \
  570. --msgbox $"Invalid domain - include the https://" 6 40
  571. return
  572. fi
  573. ./var/www/$HUBZILLA_DOMAIN_NAME/htdocs/util/config system directory_server $hubzilla_domain_server
  574. dialog --title $"Hubzilla channel directory server" \
  575. --msgbox $"Domain channel directory server changed to $hubzilla_domain_server" 6 40
  576. ;;
  577. esac
  578. }
  579. function format_drive {
  580. drive=
  581. data=$(tempfile 2>/dev/null)
  582. trap "rm -f $data" 0 1 2 5 15
  583. dialog --backtitle $"Freedombone Control Panel" \
  584. --title $"Format a USB drive (LUKS encrypted)" \
  585. --radiolist $"Choose a drive:" 12 70 5 \
  586. 1 $"sda (Beaglebone Black)" off \
  587. 2 $"sdb" off \
  588. 3 $"sdc" off \
  589. 4 $"sdd" off \
  590. 5 $"Back to Backup and Restore menu" on 2> $data
  591. sel=$?
  592. case $sel in
  593. 1) return;;
  594. 255) return;;
  595. esac
  596. case $(cat $data) in
  597. 1) drive='sda';;
  598. 2) drive='sdb';;
  599. 3) drive='sdc';;
  600. 4) drive='sdd';;
  601. 5) return;;
  602. esac
  603. dialog --title $"Format USB drive" \
  604. --backtitle $"Freedombone Control Panel" \
  605. --defaultno \
  606. --yesno $"\nPlease confirm that you wish to format drive\n\n ${drive}\n\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\n\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60
  607. sel=$?
  608. case $sel in
  609. 1) return;;
  610. 255) return;;
  611. esac
  612. clear
  613. freedombone-format $drive
  614. any_key
  615. }
  616. function shut_down_system {
  617. dialog --title $"Power off the system" \
  618. --backtitle $"Freedombone Control Panel" \
  619. --defaultno \
  620. --yesno $"\nPlease confirm that you wish to power off the system.\n\nWARNING: to power on again you will need to have physical access to the hardware." 10 60
  621. sel=$?
  622. case $sel in
  623. 1) return;;
  624. 255) return;;
  625. esac
  626. shutdown now
  627. }
  628. function restart_system {
  629. dialog --title $"Restart the system" \
  630. --backtitle $"Freedombone Control Panel" \
  631. --defaultno \
  632. --yesno $"\nPlease confirm that you wish to restart the system.\n\nWARNING: If you are using full disk encryption then you will need physical access to the hardware to type in the password" 10 60
  633. sel=$?
  634. case $sel in
  635. 1) return;;
  636. 255) return;;
  637. esac
  638. reboot
  639. }
  640. function change_system_name {
  641. data=$(tempfile 2>/dev/null)
  642. trap "rm -f $data" 0 1 2 5 15
  643. dialog --title $"Change the name of this system" \
  644. --backtitle $"Freedombone Control Panel" \
  645. --inputbox $'Enter a new name for this system on your local network\n\nIt will appear as newname.local' 10 60 2>$data
  646. sel=$?
  647. case $sel in
  648. 0) NEW_SYSTEM_NAME=$(<$data)
  649. if [ "$NEW_SYSTEM_NAME" ]; then
  650. if [ ${#NEW_SYSTEM_NAME} -gt 1 ]; then
  651. sed -i "s|host-name=.*|host-name=$NEW_SYSTEM_NAME|g" /etc/avahi/avahi-daemon.conf
  652. systemctl restart avahi-daemon
  653. if grep -q "host-name=$NEW_SYSTEM_NAME" /etc/avahi/avahi-daemon.conf; then
  654. dialog --title $"New local network name" \
  655. --msgbox $"The name of this system on your local network was changed successfully" 6 70
  656. fi
  657. fi
  658. fi
  659. ;;
  660. esac
  661. }
  662. function menu_backup_restore {
  663. while true
  664. do
  665. data=$(tempfile 2>/dev/null)
  666. trap "rm -f $data" 0 1 2 5 15
  667. dialog --backtitle $"Freedombone Control Panel" \
  668. --title $"Backup and Restore" \
  669. --radiolist $"Choose an operation:" 17 70 10 \
  670. 1 $"Backup data to USB drive" off \
  671. 2 $"Restore GPG key from USB keydrive" off \
  672. 3 $"Restore data from USB drive" off \
  673. 4 $"Restore Hubzilla data from USB drive" off \
  674. 5 $"Configure remote backups" off \
  675. 6 $"Restore from remote backup" off \
  676. 7 $"Backup GPG key to USB (master keydrive)" off \
  677. 8 $"Backup GPG key to USB (fragment keydrive)" off \
  678. 9 $"Format a USB drive (LUKS encrypted)" off \
  679. 10 $"Back to main menu" on 2> $data
  680. sel=$?
  681. case $sel in
  682. 1) break;;
  683. 255) break;;
  684. esac
  685. case $(cat $data) in
  686. 1) backup_data;;
  687. 2) restore_gpg_key;;
  688. 3) restore_data;;
  689. 4) hubzilla_restore;;
  690. 5) configure_remote_backups;;
  691. 6) restore_data_remote;;
  692. 7) create_keydrive_master;;
  693. 8) create_keydrive_fragment;;
  694. 9) format_drive;;
  695. 10) break;;
  696. esac
  697. done
  698. }
  699. function menu_email {
  700. while true
  701. do
  702. data=$(tempfile 2>/dev/null)
  703. trap "rm -f $data" 0 1 2 5 15
  704. dialog --backtitle $"Freedombone Control Panel" \
  705. --title $"Email Filtering Rules" \
  706. --radiolist $"Choose an operation:" 12 70 5 \
  707. 1 $"Add a user to a mailing list" off \
  708. 2 $"Add an email rule" off \
  709. 3 $"Block/Unblock an email address" off \
  710. 4 $"Block/Unblock email with subject text" off \
  711. 5 $"Back to main menu" on 2> $data
  712. sel=$?
  713. case $sel in
  714. 1) break;;
  715. 255) break;;
  716. esac
  717. case $(cat $data) in
  718. 1) add_to_mailing_list;;
  719. 2) email_rule;;
  720. 3) block_unblock_email;;
  721. 4) block_unblock_subject;;
  722. 5) break;;
  723. esac
  724. done
  725. }
  726. function menu_users {
  727. while true
  728. do
  729. data=$(tempfile 2>/dev/null)
  730. trap "rm -f $data" 0 1 2 5 15
  731. dialog --backtitle $"Freedombone Control Panel" \
  732. --title $"Manage Users" \
  733. --radiolist $"Choose an operation:" 12 70 5 \
  734. 1 $"Add a user" off \
  735. 2 $"Delete a user" off \
  736. 3 $"Change user password" off \
  737. 4 $"Change user ssh public key" off \
  738. 5 $"Back to main menu" on 2> $data
  739. sel=$?
  740. case $sel in
  741. 1) break;;
  742. 255) break;;
  743. esac
  744. case $(cat $data) in
  745. 1) add_user;;
  746. 2) delete_user;;
  747. 3) change_password;;
  748. 4) change_ssh_public_key;;
  749. 5) break;;
  750. esac
  751. done
  752. }
  753. function menu_hubzilla {
  754. while true
  755. do
  756. data=$(tempfile 2>/dev/null)
  757. trap "rm -f $data" 0 1 2 5 15
  758. dialog --backtitle $"Freedombone Control Panel" \
  759. --title $"Hubzilla" \
  760. --radiolist $"Choose an operation:" 13 70 4 \
  761. 1 $"Restore from usb backup" off \
  762. 2 $"Set channel directory server" off \
  763. 3 $"Renew SSL certificate" off \
  764. 4 $"Back to main menu" on 2> $data
  765. sel=$?
  766. case $sel in
  767. 1) break;;
  768. 255) break;;
  769. esac
  770. case $(cat $data) in
  771. 1) hubzilla_restore;;
  772. 2) hubzilla_channel_directory_server;;
  773. 3) hubzilla_renew_cert;;
  774. 4) break;;
  775. esac
  776. done
  777. }
  778. function menu_media {
  779. while true
  780. do
  781. data=$(tempfile 2>/dev/null)
  782. trap "rm -f $data" 0 1 2 5 15
  783. dialog --backtitle $"Freedombone Control Panel" \
  784. --title $"Media Menu" \
  785. --radiolist $"Choose an operation:" 13 70 2 \
  786. 1 $"Attach a drive containing playable media" off \
  787. 2 $"Remove a drive containing playable media" off \
  788. 3 $"Exit" on 2> $data
  789. sel=$?
  790. case $sel in
  791. 1) break;;
  792. 255) break;;
  793. esac
  794. case $(cat $data) in
  795. 1) remove-music
  796. attach-music;;
  797. 2) remove-music;;
  798. 3) break;;
  799. esac
  800. done
  801. }
  802. function menu_top_level {
  803. while true
  804. do
  805. data=$(tempfile 2>/dev/null)
  806. trap "rm -f $data" 0 1 2 5 15
  807. dialog --backtitle $"Freedombone Control Panel" \
  808. --title $"Control Panel" \
  809. --radiolist $"Choose an operation:" 21 70 14 \
  810. 1 $"Backup and Restore" off \
  811. 2 $"Show SIP Phone Extensions" off \
  812. 3 $"Reset Tripwire" off \
  813. 4 $"Logging on/off" off \
  814. 5 $"Manage Users" off \
  815. 6 $"Email Filtering Rules" off \
  816. 7 $"Security Settings" off \
  817. 8 $"Hubzilla" off \
  818. 9 $"Media menu" off \
  819. 10 $"Change the name of this system" off \
  820. 11 $"Check for updates" off \
  821. 12 $"Power off the system" off \
  822. 13 $"Restart the system" off \
  823. 14 $"Exit" on 2> $data
  824. sel=$?
  825. case $sel in
  826. 1) exit 1;;
  827. 255) exit 1;;
  828. esac
  829. case $(cat $data) in
  830. 1) menu_backup_restore;;
  831. 2) show_sip_extensions;;
  832. 3) reset_tripwire;;
  833. 4) logging_on_off;;
  834. 5) menu_users;;
  835. 6) menu_email;;
  836. 7) security_settings;;
  837. 8) menu_hubzilla;;
  838. 9) menu_media;;
  839. 10) change_system_name;;
  840. 11) check_for_updates;;
  841. 12) shut_down_system;;
  842. 13) restart_system;;
  843. 14) break;;
  844. esac
  845. done
  846. }
  847. if [ ! -f $COMPLETION_FILE ]; then
  848. echo $'This command should only be run on an installed Freedombone system'
  849. exit 1
  850. fi
  851. ADMIN_USER=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  852. menu_top_level
  853. clear
  854. cat /etc/motd
  855. exit 0