/
index.php
2626 lines (2384 loc) · 83.8 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
////////////////////////////////////////////////////////////////////////
//PREAMBLE
////////////////////////////////////////////////////////////////////////
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//UTILITIES
require_once("site/util.php");
header("Content-Type: text/html;charset=UTF-8");
//CONTENT
$CONTENT="";
$SUBMENU="";
//VARIABLES
if(!isset($action)){$action="";}
if(!isset($if)){$if="";}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
////////////////////////////////////////////////////////////////////////
//ACTIONS
////////////////////////////////////////////////////////////////////////
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(!isBlank($action)){
if(0){}
////////////////////////////////////////////////////////////////////////
//UPLOAD EARTHQUAKES FILE
////////////////////////////////////////////////////////////////////////
else if($action=="Upload"){
$file=$_FILES["file_insert"];
$name=$file["name"];
$target=preg_replace("/\.[^\.]+$/","",$name);
$tmp=$file["tmp_name"];
shell_exec("cp $tmp $USERDIR/$name");
statusMsg("Convirtiendo archivo $name ($tmp) a $target...");
$insert_msg_insert=<<<I
<p id="insert_loader_insert" style="background:white;padding:10px">
Loading data into database <img src="img/loader.gif">
</p>
<script>
$(document).ready(function(){
ajaxDo("insertquakes","input=$USERDIR/$name;output=$USERDIR/$target;label=$label",
function(e){
alert(e);
$("#insert_loader_insert").hide();
$("#insert_error").show();
});
});
</script>
I;
}
////////////////////////////////////////////////////////////////////////
//TCFS
////////////////////////////////////////////////////////////////////////
else if($action=="TCFS"){
statusMsg("$action earthquakes...");
$insert_msg_tcfs=<<<I
<p id="insert_loader_tcfs" style="background:white;padding:10px">
Computing the TCFS of the earthquakes. It may take a while. Take a cup of coffee <img src="img/loader.gif">
</p>
<script>
$(document).ready(function(){
ajaxDo("tcfs","",
function(e){
alert(e);
$("#insert_loader_tcfs").hide();
},
function(e){
alert(e);
$("#insert_loader_tcfs").hide();
}
);
});
</script>
I;
}
////////////////////////////////////////////////////////////////////////
//DECLUSTER
////////////////////////////////////////////////////////////////////////
else if($action=="Decluster Tectonic" or $action=="Decluster Volcanotectonic"){
statusMsg("$action earthquakes...");
if($action=="Decluster Tectonic"){$opt="tectonic";}
if($action=="Decluster Volcanotectonic"){$opt="volcanotectonic";}
$insert_msg_decluster=<<<I
<p id="insert_loader_decluster" style="background:white;padding:10px">
Declustering. It may take a while (15-30 min). Take a cup of coffee <img src="img/loader.gif">
</p>
<script>
$(document).ready(function(){
ajaxDo("decluster","opt=$opt",
function(e){
alert(e);
$("#insert_loader_decluster").hide();
});
});
</script>
I;
}
////////////////////////////////////////////////////////////////////////
//REMOVE STATION
////////////////////////////////////////////////////////////////////////
else if($action=="remove"){
if(is_dir("stations/$station_id")){
// REMOVE FROM DATABASE
$sql="delete from Stations where station_id='$station_id';";
mysqlCmd($sql);
// REMOVE STATION INFORMATION
shell_exec("mv stations/$station_id stations/.trash");
statusMsg("Station $station_id removed.");
}
$if="activity";
}
////////////////////////////////////////////////////////////////////////
//REGISTER STATION
////////////////////////////////////////////////////////////////////////
else if($action=="register"){
//CHECK IF MACHINE IS REGISTERED OR PREREGISTERED
$station_dir="stations/$station_id";
$station_predir="stations/.preregister/$station_id";
if(is_dir($station_dir)){
$status="Station $station_id already registered. Updating.";
}else if(is_dir($station_predir)){
$status="Station $station_id registered.";
shell_exec("mv $station_predir $station_dir");
}else{
$ERROR="Station not installed (preregistered) yet.";
}
//CREATING PUBLIC KEY
if(!preg_match("/no-port-forwarding/",$station_key)){
echo "Saving $station_key...";
$fl=fopen("$station_dir/key.pub","w");
fwrite($fl,"no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command=\"scp -r -d -t ~/tQuakes/\" $station_key");
fclose($fl);
}
//SEND A MESSAGE TO ADMINISTRATOR
if(!mysqlCmd("select * from Stations where station_id='$station_id'")){
$urlstring="station_id=$station_id&station_name=$station_name&station_email=$station_email";
$message=<<<M
<p>
Dear administrator,
</p>
<p>
A user has registered a new calculation station in this $tQuakes
server. The station is not yet activated. Please use the link
below to activate the station and start sending data to that
station.
</p>
<p>
<a href="$WEBSERVER/index.php?if=register&$urlstring">Click to activate station</a>
</p>
<p>
Please remember that you have to be logged in as the administrator
in order to activate the station.
</p>
<p>Best wishes,</p>
<p>
<b>$tQuakes Administrator</b>
</p>
M;
$subject="[tQuakes] New tQuakes computing station";
sendMail($EMAIL_USERNAME,$subject,$message,$EHEADERS);
}
//UPDATING STATION IN DATABASE
if(isBlank($station_receiving)){$station_receiving=0;}
$conf=parse_ini_file("$station_dir/${station_id}rc");
foreach(array_keys($conf) as $key){
$GLOBALS["$key"]=$conf["$key"];
}
$sql="insert into Stations (station_id,station_name,station_email,station_arch,station_nproc,station_mem,station_mac,station_receiving) values ('$station_id','$station_name','$station_email','$station_arch','$station_nproc','$station_mem','$station_mac','$station_receiving') on duplicate key update station_name=VALUES(station_name),station_email=VALUES(station_email),station_arch=VALUES(station_arch),station_nproc=VALUES(station_nproc),station_mem=VALUES(station_mem),station_mac=VALUES(station_mac),station_receiving=VALUES(station_receiving);";
mysqlCmd($sql);
header("Refresh:0;url=$WEBSERVER/?status=$status");
}
////////////////////////////////////////////////////////////////////////
//NEW USER
////////////////////////////////////////////////////////////////////////
else if($action=="Create"){
$if="newuser";
//TEST FORM
if(isBlank($email) or
!preg_match("/@/",$email)){
errorMsg("You should provide a valid e-mail");
goto endaction;
}
if(mysqlCmd("select * from Users where email='$email'")){
errorMsg("A user with this e-mail already exists");
goto endaction;
}
if(isBlank($password)){
errorMsg("Password invalid");
goto endaction;
}
if($password!=$cpassword){
errorMsg("Paswords does not match");
goto endaction;
}
if(isBlank($uname)){
errorMsg("Invalid name");
goto endaction;
}
if(strlen($ERRORS)==0){
//DATABASE ENTRY
$password=md5($password);
$ulevel="1";
insertSql("Users",array("uname"=>"",
"email"=>"",
"password"=>"",
"ulevel"=>"")
);
//MESSAGES
statusMsg("User has been registered. Please check your e-mail to activate the
account.");
$message=<<<M
<p>
Dear $name,
</p>
<p>
We have received your request to open an account in $tQuakes
website. In order to use your account you need to activate it using
the link below:
</p>
<p>
<a href="$WEBSERVER/index.php?action=activate&email=$email">Click to activate your account</a>
</p>
<p>Best wishes,</p>
<p>
<b>$tQuakes Administrator</b>
</p>
M;
$subject="[tQuakes] Account activation";
sendMail($email,$subject,$message,$EHEADERS);
}
if(isset($if)){unset($if);}
}
////////////////////////////////////////////////////////////////////////
//ACTIVATE
////////////////////////////////////////////////////////////////////////
else if($action=="activate"){
if($result=mysqlCmd("select * from Users where email='$email'")){
mysqlCmd("update Users set activate='1' where email='$email'");
header("Refresh:0;url=$WEBSERVER/?if=user&status=Your account has been activated");
}else{
errorMsg("La cuenta de $email no existe.");
}
}
////////////////////////////////////////////////////////////////////////
//RECOVER
////////////////////////////////////////////////////////////////////////
else if($action=="Change"){
//TEST FORM
if(isBlank($pass1) or
isBlank($pass2)){
errorMsg("No password provided");
goto endaction;
}
if($pass1!=$pass2){
errorMsg("Password does not match");
goto endaction;
}
$results=mysqlCmd("select * from Users where email='$email'");
$spass=$results["password"];
if($pass!=$spass){
errorMsg("Authentication failed.");
goto endaction;
}
if(strlen($ERRORS)==0){
$password=md5($pass1);
mysqlCmd("update Users set password='$password' where email='$email'");
header("Refresh:0;url=$WEBSERVER/?if=user&status=Password modified");
}
}
////////////////////////////////////////////////////////////////////////
//RECOVER
////////////////////////////////////////////////////////////////////////
else if($action=="Recover"){
if($results=mysqlCmd("select * from Users where email='$email'")){
$pass=$results["password"];
$uname=$results["uname"];
$message=<<<M
<p>
Dear $uname,
</p>
<p>
We have received a request to recover your password in $tQuakes. In
order to proceed please use the link below:
</p>
<p>
<a href="$WEBSERVER/index.php?if=setpassword&email=$email&pid=$pass">Click
to change your password</a>
</p>
<p>Best wishes,</p>
<p>
<b>$tQuakes Administrator</b>
</p>
M;
$subject="[tQuakes] Password reset";
sendMail($email,$subject,$message,$EHEADERS);
statusMsg("We have sent a recovery message to your e-mail");
}else{
errorMsg("E-mail not recognized.");
goto endaction;
}
}
////////////////////////////////////////////////////////////////////////
//CLEAN STATS
////////////////////////////////////////////////////////////////////////
else if($action=="cleanstats"){
shell_exec("cd $STATSDIR;make cleandeep");
statusMsg("Cleaned...");
}
////////////////////////////////////////////////////////////////////////
//REPLOT STATS
////////////////////////////////////////////////////////////////////////
else if($action=="restats"){
shell_exec("cd $STATSDIR;make plotall");
header("Refresh:0;url=?if=data&status=Replot");
}
////////////////////////////////////////////////////////////////////////
//LOGOUT
////////////////////////////////////////////////////////////////////////
else if($action=="logout"){
session_unset();
$urlref="?";
statusMsg("Logout succesful");
header("Refresh:0;url=$urlref");
}
////////////////////////////////////////////////////////////////////////
//LOGIN
////////////////////////////////////////////////////////////////////////
else if($action=="Login"){
//TEST FORM
if(isBlank($email) or
!preg_match("/@/",$email)){
errorMsg("Invalid e-mail");
goto endaction;
}
if(isBlank($password)){
errorMsg("Password no provisto");
goto endaction;
}
if(!mysqlCmd("select * from Users where email='$email'")){
errorMsg("No user with that e-mail");
goto endaction;
}
if(!mysqlCmd("select * from Users where email='$email' and activate='1'")){
errorMsg("Your account is not active yet.");
goto endaction;
}
if(strlen($ERRORS)==0){
//CHECK IF USER EXISTS
if($results=mysqlCmd("select * from Users where email='$email'")){
$subpass=md5($password);
if($subpass==$results["password"]){
session_start();
foreach(array_keys($results) as $key){
if(preg_match("/^\d$/",$key)){continue;}
$_SESSION["$key"]=$results[$key];
}
if(preg_match("/user/",$urlref)){$urlref="index.php";}
statusMsg("Login succesful");
header("Refresh:0;url=$urlref");
}else{
errorMsg("Invalid password");
}
}else{
errorMsg("User not recognized");
}
}
}
////////////////////////////////////////////////////////////////////////
//CLEAN
////////////////////////////////////////////////////////////////////////
else if($action=="cleansynthetic"){
statusMsg("Cleaning synthetic earthquakes");
$results=mysqlCmd("select quakeid from Quakes where extra3='MOCK'",1);
$dirquakes="$HOMEDIR/$TQUSER/tQuakes/";
foreach($results as $quakes){
$quakeid=$quakes["quakeid"];
$quakerm="$dirquakes/$quakeid";
if(file_exists("$quakerm.conf")){
$cmd="echo 'rm -f $quakerm*.*' >> tmp/clean-synthetic.sh";
statusMsg("Programming removal of $quakeid");
shell_exec($cmd);
}
}
mysqlCmd("delete from Quakes where extra3='MOCK'");
}
else if($action=="cleanhistory"){
statusMsg("Cleaning history");
shell_exec("rm -r $SCRATCHDIR/history.log");
}
////////////////////////////////////////////////////////////////////////
//CALCULATE
////////////////////////////////////////////////////////////////////////
else if($action=="calculate" or $action=="plot"){
//========================================
//CHECK INPUT FORM
//========================================
if(isBlank($qlat)){
errorMsg("You must provide a latitude");
goto endaction;
}
if(isBlank($qlon)){
errorMsg("You must provide a longitude");
goto endaction;
}
if(isBlank($qdepth)){
errorMsg("You must provide a depth");
goto endaction;
}
if(isBlank($qdatetime)){
errorMsg("You must provide a date");
goto endaction;
}
$qjd=rtrim(shell_exec("PYTHONPATH=. python util/date2jd.py '$qdatetime'"));
if(isBlank($qjd)){
errorMsg("Bad date");
goto endaction;
}
statusMsg("All fields checked...");
//BY DEFAULT THE EVENT IS NOT IN DATABASE NOR DONE
$qdb=0;
$qdone=0;
$parts=preg_split("/\s+/",$qdatetime);
$qdate=$parts[0];
$qtime=$parts[1];
if(!$qlegacy and $action!="plot"){
statusMsg("Signature of event: $md5str");
//EVENT STRING AND ID ACCORDING TO PROVIDED DATA
$md5str=md5("$qdate$qtime$qdatetime$qjd$hsun$hmoon$qlat$qlon$qdepth$Ml$qstrikemain$qdipmain$qrakemain");
$quakeid=strtoupper(substr($md5str,0,7));
$quakestr=sprintf("QUAKE-lat_%+08.4f-lon_%+09.4f-dep_%+010.4f-JD_%.6f",$qlat,$qlon,$qdepth,$qjd);
statusMsg("Signature of form data: $md5str");
statusMsg("Corresponding id $quakeid");
//CHECK IF THIS EVENT EXIST
$cmd="CONCAT(qdate,qtime,qdatetime,qjd,hsun,hmoon,qlat,qlon,qdepth,Ml,qstrikemain,qdipmain,qrakemain)";
$quakeindb=mysqlCmd("select $cmd as qstr from $QUAKES where quakeid='$quakeid'");
if($quakeindb){
$qstr=$quakeindb["qstr"];
$md5qstr=md5($qstr);
statusMsg("Signature of database event: $md5qstr");
if($md5str==$md5qstr){
$qdb=1;
}
}else{
statusMsg("Event with quakeid $dquakeid not in database");
$qlegacy=0;
}
//CHECK IF IT IS DONE
$qdone=0;
}else{
$calcbut="display:none";
$qdb=1;
}
//CHECK IF DONE
if($qdb){
if(mysqlCmd("select * from $QUAKES where quakeid='$quakeid' and astatus+0=4")){
statusMsg("Quake done");
$qdone=1;
$sql="select NOW()";
}else{
statusMsg("Quake in db but not done. ");
$sql="update Quakes set extra5='TIMELY' where quakeid='$quakeid'";
}
}
else{
statusMsg("Quake not in db");
//SPLIT DATE
//CREATE MOCK QUAKE
$sql="insert into Quakes (quakeid,quakestr,qdate,qtime,qdatetime,qjd,hsun,hmoon,qlat,qlon,qdepth,Ml,qstrikemain,qdipmain,qrakemain,qstrikeaux,qdipaux,qrakeaux,astatus,extra3) values ('$quakeid','$quakestr','$qdate','$qtime','$qdatetime','$qjd','$hsun','$hmoon','$qlat','$qlon','$qdepth','$Ml','$qstrikemain','$qdipmain','$qrakemain','$qstrikemain','$qdipmain','$qrakemain',0,'MOCK')";
}
//========================================
//CHECKTYPE
//========================================
/*
There are the following types of earthquakes:
1) Earthquake in database (qdb=1):
1.0) Earthquake is not calculated (qdone=0)
1.1) Earthquake is already calculated (qdone=1)
0) Earthquake not in database (qdb=0):
0.0) Earthquake is in queue (qdone=0)
0.1) Earthquake is already calculated (qdone=1)
*/
statusMsg("Quake type: qdb=$qdb, qdone=$qdone...");
statusMsg("SQL: $sql...");
//========================================
//IF QUAKE HAS NOT BEEN CALCULATED
//========================================
//$qdone=0;//REMOVE AFTER DEBUGGING
if(!$qdone){
//RESULTS DIRECTORY
if(!$qlegacy and $action=="calculate"){
$quakeindb=mysqlCmd($sql);
}
statusMsg("Quake database command for $quakeid fetchedin db...");
goto endcalculate;
}
//========================================
//IF QUAKE HAS BEEN ALREADY CALCULATED
//========================================
else{
$dirquakes="$HOMEDIR/$TQUSER/tQuakes/";
$quakedir="$SCRATCHDIR/$quakeid";
if(!is_dir($quakedir)){
shell_exec("mkdir -p $quakedir");
statusMsg("Scratch directory created...");
}else{
statusMsg("Scratch directory $quakedir exist...");
}
//========================================
// RECOVER QUAKE INFO
//========================================
$filequake="$dirquakes/$quakeid.tar.gz";
statusMsg("Recovering information from $filequake...");
//CHECK IF PRECALCULATED FILES ALREADY EXISTS
if(file_exists($filequake)){
statusMsg("Results for $quakeid found...");
//CHECK IF THEY HAVE BEEN UNZIPED
if(!file_exists("$quakedir/$quakeid-eterna.tar")){
statusMsg("Unzipping files...");
shell_exec("cp -rf $filequake $quakedir/");
shell_exec("cp -rf $dirquakes/$quakeid.conf $quakedir/");
shell_exec("cd $quakedir;tar zxf $quakeid.tar.gz");
//COPY SUPPORTING PYTHON FILES
shell_exec("cd $quakedir;ln -s ../../../tquakes.py");
shell_exec("cd $quakedir;ln -s ../../../util");
shell_exec("cd $quakedir;ln -s ../../../configuration");
shell_exec("cd $quakedir;ln -s ../../../plots/analysis/makefile");
//COPY PLOTTING SCRIPTS
$cmd="cd $quakedir;ln -s ../../../plots/analysis/astronomy-extremes-1970_2030.data";
shell_exec($cmd);
foreach($PHASE_COMPONENTS as $component){
$compname=$component[0];
$comp=preg_replace("/=/","_",$compname);
$comp=preg_replace("/\./","-",$comp);
if(preg_match("/_S-/",$comp)){continue;}
foreach($QUAKE_PLOTS as $plot){
$ext="py";
$cmd="cd $quakedir;cp -f ../../../plots/analysis/quake-$plot.$ext quake-$plot-$comp.$ext";
shell_exec($cmd);
foreach(array("conf","html","history") as $ext){
$cmd="cp -r plots/analysis/quake-$plot.$ext $quakedir/quake-$plot-$comp.$ext";
shell_exec($cmd);
}
shell_exec("echo >> $quakedir/quake-$plot-$comp.conf");
shell_exec("echo 'component=\"$compname\"' >> $quakedir/quake-$plot-$comp.conf");
shell_exec("echo 'description=\"Plot $plot for component $comp\"' >> $quakedir/quake-$plot-$comp.conf");
}
}
}
}
}
//========================================
//GENERATE REPORT
//========================================
$tideresults="<h2><a name=results>Results</a></h2>";
$SUBMENU.="<a href='#results'>Results</a> : ";
//FILES
$size_all=round(filesize("$quakedir/$quakeid.tar.gz")/1024.0,0);
$size_data=round(filesize("$quakedir/$quakeid.data")/1024.0,0);
//QUAKE PROPERTIES
$quakeconf="$quakedir/$quakeid.conf";
$quake=parse_ini_file($quakeconf);
//COMPONENT SIGNAL
$signaltxt.="<h3><a nmae=signal>Component signal</a></h3><ul>";
$SUBMENU.="<a href='#signal'>Signal</a> | ";
$signals=preg_split("/;/",$quake["qsignal"]);
if(isBlank($signals[0])){
$signaltxt.="<p><i style='color:red'>Execution failed</i></p>";
$signaltxt.="</ul>";
$tideresults.=$signaltxt;
goto download;
}
$i=0;
foreach($signals as $signal){
$component=$PHASE_COMPONENTS[$i];
$namecomponent=$component[0];
$units=$component[1];
if(isBlank($signal)){continue;}
$signaltxt.="<li><b>$namecomponent</b>:$signal $units</li>";
$i++;
}
$signaltxt.="</ul>";
$tideresults.=$signaltxt;
//COMPONENT PHASES
$SUBMENU.="<a href='#phases'>Tidal Phases</a> | ";
$phases=preg_split("/;/",$quake["qphases"]);
$phasetxt=<<<P
<h3><a name=phases>Component phases</a></h3>
<table border=1px cellspacing=0px>
<tr>
<td>Component</td>
<td>Semi diurnal</td>
<td>Diurnal</td>
<td>Fornightly</td>
<td>Monthly</td>
</tr>
P;
$i=0;
foreach($PHASE_COMPONENTS as $phase){
$component=$phase[0];
$phasetxt.="<tr><td>$component</td>";
for($j=0;$j<4;$j++){
$parts=preg_split("/:/",$phases[$i]);
$time=$parts[0];
$phase=$parts[1];
$phasetxt.="<td>$phase</td>";
$i++;
}
$phasetxt.="</tr>";
}
$phasetxt.="</table>";
$tideresults.=$phasetxt;
//////////////////////////////////////////////////////////////
//ASTRONOMY PHASES
//////////////////////////////////////////////////////////////
$SUBMENU.="<a href='#download'>Astronomy Phases</a> | ";
$aphases=$quake["aphases"];
$phases=preg_split("/;/",$aphases);
$tideresults.=<<<A
<h3><a name=download>Astronomy Phases</a></h3>
<table border=1px cellspacing=0px>
<tr>
<td>Component</td>
<td>Time (days)</td>
<td>Period (days)</td>
<td>Phase</td>
</tr>
A;
$table="";
$components=array("Perigea","Closest Perigea","Perihelia");
for($i=0;$i<3;$i++){
$parts=preg_split("/:/",$phases[$i]);
$table.="<tr><td>$components[$i]</td><td>$parts[0]</td><td>$parts[1]</td><td>$parts[2]</td></tr>";
}
$table.="</table>";
$tideresults.=$table;
//////////////////////////////////////////////////////////////
//TCFS
//////////////////////////////////////////////////////////////
$SUBMENU.="<a href='#TCFS'>TCFS</a> | ";
$tideresults.="<h3><a name=TCFS>Tidal stresses</a></h3>";
if(preg_match("/\d+/",$qstrikemain)){
$sql="select sigmas,sigman from Quakes where quakeid='$quakeid'";
$result=mysqlCmd($sql);
//IF NOT CALCULATED CALCULATE TCFS COMPONENTS
if(isBlank($result["sigmas"])){
$cmd="cd plots/processing;PYTHONPATH=. python tquakes-tcfs.py \"quakeid='$quakeid'\" 2>&1 |tee tmp/tcfs";
shell_exec($cmd);
}
$vsigmas=preg_split("/;/",$result["sigmas"]);
$vsigman=preg_split("/;/",$result["sigman"]);
$sigmas_main_quake=$vsigmas[0];
$sigmas_main_max=$vsigmas[2];
$sigmas_aux_quake=$vsigmas[4];
$sigmas_aux_max=$vsigmas[6];
$sigman_main_quake=$vsigman[0];
$sigman_main_max=$vsigman[2];
$sigman_aux_quake=$vsigman[4];
$sigman_aux_max=$vsigman[6];
$tcfs_main_quake=$sigmas_main_quake+0.4*$sigman_main_quake;
$tcfs_main_max=$sigmas_main_max+0.4*$sigman_main_max;
$tcfs_aux_quake=$sigmas_aux_quake+0.4*$sigman_aux_quake;
$tcfs_aux_max=$sigmas_aux_max+0.4*$sigman_aux_max;
$tideresults.=<<<A
<ul>
<li><b>Main plane:</b>
<ul>
<li><b>Sigma-s</b>: quake = $sigmas_main_quake, max = $sigmas_main_max</li>
<li><b>Sigma-n</b>: quake = $sigman_main_quake, max = $sigman_main_max </li>
<li><b>TCFS</b>: quake = $tcfs_main_quake, max = $tcfs_main_max</li>
</ul>
<li><b>Aux plane:</b>
<ul>
<li><b>Sigma-s</b>: quake = $sigmas_aux_quake, max = $sigmas_aux_max</li>
<li><b>Sigma-n</b>: quake = $sigman_aux_quake, max = $sigman_aux_max </li>
<li><b>TCFS</b>: quake = $tcfs_aux_quake, max = $tcfs_aux_max</li>
</ul>
</ul>
A;
}else{
$tideresults.="<i>No focal mechanism available</i>";
}
//////////////////////////////////////////////////////////////
//DOWNLOAD
//////////////////////////////////////////////////////////////
download:
$SUBMENU.="<a href='#download'>Download</a> | ";
$SUBMENU.="<a href='#plots'>Plots</a> | ";
$tideresults.=<<<T
<h3><a name=download>Downloads</a></h3>
<ul>
<li><a href=$quakeconf target=_blank>Summary file</a></li>
<li><a href=$quakedir/$quakeid.tar.gz target=_blank>All results</a> ($size_all kB)</li>
<li><a href=$quakedir/$quakeid.data target=_blank>Data values</a> ($size_data kB)</li>
</ul>
<h3><a name=plots>Plots</a></h3>
<input type="submit" name="action" value="plot">
T;
//SHOW PLOTS
if($action=="plot"){
//========================================
//PLOT
//========================================
$plots="";
$plotmd5s=array();
foreach($PHASE_COMPONENTS as $component){
$compname=$component[0];
$comp=preg_replace("/=/","_",$compname);
$comp=preg_replace("/\./","-",$comp);
if(preg_match("/_S-/",$comp)){continue;}
foreach($QUAKE_PLOTS as $plot){
$plotbase="quake-$plot-$comp";
$description=shell_exec("cat $quakedir/$plotbase.html");
if(isBlank($description)){$description="<h4>$plotbase</h4>";}
statusMsg("Generating plot $plotbase...");
$output=shell_exec("find -L $quakedir -name '${plotbase}__*.png'");
if(isBlank($output)){
$cmd="cd $quakedir;python $plotbase.py";
shell_exec($cmd);
$output=shell_exec("find -L $quakedir -name '${plotbase}__*.png'");
}else{
statusMsg("Plot already generated...");
}
$listpng=preg_split("/\n/",$output);
$plots.="$description<div class='plotstack'>";
foreach($listpng as $png){
if(isBlank($png)){continue;}
$pngname=rtrim(shell_exec("basename $png"));
$pngbase=preg_split("/\./",$pngname)[0];
$pngparts=preg_split("/__/",$pngbase);
$pngmd5=$pngparts[1];
if(in_array($pngmd5,$plotmd5s)){continue;}
else{array_push($plotmd5s,$pngmd5);}
$plot=parse_ini_file("$quakedir/$plotbase.history/$pngbase.conf");
if(isset($plot["description"])){$deschist=$plot["description"];}
else{$deschist="No description";}
$plotfigure=generateFigure($quakedir,$plotbase,$pngmd5);
$plots.="$plotfigure";
statusMsg("Plot generated...");
}
$plots.="</div>";
}
}
statusMsg("All plots generated...");
$tideresults.=$plots;
}
endcalculate:
if(!$qdone){
$tideresults.="Processing request...<br/><img src=img/loader.gif>";
header("Refresh:3;url=index.php?if=quaketide&action=$action&quakeid=$quakeid&qlat=$qlat&qlon=$qlon&qdepth=$qdepth&qdatetime=$qdatetime&qjd=$qjd&hmoon=$hmoon&hsun=$hsun&qstrikemain=$qstrikemain&qdipmain=$qdipmain&qrakemain=$qrakemain&qdate=$qdate&qtime=$qtime&Ml=$Ml");
}
}//End action=calculate
////////////////////////////////////////////////////////////////////////
//REGISTER STATION
////////////////////////////////////////////////////////////////////////
else {
echo "Server responding: ",$DATE;
return 0;
}
endaction:
$CONTENT.="";
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
////////////////////////////////////////////////////////////////////////
//WEBPAGE
////////////////////////////////////////////////////////////////////////
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
if(0){}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//USER
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
else if($if=="user"){
if($QPERM<1){
$CONTENT.=<<<C
<h3>User login</h3>
$FORM
<input type="hidden" name="urlref" value="$urlref">
<table>
<tr>
<td>E-mail:</td>
<td><input type="text" name="email" placeholder="Su e-mail" value="$email"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" placeholder="Contraseña"></td>
</tr>
<tr>
<td colspan=2>
<input type="submit" name="action" value="Login">
</td>
</tr>
<tr>
<td colspan=2>
<a href=?if=newuser>New user</a> |
<a href=?if=recoverpass>Recover password</a>
</td>
</tr>
</table>
</form>
C;
}else{
$CONTENT="<i>You are already logged in as $NAME</i>";
}
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//NEW USER
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
else if($if=="setpassword"){
$results=mysqlCmd("select * from Users where email='$email'");
$spass=$results["password"];
if($pid==$spass){
$CONTENT.=<<<C
$FORM
<h3>Changing password for $email</h3>
<input type="hidden" name="pass" value="$pid">
<input type="hidden" name="email" value="$email">
<table>
<tr>
<td>New password:</td>
<td><input type="password" name="pass1" placeholder="Your new password"></td>
</tr>
<tr>
<td>Confirm password:</td>
<td><input type="password" name="pass2" placeholder="Repeat your password"></td>
</tr>
<tr>
<td colspan=2>
<input type="submit" name="action" value="Change">
</td>
</tr>
</table>
</form>
C;
}else{
errorMsg("User not authorized");
$CONTENT.="<i>Authentication failed</i>";
}
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//NEW USER
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
else if($if=="newuser"){
$CONTENT.=<<<C
<form>
<h3>Nuevo usuario</h3>
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="uname" placeholder="Name" value="$uname"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="email" placeholder="Your e-mail" value="$email"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" placeholder="Your password"></td>
</tr>
<tr>
<td>Confirm password:</td>
<td><input type="password" name="cpassword" placeholder="Your password"></td>
</tr>
<tr>
<td colspan=2>
<input type="submit" name="action" value="Create">
</td>
</tr>
</table>
</form>
C;
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//RECOVER PASS
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
else if($if=="recoverpass"){
$CONTENT.=<<<C
<form>
<h2>Password Recovery</h2>
<table>
<tr>
<td>E-mail:</td>
<td><input type="text" name="email" placeholder="Your registered e-mail"></td>
</tr>
<tr>
<td colspan=2>
<input type="submit" name="action" value="Recover">
</td>
</tr>
</table>
</form>
C;
}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//DOWNLOAD
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
else if($if=="download"){
$CONTENT.=<<<C
<h2>Download tQuakes</h2>
<p>
$tQuakes is an open source project. You can download it directly
from its <a href="$GITREPO" target="_blank">GitHub repository</a>.
</p>
<p>
There are two branches:
<ul>
<li>
The <b>station branch</b> which contains all the required
"machinery" to run individual processes sent by a $tQuakes
server. In order to download it you must have <b>~40 Mb</b>
available.<br/><br/>
To <b>install station branch</b> run:
<blockquote class="cmd">
git clone --branch station --single-branch $GITREPO
</blockquote>
<p>
In order to simplify the download and installation of a computation
station you can also download and run this installation script:
<a href="site/install-station.sh">install-station.sh</a>. The
installation script is intended for clients running <b>Linux
Debian</b> and has been extensively tested in <b>Ubuntu boxes</b>.
</p>
</li>
<li>
The <b>master branch</b> which contains all the required
"machinery" to run a $tQuakes server (serve a local database,
compute own dataproducts, etc.) This branck comes with a
preloaded earthquakes database (the database in
the <a href="$MAINSERVER">main server</a>). In order to