-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-fetch-times.php
1052 lines (921 loc) · 38.1 KB
/
check-fetch-times.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
$Version = "check-fetch-times.php Version 1.13 - 09-Mar-2013";
/*
Utility diagnostic script to support the Saratoga-Weather.org AJAX/PHP template sets.
Author: Ken True - webmaster@saratoga-weather.org
Note: there are no user customizations expected in this utility. Please replace the
entire script with a newer version when available.
*/
//--self downloader --
if(isset($_REQUEST['sce']) and strtolower($_REQUEST['sce']) == 'view') {
$filenameReal = __FILE__;
$download_size = filesize($filenameReal);
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header("Content-type: text/plain");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
header('Connection: close');
readfile($filenameReal);
exit;
}
error_reporting(E_ALL);
// ------------------------------------------------------------------
if(isset($_REQUEST['show']) and preg_match('|settings|i',$_REQUEST['show'])) {
$toShow = array("Settings.php","Settings-weather.php","Settings-language.php");
$doneHeaders = false;
$doHighlight = preg_match('|settingsr|i',$_REQUEST['show'])?false:true;
foreach ($toShow as $n => $showFilename) {
if(!$doneHeaders) {
printHeaders();
$doneHeaders = true;
print "<h2>Contents of Settings files</h2>\n";
}
if(file_exists($showFilename)) {
print "<h3>$showFilename</h3>\n";
print "<pre style=\"border: 1px solid black;\">\n";
if($doHighlight) {
highlight_file_num($showFilename);
} else {
$flines = file($showFilename);
$num = 1;
foreach ($flines as $n => $line) {
$line = preg_replace('|<\?php|i','<?php',$line);
$pnum = sprintf('%6d',$num);
print "$pnum:\t$line";
$num++;
}
}
print "</pre>\n<hr/>\n";
} else {
// print "<h2>$showFilename is not found.</h2>\n<hr/>\n";
}
}
if($doneHeaders) {
print " </body>\n";
print "</html>\n";
}
exit;
}
// ------------------------------------------------------------------
if(isset($_REQUEST['show']) and preg_match('|structure|i',$_REQUEST['show'])) {
$toShow = array('top.php','header.php','menubar.php','footer.php');
$doneHeaders = false;
$doHighlight = preg_match('|structurer|i',$_REQUEST['show'])?false:true;
foreach ($toShow as $n => $showFilename) {
if(!$doneHeaders) {
printHeaders();
$doneHeaders = true;
print "<h2>Contents of Website Structure files</h2>\n";
}
if(file_exists($showFilename)) {
print "<h3>$showFilename</h3>\n";
print "<pre style=\"border: 1px solid black;\">\n";
if($doHighlight) {
highlight_file_num($showFilename);
} else {
$flines = file($showFilename);
$num = 1;
foreach ($flines as $n => $line) {
$line = preg_replace('|<\?php|i','<?php',$line);
$pnum = sprintf('%6d',$num);
print "$pnum:\t$line";
$num++;
}
}
print "</pre>\n<hr/>\n";
} else {
// print "<h2>$showFilename is not found.</h2>\n<hr/>\n";
}
}
if($doneHeaders) {
print " </body>\n";
print "</html>\n";
}
exit;
}
// ------------------------------------------------------------------
if(isset($_REQUEST['show']) and strtolower($_REQUEST['show']) == 'info') {
if(file_exists("Settings.php")) {
include_once("Settings.php");
}
# set the Timezone abbreviation automatically based on $SITE['tzname'];
# Set timezone in PHP5/PHP4 manner
if (!function_exists('date_default_timezone_set')) {
putenv("TZ=" . $SITE['tz']);
// print "<!-- using putenv(\"TZ=". $SITE['tz']. "\") -->\n";
} else {
date_default_timezone_set($SITE['tz']);
// print "<!-- using date_default_timezone_set(\"". $SITE['tz']. "\") -->\n";
}
printHeaders();
print "<h2>Key PHP information</h2>\n";
print "<p>\n";
print "Webserver OS: <b>".php_uname()."</b><br/>\n";
print "PHP Version: <b>".phpversion()."</b><br/>\n";
print "Document root: <b>".$_SERVER['DOCUMENT_ROOT']."</b><br/>\n";
print "allow_url_fopen = <b>";
print ini_get("allow_url_fopen")?"ON":"off";
print "</b><br/>\n";
print "allow_url_include = <b>";
print ini_get("allow_url_include")?"ON":"off";
print "</b></p>\n";
$toCheck = array('simplexml_load_file','iconv','json_decode',
'curl_init','curl_setopt','curl_exec','curl_error','curl_close');
print "<p>Status of needed built-in PHP functions:<br/>\n";
foreach ($toCheck as $n => $chkName) {
print "function <b>$chkName</b> ";
if(function_exists($chkName)) {
print " is available<br/>\n";
} else {
print " is <b>NOT available</b><br/>\n";
}
}
print "class <b>Imagick</b> ";
print (class_exists("Imagick"))?" is available<br/>\n":" is <b>NOT available</b><br/>\n";
print "</p>\n";
print "<p>Current GD status:</p>\n";
echo describeGDdyn();
if(!file_exists("Settings.php")) {
$settingsLoad = "Unable to find Settings.php.. directory testing skipped.\n";
print $settingsLoad;
print " </body>\n";
print "</html>\n";
exit;
}
$Base = '';
$WXdirs = array( // specific directories from Settings-weather.php $SITE and files to check
'CU' => array('graphImageDir'=> 'temp.png','NOAAdir' => 'NOAAYRyyyy.txt'),
'MH' => array('graphImageDir'=> 'tdpb2day.png'),
'VWS'=> array('graphImageDir'=> 'vws742.jpg', 'NOAAdir'=> 'noaayr.txt'),
'WCT'=> array('graphImageDir'=> 'temperature1.jpg'),
'WD' => array('graphImageDir'=> 'curr24hourgraph.gif','HistoryFilesDir'=>'MONTHyyyy.htm',
'HistoryGraphsDir'=>'yyyymmdd.gif'),
'WL' => array('graphImageDir'=> 'OutsideTempHistory.gif','NOAACurDir'=>'NOAAMO.TXT'),
// 'WSN' => array('graphImageDir'=> '?????'), // no graphs for WeatherSnoop
'WV'=> array('graphImageDir'=> 'tempdaycomp.png', 'NOAAdir'=> 'NOAA-yyyy.txt'),
// 'WXS' => array('graphImageDir'=> '?????'), // no graphs for WXSolution
);
if(isset($SITE['fcsturlNWS']) or isset($SITE['NWSforecasts'])) {
$Base = 'USA';
}
if(isset($SITE['fcsturlEC']) or isset($SITE['ecradar'])) {
$Base = 'Canada';
}
if(isset($SITE['EUwarningURL']) or isset($SITE['fcsturlWU']) or isset($SITE['WUforecasts'])) {
$Base = 'World';
}
if(isset($SITE['WXsoftware']) ){
$wxsftw=$SITE['WXsoftware'];
} else {
$wxsftw = 'N/A';
}
print "<h2>Directories/files status for Base-$Base, $wxsftw-Plugin</h2>\n";
print "<p>Status of needed subdirectories<br/>\n";
print "Settings.php <b>Cache file directory</b> in \$SITE['cacheFileDir']='<b>".$SITE['cacheFileDir']. "</b>' ";
if(is_dir($SITE['cacheFileDir'])) {
$perms = fileperms($SITE['cacheFileDir']);
$permsdecoded = decode_permissions($perms);
$permsoctal = substr(sprintf('%o', $perms), -4);
print " exists, with permissions=$permsdecoded [$permsoctal]<br/>\n";
$tfile = $SITE['cacheFileDir'] . "test.txt";
$tstring = "Test of cache directory file create and write by $Version.<br/>\n";
$fp = fopen($tfile,'w');
if($fp) {
$write = fputs($fp, $tstring);
fclose($fp);
print "..Wrote ".strlen($tstring). " bytes to $tfile successfully, ";
$deleted = unlink($tfile);
print $deleted?"then deleted test file. <b>Cache directory is fully functional</b>.<br/>\n":" but unable to delete $tfile so <b>Cache directory is NOT fully functional</b>.<br/>\n";
} else {
print "<br/><b>Error: Unable to open/write to $tfile file</b> so so <b>Cache directory is NOT fully functional</b>.<br/>\n";
}
} else {
print "<b>does not exist</b> so some scripts will be <b>not functional</b>.<br/>\n";
}
print "Settings.php <b>ajax-images file directory</b> in \$SITE['imagesDir']='<b>".$SITE['imagesDir']. "</b>' ";
if(is_dir($SITE['imagesDir'])) {
print " exists; ";
print file_exists($SITE['imagesDir'].'skc.jpg')?
" and appears to have contents.<br/>\n":" but <b>does not have contents</b>. Be sure to upload contents for proper template operation.<br/>\n";
} else {
print " <b>is not on website.</b> Be sure to upload contents for proper template operation.<br/>\n";
}
if(isset($SITE['NWSalertsCodes']) and file_exists('nws-alerts-config.php')) {
include_once('nws-alerts-config.php');
$tFolder = $icons_folder . '/';
print "nws-alerts-config.php <b>alert-images file directory</b> \$icons_folder='<b>$icons_folder</b>' ";
if(is_dir($tFolder)) {
print " exists; ";
print file_exists($tFolder.'A-none.png')?
" and appears to have contents.<br/>\n":" but <b>does not have contents</b>. Be sure to upload contents for proper template operation.<br/>\n";
} else {
print " <b>is not on website.</b> Be sure to upload contents for proper template operation.<br/>\n";
}
}
if(isset($SITE['fcsticonsdirEC']) and file_exists('ec-forecast.php')) {
$tFolder = $SITE['fcsticonsdirEC'];
print "Settings.php <b>ec-icons file directory</b> \$SITE['fcsticonsdirEC']='<b>$tFolder</b>' ";
if(is_dir($tFolder)) {
print " exists; ";
print file_exists($tFolder.'01.gif')?
" and appears to have contents.<br/>\n":" but <b>does not have contents</b>. Be sure to upload contents for proper template operation.<br/>\n";
} else {
print " <b>is not on website.</b> Be sure to upload contents for proper template operation.<br/>\n";
}
}
print "Settings.php <b>forecast images file directory</b> in \$SITE['fcsticonsdir']='<b>".$SITE['fcsticonsdir']. "</b>' ";
if(is_dir($SITE['fcsticonsdir'])) {
print " exists; ";
$fType = (isset($SITE['fcsticonstype']) and $SITE['fcsticonstype'] == '.gif')?'.gif':'.jpg';
print file_exists($SITE['fcsticonsdir'].'skc'.$fType)?
" and appears to have $fType image contents.<br/>\n":" but <b>does not have $fType image contents</b>. Be sure to upload contents for proper template operation.<br/>\n";
} else {
print " <b>is not on website.</b> Be sure to upload contents for proper template operation.<br/>\n";
}
if(isset($WXdirs[$wxsftw])) { // check weather-software specific directories
$toCheck = $WXdirs[$wxsftw]; // get the list.
foreach ($toCheck as $siteVar => $chkFile) {
if(isset($SITE[$siteVar])) {
$chkDir = $SITE[$siteVar];
print "Settings-weather.php \$SITE['$siteVar']='<b>".$chkDir. "</b>' ";
if(is_dir($chkDir)) {
print " exists; ";
list($nowYear,$nowMonth,$nowMM,$nowDD) = explode(" ",date('Y F m d',time()-24*60*60));
$chkFile = preg_replace('|yyyy|',$nowYear,$chkFile);
$chkFile = preg_replace('|yy|',substr($nowYear,2,2),$chkFile);
$chkFile = preg_replace('|MONTH|',$nowMonth,$chkFile);
$chkFile = preg_replace('|mm|',$nowMM,$chkFile);
$chkFile = preg_replace('|dd|',$nowDD,$chkFile);
print file_exists($chkDir.$chkFile)?
" and appears to have contents.<br/>\n":" but <b>does not have contents ($chkFile tested)</b>. Set $wxsftw software to upload contents for proper template operation.<br/>\n";
} else {
print " <b>is not on website.</b> Set $wxsftw software to upload contents for proper template operation.<br/>\n";
}
}
}
}
print "</p>\n";
$updateDate = file_exists("common.php")?filemtime("common.php"):'unknown';
if($updateDate <> 'unknown') {$updateDate = gmdate('D, d-M-Y g:ia T',$updateDate); }
print "<p>common.php last updated: $updateDate</p>\n";
$updateDate = file_exists("language-en.txt")?filemtime("language-en.txt"):'unknown';
if($updateDate <> 'unknown') {$updateDate = gmdate('D, d-M-Y g:ia T',$updateDate); }
print "<p>language-en.txt last updated: $updateDate</p>\n";
print " </body>\n";
print "</html>\n";
exit;
}
$time_init = time();
if(file_exists("Settings.php")) {
$T_start = microtime_float();
include("Settings.php");
$T_stop = microtime_float();
$settingsLoad = "Included Settings.php time=" . sprintf("%01.3f",round($T_stop - $T_start,3)) . " secs.\n\n";
} else {
$settingsLoad = "Unable to find Settings.php.. testing skipped.\n";
print $settingsLoad;
return;
}
printHeaders();
// ------------------------------------------------------------------
//
// do version checking for key scripts (part of V1.06+)
//
if(isset($_REQUEST['show']) and strtolower($_REQUEST['show']) == 'versions') { // do Version checking
// Template updates are all based in Pacific time in the distribution .zip files
$ourTZ = 'America/Los_Angeles';
# set the Timezone abbreviation automatically based on $SITE['tzname'];
# Set timezone in PHP5/PHP4 manner
if (!function_exists('date_default_timezone_set')) {
putenv("TZ=" . $ourTZ);
// print "<!-- using putenv(\"TZ=". $SITE['tz']. "\") -->\n";
} else {
date_default_timezone_set($ourTZ);
// print "<!-- using date_default_timezone_set(\"". $SITE['tz']. "\") -->\n";
}
global $SITE;
$Lang = 'en';
$cacheFileDir = './';
if(isset($SITE['lang'])) {$Lang = $SITE['lang'];}
if(isset($SITE['cacheFileDir'])) {$cacheFileDir = $SITE['cacheFileDir'];}
$templateVersionsFile = 'template-version-info.txt';
$templateVersionsURL = 'http://saratoga-weather.org/wxtemplates/'.$templateVersionsFile;
print $settingsLoad;
# fetch/cache template version info file from master (if available)
$TESTURL = $templateVersionsURL;
$CACHE = $cacheFileDir.$templateVersionsFile;
print "<pre>\n";
if (!isset($_REQUEST['force']) and file_exists($CACHE) and filemtime($CACHE) + 600 > time()) { // 1800
print "..loading $CACHE for version information.\n";
} else {
print "..fetching recent version information.\n";
$rawhtml = fetchUrlWithoutHanging($TESTURL,false);
$RC = '';
if (preg_match("|^HTTP\/\S+ (.*)\r\n|",$rawhtml,$matches)) {
$RC = trim($matches[1]);
}
print "RC=$RC, bytes=" . strlen($rawhtml) . "\n";
$i = strpos($rawhtml,"\r\n\r\n");
$headers = substr($rawhtml,0,$i-1);
$content = substr($rawhtml,$i+2);
$html = explode("\n",$content); // put HTML area as separate lines
$age = -1;
$udate = 'unknown';
$budate = 0;
if(preg_match('|\nLast-Modified: (.*)\n|Ui',$headers,$match)) {
$udate = trim($match[1]);
$budate = strtotime($udate);
$age = abs(time() - $budate); // age in seconds
print "Data age=$age sec '$udate'\n";
}
if (!preg_match('| 200|',$headers)) {
print "------------\nHeaders returned:\n\n$headers\n------------\n";
print "\nSkipped cache write to $CACHE file.\n";
} elseif ($CACHE <> '') {
$fp = fopen($CACHE,'w');
if($fp) {
$write = fputs($fp, $rawhtml);
fclose($fp);
print "Wrote ".strlen($rawhtml). " bytes to $CACHE successfully.\n";
} else {
print "Error: Unable to write to $CACHE file.\n";
}
}
} // end fetch new version info from saratoga-weather.org
# now load up the version info which looks like:
/*
# template-version-info updated 2012-08-06 08:38 PDT by( version-info V1.00 - 05-Aug-2012 )
#Base File ModDate Size Index ZipSize MD5 Version VDate VersionDesc
Base-Canada wxuvforecast.php 2012-03-31 05:20 PDT 7376 299 7193 abfb72a9504fc73812e8a4eb8822831a 1.01 2012-03-31 1.01 - 31-Mar-2012 - day-of-week fix for get-UV-forecast-inc.php V1.07
Base-Canada wxtrends.php 2011-01-19 11:04 PST 2914 298 2842 ff4f1a25ebeb60a130b291303005817e n/a 2011-01-19 (not specified)
*/
$MasterVersions = array();
$nVersions = 0;
$VFile = file($CACHE);
if(count($VFile) < 10) {
print "Error: $CACHE file is not complete..skipping testing.\n";
return;
}
foreach ($VFile as $n => $rec) {
$recin = trim($rec);
if ($recin and substr($recin,0,1) <> '#') { // got a non comment record
list($Base,$File,$ModDate,$Size,$Index,$ZipSize,$FileMD5,$Fversion,$FvDate,$FvDesc) = explode("\t",$recin . "\t\t\t\t\t\t\t\t\t\t");
$MasterVersions["$Base\t$File"] = "$ModDate\t$Size\t$FileMD5\t$Fversion\t$FvDate\t$FvDesc";
$nVersions++;
}
}
print "..loaded $nVersions version descriptors from $CACHE file.\n";
# end of get new template version info file
# set of files to do version checking
$templateFiles = array(
'Common' => array(
// 'ajaxgizmo.js',
'ajax-gizmo.php','ajax-dashboard.php','common.php','check-fetch-times.php',
'flyout-menu.php','include-style-switcher.php',
'get-metar-conditions-inc.php','get-USNO-sunmoon.php','get-UV-forecast-inc.php',
'include-metar-display.php','include-wxstatus.php','plaintext-parser.php','plaintext-parser-data.txt',
'thermometer.php','wxgraphs.php','wxmetar.php','wxquake.php'),
'USA' => array(
'advforecast2.php','atom-advisory.php','atom-top-warning.php','get-nnvl-iod.php',
'GR3-radar-inc.php','floatTop.js',
'nws-alerts.php','nws-alerts-details-inc.php','nws-alerts-summary-inc.php',
'nws-alertmap.js','nws-shapefile.txt','swfobject.js',
'quake-json.php','quake-json.js','radar-status.php','WU-radar-inc.php'),
'Canada' => array(
'ec-forecast.php','ec-radar.php','quake-Canada.php'),
'World' => array(
'get-meteoalarm-warning-inc.php','quake-json.php','quake-json.js','quake-UK.php',
'Settings-language.php','WU-forecast.php'),
'CU' => array('ajaxCUwx.js','CU-defs.php','gen-CUtags.php','tags.txt',
'include-NOAA-reports.php'),
'MB' => array('ajaxMBwx.js','MB-defs.php','MB-trends-inc.php','gen-MBtags.php',
'MBtags-template.txt','conds.php','MBrealtime-template.txt'),
'MH' => array('ajaxMHwx.js','MH-defs.php','yesterday.php','MH-trends-inc.php'),
'VWS' => array('ajaxVWSwx.js','VWStags.php','VWS-defs.php','gen-VWStags.php','tags.txt',
'include-NOAA-reports.php'),
'WCT' => array('ajaxWCTwx.js','WCT-defs.php','gen-WCTtags.php','WeatherCat-webtags.txt'),
'WD' => array(
'ajaxWDwx.js','WD-trends-inc.php','include-wxhistory.php'),
'WL' => array('ajaxWLwx.js','WL-defs.php','gen-WLtags.php','WLtags.txt',
'include-NOAA-reports.php'),
'WSN' => array('WSNtags.php','WSN-defs.php'),
'WV' => array('WV-defs.php','gen-WVtags.php','tags.txt',
'include-NOAA-reports.php'),
'WXS' => array('WXS-defs.php','gen-WXStags.php','tags.txt'),
);
$selectedVersions = array();
$selectedVersionsType = array();
$toCheckFiles = $templateFiles['Common'];
$toCheckLegend = 'Common Files';
foreach ($templateFiles['Common'] as $key => $val) {$selectedVersionsType[$val] = 'Common'; }
$updateBasePlugin = '';
if(isset($SITE['fcsturlNWS']) or isset($SITE['NWSforecasts'])) {
$toCheckFiles = array_merge($toCheckFiles,$templateFiles['USA']);
$toCheckLegend .= ', Base-USA';
load_selected_array('Base-USA');
$updateBasePlugin = 'Base-USA';
foreach ($templateFiles['USA'] as $key => $val) {$selectedVersionsType[$val] = 'USA'; }
}
if(isset($SITE['fcsturlEC']) or isset($SITE['ecradar'])) {
$toCheckFiles = array_merge($toCheckFiles,$templateFiles['Canada']);
$toCheckLegend .= ', Base-Canada';
load_selected_array('Base-Canada');
$updateBasePlugin = 'Base-Canada';
foreach ($templateFiles['Canada'] as $key => $val) {$selectedVersionsType[$val] = 'Canada'; }
}
if(isset($SITE['EUwarningURL']) or isset($SITE['fcsturlWU']) or isset($SITE['WUforecasts'])) {
$toCheckFiles = array_merge($toCheckFiles,$templateFiles['World']);
$toCheckLegend .= ', Base-World';
load_selected_array('Base-World');
$updateBasePlugin = 'Base-World';
foreach ($templateFiles['World'] as $key => $val) {$selectedVersionsType[$val] = 'World'; }
}
if(isset($SITE['WXsoftware']) and isset($templateFiles[ $SITE['WXsoftware'] ]) ){
$wxsftw=$SITE['WXsoftware'];
$toCheckFiles = array_merge($toCheckFiles,$templateFiles[$wxsftw]);
$toCheckLegend .= ', '.$wxsftw.'-plugin';
load_selected_array($wxsftw.'-plugin');
foreach ($templateFiles[$wxsftw] as $key => $val) {$selectedVersionsType[$val] = $wxsftw.'-plugin'; }
if( isset($SITE['WXsoftwareLongName']) ) {
$toCheckLegend .= ' (for '.$SITE['WXsoftwareLongName'].' weather software)';
}
$updateBasePlugin .= ', '.$wxsftw.'-plugin';
}
print "</pre>\n";
print "<h3>Version information for selected <strong>$toCheckLegend</strong> key template files</h3>\n";
print "<p style=\"border: 2px dotted red; background-color: #FFCC00; padding: 5px;\">";
print "<strong>Note</strong>: only selected key template files are checked with this script. Files with customary user modifications (Settings.php, Settings-weather.php, top.php, header.php, menubar.php, footer.php, most wx...php files, etc.) and graphics and weather tags files are NOT checked as they either do not contain version information or they are expected to be different from the distribution versions due to normal website customization.";
print "</p>\n";
print "<table style=\"border: 1px;\" cellpadding=\"2\" cellspacing=\"2\">\n";
print "<tr><th>Script<br/>Origin</th><th>Script<br/>Name</th><th>Installed Script</br>Version Status</th><th>Release Script<br/>Version</th><th>Installed Script<br/>Version</th><th>Installed Script Internal<br/>Version Description</th></tr>\n";
$earliestDate = '9999-99-99';
natcasesort($toCheckFiles);
$idx = 0;
foreach ($toCheckFiles as $n => $checkFile) {
if ($idx % 5 <> 0) { $TRclass = 'row-even'; } else { $TRclass = 'row-odd'; }
list($mDate,$vNumber,$vDate,$vInfo,$FileMD5,$fStatus) = chk_file_version($checkFile);
$instVer = '';
if($vNumber <> '' and $vDate <> '') {$instVer = "V$vNumber - $vDate"; }
$distVer = '';
if(isset($selectedVersions[$checkFile])) {
list($mstModDate,$mstSize,$mstFileMD5,$mstFversion,$mstFvDate,$mstFvDesc) =
explode("\t",$selectedVersions[$checkFile]);
$distVer = "V$mstFversion - $mstFvDate";
}
$fSource = $selectedVersionsType[$checkFile];
print "<tr class=\"$TRclass\"><td>$fSource</td><td><strong>$checkFile</strong></td><td>$fStatus</td><td>$distVer</td><td>$instVer</td><td>$vInfo</td></tr>\n";
$idx++;
}
print "</table>\n";
if($earliestDate <> '9999-99-99') {
//found some updates
$updateBasePluginDate = date('d-M-Y',strtotime($earliestDate));
print "<h3>To update your template set to current script version(s), use <a href=\"http://saratoga-weather.org/wxtemplates/updates.php\"><strong>the updates tool page</strong></a> with a query set for <strong>$updateBasePluginDate</strong> for ";
print "<strong>$updateBasePlugin</strong></h3>\n";
}
print "<pre>\n";
// end of version checking
} else { // do fetch file checking
// ------------------------------------------------------------------
// file fetch checking
print '
<p>This script will check the load times and the ability to save cache files for the included support
scripts with your template package.</p>
<pre>
';
print $settingsLoad;
global $SITE;
$Lang = 'en';
$cacheFileDir = './';
if(isset($SITE['lang'])) {$Lang = $SITE['lang'];}
if(isset($SITE['cacheFileDir'])) {$cacheFileDir = $SITE['cacheFileDir'];}
$Tests = array(
'fcsturlNWS' => 'NWS Forecast URL|forecast.txt|NWSforecasts|2|forecast-0.txt',
'noaazone' => 'NWS Warning Zone ATOM/CAP Feed',
'UVscript' => 'UV Forecast from temis.nl|uv-forecast.txt',
'fcsturlEC' => 'EC Forecast URL|ec-forecast-LL.txt',
'ecradar' => 'EC Radar URL',
'fcsturlWU' => 'WU Forecast URL|WU-forecast-LL.txt|WUforecasts|1|WU-forecast-0-LL.txt',
'EUwarningURL' => 'METEOalarm warning URL|meteoalarm-LL.txt'
);
print "<p>Using lang=$Lang as default for testing</p>\n";
global $TOTALtime;
$TOTALtime = $T_stop - $T_start;
foreach ($Tests as $sname => $sval) {
$useAltUrl = '';
list($sdescript,$cname,$altvar,$altindex,$altcname) = explode('|',$sval.'||||');
if($altvar <> '' and isset($SITE[$altvar][0]) ) { // fetch first entry in multiforecast variable
$vars = explode('|',$SITE[$altvar][0].'||||');
$useAltUrl = $vars[$altindex];
$cname = preg_replace('|LL|',$Lang,$altcname);
} else {
$cname = preg_replace('|LL|',$Lang,$cname);
}
if(isset($SITE[$sname])) {
print "--checking $sdescript --\n";
$TESTURL = $SITE[$sname];
$CACHE = '';
if($useAltUrl) {
$TESTURL = $useAltUrl;
}
if($cname <> '') {$CACHE = $cacheFileDir.$cname; }
if($sname == 'UVscript') {
$TESTURL = "http://www.temis.nl/uvradiation/nrt/uvindex.php?lon=" .$SITE['longitude'] . "&lat=" . $SITE['latitude'];
}
if($sname == 'noaazone') {
$TESTURL = "http://alerts.weather.gov/cap/wwaatmget.php?zone=".$SITE['noaazone'];
$CACHE = $cacheFileDir."atom-advisory-".$SITE['noaazone'].".txt";
}
if($sname == 'ecradar') {
$TESTURL = 'http://weatheroffice.gc.ca/radar/index_e.html?id=' . $SITE['ecradar'];
$CACHE = "../radar/ec-radar-en.txt";
}
if($useAltUrl <> '') {
print "Using first entry in \$SITE['$altvar'] for test.\n";
} else {
print "Using \$SITE['$sname'] entry for test.\n";
}
print "URL: $TESTURL\n";
if($CACHE <> '') {
print "Cache: $CACHE\n";
}
$rawhtml = fetchUrlWithoutHanging($TESTURL,false);
$RC = '';
if (preg_match("|^HTTP\/\S+ (.*)\r\n|",$rawhtml,$matches)) {
$RC = trim($matches[1]);
}
print "RC=$RC, bytes=" . strlen($rawhtml) . "\n";
$i = strpos($rawhtml,"\r\n\r\n");
$headers = substr($rawhtml,0,$i-1);
$content = substr($rawhtml,$i+2);
$html = explode("\n",$content); // put HTML area as separate lines
$age = -1;
$udate = 'unknown';
$budate = 0;
if(preg_match('|\nLast-Modified: (.*)\n|Ui',$headers,$match)) {
$udate = trim($match[1]);
$budate = strtotime($udate);
$age = abs(time() - $budate); // age in seconds
print "Data age=$age sec '$udate'\n";
}
if (!preg_match('| 200 |',$headers)) {
print "------------\nHeaders returned:\n\n$headers\n------------\n";
print "\nSkipped cache write test to $CACHE file.\n";
} elseif ($CACHE <> '') {
$fp = fopen($CACHE,'w');
if($fp) {
$write = fputs($fp, $rawhtml);
fclose($fp);
print "Wrote ".strlen($rawhtml). " bytes to $CACHE successfully.\n";
} else {
print "Error: Unable to write to $CACHE file.\n";
}
}
print "--end $sdescript check --\n\n";
}
}
print "\nTotal time taken = " . sprintf("%01.3f",round($TOTALtime,3)) . " secs.\n";
$time_finished = time();
$time_elapsed = $time_finished - $time_init;
print "Elapsed $time_elapsed seconds.\n\n";
} // end fetch-time-checking
print "PHP Version " . phpversion() . "\n";
print "Memory post_max_size " . ini_get('post_max_size') . " bytes.\n";
print "Memory usage " . memory_get_usage() . " bytes.\n";
print "Memory peak usage " . memory_get_peak_usage() . " bytes.\n";
?>
</pre>
<?php
// ------------------------------------------------------------------
function printHeaders() {
global $Version;
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Saratoga-weather.org Template Test Utility</title>
<meta http-equiv="Robots" content="noindex,nofollow,noarchive" />
<meta name="author" content="Ken True" />
<meta name="copyright" content="© 2012, Saratoga-Weather.org" />
<meta name="Description" content="Saratoga-weather.org AJAX/PHP website template diagnostic utility." />
<style type="text/css">
.row-odd {background-color: #96C6F5; }
.row-even {background-color: #EFEFEF; }
.num {
float: left;
color: gray;
font-size: 13px;
font-family: monospace;
text-align: right;
margin-right: 6pt;
padding-right: 6pt;
border-right: 1px solid gray;
}
body {margin: 0px; margin-left: 5px;}
td { vertical-align: top;
font-size: 13px;
font-family: monospace;
}
code {white-space: nowrap;
font-size: 13px;
font-family: monospace;
}
</style>
</head>
<body style="background-color:#FFFFFF; font-family:Arial, Helvetica, sans-serif;font-size: 10pt;">
<h3>'.$Version.'</h3>
';
}
// ------------------------------------------------------------------
// Retrieve information about the currently installed GD library
// script by phpnet at furp dot com (08-Dec-2004 06:59)
// from the PHP usernotes about gd_info
function describeGDdyn() {
echo "\n<ul><li>GD support: ";
if(function_exists("gd_info")){
echo "<span style=\"color:#00ff00\">yes</span>";
$info = gd_info();
$keys = array_keys($info);
for($i=0; $i<count($keys); $i++) {
if(is_bool($info[$keys[$i]])) {
echo "</li>\n<li>" . $keys[$i] .": " . yesNo($info[$keys[$i]]);
} else {
echo "</li>\n<li>" . $keys[$i] .": " . $info[$keys[$i]];
}
}
} else {
echo "<span style=\"color:#ff0000\">NO</span>";
}
echo "</li></ul>\n";
}
// ------------------------------------------------------------------
function yesNo($bool){
if($bool) {
return "<span style=\"color:#00ff00\"> yes</span>";
} else {
return "<span style=\"#ff0000\"> no</span>";
}
}
// ------------------------------------------------------------------
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
// ------------------------------------------------------------------
// get contents from one URL and return as string
function fetchUrlWithoutHanging($url,$useFopen) {
// thanks to Tom at Carterlake.org for this script fragment
global $Debug, $needCookie,$timeStamp,$TOTALtime;
$overall_start = time();
if (! $useFopen) {
// Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
$numberOfSeconds=2;
// Suppress error reporting so Web site visitors are unaware if the feed fails
error_reporting(0);
// Extract resource path and domain from URL ready for fsockopen
$FullUrl = $url;
$urlParts = parse_url($url);
$domain = $urlParts['host'];
if(isset($urlParts['port'])) {
$port = $urlParts['port'];
} else {
$port = 80;
}
$resourcePath = $urlParts['path'];
$resourcePath = preg_replace('|nocache|','?'.$timeStamp,$resourcePath);
if(isset($urlParts['query'])) {$resourcePath .= "?" . $urlParts['query']; }
if(isset($urlParts['fragment'])) {$resourcePath .= "#" . $urlParts['fragment']; }
$T_start = microtime_float();
$hostIP = gethostbyname($domain);
$T_dns = microtime_float();
$ms_dns = sprintf("%01.3f",round($T_dns - $T_start,3));
$Debug .= "<!-- GET $resourcePath HTTP/1.1 \n Host: $domain Port: $port IP=$hostIP-->\n";
print "GET $resourcePath HTTP/1.1 \n Host: $domain Port: $port IP=$hostIP\n";
// Establish a connection
$socketConnection = fsockopen($hostIP, $port, $errno, $errstr, $numberOfSeconds);
$T_connect = microtime_float();
$T_puts = 0;
$T_gets = 0;
$T_close = 0;
if (!$socketConnection)
{
// You may wish to remove the following debugging line on a live Web site
$Debug .= "<!-- Network error: $errstr ($errno) -->\n";
print "Network error: $errstr ($errno)\n";
} // end if
else {
$xml = '';
$getString = "GET $resourcePath HTTP/1.1\r\nHost: $domain\r\nConnection: Close\r\n\r\n";
// if (isset($needCookie[$domain])) {
// $getString .= $needCookie[$domain] . "\r\n";
// print " used '" . $needCookie[$domain] . "' for GET \n";
// }
// $getString .= "\r\n";
// print "Sending:\n$getString\n\n";
fputs($socketConnection, $getString);
$T_puts = microtime_float();
// Loop until end of file
$TGETstats = array();
$TGETcount = 0;
while (!feof($socketConnection))
{
$T_getstart = microtime_float();
$xml .= fgets($socketConnection, 8192);
$T_getend = microtime_float();
$TGETcount++;
$TGETstats[$TGETcount] = sprintf("%01.3f",round($T_getend - $T_getstart,3));
} // end while
$T_gets = microtime_float();
fclose ($socketConnection);
$T_close = microtime_float();
} // end else
$ms_connect = sprintf("%01.3f",round($T_connect - $T_dns,3));
if($T_close > 0) {
$ms_puts = sprintf("%01.3f",round($T_puts - $T_connect,3));
$ms_gets = sprintf("%01.3f",round($T_gets - $T_puts,3));
$ms_close = sprintf("%01.3f",round($T_close - $T_gets,3));
$ms_total = sprintf("%01.3f",round($T_close - $T_start,3));
} else {
$ms_puts = 'n/a';
$ms_gets = 'n/a';
$ms_close = 'n/a';
$ms_total = sprintf("%01.3f",round($T_connect - $T_start,3));
}
$Debug .= "<!-- HTTP stats: conn=$ms_connect put=$ms_puts get=$ms_gets close=$ms_close total=$ms_total secs -->\n";
print "HTTP stats: dns=$ms_dns conn=$ms_connect put=$ms_puts get($TGETcount blocks)=$ms_gets close=$ms_close total=$ms_total secs \n";
// foreach ($TGETstats as $block => $mstimes) {
// print "HTTP Block $block took $mstimes\n";
// }
$TOTALtime+= ($T_close - $T_start);
$overall_end = time();
$overall_elapsed = $overall_end - $overall_start;
print "fetch function elapsed= $overall_elapsed secs.\n";
return($xml);
} else {
// print "<!-- using file function -->\n";
$T_start = microtime_float();
$xml = implode('',file($url));
$T_close = microtime_float();
$ms_total = sprintf("%01.3f",round($T_close - $T_start,3));
$Debug .= "<!-- file() stats: total=$ms_total secs -->\n";
print " file() stats: total=$ms_total secs.\n";
$TOTALtime+= ($T_close - $T_start);
$overall_end = time();
$overall_elapsed = $overall_end - $overall_start;
print "fetch function elapsed= $overall_elapsed secs.\n";
return($xml);
}
} // end fetchUrlWithoutHanging
// ------------------------------------------------------------------
#---------------------------------------------------------
# load file to string for version checking
#---------------------------------------------------------
function chk_file_version($inFile) {
global $selectedVersions,$earliestDate;
if(!file_exists($inFile)) {
return(
array('n/a','','',"<strong>$inFile file not found.</strong>",'','<strong>File not installed</strong>'));
}
$mDate = date('Y-m-d H:i T',filemtime($inFile));
$tContents = file_get_contents($inFile);
$vInfo = scan_for_version_string($tContents);
$tContents = preg_replace('|\r|is','',$tContents);
$FileMD5 = md5($tContents);
if(strlen($vInfo) > 120) {$vInfo = '(not specified)'; }
if(preg_match('!(\d+\.\d+)[^\d]*(\d+-\S{3}-\d{4})!',$vInfo,$matches)) {
$vNumber = $matches[1];
$vDate = date('Y-m-d',strtotime($matches[2]));
} else {
$vNumber = 'n/a';
$vDate = 'n/a';
}
$fStatus = 'unknown';
if(isset($selectedVersions[$inFile])) {
list($mstModDate,$mstSize,$mstFileMD5,$mstFversion,$mstFvDate,$mstFvDesc) =
explode("\t",$selectedVersions[$inFile]);
$MD5matches = ($mstFileMD5 == $FileMD5)?true:false;
$VerMatches = ($vNumber <> 'n/a' and $mstFversion <> 'n/a' and
strcmp($vNumber,$mstFversion) === 0)?true:false;
if ($MD5matches) { $fStatus = "Current<!-- MD5 matched -->"; }
if ($fStatus == 'unknown' and $VerMatches) {$fStatus = 'Current<!-- version matched -->'; }
if ($fStatus == 'unknown' and $vNumber <> 'n/a' and $mstFversion <> 'n/a' and
strcmp($vNumber,$mstFversion) < 0) {
$fStatus = "<strong>Need update to<br/>V$mstFversion - $mstFvDate</strong>";
$earliestDate = ($mstFvDate < $earliestDate)?$mstFvDate:$earliestDate;
}
if ($fStatus == 'unknown' and $vNumber <> 'n/a' and $mstFversion <> 'n/a' and
strcmp($vNumber,$mstFversion) > 0) {
$fStatus = "<strong>Installed version is more recent</strong>";
}
if ($fStatus == 'unknown' and $mstFversion <> 'n/a' and $mstFvDate <> 'n/a') {
$fStatus = "<strong>Need update to<br/>V$mstFversion - $mstFvDate</strong>";
$earliestDate = ($mstFvDate < $earliestDate)?$mstFvDate:$earliestDate;
}
}
return(array($mDate,$vNumber,$vDate,$vInfo,$FileMD5,$fStatus));
}
#---------------------------------------------------------
# scan for a version string in a PHP/JS/TXT file
#---------------------------------------------------------
function scan_for_version_string($input) {
$vstring = '(not specified)';
preg_match('/\$\S*Version\s+=\s+[\'|"]([^\'|"]+)[\'|"];/Uis',$input,$matches);
if(isset($matches[1])) {
$vstring = $matches[1];
// print "--- 1:found $vstring ---\n";
return(trim($vstring));
}
preg_match_all('/Version (.*)\n/Uis',$input,$matches);
// print "---2:Matches\n".print_r($matches,true)."\n---\n";
if (isset($matches[1]) and count($matches[1]) > 0) {
for($i=count($matches[1])-1;$i>=0;$i--) {
$tstring = $matches[1][$i];
if(preg_match('|\d+-\S{3}-\d{4}|',$tstring)) {
$vstring = $tstring;
// print "--- 2:found $vstring ---\n";
return(trim($vstring));
}
}
}
return($vstring);
} // end scan_for_version_string
#---------------------------------------------------------
# load the to-scan array with the filenames to look for
#---------------------------------------------------------
function load_selected_array($key) {
global $MasterVersions,$selectedVersions;
$n = 0;
foreach ($MasterVersions as $k => $data) {
list($base,$file) = explode("\t",$k);
if($base == $key) {
$selectedVersions["$file"] = $data;
$n++;
}
}
print "..loaded $n version descriptors for $key.\n";
return;
} // end load_selected_array
#---------------------------------------------------------
# display file with PHP highlighting and line numbers
#---------------------------------------------------------
function highlight_file_num($file)
{
$lines = implode(range(1, count(file($file))), '<br />');
$content = highlight_file($file, true);
echo "<table><tr><td class=\"num\">\n$lines\n</td><td>\n$content\n</td></tr></table>";
}
#---------------------------------------------------------
# decode unix file permissions
#---------------------------------------------------------
function decode_permissions($perms) {