2016-02-16 17:50:37 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2016-03-07 17:59:02 +02:00
|
|
|
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
2016-02-16 17:50:37 +02:00
|
|
|
|
2016-03-07 17:59:02 +02:00
|
|
|
import sys,pwd,os
|
|
|
|
import datetime,json
|
|
|
|
sys.path.append('../..')
|
|
|
|
from base.Scope import Scope
|
2016-02-16 17:50:37 +02:00
|
|
|
|
2016-03-07 17:59:02 +02:00
|
|
|
class Messaging(object):
|
2016-02-16 17:50:37 +02:00
|
|
|
|
2016-02-21 03:24:54 +02:00
|
|
|
def __init__(self):
|
2016-03-08 18:05:42 +02:00
|
|
|
|
2016-03-07 17:59:02 +02:00
|
|
|
scope = Scope().getInstance()
|
|
|
|
self.logger = scope.getLogger()
|
|
|
|
self.configurationManager = scope.getConfigurationManager()
|
|
|
|
self.event_manger=scope.getEventManager()
|
|
|
|
|
2016-03-08 18:05:42 +02:00
|
|
|
#TODO can use sh commands for getting username and timestamp
|
|
|
|
|
2016-03-07 17:59:02 +02:00
|
|
|
def login_msg(self):
|
|
|
|
data = {}
|
2016-03-08 18:05:42 +02:00
|
|
|
data['type'] = 'LOGIN'
|
2016-03-07 17:59:02 +02:00
|
|
|
data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
|
|
|
|
data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
|
|
|
|
json_data = json.dumps(data)
|
|
|
|
return json_data
|
|
|
|
|
|
|
|
def logout_msg(self):
|
|
|
|
data = {}
|
2016-03-08 18:05:42 +02:00
|
|
|
data['type'] = 'LOGOUT'
|
2016-03-07 17:59:02 +02:00
|
|
|
data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
|
|
|
|
data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
|
|
|
|
json_data = json.dumps(data)
|
|
|
|
return json_data
|
|
|
|
|
|
|
|
def get_policies_msg(self):
|
|
|
|
data = {}
|
2016-03-08 18:05:42 +02:00
|
|
|
data['type'] = 'GET_POLICIES'
|
2016-03-07 17:59:02 +02:00
|
|
|
data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
|
|
|
|
data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
|
|
|
|
json_data = json.dumps(data)
|
|
|
|
return json_data
|
|
|
|
|
|
|
|
def unregister_msg(self):
|
|
|
|
data = {}
|
2016-03-08 18:05:42 +02:00
|
|
|
data['type'] = 'UNREGISTER'
|
2016-03-07 17:59:02 +02:00
|
|
|
data['username'] = str(pwd.getpwuid( os.getuid() )[ 0 ])
|
|
|
|
data['timestamp'] = str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
|
|
|
|
json_data = json.dumps(data)
|
|
|
|
return json_data
|