Skip to content
Snippets Groups Projects
Commit 1cae99b5 authored by Pavel Kácha's avatar Pavel Kácha
Browse files

Now auth/auth actually works. Now uses services on many places, where clients...

Now auth/auth actually works. Now uses services on many places, where clients was used (and didn't work)
parent 3cf59a6b
Branches
Tags
No related merge requests found
...@@ -119,7 +119,8 @@ INSERT INTO `clients` (`id`, `hostname`, `registered`, `requestor`, `note`, `val ...@@ -119,7 +119,8 @@ INSERT INTO `clients` (`id`, `hostname`, `registered`, `requestor`, `note`, `val
(23, 'nfsen.ics.muni.cz', '0000-00-00 00:00:00', '', '', 1, 1, 0), (23, 'nfsen.ics.muni.cz', '0000-00-00 00:00:00', '', '', 1, 1, 0),
(25, 'vinovago.cesnet.cz', '0000-00-00 00:00:00', '', '', 1, 1, 0), (25, 'vinovago.cesnet.cz', '0000-00-00 00:00:00', '', '', 1, 1, 0),
(26, 'ward.tul.cz', '0000-00-00 00:00:00', '', '', 1, 1, 0), (26, 'ward.tul.cz', '0000-00-00 00:00:00', '', '', 1, 1, 0),
(28, 'kostik.zcu.cz', '0000-00-00 00:00:00', 'kostenec@civ.zcu.cz', '', 1, 1, 1); (28, 'kostik.zcu.cz', '0000-00-00 00:00:00', 'kostenec@civ.zcu.cz', '', 1, 1, 1),
(29, 'grey.cesnet.cz', '2014-12-11 13:51:14', 'ph@cesnet.cz', '', 1, 1, 1);
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -132,7 +133,7 @@ CREATE TABLE IF NOT EXISTS `events` ( ...@@ -132,7 +133,7 @@ CREATE TABLE IF NOT EXISTS `events` (
`detected_epoch` int(11) NOT NULL, `detected_epoch` int(11) NOT NULL,
`received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`detected` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `detected` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`client_id` int(11) NOT NULL, `service_id` int(11) NOT NULL,
`data` text NOT NULL, `data` text NOT NULL,
`valid` tinyint(1) NOT NULL DEFAULT '1', `valid` tinyint(1) NOT NULL DEFAULT '1',
`origin` varchar(64) NOT NULL, `origin` varchar(64) NOT NULL,
...@@ -140,7 +141,7 @@ CREATE TABLE IF NOT EXISTS `events` ( ...@@ -140,7 +141,7 @@ CREATE TABLE IF NOT EXISTS `events` (
`origin_long` varchar(64) NOT NULL, `origin_long` varchar(64) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `detected` (`detected`), KEY `detected` (`detected`),
KEY `id` (`id`,`client_id`) KEY `id` (`id`,`service_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -175,11 +176,11 @@ CREATE TABLE IF NOT EXISTS `event_tag_mapping` ( ...@@ -175,11 +176,11 @@ CREATE TABLE IF NOT EXISTS `event_tag_mapping` (
CREATE TABLE IF NOT EXISTS `last_events` ( CREATE TABLE IF NOT EXISTS `last_events` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`client_id` int(11) NOT NULL, `service_id` int(11) NOT NULL,
`event_id` int(11) NOT NULL, `event_id` int(11) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `client_id` (`client_id`,`event_id`) KEY `service_id` (`service_id`,`event_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- -------------------------------------------------------- -- --------------------------------------------------------
...@@ -226,7 +227,7 @@ INSERT INTO `services` (`service_id`, `client_id`, `registered`, `requestor`, `s ...@@ -226,7 +227,7 @@ INSERT INTO `services` (`service_id`, `client_id`, `registered`, `requestor`, `s
(17, 17, '0000-00-00 00:00:00', '', 'synscandetector_1_0', '', 1, 'org.liberouter.collector.synscandetector_1_0', 1, 0), (17, 17, '0000-00-00 00:00:00', '', 'synscandetector_1_0', '', 1, 'org.liberouter.collector.synscandetector_1_0', 1, 0),
(18, 18, '0000-00-00 00:00:00', '', 'kippohoneypot', '', 1, 'cz.cesnet.holly.kippohoneypot', 1, 0), (18, 18, '0000-00-00 00:00:00', '', 'kippohoneypot', '', 1, 'cz.cesnet.holly.kippohoneypot', 1, 0),
(19, 19, '0000-00-00 00:00:00', '', 'dionaeahoneypot', '', 1, 'cz.cesnet.kryten.dionaeahoneypot', 1, 0), (19, 19, '0000-00-00 00:00:00', '', 'dionaeahoneypot', '', 1, 'cz.cesnet.kryten.dionaeahoneypot', 1, 0),
(20, 29, '0000-00-00 00:00:00', '', 'mentat', '', 1, 'cz.cesnet.mentat.mentat', 1, 0), (20, 20, '0000-00-00 00:00:00', '', 'mentat', '', 1, 'cz.cesnet.mentat.mentat', 1, 0),
(21, 21, '0000-00-00 00:00:00', '', 'kippo', '', 1, 'cz.slu.opf.miel.kippo', 1, 0), (21, 21, '0000-00-00 00:00:00', '', 'kippo', '', 1, 'cz.slu.opf.miel.kippo', 1, 0),
(22, 23, '0000-00-00 00:00:00', '', 'honeyscan', '', 1, 'cz.muni.ics.nfsen.honeyscan', 1, 0), (22, 23, '0000-00-00 00:00:00', '', 'honeyscan', '', 1, 'cz.muni.ics.nfsen.honeyscan', 1, 0),
(23, 23, '0000-00-00 00:00:00', '', 'scandetector_1_0', '', 1, 'cz.muni.ics.nfsen.scandetector_1_0', 1, 0), (23, 23, '0000-00-00 00:00:00', '', 'scandetector_1_0', '', 1, 'cz.muni.ics.nfsen.scandetector_1_0', 1, 0),
...@@ -236,7 +237,8 @@ INSERT INTO `services` (`service_id`, `client_id`, `registered`, `requestor`, `s ...@@ -236,7 +237,8 @@ INSERT INTO `services` (`service_id`, `client_id`, `registered`, `requestor`, `s
(27, 26, '0000-00-00 00:00:00', '', 'kippo', '', 1, 'cz.tul.ward.kippo', 1, 0), (27, 26, '0000-00-00 00:00:00', '', 'kippo', '', 1, 'cz.tul.ward.kippo', 1, 0),
(28, 28, '0000-00-00 00:00:00', 'kostenec@civ.zcu.cz', 'com.example.test-node', '', 1, 'com.example.test-node', 0, 0), (28, 28, '0000-00-00 00:00:00', 'kostenec@civ.zcu.cz', 'com.example.test-node', '', 1, 'com.example.test-node', 0, 0),
(29, 28, '0000-00-00 00:00:00', 'kostenec@civ.zcu.cz', 'com.example.test-node2', '', 1, 'com.example.test-node2', 0, 0), (29, 28, '0000-00-00 00:00:00', 'kostenec@civ.zcu.cz', 'com.example.test-node2', '', 1, 'com.example.test-node2', 0, 0),
(30, 28, '0000-00-00 00:00:00', 'kostenec@civ.zcu.cz', 'Test', '', 1, 'com.example.test-node3', 0, 0); (30, 28, '0000-00-00 00:00:00', 'kostenec@civ.zcu.cz', 'Test', '', 1, 'com.example.test-node3', 0, 0),
(31, 29, '2014-12-11 13:51:18', 'ph@cesnet.cz', 'Test', '', 1, 'cz.cesnet.grey.test', 1, 0);
-- -------------------------------------------------------- -- --------------------------------------------------------
......
...@@ -193,16 +193,20 @@ class X509Authenticator(NoAuthenticator): ...@@ -193,16 +193,20 @@ class X509Authenticator(NoAuthenticator):
def authorize(self, env, client, method, event, args): def authorize(self, env, client, method, event, args):
logging.debug("authorize: Client: " + str(client))
# Authorize for debug # Authorize for debug
if (method == 'getDebug'): if (method == 'getDebug'):
return client if client[0]['debug'] == 1 else None return client if client[0]['debug'] == 1 else None
cl = None cl = None
service = event['Node'][0]['Name'] identity = event['Node'][0]['Name']
test = 'Test' in event['Category'] test = 'Test' in event['Category']
logging.debug("Event identity: " + identity)
for clx in client: for clx in client:
if clx['service'] == service: if clx['identity'] == identity:
cl = clx cl = clx
break break
...@@ -277,6 +281,7 @@ class MySQL(Object): ...@@ -277,6 +281,7 @@ class MySQL(Object):
format_strings = ','.join(['%s'] * len(name)) format_strings = ','.join(['%s'] * len(name))
self.crs.execute("SELECT cl.`id`, cl.`hostname`, s.`service`, s.`service_id`, s.`identity`, cl.`read`, s.`write`, s.`test`, cl.`debug` FROM `clients` cl LEFT JOIN `services` s ON cl.`id` = s.`client_id` WHERE cl.`valid` = 1 AND s.`valid` = 1 AND `hostname` IN (%s)" % format_strings, tuple(name)) self.crs.execute("SELECT cl.`id`, cl.`hostname`, s.`service`, s.`service_id`, s.`identity`, cl.`read`, s.`write`, s.`test`, cl.`debug` FROM `clients` cl LEFT JOIN `services` s ON cl.`id` = s.`client_id` WHERE cl.`valid` = 1 AND s.`valid` = 1 AND `hostname` IN (%s)" % format_strings, tuple(name))
row = self.crs.fetchall() row = self.crs.fetchall()
logging.debug("Client/service info: " + str(row))
return row if row else None return row if row else None
...@@ -359,10 +364,10 @@ class MySQL(Object): ...@@ -359,10 +364,10 @@ class MySQL(Object):
if group is not None: if group is not None:
for identity in json.loads(group): for identity in json.loads(group):
sqltemp['group'] += ("cl.identity LIKE '%s' AND " % (identity)) sqltemp['group'] += ("s.identity LIKE '%s' AND " % (identity))
if nogroup is not None: if nogroup is not None:
for identity in json.loads(nogroup): for identity in json.loads(nogroup):
sqltemp['group'] += ("cl.identity NOT LIKE '%s' AND " % (identity)) sqltemp['group'] += ("s.identity NOT LIKE '%s' AND " % (identity))
# logging.debug(sqltemp['group'][:-4]) # logging.debug(sqltemp['group'][:-4])
sqlwhere.append(sqltemp['group'][:-4]) sqlwhere.append(sqltemp['group'][:-4])
...@@ -374,8 +379,8 @@ class MySQL(Object): ...@@ -374,8 +379,8 @@ class MySQL(Object):
#sqlwhere = sqlwhere[:-4] #sqlwhere = sqlwhere[:-4]
and_op = "" if not sqlwhere_string else "AND" and_op = "" if not sqlwhere_string else "AND"
# logging.debug("SELECT e.id, e.data FROM clients cl RIGHT JOIN events e ON cl.id = e.client_id WHERE e.id > %s AND %s %s e.valid = 1 LIMIT %s" % (str(id), sqlwhere_string, and_op, str(count))) logging.debug("SELECT e.id, e.data FROM services s RIGHT JOIN events e ON s.id = e.service_id WHERE e.id > %s AND %s %s e.valid = 1 LIMIT %s" % (str(id or 0), sqlwhere_string, and_op, str(count)))
self.crs.execute("SELECT e.id, e.data FROM clients cl RIGHT JOIN events e ON cl.id = e.client_id WHERE e.id > %s AND %s %s e.valid = 1 LIMIT %s" % (str(id), sqlwhere_string, and_op, str(count))) self.crs.execute("SELECT e.id, e.data FROM services s RIGHT JOIN events e ON s.service_id = e.service_id WHERE e.id > %s AND %s %s e.valid = 1 LIMIT %s" % (str(id or 0), sqlwhere_string, and_op, str(count)))
row = self.crs.fetchall() row = self.crs.fetchall()
if row: if row:
...@@ -397,8 +402,8 @@ class MySQL(Object): ...@@ -397,8 +402,8 @@ class MySQL(Object):
for event in events: for event in events:
try: try:
# logging.debug("INSERT INTO events (detected,received,client_id,data) VALUES ('%s', NOW(), '%s', '%s')" % (event['DetectTime'], client['id'], self.con.escape_string(str(event)))) # logging.debug("INSERT INTO events (detected,received,service_id,data) VALUES ('%s', NOW(), '%s', '%s')" % (event['DetectTime'], client['id'], self.con.escape_string(str(event))))
self.crs.execute("INSERT INTO events (detected,received,client_id,data) VALUES ('%s', NOW(), '%s', '%s')" % (event['DetectTime'], client['id'], self.con.escape_string(str(event)))) self.crs.execute("INSERT INTO events (detected,received,service_id,data) VALUES ('%s', NOW(), '%s', '%s')" % (event['DetectTime'], client['service_id'], self.con.escape_string(str(event))))
lastid = self.crs.lastrowid lastid = self.crs.lastrowid
# logging.debug(str(lastid)) # logging.debug(str(lastid))
for cat in event['Category']: for cat in event['Category']:
...@@ -415,16 +420,15 @@ class MySQL(Object): ...@@ -415,16 +420,15 @@ class MySQL(Object):
self.crs.execute("INSERT INTO event_tag_mapping (event_id,tag_id) VALUES ('%s', '%s')" % (str(lastid), str(tag_id))) self.crs.execute("INSERT INTO event_tag_mapping (event_id,tag_id) VALUES ('%s', '%s')" % (str(lastid), str(tag_id)))
self.con.commit() self.con.commit()
except: except Exception as e:
self.con.rollback() self.con.rollback()
raise Error("Data storing error", 00, detail={'event': event}) errs.append({"event": event, "error": str(e)})
errs.append({"event": event})
return errs return errs
def insertLastReceivedId(self, client, id): def insertLastReceivedId(self, client, id):
logging.debug("INSERT INTO last_events(client_id, event_id, timestamp) VALUES(%s, %s, NOW())" % (str(client[0]['id']), id)) logging.debug("INSERT INTO last_events(service_id, event_id, timestamp) VALUES(%s, %s, NOW())" % (str(client[0]['service_id']), id))
self.crs.execute("INSERT INTO last_events(client_id, event_id, timestamp) VALUES(%s, %s, NOW())" % (str(client[0]['id']), id)) self.crs.execute("INSERT INTO last_events(service_id, event_id, timestamp) VALUES(%s, %s, NOW())" % (str(client[0]['service_id']), id))
def getLastEventId(self): def getLastEventId(self):
self.crs.execute("SELECT MAX(id) as id FROM events") self.crs.execute("SELECT MAX(id) as id FROM events")
...@@ -434,11 +438,11 @@ class MySQL(Object): ...@@ -434,11 +438,11 @@ class MySQL(Object):
def getLastReceivedId(self, client): def getLastReceivedId(self, client):
logging.debug("IN getLastReceivedId") logging.debug("IN getLastReceivedId")
client_id = client[0]['id'] service_id = client[0]['service_id']
logging.debug("getLastReceivedId (client_id) = %s", str(client_id)) logging.debug("getLastReceivedId (service_id) = %s", str(service_id))
logging.debug("SELECT MAX(event_id) as id FROM last_events WHERE client_id = %s" % (str(client_id))) logging.debug("SELECT MAX(event_id) as id FROM last_events WHERE service_id = %s" % (str(service_id)))
self.crs.execute("SELECT MAX(event_id) as id FROM last_events WHERE client_id = %s" % (str(client_id))) self.crs.execute("SELECT MAX(event_id) as id FROM last_events WHERE service_id = %s" % (str(service_id)))
row = self.crs.fetchone() row = self.crs.fetchone()
logging.debug("getLastReceivedId - %s" % str(row['id'])) logging.debug("getLastReceivedId - %s" % str(row['id']))
...@@ -748,9 +752,9 @@ class WardenHandler(Object): ...@@ -748,9 +752,9 @@ class WardenHandler(Object):
count = min(count, self.get_events_limit) count = min(count, self.get_events_limit)
logging.debug("getEvents - count: %s" % count) logging.debug("getEvents - count: %s" % count)
res = self.db.fetch_events(_client, id, count, cat, nocat, tag, notag, group, nogroup) res = self.db.fetch_events(_client, id or 0, count, cat, nocat, tag, notag, group, nogroup)
logging.info("getEvents(%d, %d, %s, %s, %s, %s, %s, %s): sending %d events" % ( logging.info("getEvents(%d, %d, %s, %s, %s, %s, %s, %s): sending %d events" % (
id, count, cat, nocat, tag, notag, group, nogroup, len(res["events"]))) id or 0, count, cat, nocat, tag, notag, group, nogroup, len(res["events"])))
self.db.insertLastReceivedId(_client, res['lastid']) self.db.insertLastReceivedId(_client, res['lastid'])
logging.debug("lastid inserting: %s" % {'lastid': res['lastid'], 'client' : _client}) logging.debug("lastid inserting: %s" % {'lastid': res['lastid'], 'client' : _client})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment