コード例 #1
0
def pas_logger(event):
    """Log authentication events like users logging in and loggin out."""
    # subscriber is registered even if package has not yet been installed
    # ignore any error caused by missing registry records
    try:
        record = IFingerPointingSettings.__identifier__ + '.audit_pas'
        audit_pas = api.portal.get_registry_record(record)
    except InvalidParameterError:
        return

    if audit_pas:
        user, ip = get_request_information()
        if IUserLoggedInEvent.providedBy(event):
            action = 'login'
            extras = ''
        elif IUserLoggedOutEvent.providedBy(event):
            action = 'logout'
            extras = ''
        elif IPrincipalCreatedEvent.providedBy(event):
            action = 'create'
            extras = u'principal={0}'.format(event.principal)
        elif IPrincipalDeletedEvent.providedBy(event):
            action = 'remove'
            extras = u'user={0}'.format(event.principal)
        if IGroupDeletedEvent.providedBy(event):
            action = 'remove'
            extras = u'group={0}'.format(event.principal)

        log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #2
0
def pas_logger(event):
    """Log authentication events like users logging in and loggin out."""
    name = IFingerPointingSettings.__identifier__ + '.audit_pas'
    try:
        audit_pas = api.portal.get_registry_record(name, default=False)
    except ComponentLookupError:  # plonectl adduser
        return

    if not audit_pas:
        return

    user, ip = get_request_information()

    if IUserLoggedInEvent.providedBy(event):
        action = 'login'
        extras = ''
    elif IUserLoggedOutEvent.providedBy(event):
        action = 'logout'
        extras = ''
    elif IPrincipalCreatedEvent.providedBy(event):
        action = 'create'
        extras = 'principal=' + str(event.principal)
    elif IPrincipalDeletedEvent.providedBy(event):
        action = 'remove'
        extras = 'user='******'remove'
        extras = 'group=' + str(event.principal)
    else:  # should never happen
        action = 'UNKNOWN'
        extras = ''

    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #3
0
def iterate_logger(event):
    """Log events like content editing checkouts and checkins, if
    plone.app.iterate is installed.
    """
    name = IFingerPointingSettings.__identifier__ + '.audit_iterate'
    audit_iterate = api.portal.get_registry_record(name, default=False)
    if not audit_iterate:
        return

    user, ip = get_request_information()

    if ICheckoutEvent.providedBy(event):
        action = 'checkout'
        extras = 'object={0} working_copy={1}'.format(
            event.object, event.working_copy)
    elif ICheckinEvent.providedBy(event):
        action = 'checkin'
        extras = 'object={0} baseline={1}'.format(
            event.object, event.baseline)
    elif ICancelCheckoutEvent.providedBy(event):
        action = 'cancel checkout'
        extras = 'object={0} baseline={1}'.format(
            event.object, event.baseline)
    else:  # should never happen
        action = '-'
        extras = 'object=' + repr(event.object)

    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #4
0
def profile_imports_logger(event):
    """Log Generic Setup profile imports."""
    name = IFingerPointingSettings.__identifier__ + '.audit_profile_imports'
    try:
        audit_enabled = api.portal.get_registry_record(name, default=False)
    except ComponentLookupError:  # adding Plone site
        return

    if not audit_enabled:
        return

    try:
        user, ip = get_request_information()
    except AttributeError:
        # XXX: getRequest() returns None instead actual request
        #      on tests of this subscriber
        user, ip = '-', '-'

    info = event.tool.getProfileInfo(event.profile_id)
    action = 'profile imported'
    extras = 'id={0} version={1}'.format(
        info['id'],
        info.get('version', '-'),  # uninstall profiles have no version info
    )
    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #5
0
ファイル: iterate_logger.py プロジェクト: renansfs/Plone_SP
def iterate_logger(event):
    """Log events like content editing checkouts and checkins, if
    plone.app.iterate is installed.
    """
    # subscriber is registered even if package has not yet been installed
    # ignore any error caused by missing registry records
    try:
        record = IFingerPointingSettings.__identifier__ + '.audit_iterate'
        audit_iterate = api.portal.get_registry_record(record)
    except InvalidParameterError:
        return

    if audit_iterate:
        user, ip = get_request_information()

        if ICheckoutEvent.providedBy(event):
            action = 'checkout'
            extras = u'object={0} working_copy={1}'.format(
                event.object, event.working_copy)
        if ICheckinEvent.providedBy(event):
            action = 'checkin'
            extras = u'object={0} baseline={1}'.format(
                event.object, event.baseline)
        if ICancelCheckoutEvent.providedBy(event):
            action = 'cancel checkout'
            extras = u'object={0} baseline={1}'.format(
                event.object, event.baseline)

        log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #6
0
def lifecycle_logger(obj, event):
    """Log content type life cycle events like object creation,
    modification and removal.
    """
    # subscriber is registered even if package has not yet been installed
    # ignore any error caused by missing registry records
    try:
        record = IFingerPointingSettings.__identifier__ + '.audit_lifecycle'
        audit_lifecycle = api.portal.get_registry_record(record)
    except (ComponentLookupError, InvalidParameterError):
        return

    if audit_lifecycle:
        user, ip = get_request_information()

        if IObjectCreatedEvent.providedBy(event):
            action = 'create'
            extras = u'object={0}'.format(repr(obj))
        if IObjectModifiedEvent.providedBy(event):
            action = 'modify'
            extras = u'object={0}'.format(repr(obj))
        if IObjectRemovedEvent.providedBy(event):
            action = 'remove'
            extras = u'object={0}'.format(repr(obj))

        log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #7
0
def pas_logger(event):
    """Log authentication events like users logging in and loggin out."""
    name = IFingerPointingSettings.__identifier__ + '.audit_pas'
    try:
        audit_pas = api.portal.get_registry_record(name, default=False)
    except ComponentLookupError:  # plonectl adduser
        return

    if not audit_pas:
        return

    user, ip = get_request_information()

    if IUserLoggedInEvent.providedBy(event):
        action = 'login'
        extras = ''
    elif IUserLoggedOutEvent.providedBy(event):
        action = 'logout'
        extras = ''
    elif IPrincipalCreatedEvent.providedBy(event):
        action = 'create'
        extras = 'principal=' + str(event.principal)
    elif IPrincipalDeletedEvent.providedBy(event):
        action = 'remove'
        extras = 'user='******'remove'
        extras = 'group=' + str(event.principal)
    else:  # should never happen
        action = 'UNKNOWN'
        extras = ''

    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #8
0
def lifecycle_logger(obj, event):
    """Log content type life cycle events like object creation,
    modification and removal.
    """
    name = IFingerPointingSettings.__identifier__ + '.audit_lifecycle'
    try:
        audit_lifecycle = api.portal.get_registry_record(name, default=False)
    except ComponentLookupError:  # Plone site removed
        return

    if not audit_lifecycle:
        return

    user, ip = get_request_information()

    if IObjectAddedEvent.providedBy(event):
        action = 'create'
    elif IObjectModifiedEvent.providedBy(event):
        action = 'modify'
    elif IObjectRemovedEvent.providedBy(event):
        action = 'remove'
    else:  # should never happen
        action = '-'

    extras = 'object=' + repr(obj)
    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #9
0
 def test_get_request_information(self):
     request = self.layer['request']
     request['AUTHENTICATED_USER'] = TEST_USER_NAME
     request['REMOTE_ADDR'] = localhost = '127.0.0.1'
     self.assertEqual(
         get_request_information(),
         (TEST_USER_NAME, localhost),
     )
コード例 #10
0
    def _log_replace(template, match, replaced_by, old_pod_expr, new_pod_expr):
        """ Log replacements if fingerpointing installed """
        if HAS_FINGERPOINTING:
            from collective.fingerpointing.config import AUDIT_MESSAGE
            from collective.fingerpointing.logger import log_info
            from collective.fingerpointing.utils import get_request_information

            # add logging message to fingerpointing log
            user, ip = get_request_information()
            action = "replace_in_template"
            extras = u"podtemplate={0} match={1} replaced_by={2} old_pod_expr={3} new_pod_expr={4}".format(
                "/".join(template.getPhysicalPath()), match, replaced_by, old_pod_expr, new_pod_expr,
            )
            log_info(unicode(AUDIT_MESSAGE).format(user, ip, action, extras))
コード例 #11
0
def workflow_logger(event):
    """Log workflow transitions."""
    name = IFingerPointingSettings.__identifier__ + '.audit_workflow'
    audit_workflow = api.portal.get_registry_record(name, default=False)
    if not audit_workflow:
        return

    user, ip = get_request_information()

    action = 'workflow transition'
    extra_info = {'object': event.object, 'transition': event.action}

    extras = log_info.format_extras('registry', event, action, extra_info)
    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #12
0
ファイル: registry_logger.py プロジェクト: renansfs/Plone_SP
def registry_logger(event):
    """Log registry events like records being modified."""
    # subscriber is registered even if package has not yet been installed
    # ignore any error caused by missing registry records
    try:
        record = IFingerPointingSettings.__identifier__ + '.audit_registry'
        audit_registry = api.portal.get_registry_record(record)
    except InvalidParameterError:
        return

    if audit_registry:
        user, ip = get_request_information()

        if IRecordModifiedEvent.providedBy(event):
            action = 'modify'
            extras = u'object={0} value={1}'.format(event.record, event.record.value)

        log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #13
0
def registry_logger(event):
    """Log registry events like records being modified."""
    # subscriber is registered even if package has not yet been installed
    # ignore any error caused by missing registry records
    try:
        record = IFingerPointingSettings.__identifier__ + '.audit_registry'
        audit_registry = api.portal.get_registry_record(record)
    except InvalidParameterError:
        return

    if audit_registry:
        user, ip = get_request_information()

        if IRecordModifiedEvent.providedBy(event):
            action = 'modify'
            extras = u'object={0} value={1}'.format(event.record,
                                                    event.record.value)

        log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #14
0
def registry_logger(event):
    """Log registry events like records being modified."""
    name = IFingerPointingSettings.__identifier__ + '.audit_registry'
    audit_registry = api.portal.get_registry_record(name, default=False)
    if not audit_registry:
        return

    user, ip = get_request_information()

    if IRecordModifiedEvent.providedBy(event):
        action = 'modify'
        extras = 'object={0} value={1}'.format(
            event.record,
            _safe_native_string(event.record.value),
        )
    else:  # should never happen
        action = '-'
        extras = 'object' + event.record

    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #15
0
def registry_logger(event):
    """Log registry events like records being modified."""
    name = IFingerPointingSettings.__identifier__ + '.audit_registry'
    audit_registry = api.portal.get_registry_record(name, default=False)
    if not audit_registry:
        return

    user, ip = get_request_information()

    if IRecordModifiedEvent.providedBy(event):
        action = 'modify'
        extras = 'object={0} value={1}'.format(
            event.record,
            safe_utf8(event.record.value),
        )
    else:  # should never happen
        action = '-'
        extras = 'object' + event.record

    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #16
0
def registry_logger(event):
    """Log registry events like records being modified."""
    name = IFingerPointingSettings.__identifier__ + '.audit_registry'
    audit_registry = api.portal.get_registry_record(name, default=False)
    if not audit_registry:
        return

    user, ip = get_request_information()

    if IRecordModifiedEvent.providedBy(event):
        action = 'modify'
        extra_info = {
            'object': event.record,
            'value': safe_utf8(event.record.value)
        }
    else:  # should never happen
        action = '-'
        extra_info = {'object': event.record}

    extras = log_info.format_extras('registry', event, action, extra_info)
    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
コード例 #17
0
    def generate_and_download_doc(self, pod_template, output_format):
        """
        Generate a document of format 'output_format' from the template
        'pod_template' and return it as a downloadable file.
        """
        if HAS_FINGERPOINTING:
            from collective.fingerpointing.config import AUDIT_MESSAGE
            from collective.fingerpointing.logger import log_info
            from collective.fingerpointing.utils import get_request_information
            # add logging message to fingerpointing log
            user, ip = get_request_information()
            action = 'generate_document'
            extras = 'context={0} pod_template={1} output_format={2}'.format(
                '/'.join(self.context.getPhysicalPath()),
                '/'.join(pod_template.getPhysicalPath()), output_format)
            log_info(AUDIT_MESSAGE.format(user, ip, action, extras))

        doc, doc_name, gen_context = self._generate_doc(
            pod_template, output_format)
        self._set_header_response(doc_name)
        return doc
コード例 #18
0
    def generate_and_download_doc(self, pod_template, output_format):
        """
        Generate a document of format 'output_format' from the template
        'pod_template' and return it as a downloadable file.
        """
        if HAS_FINGERPOINTING:
            from collective.fingerpointing.config import AUDIT_MESSAGE
            from collective.fingerpointing.logger import log_info
            from collective.fingerpointing.utils import get_request_information
            # add logging message to fingerpointing log
            user, ip = get_request_information()
            action = 'generate_document'
            extras = 'context={0} pod_template={1} output_format={2}'.format(
                '/'.join(self.context.getPhysicalPath()),
                '/'.join(pod_template.getPhysicalPath()),
                output_format)
            log_info(AUDIT_MESSAGE.format(user, ip, action, extras))

        doc, doc_name, gen_context = self._generate_doc(pod_template, output_format)
        self._set_header_response(doc_name)
        return doc
コード例 #19
0
 def test_get_request_information(self):
     from collective.fingerpointing import utils
     self.assertEqual(
         utils.get_request_information(), ('test_user_1_', 'None'))
コード例 #20
0
 def test_get_request_information_cloudflare(self):
     self.request.environ['HTTP_CF_CONNECTING_IP'] = '192.168.1.1'
     from collective.fingerpointing import utils
     self.assertEqual(
         utils.get_request_information(), ('test_user_1_', '192.168.1.1'))
コード例 #21
0
ファイル: fingerpointing.py プロジェクト: thet/bda.empower
def fingerpointing_log(name, **payload):
    user, ip = get_request_information()
    spayload = " ".join([(k + "=" + v) for k, v in payload.items()])
    log_info(AUDIT_MESSAGE.format(user, ip, name, spayload))
コード例 #22
0
 def test_get_request_information_anonymous(self):
     from plone.app.testing import logout
     logout()
     from collective.fingerpointing import utils
     self.assertEqual(utils.get_request_information(), ('-', 'None'))