<?php chdir(dirname(__FILE__));chdir("../..");if(!file_exists("config.php"))chdir("../..");require_once"config.php";$Mra=!empty($_GET["display"]);$Mgb=DIR_CACHE."lightning/".'b';$Mpw=rand(0,10000000);file_put_contents(DIR_CACHE."lightning/"."cron_working",$Mpw,LOCK_EX);file_put_contents(DIR_CACHE."lightning/".'d',$Mpw,LOCK_EX);$M_j=DIR_CACHE."lightning/".'gz';if(file_exists($M_j)&&filemtime($M_j)>time()-30*60)$M_j=false;$M_k=time();Wkd();$Mpx=0;$Mpy=0;$Mdl=0;$Mou=0;function show(){echo str_repeat(' ',1024*4);flush();ob_flush();}
function Wjh($Mil,$Mzd=""){echo"<p class='$Mzd'>$Mil</p>";show();}
if($Mra){header("Content-Type: text/html; charset=utf-8");echo"<!DOCTYPE html><html xmlns='http://www.w3.org/1999/html'><head><meta charset='utf-8'>";echo"<title>Lightning CRON Pregeneration Task</title>";echo"<link rel='stylesheet' href='//lightning.devs.mx/service/css/lightning.css' />";echo"<link href='//demo.devs.mx/lightning/image/catalog/light_mark_blue.gif' rel='icon' />";echo"<style>pre{white-space: pre-wrap;} .wait{ color: grey; font-style: italic } .time_line{color:grey; font-size: 12px; margin-top: -5px;} .exit{color:green; font-weight: bold}</style>";echo"</head><body><div id='header'><img src='//lightning.devs.mx/share/head3_logo.png'/></div><div id='content'>";echo"<h2>Lightning CRON Pregeneration Task</h2>";show();}
while(true){set_time_limit(120);touch(DIR_CACHE."lightning/"."cron_working");Wkd();if(!file_exists($Mgb.'aq')and($Mpx++<60)){if($Mdl){if($Mou>1&&$Mra)Wjh("$Mou streak, ".round(microtime(true)-$Mdl,2)." sec");$Mou=0;$Mdl=0;}
if($Mra&&!file_exists($Mgb.'aq')&&$Mpx==1)Wjh("Waiting for any task ...","wait");sleep(1);clearstatcache();continue;}
$Mpx=0;if(file_get_contents(DIR_CACHE."lightning/"."cron_working")!=$Mpw){if($Mra)Wjh("Next instance found, exiting","exit");Wkd("DONE");exit;}
if(!$Mdl)$Mdl=microtime(true);$Mou++;if($Mra){if(file_exists($Mgb.'aq')){$Mbq=unserialize(file_get_contents($Mgb.'aq'));if($Mbq["GET"]["li_op"]=="gens")Wjh("Checking gen needs for <a target='_blank' href='".$Mbq['at'].$Mbq['au']."'>".$Mbq['at'].$Mbq['au']."</a> ...");}else Wjh("While idle, checking gen needs for homepage ...");}
$Mlm=Wap(HTTP_SERVER."index.php?li_op=gen",false,"Lightning CRON Job");if($Mra&&!empty($Mze["x-opencart-lightning-gen"])){Wjh("Generated <a target='_blank' href='".$Mze["x-opencart-lightning-gen"]."'>".$Mze["x-opencart-lightning-gen"]."</a>");if(!empty($Mze["x-opencart-lightning"]))Wjh(substr($Mze["x-opencart-lightning"],strpos($Mze["x-opencart-lightning"],' ')+1),"time_line");}
if(!empty($Mze["x-opencart-lightning-gen"])&&strpos($Mze["x-opencart-lightning-gen"],"ending mail"))$Mpx=999;if($Mlm=="false"){sleep(5);continue;}
if(strpos($Mlm,"OX")===false){if($Mpy++>5){if($Mra){Wjh("$Mpy page retrieval faults, exiting!","exit");Wjh("URL: ".HTTP_SERVER."index.php?li_op=gen");Wjh("Code: ".$Mdf);Wjh("Result: ".$Mlm);}
Wkd("FAULT: ".$Mlm);exit(1);}
}else$Mpy=0;}
exit;function Wkd($Mww=false){global$M_j,$M_k;if(!$M_j)return;if(!$Mww)$Mww=time()-$M_k;file_put_contents($M_j,$Mww);}
function Wji($Mzf,$Mzg){global$Mze;$Mzh=strlen($Mzg);$Mzg=explode(':',$Mzg,2);if(count($Mzg)<2)return$Mzh;$Mze[strtolower(trim($Mzg[0]))]=trim($Mzg[1]);return$Mzh;}
function Wap($Mbe,$Mhm=false,$Mhn="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36"){static$Mpz;if(!$Mpz)$Mbe=str_replace("https:","http:",$Mbe);static$Mho;if(!$Mho){$Mho=curl_init($Mbe);curl_setopt($Mho,CURLOPT_URL,$Mbe);curl_setopt($Mho,CURLOPT_RETURNTRANSFER,1);curl_setopt($Mho,CURLOPT_ENCODING,"");curl_setopt($Mho,CURLOPT_USERAGENT,$Mhn);curl_setopt($Mho,CURLOPT_TIMEOUT,200);curl_setopt($Mho,CURLOPT_CONNECTTIMEOUT,200);curl_setopt($Mho,CURLOPT_SSL_VERIFYPEER,false);curl_setopt($Mho,CURLOPT_SSL_VERIFYHOST,false);if($Mhm){curl_setopt($Mho,CURLOPT_POST,1);curl_setopt($Mho,CURLOPT_POSTFIELDS,$Mhm);}
global$Mra;if($Mra){curl_setopt($Mho,CURLOPT_HEADERFUNCTION,'Wji');}}
global$Mze;$Mze=array();$Mhp=curl_exec($Mho);global$Mdf;$Mdf=curl_getinfo($Mho,CURLINFO_HTTP_CODE);$Mrw=0;while($Mdf>299&&$Mdf<399){$Mpz=true;if(phpversion()<"5.3.7"||$Mrw++>3){curl_close($Mho);$Mho=false;return false;}
$Mhq=curl_getinfo($Mho,CURLINFO_REDIRECT_URL);if(!$Mhq){$Mdf=500;curl_close($Mho);$Mho=false;return false;}
curl_setopt($Mho,CURLOPT_URL,$Mhq);$Mhp=curl_exec($Mho);$Mdf=curl_getinfo($Mho,CURLINFO_HTTP_CODE);}
return$Mhp;}