SAE domain binding set up server downtime automatically modify a record and fly letter notice

Source: Internet
Author: User
Tags error code strlen urlencode

"The D-monitor URL callback feature provided by Dnspod allows you to have downtime or recovery information submitted to a URL that you specify, thereby making it more flexible to handle various notification messages." ”

We can use the URL callback after the downtime to obtain relevant parameters, and through the Dnspod API to achieve automatic modification of the recording function, and then sent by flying letter downtime notice.

Code in the back, first say set method:

Set method

1. Click here to download the code and modify the parameters for your own.

2. Upload the code to the website.

3. In the dnspod to open D monitoring, in the notification settings callback URL a column to fill in the monitorcallback.php address, such as http://blog.gimhoy.com/monitorCallback.php?rHost= Hipic.sinaapp.com, where Rhost is the SAE level two domain name. and set the callback key.

4.enjoy~

Dnspod-monitor-callback


Code
monitorcallback.php

The code is as follows Copy Code

/*
* Copyright 2007-2014 Gimhoy Studio.
*
* @author Gimhoy
* @email contact@gimhoy.com
* @version 1.0.0
*/
$rHost = $_get[' rhost ']; SAE Level two domain name
if (empty ($rHost)) $rHost = ' sinaapp.com ';
$logName = ' monitorLog.txt '; Log filename
$logStorDomain = ' log '; Storage Domain
$FetionNum = '; Letter Landing Number
$FETIONPWD = '; Letter Login Password
$MobileNum = '; The number to receive the notification message
$callback _key = ' MYKEY '; Keys set When you add a monitor

$monitor _id = $_post[' monitor_id ']; Monitor number
$domain _id = $_post[' domain_id ']; Domain number
$domain = $_post[' domain ']; Domain Name
$record _id = $_post[' record_id ']; Record number
$sub _domain = $_post[' Sub_domain ']; Host Name
$record _line = $_post[' Record_line ']; Record line
$ip = $_post[' IP ']; Record IP
$status = $_post[' status ']; Current state
$status _code = $_post[' Status_code ']; Status code
$reason = $_post[' reason ']; Downtime reasons
$created _at = $_post[' created_at ']; Time of Occurrence
$checksum = $_post[' checksum ']; School Check Code

if (MD5 ($monitor _id. $domain _id. $record _id. $callback _key. $created _at)!= $checksum) {
Illegal request
Echo ' Bad REQUEST ';
} else {
Start processing
if ($status = = ' Warn ' | | | $status = = ' Ok ') {
Downtime Recovery
$msg = Date ("y-m-d h:i:s"). ' '. $sub _domain. $domain. " (". $record _line." ". $ip.") Downtime Recovery ";
} elseif ($status = = ' down ') {
Downtime
$msg = Date ("y-m-d h:i:s"). ' '. $sub _domain. $domain. " (". $record _line." ". $ip.") In ". $created _at." Downtime. Reason for downtime: ". $reason." Available IP: ";
$ips = @gethostbyname ($rHost);
Include_once ' dnspod.class.php ';
$newIP = $ips;
$data = Array (
' domain_id ' => $domain _id,
' record_id ' => $record _id,
' Sub_domain ' => $sub _domain,
' Record_type ' => ' A ',
' Record_line ' => $record _line,
' TTL ' => ' 600 ',
' Value ' => $newIP
);
$dnspod = new Dnspod ();
$response = $dnspod->api_call (' record.modify ', $data);
if (Isset ($response [' status '] [' Code ']) && $response [' status '] [' code '] = 1} {
$msg = $msg. $newIP. ' (switched) ';
}
else {
$msg = $msg. $newIP. ' (Switch failed, error code '. $response [' status '] [' Code ']. ') ';
}
}
Notice of Flying Letter
Require_once ' Fetion.class.php ';
$fetion = new Phpfetion ($FetionNum, $FETIONPWD);
$result = $fetion->send ($MobileNum, $msg);
if (Strpos ($result, ' SMS send success! ') | | | strpos ($result, ' Send message success! ')) {$r = "success. ";} else{$r = "failed. ";}
$s = new saestorage ();
$content = $s-> read ($logStorDomain, $logName);
$content = $content. $msg. Flying Letter Notice '. $r. '
';
$s-> write ($logStorDomain, $logName, $content);

Processing complete
Echo ' Done ';
}

dnspod.class.php

/*
* Dnspod API PHP Web Example
* http://www.111cn.net/
*
* Copyright, Kexian Li
* Released under the MIT, BSD, and GPL Licenses.
*
*/

Class Dnspod {
Public Function Api_call ($API, $data) {
if ($api = = ' | |!is_array ($DATA)) {
Exit (' Internal error: Parameter error ');
}
$api = ' https://dnsapi.cn/'. $api;
$data = Array_merge ($data, Array (' Login_email ' => ' dnspod login account ', ' Login_password ' => ' dnspod ' login password ', ' format ' => ' J Son ', ' Lang ' => ' cn ', ' error_on_empty ' => ' yes ');

$result = $this->post_data ($api, $data);

if (! $result) {
Exit (' Internal error: Call failed ');
}
$results = @json_decode ($result, 1);
if (!is_array ($results)) {
Exit (' Internal error: return error ');
}
if ($results [' status '] [' Code ']!= 1) {
Exit ($results [' status '] [' message ']);
}
return $results;
}
Private Function Post_data ($url, $data) {
if ($url = = ' | |!is_array ($DATA)) {
return false;
}
$ch = @curl_init ();
if (! $ch) {
Exit (' Internal error: Server does not support curl ');
}
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_ssl_verifypeer, 0);
curl_setopt ($ch, curlopt_ssl_verifyhost, 0);
curl_setopt ($ch, Curlopt_postfields, Http_build_query ($data));
curl_setopt ($ch, Curlopt_useragent, ' Gimhoy monitor/1.0 (contact@gimhoy.com) ');
$result = curl_exec ($ch);
Curl_close ($ch);
return $result;
}
}


Fetion.class.php

The code is as follows Copy Code

Header (' content-type:text/html; Charset=utf-8 ');
/**
* PHP Letter Send Class
* @author Quanhengzhuang
* @version 1.5.0
*/
Class Phpfetion {
/**
* Sender Cell phone number
* @var String
*/
protected $_mobile;
/**
* Flying Letter Password
* @param string
*/
protected $_password;
/**
* Cookie String
* @param string
*/
protected $_cookie = ';
/**
* UID Cache
* @var Array
*/
Protected $_uids = Array ();
/**
* Csrftoken
* @param string
*/
protected $_csrftoten = null;
/**
* Constructor
* @param string $mobile mobile phone number (login)
* @param string $password letter Letter Password
*/
Public function __construct ($mobile, $password)
{
if ($mobile = = = ' | | $password = = = ')
{
Return
}
$this->_mobile = $mobile;
$this->_password = $password;
$this->_login ();
}
/**
* destructor
*/
Public Function __destruct () {
$this->_logout ();
}
/**
* Login
* @return String
*/
protected function _login ()
{
$uri = '/huc/user/space/login.do?m=submit&fr=space ';
$data = ' mobilenum= '. $this->_mobile. ' &password= '. UrlEncode ($this->_password);
$result = $this->_postwithcookie ($uri, $data);

Parsing cookies
Preg_match_all ('/.*?rnset-cookie: (. *?);. *?/si ', $result, $matches);
if (Isset ($matches [1]))
{
$this->_cookie = implode ('; ', $matches [1]);
}
$result = $this->_postwithcookie ('/im/login/cklogin.action ', ');

return $result;
}
/**
* Get Csrftoken, send a letter to a friend when you need this field
* @param string $UID flying Letter Id
* @return String
*/
protected function _getcsrftoken ($UID)
{
if ($this->_csrftoten = = null)
{
$uri = '/im/chat/toinputmsg.action?touserid= '. $uid;
$result = $this->_postwithcookie ($uri, ");
Preg_match ('/name= "Csrftoken". *?value= "(. *?)" /', $result, $matches);

$this->_csrftoten = Isset ($matches [1])? $matches [1]: ';
}

return $this->_csrftoten;
}

/**
* Send a letter to the designated mobile phone number
* @param string $mobile cell phone number (receiver)
* @param string $message SMS Content
* @return String
*/
Public function Send ($mobile, $message) {
if ($message = = = ") {
Return ";
}
The judgment is to give oneself back is to the friend hair
if ($mobile = = = $this->_mobile) {
return $this->_tomyself ($message);
}
else if (strlen ($mobile) ===11) {
$uid = $this->_getuid ($mobile);
}
else {
$uid = $mobile;
}
return $uid = = = '? $this->_addfriend ($mobile): $this->_touid ($uid, $message);
}
protected function _getname () {
$uri = '/im/index/index.action ';
$result = $this->_postwithcookie ($uri, ' # ');
The
Preg_match ('/(. *?) </a>/si ', $result, $matches);
return $matches [2];
}
/*
* Add friends through mobile phone number
* @param string $number mobile phone number (to add a friend mobile phone)
* @param string $nickname your name, appearing in the other person's verification message
* @param string $buddylist grouped, default is null
* @param string $localName friend screen name
* @return String
*/
protected function _addfriend ($number) {
$uri = '/im/user/insertfriendsubmit.action ';
$data = ' nickname= '. UrlEncode ($this->_getname ()). ' &buddylist=1&localname=&number= '. $number. ' &type=0 ';
$result = $this->_postwithcookie ($uri, $data);
return $result;
}
/**
* Get Letter Id
* @param string $mobile cell phone number
* @return String
*/
protected function _getuid ($mobile)
{
if (Empty ($this->_uids[$mobile]))
{
$uri = '/im/index/searchotherinfolist.action ';
$data = ' searchtext= '. $mobile;
$result = $this->_postwithcookie ($uri, $data);
The
Preg_match ('/toinputmsg.action?touserid= (d+)/si ', $result, $matches);

$this->_uids[$mobile] = isset ($matches [1])? $matches [1]: ';
}
return $this->_uids[$mobile];
}
/**
* Send a letter to a friend
* @param string $UID flying Letter Id
* @param string $message SMS Content
* @return String
*/
protected function _touid ($uid, $message) {
$uri = '/im/chat/sendmsg.action?touserid= '. $uid;
$csrfToken = $this->_getcsrftoken ($uid);
$data = ' msg= '. UrlEncode ($message). ' &csrftoken= '. $csrfToken;
$result = $this->_postwithcookie ($uri, $data);
return $result;
}
/**
* Send yourself a letter
* @param string $message
* @return String
*/
protected function _tomyself ($message) {
$uri = '/im/user/sendmsgtomyselfs.action ';
$result = $this->_postwithcookie ($uri, ' msg= '. UrlEncode ($message));
return $result;
}
/**
* Quit flying
* @return String
*/
protected function _logout () {
$uri = '/im/index/logoutsubmit.action ';
$result = $this->_postwithcookie ($uri, ");
return $result;
}
protected function Getgroup () {
$uri = '/im/index/index.action ';
$data = ' Type=group ';
$result = $this->_postwithcookie ($uri, $data);
The
Preg_match_all ('/contactlistview.action?idcontactlist= (d+)/si ', $result, $matches);
foreach ($matches [1] as $k => $v) {
if ($k = = 0) {
$min = $v;
$max = $v;
}else if ($v!=9998&& $v!=9999) {
$min = min ($min, $v);
$max = Max ($max, $v);
}
}
return $max;
}
Public Function getyou1 () {
$list = $this->getgroup ();
for ($i =0; $i <= $list; $i + +) {
$uri = '/im/index/contactlistview.action ';
$data = ' idcontactlist= '. $i. ' &type=group ';
$result = $this->_postwithcookie ($uri, $data);
Preg_match ('/(. *?) | (.*?) ((.*?) /(.*?)) /si ', $result, $LISTN);
if (! $LISTN [2]) {continue}
$shuchu. =str_replace ("", "", $LISTN [2]). " (". $listn [4].") n ";
Preg_match (' d+) page/si ', $result, $zpage);
Preg_match (' d+) </a> page/si ', $result, $dpage);
Isset ($zpage [1])? $page = $zpage [1]: $page = $dpage [4];
for ($j =1; $j <= $page; $j + +) {
$uri = '/im/index/contactlistview.action ';
$data = ' idcontactlist= '. $i. ' &page= '. $j;
$result = $this->_postwithcookie ($uri, $data);
Preg_match_all ('/(. *?) </a>/si ', $result, $matches);
if (! $matches [1][0]) {break;}
For ($x =0 $x <=9; $x + +) {
if (! $matches [1][$x]) {Continue}
$shuchu. = $matches [1][$x]. " ". Str_replace (" "," ", $matches [3][$x])." n ";
}
}
}
return $shuchu;
}
Public Function getyou () {
$list = $this->getgroup ();
for ($i =0; $i <= $list; $i + +) {
$uri = '/im/index/contactlistview.action ';
$data = ' idcontactlist= '. $i. ' &type=group ';
$result = $this->_postwithcookie ($uri, $data);
Preg_match ('/(. *?) | (.*?) ((.*?) /(.*?)) /si ', $result, $LISTN);
if (! $LISTN [2]) {continue}
$shuchu. =str_replace ("", "", $LISTN [2]). " (". $listn [4].") n ";
Preg_match (' d+) page/si ', $result, $zpage);
Preg_match (' d+) </a> page/si ', $result, $dpage);
Isset ($zpage [1])? $page = $zpage [1]: $page = $dpage [4];
for ($j =1; $j <= $page; $j + +) {
$uri = '/im/index/contactlistview.action ';
$data = ' idcontactlist= '. $i. ' &page= '. $j;
$result = $this->_postwithcookie ($uri, $data);
Preg_match_all ('/(. *?) </a>/si ', $result, $matches);
if (! $matches [1][0]) {break;}
For ($x =0 $x <=9; $x + +) {
if (! $matches [1][$x]) {Continue}
$shuchu. = $matches [1][$x]. " ". Str_replace (" "," ", $matches [3][$x])." n ";
}
}
}
return $shuchu;
}
/**
* Carry a cookie to send a POST request to f.10086.cn
* @param string $uri
* @param string $data
*/
protected function _postwithcookie ($uri, $data)
{
$fp = Fsockopen (' f.10086.cn ', 80);
Fputs ($fp, "POST $uri http/1.1rn");
Fputs ($fp, "host:f.10086.cnrn");
Fputs ($FP, "Cookie: {$this->_cookie}rn");
Fputs ($fp, "content-type:application/x-www-form-urlencodedrn");
Fputs ($fp, "user-agent:mozilla/5.0" (Windows NT 5.1; rv:14.0) gecko/20100101 firefox/14.0.1rn ");
Fputs ($FP, "Content-length:". strlen ($data). " RN ");
Fputs ($fp, "connection:closernrn");
Fputs ($fp, $data);

$result = ';
while (!feof ($FP))
{
$result. = Fgets ($FP);
}

Fclose ($FP);

return $result;
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.