From 72f72d64a422d6628c4796f5c0bf2e508f134214 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Wed, 4 May 2011 16:05:14 +0900 Subject: Adding upstream version 0.5.1 --- Bonus/2ch.cgi | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100755 Bonus/2ch.cgi (limited to 'Bonus/2ch.cgi') diff --git a/Bonus/2ch.cgi b/Bonus/2ch.cgi new file mode 100755 index 0000000..998c202 --- /dev/null +++ b/Bonus/2ch.cgi @@ -0,0 +1,204 @@ +#!/usr/bin/perl + +$WGET = "wget"; +$SCRIPT_NAME = $ENV{'SCRIPT_NAME'} || $0; +$CGI = "file://$SCRIPT_NAME"; +$_ = $QUERY_STRING = $ENV{"QUERY_STRING"}; +$UserAgent = "Monazilla/1.00 (w3m/2ch.cgi)"; + +if (/subback.html$/) { + &subback(); + exit; +} + +s@/(\d+)(/([^/]*))?$@/$1@ || exit; +my $datnum = $1; +$label = $3; +$cgi = "$CGI?$_"; + +s@^http://([^/]+)/test/read.cgi/([^/]+)/@$1/$2/dat/@ || exit; +$subback = "$CGI?http://$1/$2/subback.html"; +$bbs = $2; +if ($ENV{REQUEST_METHOD} eq "POST") { + &post(); + exit; +} + +$_ .= ".dat"; +$dat = "http://$_"; +$tmp = $ENV{"HOME"} . "/.w3m2ch/$_"; +$dat =~ s/([^\w\/.\:\-])/\\$1/g; +$tmp =~ s/([^\w\/.\:\-])/\\$1/g; +($dir = $tmp) =~ s@/[^/]+$@@; +$cmd = "mkdir -p $dir; $WGET -c -U \"$UserAgent\" -O $tmp $dat >/dev/null 2>&1"; +system $cmd; +$lines = (split(" ", `wc $tmp`))[0]; +$lines || exit; + +@ARGV = ($tmp); +if ($label =~ /^l(\d+)/) { + $start = $lines - $1 + 1; + if ($start < 1) { + $start = 1; + } + $end = $lines; +} elsif ($label =~ /^(\d+)-(\d+)/) { + $start = $1; + $end = $2; +} elsif ($label =~ /^(\d+)-/) { + $start = $1; + $end = $start + 100 - 1; +} elsif ($label =~ /^(\d+)/) { + $start = $1; + $end = $1; +} else { + $start = 1; + $end = $lines; +} +$head = "■掲示板に戻る■\n"; +$head .= "全部\n"; +for (0 .. ($lines - 1) / 100) { + $n = $_ * 100 + 1; + $head .= "$n-\n"; +} +$head .= "最新50\n"; +print <) { + s/\r?\n$//; + ($name, $mail, $date, $_, $title) = split(/\<\>/); + if ($i == 1) { + if (!$title) { + print < +$QUERY_STRING +EOF + unlink($tmp); + exit + } + print <$title +$head +

$title

+
+EOF + } + if ($mail) { + $name = "$name"; + } + s@http://ime.nu/@http://@g; + s@(h?ttp:)([#-~]+)@"$1$2"@ge; + s@(ftp:[#-~]+)@$1@g; + s@= $start && $i <= $end)) { + print <$i :$name:$date +
+$_ +

+EOF + } + $i++; +} +print < +


+
名前: E-mail (省略可) :
+EOF + +sub link { + local($_) = @_; + if (m@/test/read.cgi/@) { + return "$CGI?$_"; + } + return $_; +} + +sub subback { + $dat = $_; + s@http://@@ || exit; + $tmp = $ENV{"HOME"} . "/.w3m2ch/$_"; + $dat =~ s/([^\w\/.\:\-])/\\$1/g; + $tmp =~ s/([^\w\/.\:\-])/\\$1/g; + ($dir = $tmp) =~ s@/[^/]+$@@; + $cmd = "mkdir -p $dir; $WGET -O $tmp $dat >/dev/null 2>&1"; + system $cmd; +print <) { + if (/; + $QUERY_STRING =~ m@^http://([^/]+)@; + my $host = $1; + my $sock = IO::Socket::INET->new("$host:80") or die; + # retrieve posting cookie; this may not work + print "Content-Type: text/html\n\n"; + print $sock + "HEAD /test/bbs.cgi HTTP/1.1\n", + "Host: $host\n", + "Connection: keep-alive\n", + "\n"; + my $posting_cookie = undef; + while (<$sock>) { + print if ($debug); + s/[\n\r]+$//; + last if (/^$/); + if (/^set-cookie:.*(PON=[^;]+)/i) { + $posting_cookie = $1; + } + } + #$sock = IO::Socket::INET->new("$host:80") or die; + my $submit = + "POST /test/bbs.cgi HTTP/1.1\n" . + "Host: $host\n" . + "Accept-Language: ja\n" . + "User-Agent: $UserAgent\n" . + "Referer: $QUERY_STRING\n" . + "Cookie: $posting_cookie; NAME=nobody; MAIL=sage\n" . + "Content-Length: " . length(join("", @POST)) . "\n" . + "\n@POST"; + print $sock $submit or die; + print "\n-- POSTed contents --\n${submit}\n-- POSTed contents --\n" + if ($debug); + my $chunked = 0; + while (<$sock>) { + s/[\n\r]*$//; + last if (/^$/); + $chunked = 1 if (/^transfer-encoding:\s*chunked/i); + } + my $post_response = ""; + while (<$sock>) { + if ($chunked) { + s/[ \r\n]*$//; + my $len = hex($_); + $len > 0 or last; + read($sock, $_, $len); + <$sock>; #skip empty line at the end of chunk. + } + $post_response .= $_; + } + $post_response =~ s///im; + print $post_response; + exit; +} -- cgit v1.2.3 From 1d0ba25a660483da1272a31dd077ed94441e3d9f Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Sat, 2 Jan 2021 09:20:37 +0900 Subject: New upstream version 0.5.3+git20210102 --- Bonus/2ch.cgi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Bonus/2ch.cgi') diff --git a/Bonus/2ch.cgi b/Bonus/2ch.cgi index 998c202..c52ad8d 100755 --- a/Bonus/2ch.cgi +++ b/Bonus/2ch.cgi @@ -63,7 +63,7 @@ for (0 .. ($lines - 1) / 100) { } $head .= "最新50\n"; print <new("$host:80") or die; # retrieve posting cookie; this may not work - print "Content-Type: text/html\n\n"; + print "Content-Type: text/html; charset=Shift_JIS\n\n"; print $sock "HEAD /test/bbs.cgi HTTP/1.1\n", "Host: $host\n", -- cgit v1.2.3