国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

SAE域名綁定設(shè)置服務(wù)器宕機(jī)時(shí)自動(dòng)修改A記錄并飛信通知

2024-05-04 21:48:23
字體:
供稿:網(wǎng)友

SAE域名綁定之后,一般是用CNAME方式將域名綁定到應(yīng)用中。但是有時(shí)候我們需要用到A記錄(比如說根域名,雖然在DNSPOD上可以設(shè)置CNAME記錄,但很可能會(huì)影響到MX記錄),而SAE的IP地址經(jīng)常改變,ping應(yīng)用二級(jí)域名得到的IP沒多久就失效了(前些天網(wǎng)站因此幾天打不開都沒發(fā)現(xiàn),我用的是教育網(wǎng),自己能打開,但是電信線路變了)。還好DNSPOD有個(gè)功能叫D監(jiān)控,可以幫你監(jiān)控網(wǎng)站能否正常打開。如果發(fā)現(xiàn)宕機(jī),DNSPOD會(huì)用郵件、短信、微信等方式提醒你。這里用到的是它的另一個(gè)通知方式,那就是URL回調(diào)“通過DNSPod 提供的D監(jiān)控 URL 回調(diào)功能,您可以讓宕機(jī)或恢復(fù)信息提交到您指定的 URL 上,從而更加靈活地處理各種通知信息。”

我們可以通過宕機(jī)之后的URL回調(diào)取得相關(guān)參數(shù),并通過DNSPOD API實(shí)現(xiàn)自動(dòng)修改記錄的功能,再通過飛信發(fā)送宕機(jī)通知。

代碼在后面,先說設(shè)置方法:

1.點(diǎn)此下載代碼,修改其中的參數(shù)為你自己的。

2.將代碼上傳到網(wǎng)站。

3.在DNSPOD開啟D監(jiān)控,在通知設(shè)置中回調(diào)URL一欄填入monitorCallback.php的地址,如http://blog.gimhoy.com/monitorCallback.php?rHost=hipic.sinaapp.com.其中rHost是SAE的二級(jí)域名。并設(shè)置回調(diào)密鑰。

4.Enjoy~ dnspod-monitor-callback

monitorCallback.php,代碼如下:

  1. /* 
  2. * Copyright 2007-2014 Gimhoy Studio. 
  3. * 
  4. * @author Gimhoy 
  5. * @email contact@gimhoy.com 
  6. * @version 1.0.0 
  7. */ 
  8. $rHost = $_GET['rHost']; // SAE二級(jí)域名 
  9. if(emptyempty($rHost)) $rHost = 'sinaapp.com'
  10. $logName = 'monitorLog.txt'//log 文件名 
  11. $logStorDomain = 'log'// Storage Domain 
  12. $FetionNum = ''//飛信登陸號(hào)碼 
  13. $FetionPwd = ''//飛信登陸密碼 
  14. $MobileNum = ''//接收通知短信的號(hào)碼 
  15. $callback_key = 'MYKEY'// 添加監(jiān)控時(shí)設(shè)置的密鑰 
  16.  
  17. $monitor_id = $_POST['monitor_id']; // 監(jiān)控編號(hào) 
  18. $domain_id = $_POST['domain_id']; // 域名編號(hào) 
  19. $domain = $_POST['domain']; // 域名名稱 
  20. $record_id = $_POST['record_id']; // 記錄編號(hào) 
  21. $sub_domain = $_POST['sub_domain']; // 主機(jī)名稱 
  22. $record_line = $_POST['record_line']; // 記錄線路 
  23. $ip = $_POST['ip']; // 記錄IP 
  24. $status = $_POST['status']; // 當(dāng)前狀態(tài) 
  25. $status_code = $_POST['status_code']; // 狀態(tài)代碼 
  26. $reason = $_POST['reason']; // 宕機(jī)原因 
  27. $created_at = $_POST['created_at']; // 發(fā)生時(shí)間 
  28. $checksum = $_POST['checksum']; // 校檢代碼 
  29.  
  30. if (md5($monitor_id$domain_id$record_id$callback_key$created_at) != $checksum) { 
  31. // 非法請(qǐng)求 
  32. echo 'BAD REQUEST'
  33. else { 
  34. // 開始處理 
  35. if ($status == 'Warn' || $status == 'Ok') { 
  36. // 宕機(jī)恢復(fù) 
  37. $msg = date("Y-m-d H:i:s").' '.$sub_domain.'.'.$domain."(".$record_line." ".$ip.")宕機(jī)恢復(fù)"
  38. elseif ($status == 'Down') { 
  39. // 宕機(jī) 
  40. $msg = date("Y-m-d H:i:s").' '.$sub_domain.'.'.$domain."(".$record_line." ".$ip.")在".$created_at."宕機(jī)。宕機(jī)原因:".$reason."可用IP:"
  41. $ips = @gethostbyname($rHost); 
  42. include_once 'dnspod.class.php'
  43. $newIP = $ips
  44. $data = array
  45. 'domain_id' => $domain_id
  46. 'record_id' => $record_id
  47. 'sub_domain' => $sub_domain
  48. 'record_type' => 'A'
  49. 'record_line' => $record_line
  50. 'ttl' => '600'
  51. 'value' => $newIP 
  52. ); 
  53. $dnspod = new dnspod(); 
  54. $response = $dnspod->api_call('Record.Modify'$data); 
  55. if(isset($response['status']['code']) && $response['status']['code'] == 1) { 
  56. $msg = $msg.$newIP.'(已切換)'
  57. else { 
  58. $msg = $msg.$newIP.'(切換失敗,錯(cuò)誤代碼'.$response['status']['code'].')'
  59. //飛信通知 
  60. require_once 'Fetion.class.php'
  61. $fetion = new PHPFetion($FetionNum$FetionPwd); 
  62. $result = $fetion->send($MobileNum$msg); 
  63. if(strpos($result'短信發(fā)送成功!') || strpos($result'發(fā)送消息成功!')) { $r = "成功。";}else{$r = "失敗。";} 
  64. $s = new SaeStorage(); 
  65. $content = $s -> read($logStorDomain$logName); 
  66. $content = $content.$msg.'。飛信通知'.$r.' 
  67. ';//開源代碼Vevb.com 
  68. $s -> write($logStorDomain$logName$content); 
  69.  
  70. // 處理完成 
  71. echo 'DONE'

dnspod.class.php

  1. /* 
  2. * DNSPod API PHP Web 示例 
  3. * http://m.survivalescaperooms.com/ 
  4. * 
  5. * Copyright 2011, Kexian Li 
  6. * Released under the MIT, BSD, and GPL Licenses. 
  7. * 
  8. */ 
  9.  
  10. class dnspod { 
  11. public function api_call($api$data) { 
  12. if ($api == '' || !is_array($data)) { 
  13. exit('內(nèi)部錯(cuò)誤:參數(shù)錯(cuò)誤'); 
  14. $api = 'https://dnsapi.cn/' . $api
  15. $data = array_merge($dataarray('login_email' => 'DNSPOD登陸賬號(hào)''login_password' => 'DNSPOD登陸密碼''format' => 'json''lang' => 'cn''error_on_empty' => 'yes')); 
  16.  
  17. $result = $this->post_data($api$data); 
  18.  
  19. if (!$result) { 
  20. exit('內(nèi)部錯(cuò)誤:調(diào)用失敗'); 
  21. $results = @json_decode($result, 1); 
  22. if (!is_array($results)) { 
  23. exit('內(nèi)部錯(cuò)誤:返回錯(cuò)誤'); 
  24. if ($results['status']['code'] != 1) { 
  25. exit($results['status']['message']); 
  26. return $results
  27. private function post_data($url$data) { 
  28. if ($url == '' || !is_array($data)) { 
  29. return false; 
  30. $ch = @curl_init(); 
  31. if (!$ch) { 
  32. exit('內(nèi)部錯(cuò)誤:服務(wù)器不支持CURL'); 
  33. curl_setopt($ch, CURLOPT_URL, $url); 
  34. curl_setopt($ch, CURLOPT_POST, 1); 
  35. curl_setopt($ch, CURLOPT_HEADER, 0); 
  36. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  37. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
  38. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
  39. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); 
  40. curl_setopt($ch, CURLOPT_USERAGENT, 'Gimhoy Monitor/1.0 (contact@gimhoy.com)'); 
  41. $result = curl_exec($ch); 
  42. curl_close($ch); 
  43. return $result

Fetion.class.php,代碼如下:

  1. header('Content-Type: text/html; charset=utf-8'); 
  2. /** 
  3. * PHP飛信發(fā)送類 
  4. * @author quanhengzhuang 
  5. * @version 1.5.0 
  6. */ 
  7. class PHPFetion { 
  8. /** 
  9. * 發(fā)送者手機(jī)號(hào) 
  10. * @var string 
  11. */ 
  12. protected $_mobile
  13. /** 
  14. * 飛信密碼 
  15. * @param string 
  16. */ 
  17. protected $_password
  18. /** 
  19. * Cookie字符串 
  20. * @param string 
  21. */ 
  22. protected $_cookie = ''
  23. /** 
  24. * Uid緩存 
  25. * @var array 
  26. */ 
  27. protected $_uids = array(); 
  28. /** 
  29. * csrfToken 
  30. * @param string 
  31. */ 
  32. protected $_csrfToten = null; 
  33. /** 
  34. * 構(gòu)造函數(shù) 
  35. * @param string $mobile 手機(jī)號(hào)(登錄者) 
  36. * @param string $password 飛信密碼 
  37. */ 
  38. public function __construct($mobile$password
  39. if ($mobile === '' || $password === ''
  40. return
  41. $this->_mobile = $mobile
  42. $this->_password = $password
  43. $this->_login(); 
  44. /** 
  45. * 析構(gòu)函數(shù) 
  46. */ 
  47. public function __destruct() { 
  48. $this->_logout(); 
  49. /** 
  50. * 登錄 
  51. * @return string 
  52. */ 
  53. protected function _login() 
  54. $uri = '/huc/user/space/login.do?m=submit&fr=space'
  55. $data = 'mobilenum='.$this->_mobile.'&password='.urlencode($this->_password); 
  56. $result = $this->_postWithCookie($uri$data); 
  57.  
  58. //解析Cookie 
  59. preg_match_all('/.*?rnSet-Cookie: (.*?);.*?/si'$result$matches); 
  60. if (isset($matches[1])) 
  61. $this->_cookie = implode('; '$matches[1]); 
  62. $result = $this->_postWithCookie('/im/login/cklogin.action'''); 
  63.  
  64. return $result
  65. /** 
  66. * 獲取csrfToken,給好友發(fā)飛信時(shí)需要這個(gè)字段 
  67. * @param string $uid 飛信ID 
  68. * @return string 
  69. */ 
  70. protected function _getCsrfToken($uid
  71. if ($this->_csrfToten === null) 
  72. $uri = '/im/chat/toinputMsg.action?touserid='.$uid
  73. $result = $this->_postWithCookie($uri''); 
  74. preg_match('/name="csrfToken".*?value="(.*?)"/'$result$matches); 
  75.  
  76. $this->_csrfToten = isset($matches[1]) ? $matches[1] : ''
  77.  
  78. return $this->_csrfToten; 
  79.  
  80. /** 
  81. * 向指定的手機(jī)號(hào)發(fā)送飛信 
  82. * @param string $mobile 手機(jī)號(hào)(接收者) 
  83. * @param string $message 短信內(nèi)容 
  84. * @return string 
  85. */ 
  86. public function send($mobile$message) { 
  87. if($message === '') { 
  88. return ''
  89. // 判斷是給自己發(fā)還是給好友發(fā) 
  90. if($mobile === $this->_mobile) { 
  91. return $this->_toMyself($message); 
  92. else if(strlen($mobile)===11){ 
  93. $uid = $this->_getUid($mobile); 
  94. else { 
  95. $uid=$mobile
  96. return $uid === '' ? $this->_addFriend($mobile) : $this->_toUid($uid$message); 
  97. protected function _getname() { 
  98. $uri = '/im/index/index.action'
  99. $result = $this->_postWithCookie($uri'#'); 
  100. // 匹配 
  101. preg_match('/(.*?)</a>/si'$result$matches); 
  102. return $matches[2]; 
  103. /* 
  104. * 通過手機(jī)號(hào)增加好友 
  105. * @param string $number 手機(jī)號(hào)(要加的好友手機(jī)) 
  106. * @param string $nickname 你的名字,出現(xiàn)在對(duì)方的驗(yàn)證短信里 
  107. * @param string $buddylist 分組,默認(rèn)為空 
  108. * @param string $localName 好友屏顯名 
  109. * @return string 
  110. */ 
  111. protected function _addFriend($number) { 
  112. $uri = '/im/user/insertfriendsubmit.action'
  113. $data = 'nickname='. urlencode($this->_getname()).'&buddylist=1&localName=&number='$number .'&type=0'
  114. $result = $this->_postWithCookie($uri$data); 
  115. return $result
  116. /** 
  117. * 獲取飛信ID 
  118. * @param string $mobile 手機(jī)號(hào) 
  119. * @return string 
  120. */ 
  121. protected function _getUid($mobile
  122. if (emptyempty($this->_uids[$mobile])) 
  123. $uri = '/im/index/searchOtherInfoList.action'
  124. $data = 'searchText='.$mobile
  125. $result = $this->_postWithCookie($uri$data); 
  126. //匹配 
  127. preg_match('/toinputMsg.action?touserid=(d+)/si'$result$matches); 
  128.  
  129. $this->_uids[$mobile] = isset($matches[1]) ? $matches[1] : ''
  130. return $this->_uids[$mobile]; 
  131. /** 
  132. * 向好友發(fā)送飛信 
  133. * @param string $uid 飛信ID 
  134. * @param string $message 短信內(nèi)容 
  135. * @return string 
  136. */ 
  137. protected function _toUid($uid$message) { 
  138. $uri = '/im/chat/sendMsg.action?touserid='.$uid
  139. $csrfToken = $this->_getCsrfToken($uid); 
  140. $data = 'msg='.urlencode($message).'&csrfToken='.$csrfToken
  141. $result = $this->_postWithCookie($uri$data); 
  142. return $result
  143. /** 
  144. * 給自己發(fā)飛信 
  145. * @param string $message 
  146. * @return string 
  147. */ 
  148. protected function _toMyself($message) { 
  149. $uri = '/im/user/sendMsgToMyselfs.action'
  150. $result = $this->_postWithCookie($uri'msg='.urlencode($message)); 
  151. return $result
  152. /** 
  153. * 退出飛信 
  154. * @return string 
  155. */ 
  156. protected function _logout() { 
  157. $uri = '/im/index/logoutsubmit.action'
  158. $result = $this->_postWithCookie($uri''); 
  159. return $result
  160. protected function getgroup() { 
  161. $uri = '/im/index/index.action'
  162. $data = 'type=group'
  163. $result = $this->_postWithCookie($uri$data); 
  164. // 匹配 
  165. preg_match_all('/contactlistView.action?idContactList=(d+)/si'$result$matches); 
  166. foreach($matches[1] as $k=>$v){ 
  167. if$k== 0 ){ 
  168. $min = $v
  169. $max = $v
  170. }else if($v!=9998&&$v!=9999){ 
  171. $min = min($min,$v); 
  172. $max = max($max,$v); 
  173. return $max
  174. public function getyou1() { 
  175. $list=$this->getgroup(); 
  176. for($i=0;$i<=$list;$i++){ 
  177. $uri = '/im/index/contactlistView.action'
  178. $data = 'idContactList='.$i.'&type=group'
  179. $result = $this->_postWithCookie($uri$data); 
  180. preg_match('/(.*?)|(.*?)((.*?)/(.*?))/si'$result$listn); 
  181. if(!$listn[2]){continue;} 
  182. $shuchu.=str_replace(" ","",$listn[2])."(".$listn[4].")n"
  183. preg_match('/共(d+)頁/si'$result$zpage); 
  184. preg_match('/共(d+)</a>頁/si'$result$dpage); 
  185. isset($zpage[1]) ? $page=$zpage[1] : $page=$dpage[4]; 
  186. for($j=1;$j<=$page;$j++){ 
  187. $uri = '/im/index/contactlistView.action'
  188. $data = 'idContactList='.$i.'&page='.$j
  189. $result = $this->_postWithCookie($uri$data); 
  190. preg_match_all('/(.*?)</a>/si'$result$matches); 
  191. if(!$matches[1][0]){break;} 
  192. for($x=0;$x<=9;$x++){ 
  193. if(!$matches[1][$x]){continue;} 
  194. $shuchu.=$matches[1][$x]." ".str_replace(" ","",$matches[3][$x])."n"
  195. return $shuchu
  196. public function getyou() { 
  197. $list=$this->getgroup(); 
  198. for($i=0;$i<=$list;$i++){ 
  199. $uri = '/im/index/contactlistView.action'
  200. $data = 'idContactList='.$i.'&type=group'
  201. $result = $this->_postWithCookie($uri$data); 
  202. preg_match('/(.*?)|(.*?)((.*?)/(.*?))/si'$result$listn); 
  203. if(!$listn[2]){continue;} 
  204. $shuchu.=str_replace(" ","",$listn[2])."(".$listn[4].")n"
  205. preg_match('/共(d+)頁/si'$result$zpage); 
  206. preg_match('/共(d+)</a>頁/si'$result$dpage); 
  207. isset($zpage[1]) ? $page=$zpage[1] : $page=$dpage[4]; 
  208. for($j=1;$j<=$page;$j++){ 
  209. $uri = '/im/index/contactlistView.action'
  210. $data = 'idContactList='.$i.'&page='.$j
  211. $result = $this->_postWithCookie($uri$data); 
  212. preg_match_all('/(.*?)</a>/si'$result$matches); 
  213. if(!$matches[1][0]){break;} 
  214. for($x=0;$x<=9;$x++){ 
  215. if(!$matches[1][$x]){continue;} 
  216. $shuchu.=$matches[1][$x]." ".str_replace(" ","",$matches[3][$x])."n"
  217. return $shuchu
  218. /** 
  219. * 攜帶Cookie向f.10086.cn發(fā)送POST請(qǐng)求 
  220. * @param string $uri 
  221. * @param string $data 
  222. */ 
  223. protected function _postWithCookie($uri$data
  224. $fp = fsockopen('f.10086.cn', 80); 
  225. fputs($fp"POST $uri HTTP/1.1rn"); 
  226. fputs($fp"Host: f.10086.cnrn"); 
  227. fputs($fp"Cookie: {$this->_cookie}rn"); 
  228. fputs($fp"Content-Type: application/x-www-form-urlencodedrn"); 
  229. fputs($fp"User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1rn"); 
  230. fputs($fp"Content-Length: ".strlen($data)."rn"); 
  231. fputs($fp"Connection: closernrn"); 
  232. fputs($fp$data); 
  233.  
  234. $result = ''
  235. while (!feof($fp)) 
  236. $result .= fgets($fp); 
  237.  
  238. fclose($fp); 
  239.  
  240. return $result

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 岑巩县| 陆良县| 竹山县| 台安县| 凭祥市| 二连浩特市| 大洼县| 治县。| 衢州市| 冀州市| 扎兰屯市| 马尔康县| 呼玛县| 资源县| 新和县| 广德县| 伊通| 高清| 斗六市| 西盟| 高阳县| 涞源县| 孟连| 景宁| 惠安县| 临邑县| 沁水县| 哈密市| 驻马店市| 青浦区| 淳化县| 乾安县| 辉县市| 积石山| 霍州市| 南通市| 泰和县| 安丘市| 林口县| 通州区| 五家渠市|