- Add new LDC plugins
- Delete old LDC plugin
This commit is contained in:
parent
5039b5de09
commit
1992dd9711
6 changed files with 197 additions and 226 deletions
|
|
@ -44,7 +44,7 @@ RewriteEngine on
|
|||
</files>
|
||||
|
||||
# protection des fichiers sys .git
|
||||
RedirectMatch 404 /\.git
|
||||
RedirectMatch 404 /\.
|
||||
|
||||
#Bloquer l'indexation des fichiers PDF
|
||||
<files ~ "\.(doc|docx|pdf)$">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/*
|
||||
* Plugin Name: LDC Web Admin Secure
|
||||
* Description: Sécurisation des BO via LDC Web
|
||||
* Version: 1.0
|
||||
* Author: Vincent BRIDIER
|
||||
* Author URI: mailto:vincent.bridier@ldc.fr
|
||||
*/
|
||||
|
||||
add_filter( 'cron_schedules', function ( $schedules ) {
|
||||
$schedules['everyday'] = array(
|
||||
'interval' => DAY_IN_SECONDS,
|
||||
'display' => __( 'Everyday' )
|
||||
);
|
||||
return $schedules;
|
||||
} );
|
||||
|
||||
|
||||
function cron_activate_lwas() {
|
||||
if (!wp_next_scheduled ( 'update_admin_htaccess_lwas' )) {
|
||||
wp_schedule_event(strtotime('4:30:00'), 'everyday', 'update_admin_htaccess_lwas');
|
||||
}
|
||||
}
|
||||
register_activation_hook(__FILE__, 'cron_activate_lwas');
|
||||
|
||||
|
||||
// ---- unschedule event upon plugin deactivation
|
||||
function cron_deactivate_lwas() {
|
||||
$timestamp = wp_next_scheduled ('update_admin_htaccess_lwas');
|
||||
wp_unschedule_event ($timestamp, 'update_admin_htaccess_lwas');
|
||||
}
|
||||
register_deactivation_hook (__FILE__, 'cron_deactivate_lwas');
|
||||
|
||||
|
||||
function UpdateAdminHtaccess_lwas(){
|
||||
|
||||
// Get by cURL
|
||||
$url = 'https://ldc-web.ldc.fr/api/ldc-networks?token=CE8S52Qq7stf5k8frF4T';
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$ips = json_decode($result);
|
||||
$filename = ABSPATH . 'wp-admin/.htaccess';
|
||||
foreach ($ips as $k => $ip) {
|
||||
if ($k === 0) {
|
||||
file_put_contents($filename, "SetEnvIF X-Forwarded-For '$ip' AllowIP\n");
|
||||
}else{
|
||||
file_put_contents($filename, "SetEnvIF X-Forwarded-For '$ip' AllowIP\n", FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
file_put_contents($filename, "<RequireAny>\n", FILE_APPEND);
|
||||
file_put_contents($filename, "Require env AllowIP\n", FILE_APPEND);
|
||||
file_put_contents($filename, "</RequireAny>\n", FILE_APPEND);
|
||||
file_put_contents($filename, "<Files 'admin-ajax.php'>\n", FILE_APPEND);
|
||||
file_put_contents($filename, "Require all granted\n", FILE_APPEND);
|
||||
file_put_contents($filename, "</Files>\n", FILE_APPEND);
|
||||
|
||||
if (!wp_next_scheduled ( 'update_admin_htaccess_lwas' )) {
|
||||
wp_schedule_event(time(), 'everyday', 'update_admin_htaccess_lwas');
|
||||
}
|
||||
}
|
||||
|
||||
add_action ('update_admin_htaccess_lwas', 'UpdateAdminHtaccess_lwas');
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
/*
|
||||
* Plugin Name: LDC Web Status Checker
|
||||
* Description: Envoi des infos Serveur/Wordpress vers LDC Web
|
||||
* Version: 1.0
|
||||
* 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 ?
|
||||
if (file_exists(ABSPATH . 'sitemap.xml')) {
|
||||
$data['sitemap'] = 'true';
|
||||
}else{
|
||||
$data['sitemap'] = 'false';
|
||||
}
|
||||
|
||||
// Robots.txt ?
|
||||
if (file_exists(ABSPATH . 'robots.txt')) {
|
||||
$data['robots'] = 'true';
|
||||
}else{
|
||||
$data['robots'] = 'false';
|
||||
}
|
||||
|
||||
//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');
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
// --- Les niveaux de LOG
|
||||
DEFINE ("ERR_NOTICE", 0) ;
|
||||
DEFINE ("ERR_DEBUG", 1) ;
|
||||
DEFINE ("ERR_WARNING", 2) ;
|
||||
DEFINE ("ERR_ERROR", 3) ;
|
||||
|
||||
Class logger
|
||||
{
|
||||
var $iLogLevel ;
|
||||
var $zLogFilePath ;
|
||||
var $iLogFd ;
|
||||
|
||||
// --- Initialisation
|
||||
function __construct ($_zLogFilePath = "")
|
||||
{
|
||||
$this->zLogFilePath = $_zLogFilePath ;
|
||||
$this->iLogLevel = ERR_DEBUG ;
|
||||
$this->iLogFd = FALSE ;
|
||||
}
|
||||
|
||||
// --- Ecriture d'un message d'erreur dans le Log
|
||||
function writeLog ($_zLogMsg, $iLogLevel = ERR_DEBUG)
|
||||
{
|
||||
$this->iLogFd = fopen ($this->zLogFilePath, "a+") ;
|
||||
$zLogMsg = "";
|
||||
$zLogMsg = date ("[d/m/Y - h:i:s]") ;
|
||||
switch ($iLogLevel)
|
||||
{
|
||||
case ERR_NOTICE :
|
||||
$zLogMsg .= "[NOTICE]" ;
|
||||
break ;
|
||||
case ERR_DEBUG :
|
||||
$zLogMsg .= "" ;
|
||||
break ;
|
||||
case ERR_WARNING :
|
||||
$zLogMsg .= "[WARNING]" ;
|
||||
break ;
|
||||
case ERR_ERROR :
|
||||
$zLogMsg .= "[ERROR]" ;
|
||||
break ;
|
||||
}
|
||||
$zLogMsg .= $_zLogMsg . "\n" ;
|
||||
@fwrite ($this->iLogFd, $zLogMsg) ;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,177 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Plugin Name: Versions Checker
|
||||
* Description: Vérifie les versions des plugins et de wordpress
|
||||
* Version: 1.4
|
||||
* Author: Thibault Richy
|
||||
* Author URI:
|
||||
*/
|
||||
|
||||
include("logger.class.php");
|
||||
|
||||
// ---- create a scheduled event
|
||||
// function cronstarter_activation() {
|
||||
// if( !wp_next_scheduled( 'check_version_cronjob' ) ) {
|
||||
// wp_schedule_event( time(), 'hourly', 'check_version_cronjob' );
|
||||
// }
|
||||
// }
|
||||
// add_action('wp', 'cronstarter_activation');
|
||||
|
||||
add_filter( 'cron_schedules', function ( $schedules ) {
|
||||
$schedules['every-15-minutes'] = array(
|
||||
'interval' => 15 * MINUTE_IN_SECONDS,
|
||||
'display' => __( 'Every 15 minutes' )
|
||||
);
|
||||
return $schedules;
|
||||
} );
|
||||
|
||||
|
||||
function cronstarter_activate() {
|
||||
if (! wp_next_scheduled ( 'check_version_cronjob' )) {
|
||||
wp_schedule_event(time(), 'every-15-minutes', 'check_version_cronjob');
|
||||
}
|
||||
}
|
||||
register_activation_hook(__FILE__, 'cronstarter_activate');
|
||||
|
||||
|
||||
// ---- unschedule event upon plugin deactivation
|
||||
function cronstarter_deactivate() {
|
||||
$timestamp = wp_next_scheduled ('check_version_cronjob');
|
||||
wp_unschedule_event ($timestamp, 'check_version_cronjob');
|
||||
}
|
||||
register_deactivation_hook (__FILE__, 'cronstarter_deactivate');
|
||||
|
||||
|
||||
function checkingVersion(){
|
||||
$logFile = ABSPATH ."log.txt";
|
||||
//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 = [];
|
||||
|
||||
// get all plugins
|
||||
$allPlugin = get_plugins();
|
||||
//get all updatable plugins
|
||||
$plugin_to_update = get_plugin_updates();
|
||||
|
||||
//date update
|
||||
$date = new DateTime();
|
||||
$date = $date->setTimezone(new DateTimeZone('Europe/Paris'));
|
||||
$date = $date->format('d/m/Y H:i:s');
|
||||
$data['updateDate'] = $date;
|
||||
|
||||
//get active plugins
|
||||
$active_plugins = wp_get_active_and_valid_plugins();
|
||||
foreach ($active_plugins as $key => $path) {
|
||||
$plugin_data = get_plugin_data($path);
|
||||
$data['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['plugins'][$plugin_data['Name']]['Maj'] = $plugin_to_update[plugin_basename( $path )]->update->new_version;
|
||||
} else {
|
||||
$data['plugins'][$plugin_data['Name']]['Maj'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
//get non active plugins
|
||||
foreach ($allPlugin as $key => $value) {
|
||||
if (is_plugin_inactive($key)) {
|
||||
$data['inactiveplugins'][$value['Name']] = true;
|
||||
}
|
||||
}
|
||||
//get installed wordpress version
|
||||
$currentversion = get_bloginfo('version');
|
||||
$data['Wordpress']['Version'] = $currentversion;
|
||||
|
||||
//call wordpress api to check if our version is updatable
|
||||
$url = 'https://api.wordpress.org/core/version-check/1.7/';
|
||||
$response = wp_remote_get($url);
|
||||
$json = $response['body'];
|
||||
$obj = json_decode($json);
|
||||
|
||||
|
||||
if (($obj->offers[0]->current) > $currentversion) {
|
||||
$data['Wordpress']['Maj'] = $obj->offers[0]->current;
|
||||
} else {
|
||||
$data['Wordpress']['Maj'] = false;
|
||||
}
|
||||
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
||||
$data['HTTPS'] = true;
|
||||
} else {
|
||||
$data['HTTPS'] = false;
|
||||
}
|
||||
|
||||
//get mu plugins / check security plugin
|
||||
$muPlugins = get_mu_plugins();
|
||||
if (isset($muPlugins['admin-useraccount-security.php'])) {
|
||||
$data['SecurityPlugin'] = $muPlugins['admin-useraccount-security.php']['Version'];
|
||||
} else {
|
||||
$data['SecurityPlugin'] = false;
|
||||
}
|
||||
//check if .git folder is present
|
||||
$pathgit = ABSPATH .'.git';
|
||||
if (is_dir($pathgit)) {
|
||||
$data['Git'] = true;
|
||||
} else {
|
||||
$data['Git'] = false;
|
||||
}
|
||||
|
||||
//check how many untracked/modified files
|
||||
if(file_exists(WP_PLUGIN_DIR . '/revisr')) {
|
||||
require WP_PLUGIN_DIR . '/revisr/classes/class-revisr-git.php';
|
||||
$revisr = new Revisr_Git();
|
||||
$countUntracked = $revisr->count_untracked();
|
||||
$data['Revisr'] = $countUntracked;
|
||||
}
|
||||
|
||||
//Check logs
|
||||
$patherror = realpath(ABSPATH .'/..');
|
||||
|
||||
$files = glob($patherror.'/*.log');
|
||||
if(count($files) == 0){
|
||||
$data['Logs']['Exists'] = false;
|
||||
} else {
|
||||
$data['Logs']['Exists'] = true;
|
||||
foreach ($files as $filename){
|
||||
$data['Logs'][$filename] = filesize($filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//path to all the files and creates if necessary
|
||||
$pathfolder = ABSPATH .'version-checker';
|
||||
$filepath = ABSPATH .'version-checker/versions.json';
|
||||
$htaccesspath = ABSPATH .'version-checker/.htaccess';
|
||||
$htpasswdpath = ABSPATH .'version-checker/.htpasswd';
|
||||
if (!file_exists($pathfolder)) {
|
||||
mkdir($pathfolder, 0777, true);
|
||||
}
|
||||
if (!file_exists($htaccesspath)) {
|
||||
$htaccess = 'AuthName "Protected Version Checker"
|
||||
AuthType Basic
|
||||
AuthUserFile '.$htpasswdpath.'
|
||||
Require valid-user';
|
||||
file_put_contents($htaccesspath, $htaccess);
|
||||
$htpasswd = 'ldc-web:$1$LvylAO22$R72WuB1w8OpNdcISgXBZU.';
|
||||
file_put_contents($htpasswdpath, $htpasswd);
|
||||
}
|
||||
file_put_contents($filepath, json_encode($data));
|
||||
|
||||
if (! wp_next_scheduled ( 'check_version_cronjob' )) {
|
||||
wp_schedule_event(time(), 'every-15-minutes', 'check_version_cronjob');
|
||||
}
|
||||
}
|
||||
|
||||
add_action ('check_version_cronjob', 'checkingVersion');
|
||||
|
||||
?>
|
||||
|
|
@ -97,3 +97,6 @@ if ( !defined('ABSPATH') )
|
|||
require_once(ABSPATH . 'wp-settings.php');
|
||||
|
||||
set_time_limit(600);
|
||||
|
||||
// LDC WEB STATUS CHECKER
|
||||
define('PROJECT_UUID', '3b347323-7541-42fe-8fbb-5f2995d0c6d3');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue