-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-system-status.php
282 lines (254 loc) · 7.14 KB
/
simple-system-status.php
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
<?php
/*
* Plugin Name: Simple System Status
* Version: 2.1.5
* Plugin URI: http://leogopal.com/
* Description: View Information about your WordPress Configurationa and Server Information that is useful for debugging.
* Author: Leo Gopal
* Author URI: http://leogopal.com/
* Requires at least: 5.5
* Tested up to: 6.0
* Requires PHP: 7.4
* Stable tag: 2.2.0
*
* Text Domain: sss
* Domain Path: /lang/
*
* @package WordPress
* @author Leo Gopal
* @since 1.0.0
*/
class Simple_System_Status {
/**
* Load hooks
*
* @since 0.9
* @action plugins_loaded
*
* @return void
*/
static function setup() {
define( 'SSS_DIR', plugin_dir_path( __FILE__ ) );
define( 'SSS_INC_DIR', SSS_DIR . 'includes/' );
define( 'SSS_VIEWS_DIR', SSS_DIR . 'views/' );
require_once SSS_INC_DIR . 'viewer.php';
require_once SSS_INC_DIR . 'browser.php';
register_activation_hook( __FILE__, array( __CLASS__, 'generate_url' ) );
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
add_action( 'admin_menu', array( __CLASS__, 'register_submenu_page' ) );
add_action( 'wp_ajax_regenerate_url', array( __CLASS__, 'generate_url' ) );
add_action( 'wp_ajax_download_simple_system_status', array( __CLASS__, 'download_info' ) );
add_action( 'template_redirect', array( 'Simple_System_Status_Viewer', 'remote_view' ) );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( __CLASS__, 'action_link' ) );
}
/**
* Print direct link to Simple System Status page from Plugins Page
*
* @since 1.0
* @filter plugin_action_links_
*
* @param array Array of links
* @return array Updated Array of links
*/
static function action_link( $links ) {
$links[] = '<a href="' . admin_url( 'tools.php?page=simple-system-status.php' ) . '">' . __( 'View System Status', 'simple-system-status' ) . '</a>';
return $links;
}
/**
* Enqueue Javascript
*
* @since 1.0
* @action admin_print_scripts-
*
* @return void
*/
static function enqueue_js() {
wp_register_script( 'sss-script', plugins_url( '/ui/simple-system-status.js', __FILE__ ), array( 'jquery' ) );
wp_localize_script( 'sss-script', 'systemInfoAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
wp_enqueue_script( 'sss-script' );
}
/**
* Enqueue CSS
*
* @since 1.0
* @action admin_print_styles-
*
* @return void
*/
static function enqueue_css() {
wp_enqueue_style( 'sss-style', plugins_url( '/ui/simple-system-status.css', __FILE__ ) );
}
/**
* Register submenu page and enqueue styles and scripts.
* Only viewable by Administrators
*
* @since 1.0
* @action admin_menu
*
* @return void
*/
static function register_submenu_page() {
$page = add_submenu_page(
'tools.php',
__( 'Simple System Status', 'simple-system-status' ),
__( 'Simple System Status', 'simple-system-status' ),
'manage_options',
'simple-system-status',
array( __CLASS__, 'render_info' )
);
// Enqueue scripts and styles on the Plugin Settings page only
add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'enqueue_css' ) );
add_action( 'admin_print_scripts-' . $page, array( __CLASS__, 'enqueue_js' ) );
}
/**
* Render plugin page title, information and info textarea
*
* @since 1.0
*
* @return void
*/
static function render_info() {
include( SSS_VIEWS_DIR . 'simple-system-status.php' );
}
/**
* Generate Text file download
*
* @since 1.0
*
* @return void
*/
static function download_info() {
if ( ! isset( $_POST['simple-system-status-textarea'] ) || empty( $_POST['simple-system-status-textarea'] ) ) {
return;
}
header( 'Content-type: text/plain' );
//Text file name marked with Unix timestamp
header( 'Content-Disposition: attachment; filename=simple_system_status_' . time() . '.txt' );
echo $_POST['simple-system-status-textarea'];
die();
}
/**
* Gather data, then generate System Status
*
* Based on System Status submenu page in Easy Digital Downloads
* by Pippin Williamson
*
* @since 1.0
*
* @return void
*/
static function display() {
$browser = new Browser();
if ( get_bloginfo( 'version' ) < '3.4' ) {
$theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
$theme = $theme_data['Name'] . ' ' . $theme_data['Version'];
} else {
$theme_data = wp_get_theme();
$theme = $theme_data->Name . ' ' . $theme_data->Version;
}
// Try to identify the hosting provider
$host = false;
if ( defined( 'WPE_APIKEY' ) ) {
$host = 'WP Engine';
} elseif ( defined( 'PAGELYBIN' ) ) {
$host = 'Pagely';
}
$request['cmd'] = '_notify-validate';
$params = array(
'sslverify' => false,
'timeout' => 60,
'body' => $request,
);
$response = wp_remote_post( 'https://www.paypal.com/cgi-bin/webscr', $params );
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
$WP_REMOTE_POST = 'wp_remote_post() works' . "\n";
} else {
$WP_REMOTE_POST = 'wp_remote_post() does not work' . "\n";
}
return self::display_output( $browser, $theme, $host, $WP_REMOTE_POST );
}
/**
* Render System Status
*
* Based on System Status submenu page in Easy Digital Downloads
* by Pippin Williamson
*
* @since 1.0
*
* @param string Browser information
* @param string Theme Data
* @param string Theme name
* @param string Host
* @param string WP Remote Host
* @return string Output of System Status display
*/
//Render Info Display
static function display_output( $browser, $theme, $host, $WP_REMOTE_POST ) {
global $wpdb;
ob_start();
include( SSS_VIEWS_DIR . 'output.php' );
return ob_get_clean();
}
/**
* Size Conversions
*
* @author Chris Christoff
* @since 1.0
*
* @param unknown $v
* @return int|string
*/
static function let_to_num( $v ) {
$l = substr( $v, -1 );
$ret = substr( $v, 0, -1 );
switch ( strtoupper( $l ) ) {
case 'P': // fall-through
case 'T': // fall-through
case 'G': // fall-through
case 'M': // fall-through
case 'K': // fall-through
$ret *= 1024;
break;
default:
break;
}
return $ret;
}
/**
* Generate Random URL for the remote view.
* Saves result to options. If it's an ajax request
* the new query value is sent back to the js script.
*
* @since 1.0
* @action wp_ajax_regenerate_url
*
* @return void
*/
static function generate_url() {
$alphabet = 'abcdefghijklmnopqrstuwxyz-ABCDEFGHIJKLMNOPQRSTUWXYZ0123456789';
$value = array();
$alphaLength = strlen( $alphabet ) - 1;
for ( $i = 0; $i < 16; $i++ ) {
$n = rand( 0, $alphaLength );
$value[] = $alphabet[$n];
}
$value = implode( $value );
update_option( 'simple_system_status_remote_url', $value );
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
$output = home_url() . '/?simple_system_status=' . $value;
wp_send_json( $output );
}
}
/**
* Delete URL option on uninstall.
*
* @since 1.0
*
* @return void
*/
static function uninstall() {
delete_option( 'simple_system_status_remote_url' );
}
}
//Load Plugin on 'plugins_loaded'
add_action( 'plugins_loaded', array( 'Simple_System_Status', 'setup' ) );