freedombone-controlpanel 69KB

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