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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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
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
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))