Exemple #1
0
    def __init__(self, *args, **kwargs):

        logname = 'webfirewall.filter.{}.log'.format(self.__class__.__name__)
        self.exception = None
        self.log = get_log(logname, recreate=True)

        super(WebFilter, self).__init__(*args, **kwargs)
    def __init__(self, filename=None):
        '''
            Create a log file named after the class that called this constructor.

            >>> from syr.log import BASE_LOG_DIR
            >>> from syr.user import whoami
            >>> filename = 'goodcrypto.utils.log_file.log'
            >>> if os.path.exists(os.path.join(BASE_LOG_DIR, whoami(), filename)): os.remove(os.path.join(BASE_LOG_DIR, whoami(), filename))
            >>> log = LogFile(filename)
            >>> log.logging_enabled = True
            >>> log.write('test')
            >>> os.path.exists(os.path.join(BASE_LOG_DIR, whoami(), filename))
            True
            >>> if os.path.exists(os.path.join(BASE_LOG_DIR, whoami(), filename)): os.remove(os.path.join(BASE_LOG_DIR, whoami(), filename))
        '''

        try:
            from goodcrypto.utils import debug_logs_enabled
            self.logging_enabled = debug_logs_enabled()
        except Exception as IOError:
            record_exception()
            self.logging_enabled = True

        try:
            if filename is None:
                # try to find the name of the caller
                filename = caller_module_name(ignore=[__file__, 'log.py'])
        except Exception:
            filename = 'goodcrypto.utils.log'

        # get to a reasonable filename if the entire path was included
        if filename.startswith('/'):
            filename = os.path.basename(filename)

        # strip off standard python extensions
        if filename.endswith('.py') or filename.endswith('.pyc'):
            filename, __, __ = filename.rpartition('.')

        if not filename.endswith('.log'):
            filename = '{}.log'.format(filename)

        self.log = get_log(filename=filename)
        self.pathname = get_log_path(filename=filename)
    def __init__(self, filename=None):
        '''
            Create a log file named after the class that called this constructor.

            >>> from syr.log import BASE_LOG_DIR
            >>> from syr.user import whoami
            >>> filename = 'goodcrypto.utils.log_file.log'
            >>> if os.path.exists(os.path.join(BASE_LOG_DIR, whoami(), filename)): os.remove(os.path.join(BASE_LOG_DIR, whoami(), filename))
            >>> log = LogFile(filename)
            >>> log.logging_enabled = True
            >>> log.write('test')
            >>> os.path.exists(os.path.join(BASE_LOG_DIR, whoami(), filename))
            True
            >>> if os.path.exists(os.path.join(BASE_LOG_DIR, whoami(), filename)): os.remove(os.path.join(BASE_LOG_DIR, whoami(), filename))
        '''

        try:
            from goodcrypto.utils import debug_logs_enabled
            self.logging_enabled = debug_logs_enabled()
        except Exception as IOError:
            record_exception()
            self.logging_enabled = True

        try:
            if filename is None:
                # try to find the name of the caller
                filename = caller_module_name(ignore=[__file__,'log.py'])
        except Exception:
            filename = 'goodcrypto.utils.log'

        # get to a reasonable filename if the entire path was included
        if filename.startswith('/'):
            filename = os.path.basename(filename)

        # strip off standard python extensions
        if filename.endswith('.py') or filename.endswith('.pyc'):
            filename, __, __ = filename.rpartition('.')

        if not filename.endswith('.log'):
            filename = '{}.log'.format(filename)

        self.log = get_log(filename=filename)
        self.pathname = get_log_path(filename=filename)
    def __init__(self, name, program, host, port):
        ''' Initialize. '''

        self.name = name
        self.program = program
        self.host = host
        self.port = port

        self.watchdog_timer = None
        self.restarting = False

        logname = self.name.replace(' ', '.')
        self.logfile = '{}.output.log'.format(logname)
        self.log = get_log(self.logfile, recreate=True)

        # make this namespace available in threads
        namespace = {}
        namespace.update(globals())
        namespace.update(locals())
        self.namespace = DictObject(namespace)
Exemple #5
0
    This file is open source, licensed under GPLv3 <http://www.gnu.org/licenses/>.
'''
from traceback import format_exc

from django import forms
from django.core.exceptions import ValidationError

try:
    from goodcrypto.webfirewall.models import Options
except:
    from webfirewall.models import Options
    
from syr.log import get_log

log = get_log()



class OptionsAdminForm(forms.ModelForm):

    class Meta:
        model = Options

        fields = [
                  'tor_middle_relay',
        ]

    class Media:
        js = ('/static/js/admin_js.js',)
Exemple #6
0
    Last modified: 2016-10-28

    This file is open source, licensed under GPLv3 <http://www.gnu.org/licenses/>.
'''
from django.core import validators
from django.db import models
from django.db.models.signals import pre_delete, post_save

from goodcrypto.mail import constants, model_signals
from goodcrypto.mail.utils import email_in_domain
from goodcrypto.oce.utils import format_fingerprint
from goodcrypto.utils import i18n
# do not use LogFile because it references models.Options
from syr.log import get_log

_log = get_log()

HOURS = i18n('Hours')
DAYS = i18n('Days')
WEEKS = i18n('Weeks')
MONTHS = i18n('Months')
YEARS = i18n('Years')


class EncryptionSoftware(models.Model):
    '''
        The encryption software available to goodcrypto.

        Create some encryption software
        >>> test_gpg = EncryptionSoftware.objects.create(
        ... name='TestAnotherGPG', active=True, classname='goodcrypto.oce.gpg_plugin.GPGPlugin')
Exemple #7
0

import os, os.path, sys, traceback
from contextlib import contextmanager
from glob import glob


DEBUGGING = False
LOGGING = False

# site_packages_subdir_glob is relative to the virtualenv dir
site_packages_subdir_glob = 'lib/python*/site-packages'

if DEBUGGING:
    from syr.log import get_log
    log = get_log(recreate=True)

def debug(msg):
    if DEBUGGING:
        if LOGGING:
            log.write(msg)
        else:
            print(msg)

@contextmanager
def venv(dirname=None, django_app=None, restore=True):
    ''' Context manager to activate a virtualenv.

        Example::

            from ve import venv
Exemple #8
0
from abc import abstractmethod
import os, re, sh, sys, traceback
from threading import Timer

from syr.format import pretty
from syr.lock import locked
from syr import log
from syr.python import stacktrace

if IS_PY2:
    from syr.abstract_python2_class import AbstractPythonClass
else:
    from syr.abstract_python3_class import AbstractPythonClass


log = log.get_log()

class CliException(Exception):
    pass


class StderrException(Exception):
    ''' Raised when run() detects stderr output '''

    def __init__(self, sh_result):
        self.sh_result = sh_result

class AbstractCli(AbstractPythonClass):
    ''' Run a command line interface program with responses. '''

    PRINT_LOG = False
Exemple #9
0
def log(message):
    global _log
    if not _log:
        from syr.log import get_log
        _log = get_log()
    _log(message)
 def __init__(self):
     self.log = get_log()
Exemple #11
0
import syr.utils
from syr.fs import edit_file_in_place
from syr.utils import stacktrace
from syr.times import now, one_second, timedelta_to_seconds
from syr.redir import redir_stdout, redir_stderr

try:
    from goodcrypto.webfirewall.constants import USER, USER_GROUP, HTTP_PROXY_PORT, TOR_PORT
except:
    from webfirewall.constants import USER, USER_GROUP, HTTP_PROXY_PORT, TOR_PORT

# usewithtor is not needed if downstream proxies know how to use tor
# python apps should call syr.net.torify()
use_usewithtor = False

log = get_log('webfirewall.main.log', recreate=True)

localhost = '127.0.0.1' # use ip as string, not 'localhost'

proxies = []

class Proxy(object):
    ''' Proxy server manager '''

    INITIAL_PERIOD = 10 # seconds
    RETRY_PERIOD = 60 # seconds

    def __init__(self, name, program, host, port):
        ''' Initialize. '''

        self.name = name
Exemple #12
0
import sys
IS_PY2 = sys.version_info[0] == 2

if IS_PY2:
    import __builtin__
else:
    import builtins
from itertools import takewhile
from threading import Event, Thread
from time import sleep

from syr.log import get_log

# log in non-standard dir because of concurrency issues
log = get_log('/tmp/iter.log')

def is_iterable(item):
    ''' Return True iff item is iterable. 
    
        >>> print(is_iterable(3))
        False
    '''

    try:
        list(item)
    except TypeError:
        result = False
    else:
        result = True