Example #1
0
    def message(cls, mod_name, mtype, level, message):
        date = System.date(string=True)
        timestamp = System.format_time(fast_time())
        level = cls.convert_level(level)

        system_ip = None

        # using system/UTC time
        # 20140624|19:08:15|EVENT|DNSProxy:Informational|192.168.83.1|*MESSAGE*
        message = f'{date}|{timestamp}|{mtype.name}|{mod_name}:{level}|{system_ip}|{message}'

        return message.encode('utf-8')
Example #2
0
    def geo_input(self, _, log):
        month = ','.join(System.date()[:2])

        # if this is the first time this country has been seen in the current month, it will be inserted with
        # counts zerod out
        if not self._geo_entry_check(log, month):
            self._c.execute(f'insert into geolocation values (?, ?, ?, ?, ?)',
                            (month, log.country, log.direction, 0, 0))

        # incremented count of the actions specified in the log.
        self._c.execute(
            f'update geolocation set {log.action}={log.action}+1 where month=? and country=? and direction=?',
            (month, log.country, log.direction))
Example #3
0
    def organize(self):
        # print('[+] Starting organize operation.')
        log_entries = []

        date = str_join(System.date())
        for module in self._log_modules:
            module_entries = self._combine_logs(module, date)
            if (module_entries):
                log_entries.extend(module_entries)

        sorted_log_entries = sorted(log_entries)
        if (sorted_log_entries):
            self._write_combined_logs(sorted_log_entries, date)

        del log_entries  # to reclaim system memory
Example #4
0
    def query_geolocation(self, count, *, action, direction):
        month = ','.join(System.date()[:2])

        # adds an extra space to results for 'NONE' which is more common than normal since the geolocation db is not yet complete
        count += 1

        self._c.execute(
            f'select country, {action} from geolocation where month=? and direction=? '
            f'order by {action} desc limit {count}', (month, direction))

        # filtering out entries with no hits in the specified action. if those are returned, they have hits on the
        # opposite action. currently filtering out 'NONE' since the geolocation database is not yet complete.
        return [
            x[0].replace('_', ' ') for x in self._c.fetchall()
            if x[1] and x[0] != 'NONE'
        ]
Example #5
0
    def _calculate_times(self):
        restriction_start, restriction_length, offset = self._load_restriction(
        )

        now = fast_time() + offset
        c_d = [int(i) for i in System.date(now)]  # current date
        r_start = [int(i) for i in restriction_start.split(':')]

        restriction_start = datetime(c_d[0], c_d[1], c_d[2], r_start[0],
                                     r_start[1]).timestamp()
        restriction_end = restriction_start + restriction_length

        if (self.is_active):
            restriction_end = load_configuration('ip_proxy_timer')['end']

        else:
            self._write_end_time(restriction_end)

        return restriction_start, restriction_end, now