Advertisement
alessandromendozza

Untitled

Jan 5th, 2018
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 42.92 KB | None | 0 0
  1. <?php
  2. /*
  3. Version 1.3
  4. Copyright 2012-2016 - Amaury Balmer (amaury@beapi.fr)
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License, version 2, as
  8. published by the Free Software Foundation.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  18. */
  19.  
  20. // Suppress DateTime warnings
  21. date_default_timezone_set( @date_default_timezone_get() );
  22.  
  23. // Auth only for PHP/Apache
  24. if ( strpos( php_sapi_name(), 'cgi' ) === false ) {
  25.     define( 'LOGIN', 'wordpress' );
  26.     define( 'PASSWORD', 'wordpress' );
  27.  
  28.     if ( ! isset( $_SERVER['PHP_AUTH_USER'] ) || ( $_SERVER['PHP_AUTH_PW'] != PASSWORD || $_SERVER['PHP_AUTH_USER'] != LOGIN ) ) {
  29.         header( 'WWW-Authenticate: Basic realm="Authentification"' );
  30.         header( 'HTTP/1.0 401 Unauthorized' );
  31.         echo 'Authentification failed';
  32.         exit();
  33.     }
  34. }
  35.  
  36. function phpwpinfo() {
  37.     $info = new PHP_WP_Info();
  38.     $info->init_all_tests();
  39. }
  40.  
  41. /**
  42.  * TODO: Use or not session for save DB configuration
  43.  */
  44. class PHP_WP_Info {
  45.     private $debug_mode = true;
  46.     private $php_version = '5.2.4';
  47.     private $mysqli_version = '5.0';
  48.  
  49.     private $db_infos = array();
  50.     private $db_link = null;
  51.  
  52.     public function __construct() {
  53.         @session_start();
  54.  
  55.         if ( $this->debug_mode == true ) {
  56.             ini_set( 'display_errors', 1 );
  57.             ini_set( 'log_errors', 1 );
  58.             ini_set( 'error_log', dirname( __FILE__ ) . '/error_log.txt' );
  59.             error_reporting( E_ALL );
  60.         }
  61.  
  62.         // Check GET for phpinfo
  63.         if ( isset( $_GET ) && isset( $_GET['phpinfo'] ) && $_GET['phpinfo'] == 'true' ) {
  64.             phpinfo();
  65.             exit();
  66.         }
  67.  
  68.         // Check GET for self-destruction
  69.         if ( isset( $_GET ) && isset( $_GET['self-destruction'] ) && $_GET['self-destruction'] == 'true' ) {
  70.             @unlink( __FILE__ );
  71.             clearstatcache();
  72.             if ( is_file( __FILE__ ) ) {
  73.                 die( 'Self-destruction KO ! Sorry, but you must remove me manually !' );
  74.             }
  75.             die( 'Self-destruction OK !' );
  76.         }
  77.  
  78.         $this->_check_request_mysql();
  79.         $this->_check_request_adminer();
  80.         $this->_check_request_phpsecinfo();
  81.         $this->_check_request_wordpress();
  82.     }
  83.  
  84.     public function init_all_tests() {
  85.         $this->get_header();
  86.  
  87.         $this->test_versions();
  88.         $this->test_php_config();
  89.         $this->test_php_extensions();
  90.         $this->test_mysqli_config();
  91.         $this->test_apache_modules();
  92.         $this->test_form_mail();
  93.  
  94.         $this->get_footer();
  95.     }  
  96.  
  97.     /**
  98.      * Main test, check if php/mysql/git are installed and right version for WP
  99.      */
  100.     public function test_versions() {
  101.         $this->html_table_open( 'General informations & tests PHP/MySQL Version', '', 'Required', 'Recommended', 'Current' );
  102.  
  103.         // Webserver used
  104.         $this->html_table_row( 'Web server', $this->_get_current_webserver(), '', '', 'info', 3 );
  105.  
  106.         // Test PHP Version
  107.         $sapi_type = php_sapi_name();
  108.         if ( strpos( $sapi_type, 'cgi' ) !== false ) {
  109.             $this->html_table_row( 'PHP Type', 'CGI with Apache Worker or another webserver', '', '','success', 3 );
  110.         } else {
  111.             $this->html_table_row( 'PHP Type', 'Apache Module (low performance)', '', '', 'warning', 3 );
  112.         }
  113.  
  114.         // Test PHP Version
  115.         $php_version = phpversion();
  116.         if ( version_compare( $php_version, $this->php_version, '>=' ) ) {
  117.             $this->html_table_row( 'PHP Version', $this->php_version, '> 5.4', $php_version, 'success' );
  118.         } else {
  119.             $this->html_table_row( 'PHP Version', $this->php_version, '> 5.4', $php_version, 'error' );
  120.         }
  121.  
  122.         // Test MYSQL Client extensions/version.
  123.         if ( ! extension_loaded( 'mysqli' ) || ! is_callable( 'mysqli_connect' ) ) {
  124.             $this->html_table_row( 'PHP MySQLi Extension', 'Yes', 'Yes', 'Not installed', 'error' );
  125.         } else {
  126.             $this->html_table_row( 'PHP MySQLi Extension', 'Yes', 'Yes', 'Installed', 'success' );
  127.             $this->html_table_row( 'PHP MySQLi Client Version', $this->mysqli_version, '> 5.5', mysqli_get_client_info(), 'info' );
  128.         }
  129.  
  130.         // Test MySQL Server Version
  131.         if ( $this->db_link != false && is_callable( 'mysqli_get_server_info' ) ) {
  132.             $mysqli_version = preg_replace( '/[^0-9.].*/', '', mysqli_get_server_info( $this->db_link ) );
  133.             if ( version_compare( $mysqli_version, $this->mysqli_version, '>=' ) ) {
  134.                 $this->html_table_row( 'MySQL Version', $this->mysqli_version, '> 5.5', $mysqli_version, 'success' );
  135.             } else {
  136.                 $this->html_table_row( 'MySQL Version', $this->mysqli_version, '> 5.5', $mysqli_version, 'error' );
  137.             }
  138.         } else {
  139.             // Show MySQL Form
  140.             $this->html_form_mysql( ( $this->db_infos === false ) ? true : false );
  141.  
  142.             $this->html_table_row( 'MySQL Version', $this->mysqli_version, '-', 'Not available, needs credentials.', 'warning' );
  143.         }
  144.  
  145.         // Test if the server is connected to the server by attempt to find the IP(v4) of www.google.fr
  146.         if( gethostbyname('www.google.fr') != 'www.google.fr' ) {
  147.             $this->html_table_row('Internet connectivity (Google)', 'No', 'Yes', 'Yes', 'success');
  148.         } else {
  149.             $this->html_table_row('Internet connectivity (Google)', 'No', 'Yes', 'No', 'error');
  150.         }
  151.  
  152.         // Test if the command 'git' exists, so it tests if Git is installed
  153.         if ($this->_command_exists('git') == 1 ) {
  154.             $this->html_table_row('GIT is installed?', 'No', 'Yes', 'Yes');
  155.         } else {
  156.             $this->html_table_row('GIT is installed?', 'No', 'Yes', 'No', 'error');
  157.         }
  158.  
  159.         $this->html_table_row('Remote IP via $_SERVER["REMOTE_ADDR"]', '', '', $_SERVER["REMOTE_ADDR"], 'info');
  160.  
  161.         if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ) {
  162.             $this->html_table_row('Remote IP via $_SERVER["HTTP_X_FORWARDED_FOR"]', '', '', $_SERVER["HTTP_X_FORWARDED_FOR"], 'info');
  163.         }
  164.  
  165.         if ( isset($_SERVER["HTTP_X_FORWARDED"]) ) {
  166.             $this->html_table_row('Remote IP via $_SERVER["HTTP_X_FORWARDED"]', '', '', $_SERVER["HTTP_X_FORWARDED"], 'info');
  167.         }
  168.  
  169.         if ( isset($_SERVER["HTTP_CLIENT_IP"]) ) {
  170.             $this->html_table_row('Remote IP via $_SERVER["HTTP_CLIENT_IP"]', '', '', $_SERVER["HTTP_CLIENT_IP"], 'info');
  171.         }
  172.  
  173.         $this->html_table_row('Real remote IP via AJAX call', '', '', '... js loading ...', 'warning realip');
  174.     }
  175.        
  176.     public function test_php_extensions() {
  177.         $this->html_table_open( 'PHP Extensions', '', 'Required', 'Recommended','Current' );
  178.  
  179.         /**
  180.          * Check GD and Imagick like WordPress does.
  181.          */
  182.         $gd = extension_loaded( 'gd' ) && function_exists( 'gd_info' );
  183.         $imagick = extension_loaded( 'imagick' ) &&  class_exists( 'Imagick', false ) &&  class_exists( 'ImagickPixel', false ) && version_compare( phpversion( 'imagick' ), '2.2.0', '>=' );
  184.  
  185.         // GD/Imagick lib.
  186.         if ( $gd ) {
  187.             $this->html_table_row( 'Image manipulation (GD)', 'Yes', 'Yes', 'Installed', 'success' );
  188.         }
  189.  
  190.         if ( $imagick ) {
  191.             $this->html_table_row( 'Image manipulation (Imagick)', 'Yes', 'Yes', 'Installed', 'success' );
  192.         }
  193.  
  194.         if ( ! $gd && ! $imagick ) {
  195.             $this->html_table_row( 'Image manipulation (GD, Imagick)', 'Yes', 'Yes', 'Not installed', 'error' );
  196.         }
  197.  
  198.         if ( ! class_exists( 'ZipArchive' ) ) {
  199.             $this->html_table_row( 'ZIP', 'No', 'Yes', 'Not installed', 'info' );
  200.         } else {
  201.             $this->html_table_row( 'ZIP', 'No', 'Yes', 'Installed', 'success' );
  202.         }
  203.  
  204.         if ( ! is_callable( 'ftp_connect' ) ) {
  205.             $this->html_table_row( 'FTP', 'No', 'Yes', 'Not installed', 'info' );
  206.         } else {
  207.             $this->html_table_row( 'FTP', 'No', 'Yes', 'Installed', 'success' );
  208.         }
  209.  
  210.         if ( ! is_callable( 'exif_read_data' ) ) {
  211.             $this->html_table_row( 'Exif', 'No', 'Yes', 'Not installed', 'info' );
  212.         } else {
  213.             $this->html_table_row( 'Exif', 'No', 'Yes', 'Installed', 'success' );
  214.         }
  215.  
  216.         if ( ! is_callable( 'curl_init' ) ) {
  217.             $this->html_table_row( 'CURL', 'Yes*', 'Yes', 'Not installed', 'warning' );
  218.         } else {
  219.             $this->html_table_row( 'CURL', 'Yes*', 'Yes', 'Installed', 'success' );
  220.         }
  221.        
  222.         if ( is_callable( 'opcache_reset' ) ) {
  223.             $this->html_table_row( 'Opcode (Zend OPcache, APC, Xcache, eAccelerator or Zend Optimizer)', 'No', 'Yes', 'Zend OPcache Installed', 'success' );
  224.         } elseif ( is_callable( 'eaccelerator_put' ) ) {
  225.             $this->html_table_row( 'Opcode (Zend OPcache, APC, Xcache, eAccelerator or Zend Optimizer)', 'No', 'Yes', 'eAccelerator Installed', 'success' );
  226.         } elseif ( is_callable( 'xcache_set' ) ) {
  227.             $this->html_table_row( 'Opcode (Zend OPcache, APC, Xcache, eAccelerator or Zend Optimizer)', 'No', 'Yes', 'XCache Installed', 'success' );
  228.         } elseif ( is_callable( 'apc_store' ) ) {
  229.             $this->html_table_row( 'Opcode (Zend OPcache, APC, Xcache, eAccelerator or Zend Optimizer)', 'No', 'Yes', 'APC Installed', 'success' );
  230.         } elseif ( is_callable( 'zend_optimizer_version' ) ) {
  231.             $this->html_table_row( 'Opcode (Zend OPcache, APC, Xcache, eAccelerator or Zend Optimizerr)', 'No', 'Yes', 'Zend Optimizer Installed', 'success' );
  232.         } else {
  233.             $this->html_table_row( 'Opcode (Zend OPcache, APC, Xcache, eAccelerator or Zend Optimizer)', 'No', 'Yes', 'Not installed', 'warning' );
  234.         }
  235.  
  236.         if ( ! class_exists( 'Memcache' ) ) {
  237.             $this->html_table_row( 'Memcache', 'No', 'Yes', 'Not installed', 'info' );
  238.         } else {
  239.             $this->html_table_row( 'Memcache', 'No', 'Yes', 'Installed', 'success' );
  240.         }
  241.        
  242.         if ( ! class_exists( 'Memcached' ) ) {
  243.             $this->html_table_row( 'Memcached', 'No', 'Yes', 'Not installed', 'info' );
  244.         } else {
  245.             $this->html_table_row( 'Memcached', 'No', 'Yes', 'Installed', 'success' );
  246.         }
  247.  
  248.         if ( ! is_callable( 'mb_substr' ) ) {
  249.             $this->html_table_row( 'Multibyte String', 'No', 'Yes', 'Not installed', 'info' );
  250.         } else {
  251.             $this->html_table_row( 'Multibyte String', 'No', 'Yes', 'Installed', 'success' );
  252.         }
  253.  
  254.         if ( ! class_exists( 'tidy' ) ) {
  255.             $this->html_table_row( 'Tidy', 'No', 'Yes', 'Not installed', 'info' );
  256.         } else {
  257.             $this->html_table_row( 'Tidy', 'No', 'Yes', 'Installed', 'success' );
  258.         }
  259.  
  260.         if ( ! is_callable( 'finfo_open' ) && ! is_callable( 'mime_content_type' ) ) {
  261.             $this->html_table_row( 'Mime type', 'Yes*', 'Yes', 'Not installed', 'warning' );
  262.         } else {
  263.             $this->html_table_row( 'Mime type', 'Yes*', 'Yes', 'Installed', 'success' );
  264.         }
  265.  
  266.         if ( ! is_callable( 'hash' ) && ! is_callable( 'mhash' ) ) {
  267.             $this->html_table_row( 'Hash', 'No', 'Yes', 'Not installed', 'info' );
  268.         } else {
  269.             $this->html_table_row( 'Hash', 'No', 'Yes', 'Installed', 'success' );
  270.         }
  271.  
  272.         if ( ! is_callable( 'set_time_limit' ) ) {
  273.             $this->html_table_row( 'set_time_limit', 'No', 'Yes', 'Not Available', 'info' );
  274.         } else {
  275.             $this->html_table_row( 'set_time_limit', 'No', 'Yes', 'Available', 'success' );
  276.         }
  277.  
  278.         $this->html_table_close( '(*) Items with an asterisk are not required by WordPress, but it is highly recommended by me!' );
  279.     }
  280.  
  281.     public function test_apache_modules() {
  282.         if ( $this->_get_current_webserver() != 'Apache' ) {
  283.             return false;
  284.         }
  285.  
  286.         $current_modules = (array) $this->_get_apache_modules();
  287.         $modules         = array(
  288.             'mod_deflate' => false,
  289.             'mod_env' => false,
  290.             'mod_expires' => false,
  291.             'mod_headers' => false,
  292.             'mod_filter' => false,
  293.             'mod_mime' => false,
  294.             'mod_rewrite' => true,
  295.             'mod_setenvif' => false,
  296.         );
  297.  
  298.         $this->html_table_open( 'Apache Modules', '', 'Required', 'Recommended', 'Current' );
  299.  
  300.         foreach ( $modules as $module => $is_required ) {
  301.             $is_required = ($is_required == true ) ? 'Yes' : 'No'; // Boolean to Yes/NO
  302.  
  303.             $name = ucfirst( str_replace( 'mod_', '', $module ) );
  304.             if ( ! in_array( $module, $current_modules ) ) {
  305.                 $this->html_table_row( $name, $is_required, 'Recommended', 'Not installed', 'error' );
  306.             } else {
  307.                 $this->html_table_row( $name, $is_required, 'Recommended', 'Installed', 'success' );
  308.             }
  309.         }
  310.  
  311.         $this->html_table_close();
  312.  
  313.         return true;
  314.     }
  315.  
  316.     public function test_php_config() {
  317.         $this->html_table_open( 'PHP Configuration', '', 'Required', 'Recommended', 'Current' );
  318.  
  319.         $value = ini_get( 'register_globals' );
  320.         if ( strtolower( $value ) == 'on' ) {
  321.             $this->html_table_row( 'register_globals', '-', 'Off', 'On', 'warning' );
  322.         } else {
  323.             $this->html_table_row( 'register_globals', '-', 'Off', 'Off', 'success' );
  324.         }
  325.  
  326.         $value = ini_get( 'magic_quotes_runtime' );
  327.         if ( strtolower( $value ) == 'on' ) {
  328.             $this->html_table_row( 'magic_quotes_runtime', '-', 'Off', 'On', 'warning' );
  329.         } else {
  330.             $this->html_table_row( 'magic_quotes_runtime', '-', 'Off', 'Off', 'success' );
  331.         }
  332.  
  333.         $value = ini_get( 'magic_quotes_sybase' );
  334.         if ( strtolower( $value ) == 'on' ) {
  335.             $this->html_table_row( 'magic_quotes_sybase', '-', 'Off', 'On', 'warning' );
  336.         } else {
  337.             $this->html_table_row( 'magic_quotes_sybase', '-', 'Off', 'Off', 'success' );
  338.         }
  339.  
  340.         $value = ini_get( 'register_long_arrays' );
  341.         if ( strtolower( $value ) == 'on' ) {
  342.             $this->html_table_row( 'register_long_arrays', '-', 'Off', 'On', 'warning' );
  343.         } else {
  344.             $this->html_table_row( 'register_long_arrays', '-', 'Off', 'Off', 'success' );
  345.         }
  346.  
  347.         $value = ini_get( 'register_argc_argv ' );
  348.         if ( strtolower( $value ) == 'on' ) {
  349.             $this->html_table_row( 'register_argc_argv ', '-', 'Off', 'On', 'warning' );
  350.         } else {
  351.             $this->html_table_row( 'register_argc_argv ', '-', 'Off', 'Off', 'success' );
  352.         }
  353.  
  354.         $value = $this->return_bytes( ini_get( 'memory_limit' ) );
  355.         if ( intval( $value ) < $this->return_bytes('64M') ) {
  356.             $this->html_table_row( 'memory_limit', '64 MB', '256 MB', $this->_format_bytes($value), 'error' );
  357.         } else {
  358.             $status = (intval( $value ) >= $this->return_bytes('256M')) ? 'success' : 'warning';
  359.             $this->html_table_row( 'memory_limit', '64 MB', '256 MB', $this->_format_bytes($value), $status );
  360.         }
  361.        
  362.         $value = ini_get( 'max_input_vars' );
  363.         if ( intval( $value ) < 1000 ) {
  364.             $this->html_table_row( 'max_input_vars', '1000', '5000', $value, 'error' );
  365.         } else {
  366.             $status = (intval( $value ) >= 5000) ? 'success' : 'warning';
  367.             $this->html_table_row( 'max_input_vars', '1000', '5000', $value, $status );
  368.         }
  369.  
  370.         $value = ini_get( 'file_uploads' );
  371.         if ( strtolower( $value ) == 'on' || $value == '1' ) {
  372.             $this->html_table_row( 'file_uploads', 'On', 'On', 'On', 'success' );
  373.         } else {
  374.             $this->html_table_row( 'file_uploads', 'On', 'On', 'Off', 'error' );
  375.         }
  376.  
  377.         $value = $this->return_bytes( ini_get( 'upload_max_filesize' ) );
  378.         if ( intval( $value ) < $this->return_bytes('32M') ) {
  379.             $this->html_table_row( 'upload_max_filesize', '32 MB', '128 MB', $this->_format_bytes($value), 'error' );
  380.         } else {
  381.             $status = (intval( $value ) >= $this->return_bytes('128M')) ? 'success' : 'warning';
  382.             $this->html_table_row( 'upload_max_filesize', '32 MB', '128 MB', $this->_format_bytes($value), $status );
  383.         }
  384.  
  385.         $value = $this->return_bytes( ini_get( 'post_max_size' ) );
  386.         if ( intval( $value ) < $this->return_bytes('32M') ) {
  387.             $this->html_table_row( 'post_max_size', '32 MB', '128 MB', $this->_format_bytes($value), 'warning' );
  388.         } else {
  389.             $status = (intval( $value ) >= $this->return_bytes('128M')) ? 'success' : 'warning';
  390.             $this->html_table_row( 'post_max_size', '32 MB', '128 MB', $this->_format_bytes($value), $status );
  391.         }
  392.  
  393.         $value = ini_get( 'short_open_tag' );
  394.         if ( strtolower( $value ) == 'on' ) {
  395.             $this->html_table_row( 'short_open_tag', '-', 'Off', 'On', 'warning' );
  396.         } else {
  397.             $this->html_table_row( 'short_open_tag', '-', 'Off', 'Off', 'success' );
  398.         }
  399.  
  400.         $value = ini_get( 'safe_mode' );
  401.         if ( strtolower( $value ) == 'on' ) {
  402.             $this->html_table_row( 'safe_mode', '-', 'Off', 'On', 'warning' );
  403.         } else {
  404.             $this->html_table_row( 'safe_mode', '-', 'Off', 'Off', 'success' );
  405.         }
  406.  
  407.         $value = ini_get( 'open_basedir' );
  408.         $this->html_table_row( 'open_basedir', $value, '', '', 'info', 3 );
  409.  
  410.         $value = ini_get( 'zlib.output_compression' );
  411.         $this->html_table_row( 'zlib.output_compression', $value, '', '', 'info', 3 );
  412.  
  413.         $value = ini_get( 'output_handler' );
  414.         $this->html_table_row( 'output_handler', $value, '', '', 'info', 3 );
  415.  
  416.         $value = ini_get( 'expose_php' );
  417.         if ( $value == '0' || strtolower( $value ) == 'off' || empty( $value ) ) {
  418.             $this->html_table_row( 'expose_php', '-', '0 or Off', $value, 'success' );
  419.         } else {
  420.             $this->html_table_row( 'expose_php', '-', '0 or Off', $value, 'error' );
  421.         }
  422.  
  423.         $value = ini_get( 'upload_tmp_dir' );
  424.         $this->html_table_row( 'upload_tmp_dir', $value, '', '', 'info', 3 );
  425.         if ( is_dir( $value ) && @is_writable( $value ) ) {
  426.             $this->html_table_row( 'upload_tmp_dir writable ?', '-', 'Yes', 'Yes', 'success' );
  427.         } else {
  428.             $this->html_table_row( 'upload_tmp_dir writable ?', '-', 'Yes', 'No', 'error' );
  429.         }
  430.  
  431.         $value = '/tmp/';
  432.         $this->html_table_row( 'System temp dir', $value, '', '', 'info', 3 );
  433.         if ( is_dir( $value ) && @is_writable( $value ) ) {
  434.             $this->html_table_row( 'System temp dir writable ?', '-', 'Yes', 'Yes', 'success' );
  435.         } else {
  436.             $this->html_table_row( 'System temp dir writable ?', '-', 'Yes', 'No', 'error' );
  437.         }
  438.  
  439.         $value = dirname( __FILE__ );
  440.         $this->html_table_row( 'Current dir', $value, '', '', 'info', 3 );
  441.         if ( is_dir( $value ) && @is_writable( $value ) ) {
  442.             $this->html_table_row( 'Current dir writable ?', 'Yes', 'Yes', 'Yes', 'success' );
  443.         } else {
  444.             $this->html_table_row( 'Current dir writable ?', 'Yes', 'Yes', 'No', 'error' );
  445.         }
  446.  
  447.         if ( is_callable( 'apc_store' ) ) {
  448.             $value = $this->return_bytes( ini_get( 'apc.shm_size' ) );
  449.             if ( intval( $value ) < $this->return_bytes('32M') ) {
  450.                 $this->html_table_row( 'apc.shm_size', '32 MB', '128 MB', $this->_format_bytes($value), 'error' );
  451.             } else {
  452.                 $status = (intval( $value ) >= $this->return_bytes('128M')) ? 'success' : 'warning';
  453.                 $this->html_table_row( 'apc.shm_size', '32 MB', '128 MB', $this->_format_bytes($value), $status );
  454.             }
  455.         }
  456.  
  457.         $this->html_table_close();
  458.     }
  459.  
  460.     /**
  461.      * Convert PHP variable (G/M/K) to bytes
  462.      * Source: http://php.net/manual/fr/function.ini-get.php
  463.      *
  464.      */
  465.     public function return_bytes($val) {
  466.         $val = trim($val);
  467.         $last = strtolower($val[strlen($val)-1]);
  468.         $val = (int) $val;
  469.         switch($last) {
  470.             // Le modifieur 'G' est disponible depuis PHP 5.1.0
  471.             case 'g':
  472.                 $val *= 1024;
  473.             case 'm':
  474.                 $val *= 1024;
  475.             case 'k':
  476.                 $val *= 1024;
  477.         }
  478.  
  479.         return $val;
  480.     }
  481.  
  482.     /**
  483.      * @return bool
  484.      */
  485.     public function test_mysqli_config() {
  486.         if ( $this->db_link == false ) {
  487.             return false;
  488.         }
  489.  
  490.         $this->html_table_open( 'MySQL Configuration', '', 'Required', 'Recommended', 'Current' );
  491.  
  492.         $result = mysqli_query( $this->db_link, "SHOW VARIABLES LIKE 'have_query_cache'" );
  493.         if ( $result != false ) {
  494.             while ( $row = mysqli_fetch_assoc( $result ) ) {
  495.                 if ( strtolower( $row['Value'] ) == 'yes' ) {
  496.                     $this->html_table_row( "Query cache", 'Yes*', 'Yes', 'Yes', 'success' );
  497.                 } else {
  498.                     $this->html_table_row( "Query cache", 'Yes*', 'Yes', 'False', 'error' );
  499.                 }
  500.             }
  501.         }
  502.  
  503.         $result = mysqli_query( $this->db_link, "SHOW VARIABLES LIKE 'query_cache_size'" );
  504.         if ( $result != false ) {
  505.             while ( $row = mysqli_fetch_assoc( $result ) ) {
  506.                 if ( intval( $row['Value'] ) >= $this->return_bytes('8M') ) {
  507.                     $status = (intval( $row['Value'] ) >= $this->return_bytes('64M')) ? 'success' : 'warning';
  508.                     $this->html_table_row( "Query cache size", '8M', '64MB', $this->_format_bytes( (int) $row['Value'] ), $status );
  509.                 } else {
  510.                     $this->html_table_row( "Query cache size", '8M', '64MB', $this->_format_bytes( (int) $row['Value'] ), 'error' );
  511.                 }
  512.             }
  513.         }
  514.  
  515.         $result = mysqli_query( $this->db_link, "SHOW VARIABLES LIKE 'query_cache_type'" );
  516.         if ( $result != false ) {
  517.             while ( $row = mysqli_fetch_assoc( $result ) ) {
  518.                 if ( strtolower( $row['Value'] ) == 'on' || strtolower( $row['Value'] ) == '1' ) {
  519.                     $this->html_table_row( "Query cache type", '1 or on', '1 or on', strtolower( $row['Value'] ), 'success' );
  520.                 } else {
  521.                     $this->html_table_row( "Query cache type", '1', '1', strtolower( $row['Value'] ), 'error' );
  522.                 }
  523.             }
  524.         }
  525.  
  526.         $is_log_slow_queries = false;
  527.         $result = mysqli_query( $this->db_link, "SHOW VARIABLES LIKE 'log_slow_queries'" );
  528.         if ( $result != false ) {
  529.             while ( $row = mysqli_fetch_assoc( $result ) ) {
  530.                 if ( strtolower( $row['Value'] ) == 'yes' || strtolower( $row['Value'] ) == 'on' ) {
  531.                     $is_log_slow_queries = true;
  532.                     $this->html_table_row( "Log slow queries", 'No', 'Yes', 'Yes', 'success' );
  533.                 } else {
  534.                     $is_log_slow_queries = false;
  535.                     $this->html_table_row( "Log slow queries", 'No', 'Yes', 'False', 'error' );
  536.                 }
  537.             }
  538.         }
  539.  
  540.         $result = mysqli_query( $this->db_link, "SHOW VARIABLES LIKE 'long_query_time'" );
  541.         if ( $is_log_slow_queries == true && $result != false ) {
  542.             while ( $row = mysqli_fetch_assoc( $result ) ) {
  543.                 if ( intval( $row['Value'] ) <= 2 ) {
  544.                     $this->html_table_row( "Long query time (sec)", '2', '1', ( (int) $row['Value'] ), 'success' );
  545.                 } else {
  546.                     $this->html_table_row( "Long query time (sec)", '2', '1', ( (int) $row['Value'] ), 'error' );
  547.                 }
  548.             }
  549.         }
  550.  
  551.         $this->html_table_close( '(*) Items with an asterisk are not required by WordPress, but it is highly recommended by me!' );
  552.  
  553.         return true;
  554.     }
  555.  
  556.     public function test_form_mail() {
  557.         $this->html_table_open( 'Email Configuration', '', '', '' );
  558.         $this->html_form_email();
  559.         $this->html_table_close();
  560.     }
  561.  
  562.     /**
  563.      * Start HTML, call CSS/JS from CDN
  564.      * Link to Github
  565.      * TODO: Add links to Codex/WP.org
  566.      * TODO: Add colors legend
  567.      */
  568.     public function get_header() {
  569.         $output = '';
  570.         $output .= '<!DOCTYPE html>' . "\n";
  571.         $output .= '<html lang="en">' . "\n";
  572.         $output .= '<head>' . "\n";
  573.         $output .= '<meta charset="utf-8">' . "\n";
  574.         $output .= '<meta name="robots" content="noindex,nofollow">' . "\n";
  575.         $output .= '<title>PHP WordPress Info</title>' . "\n";
  576.         $output .= '<link href="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">' . "\n";
  577.         $output .= '<style>.table tbody tr.warning td{background-color:#FCF8E3;} .description{margin:-10px 0 20px 0;} caption{font-weight: 700;font-size: 18px}</style>' . "\n";
  578.         $output .= '<!--[if lt IE 9]> <script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->' . "\n";
  579.         $output .= '</head>' . "\n";
  580.         $output .= '<body style="padding:10px 0;">' . "\n";
  581.         $output .= '<div class="container">' . "\n";
  582.         $output .= '<div class="navbar">' . "\n";
  583.         $output .= '<div class="navbar-inner">' . "\n";
  584.         $output .= '<a class="brand" href="#">PHP WordPress Info</a>' . "\n";
  585.         $output .= '<ul class="nav pull-right">' . "\n";
  586.         $output .= '<li><a href="https://github.com/BeAPI/phpwpinfo">Project on Github</a></li>' . "\n";
  587.  
  588.         if ( $this->db_link != false ) {
  589.             $output .= '<li class="dropdown">' . "\n";
  590.             $output .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown">MySQL <b class="caret"></b></a>' . "\n";
  591.             $output .= '<ul class="dropdown-menu">' . "\n";
  592.             $output .= '<li><a href="?mysql-variables=true">MySQL Variables</a></li>' . "\n";
  593.             $output .= '<li><a href="?logout=true">Logout</a></li>' . "\n";
  594.             $output .= '</ul>' . "\n";
  595.             $output .= '</li>' . "\n";
  596.         }
  597.  
  598.         $output .= '<li class="dropdown">' . "\n";
  599.         $output .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tools <b class="caret"></b></a>' . "\n";
  600.         $output .= '<ul class="dropdown-menu">' . "\n";
  601.         $output .= '<li><a href="?phpinfo=true">PHPinfo()</a></li>' . "\n";
  602.  
  603.         // Adminer
  604.         if ( ! is_file( dirname( __FILE__ ) . '/adminer.php' ) && is_writable( dirname( __FILE__ ) ) ) {
  605.             $output .= '<li><a href="?adminer=install">Install Adminer</a></li>' . "\n";
  606.         } else {
  607.             $output .= '<li><a href="adminer.php">Adminer</a></li>' . "\n";
  608.             $output .= '<li><a href="?adminer=uninstall">Uninstall Adminer</a></li>' . "\n";
  609.         }
  610.  
  611.         // PHP sec info
  612.         if ( ! is_dir( dirname( __FILE__ ) . '/phpsecinfo' ) && is_writable( dirname( __FILE__ ) ) && class_exists( 'ZipArchive' ) ) {
  613.             $output .= '<li><a href="?phpsecinfo=install">Install PhpSecInfo</a></li>' . "\n";
  614.         } else {
  615.             $output .= '<li><a href="?phpsecinfo=load">PhpSecInfo</a></li>' . "\n";
  616.             $output .= '<li><a href="?phpsecinfo=uninstall">Uninstall PhpSecInfo</a></li>' . "\n";
  617.         }
  618.  
  619.         // WordPress
  620.         if ( ! is_dir( dirname( __FILE__ ) . '/wordpress' ) && is_writable( dirname( __FILE__ ) ) && class_exists( 'ZipArchive' ) ) {
  621.             $output .= '<li><a href="?wordpress=install">Download & Extract WordPress</a></li>' . "\n";
  622.         } else {
  623.             $output .= '<li><a href="wordpress/">WordPress</a></li>' . "\n";
  624.         }
  625.  
  626.         $output .= '<li><a href="?self-destruction=true">Self-destruction</a></li>' . "\n";
  627.         $output .= '</ul>' . "\n";
  628.         $output .= '</li>' . "\n";
  629.  
  630.         $output .= '</ul>' . "\n";
  631.         $output .= '</div>' . "\n";
  632.         $output .= '</div>' . "\n";
  633.  
  634.         echo $output;
  635.     }
  636.  
  637.     /**
  638.      * Close HTML, call JS
  639.      */
  640.     public function get_footer() {
  641.         $output = '';
  642.  
  643.         $output .= '<footer>&copy; <a href="http://beapi.fr">BE API</a> ' . date( 'Y' ) . '</footer>' . "\n";
  644.         $output .= '</div>' . "\n";
  645.  
  646.         $output .= '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>' . "\n";
  647.         $output .= '<script src="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>' . "\n";
  648.  
  649.         $output .= '<script type="text/javascript">
  650.             $.getJSON("//freegeoip.net/json/?callback=?", function(data) {
  651.               $(".realip td:last").html(data.ip);
  652.             });
  653.         </script>' . "\n";
  654.  
  655.         $output .= '</body>' . "\n";
  656.         $output .= '</html>' . "\n";
  657.  
  658.         echo $output;
  659.     }
  660.  
  661.     /**
  662.      * Open a HTML table
  663.      *
  664.      * @param string $title
  665.      * @param string $col1
  666.      * @param string $col2
  667.      * @param string $col3
  668.      * @param string $col4
  669.      */
  670.     public function html_table_open( $title = '', $col1 = '', $col2 = '', $col3 = '', $col4 = '' ) {
  671.         $output = '';
  672.         $output .= '<table class="table table-bordered">' . "\n";
  673.         $output .= '<caption>' . $title . '</caption>' . "\n";
  674.         $output .= '<thead>' . "\n";
  675.  
  676.         if ( ! empty( $col1 ) || ! empty( $col2 ) || ! empty( $col3 ) || ! empty( $col4 ) ) {
  677.             $output .= '<tr>' . "\n";
  678.             $output .= '<th width="40%">' . $col1 . '</th>' . "\n";
  679.             if ( !empty($col4) ) {
  680.                 $output .= '<th width="20%">' . $col2 . '</th>' . "\n";
  681.                 $output .= '<th width="20%">' . $col3 . '</th>' . "\n";
  682.                 $output .= '<th width="20%">' . $col4 . '</th>' . "\n";
  683.             } else {
  684.                 $output .= '<th width="30%">' . $col2 . '</th>' . "\n";
  685.                 $output .= '<th width="30%">' . $col3 . '</th>' . "\n";
  686.             }
  687.             $output .= '</tr>' . "\n";
  688.         }
  689.  
  690.         $output .= '</thead>' . "\n";
  691.         $output .= '<tbody>' . "\n";
  692.  
  693.         echo $output;
  694.     }
  695.  
  696.     /**
  697.      * Close HTML table
  698.      *
  699.      * @param string $description
  700.      */
  701.     public function html_table_close( $description = '' ) {
  702.         $output = '';
  703.         $output .= '</tbody>' . "\n";
  704.         $output .= '</table>' . "\n";
  705.  
  706.         if ( !empty($description) ) {
  707.             $output .= '<p class="description">'.$description.'</p>' . "\n";
  708.         }
  709.  
  710.         echo $output;
  711.     }
  712.  
  713.     /**
  714.      * Add table row
  715.      * Status available : success, error, warning, info
  716.      *
  717.      * @param string $col1
  718.      * @param string $col2
  719.      * @param string $col3
  720.      * @param string $status
  721.      * @param bool $colspan
  722.      */
  723.     public function html_table_row( $col1, $col2, $col3, $col4, $status = 'success', $colspan = false ) {
  724.         $output = '';
  725.         $output .= '<tr class="' . $status . '">' . "\n";
  726.  
  727.         if ( $colspan !== false ) {
  728.             $output .= '<td>' . $col1 . '</td>' . "\n";
  729.             $output .= '<td colspan="' . $colspan . '" style="text-align:center;">' . $col2 . '</td>' . "\n";
  730.         } else {
  731.             $output .= '<td>' . $col1 . '</td>' . "\n";
  732.             $output .= '<td>' . $col2 . '</td>' . "\n";
  733.             $output .= '<td>' . $col3 . '</td>' . "\n";
  734.             $output .= '<td>' . $col4 . '</td>' . "\n";
  735.         }
  736.  
  737.         $output .= '</tr>' . "\n";
  738.  
  739.         echo $output;
  740.     }
  741.  
  742.     /**
  743.      * Form HTML for MySQL Login
  744.      *
  745.      * @param  boolean $show_error_credentials [description]
  746.      *
  747.      * @return void                          [description]
  748.      */
  749.     public function html_form_mysql( $show_error_credentials = false ) {
  750.         $output = '';
  751.         $output .= '<tr>' . "\n";
  752.         $output .= '<td colspan="4">' . "\n";
  753.  
  754.         if ( $show_error_credentials == true ) {
  755.             $output .= '<div class="alert alert-error">Credentials invalid.</div>' . "\n";
  756.         }
  757.  
  758.         $output .= '<form class="form-inline" method="post" action="">' . "\n";
  759.         $output .= '<input type="text" class="input-small" name="credentials[host]" placeholder="localhost" value="localhost">' . "\n";
  760.         $output .= '<input type="text" class="input-small" name="credentials[user]" placeholder="user">' . "\n";
  761.         $output .= '<input type="password" class="input-small" name="credentials[password]" placeholder="password">' . "\n";
  762.         $output .= '<label class="checkbox">' . "\n";
  763.         $output .= '<input type="checkbox" name="remember"> Remember' . "\n";
  764.         $output .= '</label>' . "\n";
  765.         $output .= '<button name="mysql-connection" type="submit" class="btn">Login</button>' . "\n";
  766.         $output .= '<span class="help-inline">We must connect to the MySQL server to check the configuration</span>' . "\n";
  767.         $output .= '</form>' . "\n";
  768.         $output .= '</td>' . "\n";
  769.         $output .= '</tr>' . "\n";
  770.  
  771.         echo $output;
  772.     }
  773.  
  774.     /**
  775.      * Form for test email
  776.      *
  777.      * @return void                          [description]
  778.      */
  779.     public function html_form_email() {
  780.         $output = '';
  781.         $output .= '<tr>' . "\n";
  782.         $output .= '<td colspan="3">' . "\n";
  783.  
  784.         if ( isset( $_POST['test-email'] ) && isset( $_POST['mail'] ) ) {
  785.             if ( ! filter_var( $_POST['mail'], FILTER_VALIDATE_EMAIL ) ) {// Invalid
  786.                 $output .= '<div class="alert alert-error">Email invalid.</div>' . "\n";
  787.             } else {// Valid mail
  788.                 if ( mail( $_POST['mail'], 'Email test with PHP WP Info', "Line 1\nLine 2\nLine 3\nGreat !" ) ) {// Valid send
  789.                     $output .= '<div class="alert alert-success">Mail sent with success.</div>' . "\n";
  790.                 } else {// Error send
  791.                     $output .= '<div class="alert alert-error">An error occured during mail sending.</div>' . "\n";
  792.                 }
  793.             }
  794.         }
  795.  
  796.         $output .= '<form id="form-email" class="form-inline" method="post" action="#form-email">' . "\n";
  797.         $output .= '<i class="icon-envelope"></i> <input type="email" class="input-large" name="mail" placeholder="test@sample.com" value="">' . "\n";
  798.         $output .= '<button name="test-email" type="submit" class="btn">Send mail</button>' . "\n";
  799.         $output .= '<span class="help-inline">Send a test email to check that server is doing its job</span>' . "\n";
  800.         $output .= '</form>' . "\n";
  801.         $output .= '</td>' . "\n";
  802.         $output .= '</tr>' . "\n";
  803.  
  804.         echo $output;
  805.     }
  806.  
  807.     /**
  808.      * Stripslashes array
  809.      *
  810.      * @param  [type] $value [description]
  811.      *
  812.      * @return array|string [type]        [description]
  813.      */
  814.     public function stripslashes_deep( $value ) {
  815.         return is_array( $value ) ? array_map( array( &$this, 'stripslashes_deep' ), $value ) : stripslashes( $value );
  816.     }
  817.  
  818.     /**
  819.      * Detect current webserver
  820.      *
  821.      * @return string        [description]
  822.      */
  823.     private function _get_current_webserver() {
  824.         if ( stristr( $_SERVER['SERVER_SOFTWARE'], 'apache' ) !== false ) :
  825.             return 'Apache';
  826.         elseif ( stristr( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false ) :
  827.             return 'Lite Speed';
  828.         elseif ( stristr( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false ) :
  829.             return 'nginx';
  830.         elseif ( stristr( $_SERVER['SERVER_SOFTWARE'], 'lighttpd' ) !== false ) :
  831.             return 'lighttpd';
  832.         elseif ( stristr( $_SERVER['SERVER_SOFTWARE'], 'iis' ) !== false ) :
  833.             return 'Microsoft IIS';
  834.         else :
  835.             return 'Not detected';
  836.         endif;
  837.     }
  838.  
  839.     /**
  840.      * Method for get apaches modules with Apache modules or CGI with .HTACCESS
  841.      *
  842.      * @return string        [description]
  843.      */
  844.     private function _get_apache_modules() {
  845.         $apache_modules = ( is_callable( 'apache_get_modules' ) ? apache_get_modules() : false );
  846.  
  847.         if ( $apache_modules === false && ( isset( $_SERVER['http_mod_env'] ) || isset( $_SERVER['REDIRECT_http_mod_env'] ) ) ) {
  848.             // Test with htaccess to get ENV values
  849.             $apache_modules = array( 'mod_env' );
  850.  
  851.             if ( isset( $_SERVER['http_mod_rewrite'] ) || isset( $_SERVER['REDIRECT_http_mod_rewrite'] ) ) {
  852.                 $apache_modules[] = 'mod_rewrite';
  853.             }
  854.             if ( isset( $_SERVER['http_mod_deflate'] ) || isset( $_SERVER['REDIRECT_http_mod_deflate'] ) ) {
  855.                 $apache_modules[] = 'mod_deflate';
  856.             }
  857.             if ( isset( $_SERVER['http_mod_expires'] ) || isset( $_SERVER['REDIRECT_http_mod_expires'] ) ) {
  858.                 $apache_modules[] = 'mod_expires';
  859.             }
  860.             if ( isset( $_SERVER['http_mod_filter'] ) || isset( $_SERVER['REDIRECT_http_mod_filter'] ) ) {
  861.                 $apache_modules[] = 'mod_filter';
  862.             }
  863.             if ( isset( $_SERVER['http_mod_headers'] ) || isset( $_SERVER['REDIRECT_http_mod_headers'] ) ) {
  864.                 $apache_modules[] = 'mod_headers';
  865.             }
  866.             if ( isset( $_SERVER['http_mod_mime'] ) || isset( $_SERVER['REDIRECT_http_mod_mime'] ) ) {
  867.                 $apache_modules[] = 'mod_mime';
  868.             }
  869.             if ( isset( $_SERVER['http_mod_setenvif'] ) || isset( $_SERVER['REDIRECT_http_mod_setenvif'] ) ) {
  870.                 $apache_modules[] = 'mod_setenvif';
  871.             }
  872.         }
  873.  
  874.         return $apache_modules;
  875.     }
  876.  
  877.     /**
  878.      * Get humans values, take from http://php.net/manual/de/function.filesize.php
  879.      *
  880.      * @param $size
  881.      *
  882.      * @return string [description]
  883.      * @internal param int $bytes [description]
  884.      */
  885.     private function _format_bytes( $size ) {
  886.         $units = array( ' B', ' KB', ' MB', ' GB', ' TB' );
  887.         for ( $i = 0; $size >= 1024 && $i < 4; $i ++ ) {
  888.             $size /= 1024;
  889.         }
  890.  
  891.         return round( $size, 2 ) . $units[ $i ];
  892.     }
  893.  
  894.     private function _variable_to_html( $variable ) {
  895.         if ( $variable === true ) {
  896.             return 'true';
  897.         } else if ( $variable === false ) {
  898.             return 'false';
  899.         } else if ( $variable === null ) {
  900.             return 'null';
  901.         } else if ( is_array( $variable ) ) {
  902.             $html = "<table class='table table-bordered'>\n";
  903.             $html .= "<thead><tr><th>Key</th><th>Value</th></tr></thead>\n";
  904.             $html .= "<tbody>\n";
  905.             foreach ( $variable as $key => $value ) {
  906.                 $value = $this->_variable_to_html( $value );
  907.                 $html .= "<tr><td>$key</td><td>$value</td></tr>\n";
  908.             }
  909.             $html .= "</tbody>\n";
  910.             $html .= "</table>";
  911.  
  912.             return $html;
  913.         } else {
  914.             return strval( $variable );
  915.         }
  916.     }
  917.  
  918.     function file_get_contents_url( $url ) {
  919.         if ( function_exists( 'curl_init' ) ) {
  920.             $curl = curl_init();
  921.  
  922.             curl_setopt( $curl, CURLOPT_URL, $url );
  923.             //The URL to fetch. This can also be set when initializing a session with curl_init().
  924.             curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
  925.             //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
  926.             curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 15 );
  927.             //The number of seconds to wait while trying to connect.
  928.  
  929.             curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)' );
  930.             //The contents of the "User-Agent: " header to be used in a HTTP request.
  931.             curl_setopt( $curl, CURLOPT_FAILONERROR, true );
  932.             //To fail silently if the HTTP code returned is greater than or equal to 400.
  933.             curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
  934.             //To follow any "Location: " header that the server sends as part of the HTTP header.
  935.             curl_setopt( $curl, CURLOPT_AUTOREFERER, true );
  936.             //To automatically set the Referer: field in requests where it follows a Location: redirect.
  937.             curl_setopt( $curl, CURLOPT_TIMEOUT, 300 );
  938.             //The maximum number of seconds to allow cURL functions to execute.
  939.  
  940.             curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
  941.             curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false );
  942.  
  943.             $contents = curl_exec( $curl );
  944.             curl_close( $curl );
  945.  
  946.             return $contents;
  947.         } else {
  948.             return file_get_contents( $url );
  949.         }
  950.     }
  951.  
  952.     function rrmdir( $dir ) {
  953.         if ( is_dir( $dir ) ) {
  954.             $objects = scandir( $dir );
  955.             foreach ( $objects as $object ) {
  956.                 if ( $object != "." && $object != ".." ) {
  957.                     if ( filetype( $dir . "/" . $object ) == "dir" ) {
  958.                         $this->rrmdir( $dir . "/" . $object );
  959.                     } else {
  960.                         unlink( $dir . "/" . $object );
  961.                     }
  962.                 }
  963.             }
  964.             reset( $objects );
  965.             rmdir( $dir );
  966.         }
  967.     }
  968.  
  969.     private function _check_request_mysql() {
  970.         // Check GET for logout MySQL
  971.         if ( isset( $_GET ) && isset( $_GET['logout'] ) && $_GET['logout'] == 'true' ) {
  972.             // Flush old session if POST submit
  973.             unset( $_SESSION['credentials'] );
  974.  
  975.             header( "Location: http://" . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'], true );
  976.             exit();
  977.         }
  978.  
  979.         // Check POST for MySQL login
  980.         if ( isset( $_POST ) && isset( $_POST['mysql-connection'] ) ) {
  981.             // Flush old session if POST submit
  982.             unset( $_SESSION['credentials'] );
  983.  
  984.             // Cleanup form data
  985.             $this->db_infos = $this->stripslashes_deep( $_POST['credentials'] );
  986.  
  987.             // Check remember checkbox
  988.             if ( isset( $_POST['remember'] ) ) {
  989.                 $_SESSION['credentials'] = $this->db_infos;
  990.             }
  991.         } else {
  992.             if ( ( isset( $_SESSION ) && isset( $_SESSION['credentials'] ) ) ) {
  993.                 $this->db_infos = $_SESSION['credentials'];
  994.             }
  995.         }
  996.  
  997.         // Check credentials
  998.         if ( ! empty( $this->db_infos ) && is_array( $this->db_infos ) && is_callable( 'mysqli_connect' ) ) {
  999.             $this->db_link = mysqli_connect( $this->db_infos['host'], $this->db_infos['user'], $this->db_infos['password'] );
  1000.             if ( $this->db_link == false ) {
  1001.                 unset( $_SESSION['credentials'] );
  1002.                 $this->db_infos = false;
  1003.             }
  1004.         }
  1005.  
  1006.         // Check GET for MYSQL variables
  1007.         if ( $this->db_link != false && isset( $_GET ) && isset( $_GET['mysql-variables'] ) && $_GET['mysql-variables'] == 'true' ) {
  1008.             $result = mysqli_query( 'SHOW VARIABLES' );
  1009.             if ( ! $result ) {
  1010.                 echo "Could not successfully run query ( 'SHOW VARIABLES' ) from DB: " . mysqli_error();
  1011.                 exit();
  1012.             }
  1013.  
  1014.             if ( mysqli_num_rows( $result ) == 0 ) {
  1015.                 echo "No rows found, nothing to print so am exiting";
  1016.                 exit();
  1017.             }
  1018.  
  1019.             $output = array();
  1020.             while ( $row = mysqli_fetch_assoc( $result ) ) {
  1021.                 $output[ $row['Variable_name'] ] = $row['Value'];
  1022.             }
  1023.             $this->get_header();
  1024.             echo $this->_variable_to_html( $output );
  1025.             $this->get_footer();
  1026.             exit();
  1027.         }
  1028.     }
  1029.  
  1030.     private function _check_request_adminer() {
  1031.         // Check GET for Install Adminer
  1032.         if ( isset( $_GET ) && isset( $_GET['adminer'] ) && $_GET['adminer'] == 'install' ) {
  1033.             $code = $this->file_get_contents_url( 'https://www.adminer.org/latest-mysql-en.php' );
  1034.             if ( ! empty( $code ) ) {
  1035.                 $result = file_put_contents( dirname( __FILE__ ) . '/adminer.php', $code );
  1036.                 if ( $result != false ) {
  1037.                     header( "Location: http://" . $_SERVER['SERVER_NAME'] . '/adminer.php', true );
  1038.                     exit();
  1039.                 }
  1040.             }
  1041.  
  1042.             die( 'Impossible to download and install Adminer with this script.' );
  1043.         }
  1044.  
  1045.         // Check GET for Uninstall Adminer
  1046.         if ( isset( $_GET ) && isset( $_GET['adminer'] ) && $_GET['adminer'] == 'uninstall' ) {
  1047.             if ( is_file( dirname( __FILE__ ) . '/adminer.php' ) ) {
  1048.                 $result = unlink( dirname( __FILE__ ) . '/adminer.php' );
  1049.                 if ( $result != false ) {
  1050.                     header( "Location: http://" . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'], true );
  1051.                     exit();
  1052.                 }
  1053.             }
  1054.  
  1055.             die( 'Impossible remove file and uninstall Adminer with this script.' );
  1056.         }
  1057.     }
  1058.  
  1059.     private function _check_request_phpsecinfo() {
  1060.         // Check GET for Install phpsecinfo
  1061.         if ( isset( $_GET ) && isset( $_GET['phpsecinfo'] ) && $_GET['phpsecinfo'] == 'install' ) {
  1062.             $code = $this->file_get_contents_url( 'http://www.herewithme.fr/static/funkatron-phpsecinfo-b5a6155.zip' );
  1063.             if ( ! empty( $code ) ) {
  1064.                 $result = file_put_contents( dirname( __FILE__ ) . '/phpsecinfo.zip', $code );
  1065.                 if ( $result != false ) {
  1066.                     $zip = new ZipArchive;
  1067.                     if ( $zip->open( dirname( __FILE__ ) . '/phpsecinfo.zip' ) === true ) {
  1068.                         $zip->extractTo( dirname( __FILE__ ) . '/phpsecinfo/' );
  1069.                         $zip->close();
  1070.  
  1071.                         unlink( dirname( __FILE__ ) . '/phpsecinfo.zip' );
  1072.                     } else {
  1073.                         unlink( dirname( __FILE__ ) . '/phpsecinfo.zip' );
  1074.                         die( 'Impossible to uncompress phpsecinfo with this script.' );
  1075.                     }
  1076.  
  1077.                     header( "Location: http://" . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'], true );
  1078.                     exit();
  1079.                 } else {
  1080.                     die( 'Impossible to write phpsecinfo archive with this script.' );
  1081.                 }
  1082.             } else {
  1083.                 die( 'Impossible to download phpsecinfo with this script.' );
  1084.             }
  1085.         }
  1086.  
  1087.         // Check GET for Uninstall phpsecinfo
  1088.         if ( isset( $_GET ) && isset( $_GET['phpsecinfo'] ) && $_GET['phpsecinfo'] == 'uninstall' ) {
  1089.             if ( is_dir( dirname( __FILE__ ) . '/phpsecinfo/' ) ) {
  1090.                 $this->rrmdir( dirname( __FILE__ ) . '/phpsecinfo/' );
  1091.                 if ( ! is_dir( dirname( __FILE__ ) . '/phpsecinfo/' ) ) {
  1092.                     header( "Location: http://" . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'], true );
  1093.                     exit();
  1094.                 }
  1095.             }
  1096.  
  1097.             die( 'Impossible remove file and uninstall phpsecinfo with this script.' );
  1098.         }
  1099.  
  1100.         // Check GET for load
  1101.         if ( isset( $_GET ) && isset( $_GET['phpsecinfo'] ) && $_GET['phpsecinfo'] == 'load' ) {
  1102.             if ( is_dir( dirname( __FILE__ ) . '/phpsecinfo/' ) ) {
  1103.                 require( dirname( __FILE__ ) . '/phpsecinfo/funkatron-phpsecinfo-b5a6155/PhpSecInfo/PhpSecInfo.php' );
  1104.                 phpsecinfo();
  1105.                 exit();
  1106.             }
  1107.         }
  1108.     }
  1109.  
  1110.     function _check_request_wordpress() {
  1111.         // Check GET for Install wordpress
  1112.         if ( isset( $_GET ) && isset( $_GET['wordpress'] ) && $_GET['wordpress'] == 'install' ) {
  1113.             if ( ! is_file( dirname( __FILE__ ) . '/latest.zip' ) ) {
  1114.                 $code = $this->file_get_contents_url( 'https://wordpress.org/latest.zip' );
  1115.                 if ( ! empty( $code ) ) {
  1116.                     $result = file_put_contents( dirname( __FILE__ ) . '/latest.zip', $code );
  1117.                     if ( $result == false ) {
  1118.                         die( 'Impossible to write WordPress archive with this script.' );
  1119.                     }
  1120.                 } else {
  1121.                     die( 'Impossible to download WordPress with this script. You can also send WordPress Zip archive via FTP and renme it latest.zip, the script will only try to decompress it.' );
  1122.                 }
  1123.             }
  1124.  
  1125.             if ( is_file( dirname( __FILE__ ) . '/latest.zip' ) ) {
  1126.                 $zip = new ZipArchive;
  1127.                 if ( $zip->open( dirname( __FILE__ ) . '/latest.zip' ) === true ) {
  1128.                     $zip->extractTo( dirname( __FILE__ ) . '/' );
  1129.                     $zip->close();
  1130.  
  1131.                     unlink( dirname( __FILE__ ) . '/latest.zip' );
  1132.                 } else {
  1133.                     unlink( dirname( __FILE__ ) . '/latest.zip' );
  1134.                     die( 'Impossible to uncompress WordPress with this script.' );
  1135.                 }
  1136.             }
  1137.         }
  1138.     }
  1139.  
  1140.     /**
  1141.      * Determines if a command exists on the current environment
  1142.      * Source: https://stackoverflow.com/questions/12424787/how-to-check-if-a-shell-command-exists-from-php
  1143.      *
  1144.      * @param string $command The command to check
  1145.      * @return bool True if the command has been found ; otherwise, false.
  1146.      */
  1147.     private function _command_exists($command) {
  1148.         $whereIsCommand = (PHP_OS == 'WINNT') ? 'where' : 'which';
  1149.  
  1150.         $process = proc_open(
  1151.             "$whereIsCommand $command",
  1152.             array(
  1153.                 0 => array("pipe", "r"), //STDIN
  1154.                 1 => array("pipe", "w"), //STDOUT
  1155.                 2 => array("pipe", "w"), //STDERR
  1156.             ),
  1157.             $pipes
  1158.         );
  1159.  
  1160.         if ($process !== false) {
  1161.             $stdout = stream_get_contents($pipes[1]);
  1162.             $stderr = stream_get_contents($pipes[2]);
  1163.             fclose($pipes[1]);
  1164.             fclose($pipes[2]);
  1165.             proc_close($process);
  1166.  
  1167.             return $stdout != '';
  1168.         }
  1169.  
  1170.         return false;
  1171.     }
  1172. }
  1173.  
  1174. // Init render
  1175. phpwpinfo();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement