freedombone-controlpanel 61KB

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