├── README.md
├── cron.sh
├── md5sum.txt
├── sendmsg.sh
├── setting.conf
├── vddos-autoswitch.sh
├── vddos-sensor.sh
└── vddos-switch.sh
/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |
4 | vDDoS Auto Switch
5 | ===================
6 |
7 |
8 | vDDoS Auto Switch is a addon support for vDDoS Proxy Protection - Automatically identifies **overloaded websites** and changes their **Security Mode**.
9 |
10 | ----------
11 |
12 | 1/ Install vDDoS Proxy Protection:
13 | -------------
14 | To install vDDoS Proxy Protection please visit this site: http://vddos.voduy.com
15 |
16 | ----------
17 |
18 |
19 | 2/ Install vDDoS Auto Switch:
20 | -------------
21 | ```
22 | curl -L https://github.com/duy13/vDDoS-Auto-Switch/archive/master.zip -o vddos-auto-switch.zip ; unzip vddos-auto-switch.zip ; rm -f vddos-auto-switch.zip
23 | mv vDDoS-Auto-Switch-master /vddos/auto-switch
24 | chmod 700 /vddos/auto-switch/*.sh
25 | ln -s /vddos/auto-switch/vddos-autoswitch.sh /usr/bin/vddos-autoswitch
26 | ln -s /vddos/auto-switch/vddos-switch.sh /usr/bin/vddos-switch
27 | ln -s /vddos/auto-switch/vddos-sensor.sh /usr/bin/vddos-sensor
28 |
29 | ```
30 |
31 | ----------
32 |
33 | 3/ Config vDDoS Auto Switch:
34 | -------------
35 |
36 | ```
37 | nano /vddos/auto-switch/setting.conf
38 |
39 |
40 | # This is the default configuration for "sensor-switch.sh" and "vddos-autoswitch.sh"
41 |
42 |
43 | hostname="vDDoS Master" #(Name this server, it will show up in Email notifications)
44 |
45 | vddos_master_slave_mode="no" #(Turn on "yes" if your system has slave servers, want to sync affter switch like master)
46 | backend_url_check="no" #(Put the URL of the backend. Ex: https://1.1.1.1:8443/ (make sure Backend status response is "200"))
47 |
48 | send_notifications="no" #(Turn on "yes" if you want receive notification)
49 | smtp_server="smtps://smtp.gmail.com" #(SMTP Server)
50 | smtp_username="xxx@gmail.com" #(Your Mail)
51 | smtp_password="xxxxxxxxxxxxx" #(Get your Apps password for Gmail from https://security.google.com/settings/security/apppasswords)
52 | send_notifications_to="xxxx@gmail.com" #(Your Email Address will receive notification)
53 |
54 |
55 | maximum_allowable_delay_for_backend=2 #(Means: If Backend (status response "200") is slower than 2s, vDDoS will enable challenge mode)
56 | maximum_allowable_delay_for_website=2 #(Means: If Website (status response "200") is slower than 2s, vDDoS will enable challenge mode)
57 |
58 | default_switch_mode_not_attack="no" #(Default Mode vDDoS use when it's not under attacked)
59 | default_switch_mode_under_attack="high" #(Default Mode vDDoS use when it's under attack)
60 | default_waiting_time_to_release="60" #(For example 60 minutes, release time from challenge)
61 |
62 | ```
63 |
64 |
65 | ----------
66 |
67 | 4/ Using vDDoS Auto Switch:
68 | -------------
69 |
70 | */usr/bin/vddos-autoswitch* automatically *identifies* **overloaded websites** (if the website can not respond **200 HTTP Status** after 2 seconds - it mean they are too slow or high load...) And after that *vddos-autoswitch* will *changes* their **Security Mode** in */vddos/conf.d/website.conf*:
71 |
72 | **WARNING: Please remove [...] in all the below commands!**
73 |
74 | Auto check/switch for a domain:
75 | -------------
76 |
77 | Auto check/switch security mode for a domain (already in the *website.conf* file) to 5s mode (if it is being slow/high load):
78 | ```
79 | /usr/bin/vddos-autoswitch [checkdomain] your-domain.com 5s
80 |
81 | ```
82 |
83 | Auto check/switch for a list domains:
84 | -------------
85 |
86 | Auto check/switch security mode for each all domains (already in the *website.conf* file) to 5s mode (if it is being slow/high load):
87 | ```
88 | /usr/bin/vddos-autoswitch [checkalldomain] 5s
89 |
90 | ```
91 |
92 | Auto check/switch security mode for each domain in the list domains to 5s mode (if it is being slow/high load):
93 | ```
94 | /usr/bin/vddos-autoswitch [checklist] /etc/listdomains.txt 5s
95 |
96 | ```
97 |
98 | Flush all security mode for all domain (already in the *website.conf* file) if they are not slow/high load:
99 | ```
100 | /usr/bin/vddos-autoswitch [flushalldomain] /etc/listdomains.txt no
101 |
102 | ```
103 |
104 | 5/ Crontab vDDoS Auto Switch:
105 | -------------
106 |
107 | If you want to automate the inspection and changes website's **Security Mode**. You can configure vDDoS Auto Switch to crontab as follows:
108 |
109 | For example, check the status of every website every 3 minutes and automatically flush all security mode for them (if their **security mode** have been switch) every 30 minutes:
110 | ```
111 | echo '*/3 * * * * root /usr/bin/vddos-autoswitch checkalldomain high' >> /etc/crontab
112 | echo '*/30 * * * * root /usr/bin/vddos-autoswitch flushalldomain /vddos/conf.d/website.conf no' >> /etc/crontab
113 | echo '* * * * * root /usr/bin/vddos-sensor' >> /etc/crontab
114 | ```
115 | Or you have a list of special domains that need to check the status of every website every 3 minutes and automatically flush all security mode for them every 30 minutes:
116 | ```
117 | echo '*/3 * * * * root /usr/bin/vddos-autoswitch checklist /etc/listspecialdomains.txt captcha' >> /etc/crontab
118 | echo '*/30 * * * * root /usr/bin/vddos-autoswitch flushalldomain /etc/listspecialdomains.txt no' >> /etc/crontab
119 |
120 | ```
121 |
122 |
123 | 6/ More Config:
124 | ---------------
125 | Document: http://vddos.voduy.com
126 | ```
127 | Still in beta, use at your own risk! It is provided without any warranty!
128 | ```
--------------------------------------------------------------------------------
/cron.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #chmod 700 /vddos/auto-switch/cron.sh
4 | #ln -s /vddos/auto-switch/cron.sh /usr/bin/vddos-autoswitch
5 | #chmod 700 /vddos/auto-switch/vddos-switch.sh
6 | #ln -s /vddos/auto-switch/vddos-switch.sh /usr/bin/vddos-switch
7 |
8 | # Example:
9 | # Auto check/switch security mode for a domain (in website.conf) if it is being slow/high load:
10 | # vddos-autoswitch [checkdomain] your-domain.com 5s
11 |
12 | # Auto check/switch security mode for each domain in the list website.conf if it is being slow/high load:
13 | # vddos-autoswitch [checkalldomain] 5s
14 |
15 | # Auto check/switch for each domain in the list domains if it is being slow/high load:
16 | # vddos-autoswitch [checklist] /etc/listdomains.txt 5s
17 |
18 | # Flush all security mode for all domain (in website.conf) if they are not slow/high load:
19 | # vddos-autoswitch [flushalldomain] /etc/listdomains.txt no
20 | # OR:
21 | # vddos-switch [allsite] [no/307/200...] ; vddos restart
22 |
23 |
24 |
25 | if [ ! -f /usr/bin/vddos-switch ] || [ ! -f /usr/bin/vddos-autoswitch ]; then
26 | chmod 700 /vddos/auto-switch/cron.sh
27 | ln -s /vddos/auto-switch/cron.sh /usr/bin/vddos-autoswitch
28 | chmod 700 /vddos/auto-switch/vddos-switch.sh
29 | ln -s /vddos/auto-switch/vddos-switch.sh /usr/bin/vddos-switch
30 | fi
31 |
32 | function showerror()
33 | {
34 | echo 'ERROR!
35 |
36 | Command is ['$1'] ...
37 | Website or List is ['$2'] ...
38 | Security mode is ['$3']
39 |
40 | # Example:
41 | # Auto check/switch security mode for a domain (in website.conf) if it is being slow/high load:
42 | vddos-autoswitch [checkdomain] your-domain.com 5s
43 |
44 | # Auto check/switch security mode for each domain in the list website.conf if it is being slow/high load:
45 | vddos-autoswitch [checkalldomain] 5s
46 |
47 | # Auto check/switch for each domain in the list domains if it is being slow/high load:
48 | vddos-autoswitch [checklist] /etc/listdomains.txt 5s
49 |
50 |
51 | # Flush all security mode for all domain (in website.conf) if they are not slow/high load:
52 | vddos-switch [allsite] no
53 | # OR:
54 | vddos-switch [allsite] [no/307/200...]
55 |
56 | '|tee -a /vddos/auto-switch/log.txt
57 | return 0
58 | }
59 | function checklog()
60 | {
61 | echo '
62 | (Check logs at /vddos/auto-switch/log.txt)
63 | '
64 | return 0
65 | }
66 |
67 |
68 |
69 |
70 |
71 |
72 | Command="$1"
73 | Security_mode="$3"
74 |
75 |
76 | if [ "$1" = "" ] || [ "$2" = "" ]; then
77 | showerror
78 | exit 0
79 | fi
80 |
81 | if [ "$Command" != "checkdomain" ] && [ "$Command" != "checklist" ] && [ "$Command" != "checkalldomain" ]; then
82 | showerror
83 | exit 0
84 | fi
85 |
86 | if [ "$Command" = "checkdomain" ] || [ "$Command" = "checklist" ]; then
87 | if [ "$3" = "" ]; then
88 | showerror
89 | exit 0
90 | fi
91 | fi
92 |
93 |
94 |
95 | if [ "$Command" = "checkdomain" ]; then
96 | echo "
97 | [[[[[[[ `date` ]]]]]]]
98 | " > /vddos/auto-switch/log.txt
99 |
100 | md5sum_website_conf_latest=`cat /vddos/conf.d/website.conf| grep . | awk '!x[$0]++'| md5sum | awk 'NR==1 {print $1}'`
101 |
102 | Website="$2"
103 | Available=`awk -F: "/^$Website/" /vddos/conf.d/website.conf`
104 | WebsiteSecurityModeCurrent=`awk -F: "/^$Website/" /vddos/conf.d/website.conf| awk 'NR==1 {print $5}'`
105 | if [ "$Available" = "" ]; then
106 | echo '- Re-check: ['$Website'] is not available in /vddos/conf.d/website.conf ===> Skip!'|tee -a /vddos/auto-switch/log.txt
107 | fi
108 | if [ "$Available" != "" ]; then
109 | if [ "$WebsiteSecurityModeCurrent" = "$Security_mode" ]; then
110 | echo '- Re-check: ['$Website'] is already ['$WebsiteSecurityModeCurrent'] security mode ===> Skip!'|tee -a /vddos/auto-switch/log.txt
111 | fi
112 | if [ "$WebsiteSecurityModeCurrent" != "$Security_mode" ]; then
113 | websitestatus=`curl --user-agent "vDDos Auto Switch Check" --connect-timeout 2 --max-time 2 -s -o /dev/null -L -I -w "%{http_code}" $Website | awk '{print substr($0,1,1)}'`
114 | if [ "$websitestatus" != "2" ] && [ "$websitestatus" != "3" ]; then
115 | echo ' Found ['$Website'] in /vddos/conf.d/website.conf seems to be in the offline state: ['$websitestatus'xx']|tee -a /vddos/auto-switch/log.txt
116 | /usr/bin/vddos-switch $Website $Security_mode
117 | fi
118 | if [ "$websitestatus" = "2" ] || [ "$websitestatus" = "3" ]; then
119 | echo '- Re-check: ['$Website'] seems to be in the online state: ['$websitestatus'xx] ===> Skip!'|tee -a /vddos/auto-switch/log.txt
120 | fi
121 | fi
122 | fi
123 | md5sum_website_conf_new=`cat /vddos/conf.d/website.conf| grep . | awk '!x[$0]++'| md5sum | awk 'NR==1 {print $1}'`
124 | if [ "$md5sum_website_conf_latest" != "$md5sum_website_conf_new" ]; then
125 | /usr/bin/vddos reload |tee -a /vddos/auto-switch/log.txt
126 | fi
127 | checklog
128 | exit 0
129 | fi
130 |
131 | if [ "$Command" = "checklist" ]; then
132 | listdomains_source="$2"
133 | listdomains="/vddos/auto-switch/list/listdomains.txt"
134 | if [ ! -f $listdomains_source ]; then
135 | showerror
136 | echo ''$listdomains_source' not found!'
137 | exit 0
138 | fi
139 |
140 | if [ ! -d /vddos/auto-switch/list/ ]; then
141 | mkdir -p /vddos/auto-switch/list/
142 | fi
143 |
144 | md5sum_website_conf_latest=`cat /vddos/conf.d/website.conf| grep . | awk '!x[$0]++'| md5sum | awk 'NR==1 {print $1}'`
145 |
146 | echo "
147 | [[[[[[[ `date` ]]]]]]]
148 | " > /vddos/auto-switch/log.txt
149 | echo "`cat $listdomains_source | grep . | awk '!x[$0]++'`" > $listdomains
150 | numberlinelistdomains=`cat $listdomains | grep . | wc -l`
151 | startlinenumber=1
152 |
153 | dong=$startlinenumber
154 | while [ $dong -le $numberlinelistdomains ]
155 | do
156 | Website=$(awk " NR == $dong " $listdomains); echo $Website
157 | Available=`awk -F: "/^$Website/" /vddos/conf.d/website.conf`
158 | WebsiteSecurityModeCurrent=`awk -F: "/^$Website/" /vddos/conf.d/website.conf| awk 'NR==1 {print $5}'`
159 | if [ "$Available" = "" ]; then
160 | echo '- Re-check: ['$Website'] is not available in /vddos/conf.d/website.conf ===> Skip!'|tee -a /vddos/auto-switch/log.txt
161 | fi
162 | if [ "$Available" != "" ]; then
163 | if [ "$WebsiteSecurityModeCurrent" = "$Security_mode" ]; then
164 | echo '- Re-check: ['$Website'] is already ['$WebsiteSecurityModeCurrent'] security mode ===> Skip!'|tee -a /vddos/auto-switch/log.txt
165 | fi
166 | if [ "$WebsiteSecurityModeCurrent" != "$Security_mode" ]; then
167 | if [ "$Available" != "" ]; then
168 | websitestatus=`curl --user-agent "vDDos Auto Switch Check" --connect-timeout 2 --max-time 2 -s -o /dev/null -L -I -w "%{http_code}" $Website | awk '{print substr($0,1,1)}'`
169 | if [ "$websitestatus" != "2" ] && [ "$websitestatus" != "3" ]; then
170 | echo ' Found ['$Website'] in '$listdomains_source' seems to be in the offline state: ['$websitestatus'xx']|tee -a /vddos/auto-switch/log.txt
171 | /usr/bin/vddos-switch $Website $Security_mode
172 | fi
173 | if [ "$websitestatus" = "2" ] || [ "$websitestatus" = "3" ]; then
174 | echo '- Re-check: ['$Website'] seems to be in the online state: ['$websitestatus'xx] ===> Skip!'|tee -a /vddos/auto-switch/log.txt
175 | fi
176 | fi
177 | fi
178 | fi
179 | dong=$((dong + 1))
180 | done
181 |
182 | md5sum_website_conf_new=`cat /vddos/conf.d/website.conf| grep . | awk '!x[$0]++'| md5sum | awk 'NR==1 {print $1}'`
183 | if [ "$md5sum_website_conf_latest" != "$md5sum_website_conf_new" ]; then
184 | /usr/bin/vddos reload |tee -a /vddos/auto-switch/log.txt
185 | fi
186 | checklog
187 | exit 0
188 | fi
189 |
190 |
191 |
192 | if [ "$Command" = "checkalldomain" ]; then
193 | Security_mode="$2"
194 | listdomains_source="/vddos/conf.d/website.conf"
195 | listdomains="/vddos/auto-switch/checkalldomain/listdomains.txt"
196 | if [ ! -f $listdomains_source ]; then
197 | showerror
198 | echo ''$listdomains_source' not found!'
199 | exit 0
200 | fi
201 |
202 | if [ ! -d /vddos/auto-switch/checkalldomain/ ]; then
203 | mkdir -p /vddos/auto-switch/checkalldomain/
204 | fi
205 |
206 | echo "
207 | [[[[[[[ `date` ]]]]]]]
208 | " > /vddos/auto-switch/log.txt
209 | echo "`cat $listdomains_source | grep . | awk '{print $1}'| awk '!x[$0]++'|grep -v '^#'|grep -v '^*'|grep -v '^default'`" > $listdomains
210 |
211 | /usr/bin/vddos-autoswitch checklist $listdomains $Security_mode
212 |
213 | exit 0
214 | fi
215 |
216 |
217 |
218 |
219 | if [ "$Command" = "flushalldomain" ]; then
220 | listdomains_source="$2"
221 | listdomains="/vddos/auto-switch/flushalldomain/listdomains.txt"
222 | if [ ! -f $listdomains_source ]; then
223 | showerror
224 | echo ''$listdomains_source' not found!'
225 | exit 0
226 | fi
227 |
228 | if [ ! -d /vddos/auto-switch/flushalldomain/ ]; then
229 | mkdir -p /vddos/auto-switch/flushalldomain/
230 | fi
231 |
232 | md5sum_website_conf_latest=`cat /vddos/conf.d/website.conf| grep . | awk '!x[$0]++'| md5sum | awk 'NR==1 {print $1}'`
233 |
234 | echo "
235 | [[[[[[[ `date` ]]]]]]]
236 | " > /vddos/auto-switch/log.txt
237 | echo "`cat $listdomains_source | grep .|grep -v '^#'|grep -v '^*' | awk '{print $1}'| awk '!x[$0]++'`" > $listdomains
238 | numberlinelistdomains=`cat $listdomains | grep . | wc -l`
239 | startlinenumber=1
240 |
241 | dong=$startlinenumber
242 | while [ $dong -le $numberlinelistdomains ]
243 | do
244 | Website=$(awk " NR == $dong " $listdomains);
245 | Available=`awk -F: "/^$Website/" /vddos/conf.d/website.conf`
246 | WebsiteSecurityModeCurrent=`awk -F: "/^$Website/" /vddos/conf.d/website.conf| awk 'NR==1 {print $5}'`
247 | if [ "$Available" = "" ]; then
248 | echo '- Re-check: ['$Website'] is not available in /vddos/conf.d/website.conf ===> Skip!'|tee -a /vddos/auto-switch/log.txt
249 | fi
250 | if [ "$Available" != "" ]; then
251 | if [ "$WebsiteSecurityModeCurrent" = "$Security_mode" ]; then
252 | echo '- Re-check: ['$Website'] is already ['$WebsiteSecurityModeCurrent'] security mode ===> Skip!'|tee -a /vddos/auto-switch/log.txt
253 | fi
254 | if [ "$WebsiteSecurityModeCurrent" != "$Security_mode" ]; then
255 | if [ "$Available" != "" ]; then
256 | /usr/bin/vddos-switch $Website $Security_mode
257 | fi
258 | fi
259 | fi
260 | dong=$((dong + 1))
261 | done
262 |
263 | md5sum_website_conf_new=`cat /vddos/conf.d/website.conf| grep . | awk '!x[$0]++'| md5sum | awk 'NR==1 {print $1}'`
264 | if [ "$md5sum_website_conf_latest" != "$md5sum_website_conf_new" ]; then
265 | /usr/bin/vddos reload |tee -a /vddos/auto-switch/log.txt
266 | fi
267 | checklog
268 | exit 0
269 | fi
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
--------------------------------------------------------------------------------
/md5sum.txt:
--------------------------------------------------------------------------------
1 | 1441836bd295837b6ab85238f6aebcea cron.sh
2 | 6ce6dc5edbcd4254396444fb95825fe6 md5sum.txt
3 | aad7494f3f2bdcf8e299653f563eb843 README.md
4 | bfd39f2f8054a5ddb11daf3a11d8458c sendmsg.sh
5 | d179fa40eca4fd5cc387bc775627ac2d setting.conf
6 | 0ba1c3805f205db864749d2175b29dc1 vddos-autoswitch.sh
7 | eaee476fdaa6e6984d03866cadacfc05 vddos-sensor.sh
8 | 319818ca9cb06efb1e3c62b81e3b5250 vddos-switch.sh
9 |
--------------------------------------------------------------------------------
/sendmsg.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Teal Dulcet
4 | # Send e-mail, with optional message and attachments
5 |
6 | # Requires the curl and netcat commands
7 |
8 | # Optional S/MIME digital signatures require the openssl command
9 | # Optional PGP/MIME digital signatures require the gpg command
10 |
11 | # Run: ./sendmsg.sh