Esempio n. 1
0
    def export_status(self, taskid):
        "export status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            msg = _('The task status requested has expired or does not exist')
            flash(msg)
            log.info(msg)
            redirect(url(controller='accounts', action='index'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                msg = _('Error occured in processing %s') % result.result
                if c.user.is_superadmin:
                    flash_alert(msg)
                    log.info(msg)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                    log.info(msg)
                redirect(url(controller='accounts', action='index'))
            results = dict(
                f=True if not result.result['global_error'] else False,
                id=taskid,
                global_error=result.result['global_error'])
            audit_log(c.user.username, 5, unicode(auditmsgs.ACCOUNTEXPORT_MSG),
                      request.host, request.remote_addr,
                      arrow.utcnow().datetime)
        else:
            try:
                session['acexport-count'] += 1
            except KeyError:
                session['acexport-count'] = 1
            session.save()
            if (session['acexport-count'] >= 10
                    and result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                del session['acexport-count']
                session.save()
                msg = _('The export could not be processed, try again later')
                flash_alert(msg)
                log.info(msg)
                redirect(url(controller='accounts', action='index'))
            finished = False
            results = dict(f=None, global_error=None)

        c.finished = finished
        c.results = results
        c.success = result.successful()
        dwn = request.GET.get('d', None)
        if finished and (dwn and dwn == 'y'):
            response.content_type = 'text/csv'
            response.headers['Cache-Control'] = 'max-age=0'
            csvdata = result.result['f']
            disposition = 'attachment; filename=accounts-export-%s.csv' % \
                            taskid
            response.headers['Content-Disposition'] = str(disposition)
            response.headers['Content-Length'] = len(csvdata)
            return csvdata
        return self.render('/accounts/exportstatus.html')
Esempio n. 2
0
    def export_status(self, taskid):
        "export status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            msg = _('The task status requested has expired or does not exist')
            flash(msg)
            log.info(msg)
            redirect(url(controller='accounts', action='index'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                msg = _('Error occured in processing %s') % result.result
                if c.user.is_superadmin:
                    flash_alert(msg)
                    log.info(msg)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                    log.info(msg)
                redirect(url(controller='accounts', action='index'))
            results = dict(
                        f=True if not result.result['global_error'] else False,
                        id=taskid, global_error=result.result['global_error'])
            audit_log(c.user.username,
                    5, unicode(auditmsgs.ACCOUNTEXPORT_MSG), request.host,
                    request.remote_addr, arrow.utcnow().datetime)
        else:
            try:
                session['acexport-count'] += 1
            except KeyError:
                session['acexport-count'] = 1
            session.save()
            if (session['acexport-count'] >= 10 and
                result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                del session['acexport-count']
                session.save()
                msg = _('The export could not be processed, try again later')
                flash_alert(msg)
                log.info(msg)
                redirect(url(controller='accounts', action='index'))
            finished = False
            results = dict(f=None, global_error=None)

        c.finished = finished
        c.results = results
        c.success = result.successful()
        dwn = request.GET.get('d', None)
        if finished and (dwn and dwn == 'y'):
            response.content_type = 'text/csv'
            response.headers['Cache-Control'] = 'max-age=0'
            csvdata = result.result['f']
            disposition = 'attachment; filename=accounts-export-%s.csv' % \
                            taskid
            response.headers['Content-Disposition'] = str(disposition)
            response.headers['Content-Length'] = len(csvdata)
            return csvdata
        return self.render('/accounts/exportstatus.html')
Esempio n. 3
0
    def export_status(self, taskid):
        "export status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            flash(_('The task status requested has expired or does not exist'))
            redirect(url(controller='domains', action='index'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                if c.user.is_superadmin:
                    flash_alert(
                        _('Error occured in processing %s') % result.result)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                redirect(url(controller='domains'))
            results = dict(
                f=True if not result.result['global_error'] else False,
                id=taskid,
                global_error=result.result['global_error'])
        else:
            session['dexport-count'] += 1
            if (session['dexport-count'] >= 10
                    and result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                flash_alert(
                    _('The export could not be processed,'
                      ' try again later'))
                del session['dexport-count']
                session.save()
                redirect(url(controller='domains'))
            finished = False
            results = dict(f=None, global_error=None)

        c.finished = finished
        c.results = results
        c.success = result.successful()
        d = request.GET.get('d', None)
        if finished and (d and d == 'y'):
            info = EXPORTDOM_MSG % dict(d='all')
            audit_log(c.user.username, 5, info, request.host,
                      request.remote_addr, now())
            response.content_type = 'text/csv'
            response.headers['Cache-Control'] = 'max-age=0'
            csvdata = result.result['f']
            disposition = 'attachment; filename=domains-export-%s.csv' % taskid
            response.headers['Content-Disposition'] = str(disposition)
            response.headers['Content-Length'] = len(csvdata)
            return csvdata
        return render('/domains/exportstatus.html')
Esempio n. 4
0
    def audit_export_status(self, taskid):
        "Audit log export status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            msg = _('The task status requested has expired or does not exist')
            flash(msg)
            log.info(msg)
            redirect(url('status-audit-logs'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                msg = _('Error occured in processing %s') % result.result
                if c.user.is_superadmin:
                    flash_alert(msg)
                    log.info(msg)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                    log.info(msg)
                redirect(url('status-audit-logs'))
        else:
            session['exportauditlog-counter'] += 1
            session.save()
            if (session['exportauditlog-counter'] >= 20 and
                result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                del session['exportauditlog-counter']
                session.save()
                flash_alert(_('The audit log export failed, try again later'))
                redirect(url('status-audit-logs'))
            finished = False

        c.finished = finished
        c.results = result.result
        c.success = result.successful()
        dwn = request.GET.get('d', None)
        if finished and (dwn and dwn == 'y'):
            audit_log(c.user.username,
                    5, unicode(AUDITLOGEXPORT_MSG), request.host,
                    request.remote_addr, arrow.utcnow().datetime)
            response.content_type = result.result['content_type']
            response.headers['Cache-Control'] = 'max-age=0'
            respdata = result.result['f']
            disposition = 'attachment; filename=%s' % result.result['filename']
            response.headers['Content-Disposition'] = str(disposition)
            response.headers['Content-Length'] = len(respdata)
            return respdata
        return self.render('/status/auditexportstatus.html')
Esempio n. 5
0
    def import_status(self, taskid):
        "import domains status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            msg = _('The task status requested has expired or does not exist')
            flash(msg)
            log.info(msg)
            redirect(url(controller='organizations', action='index'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                msg = _('Error occured in processing %s') % result.result
                if c.user.is_superadmin:
                    flash_alert(msg)
                    log.info(msg)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                    log.info(msg)
                redirect(url(controller='organizations'))
            update_serial.delay()
            info = auditmsgs.IMPORTORG_MSG % dict(o='-')
            audit_log(c.user.username, 3, unicode(info), request.host,
                      request.remote_addr,
                      arrow.utcnow().datetime)
        else:
            session['dimport-counter'] += 1
            session.save()
            if (session['dimport-counter'] >= 10
                    and result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                try:
                    os.unlink(session['dimport-file'])
                except OSError:
                    pass
                del session['dimport-file']
                del session['dimport-counter']
                session.save()
                flash_alert(
                    _('The import could not be processed,'
                      ' try again later'))
                redirect(url(controller='organizations'))
            finished = False

        c.finished = finished
        c.results = result.result
        c.success = result.successful()
        return self.render('/organizations/importstatus.html')
Esempio n. 6
0
    def audit_export_status(self, taskid):
        "Audit log export status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            msg = _('The task status requested has expired or does not exist')
            flash(msg)
            log.info(msg)
            redirect(url('status-audit-logs'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                msg = _('Error occured in processing %s') % result.result
                if c.user.is_superadmin:
                    flash_alert(msg)
                    log.info(msg)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                    log.info(msg)
                redirect(url('status-audit-logs'))
        else:
            session['exportauditlog-counter'] += 1
            session.save()
            if (session['exportauditlog-counter'] >= 20
                    and result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                del session['exportauditlog-counter']
                session.save()
                flash_alert(_('The audit log export failed, try again later'))
                redirect(url('status-audit-logs'))
            finished = False

        c.finished = finished
        c.results = result.result
        c.success = result.successful()
        dwn = request.GET.get('d', None)
        if finished and (dwn and dwn == 'y'):
            audit_log(c.user.username, 5, unicode(AUDITLOGEXPORT_MSG),
                      request.host, request.remote_addr,
                      arrow.utcnow().datetime)
            response.content_type = result.result['content_type']
            response.headers['Cache-Control'] = 'max-age=0'
            respdata = result.result['f']
            disposition = 'attachment; filename=%s' % result.result['filename']
            response.headers['Content-Disposition'] = str(disposition)
            response.headers['Content-Length'] = len(respdata)
            return respdata
        return self.render('/status/auditexportstatus.html')
Esempio n. 7
0
    def import_status(self, taskid):
        "import domains status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            msg = _('The task status requested has expired or does not exist')
            flash(msg)
            log.info(msg)
            redirect(url(controller='organizations', action='index'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                msg = _('Error occured in processing %s') % result.result
                if c.user.is_superadmin:
                    flash_alert(msg)
                    log.info(msg)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                    log.info(msg)
                redirect(url(controller='organizations'))
            update_serial.delay()
            info = auditmsgs.IMPORTORG_MSG % dict(o='-')
            audit_log(c.user.username,
                    3, unicode(info), request.host,
                    request.remote_addr, arrow.utcnow().datetime)
        else:
            session['dimport-counter'] += 1
            session.save()
            if (session['dimport-counter'] >= 10 and
                result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                try:
                    os.unlink(session['dimport-file'])
                except OSError:
                    pass
                del session['dimport-file']
                del session['dimport-counter']
                session.save()
                flash_alert(_('The import could not be processed,'
                            ' try again later'))
                redirect(url(controller='organizations'))
            finished = False

        c.finished = finished
        c.results = result.result
        c.success = result.successful()
        return self.render('/organizations/importstatus.html')
Esempio n. 8
0
    def export_status(self, taskid):
        "export status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session["taskids"]:
            flash(_("The task status requested has expired or does not exist"))
            redirect(url(controller="domains", action="index"))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                if c.user.is_superadmin:
                    flash_alert(_("Error occured in processing %s") % result.result)
                else:
                    flash_alert(_("Backend error occured during processing."))
                redirect(url(controller="domains"))
            results = dict(
                f=True if not result.result["global_error"] else False,
                id=taskid,
                global_error=result.result["global_error"],
            )
        else:
            session["dexport-count"] += 1
            if session["dexport-count"] >= 10 and result.state in ["PENDING", "RETRY", "FAILURE"]:
                result.revoke()
                flash_alert(_("The export could not be processed," " try again later"))
                del session["dexport-count"]
                session.save()
                redirect(url(controller="domains"))
            finished = False
            results = dict(f=None, global_error=None)

        c.finished = finished
        c.results = results
        c.success = result.successful()
        d = request.GET.get("d", None)
        if finished and (d and d == "y"):
            info = EXPORTDOM_MSG % dict(d="all")
            audit_log(c.user.username, 5, info, request.host, request.remote_addr, datetime.now())
            response.content_type = "text/csv"
            response.headers["Cache-Control"] = "max-age=0"
            csvdata = result.result["f"]
            disposition = "attachment; filename=domains-export-%s.csv" % taskid
            response.headers["Content-Disposition"] = disposition
            response.headers["Content-Length"] = len(csvdata)
            return csvdata
        return render("/domains/exportstatus.html")
Esempio n. 9
0
    def import_status(self, taskid):
        "import status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            flash(_('The task status requested has expired or does not exist'))
            redirect(url(controller='accounts', action='index'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                if c.user.is_superadmin:
                    flash_alert(_('Error occured in processing %s') %
                                result.result)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                redirect(url(controller='accounts'))
            update_serial.delay()
            audit_log(c.user.username,
                    3, unicode(ACCOUNTIMPORT_MSG), request.host,
                    request.remote_addr, now())
        else:
            session['acimport-count'] += 1
            if (session['acimport-count'] >= 10 and
                result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                try:
                    os.unlink(session['acimport-file'])
                except OSError:
                    pass
                del session['acimport-count']
                session.save()
                flash_alert(_('The import could not be processed,'
                            ' try again later'))
                redirect(url(controller='accounts'))
            finished = False

        c.finished = finished
        c.results = result.result
        c.success = result.successful()
        return render('/accounts/importstatus.html')
Esempio n. 10
0
    def import_status(self, taskid):
        "import status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session['taskids']:
            flash(_('The task status requested has expired or does not exist'))
            redirect(url(controller='accounts', action='index'))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                if c.user.is_superadmin:
                    flash_alert(
                        _('Error occured in processing %s') % result.result)
                else:
                    flash_alert(_('Backend error occured during processing.'))
                redirect(url(controller='accounts'))
            update_serial.delay()
            audit_log(c.user.username, 3, ACCOUNTIMPORT_MSG, request.host,
                      request.remote_addr, now())
        else:
            session['acimport-count'] += 1
            if (session['acimport-count'] >= 10
                    and result.state in ['PENDING', 'RETRY', 'FAILURE']):
                result.revoke()
                try:
                    os.unlink(session['acimport-file'])
                except OSError:
                    pass
                del session['acimport-count']
                session.save()
                flash_alert(
                    _('The import could not be processed,'
                      ' try again later'))
                redirect(url(controller='accounts'))
            finished = False

        c.finished = finished
        c.results = result.result
        c.success = result.successful()
        return render('/accounts/importstatus.html')
Esempio n. 11
0
    def import_status(self, taskid):
        "import domains status"
        result = AsyncResult(taskid)
        if result is None or taskid not in session["taskids"]:
            flash(_("The task status requested has expired or does not exist"))
            redirect(url(controller="organizations", action="index"))

        if result.ready():
            finished = True
            flash.pop_messages()
            if isinstance(result.result, Exception):
                if c.user.is_superadmin:
                    flash_alert(_("Error occured in processing %s") % result.result)
                else:
                    flash_alert(_("Backend error occured during processing."))
                redirect(url(controller="organizations"))
            update_serial.delay()
            info = IMPORTORG_MSG % dict(o="-")
            audit_log(c.user.username, 3, info, request.host, request.remote_addr, now())
        else:
            session["dimport-counter"] += 1
            session.save()
            if session["dimport-counter"] >= 10 and result.state in ["PENDING", "RETRY", "FAILURE"]:
                result.revoke()
                try:
                    os.unlink(session["dimport-file"])
                except OSError:
                    pass
                del session["dimport-file"]
                del session["dimport-counter"]
                session.save()
                flash_alert(_("The import could not be processed," " try again later"))
                redirect(url(controller="organizations"))
            finished = False

        c.finished = finished
        c.results = result.result
        c.success = result.successful()
        return render("/organizations/importstatus.html")
Esempio n. 12
0
    def detail(self, id, archive=None, format=None):
        "return message detail"
        message = self._get_msg(id, archive)
        if not message:
            abort(404)

        msgstatus = Session.query(MessageStatus)\
                    .filter(MessageStatus.messageid==message.messageid)\
                    .all()
        show_trail = request.GET.get('t', None)

        c.form = ReleaseMsgForm(request.POST, csrf_context=session)
        if request.POST and c.form.validate():
            localtmz = config.get('baruwa.timezone', 'Africa/Johannesburg')
            job = dict(release=c.form.release.data,
                        learn=c.form.learn.data, 
                        salearn_as=c.form.learnas.data,
                        todelete=c.form.delete.data,
                        use_alt=c.form.usealt.data,
                        altrecipients=c.form.altrecipients.data,
                        message_id=message.messageid,
                        from_address=message.from_address,
                        date=convert_date(message.timestamp, localtmz).strftime('%Y%m%d'),
                        to_address=message.to_address,
                        hostname=message.hostname,
                        mid=message.id)
            try:
                task = process_quarantined_msg.apply_async(
                        args=[job], queue=message.hostname)
                task.wait(30)
                if task.status == 'SUCCESS':
                    # process response
                    html = process_release_results(
                            c, message, task.result,
                            Session)
                    self.invalidate = 1
                    message = self._get_msg(id, archive)
                    flash(html)
                else:
                    html = _('Processing the request failed')
                    flash_alert(html)
            except (TimeoutError, QueueNotFound):
                html = _('Processing the request failed')
                flash_alert(html)
            if format == 'json':
                flash.pop_messages()
                response.headers['Content-Type'] = 'application/json'
                return json.dumps(dict(result=html))
        elif request.POST and not c.form.validate():
            flash_alert(_(u', '.join([unicode(c.form.errors[err][0])
                                for err in c.form.errors])))
            if format == 'json':
                html = flash.pop_messages()
                response.headers['Content-Type'] = 'application/json'
                return json.dumps(dict(result=unicode(html[0])))

        if format == 'json':
            response.headers['Content-Type'] = 'application/json'
            return json.dumps(message.tojson)
        c.msg = message
        c.archived = archive
        c.show_trail = show_trail
        c.msgstatus = msgstatus
        return render('/messages/detail.html')
Esempio n. 13
0
    def detail(self, id, archive=None, format=None):
        "return message detail"
        message = self._get_msg(id, archive)
        if not message:
            abort(404)

        msgstatus = Session.query(MessageStatus)\
                    .filter(MessageStatus.messageid==message.messageid)\
                    .all()
        show_trail = request.GET.get('t', None)

        c.form = ReleaseMsgForm(request.POST, csrf_context=session)
        if request.POST and c.form.validate():
            job = dict(release=c.form.release.data,
                        learn=c.form.learn.data, 
                        salearn_as=c.form.learnas.data,
                        todelete=c.form.delete.data,
                        use_alt=c.form.usealt.data,
                        altrecipients=c.form.altrecipients.data,
                        message_id=message.messageid,
                        from_address=message.from_address,
                        date=str(message.date),
                        to_address=message.to_address,
                        hostname=message.hostname,
                        mid=message.id)
            try:
                task = process_quarantined_msg.apply_async(
                        args=[job], queue=message.hostname)
                task.wait(30)
                if task.status == 'SUCCESS':
                    # process response
                    html = process_release_results(
                            c, message, task.result,
                            Session)
                    self.invalidate = 1
                    message = self._get_msg(id, archive)
                    flash(html)
                else:
                    html = _('Processing the request failed')
                    flash_alert(html)
            except (TimeoutError, QueueNotFound):
                html = _('Processing the request failed')
                flash_alert(html)
            if format == 'json':
                flash.pop_messages()
                response.headers['Content-Type'] = 'application/json'
                return json.dumps(dict(result=html))
        elif request.POST and not c.form.validate():
            flash_alert(_(', '.join([c.form.errors[err][0]
                                for err in c.form.errors])))
            if format == 'json':
                html = flash.pop_messages()
                response.headers['Content-Type'] = 'application/json'
                return json.dumps(dict(result=html))

        if format == 'json':
            response.headers['Content-Type'] = 'application/json'
            return json.dumps(message.tojson)
        c.msg = message
        c.archived = archive
        c.show_trail = show_trail
        c.msgstatus = msgstatus
        return render('/messages/detail.html')
Esempio n. 14
0
    def detail(self, msgid, archive=None, format=None):
        "return message detail"
        message = self._get_msg(msgid, archive)
        if not message:
            abort(404)

        msgstatus = Session.query(MessageStatus)\
                    .filter(MessageStatus.messageid == message.messageid)\
                    .all()
        show_trail = request.GET.get('t', None)

        c.form = ReleaseMsgForm(request.POST, csrf_context=session)
        if request.method == 'POST' and c.form.validate():
            localtmz = config.get('baruwa.timezone', 'Africa/Johannesburg')
            job = dict(release=c.form.release.data,
                       learn=c.form.learn.data,
                       salearn_as=c.form.learnas.data,
                       todelete=c.form.delete.data,
                       use_alt=c.form.usealt.data,
                       altrecipients=c.form.altrecipients.data,
                       message_id=message.messageid,
                       from_address=message.from_address,
                       date=convert_date(message.timestamp,
                                         localtmz).strftime('%Y%m%d'),
                       msgfiles=message.msgfiles,
                       to_address=message.to_address,
                       hostname=message.hostname,
                       mid=message.id,
                       issingle=True)
            try:
                task = process_quarantined_msg.apply_async(
                    args=[job],
                    routing_key=system_hostname() if asbool(
                        config.get('ms.quarantine.shared',
                                   'false')) else message.hostname)
                task.wait(30)
                if task.status == 'SUCCESS':
                    # process response
                    html = process_release_results(c, message, task.result,
                                                   Session, self.render)
                    self.invalidate = 1
                    message = self._get_msg(msgid, archive)
                    flash(html)
                else:
                    html = _('Processing the request failed')
                    flash_alert(html)
                    log.info(html)
            except (TimeoutError, QueueNotFound):
                html = _('Processing the request failed')
                flash_alert(html)
                log.info(html)
            if format == 'json':
                flash.pop_messages()
                response.headers['Content-Type'] = 'application/json'
                return json.dumps(dict(result=html))
        elif request.method == 'POST' and not c.form.validate():
            flash_alert(
                _(u', '.join([
                    unicode(c.form.errors[err][0]) for err in c.form.errors
                ])))
            if format == 'json':
                html = flash.pop_messages()
                response.headers['Content-Type'] = 'application/json'
                return json.dumps(dict(result=unicode(html[0])))

        if format == 'json':
            response.headers['Content-Type'] = 'application/json'
            return json.dumps(message.tojson)
        c.msg = message
        c.archived = archive
        c.show_trail = show_trail
        c.msgstatus = msgstatus
        return self.render('/messages/detail.html')