-
Notifications
You must be signed in to change notification settings - Fork 0
/
newRegs.py
194 lines (164 loc) · 4.89 KB
/
newRegs.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import os
import time
import sqlite3
import datetime
import requests
import config as cfg
from shutil import copyfile
from verifier import verifier
from discord_webhook import DiscordWebhook, DiscordEmbed
def _debug(msg, obj=''):
if (cfg.DEBUG_MODE):
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
print('[' + now + '] ' + msg, obj)
# Ready the SQLite DB
try:
# If there's no database file, copy from the empty one
if not os.path.isfile('db.sqlite'):
_debug('DB copied from empty')
copyfile('empty.sqlite', 'db.sqlite')
# Connect to SQLite3 DB
_debug('Connecting to DB...')
db = sqlite3.connect('db.sqlite')
_debug('Done')
_debug('Getting cursor...')
cur = db.cursor()
_debug('Done')
except Exception as e:
print("Error while trying to load DB: " + str(e))
exit(1)
headers = {
"Authorization": "Bearer " + cfg.token
}
_debug('Requesting local accounts...')
response = requests.request(
"GET",
cfg.base_url + "/api/v1/admin/accounts",
headers=headers,
params={
"local": "true"
}
)
_debug('Done.')
for u in response.json():
_debug('Parsing user: ', u)
ping_admin = False
r = cur.execute(
'SELECT COUNT(userid) FROM knownRegs WHERE userid=?',
(u['id'],)
).fetchone()
if r[0] != 0:
_debug('User already done')
continue
_debug('New user, making webhook')
# if not u['confirmed']:
# continue
# print(u)
webhook = DiscordWebhook(
url=cfg.whook_reg,
rate_limit_retry=True
)
embed = DiscordEmbed(
title='New registration',
url=cfg.base_url + '/admin/accounts/' + u['id'],
color='03b2f8'
)
if "missing.png" not in u['account']['avatar']:
_debug('They have an avatar!')
embed.set_thumbnail(url=u['account']['avatar'])
try:
ts = datetime.datetime.strptime(
u['created_at'], "%Y-%m-%dT%H:%M:%S.%f%z"
).timestamp()
embed.set_timestamp(timestamp=ts)
_debug('Timestamp added')
except Exception:
# Silently ignore
print('Timestamp fail')
pass
embed.add_embed_field(name='Username', value=u['username'])
embed.add_embed_field(name='Locale', value=u['locale'])
embed.add_embed_field(name='Email', value=u['email'], inline=False)
# Spam check
try:
_debug('Checking spam...')
sr = requests.post(
'http://api.stopforumspam.org/api?json',
data={
'email': u['email'],
'ip': u['ip']
}
)
sc = sr.json()
_debug('Done and JSON got', sc)
sce = 'OK'
if sc['email']['appears'] == 1:
_debug('Email found in spam')
ping_admin = True
sce = 'Freq.: {}, Seen: {}, Confidence: {}'.format(
sc['email']['frequency'],
sc['email']['lastseen'],
sc['email']['confidence']
)
embed.add_embed_field(
name='Email Check',
value=sce,
inline=False
)
sci = 'OK'
if sc['ip']['appears'] == 1:
_debug('IP found in spam')
ping_admin = True
sci = 'Country: {}, Freq.: {}, Seen: {}, Confidence: {}'.format(
sc['ip']['country'],
sc['ip']['frequency'],
sc['ip']['lastseen'],
sc['ip']['confidence']
)
embed.add_embed_field(
name='IP Check',
value=sci,
inline=False
)
_debug('Spam check embed added')
except requests.exceptions.RequestException as e:
print('StopForumSpam request failed. ' + str(e))
except Exception as e:
print('StopForumSpam check failed. ' + str(e))
# Check for Burner Email Providers
try:
if cfg.verifier_key:
_debug('Checking burner')
bi = 'OK'
if not verifier.verify(u['email'], cfg.verifier_key):
_debug('Email is a burner')
ping_admin = True
bi = 'DID NOT PASS'
embed.add_embed_field(
name='Burner Email Check',
value=bi,
inline=False
)
_debug('Burner check embed added')
except Exception as e:
print('Disposable Email Detector check failed. ' + str(e))
webhook.add_embed(embed)
if ping_admin and cfg.discord_uid:
_debug('Will ping admin')
webhook.content = f'<@{cfg.discord_uid}>'
_debug('Sending webhook...')
response = webhook.execute()
_debug('Done', response)
_debug('Inserting to table...')
cur.execute(
'INSERT INTO knownRegs(userid) VALUES (?)',
(u['id'],)
)
_debug('Done')
time.sleep(2)
_debug('Commit DB...')
db.commit()
_debug('Done')
_debug('Closing DB...')
db.close()
_debug('Done')