freedombone-controlpanel 62KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Administrator control panel for the Freedombone system
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. PROJECT_NAME='freedombone'
  31. export TEXTDOMAIN=${PROJECT_NAME}-controlpanel
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. 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. detect_apps
  818. while true
  819. do
  820. app_list=()
  821. n=1
  822. applist="$n $AllStr off"
  823. n=$[n+1]
  824. app_list+=("$AllStr")
  825. util_index=0
  826. for a in "${utils_installed[@]}"
  827. do
  828. applist="$applist $n $a off"
  829. app_name=${utils_installed[util_index]}
  830. n=$[n+1]
  831. util_index=$[util_index+1]
  832. app_list+=("$app_name")
  833. done
  834. app_index=0
  835. for a in "${APPS_INSTALLED_NAMES[@]}"
  836. do
  837. applist="$applist $n $a off"
  838. n=$[n+1]
  839. app_name=${APPS_INSTALLED_NAMES[app_index]}
  840. app_index=$[app_index+1]
  841. app_list+=("$app_name")
  842. done
  843. applist="$applist $n $ExitStr on"
  844. n=$[n+1]
  845. app_list+=("$ExitStr")
  846. choice=$(dialog --stdout --backtitle $"Freedombone" \
  847. --title "$RestoreStr" \
  848. --radiolist $'Choose:' \
  849. 30 50 20 $applist)
  850. if [ $? -ne 0 ]; then
  851. break
  852. fi
  853. app_index=$[choice-1]
  854. app_name=${app_list[app_index]}
  855. # exit
  856. if [[ "$app_name" == "$ExitStr" ]]; then
  857. break
  858. fi
  859. clear
  860. # Restore all
  861. if [[ "$app_name" == "$AllStr" ]]; then
  862. $restore_command
  863. retcode="$?"
  864. if [[ "$retcode" != "0" ]]; then
  865. if [[ "$1" == "local" ]]; then
  866. dialog --title $"Restore all apps from USB" \
  867. --msgbox $"Restore failed with code $retcode" 6 60
  868. else
  869. dialog --title $"Restore all apps from $1" \
  870. --msgbox $"Restore failed with code $retcode" 6 60
  871. fi
  872. break
  873. fi
  874. if [[ "$1" == "local" ]]; then
  875. dialog --title $"Restore all apps from USB" \
  876. --msgbox $"Restore complete" 6 40
  877. else
  878. dialog --title $"Restore all apps from $1" \
  879. --msgbox $"Restore complete" 6 40
  880. fi
  881. break
  882. fi
  883. # Restore an app
  884. $restore_command "${app_name}"
  885. retcode="$?"
  886. if [[ "$retcode" != "0" ]]; then
  887. dialog --title $"Restore apps from USB" \
  888. --msgbox $"Restore of ${app_name} failed with code $retcode" 6 60
  889. return
  890. fi
  891. # finished
  892. if [[ "$1" == "local" ]]; then
  893. dialog --title $"Restore apps from USB" \
  894. --msgbox $"Restore complete" 6 40
  895. else
  896. dialog --title $"Restore apps from $1" \
  897. --msgbox $"Restore complete" 6 40
  898. fi
  899. done
  900. }
  901. function restore_data {
  902. dialog --title $"Restore data from USB" \
  903. --msgbox $"Plug in your backup USB drive" 6 40
  904. clear
  905. echo ' '
  906. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  907. restore_data_from_storage local
  908. }
  909. function restore_data_remote {
  910. if [ ! $ADMIN_USER ]; then
  911. dialog --title $"Restore data from remote server" \
  912. --msgbox $"Unknown admin user" 6 40
  913. return
  914. fi
  915. data=$(tempfile 2>/dev/null)
  916. trap "rm -f $data" 0 1 2 5 15
  917. dialog --title $"Restore from remote server" \
  918. --backtitle $"Freedombone Control Panel" \
  919. --inputbox $"Enter the domain name of the server from which you wish to restore" 8 60 2>$data
  920. sel=$?
  921. case $sel in
  922. 0)
  923. friend_server_domain_name=$(<$data)
  924. if [ ${#friend_server_domain_name} -lt 2 ]; then
  925. return
  926. fi
  927. if [[ $friend_server_domain_name != *"."* ]]; then
  928. dialog --title $"Remote server domain name" \
  929. --msgbox $"Invalid domain name" 6 40
  930. return
  931. fi
  932. restore_data_from_storage $friend_server_domain_name
  933. ;;
  934. esac
  935. }
  936. function ping_enable_disable {
  937. 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."
  938. enable_ping="no"
  939. dialog --title $"Enable Ping / ICMP" \
  940. --backtitle $"Freedombone Control Panel" \
  941. --defaultno \
  942. --yesno "$ping_str" 10 60
  943. sel=$?
  944. case $sel in
  945. 0) enable_ping="yes";;
  946. 255) return;;
  947. esac
  948. if [[ $enable_ping == "yes" ]]; then
  949. iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
  950. iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  951. echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  952. else
  953. iptables -D INPUT -p icmp --icmp-type echo-request -j ACCEPT
  954. iptables -D OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  955. echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  956. fi
  957. }
  958. function logging_on_off {
  959. logging="no"
  960. dialog --title $"Logging" \
  961. --backtitle $"Freedombone Control Panel" \
  962. --yesno $"\nDo you want to turn logging on?" 7 60
  963. sel=$?
  964. case $sel in
  965. 0) logging="yes";;
  966. 255) return;;
  967. esac
  968. clear
  969. echo ''
  970. echo $'This may take a few seconds. Please wait...'
  971. if [[ $logging == "no" ]]; then
  972. ${PROJECT_NAME}-logging off
  973. else
  974. ${PROJECT_NAME}-logging on
  975. fi
  976. }
  977. function restore_gpg_key {
  978. select_user
  979. if [ ! $SELECTED_USERNAME ]; then
  980. return
  981. fi
  982. restorestr=$"Restore GPG key for user"
  983. dialog --title "$restorestr $SELECTED_USERNAME" \
  984. --msgbox $"Plug in your USB keydrive" 6 40
  985. clear
  986. ${PROJECT_NAME}-recoverkey -u $SELECTED_USERNAME
  987. any_key
  988. }
  989. function security_settings {
  990. ${PROJECT_NAME}-sec
  991. any_key
  992. }
  993. function reset_tripwire {
  994. if [ ! -f /usr/bin/reset-tripwire ]; then
  995. return
  996. fi
  997. clear
  998. echo $'Resetting the Tripwire...'
  999. echo ' '
  1000. echo '
  1001. ' | reset-tripwire
  1002. any_key
  1003. }
  1004. function format_drive {
  1005. detect_usb_drive
  1006. data=$(tempfile 2>/dev/null)
  1007. trap "rm -f $data" 0 1 2 5 15
  1008. dialog --title $"Format USB drive $USB_DRIVE" \
  1009. --backtitle $"Freedombone Control Panel" \
  1010. --defaultno \
  1011. --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
  1012. sel=$?
  1013. case $sel in
  1014. 1) return;;
  1015. 255) return;;
  1016. esac
  1017. clear
  1018. echo ''
  1019. echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
  1020. echo ''
  1021. ${PROJECT_NAME}-format $USB_DRIVE
  1022. any_key
  1023. }
  1024. function remove_backups {
  1025. detect_usb_drive
  1026. data=$(tempfile 2>/dev/null)
  1027. trap "rm -f $data" 0 1 2 5 15
  1028. dialog --title $"Remove backups from a USB drive $USB_DRIVE" \
  1029. --backtitle $"Freedombone Control Panel" \
  1030. --defaultno \
  1031. --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
  1032. sel=$?
  1033. case $sel in
  1034. 1) return;;
  1035. 255) return;;
  1036. esac
  1037. clear
  1038. ${PROJECT_NAME}-backup-local $USB_DRIVE remove
  1039. any_key
  1040. }
  1041. function shut_down_system {
  1042. dialog --title $"Power off the system" \
  1043. --backtitle $"Freedombone Control Panel" \
  1044. --defaultno \
  1045. --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
  1046. sel=$?
  1047. case $sel in
  1048. 1) return;;
  1049. 255) return;;
  1050. esac
  1051. shutdown now
  1052. }
  1053. function restart_system {
  1054. dialog --title $"Restart the system" \
  1055. --backtitle $"Freedombone Control Panel" \
  1056. --defaultno \
  1057. --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
  1058. sel=$?
  1059. case $sel in
  1060. 1) return;;
  1061. 255) return;;
  1062. esac
  1063. reboot
  1064. }
  1065. function change_system_name {
  1066. data=$(tempfile 2>/dev/null)
  1067. trap "rm -f $data" 0 1 2 5 15
  1068. dialog --title $"Change the name of this system" \
  1069. --backtitle $"Freedombone Control Panel" \
  1070. --inputbox $'Enter a new name for this system on your local network\n\nIt will appear as newname.local' 10 60 2>$data
  1071. sel=$?
  1072. case $sel in
  1073. 0) NEW_SYSTEM_NAME=$(<$data)
  1074. if [ "$NEW_SYSTEM_NAME" ]; then
  1075. if [ ${#NEW_SYSTEM_NAME} -gt 1 ]; then
  1076. sed -i "s|host-name=.*|host-name=$NEW_SYSTEM_NAME|g" /etc/avahi/avahi-daemon.conf
  1077. systemctl restart avahi-daemon
  1078. if grep -q "host-name=$NEW_SYSTEM_NAME" /etc/avahi/avahi-daemon.conf; then
  1079. dialog --title $"New local network name" \
  1080. --msgbox $"The name of this system on your local network was changed successfully" 6 70
  1081. fi
  1082. fi
  1083. fi
  1084. ;;
  1085. esac
  1086. }
  1087. function set_dynamic_IP {
  1088. NETWORK_IS_STATIC=0
  1089. read_config_param "NETWORK_IS_STATIC"
  1090. if [ ${NETWORK_IS_STATIC} -eq 0 ]; then
  1091. return
  1092. fi
  1093. revert_to_dynamic=
  1094. dialog --title $"Return to using a dynamic IP address" \
  1095. --backtitle $"Freedombone Control Panel" \
  1096. --yesno $"\nDo you wish to go back to using a dynamic IP address?" 8 60
  1097. sel=$?
  1098. case $sel in
  1099. 0) revert_to_dynamic=1
  1100. ;;
  1101. 1) return;;
  1102. esac
  1103. if [ $revert_to_dynamic ]; then
  1104. wifi_original_network_settings
  1105. clear
  1106. echo ''
  1107. echo $'Changing to a dynamic IP address.'
  1108. echo ''
  1109. echo $"System is rebooting. You may need to close this terminal and log in from a new one."
  1110. reboot
  1111. fi
  1112. }
  1113. function set_static_IP {
  1114. IPv4_address=$(get_ipv4_address)
  1115. IPv4_address_base=$(echo "$IPv4_address" | awk -F '.' '{print $1"."$2"."$3}')
  1116. STATIC_IP="${IPv4_address_base}.60"
  1117. STATIC_GATEWAY="${IPv4_address_base}.1"
  1118. NEW_STATIC_IP=
  1119. NEW_STATIC_GATEWAY=
  1120. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1121. STATIC_IP=$(cat /etc/network/interfaces | grep "address " | head -n 1 | awk -F ' ' '{print $2}')
  1122. STATIC_GATEWAY=$(cat /etc/network/interfaces | grep "gateway " | head -n 1 | awk -F ' ' '{print $2}')
  1123. fi
  1124. # get the IP for the box
  1125. data=$(tempfile 2>/dev/null)
  1126. trap "rm -f $data" 0 1 2 5 15
  1127. dialog --title $"Set a static local IP address" \
  1128. --backtitle $"Freedombone Control Panel" \
  1129. --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
  1130. 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
  1131. sel=$?
  1132. case $sel in
  1133. 0) NEW_STATIC_IP=$(<$data)
  1134. if [[ "$NEW_STATIC_IP" != *"."* ]]; then
  1135. set_dynamic_IP
  1136. return
  1137. fi
  1138. ;;
  1139. 1) return;;
  1140. esac
  1141. # get the gateway
  1142. data=$(tempfile 2>/dev/null)
  1143. trap "rm -f $data" 0 1 2 5 15
  1144. dialog --title $"Set the IP address of your internet router/modem" \
  1145. --backtitle $"Freedombone Control Panel" \
  1146. --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
  1147. sel=$?
  1148. case $sel in
  1149. 0) NEW_STATIC_GATEWAY=$(<$data)
  1150. if [[ "$NEW_STATIC_GATEWAY" != *"."* ]]; then
  1151. return
  1152. fi
  1153. ;;
  1154. 1) return;;
  1155. esac
  1156. if [[ "$NEW_STATIC_GATEWAY" == *"."* && "$NEW_STATIC_IP" == *"."* ]]; then
  1157. ip_addresses_have_changed=
  1158. if ! grep -q "address ${NEW_STATIC_IP}" /etc/network/interfaces; then
  1159. ip_addresses_have_changed=1
  1160. fi
  1161. if ! grep -q "gateway ${NEW_STATIC_GATEWAY}" /etc/network/interfaces; then
  1162. ip_addresses_have_changed=1
  1163. fi
  1164. if [ $ip_addresses_have_changed ]; then
  1165. write_config_param "NETWORK_IS_STATIC" "1"
  1166. write_config_param "LOCAL_NETWORK_STATIC_IP_ADDRESS" "$NEW_STATIC_IP"
  1167. write_config_param "ROUTER_IP_ADDRESS" "$NEW_STATIC_GATEWAY"
  1168. email_change_relay "$NEW_STATIC_IP"
  1169. if [[ $(config_param_exists "WIFI_INTERFACE") == "0" ]]; then
  1170. # wired network
  1171. echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
  1172. echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
  1173. echo '' >> /etc/network/interfaces
  1174. echo '# The loopback network interface' >> /etc/network/interfaces
  1175. echo 'auto lo' >> /etc/network/interfaces
  1176. echo 'iface lo inet loopback' >> /etc/network/interfaces
  1177. echo '' >> /etc/network/interfaces
  1178. echo '# The primary network interface' >> /etc/network/interfaces
  1179. echo 'auto eth0' >> /etc/network/interfaces
  1180. echo 'iface eth0 inet static' >> /etc/network/interfaces
  1181. echo " address ${NEW_STATIC_IP}" >> /etc/network/interfaces
  1182. echo ' netmask 255.255.255.0' >> /etc/network/interfaces
  1183. echo " gateway ${NEW_STATIC_GATEWAY}" >> /etc/network/interfaces
  1184. echo " dns-nameservers 213.73.91.35 85.214.20.141" >> /etc/network/interfaces
  1185. echo '# Example to keep MAC address between reboots' >> /etc/network/interfaces
  1186. echo '#hwaddress ether DE:AD:BE:EF:CA:FE' >> /etc/network/interfaces
  1187. echo '' >> /etc/network/interfaces
  1188. echo '# The secondary network interface' >> /etc/network/interfaces
  1189. echo '#auto eth1' >> /etc/network/interfaces
  1190. echo '#iface eth1 inet dhcp' >> /etc/network/interfaces
  1191. echo '' >> /etc/network/interfaces
  1192. echo '# WiFi Example' >> /etc/network/interfaces
  1193. echo "#auto $WIFI_INTERFACE" >> /etc/network/interfaces
  1194. echo "#iface $WIFI_INTERFACE inet dhcp" >> /etc/network/interfaces
  1195. echo '# wpa-ssid "essid"' >> /etc/network/interfaces
  1196. echo '# wpa-psk "password"' >> /etc/network/interfaces
  1197. echo '' >> /etc/network/interfaces
  1198. echo '# Ethernet/RNDIS gadget (g_ether)' >> /etc/network/interfaces
  1199. echo '# ... or on host side, usbnet and random hwaddr' >> /etc/network/interfaces
  1200. echo '# Note on some boards, usb0 is automaticly setup with an init script' >> /etc/network/interfaces
  1201. echo '#iface usb0 inet static' >> /etc/network/interfaces
  1202. echo '# address 192.168.7.2' >> /etc/network/interfaces
  1203. echo '# netmask 255.255.255.0' >> /etc/network/interfaces
  1204. echo '# network 192.168.7.0' >> /etc/network/interfaces
  1205. echo '# gateway 192.168.7.1' >> /etc/network/interfaces
  1206. fi
  1207. clear
  1208. echo ''
  1209. echo $'Restarting the network daemon.'
  1210. echo ''
  1211. 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.'
  1212. function_check pihole_change_ipv4
  1213. pihole_change_ipv4 ${NEW_STATIC_IP}
  1214. dialog --title $"Static local IP address" \
  1215. --backtitle $"Freedombone Control Panel" \
  1216. --yesno $"\nFor the change to take effect your system will now need to reboot. Do this now?" 8 60
  1217. sel=$?
  1218. case $sel in
  1219. 0) reboot;;
  1220. esac
  1221. fi
  1222. fi
  1223. }
  1224. function wifi_settings {
  1225. if [ -f /etc/hostapd/hostapd.conf ]; then
  1226. return
  1227. fi
  1228. TEMP_WIFI_NETWORKS_FILE=~/.temp-${PROJECT_NAME}-wifi.cfg
  1229. ${PROJECT_NAME}-wifi --networksinteractive $TEMP_WIFI_NETWORKS_FILE
  1230. if [ -f $TEMP_WIFI_NETWORKS_FILE ]; then
  1231. cp $TEMP_WIFI_NETWORKS_FILE $WIFI_NETWORKS_FILE
  1232. rm $TEMP_WIFI_NETWORKS_FILE
  1233. ${PROJECT_NAME}-wifi --networks $WIFI_NETWORKS_FILE
  1234. create_wifi_startup_script
  1235. if [[ $(wifi_is_running) == "1" ]]; then
  1236. dialog --title $"Wifi Settings" \
  1237. --msgbox $"Wifi settings were changed." 6 60
  1238. else
  1239. dialog --title $"Wifi Settings" \
  1240. --msgbox $"Wifi settings were changed. You will need to restart the system with ethernet cable removed for the changes to take effect." 7 60
  1241. fi
  1242. else
  1243. remove_wifi_startup_script
  1244. fi
  1245. }
  1246. function wifi_edit_networks {
  1247. if [ -f /etc/hostapd/hostapd.conf ]; then
  1248. return
  1249. fi
  1250. if [ ! -f $WIFI_NETWORKS_FILE ]; then
  1251. echo $'# Add wifi networks as follows:' > $WIFI_NETWORKS_FILE
  1252. echo '#' >> $WIFI_NETWORKS_FILE
  1253. echo $'# MySSID' >> $WIFI_NETWORKS_FILE
  1254. echo $'# wpa2-psk' >> $WIFI_NETWORKS_FILE
  1255. echo $'# myWifiPassphrase' >> $WIFI_NETWORKS_FILE
  1256. echo '#' >> $WIFI_NETWORKS_FILE
  1257. echo $'# AnotherSSID' >> $WIFI_NETWORKS_FILE
  1258. echo $'# none' >> $WIFI_NETWORKS_FILE
  1259. echo '#' >> $WIFI_NETWORKS_FILE
  1260. fi
  1261. editor $WIFI_NETWORKS_FILE
  1262. ${PROJECT_NAME}-wifi --networks $WIFI_NETWORKS_FILE
  1263. }
  1264. function hotspot_settings {
  1265. data=$(tempfile 2>/dev/null)
  1266. trap "rm -f $data" 0 1 2 5 15
  1267. dialog --backtitle $"Freedombone Control Panel" \
  1268. --title $"Hotspot Settings" \
  1269. --form $"" 10 60 4 \
  1270. $"Enabled (yes/no):" 1 1 "$WIFI_HOTSPOT" 1 24 5 5 \
  1271. $"SSID:" 2 1 "$WIFI_SSID" 2 24 256 256 \
  1272. $"Type (wpa2-psk/none):" 3 1 "$WIFI_TYPE" 3 24 10 10 \
  1273. $"Passphrase:" 4 1 "$WIFI_PASSPHRASE" 4 24 256 256 \
  1274. 2> $data
  1275. sel=$?
  1276. case $sel in
  1277. 1) return;;
  1278. 255) return;;
  1279. esac
  1280. TEMP_WIFI_HOTSPOT=$(cat $data | sed -n 1p)
  1281. TEMP_WIFI_SSID=$(cat $data | sed -n 2p)
  1282. TEMP_WIFI_TYPE=$(cat $data | sed -n 3p)
  1283. TEMP_WIFI_PASSPHRASE=$(cat $data | sed -n 4p)
  1284. if [ ${#TEMP_WIFI_SSID} -lt 2 ]; then
  1285. return
  1286. fi
  1287. if [ ${#TEMP_WIFI_TYPE} -lt 2 ]; then
  1288. return
  1289. fi
  1290. WIFI_EXTRA=''
  1291. if [[ $TEMP_WIFI_HOTSPOT == $'yes' || $TEMP_WIFI_HOTSPOT == $'y' || $TEMP_WIFI_HOTSPOT == $'on' ]]; then
  1292. TEMP_WIFI_HOTSPOT='yes'
  1293. else
  1294. TEMP_WIFI_HOTSPOT='no'
  1295. if [ -f $WIFI_NETWORKS_FILE ]; then
  1296. WIFI_EXTRA='--networks $WIFI_NETWORKS_FILE'
  1297. fi
  1298. fi
  1299. if [[ $TEMP_WIFI_TYPE != $'none' ]]; then
  1300. if [ ! $TEMP_WIFI_PASSPHRASE ]; then
  1301. dialog --title $"Wifi Settings" \
  1302. --msgbox $"No wifi hotspot passphrase was given" 6 40
  1303. return
  1304. fi
  1305. if [ ${#TEMP_WIFI_PASSPHRASE} -lt 2 ]; then
  1306. dialog --title $"Wifi Settings" \
  1307. --msgbox $"Wifi hotspot passphrase was too short" 6 40
  1308. return
  1309. fi
  1310. WIFI_HOTSPOT=$TEMP_WIFI_HOTSPOT
  1311. WIFI_SSID=$TEMP_WIFI_SSID
  1312. WIFI_TYPE=$TEMP_WIFI_TYPE
  1313. WIFI_PASSPHRASE=$TEMP_WIFI_PASSPHRASE
  1314. ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE -p $WIFI_PASSPHRASE --hotspot $WIFI_HOTSPOT $WIFI_EXTRA
  1315. else
  1316. WIFI_HOTSPOT=$TEMP_WIFI_HOTSPOT
  1317. WIFI_SSID=$TEMP_WIFI_SSID
  1318. WIFI_TYPE=$TEMP_WIFI_TYPE
  1319. WIFI_PASSPHRASE=$TEMP_WIFI_PASSPHRASE
  1320. ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE --hotspot $WIFI_HOTSPOT $WIFI_EXTRA
  1321. fi
  1322. # store any changes
  1323. write_config_param "WIFI_HOTSPOT" "$WIFI_HOTSPOT"
  1324. write_config_param "WIFI_SSID" "$WIFI_SSID"
  1325. write_config_param "WIFI_TYPE" "$WIFI_TYPE"
  1326. write_config_param "WIFI_PASSPHRASE" "$WIFI_PASSPHRASE"
  1327. dialog --title $"Wifi Settings" \
  1328. --msgbox $"Hotspot settings were changed" 6 40
  1329. }
  1330. function reinstall_mariadb {
  1331. dialog --title $"Reinstall MariaDB" \
  1332. --backtitle $"Freedombone Control Panel" \
  1333. --defaultno \
  1334. --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
  1335. sel=$?
  1336. case $sel in
  1337. 1) return;;
  1338. 255) return;;
  1339. esac
  1340. clear
  1341. database_reinstall
  1342. dialog --title $"Reinstall MariaDB" \
  1343. --msgbox $"MariaDB has been reinstalled" 6 40
  1344. }
  1345. function show_firewall {
  1346. clear
  1347. echo $"Firewall Settings"
  1348. echo ''
  1349. while read line; do
  1350. firewall_name=$(echo "$line" | awk -F '=' '{print $1}')
  1351. firewall_port=$(echo "$line" | awk -F '=' '{print $2}')
  1352. echo -n -e "$(pad_string ${firewall_name})"
  1353. echo "${firewall_port}"
  1354. done < $FIREWALL_CONFIG
  1355. any_key
  1356. }
  1357. function email_extra_domains {
  1358. email_hostnames=$(cat /etc/exim4/update-exim4.conf.conf | grep "dc_other_hostnames" | awk -F "'" '{print $2}')
  1359. data=$(tempfile 2>/dev/null)
  1360. trap "rm -f $data" 0 1 2 5 15
  1361. dialog --title $"Email Domains" \
  1362. --backtitle $"Freedombone Control Panel" \
  1363. --inputbox $"Enter the list of email domains to use, separated by semicolons" 8 60 $email_hostnames 2>$data
  1364. sel=$?
  1365. case $sel in
  1366. 0)
  1367. emailhostnames=$(<$data)
  1368. if [ ${#emailhostnames} -gt 2 ]; then
  1369. if [[ "$email_hostnames" != "$emailhostnames" ]]; then
  1370. if [[ "$emailhostnames" == *"."* ]]; then
  1371. if [[ "$emailhostnames" != *" "* ]]; then
  1372. sed -i "s|dc_other_hostnames=.*|dc_other_hostnames='$emailhostnames'|g" /etc/exim4/update-exim4.conf.conf
  1373. update-exim4.conf
  1374. dpkg-reconfigure --frontend noninteractive exim4-config
  1375. systemctl restart saslauthd
  1376. dialog --title $"Email Domains" \
  1377. --backtitle $"Freedombone Control Panel" \
  1378. --msgbox $"Email domains were changed" 6 50
  1379. else
  1380. dialog --title $"Email Domains not set" \
  1381. --backtitle $"Freedombone Control Panel" \
  1382. --msgbox $"There should be no spaces in the list" 6 50
  1383. fi
  1384. fi
  1385. fi
  1386. fi
  1387. ;;
  1388. esac
  1389. }
  1390. function email_smtp_proxy {
  1391. MUTTRC_FILE=/home/$ADMIN_USER/.muttrc
  1392. if [ ! -f $MUTTRC_FILE ]; then
  1393. return
  1394. fi
  1395. data=$(tempfile 2>/dev/null)
  1396. trap "rm -f $data" 0 1 2 5 15
  1397. dialog --backtitle $"Freedombone Control Panel" \
  1398. --title $"SMTP Proxy for $ADMIN_USER" \
  1399. --form $"You may need to proxy outgoing email via your ISP's mail server. If so enter the details below." 14 75 6 \
  1400. $"Enable proxy:" 1 1 "$SMTP_PROXY_ENABLE" 1 24 5 5 \
  1401. $"Protocol (smtp/smtps):" 2 1 "$SMTP_PROXY_PROTOCOL" 2 24 5 5 \
  1402. $"ISP mail server:" 3 1 "$SMTP_PROXY_SERVER" 3 24 40 10000 \
  1403. $"Port:" 4 1 "$SMTP_PROXY_PORT" 4 24 5 5 \
  1404. $"Username:" 5 1 "$SMTP_PROXY_USERNAME" 5 24 40 10000 \
  1405. $"Password:" 6 1 "$SMTP_PROXY_PASSWORD" 6 24 40 10000 \
  1406. 2> $data
  1407. sel=$?
  1408. case $sel in
  1409. 1) return;;
  1410. 255) return;;
  1411. esac
  1412. SMTP_PROXY_ENABLE=$(cat $data | sed -n 1p)
  1413. SMTP_PROXY_PROTOCOL=$(cat $data | sed -n 2p)
  1414. SMTP_PROXY_SERVER=$(cat $data | sed -n 3p)
  1415. SMTP_PROXY_PORT=$(cat $data | sed -n 4p)
  1416. SMTP_PROXY_USERNAME=$(cat $data | sed -n 5p)
  1417. SMTP_PROXY_PASSWORD=$(cat $data | sed -n 6p)
  1418. # change muttrc
  1419. if [ $SMTP_PROXY_ENABLE != $'no' ]; then
  1420. if ! grep "set smtp_url" $MUTTRC_FILE; then
  1421. echo "set smtp_url=\"${SMTP_PROXY_PROTOCOL}://${SMTP_PROXY_USERNAME}:${SMTP_PROXY_PASSWORD}@${SMTP_PROXY_SERVER}:${SMTP_PROXY_PORT}/\"" >> $MUTTRC_FILE
  1422. else
  1423. 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
  1424. fi
  1425. sed -i 's|#set smtp_url|set smtp_url|g' $MUTTRC_FILE
  1426. else
  1427. if grep "set smtp_url" $MUTTRC_FILE; then
  1428. sed -i 's|set smtp_url|#set smtp_url|g' $MUTTRC_FILE
  1429. fi
  1430. fi
  1431. # save settings within the main configuration file
  1432. write_config_param "SMTP_PROXY_ENABLE" "$SMTP_PROXY_ENABLE"
  1433. write_config_param "SMTP_PROXY_PROTOCOL" "$SMTP_PROXY_PROTOCOL"
  1434. write_config_param "SMTP_PROXY_SERVER" "$SMTP_PROXY_SERVER"
  1435. write_config_param "SMTP_PROXY_PORT" "$SMTP_PROXY_PORT"
  1436. write_config_param "SMTP_PROXY_USERNAME" "$SMTP_PROXY_USERNAME"
  1437. write_config_param "SMTP_PROXY_PASSWORD" "$SMTP_PROXY_PASSWORD"
  1438. }
  1439. function menu_backup_restore {
  1440. while true
  1441. do
  1442. data=$(tempfile 2>/dev/null)
  1443. trap "rm -f $data" 0 1 2 5 15
  1444. dialog --backtitle $"Freedombone Control Panel" \
  1445. --title $"Backup and Restore" \
  1446. --radiolist $"Choose an operation:" 19 70 12 \
  1447. 1 $"Backup data to USB drive" off \
  1448. 2 $"Restore GPG key from USB keydrive" off \
  1449. 3 $"Restore data from USB drive" off \
  1450. 4 $"Reinstall mariadb" off \
  1451. 5 $"Configure remote backups" off \
  1452. 6 $"Restore from remote backup" off \
  1453. 7 $"Backup GPG key to USB (master keydrive)" off \
  1454. 8 $"Backup GPG key to USB (fragment keydrive)" off \
  1455. 9 $"Format a USB drive (LUKS encrypted)" off \
  1456. 10 $"Remove backups from a USB drive" off \
  1457. 11 $"Back to main menu" on 2> $data
  1458. sel=$?
  1459. case $sel in
  1460. 1) break;;
  1461. 255) break;;
  1462. esac
  1463. case $(cat $data) in
  1464. 1) backup_data;;
  1465. 2) restore_gpg_key;;
  1466. 3) restore_data;;
  1467. 4) reinstall_mariadb;;
  1468. 5) configure_remote_backups;;
  1469. 6) restore_data_remote;;
  1470. 7) create_keydrive_master;;
  1471. 8) create_keydrive_fragment;;
  1472. 9) format_drive;;
  1473. 10) remove_backups;;
  1474. 11) break;;
  1475. esac
  1476. done
  1477. }
  1478. function menu_email {
  1479. while true
  1480. do
  1481. data=$(tempfile 2>/dev/null)
  1482. trap "rm -f $data" 0 1 2 5 15
  1483. dialog --backtitle $"Freedombone Control Panel" \
  1484. --title $"Email Menu" \
  1485. --radiolist $"Choose an operation:" 15 70 8 \
  1486. 1 $"Add a user to a mailing list" off \
  1487. 2 $"Remove a user from a mailing list" off \
  1488. 3 $"Add an email rule" off \
  1489. 4 $"Block/Unblock an email address" off \
  1490. 5 $"Block/Unblock email with subject text" off \
  1491. 6 $"Outgoing Email Proxy" off \
  1492. 7 $"Extra email domains" off \
  1493. 8 $"Back to main menu" on 2> $data
  1494. sel=$?
  1495. case $sel in
  1496. 1) break;;
  1497. 255) break;;
  1498. esac
  1499. case $(cat $data) in
  1500. 1) add_to_mailing_list;;
  1501. 2) remove_user_from_mailing_list;;
  1502. 3) email_rule;;
  1503. 4) block_unblock_email;;
  1504. 5) block_unblock_subject;;
  1505. 6) email_smtp_proxy;;
  1506. 7) email_extra_domains;;
  1507. 8) break;;
  1508. esac
  1509. done
  1510. }
  1511. function menu_users {
  1512. while true
  1513. do
  1514. data=$(tempfile 2>/dev/null)
  1515. trap "rm -f $data" 0 1 2 5 15
  1516. dialog --backtitle $"Freedombone Control Panel" \
  1517. --title $"Manage Users" \
  1518. --radiolist $"Choose an operation:" 12 70 5 \
  1519. 1 $"Add a user" off \
  1520. 2 $"Delete a user" off \
  1521. 3 $"Change user password" off \
  1522. 4 $"Change user ssh public key" off \
  1523. 5 $"Back to main menu" on 2> $data
  1524. sel=$?
  1525. case $sel in
  1526. 1) break;;
  1527. 255) break;;
  1528. esac
  1529. case $(cat $data) in
  1530. 1) add_user;;
  1531. 2) delete_user;;
  1532. 3) change_password;;
  1533. 4) change_ssh_public_key;;
  1534. 5) break;;
  1535. esac
  1536. done
  1537. }
  1538. function wifi_enable {
  1539. disable_wifi='yes'
  1540. dialog --title $"Enable Wifi" \
  1541. --backtitle $"Freedombone Control Panel" \
  1542. --defaultno \
  1543. --yesno $"\nDo you wish to enable wifi?" 10 50
  1544. sel=$?
  1545. case $sel in
  1546. 0) disable_wifi='no';;
  1547. 1) disable_wifi='yes';;
  1548. 255) return;;
  1549. esac
  1550. ${PROJECT_NAME}-wifi --disable $disable_wifi
  1551. }
  1552. function menu_wifi {
  1553. while true
  1554. do
  1555. status_str=$'Wifi OFF'
  1556. if [ -f /etc/hostapd/hostapd.conf ]; then
  1557. status_str=$'Hotspot ON'
  1558. else
  1559. if grep -q "# wifi enabled" /etc/network/interfaces; then
  1560. status_str=$'Wifi ON'
  1561. fi
  1562. fi
  1563. data=$(tempfile 2>/dev/null)
  1564. trap "rm -f $data" 0 1 2 5 15
  1565. dialog --backtitle $"Freedombone Control Panel" \
  1566. --title $"Wifi Menu" \
  1567. --radiolist $"${status_str}\n\nChoose an operation:" 14 70 6 \
  1568. 1 $"Enable or disable Wifi" off \
  1569. 2 $"Configure wifi networks" off \
  1570. 3 $"Manually edit wifi networks file" off \
  1571. 4 $"Hotspot settings" off \
  1572. 5 $"Exit" on 2> $data
  1573. sel=$?
  1574. case $sel in
  1575. 1) break;;
  1576. 255) break;;
  1577. esac
  1578. case $(cat $data) in
  1579. 1) wifi_enable;;
  1580. 2) wifi_settings;;
  1581. 3) wifi_edit_networks;;
  1582. 4) hotspot_settings;;
  1583. 5) break;;
  1584. esac
  1585. done
  1586. }
  1587. function menu_app_settings {
  1588. detect_installable_apps
  1589. applist=""
  1590. appnames=()
  1591. n=1
  1592. app_index=0
  1593. for a in "${APPS_AVAILABLE[@]}"
  1594. do
  1595. if [[ ${APPS_INSTALLED[$app_index]} != "0" ]]; then
  1596. if [[ $(function_exists configure_interactive_${a}) == "1" ]]; then
  1597. applist="$applist $n $a off"
  1598. n=$[n+1]
  1599. appnames+=("$a")
  1600. fi
  1601. fi
  1602. app_index=$[app_index+1]
  1603. done
  1604. if [ $n -le 1 ]; then
  1605. return
  1606. fi
  1607. backstr=$'Exit'
  1608. applist="$applist $n $backstr on"
  1609. appnames+=("Exit")
  1610. choice=$(dialog --stdout --backtitle $"Freedombone" \
  1611. --title $"Change Settings for an App" \
  1612. --radiolist $'Choose:' \
  1613. 16 40 20 $applist)
  1614. if [ $? -eq 0 ]; then
  1615. app_index=$[choice-1]
  1616. chosen_app=${appnames[$app_index]}
  1617. if [[ $chosen_app != "Exit" ]]; then
  1618. configure_interactive_${chosen_app}
  1619. fi
  1620. fi
  1621. }
  1622. function menu_top_level {
  1623. while true
  1624. do
  1625. data=$(tempfile 2>/dev/null)
  1626. trap "rm -f $data" 0 1 2 5 15
  1627. dialog --backtitle $"Freedombone Control Panel" \
  1628. --title $"Control Panel" \
  1629. --radiolist $"Choose an operation:" 27 70 20 \
  1630. 1 $"About this system" off \
  1631. 2 $"Backup and Restore" off \
  1632. 3 $"Show Firewall" off \
  1633. 4 $"Reset Tripwire" off \
  1634. 5 $"App Settings" off \
  1635. 6 $"Add/Remove Apps" off \
  1636. 7 $"Logging on/off" off \
  1637. 8 $"Ping enable/disable" off \
  1638. 9 $"Manage Users" off \
  1639. 10 $"Email Menu" off \
  1640. 11 $"Security Settings" off \
  1641. 12 $"Set the main repository (repo mirrors)" off \
  1642. 13 $"Change the name of this system" off \
  1643. 14 $"Set a static local IP address" off \
  1644. 15 $"Wifi menu" off \
  1645. 16 $"Check for updates" off \
  1646. 17 $"Power off the system" off \
  1647. 18 $"Restart the system" off \
  1648. 19 $"Exit" on 2> $data
  1649. sel=$?
  1650. case $sel in
  1651. 1) exit 1;;
  1652. 255) exit 1;;
  1653. esac
  1654. case $(cat $data) in
  1655. 1) show_about;;
  1656. 2) menu_backup_restore;;
  1657. 3) show_firewall;;
  1658. 4) reset_tripwire;;
  1659. 5) menu_app_settings;;
  1660. 6) ${PROJECT_NAME}-addremove;;
  1661. 7) logging_on_off;;
  1662. 8) ping_enable_disable;;
  1663. 9) menu_users;;
  1664. 10) menu_email;;
  1665. 11) security_settings;;
  1666. 12) set_main_repo;;
  1667. 13) change_system_name;;
  1668. 14) set_static_IP;;
  1669. 15) menu_wifi;;
  1670. 16) check_for_updates;;
  1671. 17) shut_down_system;;
  1672. 18) restart_system;;
  1673. 19) break;;
  1674. esac
  1675. done
  1676. }
  1677. if [[ $USER != 'root' ]]; then
  1678. # show the user version of the control panel
  1679. ${PROJECT_NAME}-controlpanel-user
  1680. exit 0
  1681. fi
  1682. if [ ! -f $COMPLETION_FILE ]; then
  1683. echo $'This command should only be run on an installed Freedombone system'
  1684. exit 1
  1685. fi
  1686. ADMIN_USER=$(get_completion_param "Admin user")
  1687. read_repo_servers
  1688. menu_top_level
  1689. clear
  1690. cat /etc/motd
  1691. exit 0