- 論壇徽章:
- 1
|
CU 的主題回覆通知
[code]#!/bin/sh
# 帳號(hào)/密碼
id="你的 ID"
pd="你的密碼"
# 密碼的 md5 編碼,在 Cookie 中要用到,若使用系的md5sum指令,編碼出來結(jié)果與 CU 不同
pd_md5=`echo "select md5('$pd')" | mysql | grep -v 'md5'`
forum_host="72891.cn"
email="abelyang@twnic.net.tw"
# 取得 session id (sid)
# phpbb2mysql_data 為 CU 的 Cookie Name
# 這是第一次連線,所以要去 Touch 一下 CU
# Cookie 該段的 decode 結(jié)果為 s:0:""; ,意即一開始我們沒有 Cookie 的預(yù)設(shè)值
sid=$(cat << EOF | nc $forum_host 80 | grep -E 'href=.*sid'| head -1 | sed -e 's/.*index.php?sid=\(.*\)" class="nav".*/\1/g'
GET /forum/login.php
Host: $forum_host
User-Agent: nc
Accept: text/xml,application/xml,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: zh-tw,zh-cn;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: Big5,utf-8;q=0.7,*;q=0.7
Keep-Alive: 100
Connection: keep-alive
Referer: http://$forum_host/forum/login.php
Cookie: phpbb2mysql_data=s%3A0%3A%22%22%3B; phpbb2mysql_sid=
EOF)
# 預(yù)計(jì)要送出的 POST DATA ( CU 的 login 是 POST,data 的長度要計(jì)算)
post_data="username=$id&password=$pd&autologin=on&login=%B5%C7%C2%BD&sid=$sid&redirect=%3F"
# 計(jì)算 POST DATA 的 Content-Length
length=${#post_data}
# 送出 POST DATA , 並取得 CU Apache 回應(yīng)的 Set-Cookie 資訊,將 Cookie Name=Value
# 的結(jié)構(gòu)轉(zhuǎn)成 Sell 的變量
cookie_name=$(cat << EOF | nc $forum_host 80 | grep -E 'Set-Cookie: '| sed -e 's/Set-Cookie: //g'| tr ';' '\n' | sed -e 's/\(.*\)=\(.*\)/\1="\2";/g'
POST /forum/login.php HTTP/1.1
Host: $forum_host
User-Agent: NC
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: zh-tw,zh-cn;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: Big5,utf-8;q=0.7,*;q=0.7
Keep-Alive: 100
Connection: keep-alive
Referer: http://$forum_host/forum/login.php?redirect=&sid=$sid
Cookie: phpbb2mysql_data=s%3A0%3A%22%22%3B; phpbb2mysql_sid=$sid
Content-Type: application/x-www-form-urlencoded
Content-Length: $length
$post_data
EOF)
# 執(zhí)行 Cookie Name=Value 的結(jié)果
eval $cookie_name
all_post_uri="/cgi-bin/forum/search.cgi?mode=all_author&key=$id&u=$check_userid"
host="www.chinaunix.net"
file="/root/cu.html"
cookie="phpbb2mysql_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A32%3A%22${pd_md5}%22%3Bs%3A6%3A%22userid%22%3Bs%3A5%3A%22${check_usedid}%22%3B%7D; phpbb2mysql_sid=$sid; check_username=$id; check_userid=$check_userid"
# 取得 [所有帖子] 數(shù)據(jù), 要取得這個(gè)資料需要登入系統(tǒng),不同於所[發(fā)表的文章]
cat << EOF | nc $host 80 > $file
GET $all_post_uri HTTP/1.1
Host: $host
User-Agent: NC
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: zh-tw,zh-cn;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: Big5,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://$forum_host/forum/profile.php?mode=viewprofile&u=$check_userid
Cookie: $cookie
Cache-Control: max-age=0
EOF
# 取得文章總數(shù)
total=`grep '坰善' $file | sed -e 's/.*坰善 \(.*\) 骸 |
|