fork download
  1. <?php
  2.  
  3. # NOCACHE
  4. header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
  5. header("Cache-Control: post-check=0, pre-check=0", false);
  6. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  7. header("Pragma: no-cache"); // HTTP/1.0
  8. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  9.  
  10. if (isset($_GET['audit'])) {
  11. ## ESTA INICIALIZADA
  12. if ($_GET['audit'] === 'ON') {
  13. # SEGURIDAD: VALIDACION DE ERRORES
  14. ini_set('display_startup_errors', 1);
  15. ini_set('display_errors', 1);
  16. echo (ini_get('display_errors') == 1 ? 'AUDIT MODE => ON ' . '<hr>' : '');
  17. } else {
  18. exit();
  19. }
  20. }
  21.  
  22. ## DO NOT LET ECHO CONSOLE.LOGS OR THE AJAX CALING IT WILL TROW ERRORS ONLY WITH init_GET FOR DEVELOPING PORPOUSE
  23. echo (ini_get('display_errors') == 1 ? ' INITIALITED => ' . __FILE__ . '<hr>' : '');
  24.  
  25. try {
  26. // Zona Horaria
  27. // date_default_timezone_set("America/Mazatlan");
  28. $fecha = date('Y-m-d');
  29. echo (ini_get('display_errors') == 1 ? ' $fecha Actual=> ' . date('Y-m-d H:i:sa') . '<br>' : '');
  30. $nfecha1d = strtotime('-1 day', strtotime($fecha));
  31. # FECHA les 1 day
  32. $fecha1da = date('Y-m-d', $nfecha1d);
  33.  
  34. $url = "";
  35. if (isset($_SERVER['HTTPS'])) {
  36. $url = 'https://172.29.68.14/tools/PHP/feedsmn/cap.php';
  37. } else {
  38. $url = 'http://172.29.68.14/tools/PHP/feedsmn/cap.php';
  39. }
  40. $xmld = get_web_page($url);
  41. # ECHO (ini_get('display_errors') == 1 ? ' $xmld => ' . print_r($xmld, 1) . '<hr>' : '');
  42. ## ECHO (ini_get('display_errors') == 1 ? ' $xmld[content] => ' . print_r($xmld['content'], 1) . '<br>' : '');
  43.  
  44. ## IF EMPTY CURL EXIT
  45. if (empty($xmld['content'])) {
  46. echo (ini_get('display_errors') == 1 ? '<script>console.log("Curl URL => FAIL, content empty...");</script>' . '<hr>' : '');
  47. exit();
  48. }
  49.  
  50. $xml = new SimpleXMLElement($xmld['content']);
  51. # ECHO (ini_get('display_errors') == 1 ? ' $xml => ' . print_r($xml, 1) . '<br>' : '');
  52. $elementos = array();
  53. $contador = 0;
  54. $lineData = array();
  55. $arry_T = array();
  56. echo (ini_get('display_errors') == 1 ? '<script>console.log("fechaActual => ' . $fecha1da . '");</script>' : '');
  57.  
  58. // Iniciar el HTML
  59. echo '<!DOCTYPE html>
  60. <html lang="es">
  61. <head>
  62. <meta charset="UTF-8">
  63. <title>Resultados CAP</title>
  64. <style>
  65. .resultado {
  66. border: 1px solid #ccc;
  67. padding: 15px;
  68. margin: 10px 0;
  69. border-radius: 5px;
  70. background-color: #f9f9f9;
  71. }
  72. .resultado h2 {
  73. margin-top: 0;
  74. }
  75. .resultado p {
  76. margin: 5px 0;
  77. }
  78. </style>
  79. </head>
  80. <body>
  81. <h1>Resultados CAP</h1>';
  82.  
  83. foreach ($xml->entry as $entry_x) {
  84. echo (ini_get('display_errors') == 1 ? '<script>console.log("%cFeed id => ' . $entry_x->id . '","background-color: Snow");</script>' : '');
  85. echo (ini_get('display_errors') == 1 ? '<script>console.log("Feed title => ' . ((!empty($entry_x->title)) ? htmlspecialchars($entry_x->title) : 'Empty title') . '");</script>' : '');
  86.  
  87. $fechaXml = $entry_x->updated;
  88. echo (ini_get('display_errors') == 1 ? '<script>console.log("Feed updated => ' . $fechaXml . '");</script>' : '');
  89. $fechaExp = explode("T", $fechaXml);
  90. $fecha_entry = $fechaExp[0];
  91. # ECHO (ini_get('display_errors') == 1 ? '<script>console.log("$fecha_entry => ' . $fecha_entry . '");</script>' : '');
  92.  
  93. $idhrf1 = 'href';
  94. $link1 = (string)$entry_x->link->attributes()->$idhrf1;
  95. echo (ini_get('display_errors') == 1 ? '<script>console.log("Feed $link1 => ' . $link1 . '");</script>' : '');
  96.  
  97. if ($fecha_entry >= $fecha1da) {
  98. echo (ini_get('display_errors') == 1 ? '<script>console.log("Cap => Date in less than 1 day Range ... ' . '");</script>' : '');
  99. $idhrf = 'href';
  100. $title = (string)$entry_x->title;
  101. $sumary = (string)$entry_x->summary;
  102. $update = (string)$entry_x->updated;
  103. $link = (string)$entry_x->link->attributes()->$idhrf;
  104.  
  105. $linkExp = explode("mx", $link);
  106. $linkCp = $linkExp[1];
  107. $url2 = '../../..' . substr($linkCp, 6);
  108. $xml2 = simplexml_load_file($url2);
  109. $efectivo = (string)$xml2->info[0]->effective;
  110. $expira = (string)$xml2->info[0]->expires;
  111. $fecha = date('Y-m-j\TH:i:s');
  112. $fechas = strtotime('0 day', strtotime($fecha));
  113. $fecha1d = date('Y-m-d\TH:i:s', $fechas);
  114. echo (ini_get('display_errors') == 1 ? '<script>console.log("<Actual Date> => ' . $fecha1d . '");</script>' : '');
  115. echo (ini_get('display_errors') == 1 ? '<script>console.log("<Effective> => ' . $efectivo . '");</script>' : '');
  116. echo (ini_get('display_errors') == 1 ? '<script>console.log("<expires> => ' . $expira . '");</script>' : '');
  117.  
  118. if ($expira >= $fecha1d) {
  119. if ($fecha1d >= $efectivo) {
  120. echo (ini_get('display_errors') == 1 ? '<script>console.log("CAP => Valido para mostrar ... ' . '");</script>' : '');
  121.  
  122. $event = (string)$xml2->info[0]->event;
  123. $urgencia = (string)$xml2->info[0]->urgency;
  124. $severidad = (string)$xml2->info[0]->severity;
  125. $inicia = (string)$xml2->info[0]->effective;
  126. $encabezado = (string)$xml2->info[0]->headline;
  127. $descrp_texto = (string)$xml2->info[0]->description;
  128. $posDesc = strpos($descrp_texto, "datos");
  129. $gtDescr = substr($descrp_texto, 0, $posDesc - 5);
  130. $descrip = utf8_encode($gtDescr);
  131. $instruc = (string)$xml2->info[0]->instruction;
  132. $semaforo = "";
  133. $region = "";
  134.  
  135. foreach ($xml2->info[0]->parameter as $parametro) {
  136. if (utf8_encode($parametro->valueName) == utf8_encode('semáforo')) {
  137. $semaforo = (string)$parametro->value;
  138. }
  139. if ($parametro->valueName == 'layer:Google:Region:0.1') {
  140. $region = (string)$parametro->value;
  141. }
  142. }
  143. $area_par = (string)$xml2->info[0]->area->polygon;
  144.  
  145. $area_Alerta = (string)$xml2->info[0]->area->areaDesc[0];
  146. $poligon1 = (string)$xml2->info[0]->area->polygon[0];
  147. $poligon2 = (string)$xml2->info[0]->area->polygon[1];
  148. $idlink = (string)$xml2->identifier;
  149. $titulo_e = trim($encabezado);
  150. if ($area_par == "") {
  151. $poligon01 = "";
  152. } else {
  153. $poligon0 = array();
  154. $i = 0;
  155. foreach ($xml2->info[0]->area->polygon as $polgn) {
  156. array_push($poligon0, (string)$polgn);
  157. }
  158. $poligon01 = implode(":", $poligon0);
  159. }
  160.  
  161. // Imprimir cada resultado en un bloque separado
  162. echo '<div class="resultado">
  163. <h2>' . htmlspecialchars($titulo_e) . '</h2>
  164. <p><strong>ID:</strong> ' . htmlspecialchars($idlink) . '</p>
  165. <p><strong>Evento:</strong> ' . htmlspecialchars($event) . '</p>
  166. <p><strong>Urgencia:</strong> ' . htmlspecialchars($urgencia) . '</p>
  167. <p><strong>Severidad:</strong> ' . htmlspecialchars($severidad) . '</p>
  168. <p><strong>Inicio:</strong> ' . htmlspecialchars($inicia) . '</p>
  169. <p><strong>Expira:</strong> ' . htmlspecialchars($expira) . '</p>
  170. <p><strong>Descripción:</strong> ' . htmlspecialchars($descrip) . '</p>
  171. <p><strong>Instrucciones:</strong> ' . htmlspecialchars($instruc) . '</p>
  172. <p><strong>Semáforo:</strong> ' . htmlspecialchars($semaforo) . '</p>
  173. <p><strong>Región:</strong> ' . htmlspecialchars($region) . '</p>
  174. <p><strong>Área Alerta:</strong> ' . htmlspecialchars($area_Alerta) . '</p>
  175. <p><strong>Polígono:</strong> ' . htmlspecialchars($poligon01) . '</p>
  176. </div>';
  177. }
  178. }
  179. }
  180. }
  181.  
  182. // Cerrar el HTML
  183. echo '</body>
  184. </html>';
  185.  
  186. } catch (PDOException $e) {
  187. print_r("Error");
  188. die();
  189. }
  190.  
  191. ##################################################################
  192. # Get url only way with SSL
  193. ###############################################################
  194. function get_web_page($url)
  195. {
  196. echo (ini_get('display_errors') == 1 ? 'get_web_page => START...' . '<br>' : '');
  197. $response = array();
  198.  
  199. $options = array(
  200. CURLOPT_RETURNTRANSFER => true, // return web page
  201. CURLOPT_HEADER => false, // don't return headers
  202. CURLOPT_FRESH_CONNECT => true,
  203. CURLOPT_FOLLOWLOCATION => true, // follow redirects
  204. CURLOPT_ENCODING => "", // handle all encodings
  205. CURLOPT_USERAGENT => "SMN", // who am i
  206. CURLOPT_AUTOREFERER => true, // set referer on redirect
  207. CURLOPT_CONNECTTIMEOUT => 30, // timeout on connect
  208. CURLOPT_TIMEOUT => 30, // timeout on response
  209. CURLOPT_MAXREDIRS => 1, // stop after 10 redirects
  210. CURLOPT_SSL_VERIFYHOST => false, //stop SSL host verification
  211. CURLOPT_SSL_VERIFYPEER => false // Disabled SSL Cert checks
  212. );
  213.  
  214. $ch = curl_init($url);
  215. curl_setopt_array($ch, $options);
  216. $content = curl_exec($ch);
  217. $err = curl_errno($ch);
  218. $errmsg = curl_error($ch);
  219. $header = curl_getinfo($ch);
  220. curl_close($ch);
  221.  
  222. $response['header'] = $header;
  223. $response['errno'] = $err;
  224. $response['errmsg'] = $errmsg;
  225. $response['content'] = $content;
  226. return $response;
  227. }
  228. ?>
  229.  
Success #stdin #stdout 0.02s 25968KB
stdin
Standard input is empty
stdout
Standard output is empty