Ejemplo n.º 1
0
def main():
    global APIconf
    print("Generating secret server key just this instance knows...")
    secretserverkey = os.urandom(16)

    print("Loading oauth provider plugins...")
    for content in os.listdir("oauthproviders"):
        if os.path.isdir(os.path.join("oauthproviders", content)):
            print("  - " + content)
            oauthProviders[content] = {}
            oauthProviders[content]["plugin"] = importlib.import_module(
                "oauthproviders." + content).provider()
            sfile = open(os.path.join("oauthproviders", content, "config.yml"),
                         "r")
            filebuffer = sfile.read()
            sfile.close()
            config = {}
            for entry in filebuffer.split("\n"):
                if entry.find(":") > -1:
                    key, value = entry.split(":", 1)
                    config[key.strip()] = str(value.strip())
            oauthProviders[content]["config"] = config

    print("Loading mentorAPI configuration...")
    APIconf = readConfig(os.path.join(os.getcwd(), "mentorapi.yml")).config

    print("Starting cherrypy server...")
    cherrypy.quickstart(mentor(secretserverkey), "/", "mentorserver.cfg")
Ejemplo n.º 2
0
def run(file: str = None, **kwargs):
    print("----------------------------------------")
    print("Server version:", __VERSION)

    if file:
        print("Loading config file:", file)
        import lib
        from lib.config import readConfig
        lib.config = config = readConfig(file)
    else:
        from lib.config import config

    if kwargs:
        print("Applying config overrides")
        config.update(kwargs)
    print("----------------------------------------")

    try:
        settings = dict(
            ssl_options={
                "certfile":
                os.path.join(
                    "/etc/letsencrypt/live/scavhunt.tech/fullchain.pem"),
                "keyfile":
                os.path.join(
                    "/etc/letsencrypt/live/scavhunt.tech/privkey.pem"),
            })
        server = tornado.httpserver.HTTPServer(app, **settings)

        port = config["SERVER"].get("port", 443)
    except:
        # Unable to run on HTTPS
        server = tornado.httpserver.HTTPServer(app)
        port = config["SERVER"].get("port", 80)

    try:
        server.bind(port)
    except OSError:
        print("Port", port, "is in use!\nAborting...")
        return

    try:
        from os import fork
        server.start(0)
    except:
        print(
            ":: os.fork not present on system (Windows) - Defaulting to single process"
        )
        server.start(1)

    print("Server running on port %s\n" % port)
    SSE_messages.addMessage("The game server is online!")
    SSE_messages.do.reloadSite()

    tornado.ioloop.IOLoop.current().start()
Ejemplo n.º 3
0
def run(file: str = None, **kwargs):
    print("UNSW CSE CompClub 2019 Summer CTF Server")
    print("                      [ by Andrew Wong ]")
    print("----------------------------------------")
    print("Server version:", __VERSION)

    if file:
        print("Loading config file:", file)
        import lib
        from lib.config import readConfig
        # Must be getting the CONFIGURAITON OF THE FILE
        lib.config = config = readConfig(file)
    else:
        from lib.config import config

    if kwargs:
        print("Applying config overrides")
        config.update(kwargs)
    print("----------------------------------------")

    server = tornado.httpserver.HTTPServer(app)

    port = config["SERVER"].get("port", 8000)
    try:
        server.bind(port)
    except OSError:
        print("Port", port, "is in use!\nAborting...")
        return

    try:
        from os import fork
        server.start(0)
    except:
        print(
            ":: os.fork not present on system (Windows) - Defaulting to single process"
        )
        server.start(1)

    print("Server running on port %s\n" % port)
    SSE_messages.addMessage("The game server is online!")
    SSE_messages.do.reloadSite()

    # DO
    tornado.ioloop.IOLoop.current().start()
Ejemplo n.º 4
0
def main():
    global APIconf, queries, cmds

    print("loading mentorAPI configuration...")
    APIconf = readConfig(os.path.join(os.getcwd(), "mentorapi.yml")).config

    print("connecting to the database with the following dbconnstr:")
    print("  ", APIconf["dbconnstr"])
    dbhelper = management(APIconf["dbconnstr"])
    if not dbhelper.error == "":
        print("\033[1;mDatabase does not exist\033[0;m")

        print("creating database '{}'...".format(APIconf["dbname"]))
        os.system(cmds["createdb"].format(APIconf["dbname"]))

        print("restarting...")
        return main()
    else:
        print("\033[1;mDatabase does exist\033[0;m")

    print("checking existence of requirred tables...")
    for i in queries:
        if dbhelper.tableExists(i):
            print("\033[0;32m  '{}' exists...\033[0;m".format(i))
        else:
            print("\033[0;31m  '{}' does not exist\033[0;m".format(i))
            if "table_" + i in APIconf:
                print("  creating table '{}'...".format(i))
                dbhelper.executeCMD(sqls[queries[i]].format(
                    i, ",\n".join(APIconf["table_" + i])))
            else:
                print(
                    "\033[0;31mtable scheme not specified in mentorapi.yml!\033[0;m"
                )

    print("syncing columns (insert/remove)...")
    changes = False
    for i in queries:
        if "table_" + i in APIconf:
            cols = copy.copy(APIconf["table_" + i])
            for n, content in enumerate(cols):
                colname, coltype = content.split(" ")
                cols[n] = (colname, coltype)
            changes = dbhelper.alterTable(i, cols)

    print("generating select statement for the view creation query...")
    select = []
    select2 = []
    for i in queries:
        confname = "table_" + i
        if confname in APIconf:
            for content in APIconf[confname]:
                content = content.split(" ")
                if not content[0] in select2:
                    select.append(i + "." + content[0])
                    select2.append(content[0])

    print("inserting generated select statement and execute query...")
    print("View creation query: \033[0;33m" +
          sqls["createview"].format(", ".join(select)) + "\033[0;m")
    if changes or dbhelper.tableExists("userdetails"):
        print("dropping view first...")
        dbhelper.executeCMD(sqls["deleteview"])
        print("executing generated select statement...")
    dbhelper.executeCMD(sqls["createview"].format(", ".join(select)))

    print("disconnecting from database...")
    dbhelper.tearDown()