|
@@ -0,0 +1,158 @@
|
|
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
|
+
|
|
31
|
+NO_OF_ARGS=$#
|
|
32
|
+
|
|
33
|
+SSL_PROTOCOLS=
|
|
34
|
+SSL_CIPHERS=
|
|
35
|
+SSH_CIPHERS=
|
|
36
|
+SSH_MACS=
|
|
37
|
+SSH_KEX=
|
|
38
|
+SSH_HOST_KEY_ALGORITHMS=
|
|
39
|
+XMPP_CIPHERS=
|
|
40
|
+XMPP_ECC_CURVE=
|
|
41
|
+
|
|
42
|
+WIKI_DOMAIN_NAME=
|
|
43
|
+WEBSITES_DIRECTORY='/etc/nginx/sites-available'
|
|
44
|
+DOVECOT_CIPHERS='/etc/dovecot/conf.d/10-ssl.conf'
|
|
45
|
+
|
|
46
|
+MINIMUM_LENGTH=6
|
|
47
|
+
|
|
48
|
+function get_protocols_from_website {
|
|
49
|
+ if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
|
|
50
|
+ return
|
|
51
|
+ fi
|
|
52
|
+ SSL_PROTOCOLS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_protocols' | awk -F "ssl_protocols" '{print $2}' | awk -F ';' '{print $1}')
|
|
53
|
+}
|
|
54
|
+
|
|
55
|
+function get_ciphers_from_website {
|
|
56
|
+ if [ ! -f $WEBSITES_DIRECTORY/$1 ]; then
|
|
57
|
+ return
|
|
58
|
+ fi
|
|
59
|
+ SSL_CIPHERS=$(cat $WEBSITES_DIRECTORY/$1 | grep 'ssl_ciphers' | awk -F "ssl_ciphers" '{print $2}' | awk -F "'" '{print $2}')
|
|
60
|
+}
|
|
61
|
+
|
|
62
|
+function get_website_settings {
|
|
63
|
+ if [ ! -d $WEBSITES_DIRECTORY ]; then
|
|
64
|
+ return
|
|
65
|
+ fi
|
|
66
|
+
|
|
67
|
+ cd $WEBSITES_DIRECTORY
|
|
68
|
+ for file in `dir -d *` ; do
|
|
69
|
+ get_protocols_from_website $file
|
|
70
|
+ if [ ${#SSL_PROTOCOLS} -gt $MINIMUM_LENGTH ]; then
|
|
71
|
+ get_ciphers_from_website $file
|
|
72
|
+ if [ ${#SSL_CIPHERS} -gt $MINIMUM_LENGTH ]; then
|
|
73
|
+ break
|
|
74
|
+ else
|
|
75
|
+ SSL_PROTOCOLS=""
|
|
76
|
+ fi
|
|
77
|
+ fi
|
|
78
|
+ done
|
|
79
|
+}
|
|
80
|
+
|
|
81
|
+function get_imap_settings {
|
|
82
|
+ if [ ! -f $DOVECOT_CIPHERS ]; then
|
|
83
|
+ return
|
|
84
|
+ fi
|
|
85
|
+ # clear commented out cipher list
|
|
86
|
+ sed -i "s|#ssl_cipher_list.*||g" $DOVECOT_CIPHERS
|
|
87
|
+ if [ ! $SSL_CIPHERS ]; then
|
|
88
|
+ return
|
|
89
|
+ fi
|
|
90
|
+ if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
|
|
91
|
+ return
|
|
92
|
+ fi
|
|
93
|
+ SSL_CIPHERS=$(cat $DOVECOT_CIPHERS | grep 'ssl_cipher_list' | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
|
|
94
|
+}
|
|
95
|
+
|
|
96
|
+function change_website_settings {
|
|
97
|
+ if [ ! $SSL_PROTOCOLS ]; then
|
|
98
|
+ return
|
|
99
|
+ fi
|
|
100
|
+ if [ ! $SSL_CIPHERS ]; then
|
|
101
|
+ return
|
|
102
|
+ fi
|
|
103
|
+ if [ ${#SSL_PROTOCOLS} -lt $MINIMUM_LENGTH ]; then
|
|
104
|
+ return
|
|
105
|
+ fi
|
|
106
|
+ if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
|
|
107
|
+ return
|
|
108
|
+ fi
|
|
109
|
+ if [ ! -d $WEBSITES_DIRECTORY ]; then
|
|
110
|
+ return
|
|
111
|
+ fi
|
|
112
|
+
|
|
113
|
+ cd $WEBSITES_DIRECTORY
|
|
114
|
+ for file in `dir -d *` ; do
|
|
115
|
+ sed -i "s|ssl_protocols .*|ssl_protocols $SSL_PROTOCOLS;|g" $WEBSITES_DIRECTORY/$file
|
|
116
|
+ sed -i "s|ssl_ciphers .*|ssl_ciphers '$SSL_CIPHERS';|g" $WEBSITES_DIRECTORY/$file
|
|
117
|
+ done
|
|
118
|
+ service nginx restart
|
|
119
|
+}
|
|
120
|
+
|
|
121
|
+function change_imap_settings {
|
|
122
|
+ if [ ! -f $DOVECOT_CIPHERS ]; then
|
|
123
|
+ return
|
|
124
|
+ fi
|
|
125
|
+ if [ ! $SSL_CIPHERS ]; then
|
|
126
|
+ return
|
|
127
|
+ fi
|
|
128
|
+ if [ ${#SSL_CIPHERS} -lt $MINIMUM_LENGTH ]; then
|
|
129
|
+ return
|
|
130
|
+ fi
|
|
131
|
+ sed -i "s|ssl_cipher_list.*|ssl_cipher_list = '$SSL_CIPHERS'|g" $DOVECOT_CIPHERS
|
|
132
|
+ service dovecot restart
|
|
133
|
+}
|
|
134
|
+
|
|
135
|
+while [[ $# > 1 ]]
|
|
136
|
+do
|
|
137
|
+key="$1"
|
|
138
|
+
|
|
139
|
+case $key in
|
|
140
|
+ -h|--help)
|
|
141
|
+ show_help
|
|
142
|
+ ;;
|
|
143
|
+ # username within /home
|
|
144
|
+ -u|--user)
|
|
145
|
+ shift
|
|
146
|
+ MY_USERNAME="$1"
|
|
147
|
+ ;;
|
|
148
|
+ *)
|
|
149
|
+ # unknown option
|
|
150
|
+ ;;
|
|
151
|
+esac
|
|
152
|
+shift
|
|
153
|
+done
|
|
154
|
+
|
|
155
|
+get_website_settings
|
|
156
|
+#change_website_settings
|
|
157
|
+#change_imap_settings
|
|
158
|
+exit 0
|