Exemplo n.º 1
0
    def __init__(self):
        CLEO_wsdl = 'http://cougar.cs.cornell.edu/CLEO/CLEO_WS.asmx?WSDL'
        CLEO_namespace = 'http://cleo.lepp.cornell.edu/CLEO'
        config = SOAPpy.SOAPConfig()
        config.debug = 0
        config.buildWithNamespacePrefix = False

        self.proxy = SOAPpy.WSDL.Proxy(CLEO_wsdl,
                                       config,
                                       namespace=CLEO_namespace,
                                       noroot=1)

        meths = self.proxy.methods.values()
        for m in meths:
            m.namespace = CLEO_namespace
Exemplo n.º 2
0
def main(argv):
    global db

    dbname = 'db/mcids'
    type = None

    args = argv[1:]
    debug = False
    port = 1080

    while args:
        if args[0] == '-db' and len(args) > 1:
            dbname = args[1]
            args = args[2:]

        elif args[0] == '-D':
            debug = True
            args = args[1:]

        elif args[0] == '-p' and len(args) > 1:
            port = int(args[1])
            args = args[2:]

        elif type is None and not args[0].startswith('-'):
            type = args[0]
            args = args[1:]

        else:
            usage(dbname)

    db = sql.connect(dbname)
    generator.load(type)

    # This is set up so the very next allocation from the SOAP service
    # will result in a database write.  That way, you can start and
    # stop the SOAP service, and as long as there weren't any SOAP calls,
    # we're not allocating blocks of MCIDs.
    #
    for i in xrange(generator.iterations):
	generator.next_mcid()

    config = SOAPpy.SOAPConfig()
    #config.dumpSOAPIn = True
    server = SOAPpy.SOAPServer(("mcid.internal", port),
			       namespace = NS, config = config,
			       RequestHandler = RESTRequestHandler)
    server.registerFunction(generator.next_mcid_str, path='mcid', namespace=NS)
    server.registerFunction(generator.next_mcid, path='mcid', namespace=NS)

    # On unix root, try to setuid to the 'mcid_server' account for
    # least privilege
    #
    if not debug:
        try:
            from os import _exit, setuid, setgid, fork, dup2, open, close, \
                 O_RDONLY, O_WRONLY, O_APPEND, O_CREAT
            from pwd import getpwnam
        except ImportError:
            pass

        else:
            pw = getpwnam('mcid_server')

            pid = fork()

            if pid:
                print >>file(PID_FILE, 'w'), pid
                _exit(0)

            fd = open('/dev/null', O_RDONLY)
            dup2(fd, 0)

            fd = open(LOG_FILE, O_WRONLY | O_APPEND | O_CREAT)
            dup2(fd, 1)
            dup2(fd, 2)
            close(fd)

            setgid(pw.pw_gid)
            setuid(pw.pw_uid)

    server.serve_forever()
Exemplo n.º 3
0
def main(argv):
    from os import getpid

    global status

    args = argv[1:]

    debug = False
    port = DEFAULT_PORT
    username = DEFAULT_USERNAME
    pid_file = PID_FILE
    log_file = LOG_FILE

    while args:
        if args[0] == '-D':
            debug = True
            args = args[1:]

        elif args[0] == '-C' and len(args) > 1:
            args = file(args[1]).read().split() + args[2:]

        elif args[0] == '-p' and len(args) > 1:
            port = int(args[1])
            args = args[2:]

        elif args[0] == '-u' and len(args) > 1:
            username = args[1]
            args = args[2:]

        elif args[0] == '-pid' and len(args) > 1:
            pid_file = args[1]
            args = args[2:]

        elif args[0] == '-log' and len(args) > 1:
            log_file = args[1]
            args = args[2:]

        elif args[0] == '-db' and len(args) > 1:
            db_options['db'] = args[1]
            args = args[2:]

        elif args[0] == '-user' and len(args) > 1:
            db_options['user'] = args[1]
            args = args[2:]

        elif args[0] == '-host' and len(args) > 1:
            db_options['host'] = args[1]
            args = args[2:]
        else:
            usage()

    config = SOAPpy.SOAPConfig()
    #config.dumpSOAPIn = True
    server = SOAPpy.SOAPServer(('0.0.0.0', port),
                               namespace = NS,
                               config = config,
                               RequestHandler = RESTRequestHandler)

    status = Status()

    for g in generators:
        # Create function names of the form
        #    next_{}_set
        #
        # for example:
        #    next_mcid_set()
        #    next_tracking_number_set()
        #
        server.registerFunction(g.soap_set, funcName = 'next_%s_set' % g.name,
                                namespace = NS)

        setattr(status, '%s_requests' % g.name, 0)

    status.uid = status.gid = 0
    status.log_file = None
    status.version = __version__
    
    if not debug:
        try:
            from os import _exit, setuid, setgid, fork, dup2, open, close, \
                 O_RDONLY, O_WRONLY, O_APPEND, O_CREAT
            from pwd import getpwnam
        except ImportError:
            pass

        else:
            pw = getpwnam(username)
            status.user = username

            pid = fork()

            if pid:
                print >>file(pid_file, 'w'), pid
                _exit(0)

            fd = open('/dev/null', O_RDONLY)
            dup2(fd, 0)

            fd = open(log_file, O_WRONLY | O_APPEND | O_CREAT)
            dup2(fd, 1)
            dup2(fd, 2)
            close(fd)

            setgid(pw.pw_gid)
            setuid(pw.pw_uid)

            status.uid = pw.pw_uid
            status.gid = pw.pw_gid
            status.log_file = log_file

    status.port = port
    status.db_host = db_options['host']
    status.db_user = db_options['user']
    status.db = db_options['db']
    status.pid = getpid()
    status.started = datetime.utcnow()

    status.requests = 0

    server.serve_forever()
Exemplo n.º 4
0
def main(argv):
    global status, mcids, tracking_numbers, proxy, mcid_cache, tn_cache, tns_cache_path, mcid_cache_path

    args = argv[1:]

    debug = False
    username = DEFAULT_USERNAME
    port = DEFAULT_PORT

    try:
        socket.gethostbyname(DEFAULT_HOST)
        host = DEFAULT_HOST
    except socket.error:
        host = '127.0.0.1'

    pid_file = PID_FILE
    log_file = LOG_FILE

    url = DEFAULT_URL
    appliance = None
    use_cache = False

    while args:
        if args[0] == '-D':
            debug = True
            args = args[1:]

        elif args[0] == '-C' and len(args) > 1:
            args = file(args[1]).read().split() + args[2:]

        elif args[0] == '-p' and len(args) > 1:
            port = int(args[1])
            args = args[2:]

        elif args[0] == '-h' and len(args) > 1:
            host = args[1]
            args = args[2:]

        elif args[0] == '-u' and len(args) > 1:
            username = args[1]
            args = args[2:]

        elif args[0] == '-pid' and len(args) > 1:
            pid_file = args[1]
            args = args[2:]

        elif args[0] == '-log' and len(args) > 1:
            log_file = args[1]
            args = args[2:]

        elif args[0] == '-url' and len(args) > 1:
            url = args[1]
            args = args[2:]

        elif args[0] == '-usecache' and len(args) > 1:
            use_cache = True
            mcid_cache_path = os.path.join(args[1], mcid_cache_path)
            tns_cache_path = os.path.join(args[1], tns_cache_path)
            args = args[2:]

        elif not args[0].startswith('-') and not appliance:
            appliance = args[0]
            args = args[1:]

        else:
            usage()

    if not appliance:
        appliance = socket.getfqdn()

    if use_cache:
        print "Using cache for mcids and tracking numbers:  loading archived sets"
        f = open(mcid_cache_path, 'r')
        mcid_cache = pickle.load(f)
        print "Loaded " + str(len(mcid_cache)) + " mcid sets"
        mcids = infinite_sequence(next_mcid_cache, appliance)
        f.close()

        f = open(tns_cache_path, 'r')
        tn_cache = pickle.load(f)
        f.close()
        print "Loaded " + str(len(tn_cache)) + " tracking number sets"

        tracking_numbers = infinite_sequence(next_tn_cache, appliance)

    else:
        proxy = SOAPpy.SOAPProxy(url,
                                 namespace='http://www.medcommons.net/globals')
        mcids = infinite_sequence(proxy.next_mcid_set, appliance)
        tracking_numbers = infinite_sequence(proxy.next_tracking_number_set,
                                             appliance)

    status = Status()
    status.port = port
    status.host = host
    status.uid = status.gid = 0
    status.url = url
    status.requests = status.mcid_requests = 0
    status.tracking_number_requests = 0
    status.version = __version__

    config = SOAPpy.SOAPConfig()
    #config.dumpSOAPIn = True
    server = SOAPpy.SOAPServer((host, port),
                               namespace=NS2,
                               config=config,
                               RequestHandler=RESTRequestHandler)

    server.registerFunction(next_mcid_str, namespace=NS2)
    server.registerFunction(next_mcid, namespace=NS2)
    server.registerFunction(next_tracking_number_str, namespace=NS2)
    server.registerFunction(next_tracking_number, namespace=NS2)

    # backwards compatibility
    server.registerFunction(next_mcid_str, path='mcid', namespace=NS1)
    server.registerFunction(next_mcid, path='mcid', namespace=NS1)

    # On unix root, try to setuid to the 'mc_locals' account for
    # least privilege
    #
    if not debug:
        try:
            from os import _exit, setuid, setgid, fork, dup2, \
                 O_RDONLY, O_WRONLY, O_APPEND, O_CREAT
            from pwd import getpwnam
        except ImportError:
            pass

        else:
            pw = getpwnam(username)
            status.user = username

            pid = fork()

            if pid:
                print >> file(pid_file, 'w'), pid
                _exit(0)

            fd = os.open('/dev/null', O_RDONLY)
            dup2(fd, 0)

            fd = os.open(log_file, O_WRONLY | O_APPEND | O_CREAT)
            dup2(fd, 1)
            dup2(fd, 2)
            os.close(fd)

            setgid(pw.pw_gid)
            setuid(pw.pw_uid)

            status.gid = pw.pw_gid
            status.uid = pw.pw_uid

    status.started = datetime.utcnow()

    server.serve_forever()