Exemplo n.º 1
0
def load_page(form):
    logging_settings = load_configuration('logging_client')

    log = logging_settings['logging']

    # correcting time for configured offset.
    time_offset = logging_settings['time_offset']
    system_time = System.format_date_time(fast_time())
    local_time = System.calculate_time_offset(fast_time())
    local_time = System.format_date_time(local_time)

    logging_settings = {
        'system': system_time,
        'local': local_time,
        'offset': {
            'direction': time_offset['direction'],
            'amount': time_offset['amount']
        },
        'logging': {
            'log_levels': [level.title() for level in LOG_LEVELS],
            'level': log['level'],
            'length': log['length']
        }
    }

    return logging_settings
Exemplo n.º 2
0
    def ips_passively_blocked(*, table='raw', block_length=NO_DELAY):
        '''
        return list of currently blocked hosts in the specific iptables table. default table is 'raw'.

        if block_length is defined, only hosts that have reached point of expiration will be returned.
        block_length should be an integer value of the amount of seconds that represent the time to expire.

            blocked_hosts = System.ips_passivley_blocked(block_length=100)
        '''

        current_time = fast_time()

        # ACCEPT all -- 8.8.8.8(src) 0.0.0.0/0(dst) /* 123456 */L
        host_list = []
        output = util_shell(f'sudo iptables -t {table} -nL IPS').stdout.splitlines()
        for line in output[2:]:
            line = line.split()

            blocked_host, timestamp = line[3], int(line[6])

            # check whether the host rule has reach point of expiration. if not, loop will continue. for NO_DELAY
            # this condition will eval to False immediately, which marks rule for deletion.
            if (timestamp + block_length > current_time):
                continue

            host_list.append((blocked_host, timestamp))

        return host_list
Exemplo n.º 3
0
    def _timeout_reached(self):
        if (not self._timeout):
            return False

        if (fast_time() > self._initial_time + self._timeout):
            return True

        return False
Exemplo n.º 4
0
    def __init__(self, Log, name):
        self._Log = Log
        self._name = name

        self._initial_time = fast_time()

        self.has_ran = False
        self._timeout = None
        self._is_initializing = True
        self._thread_count = 0
        self._thread_ready = set()
Exemplo n.º 5
0
def add_proxy_domain(settings, *, ruleset):
    input_time = int(fast_time())
    expire_time = input_time + settings['timer'] * 60

    with ConfigurationManager(ruleset) as dnx:
        domain_list = dnx.load_configuration()

        domain_list['time_based'].update({
            settings['domain']: {
                'time': input_time,
                'rule_length': settings['timer'],
                'expire': expire_time
            }
        })

        dnx.write_configuration(domain_list)
Exemplo n.º 6
0
    def table_cleaner(self, log_length, table):
        expire_threshold = int(fast_time()) - (ONE_DAY * log_length)
        self.c.execute(
            f'delete from {table} where last_seen < {expire_threshold}')

        self.data_written = True
Exemplo n.º 7
0
    def blocked_cleaner(self, table):
        expire_threshold = int(fast_time()) - FIVE_MIN
        self.c.execute(
            f'delete from {table} where timestamp < {expire_threshold}')

        self.data_written = True