freedombone-controlpanel 49KB

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