freedombone-sec 35KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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-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}-sec
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
  34. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  35. UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
  36. for f in $UTILS_FILES
  37. do
  38. source $f
  39. done
  40. SSL_PROTOCOLS=
  41. SSL_CIPHERS=
  42. SSH_CIPHERS=
  43. SSH_MACS=
  44. SSH_KEX=
  45. SSH_HOST_KEY_ALGORITHMS=
  46. SSH_PASSWORDS=
  47. XMPP_CIPHERS=
  48. XMPP_ECC_CURVE=
  49. WEBSITES_DIRECTORY='/etc/nginx/sites-available'
  50. DOVECOT_CIPHERS='/etc/dovecot/conf.d/10-ssl.conf'
  51. SSH_CONFIG='/etc/ssh/sshd_config'
  52. XMPP_CONFIG='/etc/prosody/conf.avail/xmpp.cfg.lua'
  53. MINIMUM_LENGTH=6
  54. IMPORT_FILE=
  55. EXPORT_FILE=
  56. CURRENT_DIR=$(pwd)
  57. DH_KEYLENGTH=2048
  58. LETSENCRYPT_SERVER='https://acme-v01.api.letsencrypt.org/directory'
  59. MY_USERNAME=
  60. function export_passwords {
  61. detect_usb_drive
  62. data=$(tempfile 2>/dev/null)
  63. trap "rm -f $data" 0 1 2 5 15
  64. dialog --title $"Export passwords to USB drive $USB_DRIVE" \
  65. --backtitle $"Security Settings" \
  66. --defaultno \
  67. --yesno $"\nPlease confirm that you wish to export passwords to a LUKS formatted USB drive. The drive should be plugged in." 10 60
  68. sel=$?
  69. case $sel in
  70. 1) return;;
  71. 255) return;;
  72. esac
  73. data=$(tempfile 2>/dev/null)
  74. trap "rm -f $data" 0 1 2 5 15
  75. dialog --title $"Export passwords to USB drive $USB_DRIVE" \
  76. --backtitle $"Security Settings" \
  77. --defaultno \
  78. --yesno $"\nDo you need to format the drive as LUKS encrypted?" 12 60
  79. sel=$?
  80. case $sel in
  81. 0) ${PROJECT_NAME}-format $USB_DRIVE;;
  82. esac
  83. clear
  84. backup_mount_drive ${USB_DRIVE}
  85. ${PROJECT_NAME}-pass --export ${USB_MOUNT}/${PROJECT_NAME}-passwords.xml
  86. backup_unmount_drive ${USB_DRIVE}
  87. }
  88. function get_protocols_from_website {
  89. if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
  90. return
  91. fi
  92. SSL_PROTOCOLS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_protocols ' | awk -F "ssl_protocols " '{print $2}' | awk -F ';' '{print $1}')
  93. }
  94. function get_ciphers_from_website {
  95. if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
  96. return
  97. fi
  98. SSL_CIPHERS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_ciphers ' | awk -F "ssl_ciphers " '{print $2}' | awk -F "'" '{print $2}')
  99. }
  100. function get_imap_settings {
  101. if [ ! -f $DOVECOT_CIPHERS ]; then
  102. return
  103. fi
  104. # clear commented out cipher list
  105. sed -i "s|#ssl_cipher_list.*||g" $DOVECOT_CIPHERS
  106. if [ $SSL_CIPHERS ]; then
  107. return
  108. fi
  109. if [ ${#SSL_CIPHERS} -gt $MINIMUM_LENGTH ]; then
  110. return
  111. fi
  112. SSL_CIPHERS=$(cat $DOVECOT_CIPHERS | grep 'ssl_cipher_list' | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
  113. }
  114. function get_xmpp_settings {
  115. if [ ! -f $XMPP_CONFIG ]; then
  116. return
  117. fi
  118. XMPP_CIPHERS=$(cat $XMPP_CONFIG | grep 'ciphers ' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  119. XMPP_ECC_CURVE=$(cat $XMPP_CONFIG | grep 'curve ' | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
  120. }
  121. function get_ssh_settings {
  122. if [ -f $SSH_CONFIG ]; then
  123. SSH_PASSWORDS=$(cat $SSH_CONFIG | grep 'PasswordAuthentication ' | awk -F 'PasswordAuthentication ' '{print $2}')
  124. fi
  125. if [ -f /etc/ssh/ssh_config ]; then
  126. SSH_HOST_KEY_ALGORITHMS=$(cat /etc/ssh/ssh_config | grep 'HostKeyAlgorithms ' | awk -F 'HostKeyAlgorithms ' '{print $2}')
  127. fi
  128. }
  129. function change_website_settings {
  130. if [ ! "$SSL_PROTOCOLS" ]; then
  131. return
  132. fi
  133. if [ ! $SSL_CIPHERS ]; then
  134. return
  135. fi
  136. if [ ${#SSL_PROTOCOLS} -lt $MINIMUM_LENGTH ]; then
  137. return
  138. fi
  139. if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
  140. return
  141. fi
  142. if [ ! -d $WEBSITES_DIRECTORY ]; then
  143. return
  144. fi
  145. cd $WEBSITES_DIRECTORY
  146. for file in `dir -d *` ; do
  147. sed -i "s|ssl_protocols .*|ssl_protocols $SSL_PROTOCOLS;|g" $WEBSITES_DIRECTORY/$file
  148. sed -i "s|ssl_ciphers .*|ssl_ciphers '$SSL_CIPHERS';|g" $WEBSITES_DIRECTORY/$file
  149. done
  150. systemctl restart nginx
  151. echo $'Web security settings changed'
  152. }
  153. function change_imap_settings {
  154. if [ ! -f $DOVECOT_CIPHERS ]; then
  155. return
  156. fi
  157. if [ ! $SSL_CIPHERS ]; then
  158. return
  159. fi
  160. if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
  161. return
  162. fi
  163. sed -i "s|ssl_cipher_list.*|ssl_cipher_list = '$SSL_CIPHERS'|g" $DOVECOT_CIPHERS
  164. sed -i "s|ssl_protocols.*|ssl_protocols = '$SSL_PROTOCOLS'|g" $DOVECOT_CIPHERS
  165. systemctl restart dovecot
  166. echo $'imap security settings changed'
  167. }
  168. function change_ssh_settings {
  169. if [ -f /etc/ssh/ssh_config ]; then
  170. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  171. sed -i "s|HostKeyAlgorithms .*|HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS|g" /etc/ssh/ssh_config
  172. echo $'ssh client security settings changed'
  173. fi
  174. fi
  175. if [ -f $SSH_CONFIG ]; then
  176. if [ ! $SSH_CIPHERS ]; then
  177. return
  178. fi
  179. if [ ! $SSH_MACS ]; then
  180. return
  181. fi
  182. if [ ! $SSH_KEX ]; then
  183. return
  184. fi
  185. if [ ! $SSH_PASSWORDS ]; then
  186. SSH_PASSWORDS='yes'
  187. fi
  188. sed -i "s|Ciphers .*|Ciphers $SSH_CIPHERS|g" $SSH_CONFIG
  189. sed -i "s|MACs .*|MACs $SSH_MACS|g" $SSH_CONFIG
  190. sed -i "s|KexAlgorithms .*|KexAlgorithms $SSH_KEX|g" $SSH_CONFIG
  191. sed -i "s|#PasswordAuthentication .*|PasswordAuthentication $SSH_PASSWORDS|g" $SSH_CONFIG
  192. sed -i "s|PasswordAuthentication .*|PasswordAuthentication $SSH_PASSWORDS|g" $SSH_CONFIG
  193. systemctl restart ssh
  194. echo $'ssh server security settings changed'
  195. fi
  196. }
  197. function change_xmpp_settings {
  198. if [ ! -f $XMPP_CONFIG ]; then
  199. return
  200. fi
  201. if [ ! $XMPP_CIPHERS ]; then
  202. return
  203. fi
  204. if [ ! $XMPP_ECC_CURVE ]; then
  205. return
  206. fi
  207. sed -i "s|ciphers =.*|ciphers = \"$XMPP_CIPHERS\";|g" $XMPP_CONFIG
  208. sed -i "s|curve =.*|curve = \"$XMPP_ECC_CURVE\";|g" $XMPP_CONFIG
  209. systemctl restart prosody
  210. echo $'xmpp security settings changed'
  211. }
  212. function allow_ssh_passwords {
  213. dialog --title $"SSH Passwords" \
  214. --backtitle $"Freedombone Security Configuration" \
  215. --yesno $"\nAllow SSH login using passwords?" 7 60
  216. sel=$?
  217. case $sel in
  218. 0) SSH_PASSWORDS="yes";;
  219. 1) SSH_PASSWORDS="no";;
  220. 255) exit 0;;
  221. esac
  222. }
  223. function interactive_setup {
  224. if [ $SSL_CIPHERS ]; then
  225. data=$(tempfile 2>/dev/null)
  226. trap "rm -f $data" 0 1 2 5 15
  227. dialog --backtitle $"Freedombone Security Configuration" \
  228. --form $"\nWeb/IMAP Ciphers:" 10 95 2 \
  229. $"Protocols:" 1 1 "$SSL_PROTOCOLS" 1 15 90 90 \
  230. $"Ciphers:" 2 1 "$SSL_CIPHERS" 2 15 90 512 \
  231. 2> $data
  232. sel=$?
  233. case $sel in
  234. 1) SSL_PROTOCOLS=$(cat $data | sed -n 1p)
  235. SSL_CIPHERS=$(cat $data | sed -n 2p)
  236. ;;
  237. 255) exit 0;;
  238. esac
  239. fi
  240. data=$(tempfile 2>/dev/null)
  241. trap "rm -f $data" 0 1 2 5 15
  242. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  243. dialog --backtitle $"Freedombone Security Configuration" \
  244. --form $"\nSecure Shell Ciphers:" 13 95 4 \
  245. $"Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
  246. $"MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
  247. $"KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
  248. $"Host key algorithms:" 4 1 "$SSH_HOST_KEY_ALGORITHMS" 4 15 90 512 \
  249. 2> $data
  250. sel=$?
  251. case $sel in
  252. 1) SSH_CIPHERS=$(cat $data | sed -n 1p)
  253. SSH_MACS=$(cat $data | sed -n 2p)
  254. SSH_KEX=$(cat $data | sed -n 3p)
  255. SSH_HOST_KEY_ALGORITHMS=$(cat $data | sed -n 4p)
  256. ;;
  257. 255) exit 0;;
  258. esac
  259. else
  260. dialog --backtitle $"Freedombone Security Configuration" \
  261. --form $"\nSecure Shell Ciphers:" 11 95 3 \
  262. $"Ciphers:" 1 1 "$SSH_CIPHERS" 1 15 90 512 \
  263. $"MACs:" 2 1 "$SSH_MACS" 2 15 90 512 \
  264. $"KEX:" 3 1 "$SSH_KEX" 3 15 90 512 \
  265. 2> $data
  266. sel=$?
  267. case $sel in
  268. 1) SSH_CIPHERS=$(cat $data | sed -n 1p)
  269. SSH_MACS=$(cat $data | sed -n 2p)
  270. SSH_KEX=$(cat $data | sed -n 3p)
  271. ;;
  272. 255) exit 0;;
  273. esac
  274. fi
  275. if [ $XMPP_CIPHERS ]; then
  276. data=$(tempfile 2>/dev/null)
  277. trap "rm -f $data" 0 1 2 5 15
  278. dialog --backtitle $"Freedombone Security Configuration" \
  279. --form $"\nXMPP Ciphers:" 10 95 2 \
  280. $"Ciphers:" 1 1 "$XMPP_CIPHERS" 1 15 90 512 \
  281. $"ECC Curve:" 2 1 "$XMPP_ECC_CURVE" 2 15 50 50 \
  282. 2> $data
  283. sel=$?
  284. case $sel in
  285. 1) XMPP_CIPHERS=$(cat $data | sed -n 1p)
  286. XMPP_ECC_CURVE=$(cat $data | sed -n 2p)
  287. ;;
  288. 255) exit 0;;
  289. esac
  290. fi
  291. dialog --title $"Final Confirmation" \
  292. --backtitle $"Freedombone Security Configuration" \
  293. --defaultno \
  294. --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
  295. sel=$?
  296. case $sel in
  297. 1) clear
  298. echo $'Exiting without changing security settings'
  299. exit 0;;
  300. 255) clear
  301. echo $'Exiting without changing security settings'
  302. exit 0;;
  303. esac
  304. clear
  305. }
  306. function send_monkeysphere_server_keys_to_users {
  307. monkeysphere_server_keys=$(monkeysphere-host show-key | grep $"OpenPGP fingerprint" | awk -F ' ' '{print $3}')
  308. for d in /home/*/ ; do
  309. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  310. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  311. if [ ! -d /home/$USERNAME/.monkeysphere ]; then
  312. mkdir /home/$USERNAME/.monkeysphere
  313. fi
  314. echo $monkeysphere_server_keys > /home/$USERNAME/.monkeysphere/server_keys
  315. chown -R $USERNAME:$USERNAME /home/$USERNAME/.monkeysphere
  316. fi
  317. done
  318. }
  319. function regenerate_ssh_host_keys {
  320. rm -f /etc/ssh/ssh_host_*
  321. dpkg-reconfigure openssh-server
  322. echo $'ssh host keys regenerated'
  323. # remove small moduli
  324. awk '$5 > 2000' /etc/ssh/moduli > ~/moduli
  325. mv ~/moduli /etc/ssh/moduli
  326. echo $'ssh small moduli removed'
  327. # update monkeysphere
  328. DEFAULT_DOMAIN_NAME=
  329. read_config_param "DEFAULT_DOMAIN_NAME"
  330. monkeysphere-host import-key /etc/ssh/ssh_host_rsa_key ssh://$DEFAULT_DOMAIN_NAME
  331. SSH_ONION_HOSTNAME=$(cat ${COMPLETION_FILE} | grep 'ssh onion domain' | awk -F ':' '{print $2}')
  332. monkeysphere-host import-key /etc/ssh/ssh_host_rsa_key ssh://$SSH_ONION_HOSTNAME
  333. monkeysphere-host publish-key
  334. send_monkeysphere_server_keys_to_users
  335. echo $'updated monkeysphere ssh host key'
  336. systemctl restart ssh
  337. }
  338. function regenerate_dh_keys {
  339. if [ ! -d /etc/ssl/mycerts ]; then
  340. echo $'No dhparam certificates were found'
  341. return
  342. fi
  343. data=$(tempfile 2>/dev/null)
  344. trap "rm -f $data" 0 1 2 5 15
  345. dialog --backtitle "Freedombone Security Configuration" \
  346. --title "Diffie-Hellman key length" \
  347. --radiolist "The smaller length is better suited to low power embedded systems:" 12 40 3 \
  348. 1 "2048 bits" off \
  349. 2 "3072 bits" on \
  350. 3 "4096 bits" off 2> $data
  351. sel=$?
  352. case $sel in
  353. 1) exit 1;;
  354. 255) exit 1;;
  355. esac
  356. case $(cat $data) in
  357. 1) DH_KEYLENGTH=2048;;
  358. 2) DH_KEYLENGTH=3072;;
  359. 3) DH_KEYLENGTH=4096;;
  360. esac
  361. ${PROJECT_NAME}-dhparam --recalc yes -l ${DH_KEYLENGTH}
  362. }
  363. function renew_startssl {
  364. renew_domain=
  365. data=$(tempfile 2>/dev/null)
  366. trap "rm -f $data" 0 1 2 5 15
  367. dialog --title $"Renew a StartSSL certificate" \
  368. --backtitle $"Freedombone Security Settings" \
  369. --inputbox $"Enter the domain name" 8 60 2>$data
  370. sel=$?
  371. case $sel in
  372. 0)
  373. renew_domain=$(<$data)
  374. ;;
  375. esac
  376. if [ ! $renew_domain ]; then
  377. return
  378. fi
  379. if [[ $renew_domain == "http"* ]]; then
  380. dialog --title $"Renew a StartSSL certificate" \
  381. --msgbox $"Don't include the https://" 6 40
  382. return
  383. fi
  384. if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
  385. dialog --title $"Renew a StartSSL certificate" \
  386. --msgbox $"An existing certificate for $renew_domain was not found" 6 40
  387. return
  388. fi
  389. if [[ $renew_domain != *"."* ]]; then
  390. dialog --title $"Renew a StartSSL certificate" \
  391. --msgbox $"Invalid domain name: $renew_domain" 6 40
  392. return
  393. fi
  394. ${PROJECT_NAME}-renew-cert -h $renew_domain -p startssl
  395. exit 0
  396. }
  397. function renew_letsencrypt {
  398. renew_domain=
  399. data=$(tempfile 2>/dev/null)
  400. trap "rm -f $data" 0 1 2 5 15
  401. dialog --title $"Renew a Let's Encrypt certificate" \
  402. --backtitle $"Freedombone Security Settings" \
  403. --inputbox $"Enter the domain name" 8 60 2>$data
  404. sel=$?
  405. case $sel in
  406. 0)
  407. renew_domain=$(<$data)
  408. ;;
  409. esac
  410. if [ ! $renew_domain ]; then
  411. return
  412. fi
  413. if [[ $renew_domain == "http"* ]]; then
  414. dialog --title $"Renew a Let's Encrypt certificate" \
  415. --msgbox $"Don't include the https://" 6 40
  416. return
  417. fi
  418. if [ ! -f /etc/ssl/certs/${renew_domain}.dhparam ]; then
  419. dialog --title $"Renew a Let's Encrypt certificate" \
  420. --msgbox $"An existing certificate for $renew_domain was not found" 6 40
  421. return
  422. fi
  423. if [[ $renew_domain != *"."* ]]; then
  424. dialog --title $"Renew a Let's Encrypt certificate" \
  425. --msgbox $"Invalid domain name: $renew_domain" 6 40
  426. return
  427. fi
  428. ${PROJECT_NAME}-renew-cert -h $renew_domain -p 'letsencrypt'
  429. exit 0
  430. }
  431. function create_letsencrypt {
  432. new_domain=
  433. data=$(tempfile 2>/dev/null)
  434. trap "rm -f $data" 0 1 2 5 15
  435. dialog --title $"Create a new Let's Encrypt certificate" \
  436. --backtitle $"Freedombone Security Settings" \
  437. --inputbox $"Enter the domain name" 8 60 2>$data
  438. sel=$?
  439. case $sel in
  440. 0)
  441. new_domain=$(<$data)
  442. ;;
  443. esac
  444. if [ ! $new_domain ]; then
  445. return
  446. fi
  447. if [[ $new_domain == "http"* ]]; then
  448. dialog --title $"Create a new Let's Encrypt certificate" \
  449. --msgbox $"Don't include the https://" 6 40
  450. return
  451. fi
  452. if [[ $new_domain != *"."* ]]; then
  453. dialog --title $"Create a new Let's Encrypt certificate" \
  454. --msgbox $"Invalid domain name: $new_domain" 6 40
  455. return
  456. fi
  457. if [ ! -d /var/www/${new_domain} ]; then
  458. domain_found=
  459. if [ -f /etc/nginx/sites-available/radicale ]; then
  460. if grep "${new_domain}" /etc/nginx/sites-available/radicale; then
  461. domain_found=1
  462. fi
  463. fi
  464. if [ -f /etc/nginx/sites-available/${new_domain} ]; then
  465. domain_found=1
  466. fi
  467. if [[ "${new_domain}" == "jitsi"* || "${new_domain}" == "meet"* ]]; then
  468. domain_found=1
  469. fi
  470. if [ ! $domain_found ]; then
  471. dialog --title $"Create a new Let's Encrypt certificate" \
  472. --msgbox $'Domain not found within /var/www' 6 40
  473. return
  474. fi
  475. fi
  476. ${PROJECT_NAME}-addcert -e $new_domain -s $LETSENCRYPT_SERVER --dhkey $DH_KEYLENGTH
  477. exit 0
  478. }
  479. function update_ciphersuite {
  480. RECOMMENDED_SSL_CIPHERS="$SSL_CIPHERS"
  481. if [ ${#RECOMMENDED_SSL_CIPHERS} -lt 5 ]; then
  482. return
  483. fi
  484. RECOMMENDED_SSL_PROTOCOLS="$SSL_PROTOCOLS"
  485. if [ ${#RECOMMENDED_SSL_PROTOCOLS} -lt 5 ]; then
  486. return
  487. fi
  488. RECOMMENDED_SSH_CIPHERS="$SSH_CIPHERS"
  489. if [ ${#RECOMMENDED_SSH_CIPHERS} -lt 5 ]; then
  490. return
  491. fi
  492. RECOMMENDED_SSH_MACS="$SSH_MACS"
  493. if [ ${#RECOMMENDED_SSH_MACS} -lt 5 ]; then
  494. return
  495. fi
  496. RECOMMENDED_SSH_KEX="$SSH_KEX"
  497. if [ ${#RECOMMENDED_SSH_KEX} -lt 5 ]; then
  498. return
  499. fi
  500. cd $WEBSITES_DIRECTORY
  501. for file in `dir -d *` ; do
  502. sed -i "s|ssl_protocols .*|ssl_protocols $RECOMMENDED_SSL_PROTOCOLS;|g" $WEBSITES_DIRECTORY/$file
  503. sed -i "s|ssl_ciphers .*|ssl_ciphers '$RECOMMENDED_SSL_CIPHERS';|g" $WEBSITES_DIRECTORY/$file
  504. done
  505. systemctl restart nginx
  506. write_config_param "SSL_PROTOCOLS" "$RECOMMENDED_SSL_PROTOCOLS"
  507. write_config_param "SSL_CIPHERS" "$RECOMMENDED_SSL_CIPHERS"
  508. sed -i "s|Ciphers .*|Ciphers $RECOMMENDED_SSH_CIPHERS|g" $SSH_CONFIG
  509. sed -i "s|MACs .*|MACs $RECOMMENDED_SSH_MACS|g" $SSH_CONFIG
  510. sed -i "s|KexAlgorithms .*|KexAlgorithms $RECOMMENDED_SSH_KEX|g" $SSH_CONFIG
  511. systemctl restart ssh
  512. write_config_param "SSH_CIPHERS" "$RECOMMENDED_SSH_CIPHERS"
  513. write_config_param "SSH_MACS" "$RECOMMENDED_SSH_MACS"
  514. write_config_param "SSH_KEX" "$RECOMMENDED_SSH_KEX"
  515. dialog --title $"Update ciphersuite" \
  516. --msgbox $"The ciphersuite has been updated to recommended versions" 6 40
  517. exit 0
  518. }
  519. function gpg_pubkey_from_email {
  520. key_owner_username=$1
  521. key_email_address=$2
  522. key_id=
  523. if [[ $key_owner_username != "root" ]]; then
  524. key_id=$(su -c "gpg --list-keys $key_email_address | grep 'pub '" - $key_owner_username | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  525. else
  526. key_id=$(gpg --list-keys $key_email_address | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  527. fi
  528. echo $key_id
  529. }
  530. function enable_monkeysphere {
  531. monkey=
  532. dialog --title $"GPG based authentication" \
  533. --backtitle $"Freedombone Security Configuration" \
  534. --defaultno \
  535. --yesno $"\nEnable GPG based authentication with monkeysphere ?" 7 60
  536. sel=$?
  537. case $sel in
  538. 0) monkey='yes';;
  539. 255) exit 0;;
  540. esac
  541. if [ $monkey ]; then
  542. read_config_param "MY_USERNAME"
  543. if [ ! -f /home/$MY_USERNAME/.monkeysphere/authorized_user_ids ]; then
  544. dialog --title $"GPG based authentication" \
  545. --msgbox $"$MY_USERNAME does not currently have any ids within ~/.monkeysphere/authorized_user_ids" 6 40
  546. exit 0
  547. fi
  548. MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_USERNAME@$HOSTNAME")
  549. if [ ${#MY_GPG_PUBLIC_KEY_ID} -lt 4 ]; then
  550. echo $'monkeysphere unable to get GPG key ID for user $MY_USERNAME'
  551. exit 52825
  552. fi
  553. sed -i 's|#AuthorizedKeysFile|AuthorizedKeysFile|g' /etc/ssh/sshd_config
  554. sed -i 's|AuthorizedKeysFile.*|AuthorizedKeysFile /var/lib/monkeysphere/authorized_keys/%u|g' /etc/ssh/sshd_config
  555. monkeysphere-authentication update-users
  556. # The admin user is the identity certifier
  557. fpr=$(gpg --with-colons --fingerprint $MY_GPG_PUBLIC_KEY_ID | grep fpr | head -n 1 | awk -F ':' '{print $10}')
  558. monkeysphere-authentication add-identity-certifier $fpr
  559. monkeysphere-host publish-key
  560. send_monkeysphere_server_keys_to_users
  561. else
  562. sed -i 's|#AuthorizedKeysFile|AuthorizedKeysFile|g' /etc/ssh/sshd_config
  563. sed -i 's|AuthorizedKeysFile.*|AuthorizedKeysFile %h/.ssh/authorized_keys|g' /etc/ssh/sshd_config
  564. fi
  565. systemctl restart ssh
  566. if [ $monkey ]; then
  567. dialog --title $"GPG based authentication" \
  568. --msgbox $"GPG based authentication was enabled" 6 40
  569. else
  570. dialog --title $"GPG based authentication" \
  571. --msgbox $"GPG based authentication was disabled" 6 40
  572. fi
  573. exit 0
  574. }
  575. function register_website {
  576. domain="$1"
  577. if [[ ${domain} == *".local" ]]; then
  578. echo $"Can't register local domains"
  579. return
  580. fi
  581. if [ ! -f /etc/ssl/private/${domain}.key ]; then
  582. echo $"No SSL/TLS private key found for ${domain}"
  583. return
  584. fi
  585. if [ ! -f /etc/nginx/sites-available/${domain} ]; then
  586. echo $"No virtual host found for ${domain}"
  587. return
  588. fi
  589. monkeysphere-host import-key /etc/ssl/private/${domain}.key https://${domain}
  590. monkeysphere-host publish-key
  591. echo "0"
  592. }
  593. function register_website_interactive {
  594. data=$(tempfile 2>/dev/null)
  595. trap "rm -f $data" 0 1 2 5 15
  596. dialog --title $"Register a website with monkeysphere" \
  597. --backtitle $"Freedombone Security Settings" \
  598. --inputbox $"Enter the website domain name (without https://)" 8 60 2>$data
  599. sel=$?
  600. case $sel in
  601. 0)
  602. domain=$(<$data)
  603. register_website "$domain"
  604. if [ ! "$?" = "0" ]; then
  605. dialog --title $"Register a website with monkeysphere" \
  606. --msgbox "$?" 6 40
  607. else
  608. dialog --title $"Register a website with monkeysphere" \
  609. --msgbox $"$domain has been registered" 6 40
  610. fi
  611. ;;
  612. esac
  613. }
  614. function pin_all_tls_certs {
  615. ${PROJECT_NAME}-pin-cert all
  616. }
  617. function remove_pinning {
  618. data=$(tempfile 2>/dev/null)
  619. trap "rm -f $data" 0 1 2 5 15
  620. dialog --title $"Remove pinning for a domain" \
  621. --backtitle $"Freedombone Security Settings" \
  622. --inputbox $"Enter the website domain name (without https://)" 8 60 2>$data
  623. sel=$?
  624. case $sel in
  625. 0)
  626. domain=$(<$data)
  627. ${PROJECT_NAME}-pin-cert "$domain" remove
  628. if [ ! "$?" = "0" ]; then
  629. dialog --title $"Removed pinning from $domain" \
  630. --msgbox "$?" 6 40
  631. fi
  632. ;;
  633. esac
  634. }
  635. function store_passwords {
  636. dialog --title $"Store Passwords" \
  637. --backtitle $"Freedombone Security Configuration" \
  638. --yesno $"\nDo you wish to store passwords on the system? Stored passwords are convenient but carry some additional security risk." 10 60
  639. sel=$?
  640. case $sel in
  641. 0)
  642. if [ -f /root/.nostore ]; then
  643. read_config_param "MY_USERNAME"
  644. if [ ! -f /home/$MY_USERNAME/.ssh/authorized_keys ]; then
  645. dialog --title $"Store Passwords" \
  646. --msgbox $"\nYou should first enable key based ssh login to improve security" 8 60
  647. return
  648. fi
  649. if [[ $SSH_PASSWORDS == 'yes' ]]; then
  650. dialog --title $"Store Passwords" \
  651. --msgbox $"\nYou should disable ssh passwords to improve security" 8 60
  652. return
  653. fi
  654. ${PROJECT_NAME}-pass --enable yes
  655. dialog --title $"Store Passwords" \
  656. --msgbox $"\nUser passwords will now be stored on the system" 8 60
  657. fi
  658. return
  659. ;;
  660. 1)
  661. ${PROJECT_NAME}-pass --clear yes
  662. dialog --title $"Passwords were removed and will not be stored" \
  663. --msgbox $"\nFor the best security you should now manually change passwords via web interfaces so that there is no possibility of them being recovered from the disk" 9 60
  664. return
  665. ;;
  666. 255) return;;
  667. esac
  668. }
  669. function menu_security_settings {
  670. data=$(tempfile 2>/dev/null)
  671. trap "rm -f $data" 0 1 2 5 15
  672. dialog --backtitle $"Freedombone Control Panel" \
  673. --title $"Security Settings" \
  674. --radiolist $"Choose an operation:" 19 76 19 \
  675. 1 $"Show ssh host public key" off \
  676. 2 $"Password storage" off \
  677. 3 $"Export passwords" off \
  678. 4 $"Regenerate ssh host keys" off \
  679. 5 $"Regenerate Diffie-Hellman keys" off \
  680. 6 $"Update cipersuite" off \
  681. 7 $"Create a new Let's Encrypt certificate" off \
  682. 8 $"Renew Let's Encrypt certificate" off \
  683. 9 $"Enable GPG based authentication (monkeysphere)" off \
  684. 10 $"Register a website with monkeysphere" off \
  685. 11 $"Allow ssh login with passwords" off \
  686. 12 $"Go Back/Exit" on 2> $data
  687. sel=$?
  688. case $sel in
  689. 1) exit 1;;
  690. 255) exit 1;;
  691. esac
  692. clear
  693. read_config_param SSL_CIPHERS
  694. read_config_param SSL_PROTOCOLS
  695. read_config_param SSH_CIPHERS
  696. read_config_param SSH_MACS
  697. read_config_param SSH_KEX
  698. get_imap_settings
  699. get_ssh_settings
  700. get_xmpp_settings
  701. import_settings
  702. export_settings
  703. case $(cat $data) in
  704. 1)
  705. dialog --title $"SSH host public keys" \
  706. --msgbox "\n$(get_ssh_server_key)" 12 60
  707. exit 0
  708. ;;
  709. 2)
  710. store_passwords
  711. exit 0
  712. ;;
  713. 3)
  714. export_passwords
  715. exit 0
  716. ;;
  717. 4)
  718. regenerate_ssh_host_keys
  719. ;;
  720. 5)
  721. regenerate_dh_keys
  722. ;;
  723. 6)
  724. interactive_setup
  725. update_ciphersuite
  726. ;;
  727. 7)
  728. create_letsencrypt
  729. ;;
  730. 8)
  731. renew_letsencrypt
  732. ;;
  733. 9)
  734. enable_monkeysphere
  735. ;;
  736. 10)
  737. register_website
  738. ;;
  739. 11)
  740. allow_ssh_passwords
  741. change_ssh_settings
  742. exit 0
  743. ;;
  744. 12)
  745. exit 0
  746. ;;
  747. esac
  748. change_website_settings
  749. change_imap_settings
  750. change_ssh_settings
  751. change_xmpp_settings
  752. }
  753. function import_settings {
  754. cd $CURRENT_DIR
  755. if [ ! $IMPORT_FILE ]; then
  756. return
  757. fi
  758. if [ ! -f $IMPORT_FILE ]; then
  759. echo $"Import file $IMPORT_FILE not found"
  760. exit 6393
  761. fi
  762. if grep -q "SSL_PROTOCOLS" $IMPORT_FILE; then
  763. TEMP_VALUE=$(grep "SSL_PROTOCOLS" $IMPORT_FILE | awk -F '=' '{print $2}')
  764. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  765. SSL_PROTOCOLS=$TEMP_VALUE
  766. fi
  767. fi
  768. if grep -q "SSL_CIPHERS" $IMPORT_FILE; then
  769. TEMP_VALUE=$(grep "SSL_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  770. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  771. SSL_CIPHERS=$TEMP_VALUE
  772. fi
  773. fi
  774. if grep -q "SSH_CIPHERS" $IMPORT_FILE; then
  775. TEMP_VALUE=$(grep "SSH_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  776. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  777. SSH_CIPHERS=$TEMP_VALUE
  778. fi
  779. fi
  780. if grep -q "SSH_MACS" $IMPORT_FILE; then
  781. TEMP_VALUE=$(grep "SSH_MACS" $IMPORT_FILE | awk -F '=' '{print $2}')
  782. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  783. SSH_MACS=$TEMP_VALUE
  784. fi
  785. fi
  786. if grep -q "SSH_KEX" $IMPORT_FILE; then
  787. TEMP_VALUE=$(grep "SSH_KEX" $IMPORT_FILE | awk -F '=' '{print $2}')
  788. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  789. SSH_KEX=$TEMP_VALUE
  790. fi
  791. fi
  792. if grep -q "SSH_HOST_KEY_ALGORITHMS" $IMPORT_FILE; then
  793. TEMP_VALUE=$(grep "SSH_HOST_KEY_ALGORITHMS" $IMPORT_FILE | awk -F '=' '{print $2}')
  794. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  795. SSH_HOST_KEY_ALGORITHMS=$TEMP_VALUE
  796. fi
  797. fi
  798. if grep -q "SSH_PASSWORDS" $IMPORT_FILE; then
  799. TEMP_VALUE=$(grep "SSH_PASSWORDS" $IMPORT_FILE | awk -F '=' '{print $2}')
  800. if [[ $TEMP_VALUE == "yes" || $TEMP_VALUE == "no" ]]; then
  801. SSH_PASSWORDS=$TEMP_VALUE
  802. fi
  803. fi
  804. if grep -q "XMPP_CIPHERS" $IMPORT_FILE; then
  805. TEMP_VALUE=$(grep "XMPP_CIPHERS" $IMPORT_FILE | awk -F '=' '{print $2}')
  806. if [ ${#TEMP_VALUE} -gt $MINIMUM_LENGTH ]; then
  807. XMPP_CIPHERS=$TEMP_VALUE
  808. fi
  809. fi
  810. if grep -q "XMPP_ECC_CURVE" $IMPORT_FILE; then
  811. TEMP_VALUE=$(grep "XMPP_ECC_CURVE" $IMPORT_FILE | awk -F '=' '{print $2}')
  812. if [ ${#TEMP_VALUE} -gt 3 ]; then
  813. XMPP_ECC_CURVE=$TEMP_VALUE
  814. fi
  815. fi
  816. }
  817. function export_settings {
  818. if [ ! $EXPORT_FILE ]; then
  819. return
  820. fi
  821. cd $CURRENT_DIR
  822. if [ ! -f $EXPORT_FILE ]; then
  823. if [ "$SSL_PROTOCOLS" ]; then
  824. echo "SSL_PROTOCOLS=$SSL_PROTOCOLS" >> $EXPORT_FILE
  825. fi
  826. if [ $SSL_CIPHERS ]; then
  827. echo "SSL_CIPHERS=$SSL_CIPHERS" >> $EXPORT_FILE
  828. fi
  829. if [ $SSH_CIPHERS ]; then
  830. echo "SSH_CIPHERS=$SSH_CIPHERS" >> $EXPORT_FILE
  831. fi
  832. if [ $SSH_MACS ]; then
  833. echo "SSH_MACS=$SSH_MACS" >> $EXPORT_FILE
  834. fi
  835. if [ $SSH_KEX ]; then
  836. echo "SSH_KEX=$SSH_KEX" >> $EXPORT_FILE
  837. fi
  838. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  839. echo "SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS" >> $EXPORT_FILE
  840. fi
  841. if [ $SSH_PASSWORDS ]; then
  842. echo "SSH_PASSWORDS=$SSH_PASSWORDS" >> $EXPORT_FILE
  843. fi
  844. if [ $XMPP_CIPHERS ]; then
  845. echo "XMPP_CIPHERS=$XMPP_CIPHERS" >> $EXPORT_FILE
  846. fi
  847. if [ $XMPP_ECC_CURVE ]; then
  848. echo "XMPP_ECC_CURVE=$XMPP_ECC_CURVE" >> $EXPORT_FILE
  849. fi
  850. echo "Security settings exported to $EXPORT_FILE"
  851. exit 0
  852. fi
  853. if [ "$SSL_PROTOCOLS" ]; then
  854. if grep -q "SSL_PROTOCOLS" $EXPORT_FILE; then
  855. sed -i "s|SSL_PROTOCOLS=.*|SSL_PROTOCOLS=$SSL_PROTOCOLS|g" $EXPORT_FILE
  856. else
  857. echo "SSL_PROTOCOLS=$SSL_PROTOCOLS" >> $EXPORT_FILE
  858. fi
  859. fi
  860. if [ $SSL_CIPHERS ]; then
  861. if grep -q "SSL_CIPHERS" $EXPORT_FILE; then
  862. sed -i "s|SSL_CIPHERS=.*|SSL_CIPHERS=$SSL_CIPHERS|g" $EXPORT_FILE
  863. else
  864. echo "SSL_CIPHERS=$SSL_CIPHERS" >> $EXPORT_FILE
  865. fi
  866. fi
  867. if [ $SSH_CIPHERS ]; then
  868. if grep -q "SSH_CIPHERS" $EXPORT_FILE; then
  869. sed -i "s|SSH_CIPHERS=.*|SSH_CIPHERS=$SSH_CIPHERS|g" $EXPORT_FILE
  870. else
  871. echo "SSH_CIPHERS=$SSH_CIPHERS" >> $EXPORT_FILE
  872. fi
  873. fi
  874. if [ $SSH_MACS ]; then
  875. if grep -q "SSH_MACS" $EXPORT_FILE; then
  876. sed -i "s|SSH_MACS=.*|SSH_MACS=$SSH_MACS|g" $EXPORT_FILE
  877. else
  878. echo "SSH_MACS=$SSH_MACS" >> $EXPORT_FILE
  879. fi
  880. fi
  881. if [ $SSH_KEX ]; then
  882. if grep -q "SSH_KEX" $EXPORT_FILE; then
  883. sed -i "s|SSH_KEX=.*|SSH_KEX=$SSH_KEX|g" $EXPORT_FILE
  884. else
  885. echo "SSH_KEX=$SSH_KEX" >> $EXPORT_FILE
  886. fi
  887. fi
  888. if [ $SSH_HOST_KEY_ALGORITHMS ]; then
  889. if grep -q "SSH_HOST_KEY_ALGORITHMS" $EXPORT_FILE; then
  890. sed -i "s|SSH_HOST_KEY_ALGORITHMS=.*|SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS|g" $EXPORT_FILE
  891. else
  892. echo "SSH_HOST_KEY_ALGORITHMS=$SSH_HOST_KEY_ALGORITHMS" >> $EXPORT_FILE
  893. fi
  894. fi
  895. if [ $SSH_PASSWORDS ]; then
  896. if grep -q "SSH_PASSWORDS" $EXPORT_FILE; then
  897. sed -i "s|SSH_PASSWORDS=.*|SSH_PASSWORDS=$SSH_PASSWORDS|g" $EXPORT_FILE
  898. else
  899. echo "SSH_PASSWORDS=$SSH_PASSWORDS" >> $EXPORT_FILE
  900. fi
  901. fi
  902. if [ $XMPP_CIPHERS ]; then
  903. if grep -q "XMPP_CIPHERS" $EXPORT_FILE; then
  904. sed -i "s|XMPP_CIPHERS=.*|XMPP_CIPHERS=$XMPP_CIPHERS|g" $EXPORT_FILE
  905. else
  906. echo "XMPP_CIPHERS=$XMPP_CIPHERS" >> $EXPORT_FILE
  907. fi
  908. fi
  909. if [ $XMPP_ECC_CURVE ]; then
  910. if grep -q "XMPP_ECC_CURVE" $EXPORT_FILE; then
  911. sed -i "s|XMPP_ECC_CURVE=.*|XMPP_ECC_CURVE=$XMPP_ECC_CURVE|g" $EXPORT_FILE
  912. else
  913. echo "XMPP_ECC_CURVE=$XMPP_ECC_CURVE" >> $EXPORT_FILE
  914. fi
  915. fi
  916. echo $"Security settings exported to $EXPORT_FILE"
  917. exit 0
  918. }
  919. function refresh_gpg_keys {
  920. for d in /home/*/ ; do
  921. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  922. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  923. su -c 'gpg --refresh-keys' - $USERNAME
  924. fi
  925. done
  926. exit 0
  927. }
  928. function monkeysphere_sign_server_keys {
  929. server_keys_file=/home/$USER/.monkeysphere/server_keys
  930. if [ ! -f $server_keys_file ]; then
  931. exit 0
  932. fi
  933. keys_signed=
  934. while read line; do
  935. echo $line
  936. if [ ${#line} -gt 2 ]; then
  937. fpr=$(gpg --with-colons --fingerprint "$line" | grep fpr | head -n 1 | awk -F ':' '{print $10}')
  938. if [ ${#fpr} -gt 2 ]; then
  939. gpg --sign-key $fpr
  940. if [ "$?" = "0" ]; then
  941. gpg --update-trustdb
  942. keys_signed=1
  943. fi
  944. fi
  945. fi
  946. done <$server_keys_file
  947. if [ $keys_signed ]; then
  948. rm $server_keys_file
  949. fi
  950. exit 0
  951. }
  952. function htmly_hash {
  953. # produces a hash corresponding to a htmly password
  954. pass="$1"
  955. HTMLYHASH_FILENAME=/usr/bin/htmlyhash
  956. echo '<?php' > $HTMLYHASH_FILENAME
  957. echo 'parse_str(implode("&", array_slice($argv, 1)), $_GET);' >> $HTMLYHASH_FILENAME
  958. echo '$password = $_GET["password"];' >> $HTMLYHASH_FILENAME
  959. echo '$hash = password_hash($password, PASSWORD_BCRYPT);' >> $HTMLYHASH_FILENAME
  960. echo 'if (password_verify($password, $hash)) {' >> $HTMLYHASH_FILENAME
  961. echo ' echo $hash;' >> $HTMLYHASH_FILENAME
  962. echo '}' >> $HTMLYHASH_FILENAME
  963. echo '?>' >> $HTMLYHASH_FILENAME
  964. php $HTMLYHASH_FILENAME password="$pass"
  965. }
  966. function show_help {
  967. echo ''
  968. echo "${PROJECT_NAME}-sec"
  969. echo ''
  970. echo $'Alters the security settings'
  971. echo ''
  972. echo ''
  973. echo $' -h --help Show help'
  974. echo $' -e --export Export security settings to a file'
  975. echo $' -i --import Import security settings from a file'
  976. echo $' -r --refresh Refresh GPG keys for all users'
  977. echo $' -s --sign Sign monkeysphere server keys'
  978. echo $' --register [domain] Register a https domain with monkeysphere'
  979. echo $' -b --htmlyhash [password] Returns the hash of a password for a htmly blog'
  980. echo ''
  981. exit 0
  982. }
  983. # Get the commandline options
  984. while [[ $# > 1 ]]
  985. do
  986. key="$1"
  987. case $key in
  988. -h|--help)
  989. show_help
  990. ;;
  991. # Export settings
  992. -e|--export)
  993. shift
  994. EXPORT_FILE="$1"
  995. ;;
  996. # Export settings
  997. -i|--import)
  998. shift
  999. IMPORT_FILE="$1"
  1000. ;;
  1001. # Refresh GPG keys
  1002. -r|--refresh)
  1003. shift
  1004. refresh_gpg_keys
  1005. ;;
  1006. # register a website
  1007. --register|--reg|--site)
  1008. shift
  1009. register_website "$1"
  1010. ;;
  1011. # user signs monkeysphere server keys
  1012. -s|--sign)
  1013. shift
  1014. monkeysphere_sign_server_keys
  1015. ;;
  1016. # get a hash of the given htmly password
  1017. -b|--htmlyhash)
  1018. shift
  1019. htmly_hash "$1"
  1020. exit 0
  1021. ;;
  1022. *)
  1023. # unknown option
  1024. ;;
  1025. esac
  1026. shift
  1027. done
  1028. menu_security_settings
  1029. exit 0