freedombone-controlpanel 66KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  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@freedombone.net>
  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. UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
  34. for f in $UTILS_FILES
  35. do
  36. source $f
  37. done
  38. APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
  39. for f in $APP_FILES
  40. do
  41. source $f
  42. done
  43. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  44. SELECTED_USERNAME=
  45. SIP_CONFIGURATION_FILE=/etc/sipwitch.conf
  46. ADMIN_USER=
  47. UPGRADE_SCRIPT_NAME="${PROJECT_NAME}-upgrade"
  48. UPDATE_DATE_SCRIPT=/usr/bin/updatedate
  49. # Minimum number of characters in a password
  50. MINIMUM_PASSWORD_LENGTH=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords | grep 'MINIMUM_PASSWORD_LENGTH=' | head -n 1 | awk -F '=' '{print $2}')
  51. # Mumble
  52. MUMBLE_PORT=64738
  53. MUMBLE_ONION_PORT=8095
  54. SSH_PORT=2222
  55. # outgoing SMTP proxy
  56. SMTP_PROXY_ENABLE=$'no'
  57. SMTP_PROXY_PROTOCOL='smtps'
  58. SMTP_PROXY_SERVER='mail.myispdomain'
  59. SMTP_PROXY_PORT=465
  60. SMTP_PROXY_USERNAME=''
  61. SMTP_PROXY_PASSWORD=''
  62. WIFI_INTERFACE=wlan0
  63. WIFI_SSID=
  64. WIFI_TYPE='wpa2-psk'
  65. WIFI_PASSPHRASE=
  66. WIFI_HOTSPOT='no'
  67. WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
  68. USB_DRIVE=sdb
  69. # get default USB from config file
  70. CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
  71. read_config_param WIFI_HOTSPOT
  72. read_config_param WIFI_INTERFACE
  73. read_config_param WIFI_TYPE
  74. read_config_param WIFI_SSID
  75. read_config_param WIFI_PASSPHRASE
  76. read_config_param SSH_PORT
  77. read_config_param SMTP_PROXY_ENABLE
  78. read_config_param SMTP_PROXY_PROTOCOL
  79. read_config_param SMTP_PROXY_SERVER
  80. read_config_param SMTP_PROXY_PORT
  81. read_config_param SMTP_PROXY_USERNAME
  82. read_config_param SMTP_PROXY_PASSWORD
  83. read_config_param USB_DRIVE
  84. if [[ $USB_DRIVE == *"dev"* ]]; then
  85. USB_DRIVE=$(echo ${USB_DRIVE} | awk -F '/' '{print $3}' | sed 's|1||g' | sed 's|2||g')
  86. fi
  87. # Mirrors settings
  88. FRIENDS_MIRRORS_SERVER=
  89. FRIENDS_MIRRORS_SSH_PORT=2222
  90. FRIENDS_MIRRORS_PASSWORD=
  91. MY_MIRRORS_PASSWORD=
  92. function any_key {
  93. echo ' '
  94. read -n1 -r -p $"Press any key to continue..." key
  95. }
  96. function get_app_icann_address {
  97. app_name="$1"
  98. if grep -q "${app_name} domain" $COMPLETION_FILE; then
  99. echo $(cat ${COMPLETION_FILE} | grep "${app_name} domain" | head -n 1 | awk -F ':' '{print $2}')
  100. return
  101. fi
  102. echo "${DEFAULT_DOMAIN_NAME}"
  103. }
  104. function passwords_select_user {
  105. SELECTED_USERNAME=
  106. users_array=($(ls /home))
  107. delete=(mirrors git)
  108. for del in ${delete[@]}
  109. do
  110. users_array=(${users_array[@]/$del})
  111. done
  112. i=0
  113. W=()
  114. name=()
  115. for u in ${users_array[@]}
  116. do
  117. if [[ $(is_valid_user "$u") == "1" ]]; then
  118. i=$((i+1))
  119. W+=($i "$u")
  120. name+=("$u")
  121. fi
  122. done
  123. if [ $i -eq 1 ]; then
  124. SELECTED_USERNAME="${name[0]}"
  125. else
  126. 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)
  127. if [ $? -eq 0 ]; then
  128. SELECTED_USERNAME="${name[$((user_index-1))]}"
  129. fi
  130. fi
  131. }
  132. function passwords_show_apps {
  133. SELECTED_APP=
  134. i=0
  135. W=()
  136. name=()
  137. for a in "${APPS_AVAILABLE[@]}"
  138. do
  139. if [[ $(function_exists change_password_${a}) == "1" ]]; then
  140. i=$((i+1))
  141. W+=($i "$a")
  142. name+=("$a")
  143. fi
  144. done
  145. selected_app_index=$(dialog --backtitle $"Freedombone Control Panel" --title $"Select App" --menu $"Select one of the following:" 24 40 17 "${W[@]}" 3>&2 2>&1 1>&3)
  146. if [ $? -eq 0 ]; then
  147. SELECTED_APP="${name[$((selected_app_index-1))]}"
  148. fi
  149. }
  150. function reset_password_tries {
  151. passwords_select_user
  152. if [ ! $SELECTED_USERNAME ]; then
  153. return
  154. fi
  155. pam_tally --user $SELECTED_USERNAME --reset
  156. dialog --title $"Reset password tries" \
  157. --msgbox $"Password tries have been reset for $SELECTED_USERNAME" 6 60
  158. }
  159. function view_or_change_passwords {
  160. passwords_select_user
  161. if [ ! $SELECTED_USERNAME ]; then
  162. return
  163. fi
  164. detect_installed_apps
  165. passwords_show_apps
  166. if [ ! $SELECTED_APP ]; then
  167. return
  168. fi
  169. CURR_PASSWORD=$(${PROJECT_NAME}-pass -u ${SELECTED_USERNAME} -a ${SELECTED_APP})
  170. icann_address=$(get_app_icann_address "$app_name")
  171. onion_address=$(get_app_onion_address "${SELECTED_APP}")
  172. titlestr=$"View or Change Password"
  173. if [ ${#onion_address} -gt 0 ]; then
  174. viewstr=$"${SELECTED_APP} password for ${SELECTED_USERNAME} on $icann_address or $onion_address\n\nCopy or change it if you wish."
  175. else
  176. viewstr=$"${SELECTED_APP} password for ${SELECTED_USERNAME} on $icann_address\n\nCopy or change it if you wish."
  177. fi
  178. if [ -f /root/.nostore ]; then
  179. titlestr=$"Change Password"
  180. if [ ${#onion_address} -gt 0 ]; then
  181. viewstr=$"Change the ${SELECTED_APP} password for ${SELECTED_USERNAME} on $icann_address or $onion_address."
  182. else
  183. viewstr=$"Change the ${SELECTED_APP} password for ${SELECTED_USERNAME} on $icann_address."
  184. fi
  185. fi
  186. data=$(tempfile 2>/dev/null)
  187. trap "rm -f $data" 0 1 2 5 15
  188. dialog --title "$titlestr" \
  189. --backtitle $"Freedombone Control Panel" \
  190. --inputbox "$viewstr" 12 60 "$CURR_PASSWORD" 2>$data
  191. sel=$?
  192. case $sel in
  193. 0)
  194. CURR_PASSWORD=$(<$data)
  195. if [ ${#CURR_PASSWORD} -gt 8 ]; then
  196. ${PROJECT_NAME}-pass -u ${SELECTED_USERNAME} -a ${SELECTED_APP} -p "${CURR_PASSWORD}"
  197. change_password_${SELECTED_APP} ${SELECTED_USERNAME} "${CURR_PASSWORD}"
  198. dialog --title $"Change password" \
  199. --msgbox $"The password was changed" 6 40
  200. fi
  201. ;;
  202. esac
  203. }
  204. function check_for_updates {
  205. if [ ! -f /etc/cron.weekly/$UPGRADE_SCRIPT_NAME ]; then
  206. dialog --title $"Check for updates" \
  207. --msgbox $"Upgrade script was not found" 6 40
  208. return
  209. fi
  210. clear
  211. . /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
  212. any_key
  213. }
  214. function set_main_repo {
  215. data=$(tempfile 2>/dev/null)
  216. trap "rm -f $data" 0 1 2 5 15
  217. dialog --backtitle $"Freedombone Control Panel" \
  218. --title $"Main Repository (Mirrors)" \
  219. --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 \
  220. $"URL:" 1 1 "$FRIENDS_MIRRORS_SERVER" 1 14 40 15 \
  221. $"SSH Port:" 2 1 "$FRIENDS_MIRRORS_SSH_PORT" 2 14 40 10000 \
  222. $"Password:" 3 1 "$FRIENDS_MIRRORS_PASSWORD" 3 14 40 10000 \
  223. 2> $data
  224. sel=$?
  225. case $sel in
  226. 1) return;;
  227. 255) return;;
  228. esac
  229. new_mirrors_url=$(cat $data | sed -n 1p)
  230. new_mirrors_ssh_port=$(cat $data | sed -n 2p)
  231. new_mirrors_password=$(cat $data | sed -n 3p)
  232. if [ ${#new_mirrors_url} -lt 2 ]; then
  233. return
  234. fi
  235. if [ ${#new_mirrors_ssh_port} -lt 1 ]; then
  236. return
  237. fi
  238. if [ ${#new_mirrors_password} -lt 10 ]; then
  239. dialog --title $"Main Repository" \
  240. --msgbox $'Mirrors password was too short. Should be at least 10 characters.' 6 40
  241. return
  242. fi
  243. if [[ $new_mirrors_url == *"."* ]]; then
  244. FRIENDS_MIRRORS_SERVER=$new_mirrors_url
  245. FRIENDS_MIRRORS_SSH_PORT=$new_mirrors_ssh_port
  246. FRIENDS_MIRRORS_PASSWORD=$new_mirrors_password
  247. write_config_param "FRIENDS_MIRRORS_SERVER" "$FRIENDS_MIRRORS_SERVER"
  248. write_config_param "FRIENDS_MIRRORS_SSH_PORT" "$FRIENDS_MIRRORS_SSH_PORT"
  249. write_config_param "FRIENDS_MIRRORS_PASSWORD" "$FRIENDS_MIRRORS_PASSWORD"
  250. # re-read the repos
  251. read_repo_servers
  252. dialog --title $"Main Repository" \
  253. --msgbox $"Main repository set to $FRIENDS_MIRRORS_SERVER" 6 60
  254. fi
  255. }
  256. function add_user {
  257. data=$(tempfile 2>/dev/null)
  258. trap "rm -f $data" 0 1 2 5 15
  259. dialog --backtitle $"Freedombone Control Panel" \
  260. --title $"Add new user" \
  261. --form "\n" 8 60 3 \
  262. $"Username:" 1 1 "" 1 28 16 15 \
  263. $"ssh public key (optional):" 2 1 "" 2 28 40 10000 \
  264. 2> $data
  265. sel=$?
  266. case $sel in
  267. 1) return;;
  268. 255) return;;
  269. esac
  270. new_user_username=$(cat $data | sed -n 1p)
  271. new_user_ssh_public_key=$(cat $data | sed -n 2p)
  272. if [ ${#new_user_username} -lt 2 ]; then
  273. dialog --title $"New username" \
  274. --msgbox $"No username was given" 6 40
  275. return
  276. fi
  277. if [[ "$new_user_username" == *" "* ]]; then
  278. dialog --title $"Invalid username" \
  279. --msgbox $"The username should not contain any spaces" 6 40
  280. return
  281. fi
  282. if [ ${#new_user_ssh_public_key} -lt 20 ]; then
  283. clear
  284. ${PROJECT_NAME}-adduser "$new_user_username"
  285. any_key
  286. else
  287. if [[ "$new_user_ssh_public_key" == "ssh-"* ]]; then
  288. clear
  289. ${PROJECT_NAME}-adduser "$new_user_username" "$new_user_ssh_public_key"
  290. any_key
  291. else
  292. dialog --title $"ssh public key" \
  293. --msgbox $"This does not look like an ssh public key" 6 40
  294. fi
  295. fi
  296. }
  297. function pad_string {
  298. echo -n -e "$1" | sed -e :a -e 's/^.\{1,25\}$/& /;ta'
  299. }
  300. function show_domains {
  301. read_config_param "DEFAULT_DOMAIN_NAME"
  302. echo 'Domains'
  303. echo '======='
  304. echo ''
  305. echo -n -e "$(pad_string 'Name')"
  306. echo -n -e "$(pad_string 'ICANN')"
  307. echo -n -e "$(pad_string 'Tor')"
  308. echo ''
  309. echo '--------------------------------------------------------------------------'
  310. if grep -q "ssh onion domain" $COMPLETION_FILE; then
  311. echo -n -e "$(pad_string 'ssh')"
  312. echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
  313. echo "$(cat ${COMPLETION_FILE} | grep 'ssh onion domain' | awk -F ':' '{print $2}')"
  314. fi
  315. if grep -q "email onion domain" $COMPLETION_FILE; then
  316. echo -n -e "$(pad_string 'Email')"
  317. echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
  318. echo "$(cat ${COMPLETION_FILE} | grep 'email onion domain' | awk -F ':' '{print $2}')"
  319. fi
  320. for app_name in "${APPS_INSTALLED_NAMES[@]}"
  321. do
  322. if ! grep -q "SHOW_ON_ABOUT=1" /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}; then
  323. continue
  324. fi
  325. # handle the foibles of capitalisation
  326. if ! grep -q "${app_name} domain" $COMPLETION_FILE; then
  327. app_name_upper=$(echo ${app_name} | awk '{print toupper($0)}')
  328. if grep -q "${app_name_upper} domain" $COMPLETION_FILE; then
  329. app_name=${app_name_upper}
  330. else
  331. app_name_first_upper="$(tr '[:lower:]' '[:upper:]' <<< ${app_name:0:1})${app_name:1}"
  332. if grep -q "${app_name_first_upper} domain" $COMPLETION_FILE; then
  333. app_name=${app_name_first_upper}
  334. fi
  335. fi
  336. fi
  337. if [ ${#app_name} -gt 0 ]; then
  338. icann_address=$(get_app_icann_address "$app_name")
  339. onion_address=$(get_app_onion_address "$app_name")
  340. if [ ${#onion_address} -eq 0 ]; then
  341. onion_address="-"
  342. fi
  343. echo -n -e "$(pad_string "${app_name}")"
  344. echo -n -e "$(pad_string "${icann_address}")"
  345. echo "${onion_address}"
  346. if grep -q "${app_name}_mobile onion domain" $COMPLETION_FILE; then
  347. onion_address=$(get_app_onion_address "${app_name}" "mobile")
  348. echo -n -e "$(pad_string "${app_name} (mobile)")"
  349. echo -n -e "$(pad_string "${icann_address}")"
  350. echo "${onion_address}"
  351. fi
  352. fi
  353. done
  354. if grep -q "rss reader domain" $COMPLETION_FILE; then
  355. if [ -d /var/lib/tor/hidden_service_ttrss ]; then
  356. echo -n -e "$(pad_string 'RSS reader')"
  357. RSSDOM='-'
  358. echo -n -e "$(pad_string ${RSSDOM})"
  359. echo -n "$(cat /var/lib/tor/hidden_service_ttrss/hostname)"
  360. echo ''
  361. fi
  362. if [ -d /var/lib/tor/hidden_service_ttrss_mobile ]; then
  363. echo -n -e "$(pad_string 'RSS mobile')"
  364. RSSMOBILEDOM='-'
  365. echo -n -e "$(pad_string ${RSSMOBILEDOM})"
  366. echo -n "$(cat /var/lib/tor/hidden_service_ttrss_mobile/hostname)"
  367. echo ''
  368. fi
  369. fi
  370. echo ''
  371. }
  372. function show_users {
  373. echo 'Users'
  374. echo '====='
  375. echo ''
  376. echo -n -e "$(pad_string 'Name')"
  377. if [[ $(app_is_installed sip) == "1" ]]; then
  378. echo -n -e "$(pad_string 'SIP ext')"
  379. fi
  380. echo -n -e "$(pad_string 'Data')"
  381. echo ''
  382. echo '----------------------------------'
  383. for d in /home/*/ ; do
  384. USRNAME=$(echo "$d" | awk -F '/' '{print $3}')
  385. if [[ $(is_valid_user "$USRNAME") == "1" ]]; then
  386. echo -n -e "$(pad_string ${USRNAME})"
  387. # get the SIP extension
  388. SIPEXT=
  389. if [ -f $SIP_CONFIGURATION_FILE ]; then
  390. while read ext; do
  391. if [[ $ext == *"user id"* ]]; then
  392. CURR_UID=$(echo "$ext" | awk -F '"' '{print $2}' | awk -F '"' '{print $1}')
  393. fi
  394. if [[ $ext == *"extension"* ]]; then
  395. if [[ $CURR_UID == $USRNAME ]]; then
  396. SIPEXT=$(echo "$ext" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
  397. fi
  398. fi
  399. done < $SIP_CONFIGURATION_FILE
  400. fi
  401. if [ $SIPEXT ]; then
  402. echo -n -e "$(pad_string SIP:${SIPEXT})"
  403. else
  404. echo -n -e "$(pad_string '')"
  405. fi
  406. # size of the home directory
  407. echo "$(du -s -h /home/${USRNAME} | awk -F ' ' '{print $1}')"
  408. fi
  409. done
  410. echo ''
  411. }
  412. function show_mirrors_password {
  413. if [ ! /home/mirrors ]; then
  414. return
  415. fi
  416. read_config_param "MY_MIRRORS_PASSWORD"
  417. echo 'Local Mirrors'
  418. echo '============='
  419. echo ''
  420. echo -n "URL: "
  421. echo "$(cat ${COMPLETION_FILE} | grep 'ssh onion domain' | awk -F ':' '{print $2}')"
  422. echo "SSH Port: $SSH_PORT"
  423. echo "Password: $MY_MIRRORS_PASSWORD"
  424. echo ''
  425. }
  426. function show_tahoe_introducer {
  427. if [ ! -f /home/tahoelafs/.tahoe-introducer/private/introducer.furl ]; then
  428. return
  429. fi
  430. echo 'Tahoe-LAFS'
  431. echo '=========='
  432. echo ''
  433. cat /home/tahoelafs/.tahoe-introducer/private/introducer.furl
  434. echo ''
  435. }
  436. function show_ip_addresses {
  437. echo $'IP/DNS addresses'
  438. echo '================'
  439. echo ''
  440. echo -n "IPv4: $(get_ipv4_address)"
  441. ipv6_address="$(get_ipv6_address)"
  442. if [ ${#ipv6_address} -gt 0 ]; then
  443. echo " IPv6: ${ipv6_address}"
  444. fi
  445. echo ''
  446. echo ''
  447. }
  448. function show_ssh_public_key {
  449. echo $'SSH Public Keys'
  450. echo '==============='
  451. echo ''
  452. echo "$(get_ssh_server_key)"
  453. echo ''
  454. echo ''
  455. }
  456. function show_about {
  457. clear
  458. echo ''
  459. echo $' Detecting installed apps...'
  460. detect_apps
  461. get_apps_installed_names
  462. clear
  463. show_ip_addresses
  464. show_ssh_public_key
  465. show_domains
  466. show_mirrors_password
  467. show_tahoe_introducer
  468. show_users
  469. any_key
  470. }
  471. function select_user {
  472. SELECTED_USERNAME=
  473. users_array=($(ls /home))
  474. delete=(mirrors git)
  475. for del in ${delete[@]}
  476. do
  477. users_array=(${users_array[@]/$del})
  478. done
  479. i=0
  480. W=()
  481. name=()
  482. for u in ${users_array[@]}
  483. do
  484. if [[ $(is_valid_user "$u") == "1" ]]; then
  485. i=$((i+1))
  486. W+=($i "$u")
  487. name+=("$u")
  488. fi
  489. done
  490. if [ $i -eq 1 ]; then
  491. SELECTED_USERNAME="${name[0]}"
  492. else
  493. 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)
  494. if [ $? -eq 0 ]; then
  495. SELECTED_USERNAME="${name[$((user_index-1))]}"
  496. fi
  497. fi
  498. }
  499. function delete_user {
  500. select_user
  501. if [ ! $SELECTED_USERNAME ]; then
  502. return
  503. fi
  504. if grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
  505. dialog --title $"Administrator user" \
  506. --msgbox $"You can't delete the administrator user" 6 40
  507. return
  508. fi
  509. clear
  510. ${PROJECT_NAME}-rmuser $SELECTED_USERNAME
  511. any_key
  512. }
  513. function configure_remote_backups {
  514. if ! grep -Fxq "Admin user:$ADMIN_USER" $COMPLETION_FILE; then
  515. dialog --title $"Administrator user" \
  516. --msgbox $"No Administrator user found. Check $COMPLETION_FILE" 6 40
  517. return
  518. fi
  519. if [ ${#ADMIN_USER} -lt 2 ]; then
  520. dialog --title $"Administrator user" \
  521. --msgbox $"Username not found" 6 40
  522. return
  523. fi
  524. if [ ! -d /home/$ADMIN_USER ]; then
  525. dialog --title $"Administrator user" \
  526. --msgbox $"Home directory not found" 6 40
  527. return
  528. fi
  529. ${PROJECT_NAME}-remote -u $ADMIN_USER
  530. if [ ! "$?" = "0" ]; then
  531. any_key
  532. fi
  533. }
  534. function change_password {
  535. select_user
  536. if [ ! $SELECTED_USERNAME ]; then
  537. return
  538. fi
  539. dialog --title $"Change password" \
  540. --passwordbox $"New password for user $SELECTED_USERNAME" 8 40 2> $data
  541. newpassword=$(<$data)
  542. if [ ${#newpassword} -lt ${MINIMUM_PASSWORD_LENGTH} ]; then
  543. dialog --title $"Change password" \
  544. --msgbox $"The password should be ${MINIMUM_PASSWORD_LENGTH} or more characters" 6 40
  545. return
  546. fi
  547. echo "$SELECTED_USERNAME:$newpassword"|chpasswd
  548. dialog --title $"Change password" \
  549. --msgbox $"Password for $SELECTED_USERNAME was changed" 6 40
  550. }
  551. function change_ssh_public_key {
  552. select_user
  553. if [ ! $SELECTED_USERNAME ]; then
  554. return
  555. fi
  556. if grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
  557. dialog --title $"Change ssh public key" \
  558. --backtitle $"Freedombone Control Panel" \
  559. --defaultno \
  560. --yesno $"\nThis is the administrator user.\n\nAre you sure you want to change the ssh public key for the administrator?" 10 60
  561. sel=$?
  562. case $sel in
  563. 1) return;;
  564. 255) return;;
  565. esac
  566. fi
  567. data=$(tempfile 2>/dev/null)
  568. trap "rm -f $data" 0 1 2 5 15
  569. dialog --title $"Change ssh public key for $SELECTED_USERNAME" \
  570. --backtitle $"Freedombone Control Panel" \
  571. --inputbox $"Paste the ssh public key below" 8 60 2>$data
  572. sel=$?
  573. case $sel in
  574. 0)
  575. SSH_PUBLIC_KEY=$(<$data)
  576. if [ "$SSH_PUBLIC_KEY" ]; then
  577. if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
  578. if [ -f "$SSH_PUBLIC_KEY" ]; then
  579. if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
  580. mkdir /home/$SELECTED_USERNAME/.ssh
  581. fi
  582. cp $SSH_PUBLIC_KEY \
  583. /home/$SELECTED_USERNAME/.ssh/authorized_keys
  584. chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
  585. /home/$SELECTED_USERNAME/.ssh
  586. dialog --title $"Change ssh public key" \
  587. --msgbox $"ssh public key was installed" 6 40
  588. else
  589. if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
  590. if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
  591. mkdir /home/$SELECTED_USERNAME/.ssh
  592. fi
  593. echo "$SSH_PUBLIC_KEY" > \
  594. /home/$SELECTED_USERNAME/.ssh/authorized_keys
  595. chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
  596. /home/$SELECTED_USERNAME/.ssh
  597. dialog --title $"Change ssh public key" \
  598. --msgbox $"ssh public key was installed" 6 40
  599. fi
  600. fi
  601. fi
  602. fi
  603. ;;
  604. esac
  605. }
  606. function remove_user_from_mailing_list {
  607. select_user
  608. if [ ! $SELECTED_USERNAME ]; then
  609. return
  610. fi
  611. USER_MAILING_LISTS=$(cat "/home/$SELECTED_USERNAME/.procmailrc" | grep '\[' | grep '\]' | awk -F '\[' '{print $2}' | awk -F '\\' '{print $1}')
  612. i=0
  613. W=()
  614. list_name=()
  615. while read -r listname; do
  616. i=$((i+1))
  617. W+=($i "$listname")
  618. list_name+=("$listname")
  619. echo $listname
  620. done <<< "$USER_MAILING_LISTS"
  621. i=$((i+1))
  622. W+=($i $"Exit back to user mainenance")
  623. 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)
  624. if [ $? -eq 0 ]; then # Exit with OK
  625. if [ ${list_selected} -ne ${i} ]; then
  626. remove_list_name="${list_name[$((list_selected-1))]}"
  627. # find the line number where the list is defined
  628. line_number=0
  629. i=0
  630. while read -r line
  631. do
  632. if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
  633. line_number=${i}
  634. fi
  635. i=$((i+1))
  636. done < "/home/$SELECTED_USERNAME/.procmailrc"
  637. if [ ${line_number} -eq 0 ]; then
  638. # no match was found
  639. return
  640. fi
  641. # recreate the file
  642. if [ -f /home/${SELECTED_USERNAME}/.procmailrc_new ]; then
  643. rm /home/${SELECTED_USERNAME}/.procmailrc_new
  644. fi
  645. i=0
  646. clip=0
  647. while read -r line
  648. do
  649. i=$((i+1))
  650. if [ ${i} -gt $((line_number-1)) ]; then
  651. if [ ${clip} -eq 0 ]; then
  652. clip=1
  653. fi
  654. if [ ${clip} -eq 1 ]; then
  655. if [ ${i} -lt $((line_number+2)) ]; then
  656. continue
  657. else
  658. if [ ${#line} -lt 1 ]; then
  659. clip=2
  660. continue
  661. fi
  662. if [[ "$line" == ":"* || "$line" == "#"* ]]; then
  663. clip=2
  664. else
  665. continue
  666. fi
  667. fi
  668. fi
  669. fi
  670. echo "$line" >> /home/${SELECTED_USERNAME}/.procmailrc_new
  671. if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
  672. line_number=${i}
  673. fi
  674. done < "/home/$SELECTED_USERNAME/.procmailrc"
  675. cp /home/${SELECTED_USERNAME}/.procmailrc_new /home/${SELECTED_USERNAME}/.procmailrc
  676. rm /home/${SELECTED_USERNAME}/.procmailrc_new
  677. chown ${SELECTED_USERNAME}:${SELECTED_USERNAME} /home/${SELECTED_USERNAME}/.procmailrc
  678. dialog --title $"Remove user from mailing list" \
  679. --msgbox $"${SELECTED_USERNAME} has been removed from ${remove_list_name}" 6 50
  680. fi
  681. fi
  682. }
  683. function add_to_mailing_list {
  684. select_user
  685. if [ ! $SELECTED_USERNAME ]; then
  686. return
  687. fi
  688. data=$(tempfile 2>/dev/null)
  689. trap "rm -f $data" 0 1 2 5 15
  690. dialog --backtitle $"Freedombone Control Panel" \
  691. --title $"Subscribe $SELECTED_USERNAME to a mailing list" \
  692. --form $"You can either enter a subject or an email address\n" 11 68 4 \
  693. $"List folder name:" 1 1 "" 1 35 26 25 \
  694. $"Name between [] on subject line:" 2 1 "" 2 35 26 25 \
  695. $"List email address:" 3 1 "" 3 35 26 25 \
  696. $"Public:" 4 1 $"yes" 4 35 4 25 \
  697. 2> $data
  698. sel=$?
  699. case $sel in
  700. 1) return;;
  701. 255) return;;
  702. esac
  703. LIST_NAME=$(cat $data | sed -n 1p)
  704. LIST_SUBJECT=$(cat $data | sed -n 2p)
  705. LIST_EMAIL=$(cat $data | sed -n 3p)
  706. LIST_PUBLIC=$(cat $data | sed -n 4p)
  707. if [ ${#LIST_PUBLIC} -lt 1 ]; then
  708. LIST_PUBLIC='no'
  709. fi
  710. if [[ $LIST_PUBLIC == $'y' || $LIST_PUBLIC == $'Y' || $LIST_PUBLIC == $'true' || $LIST_PUBLIC == $'True' || $LIST_PUBLIC == $'yes' || $LIST_PUBLIC == $'Yes' || $LIST_PUBLIC == $'YES' ]]; then
  711. LIST_PUBLIC='yes'
  712. else
  713. LIST_PUBLIC='no'
  714. fi
  715. if [ ${#LIST_NAME} -lt 2 ]; then
  716. dialog --title $"Add mailing list" \
  717. --msgbox $"No mailing list name was given" 6 40
  718. return
  719. fi
  720. if [ ${#LIST_SUBJECT} -lt 2 ]; then
  721. if [ ${#LIST_EMAIL} -lt 2 ]; then
  722. dialog --title $"Add mailing list" \
  723. --msgbox $"No mailing list subject or address was given" 6 40
  724. return
  725. fi
  726. fi
  727. if [ ${#LIST_SUBJECT} -gt 1 ]; then
  728. ${PROJECT_NAME}-addlist -u $SELECTED_USERNAME -l "$LIST_NAME" \
  729. -s "$LIST_SUBJECT" --public $LIST_PUBLIC
  730. else
  731. if [[ "$LIST_EMAIL" != *"@"* || "$LIST_EMAIL" != *"."* ]]; then
  732. dialog --title $"Add mailing list" \
  733. --msgbox $"Unrecognised email address" 6 40
  734. return
  735. else
  736. ${PROJECT_NAME}-addlist -u $SELECTED_USERNAME -l "$LIST_NAME" \
  737. -e "$LIST_EMAIL" --public $LIST_PUBLIC
  738. fi
  739. fi
  740. dialog --title $"Add mailing list" \
  741. --msgbox $"$LIST_NAME list was added" 6 40
  742. }
  743. function email_rule {
  744. select_user
  745. if [ ! $SELECTED_USERNAME ]; then
  746. return
  747. fi
  748. data=$(tempfile 2>/dev/null)
  749. trap "rm -f $data" 0 1 2 5 15
  750. dialog --backtitle $"Freedombone Control Panel" \
  751. --title $"Email rule for user $SELECTED_USERNAME" \
  752. --form "\n" 9 65 4 \
  753. $"When email arrives from address:" 1 1 "" 1 35 24 28 \
  754. $"Move to folder:" 2 1 "" 2 35 24 28 \
  755. $"Public:" 3 1 $"no" 3 35 4 25 \
  756. 2> $data
  757. sel=$?
  758. case $sel in
  759. 1) return;;
  760. 255) return;;
  761. esac
  762. RULE_EMAIL=$(cat $data | sed -n 1p)
  763. RULE_FOLDER=$(cat $data | sed -n 2p)
  764. RULE_PUBLIC=$(cat $data | sed -n 3p)
  765. if [ ${#RULE_PUBLIC} -lt 1 ]; then
  766. RULE_PUBLIC='no'
  767. fi
  768. if [[ $RULE_PUBLIC == $'y' || $RULE_PUBLIC == $'Y' || $RULE_PUBLIC == $'true' || $RULE_PUBLIC == $'True' || $RULE_PUBLIC == $'yes' || $RULE_PUBLIC == $'Yes' || $RULE_PUBLIC == $'YES' ]]; then
  769. RULE_PUBLIC='yes'
  770. else
  771. RULE_PUBLIC='no'
  772. fi
  773. if [ ${#RULE_EMAIL} -lt 2 ]; then
  774. dialog --title $"Add email rule" \
  775. --msgbox $"No email address was given" 6 40
  776. return
  777. fi
  778. if [ ${#RULE_FOLDER} -lt 2 ]; then
  779. dialog --title $"Add email rule" \
  780. --msgbox $"No folder name was given" 6 40
  781. return
  782. fi
  783. if [[ "$RULE_EMAIL" != *"@"* || "$RULE_EMAIL" != *"."* ]]; then
  784. dialog --title $"Add email rule" \
  785. --msgbox $"Unrecognised email address" 6 40
  786. return
  787. fi
  788. ${PROJECT_NAME}-addemail -u $SELECTED_USERNAME -e "$RULE_EMAIL" \
  789. -g "$RULE_FOLDER" --public $RULE_PUBLIC
  790. dialog --title $"Add email rule" \
  791. --msgbox $"Email rule for $RULE_EMAIL was added" 6 40
  792. }
  793. function block_unblock_email {
  794. select_user
  795. if [ ! $SELECTED_USERNAME ]; then
  796. return
  797. fi
  798. blockstr=$"Block/Unblock email going to"
  799. data=$(tempfile 2>/dev/null)
  800. trap "rm -f $data" 0 1 2 5 15
  801. dialog --backtitle $"Freedombone Control Panel" \
  802. --title "$blockstr $SELECTED_USERNAME" \
  803. --form "\n" 8 65 3 \
  804. $"When email arrives from address:" 1 1 "" 1 35 24 100 \
  805. $"Block it:" 2 1 "yes" 2 35 4 4 \
  806. 2> $data
  807. sel=$?
  808. case $sel in
  809. 1) return;;
  810. 255) return;;
  811. esac
  812. BLOCK_EMAIL=$(cat $data | sed -n 1p)
  813. BLOCK=$(cat $data | sed -n 2p)
  814. if [ ${#BLOCK_EMAIL} -lt 2 ]; then
  815. dialog --title $"Block/Unblock an email" \
  816. --msgbox $"No email address was given" 6 40
  817. return
  818. fi
  819. if [[ "$BLOCK_EMAIL" != *"@"* || "$BLOCK_EMAIL" != *"."* ]]; then
  820. dialog --title $"Block/Unblock an email" \
  821. --msgbox $"Unrecognised email address" 6 40
  822. return
  823. fi
  824. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  825. ${PROJECT_NAME}-ignore -u $SELECTED_USERNAME -e "$BLOCK_EMAIL"
  826. dialog --title $"Block an email" \
  827. --msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME blocked" 6 75
  828. else
  829. ${PROJECT_NAME}-unignore -u $SELECTED_USERNAME -e "$BLOCK_EMAIL"
  830. dialog --title $"Unblock an email" \
  831. --msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME unblocked" 6 75
  832. fi
  833. }
  834. function block_unblock_subject {
  835. select_user
  836. if [ ! $SELECTED_USERNAME ]; then
  837. return
  838. fi
  839. blockstr=$"Block/Unblock email going to"
  840. data=$(tempfile 2>/dev/null)
  841. trap "rm -f $data" 0 1 2 5 15
  842. dialog --backtitle $"Freedombone Control Panel" \
  843. --title "$blockstr $SELECTED_USERNAME" \
  844. --form "\n" 8 70 3 \
  845. $"When email arrives with subject text:" 1 1 "" 1 40 24 28 \
  846. $"Block it:" 2 1 "yes" 2 40 4 4 \
  847. 2> $data
  848. sel=$?
  849. case $sel in
  850. 1) return;;
  851. 255) return;;
  852. esac
  853. BLOCK_SUBJECT=$(cat $data | sed -n 1p)
  854. BLOCK=$(cat $data | sed -n 2p)
  855. if [ ${#BLOCK_SUBJECT} -lt 2 ]; then
  856. dialog --title $"Block/Unblock an email" \
  857. --msgbox $"No subject was given" 6 40
  858. return
  859. fi
  860. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  861. ${PROJECT_NAME}-ignore -u $SELECTED_USERNAME -t "$BLOCK_SUBJECT"
  862. dialog --title $"Block an email" \
  863. --msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME blocked" 6 40
  864. else
  865. ${PROJECT_NAME}-unignore -u $SELECTED_USERNAME -t "$BLOCK_SUBJECT"
  866. dialog --title $"Unblock an email" \
  867. --msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME unblocked" 6 40
  868. fi
  869. }
  870. function create_keydrive_master {
  871. select_user
  872. if [ ! $SELECTED_USERNAME ]; then
  873. return
  874. fi
  875. dialog --title $"USB Master Keydrive" \
  876. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  877. clear
  878. ${PROJECT_NAME}-keydrive -u $SELECTED_USERNAME --master 'yes'
  879. any_key
  880. }
  881. function create_keydrive_fragment {
  882. select_user
  883. if [ ! $SELECTED_USERNAME ]; then
  884. return
  885. fi
  886. dialog --title $"USB Fragment Keydrive" \
  887. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  888. clear
  889. ${PROJECT_NAME}-keydrive -u $SELECTED_USERNAME
  890. any_key
  891. }
  892. function backup_data {
  893. dialog --title $"Backup data to USB" \
  894. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  895. clear
  896. detect_usb_drive
  897. echo ''
  898. echo $"Detected USB drive $USB_DRIVE"
  899. echo ''
  900. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  901. ${PROJECT_NAME}-backup-local
  902. any_key
  903. }
  904. function restore_data_from_storage {
  905. restore_type="$1"
  906. AllStr=$"all"
  907. ExitStr=$"Exit"
  908. RestoreStr=$"Restore apps"
  909. if [[ $restore_type != "local" ]]; then
  910. restore_command="${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;"
  911. else
  912. remote_domain_name="$1"
  913. detect_usb_drive
  914. restore_command="${PROJECT_NAME}-restore-local $USB_DRIVE"
  915. RestoreStr=$"Restore apps from USB drive $USB_DRIVE"
  916. fi
  917. utils_installed=(configfiles
  918. mariadb
  919. letsencrypt
  920. passwords
  921. mutt
  922. gpg
  923. procmail
  924. spamassassin
  925. readme
  926. ssh
  927. userconfig
  928. userlocal
  929. userfin
  930. certs
  931. personal
  932. email)
  933. detect_apps
  934. while true
  935. do
  936. app_list=()
  937. n=1
  938. applist="$n $AllStr off"
  939. n=$[n+1]
  940. app_list+=("$AllStr")
  941. util_index=0
  942. for a in "${utils_installed[@]}"
  943. do
  944. applist="$applist $n $a off"
  945. app_name=${utils_installed[util_index]}
  946. n=$[n+1]
  947. util_index=$[util_index+1]
  948. app_list+=("$app_name")
  949. done
  950. app_index=0
  951. for a in "${APPS_INSTALLED_NAMES[@]}"
  952. do
  953. applist="$applist $n $a off"
  954. n=$[n+1]
  955. app_name=${APPS_INSTALLED_NAMES[app_index]}
  956. app_index=$[app_index+1]
  957. app_list+=("$app_name")
  958. done
  959. applist="$applist $n $ExitStr on"
  960. n=$[n+1]
  961. app_list+=("$ExitStr")
  962. choice=$(dialog --stdout --backtitle $"Freedombone" \
  963. --title "$RestoreStr" \
  964. --radiolist $'Choose:' \
  965. 30 50 20 $applist)
  966. if [ $? -ne 0 ]; then
  967. break
  968. fi
  969. app_index=$[choice-1]
  970. app_name=${app_list[app_index]}
  971. # exit
  972. if [[ "$app_name" == "$ExitStr" ]]; then
  973. break
  974. fi
  975. clear
  976. # Restore all
  977. if [[ "$app_name" == "$AllStr" ]]; then
  978. $restore_command
  979. retcode="$?"
  980. if [[ "$retcode" != "0" ]]; then
  981. if [[ "$1" == "local" ]]; then
  982. dialog --title $"Restore all apps from USB" \
  983. --msgbox $"Restore failed with code $retcode" 6 60
  984. else
  985. dialog --title $"Restore all apps from $1" \
  986. --msgbox $"Restore failed with code $retcode" 6 60
  987. fi
  988. break
  989. fi
  990. if [[ "$1" == "local" ]]; then
  991. dialog --title $"Restore all apps from USB" \
  992. --msgbox $"Restore complete" 6 40
  993. else
  994. dialog --title $"Restore all apps from $1" \
  995. --msgbox $"Restore complete" 6 40
  996. fi
  997. break
  998. fi
  999. # Restore an app
  1000. $restore_command "${app_name}"
  1001. retcode="$?"
  1002. if [[ "$retcode" != "0" ]]; then
  1003. dialog --title $"Restore apps from USB" \
  1004. --msgbox $"Restore of ${app_name} failed with code $retcode" 6 60
  1005. return
  1006. fi
  1007. # finished
  1008. if [[ "$1" == "local" ]]; then
  1009. dialog --title $"Restore apps from USB" \
  1010. --msgbox $"Restore complete" 6 40
  1011. else
  1012. dialog --title $"Restore apps from $1" \
  1013. --msgbox $"Restore complete" 6 40
  1014. fi
  1015. done
  1016. }
  1017. function restore_data {
  1018. dialog --title $"Restore data from USB" \
  1019. --msgbox $"Plug in your backup USB drive" 6 40
  1020. clear
  1021. echo ' '
  1022. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  1023. restore_data_from_storage local
  1024. }
  1025. function restore_data_remote {
  1026. if [ ! $ADMIN_USER ]; then
  1027. dialog --title $"Restore data from remote server" \
  1028. --msgbox $"Unknown admin user" 6 40
  1029. return
  1030. fi
  1031. data=$(tempfile 2>/dev/null)
  1032. trap "rm -f $data" 0 1 2 5 15
  1033. dialog --title $"Restore from remote server" \
  1034. --backtitle $"Freedombone Control Panel" \
  1035. --inputbox $"Enter the domain name of the server from which you wish to restore" 8 60 2>$data
  1036. sel=$?
  1037. case $sel in
  1038. 0)
  1039. friend_server_domain_name=$(<$data)
  1040. if [ ${#friend_server_domain_name} -lt 2 ]; then
  1041. return
  1042. fi
  1043. if [[ $friend_server_domain_name != *"."* ]]; then
  1044. dialog --title $"Remote server domain name" \
  1045. --msgbox $"Invalid domain name" 6 40
  1046. return
  1047. fi
  1048. restore_data_from_storage $friend_server_domain_name
  1049. ;;
  1050. esac
  1051. }
  1052. function ping_enable_disable {
  1053. 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."
  1054. enable_ping="no"
  1055. dialog --title $"Enable Ping / ICMP" \
  1056. --backtitle $"Freedombone Control Panel" \
  1057. --defaultno \
  1058. --yesno "$ping_str" 10 60
  1059. sel=$?
  1060. case $sel in
  1061. 0) enable_ping="yes";;
  1062. 255) return;;
  1063. esac
  1064. if [[ $enable_ping == "yes" ]]; then
  1065. iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
  1066. iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  1067. echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  1068. else
  1069. iptables -D INPUT -p icmp --icmp-type echo-request -j ACCEPT
  1070. iptables -D OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  1071. echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  1072. fi
  1073. }
  1074. function logging_on_off {
  1075. logging="no"
  1076. dialog --title $"Logging" \
  1077. --backtitle $"Freedombone Control Panel" \
  1078. --defaultno \
  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. if [ ! -f /usr/bin/reset-tripwire ]; then
  1112. return
  1113. fi
  1114. clear
  1115. echo $'Resetting the Tripwire...'
  1116. echo ' '
  1117. echo '
  1118. ' | reset-tripwire
  1119. any_key
  1120. }
  1121. function format_drive {
  1122. detect_usb_drive
  1123. data=$(tempfile 2>/dev/null)
  1124. trap "rm -f $data" 0 1 2 5 15
  1125. dialog --title $"Format USB drive $USB_DRIVE" \
  1126. --backtitle $"Freedombone Control Panel" \
  1127. --defaultno \
  1128. --yesno $"\nPlease confirm that you wish to format drive\n\n ${USB_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
  1129. sel=$?
  1130. case $sel in
  1131. 1) return;;
  1132. 255) return;;
  1133. esac
  1134. clear
  1135. echo ''
  1136. echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
  1137. echo ''
  1138. ${PROJECT_NAME}-format $USB_DRIVE
  1139. any_key
  1140. }
  1141. function remove_backups {
  1142. detect_usb_drive
  1143. data=$(tempfile 2>/dev/null)
  1144. trap "rm -f $data" 0 1 2 5 15
  1145. dialog --title $"Remove backups from a USB drive $USB_DRIVE" \
  1146. --backtitle $"Freedombone Control Panel" \
  1147. --defaultno \
  1148. --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
  1149. sel=$?
  1150. case $sel in
  1151. 1) return;;
  1152. 255) return;;
  1153. esac
  1154. clear
  1155. ${PROJECT_NAME}-backup-local $USB_DRIVE remove
  1156. any_key
  1157. }
  1158. function shut_down_system {
  1159. dialog --title $"Power off the system" \
  1160. --backtitle $"Freedombone Control Panel" \
  1161. --defaultno \
  1162. --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
  1163. sel=$?
  1164. case $sel in
  1165. 1) return;;
  1166. 255) return;;
  1167. esac
  1168. shutdown now
  1169. }
  1170. function restart_system {
  1171. dialog --title $"Restart the system" \
  1172. --backtitle $"Freedombone Control Panel" \
  1173. --defaultno \
  1174. --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
  1175. sel=$?
  1176. case $sel in
  1177. 1) return;;
  1178. 255) return;;
  1179. esac
  1180. reboot
  1181. }
  1182. function change_system_name {
  1183. data=$(tempfile 2>/dev/null)
  1184. trap "rm -f $data" 0 1 2 5 15
  1185. dialog --title $"Change the name of this system" \
  1186. --backtitle $"Freedombone Control Panel" \
  1187. --inputbox $'Enter a new name for this system on your local network\n\nIt will appear as newname.local' 10 60 2>$data
  1188. sel=$?
  1189. case $sel in
  1190. 0) NEW_SYSTEM_NAME=$(<$data)
  1191. if [ "$NEW_SYSTEM_NAME" ]; then
  1192. if [ ${#NEW_SYSTEM_NAME} -gt 1 ]; then
  1193. sed -i "s|host-name=.*|host-name=$NEW_SYSTEM_NAME|g" /etc/avahi/avahi-daemon.conf
  1194. systemctl restart avahi-daemon
  1195. if grep -q "host-name=$NEW_SYSTEM_NAME" /etc/avahi/avahi-daemon.conf; then
  1196. dialog --title $"New local network name" \
  1197. --msgbox $"The name of this system on your local network was changed successfully" 6 70
  1198. fi
  1199. fi
  1200. fi
  1201. ;;
  1202. esac
  1203. }
  1204. function set_dynamic_IP {
  1205. revert_to_dynamic=
  1206. dialog --title $"Return to using a dynamic IP address" \
  1207. --backtitle $"Freedombone Control Panel" \
  1208. --yesno $"\nDo you wish to go back to using a dynamic IP address?" 8 60
  1209. sel=$?
  1210. case $sel in
  1211. 0) revert_to_dynamic=1
  1212. ;;
  1213. 1) return;;
  1214. esac
  1215. if [ $revert_to_dynamic ]; then
  1216. wifi_original_network_settings
  1217. clear
  1218. echo ''
  1219. echo $'Changing to a dynamic IP address.'
  1220. echo ''
  1221. echo $"System is rebooting. You may need to close this terminal and log in from a new one."
  1222. reboot
  1223. fi
  1224. }
  1225. function set_static_IP {
  1226. IPv4_address=$(get_ipv4_address)
  1227. IPv4_address_base=$(echo "$IPv4_address" | awk -F '.' '{print $1"."$2"."$3}')
  1228. STATIC_IP="${IPv4_address_base}.60"
  1229. STATIC_GATEWAY="${IPv4_address_base}.1"
  1230. NEW_STATIC_IP=
  1231. NEW_STATIC_GATEWAY=
  1232. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1233. STATIC_IP=$(cat /etc/network/interfaces | grep "address " | head -n 1 | awk -F ' ' '{print $2}')
  1234. STATIC_GATEWAY=$(cat /etc/network/interfaces | grep "gateway " | head -n 1 | awk -F ' ' '{print $2}')
  1235. fi
  1236. # get the IP for the box
  1237. data=$(tempfile 2>/dev/null)
  1238. trap "rm -f $data" 0 1 2 5 15
  1239. dialog --title $"Set a static local IP address" \
  1240. --backtitle $"Freedombone Control Panel" \
  1241. --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
  1242. Enter a static local IP address for this system.\n\nIt will typically be ${IPv4_address_base}.x\n\nIf you leave this field blank then the system will revert to using a dynamic IP address." 18 60 "$STATIC_IP" 2>$data
  1243. sel=$?
  1244. case $sel in
  1245. 0) NEW_STATIC_IP=$(<$data)
  1246. if [[ "$NEW_STATIC_IP" != *"."* ]]; then
  1247. set_dynamic_IP
  1248. return
  1249. fi
  1250. ;;
  1251. 1) return;;
  1252. esac
  1253. # get the gateway
  1254. data=$(tempfile 2>/dev/null)
  1255. trap "rm -f $data" 0 1 2 5 15
  1256. dialog --title $"Set the IP address of your internet router/modem" \
  1257. --backtitle $"Freedombone Control Panel" \
  1258. --inputbox $"Set the local IP address for your internet router or ADSL modem.\n\nIt will typically be ${IPv4_address_base}.1, ${IPv4_address_base}.254, or similar" 12 60 "$STATIC_GATEWAY" 2>$data
  1259. sel=$?
  1260. case $sel in
  1261. 0) NEW_STATIC_GATEWAY=$(<$data)
  1262. if [[ "$NEW_STATIC_GATEWAY" != *"."* ]]; then
  1263. return
  1264. fi
  1265. ;;
  1266. 1) return;;
  1267. esac
  1268. if [[ "$NEW_STATIC_GATEWAY" == *"."* && "$NEW_STATIC_IP" == *"."* ]]; then
  1269. ip_addresses_have_changed=
  1270. if ! grep -q "address ${NEW_STATIC_IP}" /etc/network/interfaces; then
  1271. ip_addresses_have_changed=1
  1272. fi
  1273. if ! grep -q "gateway ${NEW_STATIC_GATEWAY}" /etc/network/interfaces; then
  1274. ip_addresses_have_changed=1
  1275. fi
  1276. if [ $ip_addresses_have_changed ]; then
  1277. write_config_param "NETWORK_IS_STATIC" "1"
  1278. write_config_param "LOCAL_NETWORK_STATIC_IP_ADDRESS" "$NEW_STATIC_IP"
  1279. write_config_param "ROUTER_IP_ADDRESS" "$NEW_STATIC_GATEWAY"
  1280. email_change_relay "$NEW_STATIC_IP"
  1281. static_wifi_address=
  1282. if [[ $(config_param_exists "WIFI_INTERFACE") == "1" ]]; then
  1283. dialog --title $"Static local IP address" \
  1284. --backtitle $"Freedombone Control Panel" \
  1285. --yesno $"\nSet a static address for the wifi adapter?\n\nIf you select 'no' then wired ethernet will be used." 10 60
  1286. sel=$?
  1287. case $sel in
  1288. 0) static_wifi_address=1
  1289. write_config_param "NETWORK_IS_STATIC" "1"
  1290. ;;
  1291. esac
  1292. fi
  1293. if [ ! $static_wifi_address ]; then
  1294. # wired network
  1295. remove_wifi_startup_script
  1296. echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
  1297. echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
  1298. echo '' >> /etc/network/interfaces
  1299. echo '# The loopback network interface' >> /etc/network/interfaces
  1300. echo 'auto lo' >> /etc/network/interfaces
  1301. echo 'iface lo inet loopback' >> /etc/network/interfaces
  1302. echo '' >> /etc/network/interfaces
  1303. echo '# The primary network interface' >> /etc/network/interfaces
  1304. echo 'auto eth0' >> /etc/network/interfaces
  1305. echo 'iface eth0 inet static' >> /etc/network/interfaces
  1306. echo " address ${NEW_STATIC_IP}" >> /etc/network/interfaces
  1307. echo ' netmask 255.255.255.0' >> /etc/network/interfaces
  1308. echo " gateway ${NEW_STATIC_GATEWAY}" >> /etc/network/interfaces
  1309. echo " dns-nameservers 213.73.91.35 85.214.20.141" >> /etc/network/interfaces
  1310. echo '# Example to keep MAC address between reboots' >> /etc/network/interfaces
  1311. echo '#hwaddress ether DE:AD:BE:EF:CA:FE' >> /etc/network/interfaces
  1312. echo '' >> /etc/network/interfaces
  1313. echo '# The secondary network interface' >> /etc/network/interfaces
  1314. echo '#auto eth1' >> /etc/network/interfaces
  1315. echo '#iface eth1 inet dhcp' >> /etc/network/interfaces
  1316. echo '' >> /etc/network/interfaces
  1317. echo '# WiFi Example' >> /etc/network/interfaces
  1318. echo "#auto $WIFI_INTERFACE" >> /etc/network/interfaces
  1319. echo "#iface $WIFI_INTERFACE inet dhcp" >> /etc/network/interfaces
  1320. echo '# wpa-ssid "essid"' >> /etc/network/interfaces
  1321. echo '# wpa-psk "password"' >> /etc/network/interfaces
  1322. echo '' >> /etc/network/interfaces
  1323. echo '# Ethernet/RNDIS gadget (g_ether)' >> /etc/network/interfaces
  1324. echo '# ... or on host side, usbnet and random hwaddr' >> /etc/network/interfaces
  1325. echo '# Note on some boards, usb0 is automaticly setup with an init script' >> /etc/network/interfaces
  1326. echo '#iface usb0 inet static' >> /etc/network/interfaces
  1327. echo '# address 192.168.7.2' >> /etc/network/interfaces
  1328. echo '# netmask 255.255.255.0' >> /etc/network/interfaces
  1329. echo '# network 192.168.7.0' >> /etc/network/interfaces
  1330. echo '# gateway 192.168.7.1' >> /etc/network/interfaces
  1331. else
  1332. # wifi network
  1333. wifi_settings
  1334. fi
  1335. clear
  1336. echo ''
  1337. echo $'Restarting the network daemon.'
  1338. echo ''
  1339. echo $'If you logged in using the previous IP address then you may need to close this terminal and log in again on the new one.'
  1340. function_check pihole_change_ipv4
  1341. pihole_change_ipv4 ${NEW_STATIC_IP}
  1342. dialog --title $"Static local IP address" \
  1343. --backtitle $"Freedombone Control Panel" \
  1344. --yesno $"\nFor the change to take effect your system will now need to reboot. Do this now?" 8 60
  1345. sel=$?
  1346. case $sel in
  1347. 0) reboot;;
  1348. esac
  1349. fi
  1350. fi
  1351. }
  1352. function wifi_settings {
  1353. if [ -f /etc/hostapd/hostapd.conf ]; then
  1354. return
  1355. fi
  1356. TEMP_WIFI_NETWORKS_FILE=~/.temp-${PROJECT_NAME}-wifi.cfg
  1357. ${PROJECT_NAME}-wifi --networksinteractive $TEMP_WIFI_NETWORKS_FILE
  1358. if [ -f $TEMP_WIFI_NETWORKS_FILE ]; then
  1359. cp $TEMP_WIFI_NETWORKS_FILE $WIFI_NETWORKS_FILE
  1360. rm $TEMP_WIFI_NETWORKS_FILE
  1361. ${PROJECT_NAME}-wifi --networks $WIFI_NETWORKS_FILE
  1362. create_wifi_startup_script
  1363. if [[ $(wifi_is_running) == "1" ]]; then
  1364. dialog --title $"Wifi Settings" \
  1365. --msgbox $"Wifi settings were changed." 6 60
  1366. else
  1367. dialog --title $"Wifi Settings" \
  1368. --msgbox $"Wifi settings were changed. You will need to restart the system with ethernet cable removed for the changes to take effect." 7 60
  1369. fi
  1370. else
  1371. remove_wifi_startup_script
  1372. fi
  1373. }
  1374. function wifi_edit_networks {
  1375. if [ -f /etc/hostapd/hostapd.conf ]; then
  1376. return
  1377. fi
  1378. if [ ! -f $WIFI_NETWORKS_FILE ]; then
  1379. echo $'# Add wifi networks as follows:' > $WIFI_NETWORKS_FILE
  1380. echo '#' >> $WIFI_NETWORKS_FILE
  1381. echo $'# MySSID' >> $WIFI_NETWORKS_FILE
  1382. echo $'# wpa2-psk' >> $WIFI_NETWORKS_FILE
  1383. echo $'# myWifiPassphrase' >> $WIFI_NETWORKS_FILE
  1384. echo '#' >> $WIFI_NETWORKS_FILE
  1385. echo $'# AnotherSSID' >> $WIFI_NETWORKS_FILE
  1386. echo $'# none' >> $WIFI_NETWORKS_FILE
  1387. echo '#' >> $WIFI_NETWORKS_FILE
  1388. fi
  1389. editor $WIFI_NETWORKS_FILE
  1390. ${PROJECT_NAME}-wifi --networks $WIFI_NETWORKS_FILE
  1391. }
  1392. function hotspot_settings {
  1393. data=$(tempfile 2>/dev/null)
  1394. trap "rm -f $data" 0 1 2 5 15
  1395. dialog --backtitle $"Freedombone Control Panel" \
  1396. --title $"Hotspot Settings" \
  1397. --form $"" 10 60 4 \
  1398. $"Enabled (yes/no):" 1 1 "$WIFI_HOTSPOT" 1 24 5 5 \
  1399. $"SSID:" 2 1 "$WIFI_SSID" 2 24 256 256 \
  1400. $"Type (wpa2-psk/none):" 3 1 "$WIFI_TYPE" 3 24 10 10 \
  1401. $"Passphrase:" 4 1 "$WIFI_PASSPHRASE" 4 24 256 256 \
  1402. 2> $data
  1403. sel=$?
  1404. case $sel in
  1405. 1) return;;
  1406. 255) return;;
  1407. esac
  1408. TEMP_WIFI_HOTSPOT=$(cat $data | sed -n 1p)
  1409. TEMP_WIFI_SSID=$(cat $data | sed -n 2p)
  1410. TEMP_WIFI_TYPE=$(cat $data | sed -n 3p)
  1411. TEMP_WIFI_PASSPHRASE=$(cat $data | sed -n 4p)
  1412. if [ ${#TEMP_WIFI_SSID} -lt 2 ]; then
  1413. return
  1414. fi
  1415. if [ ${#TEMP_WIFI_TYPE} -lt 2 ]; then
  1416. return
  1417. fi
  1418. WIFI_EXTRA=''
  1419. if [[ $TEMP_WIFI_HOTSPOT == $'yes' || $TEMP_WIFI_HOTSPOT == $'y' || $TEMP_WIFI_HOTSPOT == $'on' ]]; then
  1420. TEMP_WIFI_HOTSPOT='yes'
  1421. else
  1422. TEMP_WIFI_HOTSPOT='no'
  1423. if [ -f $WIFI_NETWORKS_FILE ]; then
  1424. WIFI_EXTRA='--networks $WIFI_NETWORKS_FILE'
  1425. fi
  1426. fi
  1427. if [[ $TEMP_WIFI_TYPE != $'none' ]]; then
  1428. if [ ! $TEMP_WIFI_PASSPHRASE ]; then
  1429. dialog --title $"Wifi Settings" \
  1430. --msgbox $"No wifi hotspot passphrase was given" 6 40
  1431. return
  1432. fi
  1433. if [ ${#TEMP_WIFI_PASSPHRASE} -lt 2 ]; then
  1434. dialog --title $"Wifi Settings" \
  1435. --msgbox $"Wifi hotspot passphrase was too short" 6 40
  1436. return
  1437. fi
  1438. WIFI_HOTSPOT=$TEMP_WIFI_HOTSPOT
  1439. WIFI_SSID=$TEMP_WIFI_SSID
  1440. WIFI_TYPE=$TEMP_WIFI_TYPE
  1441. WIFI_PASSPHRASE=$TEMP_WIFI_PASSPHRASE
  1442. ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE -p $WIFI_PASSPHRASE --hotspot $WIFI_HOTSPOT $WIFI_EXTRA
  1443. else
  1444. WIFI_HOTSPOT=$TEMP_WIFI_HOTSPOT
  1445. WIFI_SSID=$TEMP_WIFI_SSID
  1446. WIFI_TYPE=$TEMP_WIFI_TYPE
  1447. WIFI_PASSPHRASE=$TEMP_WIFI_PASSPHRASE
  1448. ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE --hotspot $WIFI_HOTSPOT $WIFI_EXTRA
  1449. fi
  1450. # store any changes
  1451. write_config_param "WIFI_HOTSPOT" "$WIFI_HOTSPOT"
  1452. write_config_param "WIFI_SSID" "$WIFI_SSID"
  1453. write_config_param "WIFI_TYPE" "$WIFI_TYPE"
  1454. write_config_param "WIFI_PASSPHRASE" "$WIFI_PASSPHRASE"
  1455. dialog --title $"Wifi Settings" \
  1456. --msgbox $"Hotspot settings were changed" 6 40
  1457. }
  1458. function reinstall_mariadb {
  1459. dialog --title $"Reinstall MariaDB" \
  1460. --backtitle $"Freedombone Control Panel" \
  1461. --defaultno \
  1462. --yesno $"\nThis should be a LAST RESORT, if the mysql daemon won't start. You will lose ALL databases and will then need to restore them from backup.\n\nAre you sure that you wish to continue?" 12 60
  1463. sel=$?
  1464. case $sel in
  1465. 1) return;;
  1466. 255) return;;
  1467. esac
  1468. clear
  1469. database_reinstall
  1470. dialog --title $"Reinstall MariaDB" \
  1471. --msgbox $"MariaDB has been reinstalled" 6 40
  1472. }
  1473. function show_firewall {
  1474. clear
  1475. echo $"Firewall Settings"
  1476. echo ''
  1477. while read line; do
  1478. firewall_name=$(echo "$line" | awk -F '=' '{print $1}')
  1479. firewall_port=$(echo "$line" | awk -F '=' '{print $2}')
  1480. echo -n -e "$(pad_string ${firewall_name})"
  1481. echo "${firewall_port}"
  1482. done < $FIREWALL_CONFIG
  1483. any_key
  1484. }
  1485. function email_extra_domains {
  1486. email_hostnames=$(cat /etc/exim4/update-exim4.conf.conf | grep "dc_other_hostnames" | awk -F "'" '{print $2}')
  1487. data=$(tempfile 2>/dev/null)
  1488. trap "rm -f $data" 0 1 2 5 15
  1489. dialog --title $"Email Domains" \
  1490. --backtitle $"Freedombone Control Panel" \
  1491. --inputbox $"Enter the list of email domains to use, separated by semicolons" 8 60 $email_hostnames 2>$data
  1492. sel=$?
  1493. case $sel in
  1494. 0)
  1495. emailhostnames=$(<$data)
  1496. if [ ${#emailhostnames} -gt 2 ]; then
  1497. if [[ "$email_hostnames" != "$emailhostnames" ]]; then
  1498. if [[ "$emailhostnames" == *"."* ]]; then
  1499. if [[ "$emailhostnames" != *" "* ]]; then
  1500. sed -i "s|dc_other_hostnames=.*|dc_other_hostnames='$emailhostnames'|g" /etc/exim4/update-exim4.conf.conf
  1501. update-exim4.conf
  1502. dpkg-reconfigure --frontend noninteractive exim4-config
  1503. systemctl restart saslauthd
  1504. dialog --title $"Email Domains" \
  1505. --backtitle $"Freedombone Control Panel" \
  1506. --msgbox $"Email domains were changed" 6 50
  1507. else
  1508. dialog --title $"Email Domains not set" \
  1509. --backtitle $"Freedombone Control Panel" \
  1510. --msgbox $"There should be no spaces in the list" 6 50
  1511. fi
  1512. fi
  1513. fi
  1514. fi
  1515. ;;
  1516. esac
  1517. }
  1518. function email_smtp_proxy {
  1519. MUTTRC_FILE=/home/$ADMIN_USER/.muttrc
  1520. if [ ! -f $MUTTRC_FILE ]; then
  1521. return
  1522. fi
  1523. data=$(tempfile 2>/dev/null)
  1524. trap "rm -f $data" 0 1 2 5 15
  1525. dialog --backtitle $"Freedombone Control Panel" \
  1526. --title $"SMTP Proxy for $ADMIN_USER" \
  1527. --form $"You may need to proxy outgoing email via your ISP's mail server. If so enter the details below." 14 75 6 \
  1528. $"Enable proxy:" 1 1 "$SMTP_PROXY_ENABLE" 1 24 5 5 \
  1529. $"Protocol (smtp/smtps):" 2 1 "$SMTP_PROXY_PROTOCOL" 2 24 5 5 \
  1530. $"ISP mail server:" 3 1 "$SMTP_PROXY_SERVER" 3 24 40 10000 \
  1531. $"Port:" 4 1 "$SMTP_PROXY_PORT" 4 24 5 5 \
  1532. $"Username:" 5 1 "$SMTP_PROXY_USERNAME" 5 24 40 10000 \
  1533. $"Password:" 6 1 "$SMTP_PROXY_PASSWORD" 6 24 40 10000 \
  1534. 2> $data
  1535. sel=$?
  1536. case $sel in
  1537. 1) return;;
  1538. 255) return;;
  1539. esac
  1540. SMTP_PROXY_ENABLE=$(cat $data | sed -n 1p)
  1541. SMTP_PROXY_PROTOCOL=$(cat $data | sed -n 2p)
  1542. SMTP_PROXY_SERVER=$(cat $data | sed -n 3p)
  1543. SMTP_PROXY_PORT=$(cat $data | sed -n 4p)
  1544. SMTP_PROXY_USERNAME=$(cat $data | sed -n 5p)
  1545. SMTP_PROXY_PASSWORD=$(cat $data | sed -n 6p)
  1546. # change muttrc
  1547. if [ $SMTP_PROXY_ENABLE != $'no' ]; then
  1548. if ! grep "set smtp_url" $MUTTRC_FILE; then
  1549. echo "set smtp_url=\"${SMTP_PROXY_PROTOCOL}://${SMTP_PROXY_USERNAME}:${SMTP_PROXY_PASSWORD}@${SMTP_PROXY_SERVER}:${SMTP_PROXY_PORT}/\"" >> $MUTTRC_FILE
  1550. else
  1551. sed -i "s|set smtp_url=.*|set smtp_url=\"${SMTP_PROXY_PROTOCOL}://${SMTP_PROXY_USERNAME}:${SMTP_PROXY_PASSWORD}@${SMTP_PROXY_SERVER}:${SMTP_PROXY_PORT}/\"|g" $MUTTRC_FILE
  1552. fi
  1553. sed -i 's|#set smtp_url|set smtp_url|g' $MUTTRC_FILE
  1554. else
  1555. if grep "set smtp_url" $MUTTRC_FILE; then
  1556. sed -i 's|set smtp_url|#set smtp_url|g' $MUTTRC_FILE
  1557. fi
  1558. fi
  1559. # save settings within the main configuration file
  1560. write_config_param "SMTP_PROXY_ENABLE" "$SMTP_PROXY_ENABLE"
  1561. write_config_param "SMTP_PROXY_PROTOCOL" "$SMTP_PROXY_PROTOCOL"
  1562. write_config_param "SMTP_PROXY_SERVER" "$SMTP_PROXY_SERVER"
  1563. write_config_param "SMTP_PROXY_PORT" "$SMTP_PROXY_PORT"
  1564. write_config_param "SMTP_PROXY_USERNAME" "$SMTP_PROXY_USERNAME"
  1565. write_config_param "SMTP_PROXY_PASSWORD" "$SMTP_PROXY_PASSWORD"
  1566. }
  1567. function menu_backup_restore {
  1568. while true
  1569. do
  1570. data=$(tempfile 2>/dev/null)
  1571. trap "rm -f $data" 0 1 2 5 15
  1572. dialog --backtitle $"Freedombone Control Panel" \
  1573. --title $"Backup and Restore" \
  1574. --radiolist $"Choose an operation:" 19 70 12 \
  1575. 1 $"Backup data to USB drive" off \
  1576. 2 $"Restore GPG key from USB keydrive" off \
  1577. 3 $"Restore data from USB drive" off \
  1578. 4 $"Reinstall mariadb" off \
  1579. 5 $"Configure remote backups" off \
  1580. 6 $"Restore from remote backup" off \
  1581. 7 $"Backup GPG key to USB (master keydrive)" off \
  1582. 8 $"Backup GPG key to USB (fragment keydrive)" off \
  1583. 9 $"Format a USB drive (LUKS encrypted)" off \
  1584. 10 $"Remove backups from a USB drive" off \
  1585. 11 $"Back to main menu" on 2> $data
  1586. sel=$?
  1587. case $sel in
  1588. 1) break;;
  1589. 255) break;;
  1590. esac
  1591. case $(cat $data) in
  1592. 1) backup_data;;
  1593. 2) restore_gpg_key;;
  1594. 3) restore_data;;
  1595. 4) reinstall_mariadb;;
  1596. 5) configure_remote_backups;;
  1597. 6) restore_data_remote;;
  1598. 7) create_keydrive_master;;
  1599. 8) create_keydrive_fragment;;
  1600. 9) format_drive;;
  1601. 10) remove_backups;;
  1602. 11) break;;
  1603. esac
  1604. done
  1605. }
  1606. function menu_email {
  1607. while true
  1608. do
  1609. data=$(tempfile 2>/dev/null)
  1610. trap "rm -f $data" 0 1 2 5 15
  1611. dialog --backtitle $"Freedombone Control Panel" \
  1612. --title $"Email Menu" \
  1613. --radiolist $"Choose an operation:" 15 70 8 \
  1614. 1 $"Add a user to a mailing list" off \
  1615. 2 $"Remove a user from a mailing list" off \
  1616. 3 $"Add an email rule" off \
  1617. 4 $"Block/Unblock an email address" off \
  1618. 5 $"Block/Unblock email with subject text" off \
  1619. 6 $"Outgoing Email Proxy" off \
  1620. 7 $"Extra email domains" off \
  1621. 8 $"Back to main menu" on 2> $data
  1622. sel=$?
  1623. case $sel in
  1624. 1) break;;
  1625. 255) break;;
  1626. esac
  1627. case $(cat $data) in
  1628. 1) add_to_mailing_list;;
  1629. 2) remove_user_from_mailing_list;;
  1630. 3) email_rule;;
  1631. 4) block_unblock_email;;
  1632. 5) block_unblock_subject;;
  1633. 6) email_smtp_proxy;;
  1634. 7) email_extra_domains;;
  1635. 8) break;;
  1636. esac
  1637. done
  1638. }
  1639. function menu_users {
  1640. while true
  1641. do
  1642. data=$(tempfile 2>/dev/null)
  1643. trap "rm -f $data" 0 1 2 5 15
  1644. dialog --backtitle $"Freedombone Control Panel" \
  1645. --title $"Manage Users" \
  1646. --radiolist $"Choose an operation:" 13 70 6 \
  1647. 1 $"Add a user" off \
  1648. 2 $"Delete a user" off \
  1649. 3 $"Change user password" off \
  1650. 4 $"Change user ssh public key" off \
  1651. 5 $"Reset password tries" off \
  1652. 6 $"Back to main menu" on 2> $data
  1653. sel=$?
  1654. case $sel in
  1655. 1) break;;
  1656. 255) break;;
  1657. esac
  1658. case $(cat $data) in
  1659. 1) add_user;;
  1660. 2) delete_user;;
  1661. 3) change_password;;
  1662. 4) change_ssh_public_key;;
  1663. 5) reset_password_tries;;
  1664. 6) break;;
  1665. esac
  1666. done
  1667. }
  1668. function wifi_enable {
  1669. disable_wifi='yes'
  1670. dialog --title $"Enable Wifi" \
  1671. --backtitle $"Freedombone Control Panel" \
  1672. --defaultno \
  1673. --yesno $"\nDo you wish to enable wifi?" 10 50
  1674. sel=$?
  1675. case $sel in
  1676. 0) disable_wifi='no';;
  1677. 1) disable_wifi='yes';;
  1678. 255) return;;
  1679. esac
  1680. ${PROJECT_NAME}-wifi --disable $disable_wifi
  1681. }
  1682. function menu_wifi {
  1683. if [[ "$(wifi_exists)" == "0" ]]; then
  1684. dialog --title $"Wifi" \
  1685. --msgbox $"No wifi adaptors were detected" 6 40
  1686. return
  1687. fi
  1688. while true
  1689. do
  1690. status_str=$'Wifi OFF'
  1691. if [ -f /etc/hostapd/hostapd.conf ]; then
  1692. status_str=$'Hotspot ON'
  1693. else
  1694. if grep -q "# wifi enabled" /etc/network/interfaces; then
  1695. status_str=$'Wifi ON'
  1696. fi
  1697. fi
  1698. data=$(tempfile 2>/dev/null)
  1699. trap "rm -f $data" 0 1 2 5 15
  1700. dialog --backtitle $"Freedombone Control Panel" \
  1701. --title $"Wifi Menu" \
  1702. --radiolist $"${status_str}\n\nChoose an operation:" 14 70 6 \
  1703. 1 $"Enable or disable Wifi" off \
  1704. 2 $"Configure wifi networks" off \
  1705. 3 $"Manually edit wifi networks file" off \
  1706. 4 $"Hotspot settings" off \
  1707. 5 $"Exit" on 2> $data
  1708. sel=$?
  1709. case $sel in
  1710. 1) break;;
  1711. 255) break;;
  1712. esac
  1713. case $(cat $data) in
  1714. 1) wifi_enable;;
  1715. 2) wifi_settings;;
  1716. 3) wifi_edit_networks;;
  1717. 4) hotspot_settings;;
  1718. 5) break;;
  1719. esac
  1720. done
  1721. }
  1722. function menu_app_settings {
  1723. detect_installable_apps
  1724. applist=""
  1725. appnames=()
  1726. n=1
  1727. app_index=0
  1728. for a in "${APPS_AVAILABLE[@]}"
  1729. do
  1730. if [[ ${APPS_INSTALLED[$app_index]} != "0" ]]; then
  1731. if [[ $(function_exists configure_interactive_${a}) == "1" ]]; then
  1732. applist="$applist $n $a off"
  1733. n=$[n+1]
  1734. appnames+=("$a")
  1735. fi
  1736. fi
  1737. app_index=$[app_index+1]
  1738. done
  1739. if [ $n -le 1 ]; then
  1740. return
  1741. fi
  1742. backstr=$'Exit'
  1743. applist="$applist $n $backstr on"
  1744. appnames+=("Exit")
  1745. choice=$(dialog --stdout --backtitle $"Freedombone" \
  1746. --title $"Change Settings for an App" \
  1747. --radiolist $'Choose:' \
  1748. 16 40 20 $applist)
  1749. if [ $? -eq 0 ]; then
  1750. app_index=$[choice-1]
  1751. chosen_app=${appnames[$app_index]}
  1752. if [[ $chosen_app != "Exit" ]]; then
  1753. configure_interactive_${chosen_app}
  1754. fi
  1755. fi
  1756. }
  1757. function menu_top_level {
  1758. while true
  1759. do
  1760. data=$(tempfile 2>/dev/null)
  1761. trap "rm -f $data" 0 1 2 5 15
  1762. dialog --backtitle $"Freedombone Control Panel" \
  1763. --title $"Control Panel" \
  1764. --radiolist $"Choose an operation:" 28 70 21 \
  1765. 1 $"About this system" off \
  1766. 2 $"Passwords" off \
  1767. 3 $"Backup and Restore" off \
  1768. 4 $"Show Firewall" off \
  1769. 5 $"Reset Tripwire" off \
  1770. 6 $"App Settings" off \
  1771. 7 $"Add/Remove Apps" off \
  1772. 8 $"Logging on/off" off \
  1773. 9 $"Ping enable/disable" off \
  1774. 10 $"Manage Users" off \
  1775. 11 $"Email Menu" off \
  1776. 12 $"Security Settings" off \
  1777. 13 $"Set the main repository (repo mirrors)" off \
  1778. 14 $"Change the name of this system" off \
  1779. 15 $"Set a static local IP address" off \
  1780. 16 $"Wifi menu" off \
  1781. 17 $"Check for updates" off \
  1782. 18 $"Power off the system" off \
  1783. 19 $"Restart the system" off \
  1784. 20 $"Exit" on 2> $data
  1785. sel=$?
  1786. case $sel in
  1787. 1) exit 1;;
  1788. 255) exit 1;;
  1789. esac
  1790. case $(cat $data) in
  1791. 1) show_about;;
  1792. 2) view_or_change_passwords;;
  1793. 3) menu_backup_restore;;
  1794. 4) show_firewall;;
  1795. 5) reset_tripwire;;
  1796. 6) menu_app_settings;;
  1797. 7) ${PROJECT_NAME}-addremove
  1798. if [ ! "$?" = "0" ]; then
  1799. any_key
  1800. fi
  1801. ;;
  1802. 8) logging_on_off;;
  1803. 9) ping_enable_disable;;
  1804. 10) menu_users;;
  1805. 11) menu_email;;
  1806. 12) security_settings;;
  1807. 13) set_main_repo;;
  1808. 14) change_system_name;;
  1809. 15) set_static_IP;;
  1810. 16) menu_wifi;;
  1811. 17) check_for_updates;;
  1812. 18) shut_down_system;;
  1813. 19) restart_system;;
  1814. 20) break;;
  1815. esac
  1816. done
  1817. }
  1818. if [[ $USER != 'root' ]]; then
  1819. # show the user version of the control panel
  1820. ${PROJECT_NAME}-controlpanel-user
  1821. exit 0
  1822. fi
  1823. if [ ! -f $COMPLETION_FILE ]; then
  1824. echo $'This command should only be run on an installed Freedombone system'
  1825. exit 1
  1826. fi
  1827. ADMIN_USER=$(get_completion_param "Admin user")
  1828. read_repo_servers
  1829. menu_top_level
  1830. clear
  1831. cat /etc/motd
  1832. exit 0