Example #1
0
 def render_POST(self, request):
     global _Outbox
     idurl = request.getHeader('idurl')
     if idurl is None:
         return ''
     dhnio.Dprint(14, 'transport_http.SenderServer.render connection from ' + idurl)
     if not idurl in _Outbox.keys():
         return ''
     r = ''
     for filename in _Outbox[idurl]:
         if not os.path.isfile(filename):
             continue
         if not os.access(filename, os.R_OK):
             continue
         src = dhnio.ReadBinaryFile(filename)
         if src == '':
             continue
         src64 = base64.b64encode(src)
         r += src64 + '\n'
         dhnio.Dprint(12, 'transport_http.SenderServer.render sent %s to %s' % (filename, idurl))
         #TODO request.getPeer()
         transport_control.sendStatusReport(
             request.getClient(),
             filename,
             'finished',
             'http',)
     _Outbox.pop(idurl, None)
     return r
Example #2
0
 def render_POST(self, request):
     global _Outbox
     idurl = request.getHeader('idurl')
     if idurl is None:
         return ''
     lg.out(14, 'http_node.SenderServer.render connection from ' + idurl)
     if not idurl in _Outbox.keys():
         return ''
     r = ''
     for filename in _Outbox[idurl]:
         if not os.path.isfile(filename):
             continue
         if not os.access(filename, os.R_OK):
             continue
         src = dhnio.ReadBinaryFile(filename)
         if src == '':
             continue
         src64 = base64.b64encode(src)
         r += src64 + '\n'
         lg.out(
             12, 'http_node.SenderServer.render sent %s to %s' %
             (filename, idurl))
         #TODO request.getPeer()
         transport_control.sendStatusReport(
             request.getClient(),
             filename,
             'finished',
             'http',
         )
     _Outbox.pop(idurl, None)
     return r
    def sendNextPart(self):
        dhnio.Dprint(14, 'transport_ssh.MyFileTransferClient.sendNextPart')
        self.buf = ''
        try:
            self.buf = self.fin.read(self.BUFFER_SIZE)
            self.fin.flush()
        except:
            dhnio.Dprint(1, 'transport_ssh.MyFileTransferClient ERROR reading buffer data from file')
            self.breakTransfer()
            self.connectionLost(0)
            return

##        if len(self.buf) == 0:
##            self.finishTransfer()
##            self.connectionLost(1)
##            return
##
        try:
            self.transport.write(self.buf)
        except:
            dhnio.Dprint(1, 'transport_ssh.MyFileTransferClient.sendNextPart NETERROR writing data to the transport')
##            transport_control.connectionStatusCallback('ssh', self.transport.getPeer(), None, 'error writing data to the transport')
            transport_control.sendStatusReport(self.transport.getPeer(),
                self.filename,
                'failed', 'ssh', None,
                'error writing data to the transport' )
            self.breakTransfer()
            self.connectionLost(0)
            return
        self.total_sent += len(self.buf)
        dhnio.Dprint(14, 'transport_ssh.MyFileTransferClient.sendNextPart total %s bytes sent' % str(self.total_sent))
Example #4
0
    def clientConnectionFailed(self, connector, reason):
##        dhnio.Dprint(1,'transport_ssh.SendingFactory.clientConnectionFailed NETERROR with %s : %s' % (str(connector.getDestination()) ,str(reason.getErrorMessage())))
        direct.SSHClientFactory.clientConnectionFailed(self, connector, reason)
##        transport_control.connectionStatusCallback('ssh', connector.getDestination(), reason, 'connection failed' )
        transport_control.sendStatusReport(connector.getDestination(),
            self.userAuthObject.instance.filename,
            'failed', 'ssh', reason, 'connection failed' )
Example #5
0
    def ok(x):
        dhnio.Dprint(14, 'transport_email.send_public.ok: sending done')
##        if misc.transport_control_using():
        transport_control.sendStatusReport(email, filename,
            'finished', 'email')  # only one outstanding send per host
        transport_control.log('email', 'message successful sent')
        poll().send()
        if reactor_stop:
            reactor.stop()
Example #6
0
    def fail(x):
        dhnio.Dprint(1, 'transport_email.send_public.fail NETERROR sending email \n' + str(x.getErrorMessage()))
##        transport_control.msg('e', 'error sending email: ' + str(x.getErrorMessage()))
##        transport_control.connectionStatusCallback('email', smtp_info[0], x, 'error sending email')
        transport_control.sendStatusReport(email, filename,
            'failed', 'email',
            x, 'error sending email')
        transport_control.log('email', 'NETERROR sending email')
        if reactor_stop:
            reactor.stop()
Example #7
0
def send(idurl, filename):
    dhnio.Dprint(12, 'transport_http.send to %s %s' % (idurl, filename))
    global _Outbox
    if not _Outbox.has_key(idurl):
        _Outbox[idurl] = []
    _Outbox[idurl].append(filename)
    #we want to keep only 10 last files.
    if len(_Outbox[idurl]) > 10:
        lostedfilename = _Outbox[idurl].pop(0)
        transport_control.sendStatusReport(
            'unknown',
            lostedfilename,
            'failed',
            'http',)
def send(idurl, filename):
    lg.out(12, 'http_node.send to %s %s' % (idurl, filename))
    global _Outbox
    if idurl not in _Outbox:
        _Outbox[idurl] = []
    _Outbox[idurl].append(filename)
    #we want to keep only 10 last files.
    if len(_Outbox[idurl]) > 10:
        lostedfilename = _Outbox[idurl].pop(0)
        transport_control.sendStatusReport(
            'unknown',
            lostedfilename,
            'failed',
            'http',)
Example #9
0
def SendStatusCallbackDefault(host, filename, status, proto='', error=None, message=''):
    try:
        from transport_control import sendStatusReport
        return sendStatusReport(host, filename, status, proto, error, message)
    except:
        dhnio.DprintException()
        return None
    def dataReceived(self, data):
        dhnio.Dprint(14, 'transport_ssh.MyFileTransferClient.dataReceived: '+str(data))
        try:
            amount = int(data)
        except:
            dhnio.Dprint(1, 'transport_ssh.MyFileTransferClient.dataReceived NETERROR bad response from the ssh server')
##            transport_control.connectionStatusCallback('ssh', self.transport.getPeer(), None, 'bad response from the ssh server')
            transport_control.sendStatusReport(self.transport.getPeer(),
                self.filename,
                'failed', 'ssh',
                None, 'bad response from the ssh server')
            self.breakTransfer()
            self.connectionLost(0)
            return

        if amount < self.total_size:
            self.sendNextPart()
        else:
            self.finishTransfer()
            self.connectionLost(1)
Example #11
0
    def done(x, filename, c):
        dhnio.Dprint(14, 'transport_ssh.send.done')
##        if misc.transport_control_using():
        transport_control.sendStatusReport(host+':'+port, filename,
            'finished', 'ssh')
        c.transport.loseConnection()
Example #12
0
    def connection_fail(x, filename, c):
        dhnio.Dprint(14, 'transport_ssh.send.connection_fail ')
##        if misc.transport_control_using():
        transport_control.sendStatusReport(host+':'+port, filename,
            'failed', 'ssh',
            x, 'connection failed')      # not so good
Example #13
0
def sent_status_func(toUser, filename, status, reason):
    transport_control.sendStatusReport(toUser, filename, status, 'q2q', reason)
Example #14
0
def send(filename, email, subject = 'datahaven_transport', reactor_stop=False, use_smtplib=False):
    transport_control.log('email', 'start sending to ' + email)
    smtp_info = [
            settings.getEmailAddress(),   #0
            settings.getSMTPHost(),       #1
            settings.getSMTPPort(),       #2
            settings.getSMTPUser(),       #3
            settings.getSMTPPass(),       #4
            settings.getSMTPSSL(),        #5
            settings.getSMTPNeedLogin()]  #6

    if smtp_info[0].strip() == '' or smtp_info[1].strip() == '':
        dhnio.Dprint(1, 'transport_email.send empty mailbox info. check your email options')
##        transport_control.msg('e', 'empty mailbox info. check your email options')
##        transport_control.connectionStatusCallback('email', email, None, 'empty mailbox info. check your email options')
        transport_control.sendStatusReport(email, filename,
            'failed', 'email',
            None, 'empty mailbox info. check your email options')
        return

##    print smtp_info
##    smtp_info = smtp3_info
    if not os.path.isfile(filename):
        dhnio.Dprint(1, 'transport_email.send wrong file name: %s' % filename)
##        transport_control.msg('e', 'wrong file name %s' % filename)
        return
    from_address = smtp_info[0]
    dhnio.Dprint(8, 'transport_email.send  from:%s to:%s' % (from_address, email))

    if use_smtplib:
        #send via smtplib
        try:
            send_smtplib(
                smtp_info[1],
                smtp_info[3],
                smtp_info[4],
                smtp_info[5],
                from_address,
                email,
                subject,
                filename)
        except:
            dhnio.Dprint(1, 'transport_email.send NETERROR sending email ' + dhnio.formatExceptionInfo())
##            transport_control.msg('e', 'Error sending email')
            transport_control.log('email', 'error sending email')
##            transport_control.connectionStatusCallback('email', email, None, 'error sending email')
            transport_control.sendStatusReport(email, filename,
                'failed', 'email',
                None, 'error sending email')
            return
##        if misc.transport_control_using():
        transport_control.sendStatusReport(email, filename,
            'finished', 'email')  # only one outstanding send per host
        transport_control.log('email', 'done')
        poll().send()
    else:
        #Send via Twisted
        def ok(x):
            dhnio.Dprint(14, 'transport_email.send.ok: sending done')
##            if misc.transport_control_using():
            # only one outstanding send per host
            transport_control.sendStatusReport(email, filename,
                'finished', 'email')
            transport_control.log('email', 'message successful sent')
            poll().send()
            if reactor_stop:
                reactor.stop()
        def fail(x):
##            if misc.transport_control_using():
            dhnio.Dprint(1, 'transport_email.send.fail NETERROR sending email \n' + str(x.getErrorMessage()))
##            transport_control.msg('e', 'error sending email: '  + str(x.getErrorMessage()) )
##            transport_control.connectionStatusCallback('email', smtp_info[0], x, 'error sending email')
            transport_control.sendStatusReport(email, filename,
                'failed', 'email',
                x, 'error sending email')
            transport_control.log('email', 'error sending email'  + str(x.getErrorMessage()))
            if reactor_stop:
                reactor.stop()

        if smtp_info[6]:
            #1th method
            res = sendTwistedMailAuth(
                smtp_info[1],
                smtp_info[2],
                smtp_info[3],
                smtp_info[4],
                smtp_info[5],
                smtp_info[6],
                from_address,
                email,
                subject,
                filename)
        else:
            #2th method:
            res = sendTwistedMail(
                smtp_info[1],
                smtp_info[0],
                email,
                subject,
                filename,
                smtp_info[2])
        res.addCallback(ok)
        res.addErrback(fail)
        return res
Example #15
0
def send_smtplib(host, login, password, ssl_flag, addr, to, subject, filename):
    dhnio.Dprint(14, 'transport_email.send_smtplib to: ' + str(to))

    fin = file(filename, 'rb')
    bin_data = fin.read()
    fin.close()



    msg = email.MIMEMultipart.MIMEMultipart()
    msg["Subject"] = subject
    msg["From"]    = addr
    msg["To"]      = to
    part = email.MIMEBase.MIMEBase('application', "octet-stream")
    part.set_payload( bin_data+'end' )
    email.Encoders.encode_base64(part)
    part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))
    msg.attach(part)

    try:
        server = smtplib.SMTP(host)
    except:
##        transport_control.msg('e', 'could not conect to smtp server')
##        transport_control.connectionStatusCallback('email', to, None, 'could not conect to smtp server')
        transport_control.sendStatusReport(to, filename,
        'failed', 'email',
        None, 'could not conect to smtp server')
        return

    if dhnio.DebugLevel > 14:
        server.set_debuglevel(1)
    dhnio.Dprint(14, 'transport_email.send_smtplib: SSL FLAG:'+str(ssl))
    if ssl_flag:
        try:
            dhnio.Dprint(14, 'transport_email.send_smtplib ehlo')
            server.ehlo()
            dhnio.Dprint(14, 'transport_email.send_smtplib starttls')
            server.starttls()
            dhnio.Dprint(14, 'transport_email.send_smtplib ehlo')
            server.ehlo()
        except:
            dhnio.Dprint(14, 'transport_email.send_smtplib: No support ssl')
##            transport_control.connectionStatusCallback('email', to, None, 'server did not support ssl' )
            transport_control.sendStatusReport(to, filename,
            'failed', 'email',
            None, 'server did not support ssl')
##            transport_control.msg('e', 'server did not support ssl')

    try:
        dhnio.Dprint(14, 'transport_email.send_smtplib login')
        server.login(login, password)
    except:
        dhnio.Dprint(14, 'transport_email.send_smtplib: Not need to login')

    try:
        dhnio.Dprint(14, 'transport_email.send_smtplib: sendmail')
        server.sendmail(addr, [to], msg.as_string())
        dhnio.Dprint(14, 'transport_email.send_smtplib: close')
        server.close()
        dhnio.Dprint(14, 'transport_email.send_smtplib: done')
    except:
##        transport_control.connectionStatusCallback('email', to, None, 'unknown error during sending message')
        transport_control.sendStatusReport(to, filename,
        'failed', 'email',
        None, 'unknown error during sending message')