freedombone-controlpanel 62KB

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