Facebook
From Pavlus, 8 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 355
  1. <?php
  2.  
  3. //check and send information about new firmware
  4.  
  5. $dir = getcwd();
  6.  
  7. $file = $dir.'/v.txt';
  8.  
  9. //if (file_exists($file))
  10. //      echo 'ok';
  11.  
  12. $actual_frw = trim(file_get_contents($file));
  13.  
  14. $url = 'http://sportsapi.xiaoyi.com/firmware/download?serialNumber=Z23L507S0189776';
  15. $hand = file_get_contents($url);
  16.  
  17. if($hand != FALSE) {
  18. $data = explode('"', $hand);
  19. /*
  20. //dumping variables
  21. //echo count($data);
  22. for ($i = 0; $i < count($data) ; $i++) {
  23.     echo $data[$i].' </br>';
  24. }
  25. */
  26.  
  27. (string)$frw = trim($data[19]);
  28. if ($frw != $actual_frw) {
  29.  
  30. //truncate file and save actual fw version
  31. file_put_contents($file, "");
  32. file_put_contents($file, $frw);
  33. //send notice
  34. mail_utf8('[email protected]', $frw, '[email protected]');
  35. echo 'mail sent';
  36. }
  37. else
  38. {
  39. //do nothing
  40. //echo $actual_frw;
  41. }
  42.  
  43. }
  44.  
  45. //functions
  46.  
  47. function mail_utf8($to, $from_user, $from_email, $subject = 'Xiaomi Yi new firmware available', $message = '')
  48.    {
  49.       $from_user = "=?UTF-8?B?".base64_encode($from_user)."?=";
  50.       $subject = "=?UTF-8?B?".base64_encode($subject)."?=";
  51.  
  52.       $headers = "From: $from_user <$from_email>\r\n".
  53.                "MIME-Version: 1.0" . "\r\n" .
  54.                "Content-type: text/html; charset=UTF-8" . "\r\n";
  55.  
  56.      return mail($to, $subject, $message, $headers);
  57.    }
  58.  
  59. ?>
  60.