freedombone-controlpanel 49KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  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-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU 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/${PROJECT_NAME}-completed.txt
  34. SELECTED_USERNAME=
  35. SIP_CONFIG_FILE=/etc/sipwitch.conf
  36. ADMIN_USER=
  37. UPGRADE_SCRIPT_NAME="${PROJECT_NAME}-upgrade"
  38. UPDATE_DATE_SCRIPT=/usr/bin/updatedate
  39. # Minimum number of characters in a password
  40. MINIMUM_PASSWORD_LENGTH=8
  41. USB_DRIVE=sdb
  42. # get default USB from config file
  43. CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
  44. if [ -f $CONFIG_FILE ]; then
  45. if grep -q "USB_DRIVE=" $CONFIG_FILE; then
  46. USB_DRIVE=$(cat $CONFIG_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
  47. if [[ $USB_DRIVE == *"dev"* ]]; then
  48. USB_DRIVE=$(echo ${USB_DRIVE} | awk -F '/' '{print $3}' | sed 's|1||g' | sed 's|2||g')
  49. fi
  50. fi
  51. fi
  52. function any_key {
  53. echo ' '
  54. read -n1 -r -p $"Press any key to continue..." key
  55. }
  56. function check_for_updates {
  57. if [ ! -f /etc/cron.weekly/$UPGRADE_SCRIPT_NAME ]; then
  58. dialog --title $"Check for updates" \
  59. --msgbox $"Upgrade script was not found" 6 40
  60. return
  61. fi
  62. clear
  63. . /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
  64. any_key
  65. }
  66. function add_user {
  67. data=$(tempfile 2>/dev/null)
  68. trap "rm -f $data" 0 1 2 5 15
  69. dialog --backtitle $"Freedombone Control Panel" \
  70. --title $"Add new user" \
  71. --form "\n" 8 40 3 \
  72. $"Username:" 1 1 "" 1 11 16 15 \
  73. $"ssh public key (optional):" 2 1 "" 3 1 40 10000 \
  74. 2> $data
  75. sel=$?
  76. case $sel in
  77. 1) return;;
  78. 255) return;;
  79. esac
  80. new_user_username=$(cat $data | sed -n 1p)
  81. new_user_ssh_public_key=$(cat $data | sed -n 2p)
  82. if [ ${#new_user_username} -lt 2 ]; then
  83. dialog --title $"New username" \
  84. --msgbox $"No username was given" 6 40
  85. return
  86. fi
  87. if [[ "$new_user_username" == *" "* ]]; then
  88. dialog --title $"Invalid username" \
  89. --msgbox $"The username should not contain any spaces" 6 40
  90. return
  91. fi
  92. if [ ${#new_user_ssh_public_key} -lt 20 ]; then
  93. clear
  94. ${PROJECT_NAME}-adduser "$new_user_username"
  95. any_key
  96. else
  97. if [[ "$new_user_ssh_public_key" == "ssh-"* ]]; then
  98. clear
  99. ${PROJECT_NAME}-adduser "$new_user_username" "$new_user_ssh_public_key"
  100. any_key
  101. else
  102. dialog --title $"ssh public key" \
  103. --msgbox $"This does not look like an ssh public key" 6 40
  104. fi
  105. fi
  106. }
  107. function pad_string {
  108. echo -n -e "$1" | sed -e :a -e 's/^.\{1,25\}$/& /;ta'
  109. }
  110. function show_domains {
  111. echo 'Domains'
  112. echo '======='
  113. echo ''
  114. if grep -q "Email onion domain" $COMPLETION_FILE; then
  115. echo -n -e "$(pad_string 'Email')"
  116. echo -n -e "$(pad_string ' ')"
  117. echo "$(cat ${COMPLETION_FILE} | grep 'Email onion domain' | awk -F ':' '{print $2}')"
  118. fi
  119. if grep -q "Wiki domain" $COMPLETION_FILE; then
  120. echo -n -e "$(pad_string 'Wiki')"
  121. WIKIDOM=$(cat ${COMPLETION_FILE} | grep 'Wiki domain' | awk -F ':' '{print $2}')
  122. echo -n -e "$(pad_string ${WIKIDOM})"
  123. if [ -d /var/lib/tor/hidden_service_wiki ]; then
  124. echo -n "$(cat /var/lib/tor/hidden_service_wiki/hostname)"
  125. fi
  126. echo ''
  127. fi
  128. if grep -q "Hubzilla domain" $COMPLETION_FILE; then
  129. echo -n -e "$(pad_string 'Hubzilla')"
  130. HUBZILLADOM=$(cat ${COMPLETION_FILE} | grep 'Hubzilla domain' | awk -F ':' '{print $2}')
  131. echo -n -e "$(pad_string ${HUBZILLADOM})"
  132. if [ -d /var/lib/tor/hidden_service_hubzilla ]; then
  133. echo -n "$(cat /var/lib/tor/hidden_service_hubzilla/hostname)"
  134. fi
  135. echo ''
  136. fi
  137. if grep -q "Blog domain" $COMPLETION_FILE; then
  138. echo -n -e "$(pad_string 'Blog')"
  139. BLOGDOM=$(cat ${COMPLETION_FILE} | grep 'Blog domain' | awk -F ':' '{print $2}')
  140. echo -n -e "$(pad_string ${BLOGDOM})"
  141. if [ -d /var/lib/tor/hidden_service_blog ]; then
  142. echo -n "$(cat /var/lib/tor/hidden_service_blog/hostname)"
  143. fi
  144. echo ''
  145. fi
  146. if grep -q "GNU Social domain" $COMPLETION_FILE; then
  147. echo -n -e "$(pad_string 'GNU Social')"
  148. GNUSOCIALDOM=$(cat ${COMPLETION_FILE} | grep 'GNU Social domain' | awk -F ':' '{print $2}')
  149. echo -n -e "$(pad_string ${GNUSOCIALDOM})"
  150. if [ -d /var/lib/tor/hidden_service_microblog ]; then
  151. echo -n "$(cat /var/lib/tor/hidden_service_microblog/hostname)"
  152. fi
  153. echo ''
  154. fi
  155. if grep -q "Owncloud domain" $COMPLETION_FILE; then
  156. echo -n -e "$(pad_string 'Owncloud')"
  157. OWNCLOUDDOM=$(cat ${COMPLETION_FILE} | grep 'Owncloud domain' | awk -F ':' '{print $2}')
  158. echo -n -e "$(pad_string ${OWNCLOUDDOM})"
  159. if [ -d /var/lib/tor/hidden_service_owncloud ]; then
  160. echo -n "$(cat /var/lib/tor/hidden_service_owncloud/hostname)"
  161. fi
  162. echo ''
  163. fi
  164. if grep -q "Gogs domain" $COMPLETION_FILE; then
  165. echo -n -e "$(pad_string 'Gogs')"
  166. GOGSDOM=$(cat ${COMPLETION_FILE} | grep 'Gogs domain' | awk -F ':' '{print $2}')
  167. echo -n -e "$(pad_string ${GOGSDOM})"
  168. if [ -d /var/lib/tor/hidden_service_git ]; then
  169. /var/lib/tor/hidden_service_gogs/hostname
  170. echo -n "$(cat /var/lib/tor/hidden_service_gogs/hostname)"
  171. fi
  172. echo ''
  173. fi
  174. if grep -q "XMPP domain" $COMPLETION_FILE; then
  175. echo -n -e "$(pad_string 'XMPP')"
  176. XMPPDOM=$(cat ${COMPLETION_FILE} | grep 'XMPP domain' | awk -F ':' '{print $2}')
  177. echo -n -e "$(pad_string ${XMPPDOM})"
  178. if [ -d /var/lib/tor/hidden_service_xmpp ]; then
  179. echo -n "$(cat /var/lib/tor/hidden_service_xmpp/hostname)"
  180. fi
  181. echo ''
  182. fi
  183. echo ''
  184. }
  185. function show_users {
  186. echo 'Users'
  187. echo '====='
  188. echo ''
  189. for d in /home/*/ ; do
  190. USRNAME=$(echo "$d" | awk -F '/' '{print $3}')
  191. if [[ $USRNAME != "git" ]]; then
  192. echo -n -e "$(pad_string ${USRNAME})"
  193. # get the SIP extension
  194. SIPEXT=
  195. while read ext; do
  196. if [[ $ext == *"user id"* ]]; then
  197. CURR_UID=$(echo "$ext" | awk -F '"' '{print $2}' | awk -F '"' '{print $1}')
  198. fi
  199. if [[ $ext == *"extension"* ]]; then
  200. if [[ $CURR_UID == $USRNAME ]]; then
  201. SIPEXT=$(echo "$ext" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
  202. fi
  203. fi
  204. done < $SIP_CONFIG_FILE
  205. if [ $SIPEXT ]; then
  206. echo -n -e "$(pad_string SIP:${SIPEXT})"
  207. else
  208. echo -n -e "$(pad_string '')"
  209. fi
  210. # size of the home directory
  211. echo "$(du -s -h /home/${USRNAME} | awk -F ' ' '{print $1}')"
  212. fi
  213. done
  214. }
  215. function show_about {
  216. clear
  217. show_domains
  218. show_users
  219. any_key
  220. }
  221. function select_user {
  222. SELECTED_USERNAME=
  223. data=$(tempfile 2>/dev/null)
  224. trap "rm -f $data" 0 1 2 5 15
  225. dialog --title "Select a user" \
  226. --backtitle $"Freedombone Control Panel" \
  227. --dselect "/home/" 14 40 2> $data
  228. sel=$?
  229. case $sel in
  230. 0) SELECTED_USERNAME=$(cat $data | awk -F '/' '{print $3}');;
  231. 1) return;;
  232. 255) return;;
  233. esac
  234. if [ ${#SELECTED_USERNAME} -lt 2 ]; then
  235. SELECTED_USERNAME=
  236. fi
  237. if [ ! -d /home/$SELECTED_USERNAME ]; then
  238. dialog --title $"User directory check" \
  239. --msgbox $"This does not look like a user directory" 6 40
  240. SELECTED_USERNAME=
  241. fi
  242. }
  243. function delete_user {
  244. select_user
  245. if [ ! $SELECTED_USERNAME ]; then
  246. return
  247. fi
  248. if grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
  249. dialog --title $"Administrator user" \
  250. --msgbox $"You can't delete the administrator user" 6 40
  251. return
  252. fi
  253. clear
  254. ${PROJECT_NAME}-rmuser $SELECTED_USERNAME
  255. any_key
  256. }
  257. function configure_remote_backups {
  258. if ! grep -Fxq "Admin user:$ADMIN_USER" $COMPLETION_FILE; then
  259. dialog --title $"Administrator user" \
  260. --msgbox $"No Administrator user found. Check $COMPLETION_FILE" 6 40
  261. return
  262. fi
  263. if [ ${#ADMIN_USER} -lt 2 ]; then
  264. dialog --title $"Administrator user" \
  265. --msgbox $"Username not found" 6 40
  266. return
  267. fi
  268. if [ ! -d /home/$ADMIN_USER ]; then
  269. dialog --title $"Administrator user" \
  270. --msgbox $"Home directory not found" 6 40
  271. return
  272. fi
  273. ${PROJECT_NAME}-remote -u $ADMIN_USER
  274. if [ ! "$?" = "0" ]; then
  275. any_key
  276. fi
  277. }
  278. function change_password {
  279. select_user
  280. if [ ! $SELECTED_USERNAME ]; then
  281. return
  282. fi
  283. dialog --title $"Change password" \
  284. --passwordbox $"New password for user $SELECTED_USERNAME" 8 40 2> $data
  285. newpassword=$(<$data)
  286. if [ ${#newpassword} -lt ${MINIMUM_PASSWORD_LENGTH} ]; then
  287. dialog --title $"Change password" \
  288. --msgbox $"The password should be ${MINIMUM_PASSWORD_LENGTH} or more characters" 6 40
  289. return
  290. fi
  291. echo "$SELECTED_USERNAME:$newpassword"|chpasswd
  292. dialog --title $"Change password" \
  293. --msgbox $"Password for $SELECTED_USERNAME was changed" 6 40
  294. }
  295. function irc_set_global_password {
  296. dialog --title $"IRC Password" \
  297. --clear \
  298. --backtitle $"Freedombone Control Panel" \
  299. --passwordbox $"Password for all IRC users, or press Enter for no password" 10 50 2> $data
  300. sel=$?
  301. case $sel in
  302. 0)
  303. NEW_IRC_PASSWORD=$(<$data)
  304. sed -i "0,/RE/s/Password =.*/Password =$NEW_IRC_PASSWORD/" /etc/ngircd/ngircd.conf
  305. dialog --title $"IRC Password" \
  306. --msgbox $"The IRC password was changed" 6 40
  307. ;;
  308. esac
  309. }
  310. function change_ssh_public_key {
  311. select_user
  312. if [ ! $SELECTED_USERNAME ]; then
  313. return
  314. fi
  315. if grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
  316. dialog --title $"Change ssh public key" \
  317. --backtitle $"Freedombone Control Panel" \
  318. --defaultno \
  319. --yesno $"\nThis is the administrator user.\n\nAre you sure you want to change the ssh public key for the administrator?" 10 60
  320. sel=$?
  321. case $sel in
  322. 1) return;;
  323. 255) return;;
  324. esac
  325. fi
  326. data=$(tempfile 2>/dev/null)
  327. trap "rm -f $data" 0 1 2 5 15
  328. dialog --title $"Change ssh public key for $SELECTED_USERNAME" \
  329. --backtitle $"Freedombone Control Panel" \
  330. --inputbox $"Paste the ssh public key below" 8 60 2>$data
  331. sel=$?
  332. case $sel in
  333. 0)
  334. SSH_PUBLIC_KEY=$(<$data)
  335. if [ "$SSH_PUBLIC_KEY" ]; then
  336. if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
  337. if [ -f "$SSH_PUBLIC_KEY" ]; then
  338. if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
  339. mkdir /home/$SELECTED_USERNAME/.ssh
  340. fi
  341. cp $SSH_PUBLIC_KEY \
  342. /home/$SELECTED_USERNAME/.ssh/authorized_keys
  343. chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
  344. /home/$SELECTED_USERNAME/.ssh
  345. dialog --title $"Change ssh public key" \
  346. --msgbox $"ssh public key was installed" 6 40
  347. else
  348. if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
  349. if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
  350. mkdir /home/$SELECTED_USERNAME/.ssh
  351. fi
  352. echo "$SSH_PUBLIC_KEY" > \
  353. /home/$SELECTED_USERNAME/.ssh/authorized_keys
  354. chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
  355. /home/$SELECTED_USERNAME/.ssh
  356. dialog --title $"Change ssh public key" \
  357. --msgbox $"ssh public key was installed" 6 40
  358. fi
  359. fi
  360. fi
  361. fi
  362. ;;
  363. esac
  364. }
  365. function add_to_mailing_list {
  366. select_user
  367. if [ ! $SELECTED_USERNAME ]; then
  368. return
  369. fi
  370. data=$(tempfile 2>/dev/null)
  371. trap "rm -f $data" 0 1 2 5 15
  372. dialog --backtitle $"Freedombone Control Panel" \
  373. --title $"Subscribe $SELECTED_USERNAME to a mailing list" \
  374. --form "\n" 8 68 4 \
  375. $"List folder name:" 1 1 "" 1 35 26 25 \
  376. $"Name between [] on subject line:" 2 1 "" 2 35 26 25 \
  377. $"List email address:" 3 1 "" 3 35 26 25 \
  378. 2> $data
  379. sel=$?
  380. case $sel in
  381. 1) return;;
  382. 255) return;;
  383. esac
  384. LIST_NAME=$(cat $data | sed -n 1p)
  385. LIST_SUBJECT=$(cat $data | sed -n 2p)
  386. LIST_EMAIL=$(cat $data | sed -n 3p)
  387. if [ ${#LIST_NAME} -lt 2 ]; then
  388. dialog --title $"Add mailing list" \
  389. --msgbox $"No mailing list name was given" 6 40
  390. return
  391. fi
  392. if [ ${#LIST_SUBJECT} -lt 2 ]; then
  393. dialog --title $"Add mailing list" \
  394. --msgbox $"No mailing list subject was given" 6 40
  395. return
  396. fi
  397. if [ ${#LIST_EMAIL} -lt 2 ]; then
  398. dialog --title $"Add mailing list" \
  399. --msgbox $"No mailing list email address was given" 6 40
  400. return
  401. fi
  402. if [[ "$LIST_EMAIL" != *"@"* || "$LIST_EMAIL" != *"."* ]]; then
  403. dialog --title $"Add mailing list" \
  404. --msgbox $"Unrecognised email address" 6 40
  405. return
  406. fi
  407. ${PROJECT_NAME}-addlist -u $SELECTED_USERNAME -l "$LIST_NAME" \
  408. -s "$LIST_SUBJECT" -e "$LIST_EMAIL"
  409. dialog --title $"Add mailing list" \
  410. --msgbox $"$LIST_NAME list was added" 6 40
  411. }
  412. function email_rule {
  413. select_user
  414. if [ ! $SELECTED_USERNAME ]; then
  415. return
  416. fi
  417. data=$(tempfile 2>/dev/null)
  418. trap "rm -f $data" 0 1 2 5 15
  419. dialog --backtitle $"Freedombone Control Panel" \
  420. --title $"Email rule for user $SELECTED_USERNAME" \
  421. --form "\n" 8 65 3 \
  422. $"When email arrives from address:" 1 1 "" 1 35 24 28 \
  423. $"Move to folder:" 2 1 "" 2 35 24 28 \
  424. 2> $data
  425. sel=$?
  426. case $sel in
  427. 1) return;;
  428. 255) return;;
  429. esac
  430. RULE_EMAIL=$(cat $data | sed -n 1p)
  431. RULE_FOLDER=$(cat $data | sed -n 2p)
  432. if [ ${#RULE_EMAIL} -lt 2 ]; then
  433. dialog --title $"Add email rule" \
  434. --msgbox $"No email address was given" 6 40
  435. return
  436. fi
  437. if [ ${#RULE_FOLDER} -lt 2 ]; then
  438. dialog --title $"Add email rule" \
  439. --msgbox $"No folder name was given" 6 40
  440. return
  441. fi
  442. if [[ "$RULE_EMAIL" != *"@"* || "$RULE_EMAIL" != *"."* ]]; then
  443. dialog --title $"Add email rule" \
  444. --msgbox $"Unrecognised email address" 6 40
  445. return
  446. fi
  447. ${PROJECT_NAME}-addemail -u $SELECTED_USERNAME -e "$RULE_EMAIL" \
  448. -g "$RULE_FOLDER"
  449. dialog --title $"Add email rule" \
  450. --msgbox $"Email rule for $RULE_EMAIL was added" 6 40
  451. }
  452. function block_unblock_email {
  453. select_user
  454. if [ ! $SELECTED_USERNAME ]; then
  455. return
  456. fi
  457. blockstr=$"Block/Unblock email going to"
  458. data=$(tempfile 2>/dev/null)
  459. trap "rm -f $data" 0 1 2 5 15
  460. dialog --backtitle $"Freedombone Control Panel" \
  461. --title "$blockstr $SELECTED_USERNAME" \
  462. --form "\n" 8 65 3 \
  463. $"When email arrives from address:" 1 1 "" 1 35 24 28 \
  464. $"Block it:" 2 1 "yes" 2 35 4 4 \
  465. 2> $data
  466. sel=$?
  467. case $sel in
  468. 1) return;;
  469. 255) return;;
  470. esac
  471. BLOCK_EMAIL=$(cat $data | sed -n 1p)
  472. BLOCK=$(cat $data | sed -n 2p)
  473. if [ ${#BLOCK_EMAIL} -lt 2 ]; then
  474. dialog --title $"Block/Unblock an email" \
  475. --msgbox $"No email address was given" 6 40
  476. return
  477. fi
  478. if [[ "$BLOCK_EMAIL" != *"@"* || "$BLOCK_EMAIL" != *"."* ]]; then
  479. dialog --title $"Block/Unblock an email" \
  480. --msgbox $"Unrecognised email address" 6 40
  481. return
  482. fi
  483. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  484. ${PROJECT_NAME}-ignore -u $SELECTED_USERNAME -e "$BLOCK_EMAIL"
  485. dialog --title $"Block an email" \
  486. --msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME blocked" 6 40
  487. else
  488. ${PROJECT_NAME}-unignore -u $SELECTED_USERNAME -e "$BLOCK_EMAIL"
  489. dialog --title $"Unblock an email" \
  490. --msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME unblocked" 6 40
  491. fi
  492. }
  493. function block_unblock_subject {
  494. select_user
  495. if [ ! $SELECTED_USERNAME ]; then
  496. return
  497. fi
  498. blockstr=$"Block/Unblock email going to"
  499. data=$(tempfile 2>/dev/null)
  500. trap "rm -f $data" 0 1 2 5 15
  501. dialog --backtitle $"Freedombone Control Panel" \
  502. --title "$blockstr $SELECTED_USERNAME" \
  503. --form "\n" 8 70 3 \
  504. $"When email arrives with subject text:" 1 1 "" 1 40 24 28 \
  505. $"Block it:" 2 1 "yes" 2 40 4 4 \
  506. 2> $data
  507. sel=$?
  508. case $sel in
  509. 1) return;;
  510. 255) return;;
  511. esac
  512. BLOCK_SUBJECT=$(cat $data | sed -n 1p)
  513. BLOCK=$(cat $data | sed -n 2p)
  514. if [ ${#BLOCK_SUBJECT} -lt 2 ]; then
  515. dialog --title $"Block/Unblock an email" \
  516. --msgbox $"No subject was given" 6 40
  517. return
  518. fi
  519. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  520. ${PROJECT_NAME}-ignore -u $SELECTED_USERNAME -t "$BLOCK_SUBJECT"
  521. dialog --title $"Block an email" \
  522. --msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME blocked" 6 40
  523. else
  524. ${PROJECT_NAME}-unignore -u $SELECTED_USERNAME -t "$BLOCK_SUBJECT"
  525. dialog --title $"Unblock an email" \
  526. --msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME unblocked" 6 40
  527. fi
  528. }
  529. function create_keydrive_master {
  530. select_user
  531. if [ ! $SELECTED_USERNAME ]; then
  532. return
  533. fi
  534. dialog --title $"USB Master Keydrive" \
  535. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  536. clear
  537. ${PROJECT_NAME}-keydrive -u $SELECTED_USERNAME --master 'yes'
  538. any_key
  539. }
  540. function create_keydrive_fragment {
  541. select_user
  542. if [ ! $SELECTED_USERNAME ]; then
  543. return
  544. fi
  545. dialog --title $"USB Fragment Keydrive" \
  546. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  547. clear
  548. ${PROJECT_NAME}-keydrive -u $SELECTED_USERNAME
  549. any_key
  550. }
  551. function backup_data {
  552. dialog --title $"Backup data to USB" \
  553. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  554. clear
  555. echo ' '
  556. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  557. ${PROJECT_NAME}-backup-local
  558. any_key
  559. }
  560. function restore_from_usb {
  561. while true
  562. do
  563. data=$(tempfile 2>/dev/null)
  564. trap "rm -f $data" 0 1 2 5 15
  565. dialog --backtitle $"Freedombone Control Panel" \
  566. --title $"Restore from USB backup" \
  567. --radiolist $"Choose an application to restore:" 30 70 27 \
  568. 1 $"Everything" on \
  569. 2 $"Return to the backup and restore menu" off \
  570. 3 $"Configuration files" off \
  571. 4 $"MariaDB settings" off \
  572. 5 $"Let's Encrypt account" off \
  573. 6 $"Mutt email client settings" off \
  574. 7 $"GPG keys" off \
  575. 8 $"Email processing rules" off \
  576. 9 $"Spam filtering rules" off \
  577. 10 $"Administrator's README file" off \
  578. 11 $"IPFS" off \
  579. 12 $"SSH keys" off \
  580. 13 $"User configuration files" off \
  581. 14 $"SSL/TLS certificates" off \
  582. 15 $"Personal settings" off \
  583. 16 $"Mailing List" off \
  584. 17 $"XMPP chat" off \
  585. 18 $"GNU Social" off \
  586. 19 $"Hubzilla" off \
  587. 20 $"Owncloud" off \
  588. 21 $"Gogs" off \
  589. 22 $"Wiki" off \
  590. 23 $"Blog" off \
  591. 24 $"CJDNS" off \
  592. 25 $"Email" off \
  593. 26 $"DLNA" off \
  594. 27 $"VoIP" off \
  595. 28 $"Tox" off 2> $data
  596. sel=$?
  597. case $sel in
  598. 1) break;;
  599. 255) break;;
  600. esac
  601. case $(cat $data) in
  602. 1) ${PROJECT_NAME}-restore-local $USB_DRIVE;;
  603. 2) return;;
  604. 3) ${PROJECT_NAME}-restore-local $USB_DRIVE configuration;;
  605. 4) ${PROJECT_NAME}-restore-local $USB_DRIVE mariadb;;
  606. 5) ${PROJECT_NAME}-restore-local $USB_DRIVE letsencrypt;;
  607. 6) ${PROJECT_NAME}-restore-local $USB_DRIVE mutt;;
  608. 7) ${PROJECT_NAME}-restore-local $USB_DRIVE gpg;;
  609. 8) ${PROJECT_NAME}-restore-local $USB_DRIVE procmail;;
  610. 9) ${PROJECT_NAME}-restore-local $USB_DRIVE spamassassin;;
  611. 10) ${PROJECT_NAME}-restore-local $USB_DRIVE readme;;
  612. 11) ${PROJECT_NAME}-restore-local $USB_DRIVE ipfs;;
  613. 12) ${PROJECT_NAME}-restore-local $USB_DRIVE ssh;;
  614. 13) ${PROJECT_NAME}-restore-local $USB_DRIVE userconfig;;
  615. 14) ${PROJECT_NAME}-restore-local $USB_DRIVE certs;;
  616. 15) ${PROJECT_NAME}-restore-local $USB_DRIVE personal;;
  617. 16) ${PROJECT_NAME}-restore-local $USB_DRIVE mailinglist;;
  618. 17) ${PROJECT_NAME}-restore-local $USB_DRIVE xmpp;;
  619. 18) ${PROJECT_NAME}-restore-local $USB_DRIVE gnusocial;;
  620. 19) ${PROJECT_NAME}-restore-local $USB_DRIVE hubzilla;;
  621. 20) ${PROJECT_NAME}-restore-local $USB_DRIVE owncloud;;
  622. 21) ${PROJECT_NAME}-restore-local $USB_DRIVE gogs;;
  623. 22) ${PROJECT_NAME}-restore-local $USB_DRIVE wiki;;
  624. 23) ${PROJECT_NAME}-restore-local $USB_DRIVE blog;;
  625. 24) ${PROJECT_NAME}-restore-local $USB_DRIVE cjdns;;
  626. 25) ${PROJECT_NAME}-restore-local $USB_DRIVE email;;
  627. 26) ${PROJECT_NAME}-restore-local $USB_DRIVE dlna;;
  628. 27) ${PROJECT_NAME}-restore-local $USB_DRIVE voip;;
  629. 28) ${PROJECT_NAME}-restore-local $USB_DRIVE tox;;
  630. esac
  631. done
  632. any_key
  633. }
  634. function restore_from_remote {
  635. remote_domain_name=$1
  636. while true
  637. do
  638. data=$(tempfile 2>/dev/null)
  639. trap "rm -f $data" 0 1 2 5 15
  640. dialog --backtitle $"Freedombone Control Panel" \
  641. --title $"Restore from ${remote_domain_name}" \
  642. --radiolist $"Choose an application to restore:" 30 70 27 \
  643. 1 $"Everything" on \
  644. 2 $"Return to the backup and restore menu" off \
  645. 3 $"Configuration files" off \
  646. 4 $"MariaDB settings" off \
  647. 5 $"Let's Encrypt account" off \
  648. 6 $"Mutt email client settings" off \
  649. 7 $"GPG keys" off \
  650. 8 $"Email processing rules" off \
  651. 9 $"Spam filtering rules" off \
  652. 10 $"Administrator's README file" off \
  653. 11 $"IPFS" off \
  654. 12 $"SSH keys" off \
  655. 13 $"User configuration files" off \
  656. 14 $"SSL/TLS certificates" off \
  657. 15 $"Personal settings" off \
  658. 16 $"Mailing List" off \
  659. 17 $"XMPP chat" off \
  660. 18 $"GNU Social" off \
  661. 19 $"Hubzilla" off \
  662. 20 $"Owncloud" off \
  663. 21 $"Gogs" off \
  664. 22 $"Wiki" off \
  665. 23 $"Blog" off \
  666. 24 $"CJDNS" off \
  667. 25 $"Email" off \
  668. 26 $"DLNA" off \
  669. 27 $"VoIP" off \
  670. 28 $"Tox" off 2> $data
  671. sel=$?
  672. case $sel in
  673. 1) break;;
  674. 255) break;;
  675. esac
  676. case $(cat $data) in
  677. 1) ${PROJECT_NAME}-restore-remote $remote_domain_name;;
  678. 2) return;;
  679. 3) ${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;
  680. 4) ${PROJECT_NAME}-restore-remote $remote_domain_name mariadb;;
  681. 5) ${PROJECT_NAME}-restore-remote $remote_domain_name letsencrypt;;
  682. 6) ${PROJECT_NAME}-restore-remote $remote_domain_name mutt;;
  683. 7) ${PROJECT_NAME}-restore-remote $remote_domain_name gpg;;
  684. 8) ${PROJECT_NAME}-restore-remote $remote_domain_name procmail;;
  685. 9) ${PROJECT_NAME}-restore-remote $remote_domain_name spamassassin;;
  686. 10) ${PROJECT_NAME}-restore-remote $remote_domain_name readme;;
  687. 11) ${PROJECT_NAME}-restore-remote $remote_domain_name ipfs;;
  688. 12) ${PROJECT_NAME}-restore-remote $remote_domain_name ssh;;
  689. 13) ${PROJECT_NAME}-restore-remote $remote_domain_name userconfig;;
  690. 14) ${PROJECT_NAME}-restore-remote $remote_domain_name certs;;
  691. 15) ${PROJECT_NAME}-restore-remote $remote_domain_name personal;;
  692. 16) ${PROJECT_NAME}-restore-remote $remote_domain_name mailinglist;;
  693. 17) ${PROJECT_NAME}-restore-remote $remote_domain_name xmpp;;
  694. 18) ${PROJECT_NAME}-restore-remote $remote_domain_name gnusocial;;
  695. 19) ${PROJECT_NAME}-restore-remote $remote_domain_name hubzilla;;
  696. 20) ${PROJECT_NAME}-restore-remote $remote_domain_name owncloud;;
  697. 21) ${PROJECT_NAME}-restore-remote $remote_domain_name gogs;;
  698. 22) ${PROJECT_NAME}-restore-remote $remote_domain_name wiki;;
  699. 23) ${PROJECT_NAME}-restore-remote $remote_domain_name blog;;
  700. 24) ${PROJECT_NAME}-restore-remote $remote_domain_name cjdns;;
  701. 25) ${PROJECT_NAME}-restore-remote $remote_domain_name email;;
  702. 26) ${PROJECT_NAME}-restore-remote $remote_domain_name dlna;;
  703. 27) ${PROJECT_NAME}-restore-remote $remote_domain_name voip;;
  704. 28) ${PROJECT_NAME}-restore-remote $remote_domain_name tox;;
  705. esac
  706. done
  707. any_key
  708. }
  709. function restore_data {
  710. dialog --title $"Restore data from USB" \
  711. --msgbox $"Plug in your backup USB drive" 6 40
  712. clear
  713. echo ' '
  714. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  715. restore_from_usb
  716. }
  717. function restore_data_remote {
  718. if [ ! $ADMIN_USER ]; then
  719. dialog --title $"Restore data from remote server" \
  720. --msgbox $"Unknown admin user" 6 40
  721. return
  722. fi
  723. data=$(tempfile 2>/dev/null)
  724. trap "rm -f $data" 0 1 2 5 15
  725. dialog --title $"Restore from remote server" \
  726. --backtitle $"Freedombone Control Panel" \
  727. --inputbox $"Enter the domain name of the server from which you wish to restore" 8 60 2>$data
  728. sel=$?
  729. case $sel in
  730. 0)
  731. friend_server_domain_name=$(<$data)
  732. if [ ${#friend_server_domain_name} -lt 2 ]; then
  733. return
  734. fi
  735. if [[ $friend_server_domain_name != *"."* ]]; then
  736. dialog --title $"Remote server domain name" \
  737. --msgbox $"Invalid domain name" 6 40
  738. return
  739. fi
  740. restore_from_remote $friend_server_domain_name
  741. ;;
  742. esac
  743. }
  744. function ping_enable_disable {
  745. ping_str=$"\nDo you want to enable other systems to ping this machine?\n\nPing may be useful for diagnostic purposes, but for added security you may not want to enable it."
  746. enable_ping="no"
  747. dialog --title $"Enable Ping / ICMP" \
  748. --backtitle $"Freedombone Control Panel" \
  749. --defaultno \
  750. --yesno "$ping_str" 10 60
  751. sel=$?
  752. case $sel in
  753. 0) enable_ping="yes";;
  754. 255) return;;
  755. esac
  756. if [[ $enable_ping == "yes" ]]; then
  757. iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
  758. iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  759. echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  760. else
  761. iptables -D INPUT -p icmp --icmp-type echo-request -j ACCEPT
  762. iptables -D OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  763. echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  764. fi
  765. }
  766. function logging_on_off {
  767. logging="no"
  768. dialog --title $"Logging" \
  769. --backtitle $"Freedombone Control Panel" \
  770. --yesno $"\nDo you want to turn logging on?" 7 60
  771. sel=$?
  772. case $sel in
  773. 0) logging="yes";;
  774. 255) return;;
  775. esac
  776. clear
  777. echo ''
  778. echo $'This may take a few seconds. Please wait...'
  779. if [[ $logging == "no" ]]; then
  780. ${PROJECT_NAME}-logging off
  781. else
  782. ${PROJECT_NAME}-logging on
  783. fi
  784. }
  785. function restore_gpg_key {
  786. select_user
  787. if [ ! $SELECTED_USERNAME ]; then
  788. return
  789. fi
  790. restorestr=$"Restore GPG key for user"
  791. dialog --title "$restorestr $SELECTED_USERNAME" \
  792. --msgbox $"Plug in your USB keydrive" 6 40
  793. clear
  794. ${PROJECT_NAME}-recoverkey -u $SELECTED_USERNAME
  795. any_key
  796. }
  797. function security_settings {
  798. ${PROJECT_NAME}-sec
  799. any_key
  800. }
  801. function reset_tripwire {
  802. clear
  803. echo $'Resetting the Tripwire...'
  804. echo ' '
  805. echo '
  806. ' | reset-tripwire
  807. any_key
  808. }
  809. function hubzilla_renew_cert {
  810. dialog --title $"Renew SSL certificate" \
  811. --backtitle $"Freedombone Control Panel" \
  812. --yesno $"\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60
  813. sel=$?
  814. case $sel in
  815. 1) return;;
  816. 255) return;;
  817. esac
  818. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  819. if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs ]; then
  820. dialog --title $"Renew SSL certificate" \
  821. --msgbox $"Hubzilla install directory not found" 6 40
  822. return
  823. fi
  824. ${PROJECT_NAME}-renew-cert -h $HUBZILLA_DOMAIN_NAME -p 'letsencrypt'
  825. if [ ! "$?" = "0" ]; then
  826. any_key
  827. else
  828. dialog --title $"Renew SSL certificate" \
  829. --msgbox $"Hubzilla certificate has been renewed" 6 40
  830. fi
  831. }
  832. function hubzilla_channel_directory_server {
  833. if ! grep -q "Hubzilla domain" $COMPLETION_FILE; then
  834. dialog --title $"Hubzilla channel directory server" \
  835. --msgbox $"Hubzilla is not installed on this system" 6 40
  836. return
  837. fi
  838. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  839. if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs ]; then
  840. dialog --title $"Hubzilla channel directory server" \
  841. --msgbox $"Hubzilla install directory not found" 6 40
  842. return
  843. fi
  844. data=$(tempfile 2>/dev/null)
  845. trap "rm -f $data" 0 1 2 5 15
  846. dialog --title $"Hubzilla channel directory server" \
  847. --backtitle $"Freedombone Control Panel" \
  848. --inputbox $"When you click on 'channel directory' this is where Hubzilla will obtain its list from" 8 60 2>$data
  849. sel=$?
  850. case $sel in
  851. 0)
  852. hubzilla_domain_server=$(<$data)
  853. if [[ $hubzilla_domain_server != *"."* ]]; then
  854. return
  855. fi
  856. if [[ $hubzilla_domain_server != "https"* ]]; then
  857. dialog --title $"Hubzilla channel directory server" \
  858. --msgbox $"Invalid domain - include the https://" 6 40
  859. return
  860. fi
  861. ./var/www/$HUBZILLA_DOMAIN_NAME/htdocs/util/config system directory_server $hubzilla_domain_server
  862. dialog --title $"Hubzilla channel directory server" \
  863. --msgbox $"Domain channel directory server changed to $hubzilla_domain_server" 6 40
  864. ;;
  865. esac
  866. }
  867. function format_drive {
  868. drive=
  869. data=$(tempfile 2>/dev/null)
  870. trap "rm -f $data" 0 1 2 5 15
  871. dialog --backtitle $"Freedombone Control Panel" \
  872. --title $"Format a USB drive (LUKS encrypted)" \
  873. --radiolist $"Choose a drive:" 12 70 5 \
  874. 1 $"sda (Beaglebone Black)" off \
  875. 2 $"sdb" off \
  876. 3 $"sdc" off \
  877. 4 $"sdd" off \
  878. 5 $"Back to Backup and Restore menu" on 2> $data
  879. sel=$?
  880. case $sel in
  881. 1) return;;
  882. 255) return;;
  883. esac
  884. case $(cat $data) in
  885. 1) drive='sda';;
  886. 2) drive='sdb';;
  887. 3) drive='sdc';;
  888. 4) drive='sdd';;
  889. 5) return;;
  890. esac
  891. dialog --title $"Format USB drive" \
  892. --backtitle $"Freedombone Control Panel" \
  893. --defaultno \
  894. --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
  895. sel=$?
  896. case $sel in
  897. 1) return;;
  898. 255) return;;
  899. esac
  900. clear
  901. ${PROJECT_NAME}-format $drive
  902. any_key
  903. }
  904. function remove_backups {
  905. drive=
  906. data=$(tempfile 2>/dev/null)
  907. trap "rm -f $data" 0 1 2 5 15
  908. dialog --backtitle $"Freedombone Control Panel" \
  909. --title $"Remove backups from a USB drive" \
  910. --radiolist $"Choose a drive:" 12 70 5 \
  911. 1 $"sda (Beaglebone Black)" off \
  912. 2 $"sdb" off \
  913. 3 $"sdc" off \
  914. 4 $"sdd" off \
  915. 5 $"Back to Backup and Restore menu" on 2> $data
  916. sel=$?
  917. case $sel in
  918. 1) return;;
  919. 255) return;;
  920. esac
  921. case $(cat $data) in
  922. 1) drive='sda';;
  923. 2) drive='sdb';;
  924. 3) drive='sdc';;
  925. 4) drive='sdd';;
  926. 5) return;;
  927. esac
  928. dialog --title $"Remove backups from a USB drive" \
  929. --backtitle $"Freedombone Control Panel" \
  930. --defaultno \
  931. --yesno $"\nPlease confirm that you wish to remove backups from this drive\n\n ${drive}\n\nYou will not be able to recover them afterwards." 12 60
  932. sel=$?
  933. case $sel in
  934. 1) return;;
  935. 255) return;;
  936. esac
  937. clear
  938. ${PROJECT_NAME}-backup-local $drive remove
  939. any_key
  940. }
  941. function shut_down_system {
  942. dialog --title $"Power off the system" \
  943. --backtitle $"Freedombone Control Panel" \
  944. --defaultno \
  945. --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
  946. sel=$?
  947. case $sel in
  948. 1) return;;
  949. 255) return;;
  950. esac
  951. shutdown now
  952. }
  953. function restart_system {
  954. dialog --title $"Restart the system" \
  955. --backtitle $"Freedombone Control Panel" \
  956. --defaultno \
  957. --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
  958. sel=$?
  959. case $sel in
  960. 1) return;;
  961. 255) return;;
  962. esac
  963. reboot
  964. }
  965. function change_system_name {
  966. data=$(tempfile 2>/dev/null)
  967. trap "rm -f $data" 0 1 2 5 15
  968. dialog --title $"Change the name of this system" \
  969. --backtitle $"Freedombone Control Panel" \
  970. --inputbox $'Enter a new name for this system on your local network\n\nIt will appear as newname.local' 10 60 2>$data
  971. sel=$?
  972. case $sel in
  973. 0) NEW_SYSTEM_NAME=$(<$data)
  974. if [ "$NEW_SYSTEM_NAME" ]; then
  975. if [ ${#NEW_SYSTEM_NAME} -gt 1 ]; then
  976. sed -i "s|host-name=.*|host-name=$NEW_SYSTEM_NAME|g" /etc/avahi/avahi-daemon.conf
  977. systemctl restart avahi-daemon
  978. if grep -q "host-name=$NEW_SYSTEM_NAME" /etc/avahi/avahi-daemon.conf; then
  979. dialog --title $"New local network name" \
  980. --msgbox $"The name of this system on your local network was changed successfully" 6 70
  981. fi
  982. fi
  983. fi
  984. ;;
  985. esac
  986. }
  987. function set_tls_time_source {
  988. TLS_DATE_SOURCE=$(cat /usr/bin/updatedate | grep "TIMESOURCE='" | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
  989. data=$(tempfile 2>/dev/null)
  990. trap "rm -f $data" 0 1 2 5 15
  991. dialog --title $"Set the TLS date/time source" \
  992. --backtitle $"Freedombone Control Panel" \
  993. --inputbox $"Enter a domain name to use as a TLS time source.\n\nFactors to consider when choosing a source are whether you wish that site to know that your system is 'alive' and also what might happen if an adversary were to try to mess with the date/time from that domain (i.e. how much blowback would there be)." 14 60 "$TLS_DATE_SOURCE" 2>$data
  994. sel=$?
  995. case $sel in
  996. 0) NEW_TLS_DATE_SOURCE=$(<$data)
  997. if [[ $NEW_TLS_DATE_SOURCE == *"."* && $NEW_TLS_DATE_SOURCE != *'/'* ]]; then
  998. if [[ $NEW_TLS_DATE_SOURCE != "http"* ]]; then
  999. sed -i "s|TIMESOURCE='.*|TIMESOURCE='${NEW_TLS_DATE_SOURCE}'|g" $UPDATE_DATE_SCRIPT
  1000. else
  1001. dialog --title $"Invalid domain name" \
  1002. --msgbox $"Don't include the 'https'" 6 70
  1003. fi
  1004. else
  1005. dialog --title $"Invalid domain name" \
  1006. --msgbox $"That doesn't look like a domain name" 6 70
  1007. fi
  1008. ;;
  1009. esac
  1010. }
  1011. function set_static_IP {
  1012. STATIC_IP='192.168.1.60'
  1013. STATIC_GATEWAY='192.168.1.1'
  1014. NEW_STATIC_IP=
  1015. NEW_STATIC_GATEWAY=
  1016. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1017. STATIC_IP=$(cat /etc/network/interfaces | grep "address " | awk -F ' ' '{print $2}' | head -n 1)
  1018. STATIC_GATEWAY=$(cat /etc/network/interfaces | grep "gateway " | awk -F ' ' '{print $2}' | head -n 1)
  1019. fi
  1020. # get the IP for the box
  1021. data=$(tempfile 2>/dev/null)
  1022. trap "rm -f $data" 0 1 2 5 15
  1023. dialog --title $"Set a static local IP address" \
  1024. --backtitle $"Freedombone Control Panel" \
  1025. --inputbox $"In order to forward incoming internet traffic to this system most internet routers need to know a static local IP address to send the data to.\n\n
  1026. Enter a static local IP address for this system.\n\nIt will typically be 192.168.1.x" 15 60 "$STATIC_IP" 2>$data
  1027. sel=$?
  1028. case $sel in
  1029. 0) NEW_STATIC_IP=$(<$data)
  1030. if [[ "$NEW_STATIC_IP" != *"."* ]]; then
  1031. return
  1032. fi
  1033. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1034. if [[ "$NEW_STATIC_IP" != "$STATIC_IP" ]]; then
  1035. sed -i "s|${STATIC_IP}|${NEW_STATIC_IP}|g" /etc/network/interfaces
  1036. fi
  1037. fi
  1038. ;;
  1039. esac
  1040. # get the gateway
  1041. data=$(tempfile 2>/dev/null)
  1042. trap "rm -f $data" 0 1 2 5 15
  1043. dialog --title $"Set the IP address of your internet router/modem" \
  1044. --backtitle $"Freedombone Control Panel" \
  1045. --inputbox $"Set the local IP address for your internet router or ADSL modem.\n\nIt will typically be 192.168.1.1, 192.168.1.254, or similar" 12 60 "$STATIC_GATEWAY" 2>$data
  1046. sel=$?
  1047. case $sel in
  1048. 0) NEW_STATIC_GATEWAY=$(<$data)
  1049. if [[ "$NEW_STATIC_GATEWAY" != *"."* ]]; then
  1050. return
  1051. fi
  1052. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1053. if [[ "$NEW_STATIC_GATEWAY" != "$STATIC_GATEWAY" ]]; then
  1054. sed -i "s|${STATIC_GATEWAY}|${NEW_STATIC_GATEWAY}|g" /etc/network/interfaces
  1055. fi
  1056. return
  1057. fi
  1058. ;;
  1059. esac
  1060. if ! grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1061. if [ "$NEW_STATIC_GATEWAY" && "$NEW_STATIC_IP" ]; then
  1062. echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
  1063. echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
  1064. echo '' >> /etc/network/interfaces
  1065. echo '# The loopback network interface' >> /etc/network/interfaces
  1066. echo 'auto lo' >> /etc/network/interfaces
  1067. echo 'iface lo inet loopback' >> /etc/network/interfaces
  1068. echo '' >> /etc/network/interfaces
  1069. echo '# The primary network interface' >> /etc/network/interfaces
  1070. echo 'auto eth0' >> /etc/network/interfaces
  1071. echo 'iface eth0 inet static' >> /etc/network/interfaces
  1072. echo " address ${NEW_STATIC_IP}" >> /etc/network/interfaces
  1073. echo ' netmask 255.255.255.0' >> /etc/network/interfaces
  1074. echo " gateway ${NEW_STATIC_GATEWAY}" >> /etc/network/interfaces
  1075. echo " dns-nameservers 213.73.91.35 85.214.20.141" >> /etc/network/interfaces
  1076. echo '# Example to keep MAC address between reboots' >> /etc/network/interfaces
  1077. echo '#hwaddress ether DE:AD:BE:EF:CA:FE' >> /etc/network/interfaces
  1078. echo '' >> /etc/network/interfaces
  1079. echo '# The secondary network interface' >> /etc/network/interfaces
  1080. echo '#auto eth1' >> /etc/network/interfaces
  1081. echo '#iface eth1 inet dhcp' >> /etc/network/interfaces
  1082. echo '' >> /etc/network/interfaces
  1083. echo '# WiFi Example' >> /etc/network/interfaces
  1084. echo "#auto $WIFI_INTERFACE" >> /etc/network/interfaces
  1085. echo "#iface $WIFI_INTERFACE inet dhcp" >> /etc/network/interfaces
  1086. echo '# wpa-ssid "essid"' >> /etc/network/interfaces
  1087. echo '# wpa-psk "password"' >> /etc/network/interfaces
  1088. echo '' >> /etc/network/interfaces
  1089. echo '# Ethernet/RNDIS gadget (g_ether)' >> /etc/network/interfaces
  1090. echo '# ... or on host side, usbnet and random hwaddr' >> /etc/network/interfaces
  1091. echo '# Note on some boards, usb0 is automaticly setup with an init script' >> /etc/network/interfaces
  1092. echo '#iface usb0 inet static' >> /etc/network/interfaces
  1093. echo '# address 192.168.7.2' >> /etc/network/interfaces
  1094. echo '# netmask 255.255.255.0' >> /etc/network/interfaces
  1095. echo '# network 192.168.7.0' >> /etc/network/interfaces
  1096. echo '# gateway 192.168.7.1' >> /etc/network/interfaces
  1097. fi
  1098. fi
  1099. }
  1100. function menu_backup_restore {
  1101. while true
  1102. do
  1103. data=$(tempfile 2>/dev/null)
  1104. trap "rm -f $data" 0 1 2 5 15
  1105. dialog --backtitle $"Freedombone Control Panel" \
  1106. --title $"Backup and Restore" \
  1107. --radiolist $"Choose an operation:" 18 70 11 \
  1108. 1 $"Backup data to USB drive" off \
  1109. 2 $"Restore GPG key from USB keydrive" off \
  1110. 3 $"Restore data from USB drive" off \
  1111. 4 $"Configure remote backups" off \
  1112. 5 $"Restore from remote backup" off \
  1113. 6 $"Backup GPG key to USB (master keydrive)" off \
  1114. 7 $"Backup GPG key to USB (fragment keydrive)" off \
  1115. 8 $"Format a USB drive (LUKS encrypted)" off \
  1116. 9 $"Remove backups from a USB drive" off \
  1117. 10 $"Back to main menu" on 2> $data
  1118. sel=$?
  1119. case $sel in
  1120. 1) break;;
  1121. 255) break;;
  1122. esac
  1123. case $(cat $data) in
  1124. 1) backup_data;;
  1125. 2) restore_gpg_key;;
  1126. 3) restore_data;;
  1127. 4) configure_remote_backups;;
  1128. 5) restore_data_remote;;
  1129. 6) create_keydrive_master;;
  1130. 7) create_keydrive_fragment;;
  1131. 8) format_drive;;
  1132. 9) remove_backups;;
  1133. 10) break;;
  1134. esac
  1135. done
  1136. }
  1137. function menu_email {
  1138. while true
  1139. do
  1140. data=$(tempfile 2>/dev/null)
  1141. trap "rm -f $data" 0 1 2 5 15
  1142. dialog --backtitle $"Freedombone Control Panel" \
  1143. --title $"Email Filtering Rules" \
  1144. --radiolist $"Choose an operation:" 12 70 5 \
  1145. 1 $"Add a user to a mailing list" off \
  1146. 2 $"Add an email rule" off \
  1147. 3 $"Block/Unblock an email address" off \
  1148. 4 $"Block/Unblock email with subject text" off \
  1149. 5 $"Back to main menu" on 2> $data
  1150. sel=$?
  1151. case $sel in
  1152. 1) break;;
  1153. 255) break;;
  1154. esac
  1155. case $(cat $data) in
  1156. 1) add_to_mailing_list;;
  1157. 2) email_rule;;
  1158. 3) block_unblock_email;;
  1159. 4) block_unblock_subject;;
  1160. 5) break;;
  1161. esac
  1162. done
  1163. }
  1164. function menu_users {
  1165. while true
  1166. do
  1167. data=$(tempfile 2>/dev/null)
  1168. trap "rm -f $data" 0 1 2 5 15
  1169. dialog --backtitle $"Freedombone Control Panel" \
  1170. --title $"Manage Users" \
  1171. --radiolist $"Choose an operation:" 12 70 5 \
  1172. 1 $"Add a user" off \
  1173. 2 $"Delete a user" off \
  1174. 3 $"Change user password" off \
  1175. 4 $"Change user ssh public key" off \
  1176. 5 $"Back to main menu" on 2> $data
  1177. sel=$?
  1178. case $sel in
  1179. 1) break;;
  1180. 255) break;;
  1181. esac
  1182. case $(cat $data) in
  1183. 1) add_user;;
  1184. 2) delete_user;;
  1185. 3) change_password;;
  1186. 4) change_ssh_public_key;;
  1187. 5) break;;
  1188. esac
  1189. done
  1190. }
  1191. function menu_hubzilla {
  1192. while true
  1193. do
  1194. data=$(tempfile 2>/dev/null)
  1195. trap "rm -f $data" 0 1 2 5 15
  1196. dialog --backtitle $"Freedombone Control Panel" \
  1197. --title $"Hubzilla" \
  1198. --radiolist $"Choose an operation:" 13 70 4 \
  1199. 1 $"Set channel directory server" off \
  1200. 2 $"Renew SSL certificate" off \
  1201. 3 $"Back to main menu" on 2> $data
  1202. sel=$?
  1203. case $sel in
  1204. 1) break;;
  1205. 255) break;;
  1206. esac
  1207. case $(cat $data) in
  1208. 1) hubzilla_channel_directory_server;;
  1209. 2) hubzilla_renew_cert;;
  1210. 3) break;;
  1211. esac
  1212. done
  1213. }
  1214. function menu_media {
  1215. while true
  1216. do
  1217. data=$(tempfile 2>/dev/null)
  1218. trap "rm -f $data" 0 1 2 5 15
  1219. dialog --backtitle $"Freedombone Control Panel" \
  1220. --title $"Media Menu" \
  1221. --radiolist $"Choose an operation:" 13 70 3 \
  1222. 1 $"Attach a drive containing playable media" off \
  1223. 2 $"Remove a drive containing playable media" off \
  1224. 3 $"Exit" on 2> $data
  1225. sel=$?
  1226. case $sel in
  1227. 1) break;;
  1228. 255) break;;
  1229. esac
  1230. case $(cat $data) in
  1231. 1) remove-music
  1232. attach-music;;
  1233. 2) remove-music;;
  1234. 3) break;;
  1235. esac
  1236. done
  1237. }
  1238. function menu_irc {
  1239. while true
  1240. do
  1241. data=$(tempfile 2>/dev/null)
  1242. trap "rm -f $data" 0 1 2 5 15
  1243. dialog --backtitle $"Freedombone Control Panel" \
  1244. --title $"IRC Menu" \
  1245. --radiolist $"Choose an operation:" 13 70 3 \
  1246. 1 $"Set a password for all IRC users" off \
  1247. 2 $"Exit" on 2> $data
  1248. sel=$?
  1249. case $sel in
  1250. 1) break;;
  1251. 255) break;;
  1252. esac
  1253. case $(cat $data) in
  1254. 1) irc_set_global_password;;
  1255. 2) break;;
  1256. esac
  1257. done
  1258. }
  1259. function menu_top_level {
  1260. while true
  1261. do
  1262. data=$(tempfile 2>/dev/null)
  1263. trap "rm -f $data" 0 1 2 5 15
  1264. dialog --backtitle $"Freedombone Control Panel" \
  1265. --title $"Control Panel" \
  1266. --radiolist $"Choose an operation:" 25 70 18 \
  1267. 1 $"Backup and Restore" off \
  1268. 2 $"About this system" off \
  1269. 3 $"Reset Tripwire" off \
  1270. 4 $"Logging on/off" off \
  1271. 5 $"Ping enable/disable" off \
  1272. 6 $"Manage Users" off \
  1273. 7 $"Email Filtering Rules" off \
  1274. 8 $"Security Settings" off \
  1275. 9 $"Hubzilla" off \
  1276. 10 $"Media menu" off \
  1277. 11 $"IRC menu" off \
  1278. 12 $"Change the name of this system" off \
  1279. 13 $"Set the TLS date/time source" off \
  1280. 14 $"Set a static local IP address" off \
  1281. 15 $"Check for updates" off \
  1282. 16 $"Power off the system" off \
  1283. 17 $"Restart the system" off \
  1284. 18 $"Exit" on 2> $data
  1285. sel=$?
  1286. case $sel in
  1287. 1) exit 1;;
  1288. 255) exit 1;;
  1289. esac
  1290. case $(cat $data) in
  1291. 1) menu_backup_restore;;
  1292. 2) show_about;;
  1293. 3) reset_tripwire;;
  1294. 4) logging_on_off;;
  1295. 5) ping_enable_disable;;
  1296. 6) menu_users;;
  1297. 7) menu_email;;
  1298. 8) security_settings;;
  1299. 9) menu_hubzilla;;
  1300. 10) menu_media;;
  1301. 11) menu_irc;;
  1302. 12) change_system_name;;
  1303. 13) set_tls_time_source;;
  1304. 14) set_static_IP;;
  1305. 15) check_for_updates;;
  1306. 16) shut_down_system;;
  1307. 17) restart_system;;
  1308. 18) break;;
  1309. esac
  1310. done
  1311. }
  1312. if [ ! -f $COMPLETION_FILE ]; then
  1313. echo $'This command should only be run on an installed Freedombone system'
  1314. exit 1
  1315. fi
  1316. ADMIN_USER=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  1317. menu_top_level
  1318. clear
  1319. cat /etc/motd
  1320. exit 0