' . esc_html__('Terminal', 'wpterm') . ''; return $links; } add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'wpterm_settings_link'); /* ================================================================== */ function wpterm_js_insert() { /** * Insert our JS and CSS files in the footer for the admin... */ if (! current_user_can('install_plugins') || ! is_main_site() ) { return; } /**...when viewing WPTerm pages only. */ if (! empty( $_GET['page'] ) && $_GET['page'] == 'wpterm') { /** * Load terminal JS code only if we are requesting the terminal tab. */ if (! empty( $_GET['wptermtab'] ) && $_GET['wptermtab'] == 'terminal') { wp_enqueue_script( 'wpterm_script2', plugin_dir_url( __FILE__ ) .'wpterm-terminal.js', array('jquery') ); } else { wp_enqueue_script( 'wpterm_script', plugin_dir_url( __FILE__ ) .'wpterm.js', array('jquery') ); } wp_enqueue_style( 'wpterm_style', plugin_dir_url( __FILE__ ) . 'wpterm.css' ); } } add_action('admin_footer', 'wpterm_js_insert'); /* ================================================================== */ function wpterm_admin_menu() { /** * Append WPTerm menu to the "Tools" menu. */ if (! is_main_site() ) { return; } global $menu_hook; require_once( plugin_dir_path(__FILE__) . 'wpterm-help.php'); $menu_hook = add_submenu_page( 'tools.php', 'WPTerm', 'WPTerm', /** * In a multisite environment, only the superadmin will be able to access WPTerm. */ 'install_plugins', 'wpterm', 'wpterm_main_menu' ); /** * Load contextual help. */ add_action('load-' . $menu_hook, 'wpterm_help'); } add_action('admin_menu', 'wpterm_admin_menu'); /* ================================================================== */ function wpterm_main_menu() { /** * Show the selected tab and page. */ // If the terminal is password protected, // check if the user is authenticated: if (! wpterm_is_allowed() ) { return; } $tab = ['terminal', 'settings', 'about']; // Make sure $_GET['wptermtab']'s value is okay, // otherwise set it to its default 'terminal' value: if (! isset( $_GET['wptermtab'] ) || ! in_array( $_GET['wptermtab'], $tab ) ) { $_GET['wptermtab'] = 'terminal'; } $wpterm_menu = "wpterm_menu_{$_GET['wptermtab']}"; $wpterm_menu(); } /* ================================================================== */ function wpterm_menu_terminal() { /** * Display the terminal. */ /** * If DISALLOW_FILE_MODS is set, we don't allow access to the terminal. */ if ( defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS ) { wp_die( esc_html__('Sorry, but DISALLOW_FILE_MODS is set, hence I refuse to run.', 'wpterminal') ); } // Fetch our options. $wpterm_options = wpterm_menu_get_settings(); // Retrieve the current user info (name, home dir etc) $userinfo = posix_getpwuid( posix_getuid() ); // Get current working directory: if ( $wpterm_options['user-home'] == 'abspath') { // WP current dir (a.k.a. ABSPATH): $cwd = htmlspecialchars( rtrim( ABSPATH, '/') ); } else { // Linux home dir: $cwd = htmlspecialchars( rtrim( $userinfo['dir'], '/') ); } $last_login = ''; $kernel_info = ''; // Get/set last login: if (! empty( $wpterm_options['last_login'] ) ) { list ( $time, $user, $ip ) = explode( ':', $wpterm_options['last_login'], 3 ); // Try to get hostname from its IP: if (! $host = gethostbyaddr( $ip ) ) { $host = $ip; } $date = date_i18n( 'D M d H:i:s Y', $time ); // We'll display this along the "welcome" message: $last_login = sprintf( __('Last login: %s, %s from %s', 'wpterm'), esc_html( $user ), $date, esc_html( $host ) . '\n' ); } // Get the current user (system and WordPress) + his/her IP: $current_user = wp_get_current_user(); $wpuser = esc_html( $current_user->user_login ); $user = esc_html( $userinfo['name'] ); $ip = esc_html( $_SERVER['REMOTE_ADDR'] ); $time = time(); // We refuse to run if we're root (unless stated otherwise): if ( $user == 'root' && ! defined('THOU_SHALT_NOT_RUN_AS_ROOT') ) { ?>

WPTerm

"; $notice.= "
    "; $notice.= "
  1. " . esc_html__( "Just like a terminal, WPTerm lets you do almost everything you want (e.g., changing file permissions, viewing network connections or current processes etc). That's great, but if you aren't familiar with Unix shell commands, you can also damage your blog.", "wpterm") . "
    " . esc_html__( "Therefore, each time you use WPTerm, please follow this rule of thumb: if you don't know what you're doing, don't do it!", "wpterm") . "
  2. "; $notice.= "
  3. " . esc_html__( 'Take the time to password protect the access to WPTerm. Click on the contextual "Help" menu tab located in the upper right corner to get more details about how to enable this feature (or type `help` from WPTerm prompt).', "wpterm" ) . "
  4. "; $notice.= "
  5. " . esc_html__( "Do not try to run interactive commands, you can't (most would not run anyway because the TERM environment variable is not set). If you run one by mistake and are stuck at the prompt, press CTRL-C.", "wpterm" ) . "
  6. "; $notice.= "
"; $notice.= esc_html__( "If you want to read this notice again, type `notice` from WPTerm prompt.", "wpterm" ); if ( empty( $wpterm_options['version'] ) ) { $style = ''; } else { $style = 'style="display:none" '; } // Display notice: ?>
id="wpterm-warning" class="error notice">

', '' ) ?>

' . esc_html__('Because your current locale is RTL (Right To Left script), the terminal will not work well with your IE/Edge browser. Consider using another browser that is compatible (Firefox, Chrome, Opera or Safari).', 'wpterm') .'

'; } ?>

WPTerm

" style="cursor:pointer">     " style="cursor:pointer">     " style="cursor:pointer">

' . esc_html__('Your changes have been saved.', 'wpterm') .'

'; } // Fetch, verify and sanitize the current settings: $wpterm_options = wpterm_menu_get_settings(); ?>

WPTerm


red).', 'wpterm' ), 'ffffff' ) ?>

red).', 'wpterm' ), '3465A4' ) ?>

px     

Consolas,Monaco,monospace)', 'wpterm' ) ?>


cd $ABSPATH' ) ?>




3000 ) { $wpterm_options['scrollback'] = 512; } } else { $wpterm_options['scrollback'] = 512; } if (! isset( $wpterm_options['visual-bell'] ) || $wpterm_options['visual-bell'] == 1 ) { $wpterm_options['visual-bell'] = 1; } else { $wpterm_options['visual-bell'] = 0; } if (! empty( $wpterm_options['audible-bell'] ) ) { $wpterm_options['audible-bell'] = 1; } else { $wpterm_options['audible-bell'] = 0; } return $wpterm_options; } /* ================================================================== */ function wpterm_menu_save_settings() { // Check and save the terminal settings: $wpterm_options = get_option('wpterm_options'); if ( empty( $_POST['font-color'] ) ) { $wpterm_options['font-color'] = 'ffffff'; } else { // Make sure $_POST['font-color'] contains only word characters: $wpterm_options['font-color'] = preg_replace( '/\W/', '', $_POST['font-color'] ); } if ( empty( $_POST['background-color'] ) ) { $wpterm_options['background-color'] = '3465A4'; } else { // Make sure $_POST['background-color'] contains only word characters: $wpterm_options['background-color'] = preg_replace( '/\W/', '', $_POST['background-color'] ); } // Make sure $_POST['font-size'] is an integer between 9 and 20, // otherwise set it to 13, its default value: if (! isset( $_POST['font-size'] ) || ! preg_match( '/^(?:9|1[0-9]|20)$/', $_POST['font-size'] ) ) { $wpterm_options['font-size'] = 13; } else { $wpterm_options['font-size'] = (int)$_POST['font-size']; } if (! empty( $_POST['bold-font'] ) ) { $wpterm_options['bold-font'] = 1; } else { $wpterm_options['bold-font'] = 0; } // Make sure $_POST['font-family'] contains only letters, commas, spaces, single and double quotes: if (! empty( $_POST['font-family'] ) ) { $wpterm_options['font-family'] = preg_replace( '/[^\'" ,a-zA-Z]/', '', $_POST['font-family'] ); $wpterm_options['font-family'] = trim( $wpterm_options['font-family'], ' ,' ); } if ( empty( $_POST['font-family'] ) ) { $wpterm_options['font-family'] = 'Consolas,Monaco,monospace'; } // Make sure the value of $_POST['welcome-message'] is 'wpterm', 'cowsay' or 'tux', // otherwise set it to 'wpterm', its default value: if ( empty( $_POST['welcome-message'] ) || ! preg_match( '/^(?:wpterm|cowsay|tux)$/', $_POST['welcome-message'] ) ) { $wpterm_options['welcome-message'] = 'wpterm'; } else { $wpterm_options['welcome-message'] = htmlspecialchars( $_POST['welcome-message'] ); } // Make sure the value of $_POST['php-function'] is 'exec', 'shell_exec', 'system', 'popen' or 'passthru', // otherwise set it to 'exec', its default value: if ( empty( $_POST['php-function'] ) || ! preg_match( '/^(?:exec|shell_exec|system|passthru|popen)$/', $_POST['php-function'] ) ) { $wpterm_options['php-function'] = 'exec'; } else { $wpterm_options['php-function'] = htmlspecialchars( $_POST['php-function'] ); } if ( empty( $_POST['tab-completion'] ) || $_POST['tab-completion'] != 1 ) { $wpterm_options['tab-completion'] = 0; } else { $wpterm_options['tab-completion'] = 1; } // Make sure the value of $_POST['user-home'] is 'abspath' or 'homedir', // otherwise set it to 'abspath', its default value: if ( empty( $_POST['user-home'] ) || ! preg_match( '/^(?:abspath|homedir)$/', $_POST['user-home'] ) ) { $wpterm_options['user-home'] = 'abspath'; } else { $wpterm_options['user-home'] = htmlspecialchars( $_POST['user-home'] ); } // Make sure $_POST['scrollback'] is an integer between 1 and 3,000, // otherwise set it to 512, its default value: if (! empty( $_POST['scrollback'] ) ) { $wpterm_options['scrollback'] = (int) $_POST['scrollback']; if ( $wpterm_options['scrollback'] < 1 || $wpterm_options['scrollback'] > 3000 ) { $wpterm_options['scrollback'] = 512; } } else { $wpterm_options['scrollback'] = 512; } if (! empty( $_POST['audible-bell'] ) ) { $wpterm_options['audible-bell'] = 1; } else { $wpterm_options['audible-bell'] = 0; } if (! empty( $_POST['visual-bell'] ) ) { $wpterm_options['visual-bell'] = 1; } else { $wpterm_options['visual-bell'] = 0; } // Save current version too (we'll likely need it when updating the plugin): $wpterm_options['version'] = WPTERM_VERSION; update_option( 'wpterm_options', $wpterm_options ); } /* ================================================================== */ function wpterm_menu_about() { if ( file_exists( plugin_dir_path(__FILE__) . 'LICENSE.TXT' ) ) { $gpl3 = file_get_contents( plugin_dir_path(__FILE__) . 'LICENSE.TXT' ); } else { $gpl3 = esc_html__( 'Error: cannot open LICENSE.TXT!', 'wpterm' ); } ?>

WPTerm

WPTerm v

© Jerome Bruandet







 

WPTerm