ajax-inspect.php
3.26 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
<?php
if (!(isset($_POST['url']) && preg_match('|^https?://|', $_POST['url'])))
{
?>
<section class="hh-panel">
<h3><span class="hh-highlight"><?php _e('URL malformed', 'http-headers'); ?></span></h3>
</section>
<?php
exit;
}
include 'includes/config.inc.php';
$args = array();
if (isset($_POST['authentication'], $_POST['username'], $_POST['password'])
&& !empty($_POST['username'])
&& !empty($_POST['password'])
)
{
$args['headers'] = array(
'Authorization' => sprintf('Basic %s', base64_encode($_POST['username'] .':'. $_POST['password']))
);
}
$response = wp_remote_head($_POST['url'], $args);
$status = wp_remote_retrieve_response_code($response);
$dictionary = wp_remote_retrieve_headers($response);
$responseHeaders = $dictionary ? $dictionary->getAll() : array();
if ($status !== 200)
{
?>
<section class="hh-panel">
<h3><span class="hh-highlight"><?php _e('HTTP Status', 'http-headers'); ?>: <?php echo $status; ?></span></h3>
<p><?php
switch ($status)
{
case 400:
echo 'Bad Request';
break;
case 401:
echo 'Unauthorized';
break;
case 403:
echo 'Forbidden';
break;
case 404:
echo 'Not Found';
break;
case 405:
echo 'Method Not Allowed';
break;
default:
}
?></p>
</section>
<?php
exit;
}
?>
<section class="hh-panel">
<h3><span class="hh-highlight"><?php _e('Response headers', 'http-headers'); ?></span></h3>
<table class="hh-results">
<thead>
<tr>
<th style="width: 30%"><?php _e('Header', 'http-headers'); ?></th>
<th><?php _e('Value', 'http-headers'); ?></th>
</tr>
</thead>
<tbody>
<?php
$reportOnly = array('content-security-policy-report-only');
foreach ($responseHeaders as $k => $v)
{
$k = strtolower($k);
$found = in_array($k, $reportOnly);
$v = is_array($v) ? join(", ", $v) : $v;
?>
<tr<?php echo array_key_exists($k, $headers) || $found ? ' class="hh-found"' : NULL; ?>>
<td><?php echo htmlspecialchars($k); ?></td>
<td><?php echo htmlspecialchars($v); ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</section>
<?php
$special = array('content-security-policy');
$exclude = array('custom-headers', 'cookie-security', 'x-powered-by');
$missing = array();
foreach ($headers as $k => $v)
{
if (!array_key_exists($k, $responseHeaders)
&& !in_array($k, $exclude)
&& !(in_array($k, $special) && array_key_exists($k . '-report-only', $responseHeaders) ))
{
$missing[$k] = @$categories[$v[2]];
}
}
if (!empty($missing))
{
asort($missing);
?>
<section class="hh-panel">
<h3><span class="hh-highlight"><?php _e('Missing headers', 'http-headers'); ?></span></h3>
<table class="hh-results">
<thead>
<tr>
<th style="width: 30%"><?php _e('Header', 'http-headers'); ?></th>
<th><?php _e('Category', 'http-headers'); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($missing as $k => $v)
{
?>
<tr>
<td><a href="<?php echo get_admin_url(); ?>options-general.php?page=http-headers&header=<?php echo htmlspecialchars($k); ?>"><?php echo $k; ?></a></td>
<td><?php echo $v; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</section>
<?php
}