-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautobot.py
66 lines (57 loc) · 1.58 KB
/
autobot.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
import subprocess
import os
# Config
database = "koyuspace"
instance = "koyu.space"
token = os.getenv("TOKEN")
# Read wordlist
f = open("wordlist.txt", "r")
s = f.readlines()
f.close()
# Parse wordlist
wordlist = []
for l in s:
if not l.startswith("#"):
if not l == "":
if not l == "\n":
wordlist.append(l.replace("\n", ""))
# Read exceptions
f = open("exceptions.txt", "r")
e = f.readlines()
f.close()
# Parse exceptions
exceptions = []
for l in e:
if not l.startswith("#"):
if not l == "":
if not l == "\n":
exceptions.append(l.replace("\n", ""))
# Don't report twice
os.system("touch done.txt")
f = open("done.txt", "r")
done = f.readlines()
f.close()
f = open("done.txt", "a+")
# Do the actual work
for item in wordlist:
reason = item.split("$$$")[0]
word = item.split("$$$")[1]
result = subprocess.run("cd /tmp && sudo -u postgres -H -- psql -d "+database+" -c \"select id from accounts where domain is null and note ~ '"+word+"'\"", stdout=subprocess.PIPE, shell=True)
data = result.stdout.decode('utf-8').split("-\n")[1].split("(")[0].replace(" ", "").split("\n")
temp = []
for entry in data:
if not entry == "":
temp.append(entry)
data = temp
for id in data:
exception = False
for ex in exceptions:
if ex == id:
exception = True
for d in done:
if d == id:
exception = True
if not exception:
os.system("curl -X POST -H \"Authorization: Bearer "+token+"\" https://"+instance+"/api/v1/reports -d \"account_id="+id+"&comment="+reason+" (auto-report)\"")
f.write(id+"\n")
f.close()