• R/O
  • SSH
  • HTTPS

o2on: Commit


Commit MetaInfo

Revision173 (tree)
Zeit2009-09-30 17:47:33
Autornawota

Log Message

Proxy Server: POST に対応
Admin Server: /dats を実装
lib/o2on_dat: class dat に title を取得する関数 title を追加
強制終了時に強制終了するスレッドの名前を表示

Ändern Zusammenfassung

Diff

--- trunk/opy2on/lib/o2on_server.py (revision 172)
+++ trunk/opy2on/lib/o2on_server.py (revision 173)
@@ -162,7 +162,7 @@
162162 for r in remove:
163163 if r in hr: del hr[r]
164164 conn = httplib.HTTPConnection(loc)
165- conn.request("GET",p.path, None, hr)
165+ conn.request(self.command, p.path, self.rfile.read(), hr)
166166 return conn
167167 def msg(self,r):
168168 res = ''
@@ -215,13 +215,17 @@
215215 m = re.compile(r'^.*<>.*<>.*<>.*<>(.*)$').match(first)
216216 if not m: return ""
217217 return m.group(1)
218+ def do_POST(self):
219+ self.do_GET()
218220 def do_GET(self):
219221 logger = self.server.glob.logger
220222 logger.log("PROXY", "proxy requested %s" % self.path)
221223 ut = self.urltype()
222224 if ut in (self.URLTYPE_UNKNOWN, self.URLTYPE_NORMAL, self.URLTYPE_MACHI):
225+ # 普通のプロキシとして動作
223226 self.normal_proxy()
224227 return
228+ # datがリクエストされた
225229 try:
226230 conn = self.get_connection()
227231 r= conn.getresponse()
@@ -235,6 +239,7 @@
235239 if r and ut != self.URLTYPE_OFFLAW and r.status in (200,206,304):
236240 logger.log("PROXY", "\tgot response from server")
237241 data = r.read()
242+ # gzipをdecode
238243 if r.getheader("content-encoding") == "gzip":
239244 sf = StringIO.StringIO(data)
240245 dec = gzip.GzipFile(fileobj=sf)
@@ -891,6 +896,50 @@
891896 </div>
892897 """)
893898 self.wfile.write(self.html_footer)
899+ def dats(self, args):
900+ self.send_common("dats", "Dat")
901+ if len(args)==0:
902+ regBoard = re.compile(r'^\t[^\t.]+\.([^\t]+)\t([^\t]+)\t([^\t]+)$')
903+ inul = False
904+ f=open(o2on_config.Path2channel_brd)
905+ for line in f:
906+ m = regBoard.match(line)
907+ if m:
908+ boardname = m.group(3).decode('cp932').encode('utf-8')
909+ if os.path.exists(os.path.join(o2on_config.DatDir,
910+ m.group(1), m.group(2))):
911+ self.wfile.write("<li><a href=\"/dats/%s/%s\">%s</a></li>\n" % \
912+ (m.group(1), m.group(2), boardname))
913+ else:
914+ self.wfile.write("<li>%s</li>\n" % boardname)
915+ else:
916+ pos = line.find("\t")
917+ if pos == -1: continue
918+ if inul: self.wfile.write("</ul>\n")
919+ else: self.wfile.write("<ul>\n")
920+ inul = True
921+ self.wfile.write("<li>%s<ul>\n" % \
922+ (line[:pos].decode("cp932").encode('utf-8')))
923+ f.close()
924+ self.wfile.write("</ul>\n")
925+ self.wfile.write(self.html_footer)
926+ elif len(args)==2:
927+ regdat = re.compile('^(\d+)\.dat(?:\.gz)?$')
928+ self.wfile.write("<table><tr><th>スレタイ</th><th>URL</th></tr>")
929+ for root,dirs,files in os.walk(os.path.join(o2on_config.DatDir,
930+ args[0],
931+ args[1])):
932+ for f in files:
933+ m=regdat.match(f)
934+ path = args[0]+"/"+args[1]+"/"+m.group(1)
935+ dkhash = o2on_util.datkeyhash(path)
936+ dat = self.server.glob.datdb.get(dkhash)
937+ if dat:
938+ self.wfile.write("<tr><td>%s</td><td>http://xxx.%s/test/read.cgi/%s/%s/</td>\n" % \
939+ (dat.title() or "Unknown Title",
940+ args[0], args[1], m.group(1)))
941+ self.wfile.write("</table>\n")
942+ self.wfile.write(self.html_footer)
894943 def status(self,args):
895944 self.send_common("status", "Status Summary")
896945 glob = self.server.glob
--- trunk/opy2on/lib/o2on_dat.py (revision 172)
+++ trunk/opy2on/lib/o2on_dat.py (revision 173)
@@ -52,6 +52,27 @@
5252 return os.path.join(o2on_config.DatDir, self.domain, self.board,
5353 self.datnum[:4],self.datnum+".dat")
5454 raise Exception
55+ def title(self):
56+ dp = self.datpath()
57+ if os.path.exists(dp): f=open(dp)
58+ elif os.path.exists(dp+".gz"): f=gzip.GzipFile(dp+".gz")
59+ else: f=None
60+ if f:
61+ first=f.readline()
62+ f.close()
63+ m = re.compile(r'^.*<>.*<>.*<>.*<>(.*)$').match(first)
64+ if not m: return None
65+ try:
66+ first = first.decode('cp932').encode('utf-8')
67+ except UnicodeDecodeError, inst:
68+ try:
69+ first = first.decode('euc_jp').encode('utf-8')
70+ except UnicodeDecodeError, inst:
71+ first = first.decode('cp932','opy2on_replace').encode('utf-8')
72+ m = re.compile(r'^.*<>.*<>.*<>.*<>(.*)$').match(first)
73+ if not m: return None
74+ return m.group(1)
75+ return None
5576 def data(self):
5677 dp = self.datpath()
5778 if os.path.exists(dp): f=open(dp)
--- trunk/opy2on/opy2on.py (revision 172)
+++ trunk/opy2on/opy2on.py (revision 173)
@@ -196,7 +196,7 @@
196196 shutcount += 1
197197 if o2on_config.ForceShutdown != None and \
198198 o2on_config.ForceShutdown / 8 < shutcount:
199- glob.logger.popup("GLOBAL", "Force Shutdown")
199+ glob.logger.popup("GLOBAL", "Force Shutdown %s" % j.name)
200200 j.shutdown()
201201 c += 1
202202 glob.logger.log("GLOBAL", "Finished %d/%d" % (c, n))
Show on old repository browser