Example #1
0
"""
Codebay logging utility module.
"""
__docformat__ = 'epytext en'

import logging, atexit, sys, os, time, datetime
from logging import handlers

from codebay.common.siteconfig import conf

conf.add('logging_config', 'default')
conf.add('logging_debug', False)
conf.add('logging_stdout', False)
conf.add('logging_stderr', False)
conf.add('logging_syslog', False)

get = logging.getLogger


class SplittingSysLogHandler(handlers.SysLogHandler):
    _vanillaformatter = logging.Formatter('%(message)s')

    def __init__(self, *args, **kw):
        self.unixsocket = 0
        handlers.SysLogHandler.__init__(self, *args, **kw)

    def _split_record(self, rec):
        # XXX: logging the result of raise Exception('') causes a problem with Python
        # logging modules; we should try to fix that here, but it's not completely
        # trivial.
Example #2
0
"""
Codebay logging utility module.
"""
__docformat__ = 'epytext en'

import logging, atexit, sys, os, time, datetime
from logging import handlers

from codebay.common.siteconfig import conf

conf.add('logging_config', 'default')
conf.add('logging_debug', False)
conf.add('logging_stdout', False)
conf.add('logging_stderr', False)
conf.add('logging_syslog', False)

get = logging.getLogger


class SplittingSysLogHandler(handlers.SysLogHandler):
    _vanillaformatter = logging.Formatter('%(message)s')

    def __init__(self, *args, **kw):
        self.unixsocket = 0
        handlers.SysLogHandler.__init__(self, *args, **kw)

    def _split_record(self, rec):
        # XXX: logging the result of raise Exception('') causes a problem with Python
        # logging modules; we should try to fix that here, but it's not completely
        # trivial.
Example #3
0
This is not a high speed implementation.

@var minseedlen:
    Minimum random seed length.

@var seedfile:
    Random seed file.  Should be readable for all relevant users.
"""
__docformat__ = 'epytext en'

import time, os, hmac

from codebay.common.siteconfig import conf

conf.add('minseedlen', 16)
conf.add('seedfile', '/tmp/randomseed.bin') # XXX: this is bad location, but file required before /var/run/l2tpgw/ is initialized
_seedhmac = None

class Error(Exception):
    """RandomException"""

def initialize_seed():
    """Create seed file from /dev/random."""

    f = open('/dev/random', 'rb')
    seed = f.read(conf.minseedlen)
    f.close()

    f = open(conf.seedfile, 'wb')
    f.write(seed)