This repository has been archived by the owner on Jul 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathdb_up.py
87 lines (76 loc) · 1.5 KB
/
db_up.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
#!/usr/bin/env python
import MySQLdb
import sys
# DB CONFIG GOES HERE
host = 'localhost'
user = 'root'
passwd= ''
db = MySQLdb.connect(host=host,
user=user,
passwd=passwd,
db='securitybot')
cur = db.cursor()
# Start fresh
print 'Removing all tables'
cur.execute('SHOW TABLES')
tables = cur.fetchall()
for table in tables:
table = table[0]
print 'Dropping {0}'.format(table)
cur.execute('DROP TABLE {0}'.format(MySQLdb.escape_string(table)))
# Create tables
print 'Creating tables...'
cur.execute(
'''
CREATE TABLE blacklist (
ldap VARCHAR(255) NOT NULL,
PRIMARY KEY ( ldap )
)
'''
)
cur.execute(
'''
CREATE TABLE ignored (
ldap VARCHAR(255) NOT NULL,
title VARCHAR(255) NOT NULL,
reason VARCHAR(255) NOT NULL,
until DATETIME NOT NULL,
CONSTRAINT ignored_ID PRIMARY KEY ( ldap, title )
)
'''
)
cur.execute(
'''
CREATE TABLE alerts (
hash BINARY(32) NOT NULL,
ldap VARCHAR(255) NOT NULL,
title VARCHAR(255) NOT NULL,
description VARCHAR(255) NOT NULL,
reason TEXT NOT NULL,
url VARCHAR(511) NOT NULL,
event_time DATETIME NOT NULL,
PRIMARY KEY ( hash )
)
'''
)
cur.execute(
'''
CREATE TABLE alert_status (
hash BINARY(32) NOT NULL,
status TINYINT UNSIGNED NOT NULL,
PRIMARY KEY ( hash )
)
'''
)
cur.execute(
'''
CREATE TABLE user_responses(
hash BINARY(32) NOT NULL,
comment TEXT,
performed BOOL,
authenticated BOOL,
PRIMARY KEY ( hash )
)
'''
)
print 'Done!'