freedombone-sec 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Alters the security settings
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2015 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 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 General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. SSL_PROTOCOLS=
  31. SSL_CIPHERS=
  32. SSH_CIPHERS=
  33. SSH_MACS=
  34. SSH_KEX=
  35. SSH_HOST_KEY_ALGORITHMS=
  36. SSH_PASSWORDS=
  37. XMPP_CIPHERS=
  38. XMPP_ECC_CURVE=
  39. WEBSITES_DIRECTORY='/etc/nginx/sites-available'
  40. DOVECOT_CIPHERS='/etc/dovecot/conf.d/10-ssl.conf'
  41. SSH_CONFIG='/etc/ssh/sshd_config'
  42. XMPP_CONFIG='/etc/prosody/conf.avail/xmpp.cfg.lua'
  43. MINIMUM_LENGTH=6
  44. IMPORT_FILE=
  45. EXPORT_FILE=
  46. CURRENT_DIR=$(pwd)
  47. function get_protocols_from_website {
  48. if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
  49. return
  50. fi
  51. SSL_PROTOCOLS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_protocols ' | awk -F "ssl_protocols " '{print $2}' | awk -F ';' '{print $1}')
  52. }
  53. function get_ciphers_from_website {
  54. if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
  55. return
  56. fi
  57. SSL_CIPHERS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_ciphers ' | awk -F "ssl_ciphers " '{print $2}' | awk -F "'" '{print $2}')
  58. }
  59. function get_website_settings {
  60. if [ ! -d $WEBSITES_DIRECTORY ]; then
  61. return
  62. fi
  63. cd $WEBSITES_DIRECTORY
  64. for file in `dir -d *` ; do
  65. get_protocols_from_website $file
  66. if [ ${#SSL_PROTOCOLS} -gt $MINIMUM_LENGTH ]; then
  67. get_ciphers_from_website $file
  68. if [ ${#SSL_CIPHERS} -gt $MINIMUM_LENGTH ]; then
  69. break
  70. else
  71. SSL_PROTOCOLS=""
  72. fi
  73. fi
  74. done
  75. }
  76. function get_imap_settings {
  77. if [ ! -f $DOVECOT_CIPHERS ]; then
  78. return
  79. fi
  80. # clear commented out cipher list
  81. sed -i "s|#ssl_cipher_list.*||g" $DOVECOT_CIPHERS
  82. if [ $SSL_CIPHERS ]; then
  83. return
  84. fi
  85. if [ ${#SSL_CIPHERS} -gt $MINIMUM_LENGTH ]; then
  86. return
  87. fi
  88. SSL_CIPHERS=$(cat $DOVECOT_CIPHERS | grep 'ssl_cipher_list' | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
  89. }
  90. function get_xmpp_settings {
  91. if [ ! -f $XMPP_CONFIG ]; then
  92. return
  93. fi
  94. XMPP_CIPHERS=$(cat $XMPP_CONFIG | grep 'ciphers ' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  95. XMPP_ECC_CURVE=$(cat $XMPP_CONFIG | grep 'curve ' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  96. }
  97. function get_ssh_settings {
  98. if [ -f $SSH_CONFIG ]; then
  99. SSH_CIPHERS=$(cat $SSH_CONFIG | grep 'Ciphers ' | awk -F 'Ciphers ' '{print $2}')
  100. SSH_MACS=$(cat $SSH_CONFIG | grep 'MACs ' | awk -F 'MACs ' '{print $2}')
  101. SSH_KEX=$(cat $SSH_CONFIG | grep 'KexAlgorithms ' | awk -F 'KexAlgorithms ' '{print $2}')
  102. SSH_PASSWORDS=$(cat $SSH_CONFIG | grep 'PasswordAuthentication ' | awk -F 'PasswordAuthentication ' '{print $2}')
  103. fi
  104. if [ -f /etc/ssh/ssh_config ]; then
  105. SSH_HOST_KEY_ALGORITHMS=$(cat /etc/ssh/ssh_config | grep 'HostKeyAlgorithms ' | awk -F 'HostKeyAlgorithms ' '{print $2}')
  106. if [ ! $SSH_CIPHERS ]; then
  107. SSH_CIPHERS=$(cat /etc/ssh/ssh_config | grep 'Ciphers ' | awk -F 'Ciphers ' '{print $2}')
  108. fi
  109. if [ ! $SSH_MACS ]; then
  110. SSH_MACS=$(cat /etc/ssh/ssh_config | grep 'MACs ' | awk -F 'MACs ' '{print $2}')
  111. fi
  112. fi
  113. }
  114. function change_website_settings {
  115. if [ ! "$SSL_PROTOCOLS" ]; then
  116. return
  117. fi
  118. if [ ! $SSL_CIPHERS ]; then
  119. return
  120. fi
  121. if [ ${#SSL_PROTOCOLS} -lt $MINIMUM_LENGTH ]; then
  122. return
  123. fi
  124. if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
  125. return
  126. fi
  127. if [ ! -d $WEBSITES_DIRECTORY ]; then
  128. return
  129. fi
  130. cd $WEBSITES_DIRECTORY
  131. for file in `dir -d *` ; do
  132. sed -i "s|ssl_protocols .*|ssl_protocols $SSL_PROTOCOLS;|g" $WEBSITES_DIRECTORY/$file
  133. sed -i "s|ssl_ciphers .*|ssl_ciphers '$SSL_CIPHERS';|g" $WEBSITES_DIRECTORY/$file
  134. done
  135. service nginx restart
  136. echo 'Web security settings changed'
  137. }
  138. function change_imap_settings {
  139. if [ ! -f $DOVECOT_CIPHERS ]; then
  140. return
  141. fi
  142. if [ ! $SSL_CIPHERS ]; then
  143. return
  144. fi
  145. if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
  146. return
  147. fi
  148. sed -i "s|ssl_cipher_list.*|ssl_cipher_list = '$SSL_CIPHERS'|g" $DOVECOT_CIPHERS
  149. sed -i "s|ssl_protocols.*|ssl_protocols = '$SSL_PROTOCOLS'|g" $DOVECOT_CIPHERS
  150. service dovecot restart
  151. echo 'imap security settings changed'
  152. }
  153. function change_ssh_settings {
  154. if [ -f /etc/ssh/ssh_config ]; then
  155. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  156. sed -i "s|HostKeyAlgorithms .*|HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS|g" /etc/ssh/ssh_config
  157. echo 'ssh client security settings changed'
  158. fi
  159. fi
  160. if [ -f $SSH_CONFIG ]; then
  161. if [ ! $SSH_CIPHERS ]; then
  162. return
  163. fi
  164. if [ ! $SSH_MACS ]; then
  165. return
  166. fi
  167. if [ ! $SSH_KEX ]; then
  168. return
  169. fi
  170. if [ ! $SSH_PASSWORDS ]; then
  171. return
  172. fi
  173. sed -i "s|Ciphers .*|Ciphers $SSH_CIPHERS|g" $SSH_CONFIG
  174. sed -i "s|MACs .*|MACs $SSH_MACS|g" $SSH_CONFIG
  175. sed -i "s|KexAlgorithms .*|KexAlgorithms $SSH_KEX|g" $SSH_CONFIG
  176. sed -i "s|PasswordAuthentication .*|PasswordAuthentication $SSH_PASSWORDS|g" $SSH_CONFIG
  177. service ssh restart
  178. echo 'ssh server security settings changed'
  179. fi
  180. }
  181. function change_xmpp_settings {
  182. if [ ! -f $XMPP_CONFIG ]; then
  183. return
  184. fi
  185. if [ ! $XMPP_CIPHERS ]; then
  186. return
  187. fi
  188. if [ ! $XMPP_ECC_CURVE ]; then
  189. return
  190. fi
  191. sed -i "s|ciphers =.*|ciphers = \"$XMPP_CIPHERS\";|g" $XMPP_CONFIG
  192. sed -i "s|curve =.*|curve = \"$XMPP_ECC_CURVE\";|g" $XMPP_CONFIG
  193. service prosody restart
  194. echo 'xmpp security settings changed'
  195. }
  196. function interactive_setup {
  197. if [ $SSL_CIPHERS ]; then
  198. data=$(tempfile 2>/dev/null)
  199. trap "rm -f $data" 0 1 2 5 15
  200. dialog --backtitle "Freedombone Security Configuration" \
  201. --form "\nWeb/IMAP Ciphers:" 10 95 2 \
  202. "Protocols:" 1 1 "$SSL_PROTOCOLS" 1 15 90 90 \
  203. "Ciphers:" 2 1 "$SSL_CIPHERS" 2 15 90 512 \
  204. 2> $data
  205. sel=$?
  206. case $sel in
  207. 1) SSL_PROTOCOLS=$(cat $data | sed -n 1p)
  208. SSL_CIPHERS=$(cat $data | sed -n 2p)
  209. ;;
  210. 255) exit 0;;
  211. esac
  212. fi
  213. data=$(tempfile 2>/dev/null)
  214. trap "rm -f $data" 0 1 2 5 15
  215. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  216. dialog --backtitle "Freedombone Security Configuration" \
  217. --form "\nSecure Shell Ciphers:" 13 95 4 \
  218. "Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
  219. "MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
  220. "KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
  221. "Host key algorithms:" 4 1 "$SSH_HOST_KEY_ALGORITHMS" 4 15 90 512 \
  222. 2> $data
  223. sel=$?
  224. case $sel in
  225. 1) SSH_CIPHERS=$(cat $data | sed -n 1p)
  226. SSH_MACS=$(cat $data | sed -n 2p)
  227. SSH_KEX=$(cat $data | sed -n 3p)
  228. SSH_HOST_KEY_ALGORITHMS=$(cat $data | sed -n 4p)
  229. ;;
  230. 255) exit 0;;
  231. esac
  232. else
  233. dialog --backtitle "Freedombone Security Configuration" \
  234. --form "\nSecure Shell Ciphers:" 11 95 3 \
  235. "Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
  236. "MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
  237. "KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
  238. 2> $data
  239. sel=$?
  240. case $sel in
  241. 1) SSH_CIPHERS=$(cat $data | sed -n 1p)
  242. SSH_MACS=$(cat $data | sed -n 2p)
  243. SSH_KEX=$(cat $data | sed -n 3p)
  244. ;;
  245. 255) exit 0;;
  246. esac
  247. fi
  248. if [[ $SSH_PASSWORDS == "yes" ]]; then
  249. dialog --title "SSH Passwords" \
  250. --backtitle "Freedombone Security Configuration" \
  251. --yesno "\nAllow SSH login using passwords?" 7 60
  252. else
  253. dialog --title "SSH Passwords" \
  254. --backtitle "Freedombone Security Configuration" \
  255. --defaultno \
  256. --yesno "\nAllow SSH login using passwords?" 7 60
  257. fi
  258. sel=$?
  259. case $sel in
  260. 0) SSH_PASSWORDS="yes";;
  261. 1) SSH_PASSWORDS="no";;
  262. 255) exit 0;;
  263. esac
  264. if [ $XMPP_CIPHERS ]; then
  265. data=$(tempfile 2>/dev/null)
  266. trap "rm -f $data" 0 1 2 5 15
  267. dialog --backtitle "Freedombone Security Configuration" \
  268. --form "\nXMPP Ciphers:" 10 95 2 \
  269. "Ciphers:" 1 1 "$XMPP_CIPHERS" 1 15 90 512 \
  270. "ECC Curve:" 2 1 "$XMPP_ECC_CURVE" 2 15 50 50 \
  271. 2> $data
  272. sel=$?
  273. case $sel in
  274. 1) XMPP_CIPHERS=$(cat $data | sed -n 1p)
  275. XMPP_ECC_CURVE=$(cat $data | sed -n 2p)
  276. ;;
  277. 255) exit 0;;
  278. esac
  279. fi
  280. dialog --title "Final Confirmation" \
  281. --backtitle "Freedombone Security Configuration" \
  282. --defaultno \
  283. --yesno "\nPlease confirm that you wish your security settings to be changed?\n\nWARNING: any mistakes made in the security settings could compromise your system, so be extra careful when answering 'yes'." 12 60
  284. sel=$?
  285. case $sel in
  286. 1) clear
  287. echo 'Exiting without changing security settings'
  288. exit 0;;
  289. 255) clear
  290. echo 'Exiting without changing security settings'
  291. exit 0;;
  292. esac
  293. clear
  294. }
  295. function import_settings {
  296. cd $CURRENT_DIR
  297. if [ ! $IMPORT_FILE ]; then
  298. return
  299. fi
  300. if [ ! -f $IMPORT_FILE ]; then
  301. echo "Import file $IMPORT_FILE not found"
  302. exit 6393
  303. fi
  304. if grep -q "SSL_PROTOCOLS" $IMPORT_FILE; then
  305. TEMP_VALUE=$(grep "SSL_PROTOCOLS" $IMPORT_FILE | awk -F '=' '{print $2}')
  306. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  307. SSL_PROTOCOLS=$TEMP_VALUE
  308. fi
  309. fi
  310. if grep -q "SSL_CIPHERS" $IMPORT_FILE; then
  311. TEMP_VALUE=$(grep "SSL_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  312. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  313. SSL_CIPHERS=$TEMP_VALUE
  314. fi
  315. fi
  316. if grep -q "SSH_CIPHERS" $IMPORT_FILE; then
  317. TEMP_VALUE=$(grep "SSH_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  318. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  319. SSH_CIPHERS=$TEMP_VALUE
  320. fi
  321. fi
  322. if grep -q "SSH_MACS" $IMPORT_FILE; then
  323. TEMP_VALUE=$(grep "SSH_MACS" $IMPORT_FILE | awk -F '=' '{print $2}')
  324. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  325. SSH_MACS=$TEMP_VALUE
  326. fi
  327. fi
  328. if grep -q "SSH_KEX" $IMPORT_FILE; then
  329. TEMP_VALUE=$(grep "SSH_KEX" $IMPORT_FILE | awk -F '=' '{print $2}')
  330. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  331. SSH_KEX=$TEMP_VALUE
  332. fi
  333. fi
  334. if grep -q "SSH_HOST_KEY_ALGORITHMS" $IMPORT_FILE; then
  335. TEMP_VALUE=$(grep "SSH_HOST_KEY_ALGORITHMS" $IMPORT_FILE | awk -F '=' '{print $2}')
  336. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  337. SSH_HOST_KEY_ALGORITHMS=$TEMP_VALUE
  338. fi
  339. fi
  340. if grep -q "SSH_PASSWORDS" $IMPORT_FILE; then
  341. TEMP_VALUE=$(grep "SSH_PASSWORDS" $IMPORT_FILE | awk -F '=' '{print $2}')
  342. if [[ $TEMP_VALUE == "yes" || $TEMP_VALUE == "no" ]]; then
  343. SSH_PASSWORDS=$TEMP_VALUE
  344. fi
  345. fi
  346. if grep -q "XMPP_CIPHERS" $IMPORT_FILE; then
  347. TEMP_VALUE=$(grep "XMPP_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  348. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  349. XMPP_CIPHERS=$TEMP_VALUE
  350. fi
  351. fi
  352. if grep -q "XMPP_ECC_CURVE" $IMPORT_FILE; then
  353. TEMP_VALUE=$(grep "XMPP_ECC_CURVE" $IMPORT_FILE | awk -F '=' '{print $2}')
  354. if [ ${#TEMP_VALUE} -gt 3 ]; then
  355. XMPP_ECC_CURVE=$TEMP_VALUE
  356. fi
  357. fi
  358. }
  359. function export_settings {
  360. if [ ! $EXPORT_FILE ]; then
  361. return
  362. fi
  363. cd $CURRENT_DIR
  364. if [ ! -f $EXPORT_FILE ]; then
  365. if [ "$SSL_PROTOCOLS" ]; then
  366. echo "SSL_PROTOCOLS=$SSL_PROTOCOLS" >> $EXPORT_FILE
  367. fi
  368. if [ $SSL_CIPHERS ]; then
  369. echo "SSL_CIPHERS=$SSL_CIPHERS" >> $EXPORT_FILE
  370. fi
  371. if [ $SSH_CIPHERS ]; then
  372. echo "SSH_CIPHERS=$SSH_CIPHERS" >> $EXPORT_FILE
  373. fi
  374. if [ $SSH_MACS ]; then
  375. echo "SSH_MACS=$SSH_MACS" >> $EXPORT_FILE
  376. fi
  377. if [ $SSH_KEX ]; then
  378. echo "SSH_KEX=$SSH_KEX" >> $EXPORT_FILE
  379. fi
  380. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  381. echo "SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS" >> $EXPORT_FILE
  382. fi
  383. if [ $SSH_PASSWORDS ]; then
  384. echo "SSH_PASSWORDS=$SSH_PASSWORDS" >> $EXPORT_FILE
  385. fi
  386. if [ $XMPP_CIPHERS ]; then
  387. echo "XMPP_CIPHERS=$XMPP_CIPHERS" >> $EXPORT_FILE
  388. fi
  389. if [ $XMPP_ECC_CURVE ]; then
  390. echo "XMPP_ECC_CURVE=$XMPP_ECC_CURVE" >> $EXPORT_FILE
  391. fi
  392. echo "Security settings exported to $EXPORT_FILE"
  393. exit 0
  394. fi
  395. if [ "$SSL_PROTOCOLS" ]; then
  396. if grep -q "SSL_PROTOCOLS" $EXPORT_FILE; then
  397. sed -i "s|SSL_PROTOCOLS=.*|SSL_PROTOCOLS=$SSL_PROTOCOLS|g" $EXPORT_FILE
  398. else
  399. echo "SSL_PROTOCOLS=$SSL_PROTOCOLS" >> $EXPORT_FILE
  400. fi
  401. fi
  402. if [ $SSL_CIPHERS ]; then
  403. if grep -q "SSL_CIPHERS" $EXPORT_FILE; then
  404. sed -i "s|SSL_CIPHERS=.*|SSL_CIPHERS=$SSL_CIPHERS|g" $EXPORT_FILE
  405. else
  406. echo "SSL_CIPHERS=$SSL_CIPHERS" >> $EXPORT_FILE
  407. fi
  408. fi
  409. if [ $SSH_CIPHERS ]; then
  410. if grep -q "SSH_CIPHERS" $EXPORT_FILE; then
  411. sed -i "s|SSH_CIPHERS=.*|SSH_CIPHERS=$SSH_CIPHERS|g" $EXPORT_FILE
  412. else
  413. echo "SSH_CIPHERS=$SSH_CIPHERS" >> $EXPORT_FILE
  414. fi
  415. fi
  416. if [ $SSH_MACS ]; then
  417. if grep -q "SSH_MACS" $EXPORT_FILE; then
  418. sed -i "s|SSH_MACS=.*|SSH_MACS=$SSH_MACS|g" $EXPORT_FILE
  419. else
  420. echo "SSH_MACS=$SSH_MACS" >> $EXPORT_FILE
  421. fi
  422. fi
  423. if [ $SSH_KEX ]; then
  424. if grep -q "SSH_KEX" $EXPORT_FILE; then
  425. sed -i "s|SSH_KEX=.*|SSH_KEX=$SSH_KEX|g" $EXPORT_FILE
  426. else
  427. echo "SSH_KEX=$SSH_KEX" >> $EXPORT_FILE
  428. fi
  429. fi
  430. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  431. if grep -q "SSH_HOST_KEY_ALGORITHMS" $EXPORT_FILE; then
  432. sed -i "s|SSH_HOST_KEY_ALGORITHMS=.*|SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS|g" $EXPORT_FILE
  433. else
  434. echo "SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS" >> $EXPORT_FILE
  435. fi
  436. fi
  437. if [ $SSH_PASSWORDS ]; then
  438. if grep -q "SSH_PASSWORDS" $EXPORT_FILE; then
  439. sed -i "s|SSH_PASSWORDS=.*|SSH_PASSWORDS=$SSH_PASSWORDS|g" $EXPORT_FILE
  440. else
  441. echo "SSH_PASSWORDS=$SSH_PASSWORDS" >> $EXPORT_FILE
  442. fi
  443. fi
  444. if [ $XMPP_CIPHERS ]; then
  445. if grep -q "XMPP_CIPHERS" $EXPORT_FILE; then
  446. sed -i "s|XMPP_CIPHERS=.*|XMPP_CIPHERS=$XMPP_CIPHERS|g" $EXPORT_FILE
  447. else
  448. echo "XMPP_CIPHERS=$XMPP_CIPHERS" >> $EXPORT_FILE
  449. fi
  450. fi
  451. if [ $XMPP_ECC_CURVE ]; then
  452. if grep -q "XMPP_ECC_CURVE" $EXPORT_FILE; then
  453. sed -i "s|XMPP_ECC_CURVE=.*|XMPP_ECC_CURVE=$XMPP_ECC_CURVE|g" $EXPORT_FILE
  454. else
  455. echo "XMPP_ECC_CURVE=$XMPP_ECC_CURVE" >> $EXPORT_FILE
  456. fi
  457. fi
  458. echo "Security settings exported to $EXPORT_FILE"
  459. exit 0
  460. }
  461. function show_help {
  462. echo ''
  463. echo 'freedombone-sec'
  464. echo ''
  465. echo 'Alters the security settings'
  466. echo ''
  467. echo ''
  468. echo ' -h --help Show help'
  469. echo ' -e --export Export security settings to a file'
  470. echo ' -i --import Import security settings from a file'
  471. echo ''
  472. exit 0
  473. }
  474. # Get the commandline options
  475. while [[ $# > 1 ]]
  476. do
  477. key="$1"
  478. case $key in
  479. -h|--help)
  480. show_help
  481. ;;
  482. # Export settings
  483. -e|--export)
  484. shift
  485. EXPORT_FILE="$1"
  486. ;;
  487. # Export settings
  488. -i|--import)
  489. shift
  490. IMPORT_FILE="$1"
  491. ;;
  492. *)
  493. # unknown option
  494. ;;
  495. esac
  496. shift
  497. done
  498. get_website_settings
  499. get_imap_settings
  500. get_ssh_settings
  501. get_xmpp_settings
  502. import_settings
  503. export_settings
  504. interactive_setup
  505. change_website_settings
  506. change_imap_settings
  507. change_ssh_settings
  508. change_xmpp_settings
  509. exit 0