SHARE
TWEET

Untitled

a guest Jan 30th, 2015 12 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3.  * Script to check SoYouStart availability  based on http://www.tienle.com/2014/09-03/script-check-soyoustart-availability.html
  4.  * to help see http://www.richzendy.org/2014/10/05/script-php-para-chequear-y-notificar-disponibilidad-de-servidores-en-soyoustart.html
  5.  */
  6.  
  7. define('CHECK_URL',                     'http://ws.ovh.com/dedicated/r2/ws.dispatcher/getAvailability2');
  8. define('NOTIFICATION_EMAILS',   'youremail@tld.com');
  9. define('SYSTEM_EMAIL',                  '1'); // 1 = enabled local smtp system
  10. define('MANDRILL',                  '0'); // 1 = enable email trought mandrill api, require an account on https://mandrillapp.com/
  11. define('MANDRILL_API',                  '');
  12. define('TEMP_PREVIOUS_MSG_FILE',        dirname(__FILE__). '/sys-avail-cache.txt');
  13.  
  14. $f = file_get_contents(CHECK_URL);
  15.  
  16. $a = json_decode($f);
  17. $avail = $a->answer->availability;
  18.  
  19. $str_avai = '';
  20. $zone_to_check = array('143sys12'); //Replace with your choices
  21.  
  22. foreach($avail as $s) {
  23.   if( in_array($s->reference, $zone_to_check)) {
  24.     $z = $s->zones;
  25.     foreach($z as $zone) {
  26.  
  27. // Please check your best zone here http://proof.ovh.net/
  28.       if($zone->availability!=='unavailable' && strtolower($zone->zone) == 'bhs' || $zone->availability!=='unavailable' && strtolower($zone->zone) == 'gra' || $zone->availability!=='unavailable' && strtolower($zone->zone) == 'rbx' || $zone->availability!=='unavailable' && strtolower($zone->zone) == 'sbg')
  29.         {
  30.         $str_avai .= $s->reference . " is " . $zone->availability . " in " . $zone->zone . "\n";
  31.       }
  32.     }
  33.   }
  34. }
  35.  
  36. //-- write to cache file to avoid repeated notifications
  37. $previous_message = @file_get_contents(TEMP_PREVIOUS_MSG_FILE);
  38.  
  39. if ($str_avai != ''){
  40.     if ($str_avai != $previous_message){
  41.         if (defined(NOTIFICATION_EMAILS)){
  42.                 $emails = explode(',',NOTIFICATION_EMAILS);
  43.         foreach ($emails as $email)
  44.                         sendNotificationEmail($email, $str_avai);
  45.         }
  46.     $ff = fopen(TEMP_PREVIOUS_MSG_FILE, "w");
  47.         fwrite($ff, $str_avai);
  48.         fclose($ff);
  49.     }
  50. }else {
  51.         $ff = fopen(TEMP_PREVIOUS_MSG_FILE, "w");
  52.         fwrite($ff, '-');
  53.         fclose($ff);
  54. }
  55.  
  56. /**
  57.  * Send email via MANDRILL APP
  58.  */
  59. function sendNotificationEmail($to, $msg){
  60.        
  61. if (defined('MANDRILL_API') && MANDRILL == 1) {
  62.         require dirname(__FILE__) . '/vendor/autoload.php';
  63.         $mandrill = new Mandrill(MANDRILL_API);
  64.  
  65.         $date = new DateTime('now', new DateTimeZone('America/Caracas')); // replace your timezone here
  66.  
  67.         $message = new stdClass();
  68.         $message->text = $msg;
  69.         $message->subject = $date->format('Y-m-d H:i:s') . " -  SoYouStart Availability";
  70.         $message->from_email = "no'reply@example.com";
  71.         $message->from_name  = "NO REPLY";
  72.         $message->to = array(array("email" => $to));
  73.         $message->track_opens = true;
  74.  
  75.         $response = $mandrill->messages->send($message);
  76. }
  77. if ( SYSTEM_EMAIL == 1 ) {
  78.         $mail = mail($to, $message->subject, $msg);
  79. }
  80.         return ;
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top