Пример #1
0
def sendtestmailmanagers(request,*args,**kwargs):
    try:
        mail_managers(_(u'testsubject'), _(u'test content of report'))
    except Exception,e:
        txt = as2utils.txtexc()
        messages.add_message(request, messages.INFO, _(u'Sending test mail failed.'))
        pyas2init.logger.info(_(u'Sending test mail failed, error:\n%(txt)s'), {'txt':txt})
        return redirect(reverse('home'))
Пример #2
0
 def handle(self, *args, **options):
     if len(args) != 3:
         raise CommandError(
             _(u'Insufficient number of arguments specified, please check help for correct usage'
               ))
     try:
         org = models.Organization.objects.get(as2_name=args[0])
     except models.Organization.DoesNotExist:
         raise CommandError(_(u'Organization "%s" does not exist' %
                              args[0]))
     try:
         partner = models.Partner.objects.get(as2_name=args[1])
     except models.Partner.DoesNotExist:
         raise CommandError(_(u'Partner "%s" does not exist' % args[1]))
     if not os.path.isfile(args[2]):
         raise CommandError(
             _(u'Payload at location "%s" does not exist' % args[2]))
     if options['delete'] and not os.access(args[2], os.W_OK):
         raise CommandError('Insufficient file permission for payload %s' %
                            args[2])
     outdir = as2utils.join(pyas2init.gsettings['payload_send_store'],
                            time.strftime('%Y%m%d'))
     as2utils.dirshouldbethere(outdir)
     outfile = as2utils.join(outdir, os.path.basename(args[2]))
     shutil.copy2(args[2], outfile)
     if options['delete']:
         os.remove(args[2])
     payload = models.Payload.objects.create(
         name=os.path.basename(args[2]),
         file=outfile,
         content_type=partner.content_type)
     message = models.Message.objects.create(
         message_id=email.utils.make_msgid().strip('<>'),
         partner=partner,
         organization=org,
         direction='OUT',
         status='IP',
         payload=payload)
     try:
         payload = as2lib.build_message(message)
         as2lib.send_message(message, payload)
     except Exception, e:
         txt = as2utils.txtexc()
         reporttxt = _(u'Failed to send message, error:\n%(txt)s') % {
             'txt': txt
         }
         pyas2init.logger.error(reporttxt)
         message.status = 'E'
         models.Log.objects.create(
             message=message,
             status='E',
             text=_(u'Failed to send message, error is %s' % e))
         message.save()
         ### Send mail here
         as2utils.senderrorreport(
             message, _(u'Failed to send message, error is %s' % e))
         sys.exit(2)
Пример #3
0
 def handle(self, *args, **options):
     if len(args) != 3:
         raise CommandError(
             _(u'Insufficient number of arguments specified, please check help for correct usage'
               ))
     try:
         org = models.Organization.objects.get(as2_name=args[0])
     except models.Organization.DoesNotExist:
         raise CommandError(
             _(u'Organization "%s" does not exist' % args[0]))
     try:
         partner = models.Partner.objects.get(as2_name=args[1])
     except models.Partner.DoesNotExist:
         raise CommandError(_(u'Partner "%s" does not exist' % args[1]))
     if not os.path.isfile(args[2]):
         raise CommandError(
             _(u'Payload at location "%s" does not exist' % args[2]))
     if options['delete'] and not os.access(args[2], os.W_OK):
         raise CommandError(
             'Insufficient file permission for payload %s' % args[2])
     outdir = as2utils.join(pyas2init.gsettings['payload_send_store'],
                            time.strftime('%Y%m%d'))
     as2utils.dirshouldbethere(outdir)
     outfile = as2utils.join(outdir, os.path.basename(args[2]))
     shutil.copy2(args[2], outfile)
     if options['delete']:
         os.remove(args[2])
     payload = models.Payload.objects.create(
         name=os.path.basename(args[2]),
         file=outfile,
         content_type=partner.content_type)
     message = models.Message.objects.create(
         message_id=email.utils.make_msgid().strip('<>'),
         partner=partner,
         organization=org,
         direction='OUT',
         status='IP',
         payload=payload)
     try:
         payload = as2lib.build_message(message)
         as2lib.send_message(message, payload)
     except Exception, e:
         txt = as2utils.txtexc()
         reporttxt = _(u'Failed to send message, error:\n%(txt)s') % {
             'txt': txt
         }
         pyas2init.logger.error(reporttxt)
         message.status = 'E'
         models.Log.objects.create(
             message=message,
             status='E',
             text=_(u'Failed to send message, error is %s' % e))
         message.save()
         ### Send mail here
         as2utils.senderrorreport(
             message, _(u'Failed to send message, error is %s' % e))
         sys.exit(2)
Пример #4
0
def send_test_mail_managers(request, *args, **kwargs):
    """ Send a test email, used to confirm email settings"""
    try:
        mail_managers(_(u'testsubject'), _(u'test content of report'))
    except Exception:
        txt = as2utils.txtexc()
        messages.add_message(request, messages.INFO, _(u'Sending test mail failed.'))
        pyas2init.logger.info(_(u'Sending test mail failed, error:\n%(txt)s'), {'txt': txt})
        return redirect(reverse('home'))
    notification = _(u'Sending test mail succeeded.')
    messages.add_message(request, messages.INFO, notification)
    pyas2init.logger.info(notification)
    return redirect(reverse('home'))
Пример #5
0
def send_test_mail_managers(request, *args, **kwargs):
    """ Send a test email, used to confirm email settings"""
    try:
        mail_managers(_(u'testsubject'), _(u'test content of report'))
    except Exception:
        txt = as2utils.txtexc()
        messages.add_message(request, messages.INFO, _(u'Sending test mail failed.'))
        pyas2init.logger.info(_(u'Sending test mail failed, error:\n%(txt)s'), {'txt': txt})
        return redirect(reverse('home'))
    notification = _(u'Sending test mail succeeded.')
    messages.add_message(request, messages.INFO, notification)
    pyas2init.logger.info(notification)
    return redirect(reverse('home'))
Пример #6
0
             as2lib.run_postreceive(message,fullfilename)
             message.save()
         except as2utils.as2duplicatedocument,e:
             status, adv_status, status_message = 'warning', 'duplicate-document', _(u'An error occured during the AS2 message processing: %s'%e)
         except as2utils.as2partnernotfound,e:
             status, adv_status, status_message = 'error', 'unknown-trading-partner', _(u'An error occured during the AS2 message processing: %s'%e)
         except as2utils.as2insufficientsecurity,e:
             status, adv_status, status_message = 'error', 'insufficient-message-security', _(u'An error occured during the AS2 message processing: %s'%e) 
         except as2utils.as2decryptionfailed,e:
             status, adv_status, status_message = 'error', 'decryption-failed', _(u'An error occured during the AS2 message processing: %s'%e)
         except as2utils.as2decompressionfailed,e:
             status, adv_status, status_message = 'error', 'decompression-failed', _(u'An error occured during the AS2 message processing: %s'%e)
         except as2utils.as2invalidsignature,e:
             status, adv_status, status_message = 'error', 'integrity-check-failed', _(u'An error occured during the AS2 message processing: %s'%e)
         except Exception,e:
             txt = as2utils.txtexc()
             pyas2init.logger.error(_(u'Unexpected error while processing message %(msg)s, error:\n%(txt)s'), {'txt':txt,'msg':message.message_id})
             status, adv_status, status_message = 'error', 'unexpected-processing-error', 'An error occured during the AS2 message processing: %s'%e
         finally:
             mdnbody, mdnmessage = as2lib.build_mdn(message, status, adv_status=adv_status, status_message=status_message)
             if mdnbody:
                 mdnresponse = HttpResponse(mdnbody, content_type=mdnmessage.get_content_type())
                 for key,value in mdnmessage.items():
                     mdnresponse[key] = value
                 return mdnresponse
             else:
                 return HttpResponse(_(u'AS2 message has been received'))
 except Exception,e:
     txt = as2utils.txtexc()
     reporttxt = _(u'Fatal error while processing message %(msg)s, error:\n%(txt)s')%{'txt':txt,'msg':request.META.get('HTTP_MESSAGE_ID').strip('<>')}
     pyas2init.logger.error(reporttxt)
Пример #7
0
    def handle(self, *args, **options):
        # Check if organization and partner exists
        try:
            org = models.Organization.objects.get(
                as2_name=options['organization_as2name'])
        except models.Organization.DoesNotExist:
            raise CommandError(
                _(u'Organization "%s" does not exist' %
                  options['organization_as2name']))
        try:
            partner = models.Partner.objects.get(
                as2_name=options['partner_as2name'])
        except models.Partner.DoesNotExist:
            raise CommandError(
                _(u'Partner "%s" does not exist' % options['partner_as2name']))

        # Check if file exists and we have the right permissions
        if not os.path.isfile(options['path_to_payload']):
            raise CommandError(
                _(u'Payload at location "%s" does not exist' %
                  options['path_to_payload']))
        if options['delete'] and not os.access(options['path_to_payload'],
                                               os.W_OK):
            raise CommandError('Insufficient file permission for payload %s' %
                               options['path_to_payload'])

        # Copy the file to the store
        output_dir = as2utils.join(pyas2init.gsettings['payload_send_store'],
                                   time.strftime('%Y%m%d'))
        as2utils.dirshouldbethere(output_dir)
        outfile = as2utils.join(output_dir,
                                os.path.basename(options['path_to_payload']))
        shutil.copy2(options['path_to_payload'], outfile)

        # Delete original file if option is set
        if options['delete']:
            os.remove(options['path_to_payload'])

        # Create the payload and message objects
        payload = models.Payload.objects.create(
            name=os.path.basename(options['path_to_payload']),
            file=outfile,
            content_type=partner.content_type)
        message = models.Message.objects.create(
            message_id=email.utils.make_msgid().strip('<>'),
            partner=partner,
            organization=org,
            direction='OUT',
            status='IP',
            payload=payload)

        # Build and send the AS2 message
        try:
            payload = as2lib.build_message(message)
            as2lib.send_message(message, payload)
        except Exception, e:
            pyas2init.logger.error(
                _(u'Failed to send message, error:\n%(txt)s') %
                {'txt': as2utils.txtexc()})
            message.status = 'E'
            models.Log.objects.create(
                message=message,
                status='E',
                text=_(u'Failed to send message, error is %s' % e))
            message.save()

            # Send mail here
            as2utils.senderrorreport(
                message, _(u'Failed to send message, error is %s' % e))
            sys.exit(2)