Made flipnote downloads work, made connectivity test work and minor cleanup

This commit is contained in:
pbsds committed 2014-01-28 16:06:03 +01:00
1 parent 0dcd21320f
commit 0440af3ba0
7 files changed
+34 -247

No files matched your search

+4 -1
View File
@@ -5,10 +5,13 @@
*.pyo *.pyo
*.lnk *.lnk
#is emberrasing... :3
todo.txt
#Don't need all of these on github #Don't need all of these on github
logs logs
#not yet ready, this wil be put up on the wiki section later #not for the public eye, this will be put up on the wiki section as i clean it up.
documentation documentation
#temp file #temp file
+15 -1
View File
@@ -6,7 +6,7 @@ from Hatenatools import *#UGO, PPM, TMB and NTFT
ServerLog = None#Is set to the log class by server.py ServerLog = None#Is set to the log class by server.py
Silent = False Silent = False
def Log(request, path=None): def Log(request, path=None, silent=Silent):
if not path: if not path:
path = "\"%s\"" % request.path path = "\"%s\"" % request.path
ServerLog.write("%s requested %s" % (request.getClientIP(), path), Silent) ServerLog.write("%s requested %s" % (request.getClientIP(), path), Silent)
@@ -30,6 +30,15 @@ class NotFound(resource.Resource):
request.setResponseCode(404) request.setResponseCode(404)
return "404 - Not Found\nThis proxy is only for Flipnote Hatena for the DSi." return "404 - Not Found\nThis proxy is only for Flipnote Hatena for the DSi."
NotFound = NotFound() NotFound = NotFound()
class ConnectionTest(resource.Resource):#used for people setting up the proxy in their DSi. It's nice to see it's actually working.
#http://conntest.nintendowifi.net/
isLeaf = True
def render(self, request):
ServerLog.write("%s performed a connection test" % request.getClientIP(), True)
request.responseHeaders.setRawHeaders('X-Organization', ['Nintendo'])#i hope this isn't illegal...
return '<html><head><title>HTML Page</title></head><body bgcolor="#FFFFFF">This is test.html page</body></html>'
ConnectionTest = ConnectionTest()
#Root structure: #Root structure:
class Root(resource.Resource):#filters out non-hantena clients class Root(resource.Resource):#filters out non-hantena clients
@@ -42,6 +51,9 @@ class Root(resource.Resource):#filters out non-hantena clients
self.imagesResource = static.File("hatenadir/images/") self.imagesResource = static.File("hatenadir/images/")
def getChild(self, name, request): def getChild(self, name, request):
if "x-dsi-sid" not in request.getAllHeaders(): if "x-dsi-sid" not in request.getAllHeaders():
if "host" in request.getAllHeaders():
if request.getAllHeaders()["host"] == "conntest.nintendowifi.net":
return ConnectionTest
return AccessDenied return AccessDenied
if name == "ds": if name == "ds":
@@ -56,6 +68,8 @@ class Root(resource.Resource):#filters out non-hantena clients
#return NotFound #return NotFound
return self return self
def render(self, request): def render(self, request):
if request.getHost() == "conntest.nintendowifi.net":
return ConnectionTest
Log(request, "root") Log(request, "root")
return "Welcome to hatena.pbsds.net!\nThis is in early stages, so please don't expect too much." return "Welcome to hatena.pbsds.net!\nThis is in early stages, so please don't expect too much."
class ds(resource.Resource):#child of Root class ds(resource.Resource):#child of Root
@@ -13,7 +13,7 @@ class PyResource(resource.Resource):
self.pages = []#10 first pages self.pages = []#10 first pages
self.newestview = None self.newestview = None
self.Update() reactor.callLater(2, self.Update)#or it'll clash with hotmovies.ugo
def render(self, request): def render(self, request):
page = int(request.args["page"][0]) if "page" in request.args else 1 page = int(request.args["page"][0]) if "page" in request.args else 1
@@ -49,7 +49,7 @@ class PyResource(resource.Resource):
pages.append(self.MakePage(flipnotes[i*50:i*50+50], i+1, i<pagecount-1, flipcount)) pages.append(self.MakePage(flipnotes[i*50:i*50+50], i+1, i<pagecount-1, flipcount))
if self.pages:#not on startup if self.pages:#not on startup
print time.strftime("[%H:%M:%S] Updated hotmovies.ugo") print time.strftime("[%H:%M:%S] Updated likedmovies.ugo")
self.pages = pages self.pages = pages
def MakePage(self, flipnotes, page, next, count): def MakePage(self, flipnotes, page, next, count):
ugo = UGO() ugo = UGO()
+13 -7
View File
@@ -10,7 +10,7 @@ class PyResource(resource.Resource):
def __init__(self): def __init__(self):
resource.Resource.__init__(self) resource.Resource.__init__(self)
self.CreatorID = CreatorID() self.CreatorID = CreatorIDResource()
def getChild(self, name, request): def getChild(self, name, request):
if Database.CreatorExists(name): if Database.CreatorExists(name):
return self.CreatorID return self.CreatorID
@@ -23,12 +23,12 @@ class PyResource(resource.Resource):
return "403 - Denied access" return "403 - Denied access"
#The creator ID folder: #The creator ID folder:
class CreatorID(resource.Resource): class CreatorIDResource(resource.Resource):
isLeaf = False isLeaf = False
def __init__(self): def __init__(self):
resource.Resource.__init__(self) resource.Resource.__init__(self)
self.CreatorIDFile = CreatorIDFile() self.CreatorIDFile = CreatorIDFileResource()
def getChild(self, name, request): def getChild(self, name, request):
CreatorID = request.path.split("/")[-2] CreatorID = request.path.split("/")[-2]
filename = ".".join(name.split(".")[:-1]) filename = ".".join(name.split(".")[:-1])
@@ -44,7 +44,7 @@ class CreatorID(resource.Resource):
return "403 - Denied access" return "403 - Denied access"
#Any public file inside creator ID folder: #Any public file inside creator ID folder:
class CreatorIDFile(resource.Resource): class CreatorIDFileResource(resource.Resource):
isLeaf = True isLeaf = True
def __init__(self): def __init__(self):
resource.Resource.__init__(self) resource.Resource.__init__(self)
@@ -52,13 +52,13 @@ class CreatorIDFile(resource.Resource):
creator, file = request.path.split("/")[-2:] creator, file = request.path.split("/")[-2:]
filetype = file.split(".")[-1].lower() filetype = file.split(".")[-1].lower()
if filetype == "ppm": if filetype in "ppm":
#log it: #log it:
path = "/".join(request.path.split("/")[3:]) path = "/".join(request.path.split("/")[3:])
Log(request, path) Log(request, path)
#add a view: #add a view:
Database.AddView(creator, file[:-4]) Database.AddView(creator, file[:4])
#read ppm file: #read ppm file:
f = open(Database.FlipnotePath(creator, file), "rb") f = open(Database.FlipnotePath(creator, file), "rb")
@@ -70,7 +70,7 @@ class CreatorIDFile(resource.Resource):
return data return data
elif filetype == "info": elif filetype == "info":
path = "/".join(request.path.split("/")[3:]) path = "/".join(request.path.split("/")[3:])
Log(request, path) Log(request, path, True)
request.responseHeaders.setRawHeaders('content-type', ['text/plain']) request.responseHeaders.setRawHeaders('content-type', ['text/plain'])
return "0\n0\n"#undocumented what it means return "0\n0\n"#undocumented what it means
elif filetype == "htm": elif filetype == "htm":
@@ -101,6 +101,12 @@ class CreatorIDFile(resource.Resource):
#report success #report success
ServerLog.write("%s added %i stars to %s/%s.ppm" % (request.getClientIP(), amount, creator, file[:-5]), Silent) ServerLog.write("%s added %i stars to %s/%s.ppm" % (request.getClientIP(), amount, creator, file[:-5]), Silent)
return "Success" return "Success"
elif filetype == "dl":
path = "/".join(request.path.split("/")[3:])
Log(request, path, True)
#this is POSTed to when it've been downloaded.
#todo: keep count
return "Noted ;)"#muhahaha!
else: else:
path = "/".join(request.path.split("/")[3:]) path = "/".join(request.path.split("/")[3:])
ServerLog.write("%s got 403 when requesting %s" % (request.getClientIP(), path), Silent) ServerLog.write("%s got 403 when requesting %s" % (request.getClientIP(), path), Silent)
View File
Whitespace-only changes.
-222
View File
@@ -1,222 +0,0 @@
[05:04:23] Server startup...
[05:04:25] Server shutdown
[14:39:12] Server startup...
[14:39:40] 192.168.0.2 requested en/eula.txt
[14:39:41] 192.168.0.2 requested en/confirm/upload.txt
[14:39:41] 192.168.0.2 requested en/confirm/download.txt
[14:39:42] 192.168.0.2 requested en/confirm/delete.txt
[14:39:42] 192.168.0.2 requested index.ugo
[14:39:54] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[14:40:03] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[14:40:03] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[14:40:41] Server shutdown
[14:40:41] Server startup...
[14:40:44] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[14:40:44] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[14:41:06] Server shutdown
[14:41:06] Server startup...
[14:41:09] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[14:41:10] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[14:41:32] Server shutdown
[14:41:33] Server startup...
[14:41:35] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[14:41:36] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[14:42:12] 127.0.0.1 got 404 when requesting "/ds/v2-xx/ds/movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.htm"
[14:42:13] 127.0.0.1 requested root
[14:42:44] 127.0.0.1 requested root
[14:43:29] Server shutdown
[14:43:29] Server startup...
[14:43:33] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[14:43:34] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[14:43:41] 127.0.0.1 requested root
[14:44:26] Server shutdown
[14:44:26] Server startup...
[14:44:28] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[14:44:29] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[14:45:34] Server shutdown
[14:45:34] Server startup...
[14:45:37] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[14:45:37] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[14:47:16] Server shutdown
[14:47:16] Server startup...
[14:47:18] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[14:47:19] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[14:48:13] Server shutdown
[14:48:13] Server startup...
[14:48:16] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[14:48:17] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[14:48:18] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[14:49:23] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[14:49:42] 192.168.0.2 requested movie/9E96B750A0976F76/976F76_0A5B18A4D8171_000.info
[14:49:43] 192.168.0.2 requested movie/9E96B750A0976F76/976F76_0A5B18A4D8171_000.ppm
[14:50:01] 192.168.0.2 requested movie/9F346F10CC728EA2/728EA2_096EEE4226FB1_004.info
[14:50:01] 192.168.0.2 requested movie/9F346F10CC728EA2/728EA2_096EEE4226FB1_004.ppm
[14:51:40] Server shutdown
[14:51:41] Server startup...
[14:52:01] 192.168.0.2 requested movie/9F346F10CC728EA2/728EA2_096EEE4226FB1_004.info
[14:52:01] 192.168.0.2 requested movie/9F346F10CC728EA2/728EA2_096EEE4226FB1_004.ppm
[14:52:15] 192.168.0.2 requested frontpage/hotmovies.ugo page 2
[14:52:30] 192.168.0.2 requested frontpage/hotmovies.ugo page 3
[14:52:45] 192.168.0.2 requested frontpage/hotmovies.ugo page 4
[14:53:25] 192.168.0.2 requested frontpage/hotmovies.ugo page 5
[14:54:59] Server shutdown
[14:54:59] Server startup...
[14:55:04] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[14:55:05] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[14:55:06] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[14:56:24] Server shutdown
[14:56:25] Server startup...
[14:59:09] 127.0.0.1 requested root
[15:00:14] Server shutdown
[15:00:15] Server startup...
[15:00:17] 127.0.0.1 requested root
[15:00:42] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[15:00:43] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[15:02:43] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[15:04:40] Server shutdown
[15:04:41] Server startup...
[15:04:49] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[15:04:55] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[15:04:56] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[15:05:29] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[15:10:09] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[15:10:10] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[15:14:48] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[15:17:56] Server shutdown
[15:17:57] Server startup...
[15:18:03] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[15:18:03] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[15:18:45] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[15:23:04] Server shutdown
[15:23:04] Server startup...
[15:23:12] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[15:23:12] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[15:23:18] 192.168.0.2 got 403 when requesting movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.star
[15:23:22] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[16:19:22] Server shutdown
[16:19:23] Server startup...
[16:19:32] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[16:19:33] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[16:19:44] 192.168.0.2 got 403 when requesting movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.star without a X-Hatena-Star-Count header
[16:21:53] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[16:29:56] Server shutdown
[16:29:57] Server startup...
[16:30:05] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[16:30:06] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[16:30:20] Server shutdown
[16:30:21] Server startup...
[16:31:00] Server shutdown
[16:31:01] Server startup...
[16:31:03] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[16:31:05] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.info
[16:31:05] 192.168.0.2 requested movie/930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[16:31:13] Server shutdown
[16:31:13] Server startup...
[16:31:26] Server shutdown
[16:31:26] Server startup...
[16:31:29] 192.168.0.2 added 3 stars to 930EDBE0CC6FF483/6FF483_0948E7A5F44D5_000.ppm
[16:31:30] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[16:31:56] Server shutdown
[16:31:56] Server startup...
[16:31:59] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[16:32:07] 192.168.0.2 requested movie/9EEDCBF0AA42BE29/42BE29_0A52A7C3273AE_000.info
[16:32:08] 192.168.0.2 requested movie/9EEDCBF0AA42BE29/42BE29_0A52A7C3273AE_000.ppm
[16:32:20] 192.168.0.2 added 30 stars to 9EEDCBF0AA42BE29/42BE29_0A52A7C3273AE_000.ppm
[16:32:26] 192.168.0.2 requested frontpage/hotmovies.ugo page 1
[16:32:33] Server shutdown
[16:32:33] Server startup...
[16:32:35] 192.168.0.2 requested frontpage/likedmovies.ugo page 1
[16:32:56] 192.168.0.2 requested movie/9EEDCBF0AA42BE29/42BE29_0A52A7C3273AE_000.info
[16:32:57] 192.168.0.2 requested movie/9EEDCBF0AA42BE29/42BE29_0A52A7C3273AE_000.ppm
[16:56:49] Server shutdown
[21:57:30] Server startup...
[21:57:50] 192.168.0.2 requested en/eula.txt
[21:57:51] 192.168.0.2 requested en/confirm/upload.txt
[21:57:51] 192.168.0.2 requested en/confirm/download.txt
[21:57:52] 192.168.0.2 requested en/confirm/delete.txt
[21:57:53] 192.168.0.2 requested index.ugo
[22:00:39] 213.138.175.204 requested en/eula.txt
[22:00:40] 213.138.175.204 requested en/confirm/upload.txt
[22:00:40] 213.138.175.204 requested en/confirm/download.txt
[22:00:41] 213.138.175.204 requested en/confirm/delete.txt
[22:00:41] 213.138.175.204 requested index.ugo
[22:01:35] 213.138.175.204 requested frontpage/hotmovies.ugo page 1
[22:01:38] 213.138.175.204 requested movie/913304C0CC74CC1F/74CC1F_0D376FC60C9DC_000.info
[22:01:39] 213.138.175.204 requested movie/913304C0CC74CC1F/74CC1F_0D376FC60C9DC_000.ppm
[22:03:20] Server shutdown
[22:03:26] Server startup...
[22:03:29] 213.138.175.204 requested movie/913304C0CC74CC1F/74CC1F_0D376FC60C9DC_000.info
[22:03:30] 213.138.175.204 requested movie/913304C0CC74CC1F/74CC1F_0D376FC60C9DC_000.ppm
[22:12:05] Server shutdown
[22:12:05] Server startup...
[22:12:26] 213.138.175.204 requested index.ugo
[22:12:31] 213.138.175.204 requested help/info.htm
[22:12:37] Server shutdown
[22:12:37] Server startup...
[22:12:39] 213.138.175.204 requested help/info.htm
[22:12:49] Server shutdown
[22:12:49] Server startup...
[22:12:51] 213.138.175.204 requested help/info.htm
[22:13:14] Server shutdown
[22:13:15] Server startup...
[22:13:18] 213.138.175.204 requested help/info.htm
[22:13:21] 213.138.175.204 requested inbox.ugo
[22:13:23] 213.138.175.204 requested help/info.htm
[22:15:15] Server shutdown
[22:15:15] Server startup...
[22:15:24] 213.138.175.204 requested frontpage/hotmovies.ugo page 1
[22:15:27] 213.138.175.204 requested movie/913304C0CC74CC1F/74CC1F_0D376FC60C9DC_000.info
[22:15:28] 213.138.175.204 requested movie/913304C0CC74CC1F/74CC1F_0D376FC60C9DC_000.ppm
[22:15:33] 213.138.175.204 requested help/post_howto.htm
[22:18:05] Server shutdown
[22:18:05] Server startup...
[22:18:40] 213.138.175.204 requested en/eula.txt
[22:18:41] 213.138.175.204 requested en/confirm/upload.txt
[22:18:42] 213.138.175.204 requested en/confirm/download.txt
[22:18:42] 213.138.175.204 requested en/confirm/delete.txt
[22:18:43] 213.138.175.204 requested eula_list.tsv
[22:19:30] 213.138.175.204 requested index.ugo
[22:19:37] 213.138.175.204 requested help/info.htm
[22:19:46] 213.138.175.204 requested frontpage/hotmovies.ugo page 1
[22:19:53] 213.138.175.204 requested inbox.ugo
[22:19:54] 213.138.175.204 requested help/info.htm
[22:20:26] Server shutdown
[22:20:27] Server startup...
[22:21:08] Server shutdown
[22:21:08] Server startup...
[22:22:34] Server shutdown
-14
View File
@@ -1,14 +0,0 @@
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\Python27\lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "C:\Users\pbsds\Desktop\Programming\python\hatena server\hatena.py", line 219, in write
f = open("database/Creators/%s/flipnotes.dat" % ID, "wb")
IOError: [Errno 2] No such file or directory: 'database/Creators/9EEDCBF0AA42BE29/flipnotes.dat'
Error in sys.exitfunc:
Traceback (most recent call last):
File "C:\Python27\lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "C:\Users\pbsds\Desktop\Programming\python\hatena server\hatena.py", line 219, in write
f = open("database/Creators/%s/flipnotes.dat" % ID, "wb")
IOError: [Errno 2] No such file or directory: 'database/Creators/9EEDCBF0AA42BE29/flipnotes.dat'