Ejemplo n.º 1
0
def server_check():
        # Check logfile.
        srv_config['logfile'] = check_logfile(srv_config['logfile'], srv_options['lfile']['def'], where = "srv")

        # Setup hidden or not messages.
        ShellMessage.view = ( False if any(i in ['STDOUT', 'FILESTDOUT'] for i in srv_config['logfile']) else True )

        # Create log.        
        logger_create(loggersrv, srv_config, mode = 'a')

        # Random HWID.
        if srv_config['hwid'] == "RANDOM":
                randomhwid = uuid.uuid4().hex
                srv_config['hwid'] = randomhwid[:16]
           
        # Sanitize HWID.
        hexstr = srv_config['hwid'].strip('0x')
        hexsub = re.sub(r'[^0-9a-fA-F]', '', hexstr)
        diff = set(hexstr).symmetric_difference(set(hexsub))

        if len(diff) != 0:
                diff = str(diff).replace('{', '').replace('}', '')
                pretty_printer(log_obj = loggersrv.error, to_exit = True,
                               put_text = "{reverse}{red}{bold}HWID '%s' is invalid. Digit %s non hexadecimal. Exiting...{end}" %(hexstr.upper(), diff))
        else:
                lh = len(hexsub)
                if lh % 2 != 0:
                        pretty_printer(log_obj = loggersrv.error, to_exit = True,
                                       put_text = "{reverse}{red}{bold}HWID '%s' is invalid. Hex string is odd length. Exiting...{end}" %hexsub.upper())
                elif lh < 16:
                        pretty_printer(log_obj = loggersrv.error, to_exit = True,
                                       put_text = "{reverse}{red}{bold}HWID '%s' is invalid. Hex string is too short. Exiting...{end}" %hexsub.upper())
                elif lh > 16:
                        pretty_printer(log_obj = loggersrv.error, to_exit = True,
                                       put_text = "{reverse}{red}{bold}HWID '%s' is invalid. Hex string is too long. Exiting...{end}" %hexsub.upper())
                else:
                        srv_config['hwid'] = binascii.a2b_hex(hexsub)

        # Check LCID.
        srv_config['lcid'] = check_lcid(srv_config['lcid'], loggersrv.warning)
                                
        # Check sqlite.
        try:
                import sqlite3            
        except:
                pretty_printer(log_obj = loggersrv.warning,
                               put_text = "{reverse}{yellow}{bold}Module 'sqlite3' is not installed, database support disabled.{end}")
                srv_config['dbSupport'] = False
        else:
                srv_config['dbSupport'] = True

        # Check port.
        if not 1 <= srv_config['port'] <= 65535:
                pretty_printer(log_obj = loggersrv.error, to_exit = True,
                               put_text = "{red}{bold}Port number '%s' is invalid. Enter between 1 - 65535. Exiting...{end}" %srv_config['port'])
Ejemplo n.º 2
0
def server_check():
    # Setup hidden or not messages.
    ShellMessage.view = (False if any(
        i in ['STDOUT', 'FILESTDOUT']
        for i in srv_config['logfile']) else True)
    # Create log.
    logger_create(loggersrv, srv_config, mode='a')

    # Random HWID.
    if srv_config['hwid'] == "RANDOM":
        randomhwid = uuid.uuid4().hex
        srv_config['hwid'] = randomhwid[:16]

    # Sanitize HWID.
    hexstr = srv_config['hwid'].strip('0x')
    hexsub = re.sub(r'[^0-9a-fA-F]', '', hexstr)
    diff = set(hexstr).symmetric_difference(set(hexsub))

    if len(diff) != 0:
        pretty_errors(41, loggersrv, put_text=[hexstr.upper(), diff])
    else:
        lh = len(hexsub)
        if lh % 2 != 0:
            pretty_errors(42, loggersrv, put_text=hexsub.upper())
        elif lh < 16:
            pretty_errors(43, loggersrv, put_text=hexsub.upper())
        elif lh > 16:
            pretty_errors(44, loggersrv, put_text=hexsub.upper())
        else:
            srv_config['hwid'] = binascii.a2b_hex(hexsub)

    # Check LCID.
    srv_config['lcid'] = check_lcid(srv_config['lcid'], loggersrv)

    # Check sqlite.
    try:
        import sqlite3
    except:
        loggersrv.warning(
            "Module \"sqlite3\" is not installed, database support disabled.")
        srv_config['dbSupport'] = False
    else:
        srv_config['dbSupport'] = True

    # Check port.
    if not 1 <= srv_config['port'] <= 65535:
        pretty_errors(45, loggersrv, put_text=srv_config['port'])
Ejemplo n.º 3
0
def server_check():
        # Setup and some checks.
        check_setup(srv_config, srv_options, loggersrv, where = "srv")

        # Random HWID.
        if srv_config['hwid'] == "RANDOM":
                randomhwid = uuid.uuid4().hex
                srv_config['hwid'] = randomhwid[:16]
           
        # Sanitize HWID.
        hexstr = srv_config['hwid']
        # Strip 0x from the start of hexstr
        if hexstr.startswith("0x"):
            hexstr = hexstr[2:]

        hexsub = re.sub(r'[^0-9a-fA-F]', '', hexstr)
        diff = set(hexstr).symmetric_difference(set(hexsub))

        if len(diff) != 0:
                diff = str(diff).replace('{', '').replace('}', '')
                pretty_printer(log_obj = loggersrv.error, to_exit = True,
                               put_text = "{reverse}{red}{bold}HWID '%s' is invalid. Digit %s non hexadecimal. Exiting...{end}" %(hexstr.upper(), diff))
        else:
                lh = len(hexsub)
                if lh % 2 != 0:
                        pretty_printer(log_obj = loggersrv.error, to_exit = True,
                                       put_text = "{reverse}{red}{bold}HWID '%s' is invalid. Hex string is odd length. Exiting...{end}" %hexsub.upper())
                elif lh < 16:
                        pretty_printer(log_obj = loggersrv.error, to_exit = True,
                                       put_text = "{reverse}{red}{bold}HWID '%s' is invalid. Hex string is too short. Exiting...{end}" %hexsub.upper())
                elif lh > 16:
                        pretty_printer(log_obj = loggersrv.error, to_exit = True,
                                       put_text = "{reverse}{red}{bold}HWID '%s' is invalid. Hex string is too long. Exiting...{end}" %hexsub.upper())
                else:
                        srv_config['hwid'] = binascii.a2b_hex(hexsub)

        # Check LCID.
        srv_config['lcid'] = check_lcid(srv_config['lcid'], loggersrv.warning)
                                
        # Check sqlite.
        try:
                import sqlite3            
        except:
                pretty_printer(log_obj = loggersrv.warning,
                               put_text = "{reverse}{yellow}{bold}Module 'sqlite3' is not installed, database support disabled.{end}")
                srv_config['dbSupport'] = False
        else:
                srv_config['dbSupport'] = True


        # Check other specific server options.
        list_dest = ['clientcount', 'timeoutidle']
        list_opt = ['-c/--client-count', '-t0/--timeout-idle']

        if serverthread.with_gui:
                list_dest += ['activation', 'renewal']
                list_opt += ['-a/--activation-interval', '-r/--renewal-interval']

        for dest, opt in zip(list_dest, list_opt):
                value = srv_config[dest]
                if (value is not None) and (not isinstance(value, int)):
                        pretty_printer(log_obj = loggersrv.error, to_exit = True,
                                       put_text = "{reverse}{red}{bold}argument `%s`: invalid with: '%s'. Exiting...{end}" %(opt, value))
Ejemplo n.º 4
0
def server_check():
    # Setup and some checks.
    check_setup(srv_config, srv_options, loggersrv, where="srv")

    # Random HWID.
    if srv_config['hwid'] == "RANDOM":
        randomhwid = uuid.uuid4().hex
        srv_config['hwid'] = randomhwid[:16]

    # Sanitize HWID.
    hexstr = srv_config['hwid']
    # Strip 0x from the start of hexstr
    if hexstr.startswith("0x"):
        hexstr = hexstr[2:]

    hexsub = re.sub(r'[^0-9a-fA-F]', '', hexstr)
    diff = set(hexstr).symmetric_difference(set(hexsub))

    if len(diff) != 0:
        diff = str(diff).replace('{', '').replace('}', '')
        pretty_printer(
            log_obj=loggersrv.error,
            to_exit=True,
            put_text=
            "{reverse}{red}{bold}HWID '%s' is invalid. Digit %s non hexadecimal. Exiting...{end}"
            % (hexstr.upper(), diff))
    else:
        lh = len(hexsub)
        if lh % 2 != 0:
            pretty_printer(
                log_obj=loggersrv.error,
                to_exit=True,
                put_text=
                "{reverse}{red}{bold}HWID '%s' is invalid. Hex string is odd length. Exiting...{end}"
                % hexsub.upper())
        elif lh < 16:
            pretty_printer(
                log_obj=loggersrv.error,
                to_exit=True,
                put_text=
                "{reverse}{red}{bold}HWID '%s' is invalid. Hex string is too short. Exiting...{end}"
                % hexsub.upper())
        elif lh > 16:
            pretty_printer(
                log_obj=loggersrv.error,
                to_exit=True,
                put_text=
                "{reverse}{red}{bold}HWID '%s' is invalid. Hex string is too long. Exiting...{end}"
                % hexsub.upper())
        else:
            srv_config['hwid'] = binascii.a2b_hex(hexsub)

    # Check LCID.
    srv_config['lcid'] = check_lcid(srv_config['lcid'], loggersrv.warning)

    # Check sqlite.
    if srv_config['sqlite']:
        if isinstance(srv_config['sqlite'], str):
            check_dir(srv_config['sqlite'],
                      'srv',
                      log_obj=loggersrv.error,
                      argument='-s/--sqlite',
                      typefile='.db')
        elif srv_config['sqlite'] is True:
            srv_config['sqlite'] = srv_options['sql']['file']

        try:
            import sqlite3
        except ImportError:
            pretty_printer(
                log_obj=loggersrv.warning,
                put_text=
                "{reverse}{yellow}{bold}Module 'sqlite3' not installed, database support disabled.{end}"
            )
            srv_config['sqlite'] = False

    # Check other specific server options.
    opts = [('clientcount', '-c/--client-count'),
            ('timeoutidle', '-t0/--timeout-idle'),
            ('timeoutsndrcv', '-t1/--timeout-sndrcv')]
    if serverthread.with_gui:
        opts += [('activation', '-a/--activation-interval'),
                 ('renewal', '-r/--renewal-interval')]
    check_other(srv_config, opts, loggersrv, where='srv')

    # Check further addresses / ports.
    if 'listen' in srv_config:
        addresses = []
        for elem in srv_config['listen']:
            try:
                addr, port = elem.split(',')
            except ValueError:
                pretty_printer(
                    log_obj=loggersrv.error,
                    to_exit=True,
                    put_text=
                    "{reverse}{red}{bold}argument `-n/--listen`: %s not well defined. Exiting...{end}"
                    % elem)
            try:
                port = int(port)
            except ValueError:
                pretty_printer(
                    log_obj=loggersrv.error,
                    to_exit=True,
                    put_text=
                    "{reverse}{red}{bold}argument `-n/--listen`: port number '%s' is invalid. Exiting...{end}"
                    % port)

            if not (1 <= port <= 65535):
                pretty_printer(
                    log_obj=loggersrv.error,
                    to_exit=True,
                    put_text=
                    "{reverse}{red}{bold}argument `-n/--listen`: port number '%s' is invalid. Enter between 1 - 65535. Exiting...{end}"
                    % port)

            addresses.append((addr, port))
        srv_config['listen'] = addresses