-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck.ls
84 lines (64 loc) · 2.32 KB
/
check.ls
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require! {
\superagent : { get, post }
\./package.json : pack
\prelude-ls : { each, map, concat }
\require-ls
\./notify.ls
\ip-address : ip
\dns-lookup : lookup
\ipaddr.js
\fs : { write-file-sync, readdir-sync, read-file-sync }
}
addresses =
\./addresses |> readdir-sync
|> map (-> read-file-sync("./addresses/#{it}", "utf8").split('\n') )
|> concat
init-users = {}
check-address = (user, address)-->
notify("Address #{address} is not found for `#{user.email}`") if addresses.index-of(address) is -1
check-addresses = (user)->
user.addresses |> Object.keys |> check-address user
check-user = (user)->
init-users[user._id] = init-users[user._id] ? user
oldaddr = init-users[user._id].address
newaddr = user.address
notify("ETH Address is changed for `#{user.email}` #{oldaddr} => #{newaddr}") if oldaddr isnt newaddr and oldaddr?length > 0
check-addresses user
check-users = (cb)->
{ password } = pack.config
err, data <-! post "#{pack.config.host}/admin/users" .send({ password }).end
data.text |> JSON.parse
|> each check-user
cb!
check-ip = (cb)->
err, address, family <-! lookup pack.config.host
#return notify('Cannot get ip address') if err?
#return notify('IP is not match') if not address is pack.config.checkip
cb!
hashes = {}
#pack.config.host = \https://ico.covesting.io
check-page = (name, cb)->
page = "#{pack.config.host}/#{name}/index.html"
err, data <-! get page .end
#console.log data.text.match(/\"\/cdn-cgi\/l\/email-protection#[^"]+\"/)?0?length
text = data.text.replace(/\"\/cdn-cgi\/l\/email-protection#[^"]+\"/, "")
if hashes[name]? and text isnt hashes[name]
#console.log name, page, hashes[name]
write-file-sync("./diff/#{name}-before.html", hashes[name])
write-file-sync("./diff/#{name}-after.html", text)
notify "Page `#{page}` was changed"
hashes[name] = text
cb!
check-pages = ([page, ...pages], cb)->
return cb! if not page?
<-! check-page page
<-! check-pages pages
cb!
pages = <[ members login profile reset-password confirm-email reset restore settings ]>
check-all = ->
console.log \check-all
<-! check-users
<-! check-ip
<-! check-pages pages
set-timeout check-all, 10000
check-all!