mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-26 07:02:22 +03:00
parameters are fixed according to lider
This commit is contained in:
parent
8b62344e48
commit
3752a968ac
1 changed files with 17 additions and 29 deletions
|
@ -7,16 +7,9 @@ from base.logger.AhenkLogger import Logger
|
||||||
from base.Scope import Scope
|
from base.Scope import Scope
|
||||||
from base.messaging.MessageSender import MessageSender
|
from base.messaging.MessageSender import MessageSender
|
||||||
from uuid import getnode as get_mac
|
from uuid import getnode as get_mac
|
||||||
import json
|
import sys,logging,json,uuid
|
||||||
import uuid
|
import datetime,time,configparser
|
||||||
import sys,logging
|
import netifaces,socket,re
|
||||||
import datetime
|
|
||||||
import time
|
|
||||||
import netifaces
|
|
||||||
import re
|
|
||||||
import socket
|
|
||||||
import configparser
|
|
||||||
|
|
||||||
|
|
||||||
class Registration():
|
class Registration():
|
||||||
|
|
||||||
|
@ -31,8 +24,6 @@ class Registration():
|
||||||
|
|
||||||
self.event_manager.register_event('confirm_registration',self.confirm_registration)
|
self.event_manager.register_event('confirm_registration',self.confirm_registration)
|
||||||
|
|
||||||
#self.registration_reply=""
|
|
||||||
|
|
||||||
if self.conf_manager.has_section('REGISTRATION'):
|
if self.conf_manager.has_section('REGISTRATION'):
|
||||||
if self.conf_manager.get('REGISTRATION', 'registered')=='false':
|
if self.conf_manager.get('REGISTRATION', 'registered')=='false':
|
||||||
self.re_register()
|
self.re_register()
|
||||||
|
@ -40,7 +31,6 @@ class Registration():
|
||||||
self.logger.debug('[Registration] already registered')
|
self.logger.debug('[Registration] already registered')
|
||||||
else:
|
else:
|
||||||
self.register(True)
|
self.register(True)
|
||||||
#self.registration_reply=""
|
|
||||||
self.logger.debug('[Registration] ')
|
self.logger.debug('[Registration] ')
|
||||||
|
|
||||||
def registration_request(self):
|
def registration_request(self):
|
||||||
|
@ -48,13 +38,12 @@ class Registration():
|
||||||
message_sender.connect_to_server()
|
message_sender.connect_to_server()
|
||||||
|
|
||||||
def confirm_registration(self,reg_reply): #event fire and keep here
|
def confirm_registration(self,reg_reply): #event fire and keep here
|
||||||
|
|
||||||
j = json.loads(reg_reply)
|
j = json.loads(reg_reply)
|
||||||
self.logger.info('[REGISTRATION] register reply: '+j['message'])
|
self.logger.info('[REGISTRATION] register reply: '+j['message'])
|
||||||
status =j['status']
|
status =str(j['status']).lower()
|
||||||
dn=j['dn']
|
dn=str(j['agentDn']).lower()
|
||||||
|
|
||||||
if(str(status).lower()=='registered'):
|
if str(status)=='registered':
|
||||||
print("registered")
|
print("registered")
|
||||||
if self.conf_manager.has_section('CONNECTION') and self.conf_manager.get('REGISTRATION', 'from') is not None:
|
if self.conf_manager.has_section('CONNECTION') and self.conf_manager.get('REGISTRATION', 'from') is not None:
|
||||||
self.conf_manager.set('CONNECTION', 'uid',self.conf_manager.get('REGISTRATION', 'from'))
|
self.conf_manager.set('CONNECTION', 'uid',self.conf_manager.get('REGISTRATION', 'from'))
|
||||||
|
@ -63,7 +52,7 @@ class Registration():
|
||||||
self.conf_manager.set('REGISTRATION', 'registered','true')
|
self.conf_manager.set('REGISTRATION', 'registered','true')
|
||||||
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
|
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
|
||||||
self.conf_manager.write(configfile)
|
self.conf_manager.write(configfile)
|
||||||
|
self.event_manager.register_event('registration_ok',self.reload)
|
||||||
self.logger.info('[REGISTRATION] registered successfully')
|
self.logger.info('[REGISTRATION] registered successfully')
|
||||||
elif(status=='registration_error'):
|
elif(status=='registration_error'):
|
||||||
self.logger.info('[REGISTRATION] registration error')
|
self.logger.info('[REGISTRATION] registration error')
|
||||||
|
@ -83,21 +72,20 @@ class Registration():
|
||||||
|
|
||||||
if self.conf_manager.has_section('REGISTRATION'):
|
if self.conf_manager.has_section('REGISTRATION'):
|
||||||
data = {}
|
data = {}
|
||||||
data['message_type'] = 'registration'
|
data['type'] = 'REGISTER'
|
||||||
data['from'] = str(self.conf_manager.get('REGISTRATION','from'))
|
data['from'] = str(self.conf_manager.get('REGISTRATION','from'))
|
||||||
data['password'] = str(self.conf_manager.get('REGISTRATION','password'))
|
data['password'] = str(self.conf_manager.get('REGISTRATION','password'))
|
||||||
data['mac_address'] = str(self.conf_manager.get('REGISTRATION','mac_address'))
|
data['macAddresses'] = str(self.conf_manager.get('REGISTRATION','macAddresses'))
|
||||||
data['ip_address'] = str(self.conf_manager.get('REGISTRATION','ip_address'))
|
data['ipAddresses'] = str(self.conf_manager.get('REGISTRATION','ipAddresses'))
|
||||||
data['hostname'] = str(self.conf_manager.get('REGISTRATION','hostname'))
|
data['hostname'] = str(self.conf_manager.get('REGISTRATION','hostname'))
|
||||||
data['timestamp'] = str(self.conf_manager.get('REGISTRATION','timestamp'))
|
data['timestamp'] = str(self.conf_manager.get('REGISTRATION','timestamp'))
|
||||||
data['dn'] = str(self.conf_manager.get('REGISTRATION','dn'))
|
|
||||||
self.logger.debug('[Registration] json of registration message was created')
|
self.logger.debug('[Registration] json of registration message was created')
|
||||||
|
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
self.logger.debug('[Registration] json converted to str')
|
self.logger.debug('[Registration] json converted to str')
|
||||||
return json_data
|
return json_data
|
||||||
else:
|
else:
|
||||||
print("reg sec yok :(")
|
print("Registration section not found")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def register(self,uuid_depend_mac):
|
def register(self,uuid_depend_mac):
|
||||||
|
@ -109,8 +97,8 @@ class Registration():
|
||||||
|
|
||||||
self.conf_manager.add_section('REGISTRATION')
|
self.conf_manager.add_section('REGISTRATION')
|
||||||
self.conf_manager.set('REGISTRATION', 'from',str(self.generate_uuid(uuid_depend_mac)))
|
self.conf_manager.set('REGISTRATION', 'from',str(self.generate_uuid(uuid_depend_mac)))
|
||||||
self.conf_manager.set('REGISTRATION', 'mac_address',str(':'.join(("%012X" % get_mac())[i:i+2] for i in range(0, 12, 2))))
|
self.conf_manager.set('REGISTRATION', 'macAddresses',str(':'.join(("%012X" % get_mac())[i:i+2] for i in range(0, 12, 2))))
|
||||||
self.conf_manager.set('REGISTRATION', 'ip_address',str(self.get_ip_addresses()))
|
self.conf_manager.set('REGISTRATION', 'ipAddresses',str(self.get_ipAddresses()))
|
||||||
self.conf_manager.set('REGISTRATION', 'hostname',str(socket.gethostname()))
|
self.conf_manager.set('REGISTRATION', 'hostname',str(socket.gethostname()))
|
||||||
self.conf_manager.set('REGISTRATION', 'timestamp',str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M")))
|
self.conf_manager.set('REGISTRATION', 'timestamp',str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M")))
|
||||||
self.conf_manager.set('REGISTRATION', 'password',str(self.generate_password()))
|
self.conf_manager.set('REGISTRATION', 'password',str(self.generate_password()))
|
||||||
|
@ -125,9 +113,9 @@ class Registration():
|
||||||
|
|
||||||
def unregister(self):
|
def unregister(self):
|
||||||
if self.conf_manager.has_section('REGISTRATION'):
|
if self.conf_manager.has_section('REGISTRATION'):
|
||||||
|
#TODO open this block if you want to be aware about unregistration
|
||||||
message_sender=MessageSender(self.message_manager.unregister_msg(),None)
|
#message_sender=MessageSender(self.message_manager.unregister_msg(),None)
|
||||||
message_sender.connect_to_server()
|
#message_sender.connect_to_server()
|
||||||
|
|
||||||
self.conf_manager.remove_section('REGISTRATION')
|
self.conf_manager.remove_section('REGISTRATION')
|
||||||
self.conf_manager.set('CONNECTION', 'uid','')
|
self.conf_manager.set('CONNECTION', 'uid','')
|
||||||
|
@ -152,7 +140,7 @@ class Registration():
|
||||||
def generate_password(self):
|
def generate_password(self):
|
||||||
return uuid.uuid4()
|
return uuid.uuid4()
|
||||||
|
|
||||||
def get_ip_addresses(self):
|
def get_ipAddresses(self):
|
||||||
self.logger.debug('[Registration] looking for network interces')
|
self.logger.debug('[Registration] looking for network interces')
|
||||||
ip_address=""
|
ip_address=""
|
||||||
for interface in netifaces.interfaces():
|
for interface in netifaces.interfaces():
|
||||||
|
|
Loading…
Reference in a new issue