Exemple #1
0
def activate_challenge(name, config):
    metadata = get_metadata(name)

    if name in challenge_processes:
        return

    if 'run_type' in metadata:
        if metadata['run_type'] == 'tcpserver':
            config['port'] = allocate_tcp_port(name, config.get('port', None))
            config['host'] = '0.0.0.0'
        elif metadata['run_type'] == 'udpserver':
            config['port'] = allocate_udp_port(name, config.get('port', None))
            config['host'] = '0.0.0.0'

        if 'run_command' in metadata:
            logfile = get_logfile(name)
            old_cwd = os.getcwd()
            os.chdir('challenges/%s/' % name)
            challenge_processes[name] = subprocess.Popen(
                metadata['run_command'] % config,
                shell=True,
                stdin=None,
                stdout=logfile,
                stderr=logfile)
            os.chdir(old_cwd)
    def get(self, name, filename):
        if not is_challenge(name):
            raise tornado.web.HTTPError(404)

        metadata = get_metadata(name)
        if filename not in metadata['public_files']:
            raise tornado.web.HTTPError(404)
            
        file = open(os.path.join(os.getcwd(), 'challenges/%s/%s' % (name, filename)))
        for line in file:
            self.write(line)
Exemple #3
0
    def get(self, name, filename):
        if not is_challenge(name):
            raise tornado.web.HTTPError(404)

        metadata = get_metadata(name)
        if filename not in metadata['public_files']:
            raise tornado.web.HTTPError(404)

        file = open(
            os.path.join(os.getcwd(), 'challenges/%s/%s' % (name, filename)))
        for line in file:
            self.write(line)
Exemple #4
0
def deactivate_challenge(name):
    metadata = get_metadata(name)

    if 'run_type' in metadata:
        if metadata['run_type'] == 'tcpserver':
            free_tcp_ports(name)
        elif metadata['run_type'] == 'udpserver':
            free_udp_ports(name)

    if name in challenge_processes:
        if challenge_processes[name].poll() == None:
            challenge_processes[name].terminate()
        del challenge_processes[name]
def deactivate_challenge(name):
    metadata = get_metadata(name)

    if 'run_type' in metadata:
        if metadata['run_type'] == 'tcpserver':
            free_tcp_ports(name)
        elif metadata['run_type'] == 'udpserver':
            free_udp_ports(name)

    if name in challenge_processes:
        if challenge_processes[name].poll() == None:
            challenge_processes[name].terminate()
        del challenge_processes[name]
def activate_challenge(name, config):
    metadata = get_metadata(name)
    
    if name in challenge_processes:
        return

    if 'run_type' in metadata:
        if metadata['run_type'] == 'tcpserver':
            config['port'] = allocate_tcp_port(name, config.get('port', None))
            config['host'] = '0.0.0.0'
        elif metadata['run_type'] == 'udpserver':
            config['port'] = allocate_udp_port(name, config.get('port', None))
            config['host'] = '0.0.0.0'

        if 'run_command' in metadata:
            logfile = get_logfile(name)
            old_cwd = os.getcwd()
            os.chdir('challenges/%s/' % name)
            challenge_processes[name] = subprocess.Popen(metadata['run_command'] % config,
                shell=True, stdin=None, stdout=logfile, stderr=logfile)
            os.chdir(old_cwd)
Exemple #7
0
 def get(self, name):
     if not is_challenge(name):
         raise tornado.web.HTTPError(404)
     self.write(jsonpack(get_metadata(name)))
 def get(self, name):
     if not is_challenge(name):
         raise tornado.web.HTTPError(404)
     self.write(jsonpack(get_metadata(name)))