freedombone-controlpanel 66KB

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