PluginProbe
HTTP Headers / trunk
HTTP Headers vtrunk
1.19.5 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.12.0 1.12.1 1.12.2 1.13.0 1.13.1 1.13.2 1.13.3 1.13.4 1.14.0 1.14.1 1.14.2 1.15.0 All 60 releases
http-headers / views / ajax-inspect.php

ajax-inspect.php in HTTP Headers trunk, at views/ajax-inspect.php

136 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 exit;
4 }
5 if (!(isset($_POST['url']) && preg_match('|^https?://|', sanitize_text_field(wp_unslash($_POST['url'])))))
6 {
7 ?>
8 <section class="hh-panel">
9 <h3><span class="hh-highlight"><?php esc_html_e('URL malformed', 'http-headers'); ?></span></h3>
10 </section>
11 <?php
12 exit;
13 }
14
15 include 'includes/config.inc.php';
16
17 $http_headers_args = array();
18
19 if (isset($_POST['authentication'], $_POST['username'], $_POST['password'])
20 && !empty($_POST['username'])
21 && !empty($_POST['password'])
22 )
23 {
24 $http_headers_args['headers'] = array(
25 'Authorization' => sprintf('Basic %s', base64_encode(sanitize_text_field(wp_unslash($_POST['username'])) .':'. sanitize_text_field(wp_unslash($_POST['password']))))
26 );
27 }
28
29 $http_headers_response = wp_safe_remote_head(sanitize_text_field(wp_unslash($_POST['url'])), $http_headers_args);
30 $http_headers_status = wp_remote_retrieve_response_code($http_headers_response);
31 $http_headers_dictionary = wp_remote_retrieve_headers($http_headers_response);
32 $http_headers_responseHeaders = $http_headers_dictionary ? $http_headers_dictionary->getAll() : array();
33
34 if ($http_headers_status !== 200)
35 {
36 ?>
37 <section class="hh-panel">
38 <h3><span class="hh-highlight"><?php esc_html_e('HTTP Status', 'http-headers'); ?>: <?php echo esc_html($http_headers_status); ?></span></h3>
39 <p><?php
40 switch ($http_headers_status)
41 {
42 case 400:
43 echo 'Bad Request';
44 break;
45 case 401:
46 echo 'Unauthorized';
47 break;
48 case 403:
49 echo 'Forbidden';
50 break;
51 case 404:
52 echo 'Not Found';
53 break;
54 case 405:
55 echo 'Method Not Allowed';
56 break;
57 default:
58 }
59 ?></p>
60 </section>
61 <?php
62 exit;
63 }
64 ?>
65 <section class="hh-panel">
66 <h3><span class="hh-highlight"><?php esc_html_e('Response headers', 'http-headers'); ?></span></h3>
67 <table class="hh-results">
68 <thead>
69 <tr>
70 <th style="width: 30%"><?php esc_html_e('Header', 'http-headers'); ?></th>
71 <th><?php esc_html_e('Value', 'http-headers'); ?></th>
72 </tr>
73 </thead>
74 <tbody>
75 <?php
76 $http_headers_reportOnly = array('content-security-policy-report-only');
77 foreach ($http_headers_responseHeaders as $http_headers_k => $http_headers_v)
78 {
79 $http_headers_k = strtolower($http_headers_k);
80 $http_headers_found = in_array($http_headers_k, $http_headers_reportOnly);
81 $http_headers_v = is_array($http_headers_v) ? join(", ", $http_headers_v) : $http_headers_v;
82 ?>
83 <tr<?php echo array_key_exists($http_headers_k, $http_headers_headers) || $http_headers_found ? ' class="hh-found"' : NULL; ?>>
84 <td><?php echo esc_html($http_headers_k); ?></td>
85 <td><?php echo esc_html($http_headers_v); ?></td>
86 </tr>
87 <?php
88 }
89 ?>
90 </tbody>
91 </table>
92 </section>
93 <?php
94 $http_headers_special = array('content-security-policy');
95 $http_headers_exclude = array('custom-headers', 'cookie-security', 'x-powered-by');
96 $http_headers_missing = array();
97 foreach ($http_headers_headers as $http_headers_k => $http_headers_v)
98 {
99 if (!array_key_exists($http_headers_k, $http_headers_responseHeaders)
100 && !in_array($http_headers_k, $http_headers_exclude)
101 && !(in_array($http_headers_k, $http_headers_special) && array_key_exists($http_headers_k . '-report-only', $http_headers_responseHeaders) ))
102 {
103 $http_headers_missing[$http_headers_k] = isset($http_headers_categories[$http_headers_v[2]]) ? $http_headers_categories[$http_headers_v[2]] : 'Other';
104 }
105 }
106
107 if (!empty($http_headers_missing))
108 {
109 asort($http_headers_missing);
110 ?>
111 <section class="hh-panel">
112 <h3><span class="hh-highlight"><?php esc_html_e('Missing headers', 'http-headers'); ?></span></h3>
113 <table class="hh-results">
114 <thead>
115 <tr>
116 <th style="width: 30%"><?php esc_html_e('Header', 'http-headers'); ?></th>
117 <th><?php esc_html_e('Category', 'http-headers'); ?></th>
118 </tr>
119 </thead>
120 <tbody>
121 <?php
122 foreach ($http_headers_missing as $http_headers_k => $http_headers_v)
123 {
124 ?>
125 <tr>
126 <td><a href="<?php echo esc_url(get_admin_url()); ?>options-general.php?page=http-headers&amp;header=<?php echo esc_attr($http_headers_k); ?>"><?php echo esc_html($http_headers_k); ?></a></td>
127 <td><?php echo esc_html($http_headers_v); ?></td>
128 </tr>
129 <?php
130 }
131 ?>
132 </tbody>
133 </table>
134 </section>
135 <?php
136 }