Update LDCStatus Checker to 1.1.0 (remove plugin) + Add gitlab repo (composer)
- New Env VARS - PROJECT_UUID - LDCWEB_API_TOKEN - MAIL_LIST_SERVICEWEB
This commit is contained in:
parent
a13e33cf2f
commit
0cfe1c5230
4 changed files with 26 additions and 148 deletions
|
|
@ -5,7 +5,8 @@
|
|||
"vlucas/phpdotenv": "^4.1",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"dompdf/dompdf": "^1.0"
|
||||
"dompdf/dompdf": "^1.0",
|
||||
"ldc/ldc-web-status-checker-wp": "^1.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"automattic/vipwpcs": "^2.3",
|
||||
|
|
@ -18,5 +19,11 @@
|
|||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "composer",
|
||||
"url": "https://lab.s-web.fr/api/v4/group/23/-/packages/composer/packages.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,145 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Plugin Name: LDC Web Status Checker
|
||||
* Description: Envoi des infos Serveur/Wordpress vers LDC Web
|
||||
* Version: 1.2
|
||||
* Author: Vincent BRIDIER
|
||||
* Author URI: mailto:vincent.bridier@ldc.fr
|
||||
*/
|
||||
|
||||
add_filter( 'cron_schedules', function ( $schedules ) {
|
||||
$schedules['every-15-minutes'] = array(
|
||||
'interval' => 15 * MINUTE_IN_SECONDS,
|
||||
'display' => __( 'Every 15 minutes' )
|
||||
);
|
||||
return $schedules;
|
||||
} );
|
||||
|
||||
|
||||
function cron_activate_lwsc() {
|
||||
if (!wp_next_scheduled ( 'check_version_cronjob_lwsc' )) {
|
||||
wp_schedule_event(time(), 'every-15-minutes', 'check_version_cronjob_lwsc');
|
||||
}
|
||||
}
|
||||
register_activation_hook(__FILE__, 'cron_activate_lwsc');
|
||||
|
||||
|
||||
// ---- unschedule event upon plugin deactivation
|
||||
function cron_deactivate_lwsc() {
|
||||
$timestamp = wp_next_scheduled ('check_version_cronjob_lwsc');
|
||||
wp_unschedule_event ($timestamp, 'check_version_cronjob_lwsc');
|
||||
}
|
||||
register_deactivation_hook (__FILE__, 'cron_deactivate_lwsc');
|
||||
|
||||
|
||||
function checkingVersion_lwsc(){
|
||||
//Check if we have the necessary functions
|
||||
if ( ! function_exists( 'get_plugins' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
if ( ! function_exists( 'plugins_api' ) ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
|
||||
}
|
||||
if ( ! function_exists( 'get_plugin_updates' ) ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/update.php' );
|
||||
}
|
||||
if ( ! function_exists( 'get_home_path' ) ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
||||
}
|
||||
$data = [];
|
||||
$data['uuid'] = PROJECT_UUID;
|
||||
|
||||
// Sitemap.xml ?
|
||||
$url = site_url('', 'https') . '/sitemap.xml';
|
||||
$ch = curl_init($url);
|
||||
curl_exec($ch);
|
||||
if (!curl_errno($ch)) {
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($http_code === 200 || $http_code === 301){
|
||||
$data['sitemap'] = 'true';
|
||||
}else{
|
||||
$data['sitemap'] = 'false';
|
||||
}
|
||||
}else{
|
||||
$data['sitemap'] = 'false';
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
// Robots.txt ?
|
||||
$url = site_url('', 'https') . '/robots.txt';
|
||||
$ch = curl_init($url);
|
||||
curl_exec($ch);
|
||||
if (!curl_errno($ch)) {
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($http_code === 200 || $http_code === 301){
|
||||
$data['robots'] = 'true';
|
||||
}else{
|
||||
$data['robots'] = 'false';
|
||||
}
|
||||
}else{
|
||||
$data['robots'] = 'false';
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
//Check logs
|
||||
$data['logs'] = 0;
|
||||
$patherror = realpath(ABSPATH .'/..');
|
||||
$files = glob($patherror.'/*.log');
|
||||
if(count($files) > 0){
|
||||
foreach ($files as $file) {
|
||||
$data['logs'] = $data['logs'] + filesize($file);
|
||||
}
|
||||
}
|
||||
|
||||
// get all plugins
|
||||
$allPlugin = get_plugins();
|
||||
//get all updatable plugins
|
||||
$plugin_to_update = get_plugin_updates();
|
||||
|
||||
//get active plugins
|
||||
$active_plugins = wp_get_active_and_valid_plugins();
|
||||
foreach ($active_plugins as $key => $path) {
|
||||
$plugin_data = get_plugin_data($path);
|
||||
$data['code']['plugins'][$plugin_data['Name']]['Version'] = $plugin_data['Version'];
|
||||
// check if one of the active plugins is updatable
|
||||
if (array_key_exists (plugin_basename( $path ), $plugin_to_update)) {
|
||||
$data['code']['plugins'][$plugin_data['Name']]['Maj'] = $plugin_to_update[plugin_basename( $path )]->update->new_version;
|
||||
} else {
|
||||
$data['code']['plugins'][$plugin_data['Name']]['Maj'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
//get non active plugins
|
||||
foreach ($allPlugin as $key => $value) {
|
||||
if (is_plugin_inactive($key)) {
|
||||
$data['code']['inactiveplugins'][$value['Name']] = true;
|
||||
}
|
||||
}
|
||||
|
||||
//get mu plugins / check security plugin
|
||||
$muPlugins = get_mu_plugins();
|
||||
if (isset($muPlugins['admin-useraccount-security.php'])) {
|
||||
$data['code']['plugins']['SecurityPlugin'] = $muPlugins['admin-useraccount-security.php']['Version'];
|
||||
} else {
|
||||
$data['code']['plugins']['SecurityPlugin'] = false;
|
||||
}
|
||||
|
||||
//get installed wordpress version
|
||||
$currentversion = get_bloginfo('version');
|
||||
$data['code']['version'] = $currentversion;
|
||||
|
||||
// Send by cURL
|
||||
$url = 'https://ldc-web.ldc.fr/api/status-checker';
|
||||
$ch = curl_init($url);
|
||||
$payload = ['token' => 'CE8S52Qq7stf5k8frF4T', 'datas' => json_encode($data)];
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if (!wp_next_scheduled ( 'check_version_cronjob_lwsc' )) {
|
||||
wp_schedule_event(time(), 'every-15-minutes', 'check_version_cronjob_lwsc');
|
||||
}
|
||||
}
|
||||
|
||||
add_action ('check_version_cronjob_lwsc', 'checkingVersion_lwsc');
|
||||
14
crons/LDCWebStatusChecker.php
Normal file
14
crons/LDCWebStatusChecker.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
require_once(__DIR__ . '/../vendor/autoload.php');
|
||||
require_once(__DIR__ . '/../wp-load.php');
|
||||
|
||||
use Ldc\LdcWebStatusCheckerWp\Cron\ReportToLDCWebCron;
|
||||
|
||||
if (!defined('ENV')) {
|
||||
throw new \RuntimeException('Undefined constant \'ENV\'');
|
||||
}
|
||||
|
||||
if (\strtolower(strval(ENV)) === 'production') {
|
||||
ReportToLDCWebCron::sendReport();
|
||||
}
|
||||
|
|
@ -157,7 +157,9 @@ define('WP_DEBUG_DISPLAY', evalBool(getenv('WP_DEBUG_DISPLAY')));
|
|||
|
||||
define('WP_HTTP_BLOCK_EXTERNAL', evalBool(getenv('WP_HTTP_BLOCK_EXTERNAL')));
|
||||
// LDC WEB STATUS CHECKER
|
||||
define('PROJECT_UUID', getenv('PROJECT_UUID'));
|
||||
define('PROJECT_UUID', $_ENV['PROJECT_UUID']);
|
||||
define('LDCWEB_API_TOKEN', $_ENV['LDCWEB_API_TOKEN']);
|
||||
define('MAIL_LIST_SERVICEWEB', $_ENV['MAIL_LIST_SERVICEWEB']);
|
||||
// ALPHAVANTAGE
|
||||
define('ALPHAVANTAGE_API_KEY', getenv('ALPHAVANTAGE_API_KEY'));
|
||||
// MATOMO
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue