freedombone-sec 16KB

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