report-to.php
8.51 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
<?php
if (!defined('ABSPATH')) {
exit;
}
?>
<tr valign="top">
<th scope="row">Report-To
<p class="description"><?php _e('The Report-To HTTP response header field instructs the user agent to store reporting endpoints for an origin.', 'http-headers'); ?></p>
</th>
<td>
<fieldset>
<legend class="screen-reader-text">Report-To</legend>
<?php
$report_to = get_option('hh_report_to', 0);
foreach ($bools as $k => $v)
{
?><p><label><input type="radio" class="http-header" name="hh_report_to" value="<?php echo $k; ?>"<?php checked($report_to, $k, true); ?> /> <?php echo $v; ?></label></p><?php
}
?>
</fieldset>
<?php settings_fields( 'http-headers-rt' ); ?>
<?php do_settings_sections( 'http-headers-rt' ); ?>
</td>
</tr>
<?php
$default_value = array(
array(
'endpoints' => array(),
'group' => '',
'max_age' => '',
)
);
$report_to_value = get_option('hh_report_to_value');
if (!is_array($report_to_value) || empty($report_to_value))
{
$report_to_value = $default_value;
}
?>
<tr>
<td colspan="2">
<div style="max-width: 1024px; overflow-x: auto">
<table class="hh-bordered hh-p-sm">
<tr>
<th rowspan="2" class="hh-center hh-middle">group</th>
<th rowspan="2" class="hh-center hh-middle">max_age</th>
<th rowspan="2" class="hh-center hh-middle">include_subdomains</th>
<th colspan="3" class="hh-center">endpoints</th>
<th> </th>
<th> </th>
</tr>
<tr>
<th class="hh-center">url</th>
<th class="hh-center">priority</th>
<th class="hh-center">weight</th>
<th> </th>
<th> </th>
</tr>
<?php
$items = array('0' => '0 (Delete entire reporting cache)', '3600' => '1 hour', '86400' => '1 day', '604800' => '7 days', '2592000' => '30 days', '5184000' => '60 days', '7776000' => '90 days', '31536000' => '1 year', '63072000' => '2 years');
$i = 0;
foreach ($report_to_value as $item)
{
if (isset($item['endpoints']) && !empty($item['endpoints']))
{
$cnt = count($item['endpoints']);
$c = 0;
foreach ($item['endpoints'] as $k => $v)
{
$classes = array();
if ($c == 0)
{
if ($i == 0)
{
$classes[] = 'hh-tr-first';
}
$classes[] = 'hh-tr-group-start';
}
if ($c == $cnt - 1)
{
$classes[] = 'hh-tr-group-end';
}
?>
<tr class="<?php echo join(' ', $classes); ?>">
<?php
if ($c == 0)
{
?>
<td rowspan="<?php echo $cnt; ?>" class="hh-middle"><input type="text" class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][group]" value="<?php echo esc_attr($item['group']); ?>" placeholder="csp-endpoint"<?php echo $report_to == 1 ? NULL : ' readonly'; ?>></td>
<td rowspan="<?php echo $cnt; ?>" class="hh-middle"><select class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][max_age]"<?php echo $report_to == 1 ? NULL : ' readonly'; ?>>
<?php
foreach ($items as $key => $val) {
?><option value="<?php echo $key; ?>"<?php selected($item['max_age'], $key); ?>><?php echo $val; ?></option><?php
}
?>
</select></td>
<td rowspan="<?php echo $cnt; ?>" class="hh-middle hh-center"><input type="checkbox" class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][include_subdomains]" value="1"<?php checked(@$item['include_subdomains'], 1, true); ?><?php echo $report_to == 1 ? NULL : ' readonly'; ?> /></td>
<?php
}
?>
<td><input type="text" class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][endpoints][<?php echo $k; ?>][url]" value="<?php echo esc_attr($v['url']); ?>" placeholder="https://example.com/report/csp"<?php echo $report_to == 1 ? NULL : ' readonly'; ?> size="40"></td>
<td><input type="number" class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][endpoints][<?php echo $k; ?>][priority]" value="<?php echo esc_attr($v['priority']); ?>" min="0" step="1"></td>
<td><input type="number" class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][endpoints][<?php echo $k; ?>][weight]" value="<?php echo esc_attr($v['weight']); ?>" min="0" step="1"></td>
<td><?php
if ($c == 0)
{
?>
<button type="button" class="button hh-btn-add-endpoint"><?php _e('Add endpoint', 'http-headers'); ?></button>
<?php
} else {
?>
<button type="button" class="button hh-btn-delete-endpoint"><?php _e('Remove endpoint', 'http-headers'); ?></button>
<?php
}
?></td>
<?php
if ($c == 0)
{
?>
<td rowspan="<?php echo $cnt; ?>" class="hh-middle hh-center"><?php
if ($i > 0)
{
?>
<button type="button" class="button hh-btn-delete-endpoint-group" title="<?php esc_attr_e('Delete', 'http-headers'); ?>"><?php _e('Remove group', 'http-headers'); ?></button>
<?php
}
?></td>
<?php
}
?>
</tr>
<?php
$c += 1;
}
} else {
?>
<tr class="hh-tr-first hh-tr-group-start hh-tr-group-end">
<td><input type="text" class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][group]" value="<?php echo esc_attr($item['group']); ?>" placeholder="csp-endpoint"<?php echo $report_to == 1 ? NULL : ' readonly'; ?>></td>
<td><select class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][max_age]"<?php echo $report_to == 1 ? NULL : ' readonly'; ?>>
<?php
foreach ($items as $key => $val) {
?><option value="<?php echo $key; ?>"<?php selected($item['max_age'], $key); ?>><?php echo $val; ?></option><?php
}
?>
</select></td>
<td class="hh-center"><input type="checkbox" class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][include_subdomains]" value="1"<?php checked(@$item['include_subdomains'], 1, true); ?><?php echo $report_to == 1 ? NULL : ' readonly'; ?> /></td>
<td><input type="text" class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][endpoints][0][url]" placeholder="https://example.com/report/csp"<?php echo $report_to == 1 ? NULL : ' readonly'; ?> size="40"></td>
<td><input type="number" class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][endpoints][0][priority]" min="0" step="1"></td>
<td><input type="number" class="http-header-value" name="hh_report_to_value[<?php echo $i; ?>][endpoints][0][weight]" min="0" step="1"></td>
<td>
<button type="button" class="button hh-btn-add-endpoint"><?php _e('Add endpoint', 'http-headers'); ?></button>
</td>
<td rowspan="1"><?php
if ($i > 0)
{
?><button type="button" class="button hh-btn-delete-endpoint-group" title="<?php esc_attr_e('Delete', 'http-headers'); ?>"><?php _e('Remove group', 'http-headers'); ?></button><?php
}
?></td>
</tr>
<?php
}
$i += 1;
}
?>
<tr>
<td colspan="8">
<button type="button" class="button" id="hh-btn-add-endpoint-group">+ <?php _e('Add endpoint group', 'http-headers'); ?></button>
</td>
</tr>
</table>
</div>
</td>
</tr>