Exemple #1
0
def gtpswd(prompt, confirmPassword):
    """
    Temporary wrapper for Twisted's getPassword until a version that supports
    customizing the 'confirm' prompt is released.
    """
    try:
        return util.getPassword(prompt=prompt,
                                confirmPrompt=confirmPassword,
                                confirm=True)
    except TypeError:
        return util.getPassword(prompt=prompt, confirm=True)
Exemple #2
0
def gtpswd(prompt, confirmPassword):
    """
    Temporary wrapper for Twisted's getPassword until a version that supports
    customizing the 'confirm' prompt is released.
    """
    try:
        return util.getPassword(prompt=prompt,
                                confirmPrompt=confirmPassword,
                                confirm=True)
    except TypeError:
        return util.getPassword(prompt=prompt,
                                confirm=True)
Exemple #3
0
def main():
    hostname = raw_input('IMAP4 Server Hostname: ')
    port = raw_input('IMAP4 Server Port (the default is 143, 993 uses SSL): ')
    username = raw_input('IMAP4 Username: '******'IMAP4 Password: '******'utf-8'))
        endpoint = endpoints.wrapClientTLS(contextFactory, endpoint)

    endpoint.connect(factory)
    reactor.run()
Exemple #4
0
def main():
    hostname = raw_input("IMAP4 Server Hostname: ")
    port = raw_input("IMAP4 Server Port (the default is 143, 993 uses SSL): ")

    # Usernames are bytes.
    username = raw_input("IMAP4 Username: "******"ascii")

    # Passwords are bytes.
    password = util.getPassword("IMAP4 Password: "******"ascii")

    onConn = (defer.Deferred().addCallback(
        cbServerGreeting, username,
        password).addErrback(ebConnection).addBoth(cbClose))

    factory = SimpleIMAP4ClientFactory(username, onConn)

    if not port:
        port = 143
    else:
        port = int(port)

    from twisted.internet import reactor

    endpoint = endpoints.HostnameEndpoint(reactor, hostname, port)

    if port == 993:
        if isinstance(hostname, bytes):
            # This is python 2
            hostname = hostname.decode("utf-8")

        contextFactory = ssl.optionsForClientTLS(hostname=hostname, )
        endpoint = endpoints.wrapClientTLS(contextFactory, endpoint)

    endpoint.connect(factory)
    reactor.run()
Exemple #5
0
def savePersisted(app, filename, encrypted):
    if encrypted:
        try:
            import Crypto
            app.save(filename=filename, passphrase=util.getPassword("Encryption passphrase: "))
        except ImportError:
            print "The --encrypt flag requires the PyCrypto module, no file written."
    else:
        app.save(filename=filename)
Exemple #6
0
 def opt_password(self, password):
     """Required.  '-' will prompt or read a password from stdin.
     """
     # If standard input is a terminal, I prompt for a password and
     # confirm it.  Otherwise, I use the first line from standard
     # input, stripping off a trailing newline if there is one.
     if password in ('', '-'):
         self['password'] = util.getPassword(confirm=1)
     else:
         self['password'] = password
Exemple #7
0
 def opt_password(self, password):
     """Required.  '-' will prompt or read a password from stdin.
     """
     # If standard input is a terminal, I prompt for a password and
     # confirm it.  Otherwise, I use the first line from standard
     # input, stripping off a trailing newline if there is one.
     if password in ('', '-'):
         self['password'] = util.getPassword(confirm=1)
     else:
         self['password'] = password
Exemple #8
0
def main():
    hostname = raw_input('IMAP4 Server Hostname: ')
    username = raw_input('IMAP4 Username: '******'IMAP4 Password: ')

    onConn = defer.Deferred().addCallback(cbServerGreeting, username,
                                          password).addErrback(ebConnection)

    factory = SimpleIMAP4ClientFactory(username, onConn)

    from twisted.internet import reactor
    conn = reactor.connectTCP(hostname, PORT, factory)
    reactor.run()
Exemple #9
0
def main():
    hostname = raw_input("IMAP4 Server Hostname: ")
    username = raw_input("IMAP4 Username: "******"IMAP4 Password: ")

    onConn = defer.Deferred().addCallback(cbServerGreeting, username, password).addErrback(ebConnection)

    factory = SimpleIMAP4ClientFactory(username, onConn)

    from twisted.internet import reactor

    # conn = reactor.connectTCP(hostname, PORT, factory)
    conn = reactor.connectSSL(hostname, PORT, factory, ssl.ClientContextFactory())
    reactor.run()
Exemple #10
0
    def getPassword(self, prompt=None):
        if self._fd is not None:
            # go to cbreak mode, where interrupts are handled
            tty.setcbreak(self._fd)
            # reset terminal, so that we can actually get the newline that
            # terminates entering the password
            termios.tcsetattr(self._fd, termios.TCSANOW, self._oldSettings)

        from twisted.python import util
        password = util.getPassword(prompt=prompt)

        if self._fd is not None:
            self.setraw()

        return password
Exemple #11
0
    def getPassword(self, prompt=None):
        if self._fd is not None:
            # go to cbreak mode, where interrupts are handled
            tty.setcbreak(self._fd)
            # reset terminal, so that we can actually get the newline that
            # terminates entering the password
            termios.tcsetattr(self._fd, termios.TCSANOW, self._oldSettings)

        from twisted.python import util
        password = util.getPassword(prompt=prompt)

        if self._fd is not None:
            self.setraw()

        return password
Exemple #12
0
def main():
    hostname = raw_input('IMAP4 Server Hostname: ')
    port = raw_input('IMAP4 Server Port (the default is 143): ')
    username = raw_input('IMAP4 Username: '******'IMAP4 Password: ')

    onConn = defer.Deferred(
    ).addCallback(cbServerGreeting, username, password
                  ).addErrback(ebConnection
                               ).addBoth(cbClose)

    factory = SimpleIMAP4ClientFactory(username, onConn)

    from twisted.internet import reactor
    conn = reactor.connectTCP(hostname, int(port), factory)
    reactor.run()
Exemple #13
0
def main():
    if "--eventlib" in sys.argv[1:]:
        from xcaplib.green import XCAPClient as client_class
    else:
        client_class = XCAPClient
    if OPT_COMPLETE in sys.argv[-2:]:
        return run_completion(OPT_COMPLETE)
    elif '--debug-completions' in sys.argv[-2:]:
        global logfile
        logfile = sys.stderr
        return run_completion('--debug-completions', raise_ex=True)

    options, action, node_selector = parse_args()
    #if options.dump:
    #    logsocket._install()
    client = make_xcapclient(options, XCAPClient=client_class)
    url = client.get_url(options.app,
                         node_selector,
                         globaltree=options.globaltree,
                         filename=options.filename)
    sys.stderr.write('%s %s\n' % (action, url))

    try:
        result = client_request(client, action, options, node_selector)
    except (urllib.error.URLError, HTTPException, TimeoutError) as ex:
        sys.exit('FATAL: %s: %s' % (type(ex).__name__, ex))
    if result.status == 401 and not options.password and interactive():
        authreq = result.headers.get('www-authenticate')
        if authreq:
            mo = urllib.request.AbstractBasicAuthHandler.rx.search(authreq)
            if mo:
                realm = mo.groups()[-1]
                #sys.stderr.write('Server requested authentication, but no password was provided.\n')
                options.password = getPassword('Password (realm=%s): ' % realm)
                client = make_xcapclient(options, XCAPClient=client_class)
                result = client_request(client, action, options, node_selector)
    if not (result.status == 200 and action == 'get'):
        sys.stderr.write('%s %s\n' % (result.status, result.reason))
    write_etag(result.headers.get('etag'))
    if result.headers.get('content-type'):
        write_content_type(result.headers['content-type'])
    if result.body:
        write_content_length(
            len(result.body
                ))  # print content-length header instead, otherwise confusing
        write_body(options, result.body.encode())
    sys.exit(get_exit_code(result.status))
def main():
    hostname = raw_input('POP3 Server Hostname: ')
    port = raw_input('POP3 port: ')
    username = raw_input('POP3 Username: '******'POP3 Password: '******'use SSL (Yes/No): ')

    onConn = defer.Deferred(
        ).addCallback(cbServerGreeting, username, password
        ).addErrback(ebConnection
        )

    factory = SimplePOP3ClientFactory(username, onConn)

    if useSSL.lower() == "yes":
        conn = reactor.connectSSL(hostname, int(port), factory, ClientTLSContext())
    else:
        conn = reactor.connectTCP(hostname, int(port), factory)

    reactor.run()
Exemple #15
0
def main():
    hostname = raw_input('IMAP4 Server Hostname: ')
    port = raw_input('IMAP4 Server Port (the default is 143, 993 uses SSL): ')
    username = raw_input('IMAP4 Username: '******'IMAP4 Password: '******'993':
        reactor.connectSSL(hostname, int(port), factory, ssl.ClientContextFactory())
    else:
        if not port:
            port = 143
        reactor.connectTCP(hostname, int(port), factory)
    reactor.run()
Exemple #16
0
def main():
    hostname = raw_input('IMAP4 Server Hostname: ')
    port = raw_input('IMAP4 Server Port (the default is 143, 993 uses SSL): ')
    username = raw_input('IMAP4 Username: '******'IMAP4 Password: '******'993':
        reactor.connectSSL(hostname, int(port), factory,
                           ssl.ClientContextFactory())
    else:
        if not port:
            port = 143
        reactor.connectTCP(hostname, int(port), factory)
    reactor.run()
Exemple #17
0
def getSavePassphrase(needed):
    if needed:
        passphrase = util.getPassword("Encryption passphrase: ")
    else:
        return None
Exemple #18
0
def reversePassword():
    password = util.getPassword()
    return reverseString(password)
Exemple #19
0
def getSavePassphrase(needed):
    if needed:
        passphrase = util.getPassword("Encryption passphrase: ")
    else:
        return None
Exemple #20
0
# bring in our stuff
from AriGmailSmtp import *
from twistedIO import *

# change the verbosity
setVerbosity(vtype.kDebugData)
#setVerbosity(vtype.kInfo)


# parameters
mailhost = "imap.gmail.com"
mailport = 993
mailuser = "******"
mailfrom = "*****@*****.**"
mailpass = util.getPassword('Password for {0}@{1}: '
                            .format(mailuser,mailhost))
smtpuser = "******"
#smtpuser = "******"
smtppass = util.getPassword('Password for {0}@{1}: '
                            .format(smtpuser,smtphost))
mailCheckPeriod = 30 # seconds. if 0, don't repeat; just check once
reconnectPeriod = -1 # seconds. if 0, don't repeat; just once
                     #          if < 0, never intentionally logout
maxReconnDelay  = 1800 # seconds. max time between reconnect attempts
rawoutdir = "SBDmail"

# constants
LINEBREAK = '\r\n'
SBDMAXLEN = 270 - ROOT.TSnIOHeaderFrame.kMaxSizeOf

# station to talk to
    client = make_xcapclient(options, XCAPClient=client_class)
    url = client.get_url(options.app, node_selector, globaltree=options.globaltree, filename=options.filename)
    sys.stderr.write('%s %s\n' % (action, url))

    try:
        result = client_request(client, action, options, node_selector)
    except (urllib2.URLError, HTTPException), ex:
        sys.exit('FATAL: %s: %s' % (type(ex).__name__, ex))
    if result.status==401 and not options.password and interactive():
        authreq = result.headers.get('www-authenticate')
        if authreq:
            mo = urllib2.AbstractBasicAuthHandler.rx.search(authreq)
            if mo:
                realm = mo.groups()[-1]
                #sys.stderr.write('Server requested authentication, but no password was provided.\n')
                options.password = getPassword('Password (realm=%s): ' % realm)
                client = make_xcapclient(options, XCAPClient=client_class)
                result = client_request(client, action, options, node_selector)
    if not (result.status==200 and action=='get'):
        sys.stderr.write('%s %s\n' % (result.status, result.reason))
    write_etag(result.headers.get('etag'))
    if result.headers.get('content-type'):
        write_content_type(result.headers['content-type'])
    if result.body:
        write_content_length(len(result.body)) # print content-length header instead, otherwise confusing
        write_body(options, result.body)
    sys.exit(get_exit_code(result.status))

if __name__ == '__main__':
    main()
Exemple #22
0
                         globaltree=options.globaltree,
                         filename=options.filename)
    sys.stderr.write('%s %s\n' % (action, url))

    try:
        result = client_request(client, action, options, node_selector)
    except (urllib2.URLError, HTTPException), ex:
        sys.exit('FATAL: %s: %s' % (type(ex).__name__, ex))
    if result.status == 401 and not options.password and interactive():
        authreq = result.headers.get('www-authenticate')
        if authreq:
            mo = urllib2.AbstractBasicAuthHandler.rx.search(authreq)
            if mo:
                realm = mo.groups()[-1]
                #sys.stderr.write('Server requested authentication, but no password was provided.\n')
                options.password = getPassword('Password (realm=%s): ' % realm)
                client = make_xcapclient(options, XCAPClient=client_class)
                result = client_request(client, action, options, node_selector)
    if not (result.status == 200 and action == 'get'):
        sys.stderr.write('%s %s\n' % (result.status, result.reason))
    write_etag(result.headers.get('etag'))
    if result.headers.get('content-type'):
        write_content_type(result.headers['content-type'])
    if result.body:
        write_content_length(
            len(result.body
                ))  # print content-length header instead, otherwise confusing
        write_body(options, result.body)
    sys.exit(get_exit_code(result.status))

Exemple #23
0
def cbInbox(content, proto):
   log.msg("Selected INBOX")
   return proto.search("NEW").addCallback(cbNewCount)
def cbNewCount(content):
   """ Gets a list with all message ids of new messages """
   cnt = len(content)
   log.msg("Mailbox contains %d new messages." % cnt)
   return cnt
  
def checkmbox(server, uid, pwd):
   log.msg("Checking mails on "+server)
   deferred = defer.Deferred().addCallback(cbGreeting, uid, pwd)
   factory = ImapClientFactory(uid, deferred)
   #reactor.connectTCP(server, 143, factory)
   reactor.connectTCP(server, 993, factory)
   return deferred
  
def blub(cnt):
   print cnt
  
if __name__ == "__main__":
   print "simple imap client"
   server = raw_input("Server name: ")
   uid = raw_input("Username: "******"Password: ")
  
   from twisted.internet import reactor
   checkmbox(server, uid, pwd).addCallback(blub)
   reactor.run()
Exemple #24
0
def reversePassword():
    password = util.getPassword()
    return reverseString(password)
Exemple #25
0
def cbNewCount(content):
    """ Gets a list with all message ids of new messages """
    cnt = len(content)
    log.msg("Mailbox contains %d new messages." % cnt)
    return cnt


def checkmbox(server, uid, pwd):
    log.msg("Checking mails on " + server)
    deferred = defer.Deferred().addCallback(cbGreeting, uid, pwd)
    factory = ImapClientFactory(uid, deferred)
    #reactor.connectTCP(server, 143, factory)
    reactor.connectTCP(server, 993, factory)
    return deferred


def blub(cnt):
    print cnt


if __name__ == "__main__":
    print "simple imap client"
    server = raw_input("Server name: ")
    uid = raw_input("Username: "******"Password: ")

    from twisted.internet import reactor
    checkmbox(server, uid, pwd).addCallback(blub)
    reactor.run()
Exemple #26
0
# the script importing this file must call AriUtils.loadOnlineLibs()
from twisted.internet import utils, threads, defer
from twisted.python import util

import buildDefaultActors

# constants
STAGE_DIR="/data/ONLINE/Stage"
STAGE_PRF="AriStage."
STATUS_ACTOR="AriStatusActor"
FILE_ACTOR="AriFileActor"
#ALERT_TO_EMAILS=["*****@*****.**", "*****@*****.**", "*****@*****.**"]
ALERT_TO_EMAILS=["*****@*****.**"]
ALERT_FROM_ADDRESS="*****@*****.**"
SMTP_USER="******"
SMTP_PASS=util.getPassword('Password for {0}@{1} (to send alerts/SBD msgs): '
                           .format(SMTP_USER,smtphost))


def GetActorFilename(macadr):
    # get the name of the file containing the actor for the station
    adir = "{0}/{1}{2}.root".format(STAGE_DIR,STAGE_PRF,macadr)
    checkDirOfFileExists(adir)
    printout(vtype.kDebug, "ActorFN for {0} is {1}".format(macadr,adir))
    return adir


class AriStage(object):

    def __init__(self, reactor):
        self.reactor = reactor
        # file storing the actors for this stage
Exemple #27
0
 def opt_pop3password(self,password):
     """The password used to authenticate the pop3 user"""
     if password in ('','-'):
         self['password']=util.getPassword(confirm=1)
     else:
         self['password']=password