スレ産の成果物を転がしておく場所です。

#contents

#br
* 保守スクリプト [#gdf4fd23]
たぶんPerl5.8+必須。ソースはUTF-8で保存すること。ライセンスはパブリックドメイン相当でおk

 #!/usr/bin/perl
 use strict;
 use warnings;
 use utf8;
 use LWP;
 use LWP::Debug qw(+);
 use HTTP::Date;
 use HTTP::Status;
 use Encode;
 
 our $VERSION = '0.01';
 my $ua = LWP::UserAgent->new(
     agent => "Monazilla/1.00 hoshu-bot.pl/$VERSION",
     cookie_jar => {},
 );
 
 sub sjis { encode('cp932', $_[0]) }
 
 sub write_something {
     my ($host, $board_key, $thread_key) = @_;
     my $name = '';
     my $mail = '';
     my $message = 'ほしゅ';
     
     REQ:
     my $res = $ua->post("http://$host/test/bbs.cgi",
         [ bbs => $board_key, key => $thread_key,
           FROM => sjis($name), mail => sjis($mail), MESSAGE => sjis($message),
           submit => sjis('書き込む'), time => 1, hana => 'mogera' ],
         Referer => "http://$host/$board_key/");
 
     for (decode('cp932', $res->content)) {
         if (/書きこみました/ || /2ch_X:true/) { print {*STDERR} "OK! :-)\n"; }
         elsif (/2ch_X:false/)                 { print {*STDERR} "maybe OK?\n"; }
         elsif (/書き込み確認/ || /2ch_X:cookie/) {
             print {*STDERR} "Cookie needed; retry\n"; goto REQ;
         } else {
             print {*STDERR} "ERROR!\n"; exit 1;
         }
     }
 }
 
 if ($0 eq __FILE__) {
     my $thread_url = $ARGV[0];
     my ($host, $board_key, $thread_key) =
         $thread_url =~ m{http://([\w.]+)/test/read\.cgi/(\w+)/(\d+)/};
     die "Usage: $0 <thread_url>"
         unless 3 == grep {defined} ($host, $board_key, $thread_key);
     
     my $interval = 60 * 15;
     my $last_modified = 0;
     
     while (1) {
         my $res = $ua->head(
             "http://${host}/${board_key}/dat/${thread_key}.dat",
             'If-Modified-Since' => time2str($last_modified));
         if ($res->code == RC_NOT_MODIFIED) {
             write_something($host, $board_key, $thread_key);
             redo;
         }
         elsif ($res->code == RC_OK) {
             $last_modified = str2time($res->header('Last-Modified'));
             my $now = str2time($res->header('Date'));
             my $wait = $last_modified + $interval - $now;
             sleep($wait > 0 ? $wait : 1);
         }
         else {
             die 'error!';
         }
     }
 }

*Write2ch(C) [#k275b774]
ライセンスは不明。
http://www8.uploader.jp/dl/vipprog/vipprog_uljp00252.zip.html

*write2ch(ShellScript) [#j784b885]
#geshi(bash){{
#!/bin/sh
#ヤター シェルスクリプトでwrite2chできたよー\(^o^)/
#License: どーでもいーよー らいせんす
version="0.10"
usage="
Usage: write2ch.sh [-h] [--help] [-n name] [--name=NAME]
         [-m MAIL] [--mail=MAIL] [--version] URL MESSAGE"
 
while test $# -gt 0; do
  case "$1" in
  -h | --help | --h*)
    echo "$usage"; exit 0 ;;
  --name=* | --n*=* )
    name=`echo \"${1}\" | sed -e 's/^[^=]*=//'`
    shift ;;
  -n | --name | --n*)
    shift
    test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
    name="$1"
    shift ;;
  --mail=* | --m*=* )
    mail=`echo \"$1\" | sed -e 's/^[^=]*=//'`
    shift ;;
  -m | --m*)
    shift
    test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
    mail="$1"
    shift ;;
  -v | --version | --v*)
    show_version=1; shift ;;
  --)
    shift; break ;;
  -*) echo "$usage" 1>&2; exit 1 ;;
  *)
    if [ -z $url ]; then
      url="$1"
    elif [ -z $message ]; then
      message="$1"
    fi
    shift ;;
  esac
done
 
 
if test $show_version; then
  echo "write2ch.sh version $version"; exit 0
fi
 
if [ -z "$url" -o -z "$message" ]; then
  echo "$usage" 1>&2; exit 1
fi
 
name=`echo $name|nkf -s`
mail=`echo $mail|nkf -s`
message=`echo $message|nkf -s`
 
tmp=`echo $url | sed -e 's/\(http:\/\/[^\/]*\)\/test\/read\.cgi\/\([^\/]*\)\/\([^\/]*\).*/\1 \2 \3/'`
host=`echo $tmp | cut -d " " -f 1`
bbs=`echo $tmp | cut -d " " -f 2`
key=`echo $tmp | cut -d " " -f 3`
data="bbs=$bbs&key=$key&FROM=$name&mail=$mail&time=1&MESSAGE=$message"
submit=`echo "書き込む" | nkf -s`
cookie=`wget -q --save-headers --header="Cookie:NAME=\"$name\"; MAIL=\"$mail\";" --referer=$url --post-data="${data}&submit=$submit" -O - $host/test/bbs.cgi | grep Set-Cookie`
cookie=`echo $cookie | sed -e "s/Set-Cookie://"`
submit=`echo "上記全てを承諾して書き込む" | nkf -s`
wget -q --header="Cookie:NAME='$name'; MAIL='$mail';$cookie" --referer=$host/test/bbs.cgi --post-data="${data}&submit=$submit&hana=mogera" -O - $host/test/bbs.cgi > /dev/null

}}

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS