Beispiel #1
0
def client_check():
        # Setup and some checks.
        check_setup(clt_config, clt_options, loggerclt, where = "clt")

        # Check cmid.
        if clt_config['cmid'] is not None:
                try:
                        uuid.UUID(clt_config['cmid'])
                except ValueError:
                        pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt",
                                       put_text = "{reverse}{red}{bold}argument `-c/--cmid`: invalid with: '%s'. Exiting...{end}" %clt_config['cmid'])

        # Check machine name.
        if clt_config['machine'] is not None:
                try:
                        clt_config['machine'].encode('utf-16le')

                        if len(clt_config['machine']) < 2:
                                pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt",
                                               put_text = "{reverse}{red}{bold}argument `-n/--name`: too short (required 2 - 63 chars). Exiting...{end}")
                        elif len(clt_config['machine']) > 63:
                                pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt",
                                               put_text = "{reverse}{red}{bold}argument `-n/--name`: too long (required 2 - 63 chars). Exiting...{end}")
                except UnicodeEncodeError:
                        pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt",
                                       put_text = "{reverse}{red}{bold}argument `-n/--name`: invalid with: '%s'. Exiting...{end}" %clt_config['machine'])
                        
        clt_config['call_id'] = 1

        # Check other specific client options.
        opts = [('timeoutidle', '-t0/--timeout-idle'),
                ('timeoutsndrcv', '-t1/--timeout-sndrcv')]
        check_other(clt_config, opts, loggerclt, where = 'clt')
Beispiel #2
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