freedombone-sec 16KB

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