Proxy Server: POST に対応
Admin Server: /dats を実装
lib/o2on_dat: class dat に title を取得する関数 title を追加
強制終了時に強制終了するスレッドの名前を表示
@@ -162,7 +162,7 @@ | ||
162 | 162 | for r in remove: |
163 | 163 | if r in hr: del hr[r] |
164 | 164 | conn = httplib.HTTPConnection(loc) |
165 | - conn.request("GET",p.path, None, hr) | |
165 | + conn.request(self.command, p.path, self.rfile.read(), hr) | |
166 | 166 | return conn |
167 | 167 | def msg(self,r): |
168 | 168 | res = '' |
@@ -215,13 +215,17 @@ | ||
215 | 215 | m = re.compile(r'^.*<>.*<>.*<>.*<>(.*)$').match(first) |
216 | 216 | if not m: return "" |
217 | 217 | return m.group(1) |
218 | + def do_POST(self): | |
219 | + self.do_GET() | |
218 | 220 | def do_GET(self): |
219 | 221 | logger = self.server.glob.logger |
220 | 222 | logger.log("PROXY", "proxy requested %s" % self.path) |
221 | 223 | ut = self.urltype() |
222 | 224 | if ut in (self.URLTYPE_UNKNOWN, self.URLTYPE_NORMAL, self.URLTYPE_MACHI): |
225 | + # 普通のプロキシとして動作 | |
223 | 226 | self.normal_proxy() |
224 | 227 | return |
228 | + # datがリクエストされた | |
225 | 229 | try: |
226 | 230 | conn = self.get_connection() |
227 | 231 | r= conn.getresponse() |
@@ -235,6 +239,7 @@ | ||
235 | 239 | if r and ut != self.URLTYPE_OFFLAW and r.status in (200,206,304): |
236 | 240 | logger.log("PROXY", "\tgot response from server") |
237 | 241 | data = r.read() |
242 | + # gzipをdecode | |
238 | 243 | if r.getheader("content-encoding") == "gzip": |
239 | 244 | sf = StringIO.StringIO(data) |
240 | 245 | dec = gzip.GzipFile(fileobj=sf) |
@@ -891,6 +896,50 @@ | ||
891 | 896 | </div> |
892 | 897 | """) |
893 | 898 | 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) | |
894 | 943 | def status(self,args): |
895 | 944 | self.send_common("status", "Status Summary") |
896 | 945 | glob = self.server.glob |
@@ -52,6 +52,27 @@ | ||
52 | 52 | return os.path.join(o2on_config.DatDir, self.domain, self.board, |
53 | 53 | self.datnum[:4],self.datnum+".dat") |
54 | 54 | 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 | |
55 | 76 | def data(self): |
56 | 77 | dp = self.datpath() |
57 | 78 | if os.path.exists(dp): f=open(dp) |
@@ -196,7 +196,7 @@ | ||
196 | 196 | shutcount += 1 |
197 | 197 | if o2on_config.ForceShutdown != None and \ |
198 | 198 | o2on_config.ForceShutdown / 8 < shutcount: |
199 | - glob.logger.popup("GLOBAL", "Force Shutdown") | |
199 | + glob.logger.popup("GLOBAL", "Force Shutdown %s" % j.name) | |
200 | 200 | j.shutdown() |
201 | 201 | c += 1 |
202 | 202 | glob.logger.log("GLOBAL", "Finished %d/%d" % (c, n)) |