Guest User

Untitled

a guest
Jun 7th, 2014
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. cat > kimsufi.php <<EOF
  2. <?php
  3. $path = "/root/your_scripts_path/";
  4. $host = "smtp.gmail.com";
  5. $username = "your@email";
  6. $password = "password";
  7. $api_key = "apikey";
  8. $api_secret = "apipwd";
  9. $url = "http://ws.ovh.com/dedicated/r2/ws.dispatcher/getAvailability2";
  10.  
  11. if (!file_exists("/tmp/kimsufi")) {
  12. $f = file_get_contents($url);
  13.  
  14. $a = json_decode($f);
  15.  
  16. $avail = $a->answer->availability;
  17.  
  18. foreach($avail as $s) {
  19.  if($s->reference==='142sk1') {
  20.   $z = $s->zones;
  21.   foreach($z as $zone) {
  22.     if($zone->availability!=='unavailable') {
  23.         //echo $s->reference . " is " . $zone->availability . " in " . $zone->zone . "\n";
  24.                 $from = "Kimsufi daemon <your@email>";
  25.                 $to = "Your name <your@email>";
  26.                 $subject = "Disponibilidad en Kimsufi KS-1 zona ".$zone->zone;
  27.                 $body = "Disponibilidad en zona ".$zone->zone." http://www.kimsufi.com/ie/#servers";
  28.                 $para = "phone#including_country_code";
  29.                 $de = $para;
  30.                 $mensaje = $body;
  31.                 include($path."manda_email.php");
  32.                 include($path."manda_sms.php");
  33.                 //echo "Se fue email.";
  34.                 touch("/tmp/kimsufi");
  35.     }
  36.      //else { echo "No availability"; }
  37.     }
  38.    break;
  39.   }
  40. }
  41. }
  42. EOF
  43.  
  44. cat > manda_email.php <<EOF
  45. <?php
  46. require_once "Mail.php";
  47.  
  48. $headers = array ('From' => $from,
  49.   'To' => $to,
  50.   'Subject' => $subject);
  51. $smtp = Mail::factory('smtp',
  52.   array ('host' => $host,
  53.     'auth' => true,
  54.     'username' => $username,
  55.     'password' => $password));
  56.  
  57. $mail = $smtp->send($to, $headers, $body);
  58.  
  59. //file_put_contents($log_email,date("Y-m-d-H:i:s | ").$mensaje."\n",FILE_APPEND);
  60. ?>
  61. EOF
  62.  
  63. cat > manda_sms.php <<EOF
  64. <?php
  65.  
  66. $postUrl = "http://rest.innovativetxt.com/smsapi/index.php";
  67. $fields = "to=".$para."&from=".$de."&text=".$mensaje."&api_key=".$api_key."&api_secret=".$api_secret;
  68. $ch = curl_init();
  69. curl_setopt($ch, CURLOPT_URL, $postUrl);
  70. curl_setopt($ch, CURLOPT_POST, 1);
  71. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  72. //Response of the POST request
  73. $response = curl_exec($ch);
  74. curl_close($ch);
  75. //file_put_contents($log_sms,date("Y-m-d-H:i:s | ").$response."\n",FILE_APPEND);
  76. ?>
  77. EOF
  78.  
  79. cat >> /etc/crontab <<EOF
  80. */1  * * * * root       /usr/bin/php /your_scripts_path/kimsufi.php
  81. EOF
  82.  
  83. service cron restart
Advertisement
Add Comment
Please, Sign In to add comment