mirror of
https://github.com/Kkevsterrr/geneva
synced 2025-01-17 22:40:28 +01:00
add bones of demo mode
This commit is contained in:
parent
f01a0c1f93
commit
216e5636c4
@ -8,6 +8,10 @@ import string
|
|||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
import re
|
||||||
|
import socket
|
||||||
|
import random
|
||||||
|
import struct
|
||||||
|
|
||||||
import actions.action
|
import actions.action
|
||||||
import actions.trigger
|
import actions.trigger
|
||||||
@ -85,7 +89,7 @@ def parse(requested_trees, logger):
|
|||||||
return strat
|
return strat
|
||||||
|
|
||||||
|
|
||||||
def get_logger(basepath, log_dir, logger_name, log_name, environment_id, log_level=logging.DEBUG):
|
def get_logger(basepath, log_dir, logger_name, log_name, environment_id, log_level=logging.DEBUG, demo_mode=False):
|
||||||
"""
|
"""
|
||||||
Configures and returns a logger.
|
Configures and returns a logger.
|
||||||
"""
|
"""
|
||||||
@ -121,8 +125,28 @@ def get_logger(basepath, log_dir, logger_name, log_name, environment_id, log_lev
|
|||||||
ch.setLevel(log_level)
|
ch.setLevel(log_level)
|
||||||
CONSOLE_LOG_LEVEL = ch.level
|
CONSOLE_LOG_LEVEL = ch.level
|
||||||
logger.addHandler(ch)
|
logger.addHandler(ch)
|
||||||
return logger
|
return CustomAdapter(logger, {}) if demo_mode else logger
|
||||||
|
|
||||||
|
class CustomAdapter(logging.LoggerAdapter):
|
||||||
|
"""
|
||||||
|
Used for demo mode, to change sensitive IP addresses where necessary
|
||||||
|
"""
|
||||||
|
regex = re.compile(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
|
||||||
|
|
||||||
|
def __init__(self, logger, extras):
|
||||||
|
super().__init__(logger, extras)
|
||||||
|
self.ips = {}
|
||||||
|
|
||||||
|
def process(self, msg, kwargs):
|
||||||
|
for ip in self.regex.findall(msg):
|
||||||
|
if ip not in self.ips:
|
||||||
|
random_ip = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
|
||||||
|
self.logger.debug("Registering new random IP: %s" % random_ip)
|
||||||
|
self.ips[ip] = random_ip
|
||||||
|
|
||||||
|
msg = msg.replace(ip, self.ips[ip])
|
||||||
|
|
||||||
|
return msg, kwargs
|
||||||
|
|
||||||
def close_logger(logger):
|
def close_logger(logger):
|
||||||
"""
|
"""
|
||||||
|
@ -193,7 +193,7 @@ class Engine():
|
|||||||
while (not self.in_nfqueue_started or not self.out_nfqueue_started) and i < maxwait:
|
while (not self.in_nfqueue_started or not self.out_nfqueue_started) and i < maxwait:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
i += 1
|
i += 1
|
||||||
self.logger.debug("NFQueue Initialized after %d", int(i))
|
self.logger.debug(("NFQueue Initialized after %d", int(i)))
|
||||||
|
|
||||||
def shutdown_nfqueue(self):
|
def shutdown_nfqueue(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user