mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-12-23 19:12:16 +03:00
fixes about merging message receiver-sender and new enities
This commit is contained in:
parent
8fabf0d47b
commit
bfeb41c1e1
3 changed files with 21 additions and 36 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
import subprocess
|
||||
from base.Scope import Scope
|
||||
from base.messaging.MessageSender import MessageSender
|
||||
from base.model.Task import Task
|
||||
from base.model.Policy import Policy
|
||||
import hashlib,json,os,stat,shutil
|
||||
|
@ -19,13 +18,14 @@ class ExecutionManager(object):
|
|||
self.config_manager = scope.getConfigurationManager()
|
||||
self.event_manager = scope.getEventManager()
|
||||
self.task_manager = scope.getTaskManager()
|
||||
self.messager = scope.getMessager()
|
||||
self.logger=scope.getLogger()
|
||||
self.db_service=scope.getDbService()
|
||||
|
||||
self.event_manager.register_event('EXECUTE_SCRIPT',self.execute_script)
|
||||
self.event_manager.register_event('REQUEST_FILE',self.request_file)
|
||||
self.event_manager.register_event('MOVE_FILE',self.move_file)
|
||||
self.event_manager.register_event('TASK',self.add_task)
|
||||
self.event_manager.register_event('EXECUTE_TASK',self.execute_task)
|
||||
self.event_manager.register_event('POLICY',self.update_policies)
|
||||
|
||||
def update_policies(self,arg):
|
||||
|
@ -47,8 +47,9 @@ class ExecutionManager(object):
|
|||
self.db_service.update('policy',['version'],[str(policy.ahenk_policy_version)],'type=\'A\'')
|
||||
|
||||
for profile in policy.ahenk_profiles:
|
||||
profile_columns=['id','label','description','is_overridable','is_active','profile_data','modify_date']
|
||||
args=[str(ahenk_policy_id[0][0]),str(profile.label),str(profile.description),str(profile.is_overridable),str(profile.is_active),str(profile.profile_data),str(profile.modify_date)]
|
||||
profile_columns=['id','create_date','modify_date','label','description','overridable','active','deleted','profile_data','plugin']
|
||||
args=[str(ahenk_policy_id[0][0]),str(profile.create_date),str(profile.modify_date),str(profile.label),
|
||||
str(profile.description),str(profile.overridable),str(profile.active),str(profile.deleted),str(profile.profile_data),str(profile.plugin)]
|
||||
self.db_service.update('profile',profile_columns,args)
|
||||
if profile.plugin.name not in installed_plugins and profile.plugin.name not in missing_plugins:
|
||||
missing_plugins.append(profile.plugin.name)
|
||||
|
@ -61,8 +62,9 @@ class ExecutionManager(object):
|
|||
self.db_service.delete('profile','id='+str(user_policy_id[0][0]))
|
||||
self.db_service.update('policy',['version'],[str(policy.user_policy_version)],'type=\'U\' and name=\''+username+'\'')
|
||||
for profile in policy.user_profiles:
|
||||
profile_columns=['id','label','description','is_overridable','is_active','profile_data','modify_date']
|
||||
args=[str(user_policy_id[0][0]),str(profile.label),str(profile.description),str(profile.is_overridable),str(profile.is_active),str(profile.profile_data),str(profile.modify_date)]
|
||||
profile_columns=['id','create_date','modify_date','label','description','overridable','active','deleted','profile_data','plugin']
|
||||
args = [str(user_policy_id[0][0]),str(profile.create_date),str(profile.modify_date),str(profile.label),
|
||||
str(profile.description),str(profile.overridable),str(profile.active),str(profile.deleted),str(profile.profile_data),str(profile.plugin)]
|
||||
self.db_service.update('profile',profile_columns,args)
|
||||
if profile.plugin.name not in installed_plugins and profile.plugin.name not in missing_plugins:
|
||||
missing_plugins.append(profile.plugin.name)
|
||||
|
@ -79,8 +81,7 @@ class ExecutionManager(object):
|
|||
p_list.append(str(p[0])+'-'+str(p[1]))
|
||||
return p_list
|
||||
|
||||
|
||||
def add_task(self,arg):
|
||||
def execute_task(self,arg):
|
||||
self.logger.debug('[ExecutionManager] Adding new task...')
|
||||
task = Task(arg)
|
||||
self.task_manager.addTask(task)
|
||||
|
@ -111,8 +112,7 @@ class ExecutionManager(object):
|
|||
file_path =str(j['filepath']).lower()
|
||||
time_stamp=str(j['timestamp']).lower()
|
||||
self.logger.debug('[ExecutionManager] Requested file is '+file_path)
|
||||
message_sender=MessageSender(None,file_path)
|
||||
message_sender.connect_to_server()
|
||||
self.messager.send_file(file_path)
|
||||
|
||||
def get_md5_file(self,fname):
|
||||
self.logger.debug('[ExecutionManager] md5 hashing')
|
||||
|
|
|
@ -19,32 +19,15 @@ class Messaging(object):
|
|||
|
||||
# TODO can use sh commands or api for getting username and timestamp
|
||||
|
||||
|
||||
def policy_request_msg(self):
|
||||
#TODO volkan
|
||||
|
||||
self.logger.debug('[Messaging] Creating policy request message')
|
||||
|
||||
############# Create policy tables #########################
|
||||
|
||||
columns=['id INTEGER PRIMARY KEY AUTOINCREMENT','type TEXT','version TEXT','name TEXT']
|
||||
self.db_service.check_and_create_table('policy',columns)
|
||||
|
||||
columns=['id INTEGER','label TEXT','description TEXT','is_overridable INTEGER','is_active INTEGER','profile_data BLOB','modify_date TEXT']
|
||||
self.db_service.check_and_create_table('profile',columns)
|
||||
|
||||
columns=['version TEXT','name TEXT','description TEXT']
|
||||
self.db_service.check_and_create_table('plugin',columns)
|
||||
############################################################
|
||||
|
||||
#cols=['type','version','name']
|
||||
#args=['U','1','2559305d-a415-38e7-8498-2dbc458662a7']
|
||||
#self.db_service.update('policy',cols,args,None)
|
||||
|
||||
colz=['version']
|
||||
ahenk_version=self.db_service.select('policy',colz,'type = \'A\'')
|
||||
ahenk_version=self.db_service.select('policy',['version'],'type = \'A\'')
|
||||
username='volkan'
|
||||
user_version=self.db_service.select('policy',colz,'type = \'U\' and name = \''+username+'\'')
|
||||
user_version=self.db_service.select('policy',['version'],'type = \'U\' and name = \''+username+'\'')
|
||||
|
||||
if len(ahenk_version)==0:
|
||||
ahenk_version.append(-1)
|
||||
if len(user_version)==0:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
|
||||
|
||||
from base.Scope import Scope
|
||||
from base.messaging.MessageSender import MessageSender
|
||||
from base.messaging.AnonymousMessager import AnonymousMessager
|
||||
from uuid import getnode as get_mac
|
||||
import json, uuid, netifaces, socket, datetime
|
||||
|
||||
|
@ -17,6 +17,7 @@ class Registration():
|
|||
self.logger=scope.getLogger()
|
||||
self.message_manager=scope.getMessageManager()
|
||||
self.event_manager = scope.getEventManager()
|
||||
self.messager = scope.getMessager()
|
||||
|
||||
self.event_manager.register_event('confirm_registration',self.confirm_registration)
|
||||
|
||||
|
@ -30,13 +31,12 @@ class Registration():
|
|||
|
||||
def registration_request(self):
|
||||
self.logger.debug('[Registration] Requesting registration')
|
||||
message_sender=MessageSender(self.message_manager.registration_msg(),None)
|
||||
message_sender.connect_to_server()
|
||||
anon_messager = AnonymousMessager(self.message_manager.registration_msg(),None)
|
||||
anon_messager.connect_to_server()
|
||||
|
||||
def ldap_registration_request(self):
|
||||
self.logger.debug('[Registration] Requesting LDAP registration')
|
||||
message_sender=MessageSender(self.message_manager.ldap_registration_msg(),None)
|
||||
message_sender.connect_to_server()
|
||||
self.messager.send_Direct_message(self.message_manager.ldap_registration_msg())
|
||||
|
||||
def confirm_registration(self,reg_reply):
|
||||
self.logger.debug('[Registration] Reading registration reply')
|
||||
|
@ -65,6 +65,7 @@ class Registration():
|
|||
self.conf_manager.set('CONNECTION', 'password',self.conf_manager.get('REGISTRATION', 'password'))
|
||||
self.conf_manager.set('REGISTRATION', 'dn',dn)
|
||||
self.conf_manager.set('REGISTRATION', 'registered','true')
|
||||
#TODO get file path?
|
||||
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
|
||||
self.conf_manager.write(configfile)
|
||||
self.logger.debug('[Registration] Registration configuration file is updated')
|
||||
|
@ -98,7 +99,7 @@ class Registration():
|
|||
self.conf_manager.set('REGISTRATION', 'dn','')
|
||||
self.conf_manager.set('REGISTRATION', 'registered','false')
|
||||
|
||||
#TODO self.conf_manager.configurationFilePath attribute error ? READ olacak
|
||||
#TODO get file path?
|
||||
self.logger.debug('[Registration] Parameters were set up, section will write to configuration file')
|
||||
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
|
||||
self.conf_manager.write(configfile)
|
||||
|
@ -108,6 +109,7 @@ class Registration():
|
|||
self.logger.debug('[Registration] Ahenk is unregistering...')
|
||||
if self.conf_manager.has_section('REGISTRATION'):
|
||||
#TODO open this block if you want to be aware about unregistration
|
||||
#TODO messaging thread must be terminated
|
||||
#message_sender=MessageSender(self.message_manager.unregister_msg(),None)
|
||||
#message_sender.connect_to_server()
|
||||
|
||||
|
|
Loading…
Reference in a new issue