Skip to content

Instantly share code, notes, and snippets.

@jpjuliao
Last active May 31, 2019 18:00
Show Gist options
  • Save jpjuliao/18a50fd300e991bcc2cb8f98365dab06 to your computer and use it in GitHub Desktop.
Save jpjuliao/18a50fd300e991bcc2cb8f98365dab06 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin name: PHP Execute External Programs
* Description: Run terminal commands. Usage: add querystring 'cmd' on any admin url to load the console
* Author: Juan Pablo Juliao
* Version: 1.0
*/
if (!defined('ABSPATH')) exit;
add_action('current_screen', 'php_system_commands');
function php_system_commands(){
if ( !current_user_can('manage_options') ) {
return;
}
if ( !isset($_GET['cmd']) ) {
return;
}
$theme_path = get_stylesheet_directory();
$cmd = isset($_POST['cmd']) ? $_POST['cmd'] : "cd $theme_path;\r\nls;";
?>
<form method="POST" action="">
<textarea name="cmd" rows="5"><?php echo $cmd ?></textarea>
<input type="submit" value="send">
</form>
<style>
body {
background: #000;
color: #fff;
}
textarea,
input[type="text"] {
width: 100%;
padding: 3px;
}
</style>
<?php
if (isset($_POST['cmd'])){
echo '<pre>';
exec('cd ..;'.$_POST['cmd'], $out);
foreach($out as $line) {
echo $line.PHP_EOL;
}
echo '</pre>';
}
die;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment