def render_GET(self, request):
        ServerLog.write(
            "%s got 403 when requesting post/flipnote.post with GET" %
            (request.getClientIP()), Silent)

        request.setResponseCode(405)
        return "405 - Method Not Allowed"
Example #2
0
    def render_POST(self, request):  # implement channels?
        data = request.content.read()

        channel = ""
        if "channel" in request.args:
            channel = request.args["channel"][0]

        add = Database.AddFlipnote(data, channel)
        if add:
            ServerLog.write('%s successfully uploaded "%s.ppm"' % (request.getClientIP(), add[1]), Silent)
            request.setResponseCode(200)
        else:
            ServerLog.write("%s tried to upload a flipnote, but failed..." % request.getClientIP(), Silent)
            request.setResponseCode(500)  # only causes an error, need to fix

        return ""
Example #3
0
	def render_POST(self, request):#implement channels?
		data = request.content.read()
		
		channel = ""
		if "channel" in request.args:
			channel = request.args["channel"][0]
		
		add = Database.AddFlipnote(data, channel)
		if add:
			ServerLog.write("%s successfully uploaded \"%s.ppm\"" % (request.getClientIP(), add[1]), Silent)
			request.setResponseCode(200)
		else:
			ServerLog.write("%s tried to upload a flipnote, but failed..." % request.getClientIP(), Silent)
			request.setResponseCode(500)#only causes an error, need to fix
		
		return ""
	#===
Example #4
0
    def render(self, request):
        creator, file = request.path.split("/")[-2:]
        filetype = file.split(".")[-1].lower()

        if filetype in "ppm":
            #log it:
            path = "/".join(request.path.split("/")[3:])
            Log(request, path)

            #add a view:
            Database.AddView(creator, file[:-4])

            #read ppm file:
            data = Database.GetFlipnotePPM(creator, file[:-4])

            #send file to the client:
            request.responseHeaders.setRawHeaders('content-type',
                                                  ['text/plain'])
            return data
        elif filetype == "info":
            path = "/".join(request.path.split("/")[3:])
            Log(request, path, True)
            request.responseHeaders.setRawHeaders('content-type',
                                                  ['text/plain'])
            return "0\n0\n"  #undocumented what it means
        elif filetype == "htm":
            #maybe cache the details page of Database.Newest?

            if "mode" in request.args:
                if request.args["mode"][0] == "commentshalfsize":
                    pass

            return self.GenerateDetailsPage(creator, ".".join(
                file.split(".")[:-1])).encode("UTF-8")
        elif filetype == "star":
            path = "/".join(request.path.split("/")[3:])
            headers = request.getAllHeaders()

            #bad formatting
            if "x-hatena-star-count" not in headers:
                ServerLog.write(
                    "%s got 403 when requesting %s without a X-Hatena-Star-Count header"
                    % (request.getClientIP(), path), Silent)
                request.setResponseCode(403)
                return "403 - Denied access\nRequest lacks a X-Hatena-Star-Count http header"

            #add the stars:
            amount = int(headers["x-hatena-star-count"])
            if (amount < 1) or (amount > 65535):
                ServerLog.write(
                    "%s got 403 when requesting %s with an invalid X-Hatena-Star-Count header"
                    % (request.getClientIP(), path), Silent)
                request.setResponseCode(403)
                return "403 - Denied access\nRequest has an invalid X-Hatena-Star-Count http header"

            if not Database.AddStar(creator, file[:-5], amount):
                #error
                ServerLog.write(
                    "%s got 500 when requesting %s" %
                    (request.getClientIP(), path), Silent)
                request.setResponseCode(500)
                return "500 - Internal server error\nAdding the stars seem to have failed."

            #report success
            ServerLog.write(
                "%s added %i stars to %s/%s.ppm" %
                (request.getClientIP(), amount, creator, file[:-5]), Silent)
            return "Success"
        elif filetype == "dl":
            path = "/".join(request.path.split("/")[3:])
            Log(request, path, True)
            #this is POSTed to when it've been stored to memory.

            Database.AddDownload(creator, file[:-3])

            return "Noted ;)"
        else:
            path = "/".join(request.path.split("/")[3:])
            ServerLog.write(
                "%s got 403 when requesting %s" %
                (request.getClientIP(), path), Silent)

            request.setResponseCode(403)
            return "403 - Denied access"
Example #5
0
	def render(self, request):
		creator, file = request.path.split("/")[-2:]
		filetype = file.split(".")[-1].lower()
		
		if filetype in "ppm":
			#log it:
			path = "/".join(request.path.split("/")[3:])
			Log(request, path)
			
			#add a view:
			Database.AddView(creator, file[:-4])
			
			#read ppm file:
			data = Database.GetFlipnotePPM(creator, file[:-4])
			
			#send file to the client:
			request.responseHeaders.setRawHeaders('content-type', ['text/plain'])
			return data
		elif filetype == "info":
			path = "/".join(request.path.split("/")[3:])
			Log(request, path, True)
			request.responseHeaders.setRawHeaders('content-type', ['text/plain'])
			return "0\n0\n"#undocumented what it means
		elif filetype == "htm":
			#maybe cache the details page of Database.Newest?
			
			if "mode" in request.args:
				if request.args["mode"][0] == "commentshalfsize":
					pass
			
			return self.GenerateDetailsPage(creator, ".".join(file.split(".")[:-1])).encode("UTF-8")
		elif filetype == "star":
			path = "/".join(request.path.split("/")[3:])
			headers = request.getAllHeaders()
			
			#bad formatting
			if "x-hatena-star-count" not in headers:
				ServerLog.write("%s got 403 when requesting %s without a X-Hatena-Star-Count header" % (request.getClientIP(), path), Silent)
				request.setResponseCode(400)
				return "400 - Denied access\nRequest lacks a X-Hatena-Star-Count http header"
			
			#add the stars:
			amount = int(headers["x-hatena-star-count"])
			if not Database.AddStar(creator, file[:-5], amount):
				#error
				ServerLog.write("%s got 500 when requesting %s" % (request.getClientIP(), path), Silent)
				request.setResponseCode(500)
				return "500 - Internal server error\nAdding the stars seem to have failed."
			
			#report success
			ServerLog.write("%s added %i stars to %s/%s.ppm" % (request.getClientIP(), amount, creator, file[:-5]), Silent)
			return "Success"
		elif filetype == "dl":
			path = "/".join(request.path.split("/")[3:])
			Log(request, path, True)
			#this is POSTed to when it've been stored to memory.
			
			Database.AddDownload(creator, file[:-3])
			
			return "Noted ;)"
		else:
			path = "/".join(request.path.split("/")[3:])
			ServerLog.write("%s got 403 when requesting %s" % (request.getClientIP(), path), Silent)
			
			request.setResponseCode(403)
			return "403 - Denied access"
Example #6
0
    def render_GET(self, request):
        ServerLog.write("%s got 403 when requesting post/flipnote.post with GET" % (request.getClientIP()), Silent)

        request.setResponseCode(405)
        return "405 - Method Not Allowed"