Repository navigation
Expand file tree
/
Copy pathtools.php
More file actions
executable file
·1627 lines (1404 loc) · 72.6 KB
/
Copy pathtools.php
File metadata and controls
executable file
·1627 lines (1404 loc) · 72.6 KB
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
$base_dir = dirname(__FILE__);
# Load main config file.
require_once $base_dir . "/conf_default.php";
# Include user-defined overrides if they exist.
if( file_exists( $base_dir . "/conf.php" ) ) {
include_once $base_dir . "/conf.php";
}
if ( isset($conf['prerender_server_url']) || isset($conf['harrr_server_url']) ||isset($conf['harpoon_server_url']) ) {
$waterfall_output = true;
}
if ( $conf['pingmtr_enabled'] and is_executable($conf['ping_bin']) and is_executable($conf['ping_bin']) ) {
$pingmtr_enabled = true;
} else {
$pingmtr_enabled = false;
}
if ( is_executable($conf['nmap_bin']) ) {
$tlsciphers_enabled = true;
} else {
$tlsciphers_enabled = false;
}
# Include user-defined function if they exist.
if( file_exists( $base_dir . "/override_functions.php" ) ) {
include_once $base_dir . "/override_functions.php";
}
// Let's make sure there is http at the front of a URL
function validate_url($url) {
$validated_url = filter_var($url, FILTER_VALIDATE_URL);
# Do another validation by verifying that http/https are specified since URL with junky schemes can be validated
if ( $validated_url ) {
$parsed_url = parse_url($validated_url);
if ( isset($parsed_url['scheme'] ) ) {
# We only support http and https.
if ( ! ($parsed_url['scheme'] == "http" || $parsed_url['scheme'] == "https" ) )
return FALSE;
} else {
return FALSE;
}
}
return $validated_url;
}
///////////////////////////////////////////////////////////////////////
// JSON pretty print
///////////////////////////////////////////////////////////////////////
function json_prettyprint($json) {
$tab = " ";
$new_json = "";
$indent_level = 0;
$in_string = false;
$len = strlen($json);
for($c = 0; $c < $len; $c++) {
$char = $json[$c];
switch($char) {
case '{':
case '[':
if(!$in_string) {
$new_json .= $char . "\n" . str_repeat($tab, $indent_level+1);
$indent_level++;
} else {
$new_json .= $char;
}
break;
case '}':
case ']':
if(!$in_string) {
$indent_level--;
$new_json .= "\n" . str_repeat($tab, $indent_level) . $char;
} else {
$new_json .= $char;
}
break;
case ',':
if(!$in_string) {
$new_json .= ",\n" . str_repeat($tab, $indent_level);
} else {
$new_json .= $char;
}
break;
case ':':
if(!$in_string) {
$new_json .= ": ";
} else {
$new_json .= $char;
}
break;
case '"':
if($c > 0 && $json[$c-1] != '\\') {
$in_string = !$in_string;
}
default:
$new_json .= $char;
break;
}
}
return $new_json;
}
//////////////////////////////////////////////////////////////////////////////
// Return Country HTML Emoji
//////////////////////////////////////////////////////////////////////////////
function getCountryFlag($countryCode) {
// Convert to uppercase and validate
$countryCode = strtoupper((string)$countryCode);
// Check if it's a valid 2-letter code
if (strlen($countryCode) !== 2 || !ctype_alpha($countryCode)) {
return '';
}
// Convert each letter to its regional indicator symbol
$firstLetter = mb_chr(127462 + ord($countryCode[0]) - ord('A'));
$secondLetter = mb_chr(127462 + ord($countryCode[1]) - ord('A'));
return $firstLetter . $secondLetter;
}
//////////////////////////////////////////////////////////////////////////////
// Small formatting helpers used by the waterfall
//////////////////////////////////////////////////////////////////////////////
# Seconds -> "237 ms" or "1.24 s"
function wf_format_seconds($seconds) {
$ms = $seconds * 1000;
if ( $ms < 1000 )
return round($ms) . " ms";
return sprintf("%.2f s", $seconds);
}
# Milliseconds -> short axis label "500ms" / "1.5s"
function wf_format_tick($ms) {
if ( $ms < 1000 )
return $ms . "ms";
return rtrim(rtrim(sprintf("%.2f", $ms / 1000), "0"), ".") . "s";
}
# Bytes -> "263.7 kB"
function wf_format_bytes($bytes) {
if ( $bytes < 1024 )
return number_format($bytes) . " B";
if ( $bytes < 1024 * 1024 )
return sprintf("%.1f kB", $bytes / 1024);
return sprintf("%.2f MB", $bytes / (1024 * 1024));
}
# Fraction of total time as a CSS percentage
function wf_pct($seconds, $total) {
if ( $total <= 0 || $seconds <= 0 )
return "0";
return sprintf("%.3f", ($seconds / $total) * 100);
}
# Collapse the detailed server string (which carries edge locations) into a provider name
# that can be aggregated on. Falls back to the network owner of the IP, then the AS name.
function wf_provider_name($server, $ip_provider, $as_name) {
$prefixes = array(
"/^Fastly/i" => "Fastly",
"/^CF:/" => "Cloudflare",
"/^CloudFront/i" => "CloudFront",
"/^Akamai/i" => "Akamai",
"/^Stackpath/i" => "StackPath",
"/^CDNetworks/i" => "CDNetworks",
"/^Quantil/i" => "Quantil",
"/^Limelight/i" => "Limelight",
"/^CDN77/i" => "CDN77",
"/^Edgecast/i" => "Edgecast",
"/^Google/i" => "Google",
);
$server = trim($server);
if ( $server != "" ) {
foreach ( $prefixes as $pattern => $name ) {
if ( preg_match($pattern, $server) )
return $name;
}
return $server;
}
if ( $ip_provider != "UNK" )
return $ip_provider;
if ( $as_name != "" )
return $as_name;
return "Unknown";
}
# One row of the provider breakdown: name, then requests and bytes as labelled mini bars
function wf_provider_row($name, $stats, $total_requests, $total_bytes) {
$req_pct = $total_requests > 0 ? $stats['requests'] / $total_requests * 100 : 0;
$byte_pct = $total_bytes > 0 ? $stats['bytes'] / $total_bytes * 100 : 0;
return '<div class="prov-name ellipsis" title="' . htmlentities($name) . '">' . htmlentities($name) . '</div>' .
'<div class="prov-bar"><span class="prov-fill prov-req" style="width:' . sprintf("%.2f", $req_pct) . '%"></span>' .
'<span class="prov-label mono">' . $stats['requests'] . ' <small>(' . round($req_pct) . '%)</small></span></div>' .
'<div class="prov-bar"><span class="prov-fill prov-bytes" style="width:' . sprintf("%.2f", $byte_pct) . '%"></span>' .
'<span class="prov-label mono">' . wf_format_bytes($stats['bytes']) . ' <small>(' . round($byte_pct) . '%)</small></span></div>';
}
# A single timing bar segment (only emitted when it has a duration)
function wf_segment($class, $label, $seconds, $total) {
if ( $seconds <= 0 )
return "";
return '<span class="seg seg-' . $class . '" title="' . $label . ': ' . wf_format_seconds($seconds) . '" style="width:' . wf_pct($seconds, $total) . '%"></span>';
}
//////////////////////////////////////////////////////////////////////////////
// Generate waterfall chart from HAR (HTTP Archive file)
//////////////////////////////////////////////////////////////////////////////
function generate_waterfall($har) {
global $conf;
# This variable will keep the start time of the whole request chain.
$min_start_time = 10000000000;
# Read the cache file
if( isset($conf['cache_file']) && is_readable($conf['cache_file']) && filesize($conf['cache_file']) > 20 ) {
$cache_age = time() - filemtime($conf['cache_file']);
if ( $cache_age < $conf['cache_time'] )
$ip_to_as_cache = json_decode(file_get_contents($conf['cache_file']), TRUE);
} else {
$ip_to_as_cache = array();
}
# When did the page load finish
$max_end_time = 0;
if ( !isset($har['log']['entries']) ) {
print "Couldn't retrieve the HTTP Archive";
exit;
}
foreach ( $har['log']['entries'] as $key => $request ) {
$started_time = $request['startedDateTime'];
$request_duration = $request['time'] / 1000;
$url = $request['request']['url'];
$resp_code = intval($request['response']['status']);
# Uncompressed body size, used for the "should this be compressed" heuristic
$resp_size = isset($request['response']['content']['size']) ? floatval($request['response']['content']['size']) : 0;
# Bytes actually sent over the wire: Chrome's _transferSize if present, otherwise the HAR
# bodySize (compressed body) plus headersSize. HAR uses -1 for unknown values.
$resp = $request['response'];
if ( isset($resp['_transferSize']) && $resp['_transferSize'] >= 0 ) {
$wire_size = floatval($resp['_transferSize']);
} else if ( (isset($resp['bodySize']) && $resp['bodySize'] >= 0) || (isset($resp['headersSize']) && $resp['headersSize'] >= 0) ) {
$wire_size = (isset($resp['bodySize']) && $resp['bodySize'] >= 0 ? floatval($resp['bodySize']) : 0)
+ (isset($resp['headersSize']) && $resp['headersSize'] >= 0 ? floatval($resp['headersSize']) : 0);
} else {
$wire_size = max(0, $resp_size);
}
// Extract the fractional seconds since strtotime drops them. Works for both
// "...T20:18:44.286Z" and "...T20:18:44.286-04:00" style timestamps.
$fraction = 0;
if ( preg_match("/T\d{2}:\d{2}:\d{2}\.(\d+)/", $started_time, $out) ) {
$fraction = floatval("0." . $out[1]);
}
$start_time = strtotime($started_time) + $fraction;
$end_time = $start_time + $request_duration;
# Trying to find the start time of the first request
if ( $start_time < $min_start_time )
$min_start_time = $start_time;
# Find out when the last request ended
if ( $end_time > $max_end_time )
$max_end_time = $end_time;
$resp_headers = array();
$req_headers = array();
foreach ( $request['request']['headers'] as $index => $header ) {
$req_headers[$header['name']] = $header['value'];
}
foreach ( $request['response']['headers'] as $index => $header ) {
$header_name = strtolower($header['name']);
$resp_headers[$header_name] = $header['value'];
}
ksort($resp_headers);
if ( isset($request['serverIPAddress']) ) {
$server_ip = $request['serverIPAddress'];
} else {
$server_ip = false;
}
# HAR uses -1 for timings that don't apply, so clamp everything at zero
$t = isset($request['timings']) ? $request['timings'] : array();
$timing = function($name) use ($t) { return isset($t[$name]) && $t[$name] > 0 ? $t[$name] / 1000 : 0; };
# Per HAR spec the "connect" phase includes "ssl", so show TLS separately
$connect_only = max(0, $timing('connect') - $timing('ssl'));
$requests[] = array(
"url" => $url,
"start_time" => $start_time,
"blocked_time" => $timing('blocked'),
"dns_time" => $timing('dns'),
"connect_time" => $connect_only,
"ssl_time" => $timing('ssl'),
"wait_time" => $timing('send') + $timing('wait'),
"download_time" => $timing('receive'),
"duration" => $request_duration,
"size" => max(0, $resp_size),
"wire_size" => $wire_size,
"resp_code" => intval($resp_code),
"http_version" => $request['response']['httpVersion'],
"server_ip" => $server_ip,
"req_headers" => $req_headers,
"resp_headers" => $resp_headers
);
unset($req_headers, $resp_headers);
}
// If min_start_time is unchanged from original there was an error and
// HAR file was invalid.
if ( $min_start_time == 10000000000 ) {
print "<h1>Error</h1><p><PRE>";
print_r($har);
exit(1);
}
# Total time to fetch the page and all resources
$total_time = $max_end_time - $min_start_time;
$content_breakdown = array( "html" => 0, "images" => 0, "js" => 0, "json" => 0, "css" => 0, "fonts" => 0, "other" => 0);
$websockets_anchors = array();
$total_bytes = 0;
$request_count = count($requests);
$provider_stats = array();
# Pick a tick interval for the timeline grid so that we get roughly 6-10 gridlines
$total_ms = $total_time * 1000;
$tick_candidates = array(10, 20, 50, 100, 200, 250, 500, 1000, 2000, 5000, 10000, 20000, 30000, 60000);
$tick_ms = end($tick_candidates);
foreach ( $tick_candidates as $candidate ) {
if ( $candidate > $total_ms / 8 ) {
$tick_ms = $candidate;
break;
}
}
$tick_pct = $total_ms > 0 ? ($tick_ms / $total_ms) * 100 : 100;
$tick_labels = '<span class="wf-tick wf-tick-first">0</span>';
for ( $t = $tick_ms; $t < $total_ms * 0.97; $t += $tick_ms ) {
$tick_labels .= '<span class="wf-tick" style="left:' . sprintf("%.3f", ($t / $total_ms) * 100) . '%">' . wf_format_tick($t) . '</span>';
}
# The --wf-tick variable drives the CSS gridlines behind every bar so they line up with the labels
$haroutput = '<table class="harview" style="--wf-tick: ' . sprintf("%.4f", $tick_pct) . '%">
<colgroup>
<col class="col-num"><col class="col-url"><col class="col-ip"><col class="col-server">
<col class="col-hit"><col class="col-status"><col class="col-dur"><col class="col-size"><col class="col-timeline">
</colgroup>
<thead>
<tr>
<th class="num">#</th>
<th>URL</th>
<th>IP</th>
<th>Server</th>
<th>Cache</th>
<th>Status</th>
<th class="num">Time</th>
<th class="num">Size</th>
<th class="timeline"><div class="wf-ticks">' . $tick_labels . '</div></th>
</tr>
</thead>
<tbody>';
foreach ( $requests as $index => $request ) {
$time_offset = $request["start_time"] - $min_start_time;
$total_bytes += $request["wire_size"];
# Colour rows/pills by response class
$status_class = "status-" . intval($request["resp_code"] / 100) . "xx";
if ( $request["resp_code"] == 101 )
$status_class = "status-ws";
$haroutput .= "\n<tr class='wf-row response_" . $request["resp_code"] . " " . $status_class . "' data-url=\"" . htmlentities($request["url"]) . "\">";
if ( $request["resp_code"] == 101 ) {
$haroutput .= "<td class=\"num\" id=\"ws" . $index . "\">" . $index . "</td>";
$websockets_anchors[] = "ws" . $index;
} else {
$haroutput .= "<td class=\"num\">" . $index . "</td>";
}
# URL: hostname muted, path emphasised, the full URL available as tooltip. CSS handles truncation.
$parsed_url = parse_url($request["url"]);
$url_host = isset($parsed_url['host']) ? $parsed_url['host'] : "";
$url_path = (isset($parsed_url['path']) ? $parsed_url['path'] : "/") . (isset($parsed_url['query']) ? "?" . $parsed_url['query'] : "");
$url_html = htmlentities($request["url"]);
$haroutput .= '<td><div class="url-cell">' .
'<button class="hdr-toggle" title="Toggle response headers" onClick="$(\'#item_' . $index . '\').toggle(); $(this).toggleClass(\'open\'); return false"></button>' .
'<a class="url-link" href="' . $url_html . '" title="' . $url_html . '" target="_blank" rel="noopener">' .
'<span class="url-host">' . htmlentities($url_host) . '</span><span class="url-path">' . htmlentities($url_path) . '</span></a>' .
'<span class="url-badges">';
$content_type_full = isset($request['resp_headers']['content-type']) ? $request['resp_headers']['content-type'] : "Unknown";
$content_encoding = isset($request['resp_headers']['content-encoding']) ? $request['resp_headers']['content-encoding'] : false;
$content_type = false;
# Build the collapsible detail row: timing breakdown plus response headers
$details = '<tr class="http_headers wf-details" id="item_' . $index . '" style="display: none;"><td colspan="9">' .
'<div class="wf-timing">' .
'<span class="chip"><i class="sw seg-blocked"></i>Blocked <b>' . wf_format_seconds($request["blocked_time"]) . '</b></span>' .
'<span class="chip"><i class="sw seg-dns"></i>DNS <b>' . wf_format_seconds($request["dns_time"]) . '</b></span>' .
'<span class="chip"><i class="sw seg-connect"></i>Connect <b>' . wf_format_seconds($request["connect_time"]) . '</b></span>' .
'<span class="chip"><i class="sw seg-tls"></i>TLS <b>' . wf_format_seconds($request["ssl_time"]) . '</b></span>' .
'<span class="chip"><i class="sw seg-wait"></i>Wait (TTFB) <b>' . wf_format_seconds($request["wait_time"]) . '</b></span>' .
'<span class="chip"><i class="sw seg-download"></i>Download <b>' . wf_format_seconds($request["download_time"]) . '</b></span>' .
'</div><div class="hdr-grid">';
foreach ( $request['resp_headers'] as $header_name => $header_value ) {
$details .= '<div class="hdr-name">' . htmlentities($header_name) . '</div><div class="hdr-value">' . htmlentities((string)$header_value) . '</div>';
}
$details .= '</div></td></tr>';
# If response is HTTP/2 or HTTP/3 put a nice badge to identify it
if ( preg_match("/(h|http)\/?([2-3])/i", $request['http_version'], $out) )
$haroutput .= '<span title="HTTP/' . $out[2] . '" class="pill http' . $out[2] . '">H' . $out[2] . '</span>';
$compressable = false;
if ( preg_match("/text\/html/i", $content_type_full ) ) {
$content_type = "HTML";
$compressable = true;
$content_breakdown["html"] += $request["wire_size"];
} else if ( preg_match("/text\/css/i", $content_type_full ) ){
$content_type = "CSS";
$compressable = true;
$content_breakdown["css"] += $request["wire_size"];
} else if ( preg_match("/javascript|text\/js/i", $content_type_full ) ){
$content_type = "JS";
$compressable = true;
$content_breakdown["js"] += $request["wire_size"];
} else if ( preg_match("/image\/(gif|png|jpeg|avif|webp)/i", $content_type_full, $out ) ) {
$content_type = strtoupper($out[1]);
$content_breakdown["images"] += $request["wire_size"];
unset($out);
} else if ( preg_match("/json/i", $content_type_full ) ) {
$content_type = "JSON";
$content_breakdown["json"] += $request["wire_size"];
$compressable = true;
} else if ( preg_match("/svg/i", $content_type_full ) ) {
$content_type = "SVG";
$content_breakdown["images"] += $request["wire_size"];
$compressable = true;
# WOFF is already compressed https://developers.googleblog.com/2015/02/smaller-fonts-with-woff-20-and-unicode.html
} else if ( preg_match("/woff/i", $content_type_full ) ){
$content_type = "FONT";
$content_breakdown["fonts"] += $request["wire_size"];
} else if ( preg_match("/font/i", $content_type_full ) ){
$content_type = "FONT";
$content_breakdown["fonts"] += $request["wire_size"];
$compressable = true;
} else if ( preg_match("/text\/plain/i", $content_type_full ) ){
$content_type = "TXT";
$compressable = true;
} else if ( preg_match("/octet/i", $content_type_full ) ){
$content_type = "BIN";
} else if ( preg_match("/xml/i", $content_type_full ) ){
$content_type = "XML";
$compressable = true;
} else {
$content_type = "";
$content_breakdown["other"] += $request["wire_size"];
}
$addl = "";
# Check if content type is compressable and only on 2k+ files
if ( $request["size"] > 2048 && $compressable ) {
if ( $content_encoding ) {
$compressed = "yes";
$addl = "title=\"Compressed\"";
} else {
$compressed = "no";
$addl = "title=\"Not compressed however should be compressable\"";
}
} else {
if ( $content_encoding ) {
$compressed = "yes";
$addl = "title=\"Compressed\"";
} else {
$compressed = "none";
$addl = "title=\"Not compressable\"";
}
}
if ( $content_type != "" )
$haroutput .= "<span $addl class=\"pill type compressed_" . $compressed ."\">". $content_type . "</span>";
###############################################################################################################
# Let's check for questionable practices
$questionable_practice = array();
# Let's check for questionable practices
if ( isset($request['resp_headers']['vary']) ) {
if ( preg_match("/User-Agent/i", $request['resp_headers']['vary'] ) ) {
$questionable_practice[] = "User-Agent used in Vary";
}
if ( preg_match("/Cookie/i", $request['resp_headers']['vary'] ) ) {
$questionable_practice[] = "Cookie used in Vary";
}
}
if ( sizeof($questionable_practice) > 0 ) {
$haroutput .= "<img class=\"badge-icon\" title=\"" . htmlentities(join(", ", $questionable_practice)) . "\" src=\"img/attention.svg\">";
}
unset($questionable_practice);
###############################################################################################################
# Identify requests that Set Cookies
if ( isset($request['resp_headers']['set-cookie']) ) {
$haroutput .= "<img class=\"badge-icon\" title=\"Sets a cookie\" src=\"img/cookie.png\">";
}
$haroutput .= "</span></div></td>";
################################################################################################################
############################################# Server IP ########################################################
################################################################################################################
# Let's determine the AS number and details
$frontend_ip_provider = "UNK";
$as_title = "";
if ($request['server_ip']) {
$ip_parts = explode(".", $request['server_ip']);
array_pop($ip_parts);
$ip_prefix = join(".", $ip_parts);
if ( !isset($ip_to_as_cache[$ip_prefix]) ) {
$ip_details = ip_to_as_info($request['server_ip']);
$ip_to_as_cache[$ip_prefix] = $ip_details;
}
# Instead of showing text for some of the most common AS let's use an image
if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS16509" || $ip_to_as_cache[$ip_prefix]["as_number"] == "AS14618" ) {
$img_or_as_name = '<img src="img/aws.svg" class="vendor_img">';
$frontend_ip_provider = "AWS";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS15169" ) {
$img_or_as_name = '<img src="img/google.svg" class="vendor_img">';
$frontend_ip_provider = "Google";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS20940" || $ip_to_as_cache[$ip_prefix]["as_number"] == "AS16625" ) {
$img_or_as_name = '<img src="img/akamai.svg" class="vendor_img">';
$frontend_ip_provider = "Akamai";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS54113" ) {
$img_or_as_name = '<img src="img/fastly.svg" class="vendor_img">';
$frontend_ip_provider = "Fastly";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS8068" ) {
$img_or_as_name = '<img src="img/microsoft.svg" class="vendor_img">';
$frontend_ip_provider = "Microsoft";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS8075" ) {
$img_or_as_name = '<img src="img/azure.svg" class="vendor_img">';
$frontend_ip_provider = "Azure";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS32934" ) {
$img_or_as_name = '<img src="img/facebook.svg" class="vendor_img">';
$frontend_ip_provider = "Facebook";
} else if ( in_array($ip_to_as_cache[$ip_prefix]["as_number"], array("AS13335", "AS209242", "AS139242" ) ) ) {
$img_or_as_name = '<img src="img/cloudflare.svg" class="vendor_img">';
if ( in_array($ip_to_as_cache[$ip_prefix]["as_number"], array("AS209242", "AS139242" ) ) )
$img_or_as_name .= " <b>BYOIP</b>";
$frontend_ip_provider = "Cloudflare";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS396982" ) {
$img_or_as_name = '<img src="img/gcp.svg" class="vendor_img">';
$frontend_ip_provider = "GCP";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS15133" ) {
$img_or_as_name = '<img src="img/edgecast.svg" class="vendor_img">';
$frontend_ip_provider = "Edgecast";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS135340" || $ip_to_as_cache[$ip_prefix]["as_number"] == "AS133165" || $ip_to_as_cache[$ip_prefix]["as_number"] == "AS14061" ) {
$img_or_as_name = '<img src="img/digitalocean.png" class="vendor_img">';
$frontend_ip_provider = "Digital Ocean";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS20446" ) {
$img_or_as_name = '<img src="img/stackpath.svg" class="vendor_img" title="StackPath">';
$frontend_ip_provider = "Stackpath";
} else if ( $ip_to_as_cache[$ip_prefix]["as_number"] == "AS19551" ) {
$img_or_as_name = '<img src="img/incapsula.png" class="vendor_img">';
$frontend_ip_provider = "Incapsula";
} else {
$img_or_as_name = $ip_to_as_cache[$ip_prefix]["as_name"];
}
$as_country = isset($ip_to_as_cache[$ip_prefix]["as_country"]) ? $ip_to_as_cache[$ip_prefix]["as_country"] : "";
$as_title = isset($ip_to_as_cache[$ip_prefix]["as_name"]) ? $ip_to_as_cache[$ip_prefix]["as_name"] : "";
# Long AS names get truncated by CSS; the full name stays in the tooltip
$haroutput .= '<td><div class="ip-cell" title="' . htmlentities($as_title) . '">' .
'<span class="ip-vendor">' . $img_or_as_name . '</span>' .
'<span class="ip-flag">' . getCountryFlag($as_country) . '</span>' .
'<span class="ip-addr mono">' . htmlentities($request['server_ip']) . '</span></div></td>';
} else {
$haroutput .= "<td></td>";
}
################################################################################################################
############################################# Identify CDN #####################################################
################################################################################################################
$server = "";
$hit_or_miss = "UNK";
$hit_or_miss_css = "UNK";
# Let's try to identify some CDNs. This is Fastly
if ( isset($request['resp_headers']['server']) && preg_match("/^imgix/i", $request['resp_headers']['server']) ) {
$server = "ImgIX";
} else if ( isset($request['resp_headers']['x-served-by']) && preg_match("/^cache-/", $request['resp_headers']['x-served-by']) ) {
$server = "Fastly " . str_replace("cache-", "", $request['resp_headers']['x-served-by']);
# Check if Server header provided. It's used by NetDNA and Edgecast
} else if ( isset($request['resp_headers']['server']) && preg_match("/^EC[A-Z]/", $request['resp_headers']['server']) ) {
$server = trim(preg_replace("/^EC[A-Z]/", "Edgecast", $request['resp_headers']['server']));
} else if ( isset($request['resp_headers']['server']) && preg_match("/^NetDNA/i", $request['resp_headers']['server']) ) {
$server = trim($request['resp_headers']['server']);
# CloudFront
}
else if ( isset($request['resp_headers']['via']) && preg_match("/CloudFront/i", $request['resp_headers']['via']) ) {
$server = "CloudFront";
if ( isset($request['resp_headers']['x-amz-cf-pop']) ) {
$server .= " " . $request['resp_headers']['x-amz-cf-pop'];
}
# ChinaCache
}
else if ( isset($request['resp_headers']['powered-by-chinacache']) ) {
$server = "ChinaCache";
# Incapsula
}
else if ( isset($request['resp_headers']['x-instart-request-id']) ) {
$server = "Instart";
}
else if ( isset($request['resp_headers']['quant-server']) ) {
$server = "QuantCDN";
}
else if ( isset($request['resp_headers']['section-io-id']) ) {
$server = "Section.io";
if ( isset($request['resp_headers']['section-io-cache'])) {
$hit_or_miss_css = $request['resp_headers']['section-io-cache'];
$hit_or_miss = $request['resp_headers']['section-io-cache'];
}
}
else if ( isset($request['resp_headers']['x-cdn']) and $request['resp_headers']['x-cdn'] == "Incapsula" ) {
$server = "Incapsula";
}
else if ( isset($request['resp_headers']['server']) && preg_match("/^Footprint Distributor/i", $request['resp_headers']['server']) ) {
$server = "Level3";
}
else if ( isset($request['resp_headers']['server']) && preg_match("/^Windows-Azure-Blob/i", $request['resp_headers']['server']) ) {
$server = "Azure Blob Storage";
}
else if ( isset($request['resp_headers']['x-yottaa-optimizations']) or isset($request['resp_headers']['x-yottaa-metrics']) ) {
$server = "Yottaa";
}
# CD Networks
else if ( isset($request['resp_headers']['x-px']) ) {
if ( preg_match("/.*\.(.*)\.cdngp.net/i", $request['resp_headers']['x-px'], $out )) {
$edge_location = " " .$out[1];
} else {
$edge_location = "";
}
$server = "CDNetworks" . $edge_location;
}
# Cloudflare
else if ( isset($request['resp_headers']['cf-ray']) ) {
$server = "CF: " . preg_replace('/^(.*)-/', '', $request['resp_headers']['cf-ray']);
if ( isset($request['resp_headers']['cf-cache-status'])) {
$hit_or_miss_css = $request['resp_headers']['cf-cache-status'];
$hit_or_miss = $request['resp_headers']['cf-cache-status'];
}
}
# Highwinds
else if ( isset($request['resp_headers']['x-hw']) ) {
$server = substr("Stackpath " . preg_replace("/\d+\.(.*),\d+\.(.*)/", "$1, $2", $request['resp_headers']['x-hw']), 0, 16);
}
# Match Akamai headers
else if ( isset($request['resp_headers']['x-cache']) && preg_match("/(\w+) from.*akamai/i", $request['resp_headers']['x-cache'], $out) ) {
$server = "Akamai";
$hit_or_miss = $out[1];
} else if ( isset($request['resp_headers']['server']) && preg_match("/^Akamai/i", $request['resp_headers']['server']) ) {
$server = $request['resp_headers']['server'];
} else if ( isset($request['resp_headers']['server']) && preg_match("/^CDNNet/i", $request['resp_headers']['server']) ) {
$server = "CDN.Net";
} else if ( isset($request['resp_headers']['server']) && preg_match("/keycdn/i", $request['resp_headers']['server']) ) {
$server = "KeyCDN";
} else if ( isset($request['resp_headers']['server']) && preg_match("/vercel/i", $request['resp_headers']['server']) ) {
$server = "Vercel";
} else if ( isset($request['resp_headers']['server']) && preg_match("/netlify/i", $request['resp_headers']['server']) ) {
$server = "Netlify";
} else if ( (isset($request['resp_headers']['server']) && preg_match("/envoy/i", $request['resp_headers']['server'])) || isset($request['resp_headers']['x-envoy-upstream-service-time']) ) {
$server = "Istio Envoy";
# Not exhaustive way to identify Google
} else if ( preg_match("/(youtube|gstatic|doubleclick|google).*\.(com|net)\//i", $request["url"]) ) {
$server = "Google";
# Not exhaustive way to identify Facebook
} else if ( preg_match("/(facebook|fbcdn).*\.(com|net)\//i", $request["url"]) ) {
$server = "Facebook";
} else if ( preg_match("/s3.*amazonaws/i", $request["url"]) ) {
$server = "AWS S3";
} else if ( isset($request['resp_headers']['set-cookie']) && preg_match("/AWS(A|E)LB/i", $request['resp_headers']['set-cookie'], $out ) ) {
$server = "AWS " . $out[1] . "LB";
} else if ( preg_match("/bing\.com\//i", $request["url"]) ) {
$server = "MS Bing";
} else if ( preg_match("/(yahoo|ytimg)\.com\//i", $request["url"]) ) {
$server = "Yahoo";
} else if ( isset($request['resp_headers']['server']) && $request['resp_headers']['server'] == "UploadServer" && isset($request['resp_headers']['x-goog-storage-class']) ) {
$server = "Google Storage";
} else if ( isset($request['resp_headers']['server']) && $request['resp_headers']['server'] == "Azion IMS" ) {
$server = "AzionCDN";
} else if ( isset($request['resp_headers']['server']) && preg_match("/^NWS/i" , $request['resp_headers']['server'] ) ) {
$server = "Tencent";
} else if ( isset($request['resp_headers']['server']) && preg_match("/leasewebcdn/i" , $request['resp_headers']['server'] ) ) {
$server = "LeaseWeb CDN";
} else if ( isset($request['resp_headers']['server']) && preg_match("/bunnycdn/i" , $request['resp_headers']['server'] ) ) {
$server = "BunnyCDN";
} else if ( isset($request['resp_headers']['server']) && $request['resp_headers']['server'] == "DOSarrest" ) {
$server = "DOSarrest";
} else if ( isset($request['resp_headers']['server']) && preg_match("/keycdn/i", $request['resp_headers']['server']) ) {
if ( isset($request['resp_headers']['x-edge-location']) ) {
$edge_location = " " .$request['resp_headers']['x-edge-location'];
} else {
$edge_location = "";
}
} else if ( isset($request['resp_headers']['x-via']) && preg_match("/1\.1 (.*) \(Cdn Cache Server/i", $request['resp_headers']['x-via'], $out ) ) {
$server = "Quantil " . $out[1];
} else if ( isset($request['resp_headers']['via']) && preg_match("/1\.1 (.*)squid/i", $request['resp_headers']['via'], $out ) ) {
$server = "Squid";
} else if ( isset($request['resp_headers']['server']) && preg_match("/myracloud/i", $request['resp_headers']['server'] )) {
$server = "MyraCloud";
} else if ( isset($request['resp_headers']['server']) && $request['resp_headers']['server'] == "EdgePrismSSL" ) {
if ( isset($request['resp_headers']['x-server-name']) )
$cache_node = $request['resp_headers']['x-server-name'];
else
$cache_node = "";
$server = "Limelight " . $cache_node;
} else if ( isset($request['resp_headers']['x-distil-cs']) ) {
$server = "Distil";
$hit_or_miss = $request['resp_headers']['x-distil-cs'];
} else if ( isset($request['resp_headers']['server']) && $request['resp_headers']['server'] == "CDN77-Turbo" ) {
$edge_location = isset($request['resp_headers']['x-edge-location']) ? " " . htmlentities($request['resp_headers']['x-edge-location']) : "";
$server = "CDN77" . $edge_location;
} else if ( isset($request['resp_headers']['x-li-pop']) ) {
$server = "LinkedIn";
} else if ( preg_match("/^wss:\/\//", $request["url"]) ) {
$server = "WebSockets";
}
$cms = array();
##############################################################################################
# Figure out if a specific CMS or backend storage is being used
if ( isset($request['resp_headers']['x-ah-environment']) ) {
$cms[] = "Acquia";
} else if ( isset($request['resp_headers']['x-vtex-cache-status']) ) {
$cms[] = "VTEX";
} else if ( isset($request['resp_headers']['x-drupal-cache']) ) {
$cms[] = "Drupal";
} else if ( isset($request['resp_headers']['x-amz-apigw-id']) ) {
$cms[] = "AWS API GW";
} else if ( isset($request['resp_headers']['x-shopid']) || preg_match("/shopify/", $request["url"]) ) {
$cms[] = "Shopify";
} else if ( isset($request['resp_headers']['server']) && preg_match("/Contentful/i", $request['resp_headers']['server'] ) ) {
$cms[] = "Contentful";
} else if ( isset($request['resp_headers']['x-varnish']) || isset($request['resp_headers']['via']) && preg_match("/varnish/i", $request['resp_headers']['via']) ) {
if ( !preg_match("/fastly/i", $server) )
$cms[] = "Varnish";
# Magento version 1
} else if ( isset($request['resp_headers']['wp-super-cache']) || isset($request['resp_headers']['x-pingback']) || preg_match("/\/wp-content\//i", $request["url"] )
|| (isset($request['resp_headers']['link']) && preg_match("/wp-json|wp\.me/i", $request['resp_headers']['link']))) {
$cms[] = "Wordpress";
} else if ( isset($request['resp_headers']['set-cookie']) && preg_match("/frontend=/i", $request['resp_headers']['set-cookie'] ) ) {
$cms[] = "Magento1";
} else if ( isset($request['resp_headers']['server']) && preg_match("/squarespace/i", $request['resp_headers']['server'] ) ) {
$cms[] = "Squarespace";
} else if ( preg_match("/\/wcsstore\//i", $request["url"] ) || (isset($request['resp_headers']['server']) && preg_match("/websphere/i", $request['resp_headers']['server'] ) ) ) {
$cms[] = "WebSphere";
} else if ( isset($request['resp_headers']['set-cookie']) && preg_match("/Demandware/i", $request['resp_headers']['set-cookie'] ) ) {
$cms[] = "Demandware";
# Let's see if the request was in some form or shape backed by S3 ie. it was served by a CDN but storage was actually
# S3. Append only if server was determined not to be AWS S3 since we don't need double output
} else if ( ( isset($request['resp_headers']['x-amz-id-2']) || isset($request['resp_headers']['x-amz-request-id']) || (isset($request['resp_headers']['server']) && $request['resp_headers']['server'] == "AmazonS3") ) && $server != "AWS S3" ) {
$cms[] = "S3";
} else if ( ( isset($request['resp_headers']['akamai-grn']) && $frontend_ip_provider != "Akamai" ) ) {
$cms[] = "AKAM bcknd";
# Same with Google Cloud Storage (GCS)
} else if ( isset($request['resp_headers']['server']) && preg_match("/cloudinary/i", $request['resp_headers']['server']) ) {
$cms[] = "Cloudinary";
} else if ( isset($request['resp_headers']['x-goog-generation']) && $server != "Google Storage" ) {
$cms[] = "GCS";
} else if ( isset($request['resp_headers']['x-ms-blob-type']) ) {
$cms[] = "Azure BlobStorage";
} else if ( (isset($request['resp_headers']['server']) && $request['resp_headers']['server'] == "Cowboy") || (isset($request['resp_headers']['via']) && preg_match("/vegur/i", $request['resp_headers']['via']) )) {
$cms[] = "Heroku";
# Yottaa may be using other CDNs for their static delivery
} else if ( isset($request['resp_headers']['x-yottaa-optimizations']) and $server != "Yottaa" ) {
$cms[] = "Yottaa";
}
if ( isset($request['resp_headers']['set-cookie']) && preg_match("/BIGipServer|MRHSession/i", $request['resp_headers']['set-cookie'] ) ) {
$cms[] = "F5 BIGIP";
} else if ( isset($request['resp_headers']['set-cookie']) && preg_match("/NSC_Qspe/i", $request['resp_headers']['set-cookie'] ) ) {
$cms[] = "NetScaler";
}
# Bot Challenge or WAF
if ( isset($request['resp_headers']['cf-mitigated']) ) {
$cms[] = "Bot Challenge";
} else if ( preg_match("/_Incapsula_Resource/", $request['url'] ) ) {
$cms[] = "Bot Challenge";
} else if ( isset($request['resp_headers']['x-amzn-waf-challenge-id'] ) || isset($request['resp_headers']['x-amzn-waf-action']) ) {
$cms[] = "AWS WAF";
} else if ( preg_match("/sdk\.awswaf\.com/i", $request['url'] ) ) {
$cms[] = "AWS WAF";
}
if ( preg_match("/px\-(cdn|translator|cloud|client)|perimeterx/", $request['url'] ) ) {
$cms[] = "Human/PX";
}
if ( preg_match("/hyva/i", $request['url'] ) ) {
$cms[] = "Hyva";
}
if ( preg_match("/datadome\.co/", $request['url'] ) || ( isset($request['resp_headers']['set-cookie']) && preg_match("/datadome=/i", $request['resp_headers']['set-cookie'] ) ) ) {
$cms[] = "Datadome";
}
if ( isset($request['resp_headers']['set-cookie']) && preg_match("/bm_sv=/i", $request['resp_headers']['set-cookie'] ) ) {
$cms[] = "Akamai Botman";
}
if ( isset($request['resp_headers']['x-yext-site']) ) {
$cms[] = "Yext";
}
if ( isset($request['resp_headers']['via']) && preg_match("/google$/i", $request['resp_headers']['via']) ) {
$cms[] = "Google Cloud";
}
if ( preg_match("/\/_next\//i", $request["url"] ) ) {
$cms[] = "Next.js";
}
if ( isset($request['resp_headers']['x-dw-request-base-id']) || preg_match("/on\/demandware/i", $request['url']) ) {
$cms[] = "Salesforce Commerce";
}
if ( isset($request['resp_headers']['x-akamai-transformed']) ||
( isset($request['resp_headers']['server-timing']) && preg_match("/^ak_/i", $request['resp_headers']['server-timing']) ) ) {
$cms[] = "Akamai FEO";
}
if ( isset($request['resp_headers']['x-cache']) && preg_match("/function|LambdaGeneratedResponse/i", $request['resp_headers']['x-cache'] ) ) {
$cms[] = "Lambda@Edge";
$request['resp_headers']['x-cache'] = "Lambda";
}
# It's a tracking pixel or it's an ad
if ( ( isset($request['resp_headers']['content-type']) && preg_match("/image\/gif/i", $request['resp_headers']['content-type']) )
&& intval($request['resp_headers']['content-length']) < 50 ) {
$cms[] = "Tracking pixel";
} else if ( preg_match("/googleads|pagead/", $request['url'] ) ) {
$cms[] = "Ads";
# Or is it a font
} else if ( preg_match("/fonts\.googleapis\.com/", $request['url'] ) ) {
$cms[] = "Fonts";
} else if ( preg_match("/www\.googletagmanager\.com/", $request['url'] ) ) {
$cms[] = "Tag Manager";
} else if ( preg_match("/(gstatic|google)\.com\/recaptcha/", $request['url'] ) ) {
$cms[] = "Recaptcha";
}
# Aggregate requests and bytes per provider before the CMS details get appended
$provider = wf_provider_name($server, $frontend_ip_provider, $as_title);
if ( !isset($provider_stats[$provider]) )
$provider_stats[$provider] = array("requests" => 0, "bytes" => 0);
$provider_stats[$provider]["requests"]++;
$provider_stats[$provider]["bytes"] += $request["wire_size"];
if ( count($cms) > 0 ) {
$server .= " (" . join(",", $cms) . ")";
}
unset($cms);
if ( $server == "" )
$server = "Unknown";
# Let's see if we can find any Cache headers and can identify whether request was a HIT or a MISS
# We already figured out for Akamai whether it's a hit or miss so skip it there
if ( isset($request['resp_headers']['x-cache']) && $hit_or_miss == "UNK" && $server != "Akamai" ) {
$hit_or_miss = strtoupper(preg_replace("/ from Cloudfront/i", "", $request['resp_headers']['x-cache']));
}
if ( $hit_or_miss != "UNK" ) {
if ( preg_match("/(TCP_HIT|TCP_MEM_HIT|HIT$)/i", $hit_or_miss )) {
$hit_or_miss_css = "HIT";
} else {
$hit_or_miss_css = "MISS";
}
}
if ( $hit_or_miss == "UNK" ) {
$hit_html = '<span class="pill unk" title="No cache status header found">–</span>';
} else {
$hit_html = '<span class="pill ' . strtolower($hit_or_miss_css) . '">' . htmlentities($hit_or_miss) . '</span>';
}
# Position the duration label right after the bar, or before it when the bar ends near the right edge
$bar_start_pct = wf_pct($time_offset, $total_time);
$bar_end_pct = wf_pct($time_offset + $request["duration"], $total_time);
if ( $bar_end_pct > 88 ) {
$label_style = 'right: calc(' . (100 - $bar_start_pct) . '% + 4px)';
} else {
$label_style = 'left: calc(' . $bar_end_pct . '% + 4px)';
}
# The segment wrapper gets the request's share of the timeline; each phase is then a share of the wrapper
$phases_total = $request["blocked_time"] + $request["dns_time"] + $request["connect_time"] + $request["ssl_time"] + $request["wait_time"] + $request["download_time"];
if ( $phases_total <= 0 )
$phases_total = $request["duration"];
$haroutput .= '<td><span class="ellipsis" title="' . htmlentities($server) . '">' . htmlentities($server) . '</span></td>' .
'<td class="x-cache-' . $hit_or_miss_css . '">' . $hit_html . '</td>' .
'<td><span class="pill ' . $status_class . '">' . intval($request["resp_code"]) . '</span></td>' .
'<td class="num mono">' . wf_format_seconds($request["duration"]) . '</td>' .
'<td class="num mono" title="' . number_format($request["wire_size"]) . ' bytes over the wire, ' . number_format($request["size"]) . ' bytes uncompressed">' . wf_format_bytes($request["wire_size"]) . '</td>' .
'<td class="timeline-data"><div class="bar">' .
'<span class="gap" style="width:' . $bar_start_pct . '%"></span><span class="segs" style="width:' . wf_pct($phases_total, $total_time) . '%">' .
wf_segment("blocked", "Blocked / queued", $request["blocked_time"], $phases_total) .
wf_segment("dns", "DNS lookup", $request["dns_time"], $phases_total) .
wf_segment("connect", "TCP connect", $request["connect_time"], $phases_total) .
wf_segment("tls", "TLS handshake", $request["ssl_time"], $phases_total) .
wf_segment("wait", "Waiting for response (TTFB)", $request["wait_time"], $phases_total) .
wf_segment("download", "Content download", $request["download_time"], $phases_total) .
'</span><span class="bar-label mono" style="' . $label_style . '">' . wf_format_seconds($request["duration"]) . '</span>' .
'</div></td></tr>' . $details;
}
unset($requests);
unset($har);
$haroutput .= '</tbody></table>';
###############################################################################################################
# Summary strip: headline stats, content breakdown and legend for the bar colours
$header = '<div class="wf-summary">';
$header .= '<div class="wf-stats">' .
'<div class="stat"><span class="stat-label">Load time</span><span class="stat-value"><span id="total-time">' . sprintf("%.3f", $total_time) . '</span> s</span></div>' .
'<div class="stat"><span class="stat-label">Requests</span><span class="stat-value">' . $request_count . '</span></div>' .
'<div class="stat" title="Bytes sent over the wire (compressed bodies plus headers)"><span class="stat-label">Transferred</span><span class="stat-value">' . wf_format_bytes($total_bytes) . '</span></div>' .
'</div>';
$header .= '<div class="wf-breakdown"><div class="stat-label" title="Bytes sent over the wire per content type">Content breakdown (wire bytes)</div><div class="wf-stack">';
foreach ( $content_breakdown as $type => $bytes ) {
if ( $bytes <= 0 ) continue;
$header .= '<span class="ct-' . $type . '" title="' . strtoupper($type) . ' ' . wf_format_bytes($bytes) . '" style="width:' . wf_pct($bytes, $total_bytes) . '%"></span>';
}
$header .= '</div><div class="wf-chips">';
foreach ( $content_breakdown as $type => $bytes ) {
if ( $bytes <= 0 ) continue;
$header .= '<span class="chip"><i class="sw ct-' . $type . '"></i>' . strtoupper($type) . ' <b>' . wf_format_bytes($bytes) . '</b></span>';
}
$header .= '</div></div>';
$header .= '<div class="wf-legend"><div class="stat-label">Timing</div><div class="wf-chips">' .
'<span class="chip"><i class="sw seg-blocked"></i>Blocked</span>' .
'<span class="chip"><i class="sw seg-dns"></i>DNS</span>' .
'<span class="chip"><i class="sw seg-connect"></i>Connect</span>' .
'<span class="chip"><i class="sw seg-tls"></i>TLS</span>' .
'<span class="chip"><i class="sw seg-wait"></i>Wait (TTFB)</span>' .
'<span class="chip"><i class="sw seg-download"></i>Download</span>' .
'</div>';
# Add links to click to Websocket anchors
if ( count($websockets_anchors) > 0 ) {
$header .= '<div class="wf-chips"><span class="chip"><i class="sw status-ws"></i>WebSockets';
foreach ( $websockets_anchors as $key => $value ) {
$header .= ' <a href="#' . $value . '">#' . ($key + 1) . '</a>';
}
$header .= '</span></div>';
}
$header .= '</div>';
$header .= '<div class="wf-actions"><button class="wf-btn" id="show_all_headers_button" onClick="$(\'.http_headers\').toggle(); $(\'.hdr-toggle\').toggleClass(\'open\'); return false">Toggle all headers</button></div>';
# Requests and bytes per provider, largest by bytes first. Long tails get folded into "Other".
uasort($provider_stats, function($a, $b) {
if ( $a["bytes"] == $b["bytes"] ) return $b["requests"] - $a["requests"];