Exemplo n.º 1
0
def main():
    import getopt
    import getpass

    prog = sys.argv[0]
    args = sys.argv[1:]

    port = py9p.PORT
    listen = '0.0.0.0'
    root = '/'
    mods = []
    user = None
    noauth = 0
    chatty = 0
    cancreate = 0
    dotu = 0
    authmode = None
    dom = None
    passwd = None
    key = None

    try:
        opt, args = getopt.getopt(args, "dDcp:r:l:a:")
    except:
        usage(prog)
    for opt, optarg in opt:
        if opt == "-D":
            chatty = 1
        if opt == "-d":
            dotu = 1
        if opt == '-c':
            cancreate = 1
        if opt == '-r':
            root = optarg
        if opt == "-p":
            port = int(optarg)
        if opt == '-l':
            listen = optarg
        if opt == '-a':
            authmode = optarg

    if authmode == 'sk1':
        if len(args) != 2:
            print >> sys.stderr, 'missing user and authsrv'
            usage(prog)
        else:
            py9p.sk1 = __import__("py9p.sk1").sk1
            user = args[0]
            dom = args[1]
            passwd = getpass.getpass()
            key = py9p.sk1.makeKey(passwd)
    elif authmode == 'pki':
        py9p.pki = __import__("py9p.pki").pki
        user = '******'
    elif authmode != None and authmode != 'none':
        print >> sys.stderr, "unknown auth type: %s; accepted: pki, sk1, none" % authmode
        sys.exit(1)

    srv = py9p.Server(listen=(listen, port),
                      authmode=authmode,
                      user=user,
                      dom=dom,
                      key=key,
                      chatty=chatty,
                      dotu=dotu)
    srv.mount(LocalFs(root, cancreate, dotu))
    srv.serve()
Exemplo n.º 2
0
    port = py9p.PORT
    address = 'localhost'
    dbg = False

    for i, k in opt:
        if i == "-D":
            dbg = True
        if i == "-p":
            port = int(k)
        if i == "-l":
            address = k

    print("%s:%s, debug=%s" % (address, port, dbg))
    storage = Storage(RootDir)
    srv = py9p.Server(listen=(address, port), chatty=dbg, dotu=True)
    srv.mount(v9fs(storage))

    ifaces = {}
    ifaces['by-name'] = dict([(x['dev'], x) for x in ifaces.values()])
    iproute2.get_all_links()
    iproute2.get_all_addrs()
    storage.root.sync()
    storage.root.children["interfaces"].ifaces = ifaces
    storage.root.children["interfaces"].subst_map = ifaces['by-name']

    s = Thread(target=sync, name="sync thread", args=(ifaces, True))
    s.daemon = True
    s.start()

    srv.serve()