freedombone-controlpanel 70KB

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