-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcloudflare.js
More file actions
39 lines (33 loc) · 1.32 KB
/
cloudflare.js
File metadata and controls
39 lines (33 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var os = require("os");
var fs = require("fs");
var touch = require("touch");
var server_load = os.loadavg()[1];
if (server_load > 6) {
if (! fs.existsSync(".cf_under_attack")) {
touch(".cf_under_attack");
CloudFlareOn();
console.log("CloudFlare = ON");
}
} else {
if (fs.existsSync(".cf_under_attack")) {
var file_stats = fs.statSync(".cf_under_attack");
var time_file_create = file_stats["ctime"];
var time_1_hour_ago = new Date() - (3600 * 1000); // JS time is in mulli seconds.
if (time_file_create.getTime() < time_1_hour_ago) {
fs.unlinkSync(".cf_under_attack");
CloudFlareOff();
}
}
}
function CloudFlareOn() {
var exec = require('child_process').exec;
exec("/usr/bin/curl https://www.cloudflare.com/api_json.html -d 'a=sec_lvl' -d 'tkn=CF_API_KEY' -d 'email=you@your-email.com' -d 'z=YOUR-DOMAIN-NAME.COM' -d 'v=help'", function callback(error, stdout, stderr){
console.log(stdout);
});
}
function CloudFlareOff() {
var exec = require('child_process').exec;
exec("/usr/bin/curl https://www.cloudflare.com/api_json.html -d 'a=sec_lvl' -d 'tkn=CF_API_KEY' -d 'email=you@your-email.com' -d 'z=YOUR-DOMAIN-NAME.COM' -d 'v=high'", function callback(error, stdout, stderr){
console.log(stdout);
});
}