示例#1
0
    def asyncPost(self):
        try:
            if glob.debug:
                requestsManager.printArguments(self)

            # Make sure screenshot file was passed
            if "ss" not in self.request.files:
                raise exceptions.invalidArgumentsException(MODULE_NAME)

            # Check user auth because of sneaky people
            if not requestsManager.checkArguments(self.request.arguments,
                                                  ["u", "p"]):
                raise exceptions.invalidArgumentsException(MODULE_NAME)
            username = self.get_argument("u")
            password = self.get_argument("p")
            ip = self.getRequestIP()
            userID = userUtils.getID(username)
            if not verify_password(userID, password):
                raise exceptions.loginFailedException(MODULE_NAME, username)
            if not userUtils.checkBanchoSession(userID, ip):
                raise exceptions.noBanchoSessionException(
                    MODULE_NAME, username, ip)

            # Rate limit
            if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
                return self.write("no")
            glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

            while os.path.exists(
                    path := BASE_PATH.format(generalUtils.randomString(8))):
                pass
示例#2
0
    def asyncGet(self):
        try:
            requestsManager.printArguments(self)

            # Check user auth because of sneaky people
            if not requestsManager.checkArguments(self.request.arguments,
                                                  ["u", "h"]):
                raise exceptions.invalidArgumentsException(MODULE_NAME)
            username = self.get_argument("u")
            password = self.get_argument("h")
            userID = userUtils.getID(username)
            if not userUtils.checkLogin(userID, password):
                raise exceptions.loginFailedException(MODULE_NAME, username)

            beatmapSetId = int(self.get_argument("s"))
            beatmapIds = self.get_argument("b").split(',')
            oldOsz2Hash = self.get_argument("z")

            if userID != 1000:
                return self.write(
                    return_errorcode(5, "f**k you, you are NOT Xxdstem"))
            glob.db.execute(
                "DELETE FROM gatari_beatmapsets WHERE user_id = {} AND active = -1"
                .format(userID))
            bmInfo = fetch_info(beatmapSetId, False)
            if beatmapSetId > 0 and bmInfo is not None:
                if authenticate_creator(userID, bmInfo["user_id"],
                                        username) == False:
                    return self.write(return_errorcode(1, ""))
                if (bmInfo["ranked"] > 0
                        and has_special_permissions(username) == False):
                    return self.write(return_errorcode(3, ""))
            else:
                uploadcap = check_remaining_uploadcap(userID)
                if (uploadcap == 0):
                    return self.write(
                        return_errorcode(
                            6, "You have exceeded your submission cap"))
                if (uploadcap == -1):
                    return self.write(
                        return_errorcode(6,
                                         "Only druzhbans can submit beatmaps"))
                beatmapSetId = create_beatmapset(userID, username)
                newSubmit = True

            serverHash = get_osz2_file_hash(beatmapSetId)
            fullSubmit = newSubmit or oldOsz2Hash == "0" or serverHash is None or serverHash != oldOsz2Hash
            self.write("0\n\
				{}\n\
				{}\n\
				{}\n\
				{}\n\
				0\n\
				{}".format(beatmapSetId, self.get_argument("b"),
               "1" if fullSubmit == True else "2", int(uploadcap), 0))

        except exceptions.invalidArgumentsException:
            pass
        except exceptions.loginFailedException:
            pass
示例#3
0
    def asyncPost(self):
        try:
            if glob.debug:
                requestsManager.printArguments(self)

            # Make sure screenshot file was passed
            if "ss" not in self.request.files:
                raise exceptions.invalidArgumentsException(MODULE_NAME)

            # Check user auth because of sneaky people
            if not requestsManager.checkArguments(self.request.arguments,
                                                  ["u", "p"]):
                raise exceptions.invalidArgumentsException(MODULE_NAME)
            username = self.get_argument("u")
            password = self.get_argument("p")
            ip = self.getRequestIP()
            userID = userUtils.getID(username)
            if not userUtils.checkLogin(userID, password):
                raise exceptions.loginFailedException(MODULE_NAME, username)
            if userUtils.check2FA(userID, ip):
                raise exceptions.need2FAException(MODULE_NAME, username, ip)

            # Rate limit
            if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
                self.write("no")
                return
            glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

            # Get a random screenshot id
            found = False
            screenshotID = ""
            while not found:
                screenshotID = generalUtils.randomString(8)
                if not os.path.isfile(
                        ".data/screenshots/{}.png".format(screenshotID)):
                    found = True
                    glob.db.execute(
                        "INSERT INTO screenshots (userid, ssid, sstime) VALUES (%s, %s, %s)",
                        [userID, screenshotID,
                         int(time.time())])

            # Write screenshot file to .data folder
            with open(".data/screenshots/{}.png".format(screenshotID),
                      "wb") as f:
                f.write(self.request.files["ss"][0]["body"])

            # Output
            log.info("New screenshot ({})".format(screenshotID))

            # Return screenshot link
            self.write("{}/ss/{}.png".format(
                glob.conf.config["server"]["serverurl"], screenshotID))
        except exceptions.need2FAException:
            pass
        except exceptions.invalidArgumentsException:
            pass
        except exceptions.loginFailedException:
            pass
示例#4
0
	def asyncPost(self):
		try:
			if glob.debug:
				requestsManager.printArguments(self)

			# Make sure screenshot file was passed
			if "ss" not in self.request.files:
				raise exceptions.invalidArgumentsException(MODULE_NAME)

			# Check user auth because of sneaky people
			if not requestsManager.checkArguments(self.request.arguments, ["u", "p"]):
				raise exceptions.invalidArgumentsException(MODULE_NAME)
			username = self.get_argument("u")
			password = self.get_argument("p")
			userID = userUtils.getID(username)
			if not userUtils.checkLogin(userID, password):
				raise exceptions.loginFailedException(MODULE_NAME, username)
			if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
				self.write("no")
				return
			glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)
			# Get a random screenshot id
			found = False
			screenshotID = ""
			while not found:
				screenshotID = generalUtils.randomString(8)
				if not os.path.isfile(".data/screenshots/{}.jpg".format(screenshotID)):
					found = True

			# Write screenshot file to .data folder
			with open(".data/screenshots/{}.jpg".format(screenshotID), "wb") as f:
				f.write(self.request.files["ss"][0]["body"])

			# Output
			log.info("New screenshot ({})".format(screenshotID))

			# Return screenshot link
			self.write("{}/ss/{}.jpg".format("https://osu.gatari.pw", screenshotID))
		except exceptions.invalidArgumentsException:
			pass
		except exceptions.loginFailedException:
			pass
示例#5
0
	def asyncPost(self):
		try:
			if glob.debug:
				requestsManager.printArguments(self)

			# Check user auth because of sneaky people
			if not requestsManager.checkArguments(self.request.arguments, ["u", "h", "action"]):
				raise exceptions.invalidArgumentsException(MODULE_NAME)

			username = self.get_argument("u")
			password = self.get_argument("h")
			action = self.get_argument("action")
			ip = self.getRequestIP()
			userID = userUtils.getID(username)
			if not userUtils.checkLogin(userID, password):
				raise exceptions.loginFailedException(MODULE_NAME, username)
			if userUtils.check2FA(userID, ip):
				raise exceptions.need2FAException(MODULE_NAME, username, ip)

			if action != "submit":
				log.debug("{} didn't send anything like \"submit\" to the server".format(username))
				self.write("ok")
				return

			content = self.get_argument("content")
			try:
				contentDict = json.loads(content)
				session.setUserSession(userID, contentDict)
				log.debug("Good, We got {} from {}".format(content, username))
				self.write("ok")
			except:
				self.write("Not yet")

			return
		except exceptions.need2FAException:
			pass
		except exceptions.invalidArgumentsException:
			pass
		except exceptions.loginFailedException:
			pass
示例#6
0
    def asyncPost(self):
        try:
            if glob.debug:
                requestsManager.printArguments(self)

            # Check user auth because of sneaky people
            if not requestsManager.checkArguments(self.request.arguments,
                                                  ["u", "h", "action"]):
                raise exceptions.invalidArgumentsException(MODULE_NAME)

            username = self.get_argument("u")
            password = self.get_argument("h")
            action = self.get_argument("action")
            ip = self.getRequestIP()
            userID = userUtils.getID(username)
            if not userUtils.checkLogin(userID, password):
                raise exceptions.loginFailedException(MODULE_NAME, username)
            if userUtils.check2FA(userID, ip):
                raise exceptions.need2FAException(MODULE_NAME, username, ip)

            if action != "submit":
                self.write("Yield")
                return

            content = self.get_argument("content")
            try:
                contentDict = json.loads(content)
                kotrikhelper.setUserSession(userID, contentDict)
                self.write("Yield")
            except:
                self.write("Not Yet")

            return
        except exceptions.need2FAException:
            pass
        except exceptions.invalidArgumentsException:
            pass
        except exceptions.loginFailedException:
            pass
示例#7
0
	def asyncPost(self):
		try:
			if glob.debug:
				requestsManager.printArguments(self)

			# Make sure screenshot file was passed
			if "ss" not in self.request.files:
				raise exceptions.invalidArgumentsException(MODULE_NAME)

			# Check user auth because of sneaky people
			if not requestsManager.checkArguments(self.request.arguments, ["u", "p"]):
				raise exceptions.invalidArgumentsException(MODULE_NAME)
			username = self.get_argument("u")
			password = self.get_argument("p")
			ip = self.getRequestIP()
			userID = userUtils.getID(username)
			if not userUtils.checkLogin(userID, password):
				raise exceptions.loginFailedException(MODULE_NAME, username)
			if userUtils.check2FA(userID, ip):
				raise exceptions.need2FAException(MODULE_NAME, username, ip)

			# Rate limit
			if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
				self.write("no")
				return
			glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

			# Get a random screenshot id
			found = False
			screenshotID = ""
			while not found:
				screenshotID = generalUtils.randomString(8)
				if not os.path.isfile(".data/screenshots/{}.png".format(screenshotID)):
					found = True

			# Write screenshot file to .data folder
			with open(".data/screenshots/{}.png".format(screenshotID), "wb") as f:
				f.write(self.request.files["ss"][0]["body"])

			# Add Akatsuki's watermark
			base_screenshot = Image.open('.data/screenshots/{}.png'.format(screenshotID))
			watermark = Image.open('constants/watermark.png')
			width, height = base_screenshot.size

			position = (width - 330, height - 200)

			transparent = Image.new('RGBA', (width, height), (0,0,0,0))
			transparent.paste(base_screenshot, (0,0))
			transparent.paste(watermark, position, mask=watermark)
			transparent.show()
			transparent.save('.data/screenshots/{}.png'.format(screenshotID))

			# Output
			log.info("New screenshot ({})".format(screenshotID))

			# Return screenshot link
			self.write("{}/ss/{}.png".format(glob.conf.config["server"]["servername"], screenshotID))
		except exceptions.need2FAException:
			pass
		except exceptions.invalidArgumentsException:
			pass
		except exceptions.loginFailedException:
			pass
示例#8
0
    def asyncPost(self):
        try:
            if glob.debug:
                requestsManager.printArguments(self)

            # Make sure screenshot file was passed
            if "ss" not in self.request.files:
                raise exceptions.invalidArgumentsException(MODULE_NAME)

            # Check user auth because of sneaky people
            if not requestsManager.checkArguments(self.request.arguments,
                                                  ["u", "p"]):
                raise exceptions.invalidArgumentsException(MODULE_NAME)
            username = self.get_argument("u")
            password = self.get_argument("p")
            ip = self.getRequestIP()
            userID = userUtils.getID(username)
            if not userUtils.checkLogin(userID, password):
                raise exceptions.loginFailedException(MODULE_NAME, username)
            if userUtils.check2FA(userID, ip):
                raise exceptions.need2FAException(MODULE_NAME, username, ip)

            # Rate limit
            if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
                self.write("no")
                return
            glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

            #check if user folder exist
            screenshotID = generalUtils.randomString(8)
            if not os.path.isdir("{}/{}/".format(
                    glob.conf.config["server"]["storagepath"], userID)):
                os.mkdir("{}/{}/".format(
                    glob.conf.config["server"]["storagepath"], userID))

            # Get a random screenshot id
            found = False
            screenshotID = ""
            while not found:
                screenshotID = generalUtils.randomString(8)
                if not os.path.isfile("{}/{}/{}.jpg".format(
                        glob.conf.config["server"]["storagepath"], userID,
                        screenshotID)):
                    found = True

            # Write screenshot file to screenshots folder
            with open(
                    "{}/{}/{}.jpg".format(
                        glob.conf.config["server"]["storagepath"], userID,
                        screenshotID), "wb") as f:
                f.write(self.request.files["ss"][0]["body"])

            # Output
            log.info("New screenshot ({})".format(screenshotID))

            # Return screenshot link
            self.write("https://storage.aeris-dev.pw/get/{}/{}.jpg".format(
                userID, screenshotID))
        except exceptions.need2FAException:
            pass
        except exceptions.invalidArgumentsException:
            pass
        except exceptions.loginFailedException:
            pass
示例#9
0
    def asyncPost(self):
        try:
            if glob.conf["DEBUG"]:
                requestsManager.printArguments(self)

            # Make sure screenshot file was passed
            if "ss" not in self.request.files:
                raise exceptions.invalidArgumentsException(MODULE_NAME)

            # Check user auth because of sneaky people
            if not requestsManager.checkArguments(self.request.arguments,
                                                  ["u", "p"]):
                raise exceptions.invalidArgumentsException(MODULE_NAME)
            username = self.get_argument("u")
            password = self.get_argument("p")
            ip = self.getRequestIP()
            userID = userUtils.getID(username)
            if not userUtils.checkLogin(userID, password):
                raise exceptions.loginFailedException(MODULE_NAME, username)
            if userUtils.check2FA(userID, ip):
                raise exceptions.need2FAException(MODULE_NAME, username, ip)

            # Rate limit
            if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
                self.write("no")
                return
            glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

            # Get a random screenshot id
            hasS3 = bool(glob.conf["S3_SCREENSHOTS_BUCKET"]) \
             and bool(glob.conf["S3_SCREENSHOTS_REGION"]) \
             and bool(glob.conf["S3_SCREENSHOTS_ENDPOINT_URL"])
            found = False
            screenshotID = ""
            while not found:
                screenshotID = generalUtils.randomString(8)
                if hasS3:
                    try:
                        glob.threadScope.s3Screenshots.head_object(
                            Bucket=glob.conf["S3_SCREENSHOTS_BUCKET"],
                            Key=f"{screenshotID}.jpg")
                        found = False
                    except botocore.errorfactory.ClientError:
                        found = True
                else:
                    found = not os.path.isfile("{}/{}.jpg".format(
                        glob.conf["SCREENSHOTS_FOLDER"], screenshotID))

            # Output
            log.info("New screenshot ({})".format(screenshotID))

            # Write screenshot file to .data folder
            if hasS3:
                with io.BytesIO(self.request.files["ss"][0]["body"]) as f:
                    glob.threadScope.s3Screenshots.upload_fileobj(
                        f,
                        glob.conf["S3_SCREENSHOTS_BUCKET"],
                        f"{screenshotID}.jpg",
                        ExtraArgs={"ACL": "public-read"})
            else:
                with open(
                        "{}/{}.jpg".format(glob.conf["SCREENSHOTS_FOLDER"],
                                           screenshotID), "wb") as f:
                    f.write(self.request.files["ss"][0]["body"])

            # Return screenshot link
            self.write("{}/ss/{}.jpg".format(glob.conf["SERVER_URL"],
                                             screenshotID))
        except exceptions.need2FAException:
            pass
        except exceptions.invalidArgumentsException:
            pass
        except exceptions.loginFailedException:
            pass