Initial commit

This commit is contained in:
GRASPA
2017-09-22 15:02:55 +02:00
parent 4cf73afa59
commit 63586bf3e6
159 changed files with 20811 additions and 0 deletions
+3952
View File
File diff suppressed because it is too large Load Diff
+2612
View File
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
[db]
host = "db.earthquakenetwork.it"
db = "eqn_prod"
dbase = "eqn_prod"
user = "eqnet.user"
pass = "due.7632"
log = "0"
+36
View File
@@ -0,0 +1,36 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
$user_id=$_REQUEST['user_id'];
$codever=$_REQUEST['code'];
if ($user_id<>0)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query("select ID,ver_code from mailservice where user_id=$user_id");
if (mysql_num_rows($sql))
{
$id=mysql_result($sql,0,"ID");
$code=mysql_result($sql,0,"ver_code");
if ($code==$codever){
$output[]="ok";
$sql=mysql_query("delete from mailservice where ID=$id");
}
else{
$output[]="wrg";
}
}
else
{
$output[]="mis";
}
print(json_encode($output));
mysql_close();
}
else{
$output[]="nok";
print(json_encode($output));
}
?>
+688
View File
@@ -0,0 +1,688 @@
<?php
$url="http://earthquake.usgs.gov/earthquakes/feed/geojson/2.5/week";
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
if (count($data)>0)
{
//extract the maximum date
$sql=mysql_query("select data from automatic_temp order by data DESC limit 1");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"data");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_temp");
foreach($data['features'] as $quake) {
$place=mysql_real_escape_string($quake['properties']['place']);
$stamp=$quake['properties']['time']/1000;
$time=date('Y-m-d H:i:s',$stamp);
$felt=$quake['properties']['felt'];
$cdi=$quake['properties']['cdi'];
$mmi=$quake['properties']['mmi'];
$tsunami=$quake['properties']['tsunami'];
$url=$quake['properties']['url'];
if ($felt==null){
$felt=0;
}
if ($cdi==null){
$cdi=0;
}
if ($mmi==null){
$mmi=0;
}
$cdi=max($cdi,$mmi);
if ($tsunami==null){
$tsunami=-1;
}
$mag=(float)$quake['properties']['mag'];
$lat=(float)$quake['geometry']['coordinates'][1];
$lon=(float)$quake['geometry']['coordinates'][0];
$dep=(float)$quake['geometry']['coordinates'][2];
$code=$quake['properties']['code'];
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$sql=mysql_query("insert into automatic_temp (latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,place,data,code,tsunami,url,provider) values ($lat,$lon,$dep,$mag,$felt,$cdi,$pop25,$pop100,$pop200,'$place','$time','$code',$tsunami,'$url','USGS')");
}
}
$sql=mysql_query("select automatic_temp.latitude,automatic_temp.longitude,automatic_temp.depth,automatic_temp.magnitude,automatic_temp.data,automatic_temp.code,automatic_temp.place from automatic_temp left join contest_earthquakes on automatic_temp.code=contest_earthquakes.code where automatic_temp.magnitude>=5.5 AND contest_earthquakes.code is null AND automatic_temp.code<>'' AND automatic_temp.data > (select data from contest_earthquakes order by data desc limit 1)");
if (mysql_num_rows($sql)){
$q=mysql_query("select ID,current_contest_number from contest_state");
$contest_number=mysql_result($q,0,"current_contest_number");
$contest_ID=mysql_result($q,0,"ID");
$num_rows = mysql_num_rows($sql);
for ($i=0;$i<$num_rows;$i++){
$latitude=mysql_result($sql,$i,"latitude");
$longitude=mysql_result($sql,$i,"longitude");
$depth=mysql_result($sql,$i,"depth");
$magnitude=mysql_result($sql,$i,"magnitude");
$data=mysql_result($sql,$i,"data");
$code=mysql_result($sql,$i,"code");
$place=mysql_real_escape_string(mysql_result($sql,$i,"place"));
$q=mysql_query("insert into contest_earthquakes (latitude,longitude,depth,magnitude,data,code,place,contest_number) values ($latitude,$longitude,$depth,$magnitude,'$data','$code','$place',$contest_number)");
$q=mysql_query("insert into contest_earthquakes_notify (contest_number) values ($contest_number)");
}
$q=mysql_query("select * from contest_users where contest_number=$contest_number");
$num_quakes = mysql_num_rows($sql);
$num_users = mysql_num_rows($q);
for ($i=0;$i<$num_users;$i++){
$distance=99999;
$user_id=mysql_result($q,$i,"user_id");
$user_code=mysql_result($q,$i,"user_code");
for ($j=0;$j<$num_quakes;$j++){
$latitude_earthquake=mysql_result($sql,$j,"latitude");
$longitude_earthquake=mysql_result($sql,$j,"longitude");
$latitude_user=mysql_result($q,$i,"latitude");
$longitude_user=mysql_result($q,$i,"longitude");
$dlat=($latitude_user-$latitude_earthquake)/360*2*pi();
$dlong=($longitude_user-$longitude_earthquake)/360*2*pi();
$latitude_user=$latitude_user/360*2*pi();
$latitude_earthquake=$latitude_earthquake/360*2*pi();
$a=pow(sin($dlat/2),2)+cos($latitude_user)*cos($latitude_earthquake)*pow(sin($dlong/2),2);
$c=2*atan2(sqrt($a),sqrt(1-$a));
$current_distance=6371*$c;
if ($current_distance<$distance){
$distance=$current_distance;
}
}
$score=5;
if ($distance<50){
$score=100;
}
else{
if ($distance<100){
$score=75;
}
else{
if ($distance<250){
$score=50;
}
else{
if ($distance<500){
$score=25;
}
else{
if ($distance<3000){
$score=10;
}
}
}
}
}
if ($user_code==0){
$q2=mysql_query("select * from contest_rank where user_id=$user_id");
if (mysql_num_rows($q2)){
$ID=mysql_result($q2,0,"ID");
$q3=mysql_query("update contest_rank SET number_contests=number_contests+1, score=score+$score where ID=$ID"); }
else{
$nc=1;
$q3=mysql_query("insert into contest_rank (user_id,score,number_contests) values ($user_id,$score,$nc)");
}
}
else{
$q2=mysql_query("select * from contest_rank where user_code=$user_code");
if (mysql_num_rows($q2)){
$ID=mysql_result($q2,0,"ID");
$q3=mysql_query("update contest_rank SET number_contests=number_contests+1, score=score+$score where ID=$ID"); }
else{
$nc=1;
$q3=mysql_query("insert into contest_rank (user_code,score,number_contests) values ($user_code,$score,$nc)");
}
}
}
//invio notifica tramite gcm
$dataArray = array('contest_number'=>$contest_number,'type'=>'contest');
//extract users for notifications
$sql2=mysql_query("select reg_id from gcm");
$counter=0;
$num_rows = mysql_num_rows($sql2);
for ($i = 0; $i < $num_rows; $i++)
{
$regidArray[$counter]=mysql_result($sql2,$i,"reg_id");
$counter=$counter+1;
if ($counter==500 or $i==($num_rows-1))
{
$headers = array(
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
'Content-Type: application/json');
$fields = array(
'registration_ids' => $regidArray,
'data' => $dataArray);
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => $headers,
'content' => json_encode($fields))));
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context);
var_dump($response);
$counter=0;
$regidArray=array();
}
}
$q=mysql_query("UPDATE contest_state SET current_contest_number=current_contest_number+1 WHERE ID=$contest_ID");
}
$sql=mysql_query("select count(*) as mag_45 from automatic_temp where magnitude>4.5 and data > date_sub(now(), interval 3 day)");
$mag_45=mysql_result($sql,0,"mag_45");
$sql=mysql_query("select count(*) as mag_55 from automatic_temp where magnitude>5.5 and data > date_sub(now(), interval 3 day)");
$mag_55=mysql_result($sql,0,"mag_55");
$sql=mysql_query("select count(*) as mag_65 from automatic_temp where magnitude>6.5 and data > date_sub(now(), interval 3 day)");
$mag_65=mysql_result($sql,0,"mag_65");
$sql=mysql_query("select count(*) as mer_40 from automatic_temp where cdi>4.0 and data > date_sub(now(), interval 3 day)");
$mer_40=mysql_result($sql,0,"mer_40");
$sql=mysql_query("select count(*) as mer_60 from automatic_temp where cdi>6.0 and data > date_sub(now(), interval 3 day)");
$mer_60=mysql_result($sql,0,"mer_60");
$sql=mysql_query("select count(*) as mer_80 from automatic_temp where cdi>8.0 and data > date_sub(now(), interval 3 day)");
$mer_80=mysql_result($sql,0,"mer_80");
$sql=mysql_query("select magnitude,cdi,TIMESTAMPDIFF(MINUTE,data, NOW()) AS difference from automatic_temp where data > date_sub(now(), interval 3 day)");
$num_rows = mysql_num_rows($sql);
$geo_index=0;
$pop_index=0;
for ($i=0;$i<$num_rows;$i++){
$magnitude=mysql_result($sql,$i,"magnitude");
$cdi=mysql_result($sql,$i,"cdi");
$difference=mysql_result($sql,$i,"difference");
$factor_time=pow(1-$difference/(3*1440),0.3);
$geo_index=$geo_index+exp($magnitude)*$factor_time;
if ($cdi>0){
$pop_index=$pop_index+exp($cdi)*$factor_time;
}
}
$sql=mysql_query("insert into pressure (mag_45,mag_55,mag_65,mer_40,mer_60,mer_80,geo_index,pop_index) values ($mag_45,$mag_55,$mag_65,$mer_40,$mer_60,$mer_80,$geo_index,$pop_index)");
//Italian quakes
$url="http://geoserver.rm.ingv.it/prociv/ingvrss.xml";
$str = file_get_contents($url);
$xml = simplexml_load_string($str, 'SimpleXMLElement',LIBXML_NOCDATA);
date_default_timezone_set("UTC");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
foreach ($xml->channel->item as $item) {
$pos=strpos($item->description,"Data:");
$desc=substr($item->description,$pos);
$pos1=strpos($desc,"Data:");
$pos2=strpos($desc,"<br");
$data=substr($desc,$pos1+11,$pos2-$pos1-11);
$y=substr($data,6,4);
$m=substr($data,3,2);
$d=substr($data,0,2);
$time=substr($data,11,8);
$delta='+'.$hourdiff.' hour';
$stamp=$y.'-'.$m.'-'.$d.' '.$time;
$timestamp = strtotime($stamp);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$pos1=strpos($desc,"Magnitudo:");
$pos2=strpos($desc,"Distretto:");
$magnitudo=substr($desc,$pos1+16,$pos2-$pos1-28);
$pos1=strpos($desc,"Distretto:");
$pos2=strpos($desc,"Lat:");
$distretto=substr($desc,$pos1+16,$pos2-$pos1-28);
$distretto=str_replace("_"," ",$distretto);
$pos1=strpos($desc,"Lat:");
$pos2=strpos($desc,"Lon:");
$lat=substr($desc,$pos1+10,$pos2-$pos1-19);
$pos1=strpos($desc,"Lon:");
$pos2=strpos($desc,"Profondit");
$lon=substr($desc,$pos1+10,$pos2-$pos1-22);
$pos1=strpos($desc,"Profondit");
$pos2=strpos($desc,"km");
$depth=substr($desc,$pos1+24,$pos2-$pos1-25);
$tsunami=-1;
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$sql=mysql_query("insert into automatic_temp (latitude,longitude,depth,magnitude,pop25,pop100,pop200,place,data,tsunami,provider) values ($lat,$lon,$depth,$magnitudo,$pop25,$pop100,$pop200,'$distretto','$stamp',$tsunami,'INGV')");
}
//Spanish quakes
$data = file_get_contents("http://www.ign.es/ign/layoutIn/sismoTerremotos30Spain.do");
$data = mb_convert_encoding($data, 'UTF-8',mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true));
$data = str_replace("\n", '', $data); // remove new lines
$data = str_replace("\r", '', $data); // remove carriage returns
preg_match_all('|<td>.*?</td>|',$data,$result);
$result=array_slice($result[0],11);
if (count($result)%11 != 0)
{
print("Errore - Numero di celle errato");
}
else
{
date_default_timezone_set("GMT");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$count=count($result)/11;
for ($i=0;$i<$count;$i++)
{
$code=$result[$i*11];
$code=substr($code,4,strlen($code)-9);
$date=$result[$i*11+1];
$date=substr($date,4,strlen($date)-9);
$time=$result[$i*11+2];
$time=substr($time,4,strlen($time)-9);
$lat=$result[$i*11+3];
$lat=substr($lat,4,strlen($lat)-9);
$lon=$result[$i*11+4];
$lon=substr($lon,4,strlen($lon)-9);
$depth=$result[$i*11+5];
$depth=substr($depth,4,strlen($depth)-9);
$magnitude=$result[$i*11+6];
$magnitude=substr($magnitude,4,strlen($magnitude)-9);
$intensity=$result[$i*11+8];
$intensity=substr($intensity,4,strlen($intensity)-9);
$place=$result[$i*11+9];
$place=substr($place,4,strlen($place)-9);
$place=ucwords(strtolower($place));
$y=substr($date,6,4);
$m=substr($date,3,2);
$d=substr($date,0,2);
$delta='+'.$hourdiff.' hour';
$stamp=$y.'-'.$m.'-'.$d.' '.$time;
$timestamp = strtotime($stamp);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$tsunami=-1;
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$sql=mysql_query("insert into automatic_temp (latitude,longitude,depth,magnitude,pop25,pop100,pop200,place,data,tsunami,provider) values ($lat,$lon,$depth,$magnitude,$pop25,$pop100,$pop200,'$place','$stamp',$tsunami,'IGN')");
}
}
//EMCS quakes
$url="http://www.emsc-csem.org/Earthquake/Map/earth/kml.php";
$str = file_get_contents($url);
$xml = simplexml_load_file($url);
date_default_timezone_set("GMT");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
foreach ($xml->Document->Folder as $folder) {
foreach($folder->Placemark as $place){
$description=(string)$place->description;
preg_match_all('|-.*?</h2>|',$description,$result);
$result=$result[0][0];
$result=substr($result,2,strlen($result)-7);
$place=ucwords(strtolower($result));
preg_match_all('|</h2><br><b>.*?</b>|',$description,$result);
$result=$result[0][0];
$stamp=substr($result,12,strlen($result)-22);
$timestamp = strtotime($stamp);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
if($stamp2>strtotime('-7 days'))
{
preg_match_all('|Latitude</b></td><td style="padding-left:5px;">.*?<br>|',$description,$result);
$result=$result[0][0];
$lat=substr($result,49,strlen($result)-53);
$sign=substr($lat,strlen($lat)-1,1);
$lat=substr($lat,0,strlen($lat)-2);
if (strcmp($sign,'S')==0){
$lat=$lat*-1;
}
preg_match_all('|Longitude</b></td><td style="padding-left:5px;">.*?<br>|',$description,$result);
$result=$result[0][0];
$lon=substr($result,50,strlen($result)-54);
$sign=substr($lon,strlen($lon)-1,1);
$lon=substr($lon,0,strlen($lon)-2);
if (strcmp($sign,'W')==0){
$lon=$lon*-1;
}
preg_match_all('|Deph</b></td><td style="padding-left:5px;">.*?Km|',$description,$result);
$result=$result[0][0];
$depth=substr($result,45,strlen($result)-50);
preg_match_all('|Magnitude</b></td><td style="padding-left:5px;">.*?<br>|',$description,$result);
$result=$result[0][0];
$magnitude=substr($result,53,strlen($result)-57);
$tsunami=-1;
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$sql=mysql_query("insert into automatic_temp (latitude,longitude,depth,magnitude,pop25,pop100,pop200,place,data,tsunami,provider) values ($lat,$lon,$depth,$magnitude,$pop25,$pop100,$pop200,'$place','$stamp',$tsunami,'EMSC')");
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic");
$sql=mysql_query("INSERT INTO automatic SELECT * FROM automatic_temp");
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,place,provider from automatic_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'type'=>'official');
//extract users for notifications
$sql2=mysql_query("select reg_id from gcm");
$counter=0;
$num_rows2 = mysql_num_rows($sql2);
for ($i = 0; $i < $num_rows2; $i++)
{
$regidArray[$counter]=mysql_result($sql2,$i,"reg_id");
$counter=$counter+1;
if ($counter==500 or $i==($num_rows2-1))
{
$headers = array(
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
'Content-Type: application/json');
$fields = array(
'registration_ids' => $regidArray,
'data' => $dataArray);
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => $headers,
'content' => json_encode($fields))));
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context);
var_dump($response);
$counter=0;
$regidArray=array();
}
}
}
}
$output[]="ok";
print(json_encode($output));
mysql_close();
?>
+358
View File
@@ -0,0 +1,358 @@
<?php
//CSI earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 35
)
)
);
$data = file_get_contents("http://www.csi.ac.cn/publish/main/1/100170/index.html",0,$ctx);
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='CSI'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_csi_temp");
$data = str_replace("\n", '', $data); // remove new lines
$data = str_replace("\r", '', $data); // remove carriage returns
preg_match_all('|<tr onmouseover.*?</tr>|',$data,$result);
$result=$result[0];
date_default_timezone_set("Asia/Shanghai");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
for ($i=0;$i<count($result);$i++){
preg_match_all('|<td.*?</td>|',$result[$i],$item);
$item=$item[0];
$idx=strpos($item[0],'/');
$url=substr($item[0],$idx,strlen($item[0])-$idx-32);
$url="http://www.csi.ac.cn".$url;
$date=substr($item[1],9,18);
$date=str_replace('/','-',$date);
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$lat=substr($item[2],9,strlen($item[2])-20);
$lon=substr($item[3],9,strlen($item[3])-20);
$idx1=strpos($item[4],'"');
$idx2=strrpos($item[4],'"');
$depth=substr($item[4],$idx1+1,$idx2-$idx1-1);
$magnitude=substr($item[5],6,strlen($item[5])-15);
$magnitude_type='ML';
$idx1=strpos($item[6],'self">');
$idx2=strrpos($item[6],'</a>');
$place=substr($item[6],$idx1+6,$idx2-$idx1-6);
$tsunami=-1;
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_csi_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'CSI',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_csi_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'CSI',$picture_count)");
}
}
$sql=mysql_query("select * from automatic_csi_temp");
if (mysql_num_rows($sql)){
//empty the table
$sql=mysql_query("TRUNCATE automatic_csi");
$sql=mysql_query("INSERT INTO automatic_csi SELECT * FROM automatic_csi_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'CSI'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type,felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_csi_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_csi_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by difference desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_csi (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'difference'=>mysql_result($sql,$j,"difference"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_csi=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='CSI'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='CSI'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_csi");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_csi where ID<$max_id-40");
}
}
}
else{
print("Timeout");
}
mysql_close();
?>
+407
View File
@@ -0,0 +1,407 @@
<?php
//EMSC earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$url="http://www.emsc-csem.org/Earthquake/Map/earth/kml.php";
$xml = simplexml_load_file($url);
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='EMSC'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_emsc_temp");
date_default_timezone_set("UTC");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
foreach ($xml->Document->Folder as $folder) {
foreach($folder->Placemark as $place){
$description=(string)$place->description;
preg_match_all('|-.*?</h2>|',$description,$result);
$result=$result[0][0];
$result=substr($result,2,strlen($result)-7);
$place=ucwords(strtolower($result));
preg_match_all('|</h2><br><b>.*?</b>|',$description,$result);
$result=$result[0][0];
$stamp=substr($result,12,strlen($result)-22);
$code=hash('ripemd160',$stamp);
$timestamp = strtotime($stamp);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
if($stamp2>strtotime('-1 days'))
{
preg_match_all('|Latitude</b></td><td style="padding-left:5px;">.*?<br>|',$description,$result);
$result=$result[0][0];
$lat=substr($result,49,strlen($result)-53);
$sign=substr($lat,strlen($lat)-1,1);
$lat=substr($lat,0,strlen($lat)-2);
if (strcmp($sign,'S')==0){
$lat=$lat*-1;
}
preg_match_all('|Longitude</b></td><td style="padding-left:5px;">.*?<br>|',$description,$result);
$result=$result[0][0];
$lon=substr($result,50,strlen($result)-54);
$sign=substr($lon,strlen($lon)-1,1);
$lon=substr($lon,0,strlen($lon)-2);
if (strcmp($sign,'W')==0){
$lon=$lon*-1;
}
preg_match_all('|Deph</b></td><td style="padding-left:5px;">.*?Km|',$description,$result);
$result=$result[0][0];
$depth=substr($result,45,strlen($result)-50);
preg_match_all('|Magnitude</b></td><td style="padding-left:5px;">.*?<br>|',$description,$result);
$result=$result[0][0];
$magnitude=substr($result,53,strlen($result)-57);
$magnitude_type=trim(substr($result,50,2));
$tsunami=-1;
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_emsc_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'EMSC',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_emsc_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'EMSC',$picture_count)");
}
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_emsc");
$sql=mysql_query("INSERT INTO automatic_emsc SELECT * FROM automatic_emsc_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'EMSC'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_emsc_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_emsc_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 and magnitude>=2 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$mag=mysql_result($sql,$j,"magnitude");
$sql_z=mysql_query("INSERT INTO delay_emsc (delay) values ($delay)");
if (floatval($mag)>=4.5){
$url = 'http://www.earthquakenetwork.it/mysql/distquake_upload_chat3.php';
$text_ita="Sisma magnitudo preliminare ".mysql_result($sql,$j,"magnitude")." rilevato a ".mysql_result($sql,$j,"place")." ".$delay." minuti fa. Fonte EMSC.";
$chat_data = array('u_id'=>'1','nick' => 'Robot', 'password' => 'h7k32fw9','postfix' =>'_ita_gen','u_code'=>'1','msg_code'=>'123456','message'=>$text_ita,'ver'=>'1');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($chat_data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$text_es="Sismo magnitud preliminar ".mysql_result($sql,$j,"magnitude")." detectado en ".mysql_result($sql,$j,"place")." hace ".$delay." minutos. Fuente EMSC.";
$chat_data = array('u_id'=>'1','nick' => 'Robot', 'password' => 'h7k32fw9','postfix' =>'_es_gen','u_code'=>'1','msg_code'=>'123457','message'=>$text_es,'ver'=>'1');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($chat_data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$text_eng="Earthquake preliminary magnitude ".mysql_result($sql,$j,"magnitude")." detected at ".mysql_result($sql,$j,"place")." ".$delay." minutes ago. Source EMSC.";
$chat_data = array('u_id'=>'1','nick' => 'Robot', 'password' => 'h7k32fw9','postfix' =>'_eng_gen','u_code'=>'1','msg_code'=>'123458','message'=>$text_eng,'ver'=>'1');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($chat_data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
}
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'difference'=>mysql_result($sql,$j,"difference"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_emsc=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='EMSC'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='EMSC'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_emsc");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_emsc where ID<$max_id-40");
}
$output[]="ok";
print(json_encode($output));
mysql_close();
?>
+371
View File
@@ -0,0 +1,371 @@
<?php
//FUNVISI earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 15
)
)
);
$data = file_get_contents("http://www.funvisis.gob.ve/sis_reciente.php",0,$ctx);
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='FUNVISIS'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_funvisis_temp");
$data = str_replace("\n", '', $data); // remove new lines
$data = str_replace("\r", '', $data); // remove carriage returns
preg_match_all('|<tbody><tr>.*?HLV|',$data,$result);
$result=$result[0];
preg_match_all('|<tr>.*?</tr>|',$result[0],$result1);
$result1=$result1[0];
date_default_timezone_set("America/Caracas");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/60, 1);
$delta='+'.$hourdiff.' minute';
for ($i=0;$i<count($result1);$i++){
if (strlen($result1[$i])>100)
{
preg_match_all('|<td.*?</td>|',$result1[$i],$result2);
$result2=$result2[0];
$lat=$result2[2];
$lat=substr($lat,20,strlen($lat)-25);
$lon=$result2[3];
$lon=substr($lon,20,strlen($lon)-25);
$depth=$result2[4];
$depth=substr($depth,20,strlen($depth)-25);
$magnitude=$result2[5];
$magnitude=substr($magnitude,20,strlen($magnitude)-25);
$magnitude_type='ML';
$place=$result2[6];
preg_match_all('|gif.*?</a>|',$place,$place);
$place=$place[0];
$place=$place[0];
$place=substr($place,5,strlen($place)-9);
$date=$result2[0];
$date=substr($date,20,strlen($date)-25);
$time=$result2[1];
$time=substr($time,20,strlen($time)-25);
$date = str_replace('/','-', $date);
$date=$date.' '.$time;
$code=hash('ripemd160',$date);
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$tsunami=-1;
if ($magnitude>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_funvisis_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'FUNVISIS',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_funvisis_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'FUNVISIS',$picture_count)");
}
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_funvisis");
$sql=mysql_query("INSERT INTO automatic_funvisis SELECT * FROM automatic_funvisis_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'FUNVISIS'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_funvisis_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type, pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_funvisis_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_funvisis (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'difference'=>mysql_result($sql,$j,"difference"),
'data'=>mysql_result($sql,$j,"data"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_funvisis=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='FUNVISIS'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='FUNVISIS'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_funvisis");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_funvisis where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+379
View File
@@ -0,0 +1,379 @@
<?php
//GEONET earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 15
)
)
);
$current_date=date('Y-m-d', time());
$first_date=strtotime("-1 day", strtotime($current_date));
$first_date=date("Y-m-d", $first_date);
$second_date=strtotime("+2 day", strtotime($current_date));
$second_date=date("Y-m-d", $second_date);
$web="http://quakesearch.geonet.org.nz/geojson?bbox=163.60840,-49.18170,182.98828,-32.28713&minmag=2&startdate=".$first_date."&enddate=".$second_date;
var_dump($web);
$json = file_get_contents($web,0,$ctx);
$data = json_decode($json, TRUE);
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='GEONET'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_geonet_temp");
date_default_timezone_set("UTC");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
foreach($data['features'] as $quake)
{
$publicID=$quake['properties']['publicid'];
$sql_place=mysql_query("select place from automatic_geonet where code='$publicID' limit 1");
if (mysql_num_rows($sql_place))
{
$place=mysql_result($sql_place,0,"place");
}
else
{
$location_data = file_get_contents("http://geonet.org.nz/quakes/region/newzealand/".$publicID,0,$ctx);
$location_data = " ".$location_data;
$ini = strpos($location_data,"<td>Location</td>");
$ini += strlen("<td>Location</td><td><strong>");
$len = strpos($location_data,"</strong>",$ini) - $ini;
$place=substr($location_data,$ini,$len);
if (strlen($place)>100){
$place="";
}
}
$place=addslashes($place);
$point=$quake['geometry']['coordinates'];
$lat=$point[1];
$lon=$point[0];
$magnitude=$quake['properties']['magnitude'];
$magnitude=round($magnitude*10)/10;
$magnitude_type=$quake['properties']['magnitudetype'];
$depth=$quake['properties']['depth'];
$date=$quake['properties']['origintime'];
$date=str_replace('T',' ',$date);
$date=str_replace('Z','',$date);
$code=hash('ripemd160',$date);
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$tsunami=-1;
if ($magnitude>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_geonet_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'GEONET',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_geonet_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'GEONET',$picture_count)");
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_geonet");
$sql=mysql_query("INSERT INTO automatic_geonet SELECT * FROM automatic_geonet_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'GEONET'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_geonet_temp order by data DESC limit 150");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_geonet_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_geonet (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'difference'=>mysql_result($sql,$j,"difference"),
'data'=>mysql_result($sql,$j,"data"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_geonet=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='GEONET'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='GEONET'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_geonet");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_geonet where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+382
View File
@@ -0,0 +1,382 @@
<?php
//Chile earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 15
)
)
);
$year0=date('Y');
$month0=date('m');
$day0=date('d');
$year1=date('Y',strtotime('-1 days'));
$month1=date('m',strtotime('-1 days'));
$day1=date('d',strtotime('-1 days'));
$year2=date('Y',strtotime('-2 days'));
$month2=date('m',strtotime('-2 days'));
$day2=date('d',strtotime('-2 days'));
//$link0='http://www.sismologia.cl/events/listados/'.$year0.'/'.$month0.'/'.$year0.$month0.$day0.'.html';
//$data0 = file_get_contents($link0,0,$ctx);
//$link1='http://www.sismologia.cl/events/listados/'.$year1.'/'.$month1.'/'.$year1.$month1.$day1.'.html';
//$data1 = file_get_contents($link1,0,$ctx);
//$link2='http://www.sismologia.cl/events/listados/'.$year2.'/'.$month2.'/'.$year2.$month2.$day2.'.html';
//$data2 = file_get_contents($link2,0,$ctx);
//$data=$data0.$data1.$data2;
// sostituire $place=substr($item[7],4,strlen($item[7])-9); SE SI ATTIVA CODICE SOPRA!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$link='http://www.sismologia.cl/links/ultimos_sismos.html';
$data=file_get_contents($link,0,$ctx);
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='CSN'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_guc_temp");
$data = str_replace("\n", '', $data); // remove new lines
$data = str_replace("\r", '', $data); // remove carriage returns
preg_match_all('|<tr class=.*?</tr>|',$data,$result);
$result=$result[0];
date_default_timezone_set("UTC");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
for ($i=0;$i<count($result);$i++){
preg_match_all('|<td>.*?</td>|',$result[$i],$item);
$item=$item[0];
if (count($item)>0){
$datetime=substr($item[1],4,strlen($item[1])-9);
$code=hash('ripemd160',$datetime);
$lat=substr($item[2],4,strlen($item[2])-9);
$lon=substr($item[3],4,strlen($item[3])-9);
$depth=substr($item[4],4,strlen($item[4])-9);
$magnitude=substr($item[5],4,3);
$magnitude_type=substr($item[5],8,2);
if (strcmp($magnitude_type,'Ml')==0){
$magnitude_type='ML';
}
$place=substr($item[7],4,strlen($item[7])-9);
$date=str_replace('/','-',$datetime);
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$tsunami=-1;
if ($magnitude>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_guc_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'CSN',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_guc_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'CSN',$picture_count)");
}
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_guc");
$sql=mysql_query("INSERT INTO automatic_guc SELECT * FROM automatic_guc_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'CSN'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_guc_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_guc_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_guc (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'difference'=>mysql_result($sql,$j,"difference"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_guc=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='CSN'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='CSN'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_guc");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_guc where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+340
View File
@@ -0,0 +1,340 @@
<?php
//IGEPN earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 15
)
)
);
$xml = simplexml_load_file("http://eventos.igepn.edu.ec/eqevents/events.xml");
if (count($xml)>0)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='IGEPN'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_igepn_temp");
date_default_timezone_set("GMT");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
foreach ($xml->marker as $marker){
$magnitude=$marker["mg"];
$magnitude_type='ML';
$depth=round($marker["z"]);
$place=$marker["localizacion"];
$lat=$marker["lat"];
$lon=$marker["lng"];
$date=$marker["fecha"];
$code=hash('ripemd160',$date);
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$tsunami=-1;
if ($magnitude>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_igepn_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'IGEPN',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_igepn_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'IGEPN',$picture_count)");
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_igepn");
$sql=mysql_query("INSERT INTO automatic_igepn SELECT * FROM automatic_igepn_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'IGEPN'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_igepn_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_igepn_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_igepn (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'difference'=>mysql_result($sql,$j,"difference"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_igepn=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='IGEPN'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='IGEPN'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_igepn");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_igepn where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+355
View File
@@ -0,0 +1,355 @@
<?php
//IGN earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='IGN'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_ign_temp");
$data = file_get_contents("http://www.ign.es/web/ign/portal/ultimos-terremotos");
$data = mb_convert_encoding($data, 'UTF-8',mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true));
$data = str_replace("\n", '', $data); // remove new lines
$data = str_replace("\r", '', $data); // remove carriage returns
preg_match_all('|<tr>.*?</form> </td>|',$data,$result);
$result=$result[0];
if (count($result)>0)
{
date_default_timezone_set("GMT");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
for ($i=0;$i<count($result);$i++)
{
if ($i==0){
$idx=strpos($result[$i],"info</th>");
$result[$i]=substr($result[$i],$idx+20,strlen($result[$i]));
}
preg_match_all('|<td>.*?</td>|',$result[$i],$result2);
$result2=$result2[0];
$code=substr($result2[0],4,strlen($result2[0])-9);
$date=substr($result2[1],4,strlen($result2[1])-9);
$date=substr($date,6,4).'-'.substr($date,3,2).'-'.substr($date,0,2);
$time=substr($result2[2],4,strlen($result2[2])-9);
preg_match_all('|<td class="ta.*?</td>|',$result[$i],$result2);
$result2=$result2[0];
$lat=substr($result2[0],16,strlen($result2[0])-22);
$lon=substr($result2[1],16,strlen($result2[1])-22);
$depth=substr($result2[2],16,strlen($result2[2])-22);
$magnitude=substr($result2[3],16,strlen($result2[3])-22);
$magnitude_type=trim(substr($result2[4],16,strlen($result2[4])-22));
$place=substr($result2[6],16,strlen($result2[6])-22);
$date=$date.' '.$time;
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$tsunami=-1;
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_ign_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'IGN',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_ign_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'IGN',$picture_count)");
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_ign");
$sql=mysql_query("INSERT INTO automatic_ign SELECT * FROM automatic_ign_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'IGN'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_ign_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_ign_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 and TIMESTAMPDIFF(MINUTE,data,NOW())<120 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_ign (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'difference'=>mysql_result($sql,$j,"difference"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_ign=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='IGN'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='IGN'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_ign");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_ign where ID<$max_id-40");
}
mysql_close();
?>
+367
View File
@@ -0,0 +1,367 @@
<?php
//Ineter (nicaragua) earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 50
)
)
);
$url="http://webserver2.ineter.gob.ni/geofisica/sis/events/sismos.php";
$data = file_get_contents($url,0,$ctx);
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='Ineter'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_ineter_temp");
preg_match_all('|<PRE>.*?</PRE>|',$data,$result);
$result=$result[0];
date_default_timezone_set("Europe/Rome");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("America/Managua");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='-'.$hourdiff.' hour';
for ($i=0;$i<count($result)-1;$i++){
$temp=explode(" ",$result[$i]);
$date=$temp[0];
$date=substr($date,5,strlen($date)-4);
$date=str_replace('/','-',$date);
$code=hash('ripemd160',$date);
$time=$temp[1];
$lat=substr($temp[2],0,strlen($temp[2])-1);
$lon=substr($temp[3],0,strlen($temp[3])-1);
$lon=$lon*-1;
if ($temp[6]<>""){
$depth=$temp[6];
}
$magnitude=$temp[8];
$magnitude_type='ML';
$place="";
for ($j=12;$j<count($temp);$j++){
$place=$place." ".$temp[$j];
}
$place=substr($place,1,strlen($place)-7);
$place=mysql_real_escape_string($place);
$date=$date.' '.$time;
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('y-m-d H:i:s',$stamp2);
$tsunami=-1;
if ($magnitude>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_ineter_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'Ineter',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_ineter_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'Ineter',$picture_count)");
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_ineter");
$sql=mysql_query("INSERT INTO automatic_ineter SELECT * FROM automatic_ineter_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'Ineter'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_ineter_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_ineter_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_ineter (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'difference'=>mysql_result($sql,$j,"difference"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_ineter=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='Ineter'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='Ineter'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_ineter");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_ineter where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+401
View File
@@ -0,0 +1,401 @@
<?php
//INGV earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 15
)
)
);
$current_date=date('Y-m-d', time());
$first_date=strtotime("-1 day", strtotime($current_date));
$first_date=date("Y-m-d", $first_date);
$web="http://webservices.rm.ingv.it/fdsnws/event/1/query?starttime=".$first_date."+00%3A00%3A00&endtime=".$current_date."+23%3A59%3A59&last_nd=7&minmag=2&maxmag=10&minlat=35&maxlat=48&minlon=6&maxlon=19&limit=50&page=1&orderby=time&radius_lat=&radius_lon=&radius_km=-1&format=text&limit=250";
$data = file_get_contents($web,0,$ctx);
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='INGV'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_ingv_temp");
$result = explode(PHP_EOL, $data);
date_default_timezone_set("UTC");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
for ($i=1;$i<count($result);$i++){
$result_single = explode("|", $result[$i]);
if (count($result_single)>1){
$code=$result_single[0];
$sql_place=mysql_query("select place from automatic_ingv where code=$code limit 1");
if (mysql_num_rows($sql_place))
{
$place=mysql_result($sql_place,0,"place");
$place=mysql_real_escape_string($place);
}
else
{
$location_data = file_get_contents("http://cnt.rm.ingv.it/event/".$code,0,$ctx);
$location_data = str_replace("\n", '', $location_data); // remove new lines
$location_data = str_replace("\r", '', $location_data); // remove carriage returns
preg_match_all('|<tr class.*?</tr>|',$location_data,$result_location);
if (!empty($result_location[0])){
preg_match_all('|<td>.*?</td>|',$result_location[0][0],$result_location2);
$result_location2=$result_location2[0];
$town=$result_location2[0];
$town=substr($town,4,strlen($town)-9);
$distance_km=$result_location2[2];
$distance_km=substr($distance_km,4,strlen($distance_km)-9);
$place=$result_single[12];
$place=$distance_km."km da ".$town.", Prov. ".$place;
}
else{
$place=$result_single[12];
}
$place=str_replace('&#039;',' ',$place);
$place=str_replace('&ograve;','o',$place);
$place=mysql_real_escape_string($place);
}
$lat=$result_single[2];
$lon=$result_single[3];
$depth=$result_single[4];
$magnitude_type=$result_single[9];
$magnitude=$result_single[10];
$date=$result_single[1];
$date=str_replace('T',' ',$date);
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$tsunami=-1;
if ($magnitude>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_ingv_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'INGV',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_ingv_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'INGV',$picture_count)");
}
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_ingv");
$sql=mysql_query("INSERT INTO automatic_ingv SELECT * FROM automatic_ingv_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'INGV'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_ingv_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_ingv_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_ingv (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'difference'=>mysql_result($sql,$j,"difference"),
'data'=>mysql_result($sql,$j,"data"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_ingv=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='INGV'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='INGV'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_ingv");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_ingv where ID<$max_id-40");
}
$sql=mysql_query("select min(abs(timestampdiff(minute,date,now()))) as delta_min from italian_swarm");
$delta_min=mysql_result($sql,0,"delta_min");
if (is_null($delta_min)){
$delta_min=9999;
}
if ($delta_min>14){
$sql=mysql_query("SET @prevValue:=(SELECT data FROM automatic_ingv where latitude>42 and latitude<43 and longitude>12 and longitude<14 and timestampdiff(MINUTE,data,now())<480 order by data limit 1)");
$sql=mysql_query("SELECT avg(delta) as mean_time from (SELECT abs(timestampdiff(MINUTE,data,@prevValue)) AS delta,@prevValue:=data FROM automatic_ingv where latitude>42 and latitude<43.5 and longitude>12 and longitude<14 and timestampdiff(MINUTE,data,now())<480 order by data) as res");
$mean_time=mysql_result($sql,0,"mean_time");
if ($mean_time>0){
$sql=mysql_query("SELECT avg(magnitude) as mean_magnitude from automatic_ingv where latitude>42 and latitude<43.5 and longitude>12 and longitude<14 and timestampdiff(MINUTE,data,now())<480");
$mean_magnitude=mysql_result($sql,0,"mean_magnitude");
$sql=mysql_query("SELECT max(magnitude) as max_magnitude from automatic_ingv where latitude>42 and latitude<43.5 and longitude>12 and longitude<14 and timestampdiff(MINUTE,data,now())<480");
$max_magnitude=mysql_result($sql,0,"max_magnitude");
$sql=mysql_query("INSERT INTO italian_swarm (mean_time,mean_magnitude,max_magnitude) values ($mean_time,$mean_magnitude,$max_magnitude)");
}
}
}
else{
print("Timeout");
}
mysql_close();
?>
+367
View File
@@ -0,0 +1,367 @@
<?php
//Inpres earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 15
)
)
);
$data = file_get_contents("http://contenidos.inpres.gov.ar/rss/ultimos50.xml",0,$ctx);
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='INPRES'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_inpres_temp");
$data = str_replace("\n", '', $data); // remove new lines
$data = str_replace("\r", '', $data); // remove carriage returns
preg_match_all('|<title>.*?</title>|',$data,$result);
$result=$result[0];
preg_match_all('|<description>.*?</description>|',$data,$result2);
$result2=$result2[0];
date_default_timezone_set("America/Argentina/San_Juan");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
for ($i=0;$i<count($result);$i++){
$item=explode("--",$result[$i]);
$date=substr($item[1],1,strlen($item[1])-2);
$date = str_replace('/','-', $date);
$code=hash('ripemd160',$date);
$time=substr($item[2],1,strlen($item[2])-6);
$datetime=$date.' '.$time;
$lat=substr($item[3],1,strlen($item[3])-2);
$lon=substr($item[4],1,strlen($item[3])-2);
$magnitude=substr($item[5],1,strlen($item[5])-2);
$magnitude_type='ML';
$depth=floatval(substr($item[6],1,strlen($item[6])-6));
$item2=explode(",",$result2[$i]);
$place=$item2[0];
$place=substr($place,13,strlen($place)-1);
$date=$datetime;
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$tsunami=-1;
if ($magnitude>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_inpres_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'INPRES',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_inpres_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'INPRES',$picture_count)");
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_inpres");
$sql=mysql_query("INSERT INTO automatic_inpres SELECT * FROM automatic_inpres_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'INPRES'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_inpres_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_inpres_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_inpres (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'difference'=>mysql_result($sql,$j,"difference"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_inpres=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='INPRES'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='INPRES'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_inpres");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_inpres where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+409
View File
@@ -0,0 +1,409 @@
<?php
//JMA earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 15
)
)
);
$data = file_get_contents("http://www.jma.go.jp/jp/quake/quake_local_index.html",0,$ctx);
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='JMA'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_jma_temp");
$data = str_replace("\n", '', $data); // remove new lines
$data = str_replace("\r", '', $data); // remove carriage returns
preg_match_all('|<a href=\..*?html>|',$data,$result);
$result=$result[0];
date_default_timezone_set("Asia/Tokyo");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
for ($i=0;$i<count($result);$i++){
$address=$result[$i];
$address=substr($address,9,strlen($address)-10);
$url="http://www.jma.go.jp/jp/quake".$address;
$data2 = file_get_contents($url,0,$ctx);
$data2 = str_replace("\n", '', $data2); // remove new lines
$data2 = str_replace("\r", '', $data2); // remove carriage returns
$idx1=strpos($data2,'平成')+6;
$idx2=strpos($data2,'年');
$year=substr($data2,$idx1,$idx2-$idx1)+1988;
$idx1=strpos($data2,'年')+3;
$idx2=$idx1+2;
$month=substr($data2,$idx1,$idx2-$idx1);
//rimuove la parte iniziale di $data2
$idx1=strpos($data2,'気象庁発表<br>');
$data2=substr($data2,$idx1,1000);
$idx1=strpos($data2,'気象庁発表<br>')+19;
$idx2=strpos($data2,'日');
$day=substr($data2,$idx1,$idx2-$idx1);
$idx1=strpos($data2,'気象庁発表<br>');
$hour=substr($data2,$idx1+24,2);
$minute=substr($data2,$idx1+29,2);
$timestamp = strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':00');
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$idx1=strpos($data2,'北緯')+6;
$idx2=strpos($data2,'度、東');
$lat=substr($data2,$idx1,$idx2-$idx1);
$idx1=strpos($data2,'度、東経')+12;
$idx2=strpos($data2,'度',$idx1);
$lon=substr($data2,$idx1,$idx2-$idx1);
$idx1=strpos($data2,'約')+3;
$idx2=strpos($data2,'km',$idx1);
if ($idx2==FALSE){
$depth="0";
}
else{
$depth=substr($data2,$idx1,$idx2-$idx1);
}
$idx1=strpos($data2,')は')+6;
$idx2=strpos($data2,'と推');
$magnitude=substr($data2,$idx1,$idx2-$idx1);
$magnitude_type='ML';
$lat=$lat+$magnitude/500;
$idx1=strpos($data2,'震源地は')+12;
$idx2=strpos($data2,'(北緯');
$place=substr($data2,$idx1,$idx2-$idx1);
$code=hash('ripemd160',$place);
//rimuove la parte iniziale di $data2
$idx1=strpos($data2,'<pre>');
$data2=substr($data2,$idx1,100);
$idx1=strpos($data2,'震度')+6;
$intensity=substr($data2,$idx1,3);
$intensity=(string)bin2hex(iconv('UTF-8', 'UCS-2',$intensity));
$intensity=intval(substr($intensity,1,1));
$tsunami=-1;
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_jma_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'JMA',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_jma_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'JMA',$picture_count)");
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_jma");
$sql=mysql_query("INSERT INTO automatic_jma SELECT * FROM automatic_jma_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'JMA'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_jma_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_jma_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_jma (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'difference'=>mysql_result($sql,$j,"difference"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_jma=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='JMA'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='JMA'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_jma");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_jma where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+374
View File
@@ -0,0 +1,374 @@
<?php
//Philippines earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 15
)
)
);
$data = file_get_contents('http://www.phivolcs.dost.gov.ph/html/update_SOEPD/EQLatest.html',0,$ctx);
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='PHIVOLCS'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_phivolcs_temp");
$data = str_replace("\n", '', $data); // remove new lines
$data = str_replace("\r", '', $data); // remove carriage returns
preg_match_all('|<tr>.*?</tr>|',$data,$result);
$result=$result[0];
date_default_timezone_set("Asia/Manila");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
for ($i=1;$i<count($result);$i++){ //Notare che il ciclo for inizia da 1!
$str=str_replace('&nbsp;','',$result[$i]);
$str=preg_replace("#\<.*?\>#s","$", $str);
$str=preg_replace('/\$\s+/','$', $str);
$str=preg_replace('/\$+/','$',$str);
$blocks = explode('$', $str);
foreach ($blocks as $key=>&$value) {
if (strlen($value) < 3) {
unset($blocks[$key]);
}
}
$blocks = array_values($blocks);
$datetime=preg_replace("#\<.*?\>#s","", $blocks[0]);
$datetime=preg_replace('/\s+/',' ',$datetime);
$datetime=trim($datetime);
$code=hash('ripemd160',$datetime);
$datetime=str_replace('- ','',$datetime);
$datetime=str_replace(';',':',$datetime);
if (strlen($datetime)==20){
$date=date_create_from_format('j M Y H:i A',$datetime);
$timestamp = strtotime(date_format($date, 'Y-m-d H:i:s'));
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$diff = round((strtotime(date('Y-m-d H:i:s')) - strtotime($stamp))/3600, 1);
if ($diff<=24){
$lat=$blocks[1];
$lon=$blocks[2];
$depth=$blocks[3];
$magnitude=$blocks[4];
$magnitude_type='Ms';
$place=$blocks[5].' '.$blocks[6].' '.$blocks[8].' '.$blocks[9];
$place=preg_replace('/[^A-Za-z0-9\- ()]/', 'deg', $place);
$place=trim($place);
$place=mysql_real_escape_string($place);
$tsunami=-1;
if (floatval($magnitude)>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($magnitude<5.5){
if ($ok==1){
$sql=mysql_query("insert into automatic_phivolcs_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'PHIVOLCS',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_phivolcs_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'PHIVOLCS',$picture_count)");
}
}
}
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_phivolcs");
$sql=mysql_query("INSERT INTO automatic_phivolcs SELECT * FROM automatic_phivolcs_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'PHIVOLCS'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_phivolcs_temp");
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_phivolcs_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_phivolcs (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'difference'=>mysql_result($sql,$j,"difference"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_phivolcs=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='PHIVOLCS'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='PHIVOLCS'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_phivolcs");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_phivolcs where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+345
View File
@@ -0,0 +1,345 @@
<?php
//RSN earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 15
)
)
);
$xml = simplexml_load_file("http://www.rsn.ucr.ac.cr/mapalocal/generamapa.php");
if (count($xml)>0)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='RSN'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_rsn_temp");
date_default_timezone_set("GMT");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
foreach ($xml->marker as $marker){
$magnitude=$marker["magnitude"];
$magnitude_type='Mw';
$depth=$marker["evdepth"];
$place=$marker["local"];
$lat=$marker["lat"];
$lon=$marker["lon"];
$date=$marker["origintime"];
$code=hash('ripemd160',$date);
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('Y-m-d H:i:s',$stamp2);
$tsunami=-1;
if ($magnitude>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_rsn_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'RSN',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_rsn_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'RSN',$picture_count)");
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_rsn");
$sql=mysql_query("INSERT INTO automatic_rsn SELECT * FROM automatic_rsn_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'RSN'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_rsn_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_rsn_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_rsn (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'difference'=>mysql_result($sql,$j,"difference"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_rsn=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='RSN'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='RSN'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_rsn");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_rsn where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+370
View File
@@ -0,0 +1,370 @@
<?php
//SGC earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 15
)
)
);
$data = file_get_contents("http://seisan.sgc.gov.co/RSNC/paginas/destacados/diez.php",0,$ctx);
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='SGC'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_sgc_temp");
//$data = str_replace("\n", '', $data); // remove new lines
//$data = str_replace("\r", '', $data); // remove carriage returns
preg_match_all('|<td align=center>.*?</td>|',$data,$result);
$result=$result[0];
$result=array_slice($result,10);
date_default_timezone_set("UTC");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("Europe/Rome");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='+'.$hourdiff.' hour';
for ($i=0;$i<count($result);$i++){
$code='0';
switch (($i+1) % 10) {
case 1:
break;
case 2:
break;
case 3:
$date=substr($result[$i],17,strlen($result[$i])-22);
break;
case 4:
$lat=substr($result[$i],17,strlen($result[$i])-22);
break;
case 5:
$lon=substr($result[$i],17,strlen($result[$i])-22);
break;
case 6:
$depth=substr($result[$i],17,strlen($result[$i])-22);
break;
case 7:
$magnitude=substr($result[$i],17,strlen($result[$i])-22);
$magnitude_type='ML';
break;
case 8:
break;
case 9:
$place=substr($result[$i],17,strlen($result[$i])-22);
break;
case 0:
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('y-m-d H:i:s',$stamp2);
$tsunami=-1;
if ($magnitude>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_sgc_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'SGC',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_sgc_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'SGC',$picture_count)");
}
}
break;
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_sgc");
$sql=mysql_query("INSERT INTO automatic_sgc SELECT * FROM automatic_sgc_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'SGC'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_sgc_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_sgc_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_sgc (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'difference'=>mysql_result($sql,$j,"difference"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_sgc=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='SGC'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='SGC'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_sgc");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_sgc where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+378
View File
@@ -0,0 +1,378 @@
<?php
//SSN earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 50
)
)
);
$url="http://www.ssn.unam.mx/sismicidad/ultimos/";
$data = file_get_contents($url,0,$ctx);
$data = str_replace("\n", '', $data); // remove new lines
$data = str_replace("\r", '', $data); // remove carriage returns
if ($data!=false)
{
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='SSN'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_ssn_temp");
preg_match_all('|<tr class.*?</tr>|',$data,$result);
$result=$result[0];
date_default_timezone_set("Europe/Rome");
$date1=date("Y-m-d H:i:s", time());
date_default_timezone_set("America/Mexico_City");
$date2=date("Y-m-d H:i:s", time());
$hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1);
$delta='-'.$hourdiff.' hour';
for ($i=1;$i<count($result);$i++){
preg_match_all('|<td class.*?</td>|',$result[$i],$block);
$block=$block[0];
$idx1=strpos($block[0],'>');
$idx2=strpos($block[0],'</td>');
$magnitude=substr($block[0],$idx1+1,$idx2-$idx1-1);
$magnitude_type='ML';
$idx1=strpos($block[1],'</span>');
$date=substr($block[1],$idx1-10,10);
$idx1=strpos($block[1],':');
$time=substr($block[1],$idx1-2,8);
$idx1=strpos($block[2],'>');
$idx2=strpos($block[2],'km');
$depth=substr($block[2],$idx1+1,$idx2-$idx1-2);
preg_match_all('|<td><b><span id.*?</td>|',$result[$i],$block);
$block=$block[0];
$idx1=strpos($block[0],"'>");
$idx2=strpos($block[0],'</span>');
$place=substr($block[0],$idx1+2,$idx2-$idx1-2);
$idx1=strpos($block[0],'</b>');
$block[0]=substr($block[0],$idx1+4,200);
$idx1=strpos($block[0],'>');
$idx2=strpos($block[0],'</');
$lat=substr($block[0],$idx1+1,$idx2-$idx1-1);
$idx1=strpos($block[0],'</span>');
$block[0]=substr($block[0],$idx1+7,200);
$idx1=strpos($block[0],'>');
$idx2=strpos($block[0],'</');
$lon=substr($block[0],$idx1+1,$idx2-$idx1-1);
$date=$date.' '.$time;
$timestamp = strtotime($date);
$stamp2=strtotime($delta,$timestamp);
$stamp=date('y-m-d H:i:s',$stamp2);
$tsunami=-1;
$code='0';
if ($magnitude>=2){
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_ssn_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'SSN',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_ssn_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'SSN',$picture_count)");
}
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_ssn");
$sql=mysql_query("INSERT INTO automatic_ssn SELECT * FROM automatic_ssn_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'SSN'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_ssn_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_ssn_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_ssn (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'data'=>mysql_result($sql,$j,"data"),
'difference'=>mysql_result($sql,$j,"difference"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_ssn=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='SSN'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='SSN'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_ssn");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_ssn where ID<$max_id-40");
}
}
else{
print("Timeout");
}
mysql_close();
?>
+27
View File
@@ -0,0 +1,27 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("TRUNCATE automatic");
$sql=mysql_query("INSERT INTO automatic (latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,data,code,place,tsunami,url,provider) SELECT latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,data,code,place,tsunami,url,provider FROM automatic_emsc");
print("ok1");
$sql=mysql_query("INSERT INTO automatic (latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,data,code,place,tsunami,url,provider) SELECT latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,data,code,place,tsunami,url,provider FROM automatic_usgs");
print("ok2");
$sql=mysql_query("INSERT INTO automatic (latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,data,code,place,tsunami,url,provider) SELECT latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,data,code,place,tsunami,url,provider FROM automatic_ingv");
print("ok3");
$sql=mysql_query("INSERT INTO automatic (latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,data,code,place,tsunami,url,provider) SELECT latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,data,code,place,tsunami,url,provider FROM automatic_ign");
print("ok4");
$sql=mysql_query("INSERT INTO automatic (latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,data,code,place,tsunami,url,provider) SELECT latitude,longitude,depth,magnitude,felt,cdi,pop25,pop100,pop200,data,code,place,tsunami,url,provider FROM automatic_csi");
print("ok5");
mysql_close();
?>
+382
View File
@@ -0,0 +1,382 @@
<?php
//USGS earthquakes
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$url="http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson";
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
//extract the maximum date
$sql=mysql_query("select date from last_notifications where provider='USGS'");
if (mysql_num_rows($sql)){
$max_date=mysql_result($sql,0,"date");
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_usgs_temp");
foreach($data['features'] as $quake)
{
$place=mysql_real_escape_string($quake['properties']['place']);
$stamp2=$quake['properties']['time']/1000;
$stamp=date('Y-m-d H:i:s',$stamp2);
$felt=$quake['properties']['felt'];
$cdi=$quake['properties']['cdi'];
$mmi=$quake['properties']['mmi'];
$tsunami=$quake['properties']['tsunami'];
$url=$quake['properties']['url'];
if ($felt==null){
$felt=0;
}
if ($cdi==null){
$cdi=0;
}
if ($mmi==null){
$mmi=0;
}
$cdi=max($cdi,$mmi);
if ($tsunami==null){
$tsunami=-1;
}
$magnitude=(float)$quake['properties']['mag'];
$magnitude_type=$quake['properties']['magType'];
if (strcmp($magnitude_type,'mb_lg')==0){
$magnitude_type='mbLg';
}
if (strcmp($magnitude_type,'ml')==0){
$magnitude_type='ML';
}
$lat=(float)$quake['geometry']['coordinates'][1];
$lon=(float)$quake['geometry']['coordinates'][0];
$depth=(float)$quake['geometry']['coordinates'][2];
$code=$quake['properties']['code'];
$lat_idx=$lat;
$lat_idx=(round($lat_idx*10)/10+0.025)*1000;
if ($lat_idx>90000){
$lat_idx=90000-25;
}
$lon_idx=$lon;
$lon_idx=(round($lon_idx*10)/10+0.025)*1000;
if ($lon_idx>180000){
$lon_idx=$lon_idx-360000;
}
$sql=mysql_query("select pop25,pop100,pop200 from worldpop_recent where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
if (mysql_num_rows($sql)){
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else{
if ($lon_idx<=-120025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop1 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-60025){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop2 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=-25){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop3 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=59975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop4 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
if ($lon_idx<=119975){
$sql=mysql_query("select pop25,pop100,pop200 from worldpop5 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
else{
$sql=mysql_query("select pop25,pop100,pop200 from worldpop6 where latitude=$lat_idx and longitude=$lon_idx LIMIT 1");
}
}
}
}
}
if (mysql_num_rows($sql))
{
$pop25=mysql_result($sql,0,"pop25");
$pop100=mysql_result($sql,0,"pop100");
$pop200=mysql_result($sql,0,"pop200");
}
else
{
$pop25=0;
$pop100=0;
$pop200=0;
}
$sql=mysql_query("insert into worldpop_recent (latitude,longitude,pop25,pop100,pop200) values ($lat_idx,$lon_idx,$pop25,$pop100,$pop200)");
}
$ok=0;
$sql=mysql_query("select * from weather_recent where abs(latitude-$lat)<0.01 and abs(longitude-$lon)<0.01 and abs(TIMESTAMPDIFF(MINUTE,earthquake_date,'$stamp'))<5 LIMIT 1");
if (mysql_num_rows($sql)){
$weather_code=mysql_result($sql,0,"weather_code");
$temperature=mysql_result($sql,0,"temperature");
$humidity=mysql_result($sql,0,"humidity");
$pressure=mysql_result($sql,0,"pressure");
$wind_speed=mysql_result($sql,0,"wind_speed");
$wind_dir=mysql_result($sql,0,"wind_dir");
$clouds=mysql_result($sql,0,"clouds");
$icon=mysql_result($sql,0,"icon");
$ok=1;
}
else{
$current_time=time();
if ($current_time-$stamp2<3600){
$url_weather="http://api.openweathermap.org/data/2.5/weather?lat=".$lat."&lon=".$lon."&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url_weather);
$data_weather = json_decode($json, TRUE);
$weather_code=$data_weather["weather"][0]["id"];
$temperature=$data_weather["main"]["temp"];
$humidity=$data_weather["main"]["humidity"];
$pressure=$data_weather["main"]["pressure"];
if (array_key_exists('speed', $data_weather["wind"])){
$wind_speed=$data_weather["wind"]["speed"];
}
else{
$wind_speed=0;
}
if (array_key_exists('deg', $data_weather["wind"])){
$wind_dir=$data_weather["wind"]["deg"];
}
else{
$wind_dir=0;
}
$clouds=$data_weather["clouds"]["all"];
$icon=$data_weather["weather"][0]["icon"];
if (!is_null($weather_code)){
$sql=mysql_query("insert into weather_recent (latitude,longitude,earthquake_date,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon) values ($lat,$lon,'$stamp',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon')");
$ok=1;
}
}
else{
$ok=0;
}
}
if ($magnitude>=5.5){
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440");
if (mysql_num_rows($sql)){
$picture_count=mysql_result($sql,0,"count");
}
else{
$picture_count=0;
}
}
else{
$picture_count=0;
}
if ($ok==1){
$sql=mysql_query("insert into automatic_usgs_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'USGS',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)");
}
else{
$sql=mysql_query("insert into automatic_usgs_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'USGS',$picture_count)");
}
}
//empty the table
$sql=mysql_query("TRUNCATE automatic_usgs");
$sql=mysql_query("INSERT INTO automatic_usgs SELECT * FROM automatic_usgs_temp");
$sql=mysql_query("DELETE from automatic_all WHERE provider like 'USGS'");
$sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_usgs_temp");
//generate the file
$filename="seismic_free.txt";
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
//extract the new earthquakes
$sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_usgs_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc");
if (mysql_num_rows($sql))
{
$num_rows = mysql_num_rows($sql);
for ($j = 0; $j < $num_rows; $j++)
{
$delay=mysql_result($sql,$j,"difference");
$sql_z=mysql_query("INSERT INTO delay_usgs (delay) values ($delay)");
$dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"),
'longitude'=>mysql_result($sql,$j,"longitude"),
'magnitude'=>mysql_result($sql,$j,"magnitude"),
'magnitude_type'=>mysql_result($sql,$j,"magnitude"),
'place'=>mysql_result($sql,$j,"place"),
'provider'=>mysql_result($sql,$j,"provider"),
'depth'=>mysql_result($sql,$j,"depth"),
'difference'=>mysql_result($sql,$j,"difference"),
'data'=>mysql_result($sql,$j,"data"),
'pop100'=>mysql_result($sql,$j,"pop100"),
'type'=>'official');
//extract users for notifications
$magnitude_notification=mysql_result($sql,$j,"magnitude");
$current_date=mysql_result($sql,$j,"data");
$sql2=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql2, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
while ($keep_going){
$sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_usgs=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
$folder_eqn=uniqid();
mkdir($folder_eqn);
$filename_data=$folder_eqn."/dataarray.json";
file_put_contents($filename_data,json_encode($dataArray));
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$filename=$folder_eqn."/gcmid".$i.".json";
file_put_contents($filename,json_encode($regidArrayGCM));
exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &");
sleep(0.1);
}
sleep(1);
$files = glob($folder_eqn.'/*',GLOB_MARK);
foreach ($files as $file) {
unlink($file);
}
rmdir($folder_eqn.'/');
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
}
$sql_z=mysql_query("select date FROM last_notifications where provider='USGS'");
$last_date=mysql_result($sql_z,0,"date");
if ($current_date>$last_date){
$sql_z=mysql_query("update last_notifications set date='$current_date' where provider='USGS'");
}
}
$sql_z=mysql_query("select max(ID) as max_id FROM delay_usgs");
$max_id=mysql_result($sql_z,0,"max_id");
$sql_z=mysql_query("delete from delay_usgs where ID<$max_id-40");
}
//pressure
$sql=mysql_query("select count(*) as mag_45 from automatic_usgs_temp where magnitude>4.5 and data > date_sub(now(), interval 3 day)");
$mag_45=mysql_result($sql,0,"mag_45");
$sql=mysql_query("select count(*) as mag_55 from automatic_usgs_temp where magnitude>5.5 and data > date_sub(now(), interval 3 day)");
$mag_55=mysql_result($sql,0,"mag_55");
$sql=mysql_query("select count(*) as mag_65 from automatic_usgs_temp where magnitude>6.5 and data > date_sub(now(), interval 3 day)");
$mag_65=mysql_result($sql,0,"mag_65");
$sql=mysql_query("select count(*) as mer_40 from automatic_usgs_temp where cdi>4.0 and data > date_sub(now(), interval 3 day)");
$mer_40=mysql_result($sql,0,"mer_40");
$sql=mysql_query("select count(*) as mer_60 from automatic_usgs_temp where cdi>6.0 and data > date_sub(now(), interval 3 day)");
$mer_60=mysql_result($sql,0,"mer_60");
$sql=mysql_query("select count(*) as mer_80 from automatic_usgs_temp where cdi>8.0 and data > date_sub(now(), interval 3 day)");
$mer_80=mysql_result($sql,0,"mer_80");
$sql=mysql_query("select magnitude,cdi,TIMESTAMPDIFF(MINUTE,data, NOW()) AS difference from automatic_usgs_temp where data > date_sub(now(), interval 3 day)");
$num_rows = mysql_num_rows($sql);
$geo_index=0;
$pop_index=0;
for ($i=0;$i<$num_rows;$i++){
$magnitude=mysql_result($sql,$i,"magnitude");
$cdi=mysql_result($sql,$i,"cdi");
$difference=mysql_result($sql,$i,"difference");
$factor_time=pow(1-$difference/(3*1440),0.3);
$geo_index=$geo_index+exp($magnitude)*$factor_time;
if ($cdi>0){
$pop_index=$pop_index+exp($cdi)*$factor_time;
}
}
$sql=mysql_query("insert into pressure (mag_45,mag_55,mag_65,mer_40,mer_60,mer_80,geo_index,pop_index) values ($mag_45,$mag_55,$mag_65,$mer_40,$mer_60,$mer_80,$geo_index,$pop_index)");
mysql_close();
?>
+40
View File
@@ -0,0 +1,40 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("select ID from manual_history where code='".$_REQUEST['code']."'");
if (mysql_num_rows($sql))
{
$id=mysql_result($sql,0,"ID");
mysql_query("update manual_history SET ban = ban + 0 WHERE ID = $id");
}
$sql=mysql_query("select ID from manual where code='".$_REQUEST['code']."'");
if (mysql_num_rows($sql))
{
$id=mysql_result($sql,0,"ID");
mysql_query("update manual SET ban = ban + 0 WHERE ID = $id");
}
$sql=mysql_query("select ID from manual_notify where code='".$_REQUEST['code']."'");
if (mysql_num_rows($sql))
{
$id=mysql_result($sql,0,"ID");
mysql_query("update manual_notify SET ban = ban + 0 WHERE ID = $id");
}
$output[]="ok";
print(json_encode($output));
mysql_close();
?>
+26
View File
@@ -0,0 +1,26 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("select ID from earthquakes where code='".$_REQUEST['code']."'");
if (mysql_num_rows($sql))
{
$id=mysql_result($sql,0,"ID");
mysql_query("update earthquakes SET ban = ban + 0 WHERE ID = $id");
}
$output[]="ok";
print(json_encode($output));
mysql_close();
?>
+66
View File
@@ -0,0 +1,66 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$user_id=$_REQUEST['u_id'];
$nick=$_REQUEST['nick'];
$nick=mysql_real_escape_string($nick);
$password=$_REQUEST['password'];
$user_toban_code=$_REQUEST['user_toban_code'];
if ($user_id<>0)
{
$sql=mysql_query("select user_code from contest_nick where nick='$nick' and pwd='$password' limit 1");
if (mysql_num_rows($sql))
{
$user_code=mysql_result($sql,0,"user_code");
$match=1;
}
else
{
$match=0;
}
if($match==1){
$sql=mysql_query("select last_known_user_id,nick from contest_nick where user_code=$user_toban_code limit 1");
if (mysql_num_rows($sql))
{
$found=1;
$last_known_user_id=mysql_result($sql,0,"last_known_user_id");
$nick_to_ban=mysql_result($sql,0,"nick");
}
else
{
$found=0;
}
if ($found==1)
{
$sql=mysql_query("insert into personal_ban (user_id_from,user_id_to,user_code_from,user_code_to,nick_from,nick_to) values ($user_id,$last_known_user_id,$user_code,$user_toban_code,'$nick','$nick_to_ban')");
$output="ok";
}
else
{
$output="wrong";
}
}
else{
$output="wrong";
}
}
else{
$output="wrong";
}
print($output);
mysql_close();
?>
+66
View File
@@ -0,0 +1,66 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$user_id=$_REQUEST['u_id'];
$nick=$_REQUEST['nick'];
$nick=mysql_real_escape_string($nick);
$uID=$_REQUEST['uID'];
$user_toban_code=$_REQUEST['user_toban_code'];
if ($user_id<>0)
{
$sql=mysql_query("select user_code from contest_nick where nick='$nick' and uID='$uID' limit 1");
if (mysql_num_rows($sql))
{
$user_code=mysql_result($sql,0,"user_code");
$match=1;
}
else
{
$match=0;
}
if($match==1){
$sql=mysql_query("select last_known_user_id,nick from contest_nick where user_code=$user_toban_code limit 1");
if (mysql_num_rows($sql))
{
$found=1;
$last_known_user_id=mysql_result($sql,0,"last_known_user_id");
$nick_to_ban=mysql_result($sql,0,"nick");
}
else
{
$found=0;
}
if ($found==1)
{
$sql=mysql_query("insert into personal_ban (user_id_from,user_id_to,user_code_from,user_code_to,nick_from,nick_to) values ($user_id,$last_known_user_id,$user_code,$user_toban_code,'$nick','$nick_to_ban')");
$output="ok";
}
else
{
$output="wrong";
}
}
else{
$output="wrong";
}
}
else{
$output="wrong";
}
print($output);
mysql_close();
?>
+76
View File
@@ -0,0 +1,76 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$ID=$_REQUEST['picture_id'];
$user_id=$_REQUEST['u_id'];
$password_ban=$_REQUEST['password_ban'];
$sql=mysql_query("select user_id from manual_picture where ID=$ID");
if (mysql_num_rows($sql)){
$user_toban_id=mysql_result($sql,0,"user_id");
}
else{
$user_toban_id=0;
}
$sql=mysql_query("select * from banned where user_id=$user_toban_id");
if (mysql_num_rows($sql)){
$banned=1;
$output="already";
}
else{
$banned=0;
}
if($banned==0){
$sql=mysql_query("select canbemoderator,nick from contest_nick where last_known_user_id=$user_id order by date_firstlog desc limit 1");
if (mysql_num_rows($sql)){
$moderator=mysql_result($sql,0,"canbemoderator");
$moderator_nick=mysql_result($sql,0,"nick");
}
else{
$moderator=0;
}
if ($moderator==1){
if ($password_ban==91280){
$sql=mysql_query("delete from manual_picture where ID=$ID");
$sql=mysql_query("select last_known_user_id,canbemoderator,nick from contest_nick where last_known_user_id=$user_toban_id limit 1");
if (mysql_num_rows($sql)){
$canbemoderator=mysql_result($sql,0,"canbemoderator");
if ($user_toban_id<>0 && $canbemoderator==0){
$sql=mysql_query("insert into banned (user_id,banned_by) values ($user_toban_id,'$moderator_nick')");
}
}
else{
if ($user_toban_id<>0){
$sql=mysql_query("insert into banned (user_id,banned_by) values ($user_toban_id,'$moderator_nick')");
}
}
$output="ok";
}
else{
$output="wrongpwd";
}
}
else{
$output="nomod";
}
}
else{
$output="nomod";
}
print($output);
mysql_close();
?>
+105
View File
@@ -0,0 +1,105 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$user_id=$_REQUEST['u_id'];
$nick=$_REQUEST['nick'];
$password=$_REQUEST['password'];
$password_ban=$_REQUEST['password_ban'];
$user_toban_code=$_REQUEST['user_code'];
if (!empty($_REQUEST['postfix'])){
$postfix=$_REQUEST['postfix'];
}
else{
$postfix="no_postfix";
}
$sql=mysql_query("select * from banned where user_id=$user_id");
if (mysql_num_rows($sql)){
$banned=1;
$output="wrong";
}
else{
$banned=0;
}
if($banned==0 and $user_id<>862046030418099){
$sql=mysql_query("select moderator from contest_nick where nick='$nick' and pwd='$password' limit 1");
if (mysql_num_rows($sql)){
$moderator=mysql_result($sql,0,"moderator");
}
else{
$moderator=0;
}
if ($moderator==1){
if ($password_ban==91280){
$sql=mysql_query("select last_known_user_id,canbemoderator,nick from contest_nick where user_code=$user_toban_code limit 1");
if (mysql_num_rows($sql)){
$user_toban_id=mysql_result($sql,0,"last_known_user_id");
$user_toban_nick=mysql_result($sql,0,"nick");
$canbemoderator=mysql_result($sql,0,"canbemoderator");
$sql=mysql_query("select ID from banned where user_id=$user_toban_id");
if (mysql_num_rows($sql)){
$output="already";
}
else{
if ($user_toban_id<>0 && $canbemoderator==0){
$sql=mysql_query("insert into banned (user_id,banned_by) values ($user_toban_id,'$nick')");
if (strcmp($postfix,"no_postfix")==0){
$output="ok";
}
else{
$text=$user_toban_nick.' blocked by '.$nick;
$url = 'http://www.earthquakenetwork.it/mysql/distquake_upload_chat3.php';
$chat_data = array('u_id'=>'1','nick' => 'Robot', 'password' => 'h7k32fw9','postfix' =>$postfix,'u_code'=>'1','msg_code'=>'1234','message'=>$text);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($chat_data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$output="ok";
}
}
else{
$output="wrong";
}
}
}
else{
$output="wrong";
}
}
else{
$output="wrongpwd";
}
}
else{
$output="nomod";
}
}
else{
$output="nomod";
}
print($output);
mysql_close();
?>
+105
View File
@@ -0,0 +1,105 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$user_id=$_REQUEST['u_id'];
$nick=$_REQUEST['nick'];
$uID=$_REQUEST['uID'];
$password_ban=$_REQUEST['password_ban'];
$user_toban_code=$_REQUEST['user_code'];
if (!empty($_REQUEST['postfix'])){
$postfix=$_REQUEST['postfix'];
}
else{
$postfix="no_postfix";
}
$sql=mysql_query("select * from banned where user_id=$user_id");
if (mysql_num_rows($sql)){
$banned=1;
$output="wrong";
}
else{
$banned=0;
}
if($banned==0 and $user_id<>862046030418099){
$sql=mysql_query("select moderator from contest_nick where nick='$nick' and uID='$uID' limit 1");
if (mysql_num_rows($sql)){
$moderator=mysql_result($sql,0,"moderator");
}
else{
$moderator=0;
}
if ($moderator==1){
if ($password_ban==91280){
$sql=mysql_query("select last_known_user_id,canbemoderator,nick from contest_nick where user_code=$user_toban_code limit 1");
if (mysql_num_rows($sql)){
$user_toban_id=mysql_result($sql,0,"last_known_user_id");
$user_toban_nick=mysql_result($sql,0,"nick");
$canbemoderator=mysql_result($sql,0,"canbemoderator");
$sql=mysql_query("select ID from banned where user_id=$user_toban_id");
if (mysql_num_rows($sql)){
$output="already";
}
else{
if ($user_toban_id<>0 && $canbemoderator==0){
$sql=mysql_query("insert into banned (user_id,banned_by) values ($user_toban_id,'$nick')");
if (strcmp($postfix,"no_postfix")==0){
$output="ok";
}
else{
$text=$user_toban_nick.' blocked by '.$nick;
$url = 'http://www.earthquakenetwork.it/mysql/distquake_upload_chat3.php';
$chat_data = array('u_id'=>'1','nick' => 'Robot', 'password' => 'h7k32fw9','postfix' =>$postfix,'u_code'=>'1','msg_code'=>'1234','message'=>$text,'ver'=>'1');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($chat_data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$output="ok";
}
}
else{
$output="wrong";
}
}
}
else{
$output="wrong";
}
}
else{
$output="wrongpwd";
}
}
else{
$output="nomod";
}
}
else{
$output="nomod";
}
print($output);
mysql_close();
?>
+21
View File
@@ -0,0 +1,21 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("TRUNCATE notifications_copy");
$sql=mysql_query("INSERT INTO notifications_copy (ID,event,user_id,latitude,longitude,accuracy,delta_notification,data,calibrated,Charge,screenOn) SELECT ID,event,user_id,latitude,longitude,accuracy,delta_notification,data,calibrated,Charge,screenOn FROM notifications");
mysql_close();
?>
+72
View File
@@ -0,0 +1,72 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql1=mysql_query("select count(*) as count_earthquakes from earthquakes where donotshow=0 AND ban<5");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_green from notifications where latitude<>0 AND longitude<>0 AND enabled=1");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_red from notifications_notactive where latitude<>0 AND longitude<>0 AND enabled=0");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_manual_green from manual where magnitude=1 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_manual_yellow from manual where magnitude=2 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_manual_red from manual where magnitude=3 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 0 as count_automatic");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 'Update app' as message");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 0 as count_automatic24");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+46
View File
@@ -0,0 +1,46 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$filename="count_manual.txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>5)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql1=mysql_query("select count(*) as count_manual_green from manual where magnitude=1 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_manual_yellow from manual where magnitude=2 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_manual_red from manual where magnitude=3 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$json_file = json_encode($output);
file_put_contents($filename,$json_file);
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+101
View File
@@ -0,0 +1,101 @@
<?php
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$filename="count_network.txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>15)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql1=mysql_query("select count(*) as count_earthquakes from earthquakes where donotshow=0");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_green from notifications where latitude<>0 AND longitude<>0 AND enabled=1");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 0 count_red");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_past_earthquakes from earthquakes where latitude<>0 AND longitude<>0 AND falsealarm=0");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 0 as online_users");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 435-count(*) as top_100_available from subscriptions where top_100=1 or top_100_annual=1");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 1000-count(*) as top_1000_available from subscriptions where top_1000=1 or top_1000_annual=1");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 10000-count(*) as top_10000_available from subscriptions where top_10000=1 or top_10000_annual=1");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 0 as count_green_ong");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 0 as count_red_ong");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 0 as count_green_sc");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select 0 as count_red_sc");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as emsc_g from automatic_emsc where magnitude<3.5 and data > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as emsc_y from automatic_emsc where magnitude>=3.5 and magnitude<4.5 and data > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as emsc_r from automatic_emsc where magnitude>=4.5 and magnitude<5.5 and data > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as emsc_p from automatic_emsc where magnitude>=5.5 and data > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select latitude as max_lat,longitude as max_lon,magnitude as max_mag,place as max_place from automatic_emsc where data > date_sub(now(), interval 1440 minute) and magnitude=(select max(magnitude) from automatic_emsc where data> date_sub(now(), interval 1440 minute)) limit 1");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$json_file = json_encode($output);
file_put_contents($filename,$json_file);
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+54
View File
@@ -0,0 +1,54 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql1=mysql_query("select count(*) as count_earthquakes from earthquakes where donotshow=0");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_green from notifications where latitude<>0 AND longitude<>0 AND enabled=1");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_red from notifications where latitude<>0 AND longitude<>0 AND enabled=0");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_manual_green from manual where magnitude=1 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_manual_yellow from manual where magnitude=2 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as count_manual_red from manual where magnitude=3 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+126
View File
@@ -0,0 +1,126 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql1=mysql_query("select count(*) as count_earthquakes from earthquakes where donotshow=0");
$sql2=mysql_query("select count(*) as count_green from notifications where latitude<>0 AND longitude<>0 AND enabled=1");
$count_red=0;
$sql4=mysql_query("select least(count(*),999) as count_manual_green from manual where magnitude=1 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$sql5=mysql_query("select least(count(*),999) as count_manual_yellow from manual where magnitude=2 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$sql6=mysql_query("select least(count(*),999) as count_manual_red from manual where magnitude=3 and ban<3 and donotshow=0 and date > date_sub(now(), interval 1440 minute)");
$dataArray = array('count_quakes'=>mysql_result($sql1,0,"count_earthquakes"),
'count_green'=>mysql_result($sql2,0,"count_green"),
'count_red'=>$count_red,
'count_manual_green'=>mysql_result($sql4,0,"count_manual_green"),
'count_manual_yellow'=>mysql_result($sql5,0,"count_manual_yellow"),
'count_manual_red'=>mysql_result($sql6,0,"count_manual_red"),
'type'=>'counts');
$sql=mysql_query("select user_id from gcm order by user_id limit 1");
$user_id_ref = mysql_result($sql, 0, "user_id");
$user_id_ref=$user_id_ref-1;
$row_limit=250000;
$keep_going=1;
$counter_block=1;
while ($keep_going){
print($counter_block."\r\n");
$sql2=mysql_query("select user_id,reg_id from gcm where reg_id<>'' and user_id>$user_id_ref order by user_id limit $row_limit");
$num_rows2 = mysql_num_rows($sql2);
if ($num_rows2>0){
while($data = mysql_fetch_assoc($sql2)){
$regidArray[] = $data['reg_id'];
$IDArray[] = $data['user_id'];
}
$user_id_ref=end($IDArray);
$block_size=999;
$iter=ceil($num_rows2/$block_size);
for ($i=0; $i<$iter; $i++){
$index_start=$i*$block_size;
$index_end=($i+1)*$block_size-1;
if ($index_end>$num_rows2-1){
$index_end=$num_rows2-1;
}
$regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1);
$IDArrayGCM = array_slice($IDArray,$index_start,$index_end-$index_start+1);
$headers = array(
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
'Content-Type: application/json');
$fields = array(
'registration_ids' => $regidArrayGCM,
'time_to_live' => 1500,
'collapse_key' => 'counts_widget',
'priority' => 'normal',
'data' => $dataArray);
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => $headers,
'content' => json_encode($fields))));
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context);
$response=json_decode($response);
$counter=0;
foreach ($response->results as $item)
{
if (array_key_exists('error', $item))
{
$error=$item->error;
if (strcmp($error,'NotRegistered')==0){
$ID=$IDArrayGCM[$counter];
$sql3=mysql_query("update gcm set to_be_deleted=1 where user_id=$ID");
print("Delete user_id ".$ID." at position ".$counter."\r\n");
}
}
if (array_key_exists('registration_id', $item))
{
$new_reg_id=$item->registration_id;
$ID=$IDArrayGCM[$counter];
$sql3=mysql_query("update gcm set reg_id='$new_reg_id' where user_id=$ID");
print("Replaced the reg_id of user with user_id".$ID." at array position ".$counter." with the new id ".$new_reg_id."\r\n");
}
$counter=$counter+1;
}
}
unset($regidArray);
unset($IDArray);
}
else{
$keep_going=0;
}
$counter_block=$counter_block+1;
}
$sql3=mysql_query("delete from gcm where to_be_deleted>=1");
$output[]="ok";
print(json_encode($output));
mysql_close();
?>
+26
View File
@@ -0,0 +1,26 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$q=mysql_query("SELECT DISTINCT(date(date)) AS day, count(*) AS count FROM manual_history GROUP BY day ORDER BY day");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+19
View File
@@ -0,0 +1,19 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("delete from notifications where data < date_sub(now(), interval 41 minute)");
$sql=mysql_query("delete from notifications_notactive where data < date_sub(now(), interval 41 minute)");
mysql_close();
?>
+21
View File
@@ -0,0 +1,21 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("delete from cache_refcount where date < date_sub(now(), interval 10 minute)");
$sql=mysql_query("delete from cache_refcount_all where date < date_sub(now(), interval 10 minute)");
$sql=mysql_query("delete from cache_manualcount where date < date_sub(now(), interval 30 second)");
$sql = mysql_query("delete from candidate where data < date_sub(now(), interval 7 second)");
mysql_close();
?>
+26
View File
@@ -0,0 +1,26 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("delete from chat_eng_gen where date < date_sub(now(), interval 2 day)");
$sql=mysql_query("delete from chat_ita_gen where date < date_sub(now(), interval 2 day)");
$sql=mysql_query("delete from chat_es_gen where date < date_sub(now(), interval 2 day)");
$sql=mysql_query("delete from chat_zh_gen where date < date_sub(now(), interval 2 day)");
$sql=mysql_query("delete from chat_jp_gen where date < date_sub(now(), interval 2 day)");
$sql=mysql_query("delete from chat_pt_gen where date < date_sub(now(), interval 2 day)");
$sql=mysql_query("delete from chat_tag_gen where date < date_sub(now(), interval 2 day)");
$sql=mysql_query("delete from weather_recent where earthquake_date < date_sub(now(), interval 2 day)");
$sql=mysql_query("update earthquakes set donotshow=1 where date < date_sub(now(), interval 24 hour)");
mysql_close();
?>
+18
View File
@@ -0,0 +1,18 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("delete from manual where date < date_sub(now(), interval 24 hour)");
mysql_close();
?>
+33
View File
@@ -0,0 +1,33 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("delete from online_chat_eng where date < date_sub(now(), interval 20 minute)");
$sql=mysql_query("delete from online_chat_ita where date < date_sub(now(), interval 20 minute)");
$sql=mysql_query("delete from online_chat_es where date < date_sub(now(), interval 20 minute)");
$sql=mysql_query("delete from online_chat_zh where date < date_sub(now(), interval 20 minute)");
$sql=mysql_query("delete from online_chat_jp where date < date_sub(now(), interval 20 minute)");
$sql=mysql_query("delete from online_chat_pt where date < date_sub(now(), interval 20 minute)");
$sql=mysql_query("delete from online_chat_tag where date < date_sub(now(), interval 20 minute)");
$sql=mysql_query("delete from online_users where date < date_sub(now(), interval 6 minute)");
$sql=mysql_query("update online_chat_eng set status=1 where date < date_sub(now(), interval 5 minute)");
$sql=mysql_query("update online_chat_ita set status=1 where date < date_sub(now(), interval 5 minute)");
$sql=mysql_query("update online_chat_es set status=1 where date < date_sub(now(), interval 5 minute)");
$sql=mysql_query("update online_chat_zh set status=1 where date < date_sub(now(), interval 5 minute)");
$sql=mysql_query("update online_chat_jp set status=1 where date < date_sub(now(), interval 5 minute)");
$sql=mysql_query("update online_chat_pt set status=1 where date < date_sub(now(), interval 5 minute)");
$sql=mysql_query("update online_chat_tag set status=1 where date < date_sub(now(), interval 5 minute)");
mysql_close();
?>
+18
View File
@@ -0,0 +1,18 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("delete from worldpop_recent where date < date_sub(now(), interval 8 day)");
mysql_close();
?>
+28
View File
@@ -0,0 +1,28 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$nick=$_REQUEST['nick'];
$password=$_REQUEST['password'];
$other_user_code=$_REQUEST['user_code'];
$sql=mysql_query("select nick,country,town,sex,updated,DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), birth)), '%Y')+0 AS age from contest_nick where user_code=$other_user_code limit 1");
while($e=mysql_fetch_assoc($sql))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+44
View File
@@ -0,0 +1,44 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$nick=$_REQUEST['nick'];
$password=$_REQUEST['password'];
$sql=mysql_query("select ID,user_code from contest_nick where nick='$nick' and pwd='$password' limit 1");
if (mysql_num_rows($sql))
{
$user_code=mysql_result($sql,0,"user_code");
$id=mysql_result($sql,0,"ID");
$match=1;
}
else
{
$match=0;
}
if ($match==1)
{
$sql=mysql_query("select nick,country,town,sex,birth from contest_nick where ID=$id limit 1");
while($e=mysql_fetch_assoc($sql))
$output[]=$e;
print(json_encode($output));
}
else
{
print("wrog_user");
}
mysql_close();
?>
+32
View File
@@ -0,0 +1,32 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
//$q=mysql_query("SELECT latitude,longitude,enabled as state FROM notifications union SELECT latitude,longitude,enabled as state FROM notifications_notactive");
$q=mysql_query("SELECT latitude,longitude,enabled as state FROM notifications");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
$q=mysql_query("SELECT latitude,longitude,signals as users,state,code,pro,TIMESTAMPDIFF(MINUTE,date,NOW()) AS difference FROM earthquakes where latitude<>0 AND longitude<>0 AND donotshow=0 AND ban<5");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+32
View File
@@ -0,0 +1,32 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$q=mysql_query("SELECT latitude,longitude,(calibrated&(~screenOn)&(~only_when_charging^Charge)) AS state FROM notifications where latitude<>0 AND longitude<>0");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
$q=mysql_query("SELECT latitude,longitude,state,pro FROM earthquakes where latitude<>0 AND longitude<>0");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+29
View File
@@ -0,0 +1,29 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$latitude = $_REQUEST['lat'];
$longitude = $_REQUEST['lon'];
$sql1=mysql_query("select count(*) as total from notifications where abs(latitude-$latitude)<0.2 and abs(longitude-$longitude)<0.2");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
$sql1=mysql_query("select count(*) as active from notifications where abs(latitude-$latitude)<0.2 and abs(longitude-$longitude)<0.2 and enabled=1");
$e=mysql_fetch_assoc($sql1);
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+25
View File
@@ -0,0 +1,25 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$q=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_emsc union select * from automatic_usgs union select * from automatic_ingv union select * from automatic_ign) as a WHERE a.data > date_sub(NOW(), interval '".$_REQUEST['timeframe']."' minute) AND a.magnitude>='".$_REQUEST['magnitude']."' ORDER BY a.data DESC");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+38
View File
@@ -0,0 +1,38 @@
<?php
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$filename="seismic_free.txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>3)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 AND a.provider NOT LIKE 'IGEPN' ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+38
View File
@@ -0,0 +1,38 @@
<?php
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$filename="seismic_free11.txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>3)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference,weather_code as wc,icon as ic,clouds as cl,wind_speed as ws,pressure as pr,humidity as hu,temperature as te FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 AND a.provider NOT LIKE 'PHIVOLCS' ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+38
View File
@@ -0,0 +1,38 @@
<?php
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$filename="seismic_free12.txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>3)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type as mt,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference,weather_code as wc,icon as ic,clouds as cl,wind_speed as ws,pressure as pr,humidity as hu,temperature as te,picture_count as pc FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+27
View File
@@ -0,0 +1,27 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$q=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_emsc union select * from automatic_usgs union select * from automatic_ingv union select * from automatic_ign union select * from automatic_csi) as a WHERE a.data > date_sub(NOW(), interval '".$_REQUEST['timeframe']."' minute) AND a.magnitude>='".$_REQUEST['magnitude']."' ORDER BY a.data DESC");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+27
View File
@@ -0,0 +1,27 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$q=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_emsc union select * from automatic_usgs union select * from automatic_ingv union select * from automatic_ign union select * from automatic_csi union select * from automatic_jma) as a WHERE a.data > date_sub(NOW(), interval '".$_REQUEST['timeframe']."' minute) AND a.magnitude>='".$_REQUEST['magnitude']."' ORDER BY a.data DESC");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$q=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_emsc union select * from automatic_usgs union select * from automatic_ingv union select * from automatic_ign union select * from automatic_csi union select * from automatic_jma union select * from automatic_ineter) as a WHERE a.data > date_sub(NOW(), interval '".$_REQUEST['timeframe']."' minute) AND a.magnitude>='".$_REQUEST['magnitude']."' ORDER BY a.data DESC");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$q=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_emsc union select * from automatic_usgs union select * from automatic_ingv union select * from automatic_ign union select * from automatic_csi union select * from automatic_jma union select * from automatic_ineter union select * from automatic_ssn) as a WHERE a.data > date_sub(NOW(), interval '".$_REQUEST['timeframe']."' minute) AND a.magnitude>='".$_REQUEST['magnitude']."' ORDER BY a.data DESC");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$q=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_emsc union select * from automatic_usgs union select * from automatic_ingv union select * from automatic_ign union select * from automatic_csi union select * from automatic_jma union select * from automatic_ineter union select * from automatic_ssn union select * from automatic_sgc union select * from automatic_rsn) as a WHERE a.data > date_sub(NOW(), interval '".$_REQUEST['timeframe']."' minute) AND a.magnitude>='".$_REQUEST['magnitude']."' ORDER BY a.data DESC");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$q=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_emsc union select * from automatic_usgs union select * from automatic_ingv union select * from automatic_ign union select * from automatic_csi union select * from automatic_jma union select * from automatic_ineter union select * from automatic_ssn union select * from automatic_sgc union select * from automatic_rsn union select * from automatic_guc) as a WHERE a.data > date_sub(NOW(), interval '".$_REQUEST['timeframe']."' minute) AND a.magnitude>='".$_REQUEST['magnitude']."' ORDER BY a.data DESC");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$q=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_emsc union select * from automatic_usgs union select * from automatic_ingv union select * from automatic_ign union select * from automatic_csi union select * from automatic_jma union select * from automatic_ineter union select * from automatic_ssn union select * from automatic_sgc union select * from automatic_rsn union select * from automatic_guc union select * from automatic_funvisis) as a WHERE a.data > date_sub(NOW(), interval '".$_REQUEST['timeframe']."' minute) AND a.magnitude>='".$_REQUEST['magnitude']."' ORDER BY a.data DESC");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+23
View File
@@ -0,0 +1,23 @@
<?phpND a.provider NOT LIKE 'INPRES'
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$q=mysql_query("SELECT latitude,longitude,depth,magnitude,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval '".$_REQUEST['timeframe']."' minute) AND a.magnitude>='".$_REQUEST['magnitude']."' AND a.provider NOT LIKE 'INPRES' ORDER BY a.data DESC");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+43
View File
@@ -0,0 +1,43 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$nick=$_REQUEST['nick'];
$password=$_REQUEST['password'];
$sql=mysql_query("select user_code from contest_nick where nick='$nick' and pwd='$password' limit 1");
if (mysql_num_rows($sql)){
$user_code=mysql_result($sql,0,"user_code");
$match=1;
}
else{
$match=0;
}
if ($match==1)
{
$q=mysql_query("SELECT nick_to,user_code_to FROM personal_ban where user_code_from=$user_code");
if (mysql_num_rows($q))
{
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
}
else{
print("no_banned");
}
}
mysql_close();
?>
+43
View File
@@ -0,0 +1,43 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$nick=$_REQUEST['nick'];
$uID=$_REQUEST['uID'];
$sql=mysql_query("select user_code from contest_nick where nick='$nick' and uID='$uID' limit 1");
if (mysql_num_rows($sql)){
$user_code=mysql_result($sql,0,"user_code");
$match=1;
}
else{
$match=0;
}
if ($match==1)
{
$q=mysql_query("SELECT nick_to,user_code_to FROM personal_ban where user_code_from=$user_code");
if (mysql_num_rows($q))
{
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
}
else{
print("no_banned");
}
}
mysql_close();
?>
+32
View File
@@ -0,0 +1,32 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$idmin=$_REQUEST['idmin'];
$q=mysql_query("SELECT ID,user_id,message,TIMESTAMPDIFF(MINUTE,date, NOW()) AS difference FROM chat_ita_gen where ID>$idmin and date > date_sub(NOW(), interval 1440 minute) order by ID asc");
if (mysql_num_rows($q))
{
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
}
else{
print("no_new");
}
mysql_close();
?>
+35
View File
@@ -0,0 +1,35 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$idmin=$_REQUEST['idmin'];
$postfix=$_REQUEST['postfix'];
$table="chat".$postfix;
$q=mysql_query("SELECT $table.ID,$table.user_code as user_id,nick,message,moderator,TIMESTAMPDIFF(MINUTE,date, NOW()) AS difference FROM $table left join contest_nick on $table.user_code=contest_nick.user_code where $table.ID>$idmin and $table.date > date_sub(NOW(), interval 1440 minute) order by $table.ID asc");
if (mysql_num_rows($q))
{
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
}
else{
print("no_new");
}
mysql_close();
?>
+35
View File
@@ -0,0 +1,35 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$idmin=$_REQUEST['idmin'];
$postfix=$_REQUEST['postfix'];
$table="chat".$postfix;
$q=mysql_query("SELECT * FROM (SELECT ID,user_code as user_id,nick,message,moderator,weather,day,TIMESTAMPDIFF(MINUTE,date, NOW()) AS difference FROM $table where ID>$idmin order by ID desc limit 200) AS dummy ORDER BY ID");
if (mysql_num_rows($q))
{
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
}
else{
print("no_new");
}
mysql_close();
?>
+62
View File
@@ -0,0 +1,62 @@
<?php
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$idmin=$_REQUEST['idmin'];
$postfix=$_REQUEST['postfix'];
$table="chat".$postfix;
$full=0;
if ($full==1){
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT * FROM (SELECT ID,user_code as user_id,nick,message,moderator,weather,day,TIMESTAMPDIFF(MINUTE,date, NOW()) AS difference FROM $table where ID>$idmin order by ID desc limit 200) AS dummy ORDER BY ID");
if (mysql_num_rows($sql))
{
while($e=mysql_fetch_assoc($sql))
$output[]=$e;
print(json_encode($output));
}
else{
print("no_new");
}
mysql_close();
}
else{
$filename="chat_table".$postfix.".txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>5)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT * FROM (SELECT ID,user_code as user_id,nick,message,moderator,weather,day,TIMESTAMPDIFF(MINUTE,date, NOW()) AS difference FROM $table order by ID desc limit 200) AS dummy ORDER BY ID");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
mysql_close();
}
$data = file_get_contents($filename);
print($data);
}
?>
+82
View File
@@ -0,0 +1,82 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
mysql_set_charset("utf8");
$idmin=$_REQUEST['idmin'];
$postfix=$_REQUEST['postfix'];
$nick=$_REQUEST['nick'];
$password=$_REQUEST['password'];
$table="chat".$postfix;
if (strcmp($postfix,'_ita_gen')==0){
$online_table='online_chat_ita';
}
if (strcmp($postfix,'_es_gen')==0){
$online_table='online_chat_es';
}
if (strcmp($postfix,'_eng_gen')==0){
$online_table='online_chat_eng';
}
if (strcmp($postfix,'_pt_gen')==0){
$online_table='online_chat_pt';
}
if (strcmp($postfix,'_jp_gen')==0){
$online_table='online_chat_jp';
}
if (strcmp($postfix,'_zh_gen')==0){
$online_table='online_chat_zh';
}
$sql=mysql_query("select user_code,moderator from contest_nick where nick='$nick' and pwd='$password' limit 1");
if (mysql_num_rows($sql)){
$match=1;
$user_code=mysql_result($sql,0,"user_code");
$moderator=mysql_result($sql,0,"moderator");
}
else{
$match=0;
}
if ($match==1){
$sql=mysql_query("replace into $online_table (user_code,nick,moderator,date) values ($user_code,'$nick',$moderator,NOW())");
$q=mysql_query("SELECT * FROM (SELECT ID,user_code as user_id,nick,message,moderator,weather,day,TIMESTAMPDIFF(MINUTE,date, NOW()) AS difference FROM $table where ID>$idmin order by ID desc limit 250) AS dummy ORDER BY ID");
if (mysql_num_rows($q))
{
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
}
else{
print("no_new");
}
}
mysql_close();
?>
+31
View File
@@ -0,0 +1,31 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$q=mysql_query("SELECT latitude,longitude,enabled,not_enabled,0 as state FROM network");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
$q=mysql_query("SELECT latitude,longitude,users,state,pro,code,TIMESTAMPDIFF(MINUTE,date,NOW()) AS difference FROM earthquakes where latitude<>0 AND longitude<>0 AND donotshow=0 AND ban<5");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+58
View File
@@ -0,0 +1,58 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("select avg(delay) as csi from delay_csi");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as emsc from delay_emsc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ign from delay_ign");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ineter from delay_ineter");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ingv from delay_ingv");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as jma from delay_jma");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as rsn from delay_rsn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as sgc from delay_sgc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ssn from delay_ssn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as usgs from delay_usgs");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+62
View File
@@ -0,0 +1,62 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("select avg(delay) as csi from delay_csi");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as csn from delay_guc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as emsc from delay_emsc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ign from delay_ign");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ineter from delay_ineter");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ingv from delay_ingv");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as jma from delay_jma");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as rsn from delay_rsn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as sgc from delay_sgc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ssn from delay_ssn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as usgs from delay_usgs");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+66
View File
@@ -0,0 +1,66 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("select avg(delay) as csi from delay_csi");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as csn from delay_guc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as emsc from delay_emsc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as funvisis from delay_funvisis");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ign from delay_ign");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ineter from delay_ineter");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ingv from delay_ingv");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as jma from delay_jma");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as rsn from delay_rsn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as sgc from delay_sgc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ssn from delay_ssn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as usgs from delay_usgs");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+70
View File
@@ -0,0 +1,70 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("select avg(delay) as csi from delay_csi");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as csn from delay_guc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as emsc from delay_emsc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as funvisis from delay_funvisis");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as geonet from delay_geonet");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ign from delay_ign");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ineter from delay_ineter");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ingv from delay_ingv");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as jma from delay_jma");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as rsn from delay_rsn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as sgc from delay_sgc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ssn from delay_ssn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as usgs from delay_usgs");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+74
View File
@@ -0,0 +1,74 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("select avg(delay) as csi from delay_csi");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as csn from delay_guc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as emsc from delay_emsc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as funvisis from delay_funvisis");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as geonet from delay_geonet");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ign from delay_ign");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ineter from delay_ineter");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ingv from delay_ingv");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as inpres from delay_inpres");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as jma from delay_jma");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as rsn from delay_rsn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as sgc from delay_sgc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ssn from delay_ssn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as usgs from delay_usgs");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+78
View File
@@ -0,0 +1,78 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("select avg(delay) as csi from delay_csi");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as csn from delay_guc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as emsc from delay_emsc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as funvisis from delay_funvisis");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as geonet from delay_geonet");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as igepn from delay_igepn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ign from delay_ign");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ineter from delay_ineter");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ingv from delay_ingv");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as inpres from delay_inpres");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as jma from delay_jma");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as rsn from delay_rsn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as sgc from delay_sgc");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as ssn from delay_ssn");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
$sql=mysql_query("select avg(delay) as usgs from delay_usgs");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+68
View File
@@ -0,0 +1,68 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$magnitude=$_REQUEST['magnitude'];
$latitude=$_REQUEST['latitude'];
$longitude=$_REQUEST['longitude'];
if ($magnitude>=5.5 and $magnitude<6.0)
{
$max_distance=40;
}
else{
if ($magnitude>=6.0 and $magnitude<6.5){
$max_distance=100;
}
else{
if ($magnitude>=6.5 and $magnitude<7.0){
$max_distance=200;
}
else{
if ($magnitude>=7.0 and $magnitude<7.5){
$max_distance=500;
}
else{
if ($magnitude>=7.5 and $magnitude<8.0){
$max_distance=800;
}
else{
if ($magnitude>=8.0 and $magnitude<8.5){
$max_distance=1000;
}
else{
if ($magnitude>=8.5 and $magnitude<9.0){
$max_distance=2000;
}
else{
if ($magnitude>=9.0){
$max_distance=3000;
}
}
}
}
}
}
}
}
$max_distance_deg=$max_distance/111;
$sql=mysql_query("SELECT ID,latitude,longitude,date FROM manual_picture where abs(latitude-$latitude)<$max_distance_deg and abs(longitude-$longitude)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,NOW()))<1440");
while($e=mysql_fetch_assoc($sql))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
@@ -0,0 +1,30 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$ID=$_REQUEST['ID'];
$sql=mysql_query("select picture from manual_picture where ID=$ID limit 1");
if (mysql_num_rows($sql))
{
while($e=mysql_fetch_assoc($sql))
$output[]=$e;
print(json_encode($output));
}
else{
print("no_pic");
}
mysql_close();
?>
+29
View File
@@ -0,0 +1,29 @@
<?php
$ini = parse_ini_file("conf.ini", true);
//mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
//mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
//$user_id=$_REQUEST['u_id'];
//$sql=mysql_query("SELECT iterator FROM (SELECT user_id,@i:=@i+1 AS iterator FROM gcm AS t,(SELECT @i:=0) as temp order by date) as temp2 where temp2.user_id=$user_id");
//if (mysql_num_rows($sql)){
// $iterator=mysql_result($sql,0,"iterator");
//}
//else{
// $iterator=-1;
//}
$iterator=632000;
print(strval($iterator));
//mysql_close();
?>
+38
View File
@@ -0,0 +1,38 @@
<?php
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$filename="italian_swarm.txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>60)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT mean_time as mt, mean_magnitude as mm, max_magnitude as mam,date from italian_swarm WHERE date > date_sub(NOW(), interval 7200 minute) order by date");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+30
View File
@@ -0,0 +1,30 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$uID=$_REQUEST['uID'];
$sql=mysql_query("select nick,user_code from contest_nick where uID='$uID' limit 1");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output[]=$e;
print(json_encode($output));
}
else
{
print("not_found");
}
mysql_close();
?>
+45
View File
@@ -0,0 +1,45 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$filename="manual_free.txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>3)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,magnitude,code,ban,msg,address,date,TIMESTAMPDIFF(MINUTE,date, NOW()) AS difference FROM manual WHERE date > date_sub(now(), interval 1440 minute) and donotshow=0 ORDER BY date DESC LIMIT 150");
if (mysql_num_rows($sql)>0){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
else{
//$fh = fopen($filename,'w');
//fclose($fh);
}
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+29
View File
@@ -0,0 +1,29 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$timeframe=1440;
$q=mysql_query("SELECT latitude,longitude,magnitude,code,ban,msg,address,TIMESTAMPDIFF(MINUTE,date, NOW()) AS difference FROM manual WHERE date > date_sub(now(), interval $timeframe minute) and donotshow=0 ORDER BY date DESC");
$output=array();
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+46
View File
@@ -0,0 +1,46 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$filename="manual_pro.txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>3)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude,magnitude,code,ban,msg,address,date,TIMESTAMPDIFF(MINUTE,date, NOW()) AS difference FROM manual WHERE date > date_sub(now(), interval 10080 minute) and donotshow=0 ORDER BY date DESC LIMIT 150");
if (mysql_num_rows($sql)>0){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
else{
//$fh = fopen($filename,'w');
//fclose($fh);
}
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+25
View File
@@ -0,0 +1,25 @@
<?php
$ini = parse_ini_file("conf.ini", true);
//mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
//mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
//$user_id=$_REQUEST['u_id'];
//$sql=mysql_query("SELECT iterator,monitoring_time as mon,total_mon,count FROM (SELECT user_id,monitoring_time,timestampdiff(minute,date,now()) as total_mon,@i:=@i+1 AS iterator,(SELECT COUNT(*) from monitoring) as count FROM monitoring AS t,(SELECT @i:=0) as temp order by monitoring_time desc) as temp2 where temp2.user_id=$user_id");
//if (mysql_num_rows($sql)){
// while($e=mysql_fetch_assoc($sql))
// $output[]=$e;
// print(json_encode($output));
//}
//mysql_close();
?>
+108
View File
@@ -0,0 +1,108 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$postfix=$_REQUEST['postfix'];
$nick=$_REQUEST['nick'];
$password=$_REQUEST['password'];
if (!empty($_REQUEST['u_code']))
{
$user_code=$_REQUEST['u_code'];
}
else
{
$user_code=0;
}
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI'].$nick."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
if (strcmp($postfix,'_ita_gen')==0){
$online_table='online_chat_ita';
}
if (strcmp($postfix,'_es_gen')==0){
$online_table='online_chat_es';
}
if (strcmp($postfix,'_eng_gen')==0){
$online_table='online_chat_eng';
}
if (strcmp($postfix,'_pt_gen')==0){
$online_table='online_chat_pt';
}
if (strcmp($postfix,'_jp_gen')==0){
$online_table='online_chat_jp';
}
if (strcmp($postfix,'_zh_gen')==0){
$online_table='online_chat_zh';
}
if (strcmp($postfix,'_tag_gen')==0){
$online_table='online_chat_tag';
}
$filename=$online_table.".txt";
if ($nick<>''){
if ($user_code!=0){
$sql=mysql_query("select user_code,last_known_user_id,canbemoderator from contest_nick where user_code=$user_code limit 1");
}
else{
$sql=mysql_query("select user_code,last_known_user_id,canbemoderator from contest_nick where nick='$nick' and pwd='$password' limit 1");
}
if (mysql_num_rows($sql)){
$user_code=mysql_result($sql,0,"user_code");
$canbemoderator=mysql_result($sql,0,"canbemoderator");
$user_id=mysql_result($sql,0,"last_known_user_id");
if ($canbemoderator==1){
$sql=mysql_query("select count(*) as c from $online_table where moderator=1 and status=0");
$c=mysql_result($sql,0,"c");
if ($c<=3){
$moderator=1;
}
else{
$moderator=0;
}
$sql=mysql_query("update contest_nick set moderator=$moderator where user_code=$user_code limit 1");
}
else{
$moderator=0;
}
$sql=mysql_query("replace into $online_table (user_code,user_id,nick,moderator,date) values ($user_code,$user_id,'$nick',$moderator,NOW())");
}
}
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>3)
{
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("select user_code,nick,moderator,status,TIMESTAMPDIFF(MINUTE,date,NOW()) AS difference from $online_table where nick<>'' order by status,nick");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
else{
$fh = fopen($filename,'w');
fclose($fh);
}
}
$data = file_get_contents($filename);
print($data);
mysql_close();
?>
+36
View File
@@ -0,0 +1,36 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$code=$_REQUEST['code'];
$filename="quakedetail_".$code.".txt";
if(!file_exists($filename))
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT latitude,longitude FROM earthquake_details where code=$code limit 200");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+40
View File
@@ -0,0 +1,40 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$filename="past_quakes.txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>30)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT format(latitude,3) as latitude,format(longitude,3) as longitude,signals as users,state,code,date,TIMESTAMPDIFF(MINUTE,date,NOW()) AS difference,intensity FROM earthquakes where latitude<>0 AND longitude<>0 AND TIMESTAMPDIFF(MINUTE,date,NOW())<525600 AND falsealarm=0");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+25
View File
@@ -0,0 +1,25 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$q=mysql_query("SELECT format(latitude,3) as latitude,format(longitude,3) as longitude,signals as users,date FROM earthquakes where latitude<>0 AND longitude<>0 AND ban<5 AND falsealarm=0");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+22
View File
@@ -0,0 +1,22 @@
<?php
// Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$sql=mysql_query("select * from pressure order by ID DESC LIMIT 0, 1");
$e=mysql_fetch_assoc($sql);
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+24
View File
@@ -0,0 +1,24 @@
<?php
//Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$q=mysql_query("SELECT geo_index as geo,pop_index as pop,DATE_FORMAT(date,'%e-%b') as dat FROM pressure where ID mod 3 = 0 order by date DESC limit 240");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
+32
View File
@@ -0,0 +1,32 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$nick=$_REQUEST['nick'];
$password=$_REQUEST['password'];
$user_code=$_REQUEST['user_code'];
$sql=mysql_query("select picture from user_picture where user_code=$user_code limit 1");
if (mysql_num_rows($sql))
{
while($e=mysql_fetch_assoc($sql))
$output[]=$e;
print(json_encode($output));
}
else{
print("no_pic");
}
mysql_close();
?>
+33
View File
@@ -0,0 +1,33 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$nick=$_REQUEST['nick'];
$password=$_REQUEST['password'];
$sql=mysql_query("select user_code from contest_nick where nick='$nick' and pwd='$password' limit 1");
if (mysql_num_rows($sql))
{
$user_code=mysql_result($sql,0,"user_code");
}
else
{
$user_code=0;
}
print($user_code);
mysql_close();
?>
+33
View File
@@ -0,0 +1,33 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$nick=$_REQUEST['nick'];
$uID=$_REQUEST['uID'];
$sql=mysql_query("select user_code from contest_nick where nick='$nick' and uID='$uID' limit 1");
if (mysql_num_rows($sql))
{
$user_code=mysql_result($sql,0,"user_code");
}
else
{
$user_code=0;
}
print($user_code);
mysql_close();
?>
+30
View File
@@ -0,0 +1,30 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$uID=$_REQUEST['uID'];
$sql=mysql_query("select nick,country,town,sex,birth from contest_nick where uID='$uID' limit 1");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output[]=$e;
print(json_encode($output));
}
else
{
print("wrog_user");
}
mysql_close();
?>
+38
View File
@@ -0,0 +1,38 @@
<?php
$ini = parse_ini_file("conf.ini", true);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$filename="users_graph.txt";
if (file_exists($filename)){
$delta_time=time()-filemtime($filename);
}
else{
$delta_time=1000;
}
if ($delta_time>120)
{
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query('SET CHARACTER SET utf8');
$sql=mysql_query("SELECT enabled as en,geolocated as geo,total as tot,DATE_FORMAT(date,'%e-%b') as dat FROM status order by date DESC limit 240");
if (mysql_num_rows($sql)){
while($e=mysql_fetch_assoc($sql))
$output_file[]=$e;
$json_file = json_encode($output_file);
file_put_contents($filename,$json_file);
}
mysql_close();
}
$data = file_get_contents($filename);
print($data);
?>
+29
View File
@@ -0,0 +1,29 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$fault_code=$_REQUEST['fault_code'];
$q=mysql_query("SELECT AsText(line) from usgs_fault_lines where fault_code=$fault_code");
if (mysql_num_rows($q))
{
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
}
else{
print("ko");
}
mysql_close();
?>
+32
View File
@@ -0,0 +1,32 @@
<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
$lat_min=$_REQUEST['lat_min'];
$lat_max=$_REQUEST['lat_max'];
$lon_min=$_REQUEST['lon_min'];
$lon_max=$_REQUEST['lon_max'];
$q=mysql_query("SELECT code,name,age,Y(location) as latitude,X(location) as longitude from usgs_faults where X(location)>=$lon_min and X(location)<=$lon_max and Y(location)>=$lat_min and Y(location)<=$lat_max");
if (mysql_num_rows($q))
{
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
}
else{
print("nothing");
}
mysql_close();
?>
+5
View File
@@ -0,0 +1,5 @@
<?php
$url="http://www.earthquakenetwork.it/fault.kml";
$xml = simplexml_load_file($url);
var_dump($xml);
?>
+27
View File
@@ -0,0 +1,27 @@
<?php
$filename_data=$argv[1];
$filename=$argv[2];
$dataArray = json_decode(file_get_contents($filename_data), true);
$regidArrayGCM = json_decode(file_get_contents($filename), true);
$headers = array(
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
'Content-Type: application/json');
$fields = array(
'registration_ids' => $regidArrayGCM,
'time_to_live' => 240,
'priority' => 'high',
'data' => $dataArray);
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => $headers,
'content' => json_encode($fields))));
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context);
$filename_rnd = uniqid();
file_put_contents('/home/francesco/temp/'.$filename_rnd,json_encode($response));
?>
+27
View File
@@ -0,0 +1,27 @@
<?php
$filename_data=$argv[1];
$filename=$argv[2];
$dataArray = json_decode(file_get_contents($filename_data), true);
$regidArrayGCM = json_decode(file_get_contents($filename), true);
$headers = array(
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
'Content-Type: application/json');
$fields = array(
'registration_ids' => $regidArrayGCM,
'time_to_live' => 36000,
'data' => $dataArray);
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => $headers,
'content' => json_encode($fields))));
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context);
?>
+29
View File
@@ -0,0 +1,29 @@
<?php
$filename_data=$argv[1];
$filename=$argv[2];
$dataArray = json_decode(file_get_contents($filename_data), true);
$regidArrayGCM = json_decode(file_get_contents($filename), true);
$headers = array(
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
'Content-Type: application/json');
$fields = array('registration_ids' => $regidArrayGCM,
'time_to_live' => 36000,
'priority' => 'high',
'data' => $dataArray);
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => $headers,
'content' => json_encode($fields))));
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context);
?>
+48
View File
@@ -0,0 +1,48 @@
<?php
//Parse with sections
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
$sql=mysql_query("select user_code from contest_nick where nick='".$_REQUEST['nick']."' and pwd='".$_REQUEST['password']."'");
if (mysql_num_rows($sql))
{
$user_code=mysql_result($sql,0,"user_code");
$match=1;
}
else
{
$match=0;
}
if ($match==1)
{
$sql2=mysql_query("SELECT score FROM contest_rank WHERE user_code=$user_code");
if (mysql_num_rows($sql2))
{
$my_score=mysql_result($sql2,0,"score");
$sql3=mysql_query("select score,number_contests,(select count(*) from contest_rank where score > $my_score)+1 AS rank from contest_rank where user_code=$user_code");
$e=mysql_fetch_assoc($sql3);
$output[]=$e;
}
$sql4=mysql_query("SELECT count(*) as total FROM contest_rank");
$e=mysql_fetch_assoc($sql4);
$output[]=$e;
$sql5=mysql_query("SELECT current_contest_number FROM contest_state");
$e=mysql_fetch_assoc($sql5);
$output[]=$e;
$ccn=mysql_result($sql5,0,"current_contest_number");
$sql6=mysql_query("SELECT count(*) as players FROM (SELECT user_code,MAX(date) AS maxdate FROM contest_users WHERE contest_number=$ccn GROUP BY user_code) AS a INNER JOIN contest_users AS b ON a.user_code=b.user_code AND a.maxdate=b.date AND b.contest_number=$ccn");
$e=mysql_fetch_assoc($sql6);
$output[]=$e;
}
else
{
$output[]="ko";
}
$out=json_encode($output);
print($out);
mysql_close();
?>

Some files were not shown because too many files have changed in this diff Show More