<commit_before>#!/usr/bin/env python
import os
import sys


questions = [
    ('e', 
"""You must create a postgresql database in advance to running this
script. Also, you'll need a postgresql user for the scoring bot. If
you haven't created both, please terminate this script, create them,
and restart this script."""),
    ('q', 'dbuser', "Name of the postgresql DB user", 'ctf'),
    ('q', 'dbname', "Name of the postgresql DB", 'ctf'),
    ('q', 'dbpass', "Database password", ''),
    ('q', 'dbhost', "Host of the postgresql DB server", 'localhost'),
    ('e', """The scorebot telnet interface allows teams to report
flags and advisories; gamemasters use it to set up teams and services,
and to rate advisories."""),
    ('q', 'adminpwd', 'Scorebot console administrator password', ''),
    ('q', 'sbc', "Parallel connections to the scorebot", "40"),
    ('q', 'prompt', "Scorebot prompt", "scorebot"),
    ('e',
"""The scorebot distributes and later collects flags. Please decide
how long a flag should be valid. (Period between distribution and
collection) 300 is a reasonable default. Note that flags may be valid
longer; this value merely indicates after how many seconds a flag may
be collected by the scorebot. If a round lasts longer, or if the
gameserver job queue grows long, flags may be valid considerably
longer."""),
    ('q', 'flagage', 'Flag validity period (seconds)', '300'),
    ('e',
"""Testscripts are controlled by worker threads. The more worker
threads exist, the more testscripts can be executed in parallel.
Worker threads control both local and remotely running testscripts, so
you have to consider the number of remote peers when deciding this
value. (You can change it at runtime)"""),
    ('q', 'workers', 'Number of worker threads', '10'),
    ('e',
"""This gameserver uses rounds -- during each round, old flags are
collected and new ones distributed. You must decide how long each
round lasts.  This value should be considerably higher than the
average time it takes to do the flag collection+distribution. 600
seconds is a reasonable default."""),
    ('q', 'rounddelay', "Round duration in seconds", '600'),
    ('e',
"""Configuring webserver stuff. You must specify a directory which
will be served via HTTP to the public. If you're using debian, this
might be something like /var/www/score In addition to that, you'll
need to know the exact URL your users will be accessing the scorebot
through."""),
    ('q', 'wwwpath', "Path to www directory", "/var/www/score"),
    ('q', 'wwwroot', "URL to access scoredata from", "http://172.16.58.3/score"),
    ('e',
"""The scorebot allows you to distribute testscript execution to
various peers. For each peer, a maximum number of connections and some
other parameters can be configured. If a peer is not working, the next
one is tried. If no peer can be reached, the job is executed locally.
If you want to use that feature, enter the IPs / hostnames of the
peers now, separated by spaces."""),
    ('q', 'tspeers', "Peer IPs", ''),
    ('e',
"""I will now try to import the database. I do this by invoking psql
directly. You will be asked for the database password, although you
already specified it here."""),
    ('r', "psql %(dbname)s -U %(dbuser)s -h %(dbhost)s < sql/ctf.sql"),
    ('e', """Hmm, looks good :-)
Most configuration can be done by changing the files in control/

You can now:
  ./gameserver.sh        launch the flag distributor
  ./scoringbot.sh        launch the telnet interface
  ./pagegen.sh           launch the website generator
Visit http://ctf.hcesperer.org/gameserver/ for updates
Feedback? <EMAIL>

Happy CTF'ing!
]

def die(s):
    sys.stderr.write("\n\n======================================================================\n%s\n" % s)
    sys.exit(1)


class EmptyException(Exception): pass

def ask_questions():
    results = {}
    for item in questions:
        qtype = item[0]
        if qtype == 'e':
            print "\n%s" % item[1]
        elif qtype =='q':
            sys.stdout.write("  %s [%s] " % tuple(item[2:4]))
            sys.stdout.flush()
            res = sys.stdin.readline()[:-1]
            if res == '': res = item[3]
            if item[1] != 'tspeers': #hack
                if res == '': raise EmptyException()<commit_msg>a big oops<commit_after>#!/usr/bin/env python
import os
import sys


questions = [
    ('e', 
"""You must create a postgresql database in advance to running this
script. Also, you'll need a postgresql user for the scoring bot. If
you haven't created both, please terminate this script, create them,
and restart this script."""),
    ('q', 'dbuser', "Name of the postgresql DB user", 'ctf'),
    ('q', 'dbname', "Name of the postgresql DB", 'ctf'),
    ('q', 'dbpass', "Database password", ''),
    ('q', 'dbhost', "Host of the postgresql DB server", 'localhost'),
    ('e', """The scorebot telnet interface allows teams to report
flags and advisories; gamemasters use it to set up teams and services,
and to rate advisories."""),
    ('q', 'adminpwd', 'Scorebot console administrator password', ''),
    ('q', 'sbc', "Parallel connections to the scorebot", "40"),
    ('q', 'prompt', "Scorebot prompt", "scorebot"),
    ('e',
"""The scorebot distributes and later collects flags. Please decide
how long a flag should be valid. (Period between distribution and
collection) 300 is a reasonable default. Note that flags may be valid
longer; this value merely indicates after how many seconds a flag may
be collected by the scorebot. If a round lasts longer, or if the
gameserver job queue grows long, flags may be valid considerably
longer."""),
    ('q', 'flagage', 'Flag validity period (seconds)', '300'),
    ('e',
"""Testscripts are controlled by worker threads. The more worker
threads exist, the more testscripts can be executed in parallel.
Worker threads control both local and remotely running testscripts, so
you have to consider the number of remote peers when deciding this
value. (You can change it at runtime)"""),
    ('q', 'workers', 'Number of worker threads', '10'),
    ('e',
"""This gameserver uses rounds -- during each round, old flags are
collected and new ones distributed. You must decide how long each
round lasts.  This value should be considerably higher than the
average time it takes to do the flag collection+distribution. 600
seconds is a reasonable default."""),
    ('q', 'rounddelay', "Round duration in seconds", '600'),
    ('e',
"""Configuring webserver stuff. You must specify a directory which
will be served via HTTP to the public. If you're using debian, this
might be something like /var/www/score In addition to that, you'll
need to know the exact URL your users will be accessing the scorebot
through."""),
    ('q', 'wwwpath', "Path to www directory", "/var/www/score"),
    ('q', 'wwwroot', "URL to access scoredata from", "http://130.83.160.197/score"),
    ('e',
"""The scorebot allows you to distribute testscript execution to
various peers. For each peer, a maximum number of connections and some
other parameters can be configured. If a peer is not working, the next
one is tried. If no peer can be reached, the job is executed locally.
If you want to use that feature, enter the IPs / hostnames of the
peers now, separated by spaces."""),
    ('q', 'tspeers', "Peer IPs", ''),
    ('e',
"""I will now try to import the database. I do this by invoking psql
directly. You will be asked for the database password, although you
already specified it here."""),
    ('r', "psql %(dbname)s -U %(dbuser)s -h %(dbhost)s < sql/ctf.sql"),
    ('e', """Hmm, looks good :-)
Most configuration can be done by changing the files in control/

You can now:
  ./gameserver.sh        launch the flag distributor
  ./scoringbot.sh        launch the telnet interface
  ./pagegen.sh           launch the website generator
Visit http://ctf.hcesperer.org/gameserver/ for updates
Feedback? <EMAIL>

Happy CTF'ing!""")
]

def die(s):
    sys.stderr.write("\n\n======================================================================\n%s\n" % s)
    sys.exit(1)


class EmptyException(Exception): pass

def ask_questions():
    results = {}
    for item in questions:
        qtype = item[0]
        if qtype == 'e':
            print "\n%s" % item[1]
        elif qtype =='q':
            sys.stdout.write("  %s [%s] " % tuple(item[2:4]))
            sys.stdout.flush()
            res = sys.stdin.readline()[:-1]
            if res == '': res = item[3]
            if item[1] != 'tspeers': #hack
                if res == '': raise EmptyException()
{'fraction_non_alphanumeric': 0.13840749414519907, 'fraction_numerical': 0.00784543325526932, 'mean_word_length': 3.5944055944055946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2786715', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2371, 'n_words': 1125}