|
#!/usr/bin/env php
/**
* 自动刷日志工具
* Useage : diarly.php diarly.php [start_date] [end_date]
* 日期格式: 2009-01-20 默认刷当日日志
*
*@Author rikugun <mailto:v5.rikugun@gmail.com>
*/
<?php
class Diarly{
//需要设置
//登录提交url
var $sLoginUrl = "http://yourdomain/logincheck.php";
//提交日志url
var $sSubmitUrl = "http://yourdomain/general/diary/new/submit.php";
//登录用户名
var $username = "用户名";
//登录密码
var $psw = "密码";
//日志内容
var $content = "日志内容";
//结束设置
var $ch;
var $postField;
var $cfp;
function Diarly(){
}
function init($start_date,$end_date){
$this->ch = curl_init();
$this->cfp = tempnam('/tmp','leznet');
$this->username = iconv('UTF-8','GB2312',$this->username);
$this->psw = iconv('UTF-8','GB2312',$this->psw);
$this->filename = $filename;
$this->content =urlencode(iconv('UTF-8','GB2312',$this->content));
$this->postField = "DIA_TYPE=1&CONTENT=".$this->content;
curl_setopt($this->ch,CURLOPT_POST,1);
$this->curr_date = new DateTime($start_date);
$this->end_date = $end_date;
}
//登录
function login(){
echo "Now Loginng ...\n";
$logstr = "USERNAME=".urlencode($this->username)."&PASSWORD=".urlencode($this->psw);
// echo "Login with ".$logstr."\n";
curl_setopt($this->ch,CURLOPT_URL,$this->sLoginUrl);
// curl_setopt($this->ch,CURLOPT_NOBODY,1);
curl_setopt($this->ch,CURLOPT_POSTFIELDS,$logstr);
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cfp);
curl_setopt($this->ch,CURLOPT_COOKIEFILE,$this->cfp);
curl_exec($this->ch);
echo "Success Login\n";
}
//添加日志
function submit(){
echo "Now Sending Diarly(ies) to Sever\n";
curl_setopt($this->ch,CURLOPT_URL,$this->sSubmitUrl);
while ($this->curr_date->format('Y-m-d')!==$this->end_date) {
echo "Add Diarly of ".$this->curr_date->format('Y-m-d')." end with less than ".$this->end_date."\n";
$postfield = $this->postField."&DIA_DATE=".$this->curr_date->format('Y-m-d');
curl_setopt($this->ch,CURLOPT_POSTFIELDS,$postfield);
curl_exec($this->ch);
echo curl_error($this->ch);
$this->curr_date->modify("+1 day");
}
echo "Success Add Diarly(ies)!\n";
}
function close(){
curl_close($this->ch);
unlink($this->cfp);
}
}
//var_dump($argv);
$d = new Diarly();
//处理输入参数
switch(count($argv)){
case 3:
$d->init($argv[1],$argv[2]);
break;
case 2:
$d->init(date('Y-m-d'),$argv[2]);
break;
case 1:
$d->init(date('Y-m-d'),date('Y-m-d',time()+24*60*60));
break;
default:
useage();
}
$d->login();
$d->submit();
$d->close();
echo "Total Success!\n";
function useage(){
echo "Useage: diarly.php [start_date] [end_date]\n";
exit (1);
}
?> |
|
|