-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
178 lines (157 loc) · 5.11 KB
/
Copy pathadmin.php
File metadata and controls
178 lines (157 loc) · 5.11 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
<?php
/**
* Admin Page
*
* @package SecuritytxtManager
*/
namespace SecuritytxtManager\Admin;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use const SecuritytxtManager\Constants\CAPABILITY;
use const SecuritytxtManager\Constants\SETTING_OPTION;
/**
* Default setup routine
*
* @return void
*/
function setup() {
if ( SECURITY_TXT_MANAGER_IS_NETWORK ) {
add_action( 'network_admin_menu', __NAMESPACE__ . '\\network_admin_menu' );
} else {
add_action( 'admin_menu', __NAMESPACE__ . '\\admin_menu' );
}
add_action( 'admin_init', __NAMESPACE__ . '\\save_settings' );
}
/**
* Add admin menu
*
* @return void
*/
function network_admin_menu() {
add_submenu_page(
'settings.php',
esc_html__( 'Security.txt', 'security-txt-manager' ),
esc_html__( 'Security.txt', 'security-txt-manager' ),
'manage_network',
'security-txt-settings',
__NAMESPACE__ . '\\securitytxt_settings_screen'
);
}
/**
* Add admin menu
*
* @return void
*/
function admin_menu() {
add_options_page(
esc_html__( 'Security.txt', 'security-txt-manager' ),
esc_html__( 'Security.txt', 'security-txt-manager' ),
CAPABILITY,
'security-txt-settings',
__NAMESPACE__ . '\\securitytxt_settings_screen'
);
}
/**
* Settings screen
*
* @return void
*/
function securitytxt_settings_screen() {
$settings = \SecuritytxtManager\Utils\get_settings();
?>
<div class="wrap">
<h1><?php esc_html_e( 'Security.txt Manager', 'security-txt-manager' ); ?></h1>
<?php if ( is_network_admin() ) : ?>
<?php settings_errors(); ?>
<?php endif; ?>
<form method="post" action="">
<?php
wp_nonce_field( 'security_txt', 'security_txt_nonce' );
?>
<p>
<?php
// Translators: %1$s Link to securitytxt.org website
printf( __( 'You can generate security.txt content on %1$s', 'security-txt-manager' ), '<a rel="noopener" target="_blank" href="https://securitytxt.org/">securitytxt.org</a>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</p>
<label class="screen-reader-text" for="security_txt_content"><?php esc_html_e( 'Security.txt content', 'security-txt-manager' ); ?></label>
<textarea class="widefat code" rows="25" name="security_txt_content" id="security_txt_content"><?php echo esc_textarea( $settings['content'] ); ?></textarea>
<table class="form-table">
<tr>
<th scope="row"><label for="is_sandbox"><?php esc_html_e( 'Credits', 'security-txt-manager' ); ?></label></th>
<td>
<label>
<input type="checkbox" <?php checked( $settings['credits'], 1 ); ?> id="credits" name="credits" value="1">
<?php esc_html_e( 'Enable credits at the bottom of your security.txt file.', 'security-txt-manager' ); ?>
</label>
</td>
</tr>
</table>
<?php
submit_button( esc_html__( 'Save Changes', 'security-txt-manager' ), 'submit primary' );
?>
</form>
<?php server_configuration_notes(); ?>
</div>
<?php
}
/**
* Server configuration notes.
*
* @return void
*/
function server_configuration_notes() {
$apache_rules = <<<'APACHE'
# Add before the WordPress rewrite rules.
RewriteRule ^\.well-known/security\.txt$ index.php [L]
RewriteRule ^security\.txt$ index.php [L]
APACHE;
$nginx_rules = <<<'NGINX'
location = /.well-known/security.txt {
try_files $uri /index.php?$args;
}
location = /security.txt {
try_files $uri /index.php?$args;
}
NGINX;
?>
<hr>
<h2><?php esc_html_e( 'Server configuration', 'security-txt-manager' ); ?></h2>
<p>
<?php
$message = sprintf(
/* translators: 1: .well-known/security.txt URL, 2: security.txt URL. */
esc_html__( 'The plugin registers WordPress rewrite rules for %1$s and %2$s. If your web server handles these paths before WordPress, add one of the rules below to pass the request to WordPress.', 'security-txt-manager' ),
'<code>' . esc_html( wp_parse_url( home_url( '/.well-known/security.txt' ), PHP_URL_PATH ) ) . '</code>',
'<code>' . esc_html( wp_parse_url( home_url( '/security.txt' ), PHP_URL_PATH ) ) . '</code>'
);
echo wp_kses( $message, [ 'code' => [] ] );
?>
</p>
<h3><?php esc_html_e( 'Apache', 'security-txt-manager' ); ?></h3>
<textarea class="large-text code" rows="4" readonly><?php echo esc_textarea( $apache_rules ); ?></textarea>
<h3><?php esc_html_e( 'Nginx', 'security-txt-manager' ); ?></h3>
<textarea class="large-text code" rows="8" readonly><?php echo esc_textarea( $nginx_rules ); ?></textarea>
<?php
}
/**
* Save settings
*
* @return void
*/
function save_settings() {
$settings = [];
$nonce = filter_input( INPUT_POST, 'security_txt_nonce', FILTER_SANITIZE_SPECIAL_CHARS );
if ( wp_verify_nonce( $nonce, 'security_txt' ) ) {
$security_txt_content = sanitize_textarea_field( filter_input( INPUT_POST, 'security_txt_content' ) );
$settings['content'] = $security_txt_content;
$settings['credits'] = (bool) filter_input( INPUT_POST, 'credits' );
if ( SECURITY_TXT_MANAGER_IS_NETWORK ) {
update_site_option( SETTING_OPTION, $settings );
} else {
update_option( SETTING_OPTION, $settings, false );
}
add_settings_error( 'security-txt-settings', 'security-txt-settings', esc_html__( 'Settings saved.', 'security-txt-manager' ), 'success' );
}
}