From 6496b0e35e16e0454a957d3f23f0650cf4cc22ce Mon Sep 17 00:00:00 2001 From: volkansahin Date: Thu, 6 Jul 2017 11:12:18 +0300 Subject: [PATCH] ip parameter handled --- opt/ahenk/base/command/command_manager.py | 4 +++- opt/ahenk/base/command/command_runner.py | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/opt/ahenk/base/command/command_manager.py b/opt/ahenk/base/command/command_manager.py index 09dfaa3..d8af143 100644 --- a/opt/ahenk/base/command/command_manager.py +++ b/opt/ahenk/base/command/command_manager.py @@ -38,12 +38,14 @@ class Commander(object): self.clean() return False - elif len(params) == 5 and params[1] == 'login': + elif len(params) > 4 and params[1] == 'login': print('{0} logging in'.format(str(params[2]))) data['event'] = params[1] data['username'] = params[2] data['desktop'] = params[3] data['display'] = params[4] + if len(params) == 6: + data['ip'] = params[5] elif len(params) == 3 and params[1] == 'logout': print('{0} logging out'.format(str(params[2]))) diff --git a/opt/ahenk/base/command/command_runner.py b/opt/ahenk/base/command/command_runner.py index a6f2146..a9bf882 100644 --- a/opt/ahenk/base/command/command_runner.py +++ b/opt/ahenk/base/command/command_runner.py @@ -28,6 +28,9 @@ class CommandRunner(object): def check_last_login(self): last_login_tmstmp=self.db_service.select_one_result('session', 'timestamp') + if not last_login_tmstmp: + return True + if (int(time.time())-int(last_login_tmstmp))<10: return False else: @@ -57,6 +60,11 @@ class CommandRunner(object): username = json_data['username'] display = json_data['display'] desktop = json_data['desktop'] + + ip = None + if 'ip' in json_data: + ip = json_data['ip'] + self.logger.info('login event is handled for user: {0}'.format(username)) login_message = self.message_manager.login_msg(username) self.messenger.send_direct_message(login_message) @@ -110,7 +118,7 @@ class CommandRunner(object): username)) session_columns = self.db_service.get_cols('session') self.db_service.update('session', session_columns, - [username, display, desktop, str(int(time.time()))]) + [username, display, desktop, str(int(time.time())),ip]) get_policy_message = self.message_manager.policy_request_msg(username) self.plugin_manager.process_mode('safe', username)