Posts Tagged script
SMSGateway Exporter
Posted in Users Skills - 19 October 2009 00:50:34.htaccess and blocked country
Posted in Administrator Skills - 24 August 2008 11:44:11
สืบเนื่องจากเป็นลูกค้า SMSGateway หลายๆ ที่ และ แต่ละที่ส่วนใหญ่จะเก็บข้อมูลไว้ที่เซิร์ฟเวอร์ ไม่สามารถ Export ออกมาได้ ผมนิยมเก็บข้อมูลที่ส่งทุกประเภทไว้กับตัวเอง เลยจำเป็นต้องทำสคริปต์เพื่อ Export ข้อมูลออกมาจาก SMSGateway เจ้าต่างๆ ครับ ซึ่งใน Entry นี้ จะเป็นตัวอย่างของ SMSGateway.PacketLove.com (Oct 2009) สคริปต์นี้ ไม่รับประกันความสำเร็จในการใช้งาน และผู้ใช้รับความเสี่ยงต่อการทำงานผิดพลาดของสคริปต์ด้วยตนเอง.
<?php
class PacketLoveImportor {
var $username;
var $password;
var $rawdata;
function PacketLoveImportor(){
$this->username = "USERNAME";
$this->password = "PASSWORD";
}
function loadURL(){
define('POSTURL', 'http://smsgateway.packetlove.com/history.php');
$query = array (
"userLogin" => $data->username,
"uPasswd" => $data->password,
"page" => 0,
"page_limit" => 1000 // จำนวนข้อมูลที่แสดงในหนึ่งหน้า
);
$ch = curl_init(POSTURL);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,$query);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL
$result = curl_exec($ch);
curl_close($ch);
$this->rawdata = $result;
return $result;
}
function loadFile(){
$result = file_get_contents("import_packetlove.html");
$this->rawdata = $result;
return $result;
}
function export($encoding = "UTF-8"){
$found = false;
$offset = 0;
$html = $this->rawdata;
$result = null;
while (preg_match("/(20[0-9]{2}-[01]{0,1}[0-9]{0,1}-[0-9]{2}.[0-9]{2}:[0-9]{2}:[0-9]{2})/",$html,$match,PREG_OFFSET_CAPTURE,$offset) && !$found){
// เริ่มต้นหาจากวันที่
$date = $match[0][0];
// เสร็จแล้วเก็บ Field ที่เหลือ
$result_mobile = preg_match("/([0-9]{10})/",$html,$match,PREG_OFFSET_CAPTURE,$offset);
$mobile = $match[0][0];
$result_message = preg_match("/(<td><span class=\"link\"> )(.[^<]{0,255})(<\/style>)/",$html,$match,PREG_OFFSET_CAPTURE,$offset);
$message = $match[2][0];
$offset = $match[0][1] +1;
$result[] = array(
"date" => trim($date),
"tel" => trim($mobile),
"message" => iconv("ISO-8859-11",$encoding,$message),
);
}
// [DATA]
return $result;
}
}
//ตัวอย่างการใช้งาน ในกรณีนี้โหลดจากไฟล์ขึ้นมาทดสอบ ถ้าหากต้องการให้ดึงข้อมูลจากเซิร์ฟเวอร์ตรงๆ ให้เปลี่ยนไปใช้ $data->loadURL();
$data = new PacketLoveImportor();
$data->loadFile();
var_dump($data->export());
?>Got Denial-of-Service? Webboard spamming? Now, we have a tool that can blocked whole country you don’t want by simply input to .htaccess file. Visit Blockacountry.com for a script generator. I hope that they will provide autoupdate script in a future or I will do it by myself because IP address may be reassign to another country when the time is going.
อยากบล๊อกคนที่เข้ามาเยี่ยมชมจากประเทศบางประเทศ? ได้เลย ไม่ยาก เข้าไป generate .htaccess มาจากเว็บไซต์นี้ได้เลย หลังจากนั้นก็เอาไปใส่อัพโหลดไปไว้ที่โฟรเดอร์โฮมเพจ เท่านั้นเป็นอันเรียบร้อย เราสามารถเลือกให้บางประเทศเข้ามาชมเว็บเพจเราไม่ได้ดังที่ต้องการ.


