Posted By

gerswin on 03/12/13


Tagged

phpdemonio


Versions (?)

Demonio


 / Published in: PHP
 

el demonio

  1. <?php
  2. date_default_timezone_set("America/Caracas");
  3.  
  4. // ////////////////// Actualiza Mongo
  5.  
  6. function statusd($numero, $mensaje, $modem)
  7. {
  8. $services_json = json_decode(getenv("VCAP_SERVICES") , true);
  9. $mongo_config = $services_json["mongodb-1.8"][0]["credentials"];
  10. $username = $mongo_config["username"];
  11. $password = $mongo_config["password"];
  12. $hostname = $mongo_config["hostname"];
  13. $port = $mongo_config["port"];
  14. $db = $mongo_config["db"];
  15. $name = $mongo_config["name"];
  16. $connect = "mongodb://${username}:${password}@${hostname}:${port}/${db}";
  17. $m = new Mongo($connect);
  18. $db = $m->selectDB($db);
  19. $collection = $db->smsout;
  20. $collection->update(array(
  21. "numero" => $numero,
  22. "mensaje" => $mensaje
  23. ) , array(
  24. '$set' => array(
  25. "status" => "delivered",
  26. "modem" => $modem
  27. )
  28. ) , array(
  29. "multiple" => true
  30. ));
  31.  
  32. // /////////////// Push
  33.  
  34. function pushover($mensaje)
  35. {
  36. curl_setopt_array($ch = curl_init() , array(
  37. CURLOPT_URL => "https://api.pushover.net/1/messages.json",
  38. CURLOPT_RETURNTRANSFER => 1,
  39. CURLOPT_POSTFIELDS => array(
  40. "token" => "bziHoGmCt1dcSxSgvpOtpVMOXkzuKm",
  41. "user" => "qDwFKeHeeeIcFxoGvkHJDBmqgW7r80",
  42. "title" => "Server Status:",
  43. "message" => $mensaje,
  44. "priority " => "1",
  45. )
  46. ));
  47. curl_exec($ch);
  48. curl_close($ch);
  49. }
  50.  
  51. // ////// Revisa si esta en linea
  52.  
  53. function online($url)
  54. {
  55. $handle = curl_init(urldecode($url));
  56. curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
  57. curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 3);
  58. $response = curl_exec($handle);
  59. $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
  60. if ($httpCode >= 200 && $httpCode < 400)
  61. {
  62. return true;
  63. }
  64. else
  65. {
  66. return false;
  67. }
  68.  
  69. curl_close($handle);
  70. }
  71.  
  72. // ///////////// Funciones para los Modem
  73.  
  74. function nueve900($numero, $mensaje)
  75. {
  76. $server = "http://home.gerswin.com:9900";
  77. $mensaje = urlencode($txt);
  78. $str = "?PhoneNumber=" . $numero . "&Text=" . $mensaje;
  79. $ch = curl_init();
  80. curl_setopt($ch, CURLOPT_URL, $server . $str);
  81. curl_setopt($ch, CURLOPT_POST, 1);
  82. curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
  83. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  84. $retorno = curl_exec($ch);
  85. curl_close($ch);
  86. return $retorno;
  87. }
  88.  
  89. function nueve901($numero, $mensaje)
  90. {
  91. $server = "http://home.gerswin.com:9901";
  92. $mensaje = urlencode($txt);
  93. $str = "?PhoneNumber=" . $numero . "&Text=" . $mensaje;
  94. $ch = curl_init();
  95. curl_setopt($ch, CURLOPT_URL, $server . $str);
  96. curl_setopt($ch, CURLOPT_POST, 1);
  97. curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
  98. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  99. $retorno = curl_exec($ch);
  100. curl_close($ch);
  101. return $retorno;;
  102. }
  103.  
  104. function android($numero, $mensaje)
  105. {
  106. $server = "http://home.gerswin.com:9901";
  107. $mensaje = urlencode($txt);
  108. $str = "?PhoneNumber=" . $numero . "&Text=" . $mensaje;
  109. $ch = curl_init();
  110. curl_setopt($ch, CURLOPT_URL, $server . $str);
  111. curl_setopt($ch, CURLOPT_POST, 1);
  112. curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
  113. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  114. $retorno = curl_exec($ch);
  115. curl_close($ch);
  116. return $retorno;
  117. }
  118.  
  119. // ///////////// Seleccionamos la Funcion para el Modem
  120.  
  121. function enviasms($numero, $mensaje)
  122. {
  123. if (online("http://home.gerswin.com:9900/")== true)
  124. {
  125. $modem = "nueve900";
  126. }
  127. elseif (online("http://home.gerswin.com:9901/") == true)
  128. {
  129. $modem = "nueve901";
  130. }
  131. elseif (online("http://smsdroid.dyndns.tv:9999/") == true)
  132. {
  133. $modem = "android";
  134. }
  135. else
  136. {
  137. pushover("Ningun Modem Disponible");
  138. die;
  139. }
  140.  
  141. $todo = $modem($numero, $mensaje);
  142. $sucess = "Message Submitted";
  143. $sucessa = "Mesage SENT!";
  144. $status = strpos($todo, $sucess);
  145. $statusa = strpos($todo, $sucessa);
  146. if ($statusa !== FALSE)
  147. {
  148. statusd($numero, $mensaje, $modem);
  149. }
  150. elseif ($statusa !== FALSE)
  151. {
  152. statusd($numero, $mensaje, $modem);
  153. }
  154. }
  155.  
  156. $services_json = json_decode(getenv("VCAP_SERVICES") , true);
  157. $mongo_config = $services_json["mongodb-1.8"][0]["credentials"];
  158. $username = $mongo_config["username"];
  159. $password = $mongo_config["password"];
  160. $hostname = $mongo_config["hostname"];
  161. $port = $mongo_config["port"];
  162. $db = $mongo_config["db"];
  163. $name = $mongo_config["name"];
  164. $connect = "mongodb://${username}:${password}@${hostname}:${port}/${db}";
  165. $m = new Mongo($connect);
  166. $db = $m->selectDB($db);
  167. $modo = "sms";
  168. $collection = $db->smsout;
  169. $cursor = $collection->find(array(
  170. 'status' => 'accepted'
  171. ))->limit(10);
  172. foreach($cursor as $obj)
  173. {
  174. enviasms($obj['numero'],$obj['mensaje']);
  175. }

Report this snippet  

You need to login to post a comment.