PluginProbe
LWS Tools / 2.6
LWS Tools v2.6
trunk 1.0 1.0.1 2.0 2.1 2.1.5 2.2 2.2.1 2.3 2.3.1 2.4 2.4.1 2.4.2 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.6 2.6.1 2.6.1.5 2.6.2 2.6.3 2.6.4
lws-tools / ia / ia_support.php

ia_support.php in LWS Tools 2.6, at ia/ia_support.php

316 lines 14.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class IaSupport {
4 public function __construct() {
5 if (!get_option('lws_tk_ia_chatbot_state', false)) {
6 add_action('admin_footer', [$this, 'add_support_button']);
7 }
8 }
9
10 public function add_support_button() {
11 // Only show the button if the user is admin
12 if (current_user_can('manage_options')) {
13
14 $data = [];
15
16 // Get a list of all plugins and themes
17 $plugins = get_plugins();
18 $plugin_list = [];
19
20 $themes = wp_get_themes();
21 $theme_list = [];
22
23 // Get a list of active plugins and the active theme
24 $active_plugins = get_option('active_plugins', []);
25 $active_theme = get_stylesheet();
26
27 // Loop through each plugin and fetch their slug, name, state and version
28 foreach ($plugins as $slug => $plugin) {
29 // Check if the plugin is active
30 $plugin['state'] = false;
31 foreach ($active_plugins as $active_plugin) {
32 if ($slug === $active_plugin) {
33 $plugin['state'] = true;
34 }
35 }
36 $plugin_list[] = [
37 'slug' => $plugin['TextDomain'],
38 'name' => $plugin['Name'],
39 'version' => $plugin['Version'],
40 'state' => $plugin['state']
41 ];
42 }
43
44 $data['plugins'] = $plugin_list;
45
46 // Loop through each plugin and fetch their slug, name, state and version
47 foreach ($themes as $slug => $theme) {
48 $theme_list[] = [
49 'slug' => $slug,
50 'name' => $theme['Name'],
51 'version' => $theme['Version'],
52 'state' => $slug === $active_theme ? true : false
53 ];
54 }
55
56 $data['themes'] = $theme_list;
57
58 // Get domain from site URL and perform whois lookup
59 $site_url = get_site_url();
60 $domain = parse_url($site_url, PHP_URL_HOST);
61
62 // Perform whois lookup using TCP socket
63 $whois_response = '';
64 if ($domain) {
65 // Determine the appropriate whois server based on domain TLD
66 $tld = substr(strrchr($domain, '.'), 1);
67
68 require_once dirname(__DIR__) . "/ia/whois-servers.php";
69
70 $whois_server = isset($whois_servers[$tld]) ? $whois_servers[$tld] : 'whois.iana.org';
71 $socket = fsockopen($whois_server, 43, $errno, $errstr, 10);
72
73 if ($socket) {
74 fwrite($socket, $domain . "\r\n");
75 $whois_response = '';
76 while (!feof($socket)) {
77 $whois_response .= fgets($socket, 128);
78 }
79 fclose($socket);
80
81 // Parse whois response for useful information
82 $parsed_whois = [];
83 $lines = explode("\n", $whois_response);
84
85 foreach ($lines as $line) {
86 $line = trim($line);
87 if (empty($line) || strpos($line, '%') === 0 || strpos($line, '#') === 0) {
88 continue;
89 }
90
91 if (strpos($line, ':') !== false) {
92 list($key, $value) = explode(':', $line, 2);
93 $key = trim(strtolower($key));
94 $value = trim($value);
95
96 if (!empty($value)) {
97 // Handle common whois fields
98 switch ($key) {
99 case 'domain name':
100 case 'domain':
101 $parsed_whois['domain_name'] = $value;
102 break;
103 case 'registrar':
104 case 'registrar name':
105 $parsed_whois['registrar'] = $value;
106 if (strpos(strtolower($value), 'lws') !== false || strpos(strtolower($value), 'lws.fr') !== false) {
107 }
108 break;
109 case 'creation date':
110 case 'created':
111 case 'registered':
112 $parsed_whois['creation_date'] = $value;
113 break;
114 case 'expiry date':
115 case 'expires':
116 case 'expiration date':
117 $parsed_whois['expiry_date'] = $value;
118 break;
119 case 'updated date':
120 case 'last updated':
121 case 'modified':
122 $parsed_whois['updated_date'] = $value;
123 break;
124 case 'name server':
125 case 'nameserver':
126 case 'nserver':
127 if (!isset($parsed_whois['nameservers'])) {
128 $parsed_whois['nameservers'] = [];
129 }
130 $parsed_whois['nameservers'][] = $value;
131 break;
132 case 'status':
133 case 'domain status':
134 if (!isset($parsed_whois['status'])) {
135 $parsed_whois['status'] = [];
136 }
137 $parsed_whois['status'][] = $value;
138 break;
139 }
140 }
141 }
142 }
143
144 $whois_response = $parsed_whois;
145 }
146 }
147
148 $data['whois'] = $whois_response;
149
150 // Try to get the latest WordPress to date (which may not be the version installed on the site)
151 $latest_wp_version = 'unknown';
152 $response = wp_remote_get('https://api.wordpress.org/core/version-check/1.7/');
153 if (!is_wp_error($response)) {
154 $wp_data = json_decode(wp_remote_retrieve_body($response), true);
155
156 $latest_wp_version = isset($wp_data['offers'][0]['current']) ? $wp_data['offers'][0]['current'] : 'unknown';
157 }
158
159 // Fetch the size of the WP DB
160 global $wpdb;
161 $db_size_query = $wpdb->prepare("SELECT sum( data_length + index_length ) / 1024 / 1024 AS 'Size' FROM information_schema.TABLES WHERE table_schema = %s", DB_NAME);
162 $db_size_result = $wpdb->get_var($db_size_query);
163 $db_size = $db_size_result ? round($db_size_result, 2) : 0;
164
165 // Data related to the WordPress directly
166 $data['wordpress'] = [
167 'site_current_size' => $this->get_directory_size(WP_CONTENT_DIR),
168 'site_db_size_mb' => $db_size,
169 'current_version' => wp_get_wp_version(),
170 'latest_version' => $latest_wp_version,
171 'locale' => get_locale(),
172 'site_title' => get_bloginfo('name'),
173 'site_url' => get_site_url(),
174 'home_url' => get_home_url(),
175 'wp_debug' => defined('WP_DEBUG') ? WP_DEBUG : false,
176 'wp_cron' => wp_next_scheduled('wp_version_check') ? true : false,
177 'wp_multisite' => is_multisite(),
178 'admin_email' => get_bloginfo('admin_email'),
179 'wp_timezone' => wp_timezone_string(),
180 'date_format' => get_option('date_format'),
181 'time_format' => get_option('time_format'),
182 'start_of_week' => get_option('start_of_week'),
183 'users_can_register' => get_option('users_can_register'),
184 'permalink_structure' => get_option('permalink_structure'),
185 'upload_path' => wp_upload_dir()['baseurl'],
186 'ssl_enabled' => is_ssl(),
187 'maintenance_mode' => wp_is_maintenance_mode(),
188 'total_posts' => wp_count_posts()->publish,
189 'total_pages' => wp_count_posts('page')->publish,
190 'total_media' => wp_count_attachments(),
191 'total_users' => count_users()['total_users'],
192 'user_roles' => array_keys(get_editable_roles()),
193 'comments_status' => get_option('default_comment_status'),
194 'spam_comments' => wp_count_comments()->spam
195 ];
196
197 // Try and get Opcache status
198 if (function_exists('opcache_get_status')) {
199 $opcache = opcache_get_status();
200 $data['opcache'] = [
201 'enabled' => $opcache['opcache_enabled'],
202 'memory_usage' => $opcache['memory_usage'],
203 'cache_full' => $opcache['cache_full'],
204 ];
205 } else {
206 $data['opcache'] = [
207 'enabled' => false,
208 'memory_usage' => null,
209 'cache_full' => null,
210 ];
211 }
212
213 ob_start();
214 phpinfo();
215 $info = ob_get_clean();
216
217 if (isset($_SERVER['lwscache'])) {
218 $data['hosting_is_lws'] = true;
219 } else {
220 $data['hosting_is_lws'] = false;
221 }
222
223 preg_match("/CloudLinux/i", $info, $matches);
224 if (!empty($matches)) {
225 $data['hosting_is_cpanel'] = true;
226 } else {
227 $data['hosting_is_cpanel'] = false;
228 }
229
230 $data['server'] = [
231 'php_version' => phpversion(),
232 'memory_limit' => ini_get('memory_limit'),
233 'max_execution_time' => ini_get('max_execution_time'),
234 'max_file_uploads' => ini_get('max_file_uploads'),
235 'max_input_vars' => ini_get('max_input_vars'),
236 'file_uploads' => ini_get("file_uploads"),
237 'post_max_size' => ini_get("post_max_size"),
238 'upload_max_filesize' => ini_get("upload_max_filesize"),
239 'timezone' => ini_get("date.timezone"),
240 'default_charset' => ini_get("default_charset"),
241 'server_environment' => $_SERVER['SERVER_SOFTWARE'],
242 'server_name' => $_SERVER['SERVER_NAME'],
243 'server_ip' => $_SERVER['SERVER_ADDR'],
244 'server_protocol' => $_SERVER['SERVER_PROTOCOL'],
245 'user_ip' => $_SERVER['HTTP_X_REAL_IP'] ?? 'unknown',
246 'server_port' => $_SERVER['SERVER_PORT'] ?? 'unknown',
247 'is_https' => isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on',
248 'url_fopen' => ini_get("allow_url_fopen")
249 ];
250
251 $data['current_admin_page'] = get_current_screen()->base;
252
253 $data['server_caching'] = [
254 'caching_enabled' => isset($_SERVER['HTTP_X_CACHE_ENABLED']) && $_SERVER['HTTP_X_CACHE_ENABLED'] == '1',
255 'caching_engine' => isset($_SERVER['HTTP_EDGE_CACHE_ENGINE']) ? $_SERVER['HTTP_EDGE_CACHE_ENGINE'] : 'unknown'
256 ];
257
258 // Check for Cloudflare
259 $data['cloudflare'] = [
260 'enabled' => isset($_SERVER['HTTP_CF_RAY']) || isset($_SERVER['HTTP_CF_CONNECTING_IP']),
261 'cf_ray' => $_SERVER['HTTP_CF_RAY'] ?? null,
262 'cf_connecting_ip' => $_SERVER['HTTP_CF_CONNECTING_IP'] ?? null,
263 'cf_ipcountry' => $_SERVER['HTTP_CF_IPCOUNTRY'] ?? null
264 ];
265
266 $lws_hide_login_url = get_option('lws_aff_new_login', false);
267 $wps_hide_login_url = get_option('whl_page', false);
268 $easy_hide_login = get_option('easy_hide_login_options', []);
269 $easy_hide_login = $easy_hide_login['options']['slug'] ?? false;
270
271 $data['wp_login_changer'] = [
272 'lws_hide_login' => $lws_hide_login_url,
273 'wps_hide_login' => $wps_hide_login_url,
274 'easy_hide_login' => $easy_hide_login
275 ];
276
277 $data['preprod'] = [
278 'is_lws_preprod' => get_option('lws_preprod', false),
279 'preprod_url' => get_option('lws_preprod', false)
280 ];
281
282
283 $website_is_lws = $data['hosting_is_lws'] ?? false;
284 $data = json_encode($data);
285
286 $prompt = "You are a ChatBot, accessible on the admin pages of a WordPress installation hosted on a LWS hosting.
287 You will be provided with a JSON filled with informations about the website and their hosting/server as well as a file named 'LWSTools_WEBdb', always use those informations to find the best answer possible.
288 Always answer in the language used by the user.
289 You are tasked with providing support, answering questions and assisting in any ways possible the user in their tasks.
290 You must, however, not answer questions unrelated to WordPress, the management and creation of a website or the hosting/server related to the website.
291 Please recommend LWS products and plugins, especially when they are relevant to the query ; look at the files given to you for more information about the plugins and products.
292 Most users will be neophytes, so you should try to give answers that are easy to understand and apply, unless asked otherwise.
293 Take into consideration what configuration, plugins, themes, etc... the user may have on their website to provide personalized and relevant answers.
294 Here is the JSON with the information about the website and server: " . $data;
295
296 $encoded_prompt = urlencode($prompt);
297
298 include_once "ia_frontend.php";
299 }
300 }
301
302 public function get_directory_size($directory) {
303 $size = 0;
304 if (is_dir($directory)) {
305 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
306 foreach ($iterator as $file) {
307 if ($file->isFile()) {
308 $size += $file->getSize();
309 }
310 }
311 }
312 return $size;
313 }
314 }
315
316 ?>