Example #1
0
 def DoEdit(um):
     if um[1]=='list':
         at = OMCEAuthenticator.from_file(vdbn,'r')
         DefConText.PRINT('Users in "%s":' % vdbn)
         for un in at.list_users():
             DefConText.PRINT(un)
     else:
         at = OMCEAuthenticator.from_file(vdbn,'w')
         if um[1]=='addfile':
             if len(um)!=3:
                 DefConText.ERROR(76,'addfile')
             fn=um[2]
             if not os.path.isfile(fn):
                 DefConText.ERROR(2,fn)
             DefConText.PRINT('Processing "%s":' % fn)
             unf=open(fn,'r')
             cs=unf.read()
             ls=cs.split('\n')
             for cl in ls:
                 un=cl.split(' ')[0]
                 pssw=cl[len(un):].strip()
                 try:
                     pssw=UnQuote(pssw)[0]
                 except:
                     raise Error(81,pssw)
                 if un!='':
                     if pssw=='':
                         DefConText.PRINT(MSG(105,un))
                     DefConText.PRINT("Adding %s" % un)
                     at.set_user(un,pssw)
         elif um[1]=='add':
             if len(um)!=4:
                 DefConText.ERROR(76,'add')
             if (um[2].strip()=='') or (um[3]==''):
                 DefConText.ERROR(80)
             at.set_user(um[2].strip(),um[3])
         elif um[1]=='del':
             if len(um)!=3:
                 DefConText.ERROR(76,'del')
             try:
                 at.del_user(um[2].strip())
             except:
                 DefConText.ERROR(79,um[2],vdbn)
         else:
             DefConText.ERROR(78,um[1])
         at.sync()
     return
Example #2
0
def StartServer(port, ar=False, host='0.0.0.0', fork=False, quiet=False, vdbn='', tls=False):
    global Simulator
    from OMCE import Simulator
    from OMCE import __version__ as OMCEversion
    if quiet:
        console=None
    else:
        DefConText.PRINT(__MODIDstr__  % OMCEversion,VL_Startup)
        DefConText.PRINT(__AUTHOR__,VL_Startup)
        console = sys.stderr
    at=None
    if (vdbn!='') or tls:
        if vdbn=='':
            UL={tls[0]:tls[1]}
            DefConText.NOISE('Using simple TLS with user "'+UL.keys()[0]+'" and password "'+UL[UL.keys()[0]]+'"')
            at = OMCEAuthenticator.from_dict(UL)
        else:
            DefConText.NOISE('Using VDB ('+vdbn+')')
            at = OMCEAuthenticator.from_file(vdbn,'r')
        at.bypass_known_ip=True
    DefConText.NOISE(DefConText.MSG(104))
    logger=OMCElogger(OMCEService.ALIASES[0],show_tid = True,console = console,file=DefConText.logfile)
    DefConText.logfile=None
    if fork:
        OMCEService.Server = OMCEForkingServer(OMCEService, port = port, auto_register = ar, hostname=host, logger = logger, authenticator = at)
    else:
        OMCEService.Server = OMCEThreadedServer(OMCEService, port = port, auto_register = ar, hostname=host, logger = logger, authenticator = at)
    if DefConText.VerboseLevel>VL_Details:
        logger.filter=set(["TRACEBACK"])
    if DefConText.VerboseLevel>VL_Info:
        logger.filter=set(["TRACEBACK","INFO"])
    if DefConText.VerboseLevel>VL_Warn:
        logger.filter=set(["TRACEBACK","INFO","WARNING"])
    OMCEService.Fork=fork
    try:
        OMCEService.Server.start()
    finally:
        DefConText.logfile=logger.file
        logger.file=None
    return