freedombone-controlpanel 63KB

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