Ejemplo n.º 1
0
#!/usr/bin/python
from __future__ import print_function
import os
import shlex
import signal
import subprocess
import sys
import time
from optparse import OptionParser
from Queue import Queue, Empty
from threading import Thread

try:
    from server_info import server_info
    _SECURE_DEFAULT = server_info.get('secure_jail', True)
except ImportError:
    _SECURE_DEFAULT = False

class SandboxError(StandardError):
    pass

def _guard_monitor(jail):
    guard_out = jail.command_process.stdout
    while True:
        line = guard_out.readline()
        if not line:
            end_item = (time.time(), None)
            jail.resp_queue.put(end_item)
            jail.stdout_queue.put(end_item)
            jail.stderr_queue.put(end_item)
            break
Ejemplo n.º 2
0
import glob
import json
import os
import re
import shutil
import subprocess
import sys
import time
from optparse import OptionParser

from sandbox import get_sandbox
from string import split

try:
    from server_info import server_info
    MEMORY_LIMIT = server_info.get('memory_limit', 1500)
except ImportError:
    MEMORY_LIMIT = 1500

BOT = "MyBot"
SAFEPATH = re.compile('[a-zA-Z0-9_.$-]+$')

class CD(object):
    def __init__(self, new_dir):
        self.new_dir = new_dir

    def __enter__(self):
        self.org_dir = os.getcwd()
        os.chdir(self.new_dir)
        return self.new_dir
Ejemplo n.º 3
0
# Original Author: Jeff Cameron ([email protected])

import collections
import errno
import fnmatch
import os
import os.path
import re
import subprocess
import sys

import util

try:
    from server_info import server_info
    MEMORY_LIMIT = server_info.get('memory_limit', 1500)
except ImportError:
    MEMORY_LIMIT = 1500

BOT = "MyBot"
# Which file is used to override the detected language?
LANGUAGE_FILE = "LANGUAGE"
SAFEPATH = re.compile('[a-zA-Z0-9_.$-]+$')


class CD(object):
    """
    A context manager that enters a given directory and restores the old one.
    """
    def __init__(self, new_dir):
        self.new_dir = new_dir
Ejemplo n.º 4
0
#!/usr/bin/python
from __future__ import print_function
import os
import shlex
import signal
import subprocess
import sys
import time
from optparse import OptionParser
from Queue import Queue, Empty
from threading import Thread

try:
    from server_info import server_info
    _SECURE_DEFAULT = server_info.get('secure_jail', True)
except ImportError:
    _SECURE_DEFAULT = False


class SandboxError(StandardError):
    pass


def _guard_monitor(jail):
    guard_out = jail.command_process.stdout
    while True:
        line = guard_out.readline()
        if not line:
            end_item = (time.time(), None)
            jail.resp_queue.put(end_item)
            jail.stdout_queue.put(end_item)
Ejemplo n.º 5
0
# make python 3.x compatible with python 2.x
if sys.version_info >= (3,):

    def unicode(s, errors="strict"):
        if isinstance(s, str):
            return s
        elif isinstance(s, bytes) or isinstance(s, bytearray):
            return s.decode("utf-8", errors)
        raise SandboxError("Tried to convert unrecognized type to unicode")


try:
    from server_info import server_info

    _SECURE_DEFAULT = server_info.get("secure_jail", True)
except ImportError:
    _SECURE_DEFAULT = False


class SandboxError(Exception):
    pass


def _guard_monitor(jail):
    guard_out = jail.command_process.stdout
    while True:
        line = guard_out.readline()
        if not line:
            end_item = (time.time(), None)
            jail.resp_queue.put(end_item)
Ejemplo n.º 6
0
import fnmatch
import glob
import json
import os
import os.path
import re
import shutil
import subprocess
import sys
import time
from optparse import OptionParser

try:
    from server_info import server_info

    MEMORY_LIMIT = server_info.get("memory_limit", 1500)
except ImportError:
    MEMORY_LIMIT = 1500

BOT = "MyBot"
LANGUAGE_FILE = "LANGUAGE"
SAFEPATH = re.compile("[a-zA-Z0-9_.$-]+$")


class CD(object):
    def __init__(self, new_dir):
        self.new_dir = new_dir

    def __enter__(self):
        self.org_dir = os.getcwd()
        os.chdir(self.new_dir)
Ejemplo n.º 7
0
import fnmatch
import glob
import json
import os
import re
import shutil
import subprocess
import sys
import time
from optparse import OptionParser

from sandbox import get_sandbox

try:
    from server_info import server_info
    MEMORY_LIMIT = server_info.get('memory_limit', 500)
    COMPILE_TIME = server_info.get('compile_time', 10 * 60)
except ImportError:
    MEMORY_LIMIT = 500
    COMPILE_TIME = 10 * 60

BOT = "MyBot"
SAFEPATH = re.compile('[a-zA-Z0-9_.$-]+$')


class CD(object):
    def __init__(self, new_dir):
        self.new_dir = new_dir

    def __enter__(self):
        self.org_dir = os.getcwd()
Ejemplo n.º 8
0
import unicodedata
import traceback
import tempfile
from copy import copy, deepcopy

from optparse import OptionParser

from server_info import server_info

import compiler
from engine import run_game

# Set up logging
log = logging.getLogger('worker')
log.setLevel(logging.INFO)
log_file = os.path.join(server_info.get('logs_path', '.'), 'worker.log')
handler = logging.handlers.RotatingFileHandler(log_file,
                                               maxBytes=10000000,
                                               backupCount=5)
handler.setLevel(logging.INFO)
handler2 = logging.StreamHandler()
formatter = logging.Formatter("%(asctime)s - " + str(os.getpid()) +
                              " - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
handler2.setFormatter(formatter)
log.addHandler(handler)
log.addHandler(handler2)

handler2 = logging.StreamHandler()

Ejemplo n.º 9
0
import fnmatch
import glob
import json
import os
import re
import shutil
import subprocess
import sys
import time
from optparse import OptionParser

from sandbox import get_sandbox

try:
    from server_info import server_info
    MEMORY_LIMIT = server_info.get('memory_limit', 500)
    COMPILE_TIME = server_info.get('compile_time', 10 * 60)
except ImportError:
    MEMORY_LIMIT = 500
    COMPILE_TIME = 10 * 60

BOT = "MyBot"
SAFEPATH = re.compile('[a-zA-Z0-9_.$-]+$')

class CD(object):
    def __init__(self, new_dir):
        self.new_dir = new_dir

    def __enter__(self):
        self.org_dir = os.getcwd()
        os.chdir(self.new_dir)
Ejemplo n.º 10
0
import platform
import traceback
import tempfile
from copy import copy, deepcopy

from optparse import OptionParser

from server_info import server_info

import compiler
from engine import run_game

# Set up logging
log = logging.getLogger('worker')
log.setLevel(logging.INFO)
log_file = os.path.join(server_info.get('logs_path', '.'), 'worker.log')
handler = logging.handlers.RotatingFileHandler(log_file,
                                               maxBytes=10000000,
                                               backupCount=5)
handler.setLevel(logging.INFO)
handler2 = logging.StreamHandler()
formatter = logging.Formatter("%(asctime)s - " + str(os.getpid()) +
                              " - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
handler2.setFormatter(formatter)
log.addHandler(handler)
log.addHandler(handler2)

handler2 = logging.StreamHandler()