2016-06-02 20:33:39 +00:00
|
|
|
import json
|
2016-10-02 20:48:14 +00:00
|
|
|
|
|
|
|
from common.log import logUtils as log
|
|
|
|
from common.web import requestsManager
|
|
|
|
from constants import exceptions
|
2016-06-02 20:33:39 +00:00
|
|
|
from helpers import systemHelper
|
2016-10-02 20:48:14 +00:00
|
|
|
from objects import glob
|
|
|
|
|
2016-06-02 20:33:39 +00:00
|
|
|
|
2016-10-02 20:48:14 +00:00
|
|
|
class handler(requestsManager.asyncRequestHandler):
|
2016-06-02 20:33:39 +00:00
|
|
|
def asyncGet(self):
|
|
|
|
statusCode = 400
|
|
|
|
data = {"message": "unknown error"}
|
|
|
|
try:
|
|
|
|
# Check arguments
|
2016-10-02 20:48:14 +00:00
|
|
|
if not requestsManager.checkArguments(self.request.arguments, ["k"]):
|
2016-06-02 20:33:39 +00:00
|
|
|
raise exceptions.invalidArgumentsException()
|
|
|
|
|
|
|
|
# Check ci key
|
|
|
|
key = self.get_argument("k")
|
2016-06-04 10:44:54 +00:00
|
|
|
if key is None or key != glob.conf.config["server"]["cikey"]:
|
2016-06-02 20:33:39 +00:00
|
|
|
raise exceptions.invalidArgumentsException()
|
|
|
|
|
2016-06-04 10:44:54 +00:00
|
|
|
log.info("Ci event triggered!!")
|
2016-06-02 20:33:39 +00:00
|
|
|
systemHelper.scheduleShutdown(5, False, "A new Bancho update is available and the server will be restarted in 5 seconds. Thank you for your patience.")
|
|
|
|
|
|
|
|
# Status code and message
|
|
|
|
statusCode = 200
|
|
|
|
data["message"] = "ok"
|
|
|
|
except exceptions.invalidArgumentsException:
|
|
|
|
statusCode = 400
|
|
|
|
data["message"] = "invalid ci key"
|
|
|
|
finally:
|
|
|
|
# Add status code to data
|
|
|
|
data["status"] = statusCode
|
|
|
|
|
|
|
|
# Send response
|
2016-06-16 12:57:54 +00:00
|
|
|
self.write(json.dumps(data))
|
2016-06-02 20:33:39 +00:00
|
|
|
self.set_status(statusCode)
|