From 294908b47e83a631898d8f52b61f3ff16e4a348a Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 8 Aug 2018 18:08:33 +0530 Subject: [PATCH 01/26] Add docker-compose-admin template Signed-off-by: Riddhesh Sanghvi --- templates/docker-compose-admin.mustache | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 templates/docker-compose-admin.mustache diff --git a/templates/docker-compose-admin.mustache b/templates/docker-compose-admin.mustache new file mode 100644 index 0000000..7a40d72 --- /dev/null +++ b/templates/docker-compose-admin.mustache @@ -0,0 +1,13 @@ +version: '3' + +services: + + php: + volumes: + - "/opt/easyengine/admin-tools:/var/www/htdocs/ee-admin:ro" + - "/opt/easyengine/ee.sqlite:/opt/easyengine/ee.sqlite:ro" + + nginx: + volumes: + - "/opt/easyengine/admin-tools:/var/www/htdocs/ee-admin:ro" + - "/opt/easyengine/ee.sqlite:/opt/easyengine/ee.sqlite:ro" From b11611a057b54e74951ef7d86c7a8290c31c25a2 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 8 Aug 2018 18:08:49 +0530 Subject: [PATCH 02/26] Add template for index.php Signed-off-by: Riddhesh Sanghvi --- templates/index.mustache | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 templates/index.mustache diff --git a/templates/index.mustache b/templates/index.mustache new file mode 100644 index 0000000..7999c77 --- /dev/null +++ b/templates/index.mustache @@ -0,0 +1,68 @@ + $site_name ), 'sites', 1 ); + + return $db_select[0]; + +} + +function select( $columns = array(), $where = array(), $table_name = 'services', $limit = null ) { + + $db_path = '/opt/easyengine/ee.sqlite'; + $db = new SQLite3( $db_path ); + + $conditions = array(); + if ( empty( $columns ) ) { + $columns = '*'; + } else { + $columns = implode( ',', $columns ); + } + + foreach ( $where as $key => $value ) { + $conditions[] = "`$key`='" . $value . "'"; + } + + $conditions = implode( ' AND ', $conditions ); + + $select_data_query = "SELECT {$columns} FROM `$table_name`"; + + if ( ! empty( $conditions ) ) { + $select_data_query .= " WHERE $conditions"; + } + + if ( ! empty( $limit ) ) { + $select_data_query .= " LIMIT $limit"; + } + + $select_data_exec = $db->query( $select_data_query ); + $select_data = array(); + if ( $select_data_exec ) { + while ( $row = $select_data_exec->fetchArray( SQLITE3_ASSOC ) ) { + $select_data[] = $row; + } + } + if ( empty( $select_data ) ) { + return false; + } + + return $select_data; +} + +$services = populate_site_info(); +unset( $services['id'] ); +unset( $services['sitename'] ); + + +$scan = scandir( '/var/www/htdocs/ee-admin' ); +$tools = array_slice( $scan, 2 ); + +if ( ! $services['cache_type'] ) { + $tools = array_diff( $tools, [ 'pra' ] ); +} + +foreach ( $tools as $tool ) { + echo '' . $tool . '
'; +} From 40988d07a3be2bc8ca581bda41fe44e927c6149c Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 8 Aug 2018 18:09:05 +0530 Subject: [PATCH 03/26] Add template for phpinfo.php Signed-off-by: Riddhesh Sanghvi --- templates/phpinfo.mustache | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 templates/phpinfo.mustache diff --git a/templates/phpinfo.mustache b/templates/phpinfo.mustache new file mode 100644 index 0000000..2fa5939 --- /dev/null +++ b/templates/phpinfo.mustache @@ -0,0 +1,2 @@ + Date: Wed, 8 Aug 2018 18:09:21 +0530 Subject: [PATCH 04/26] Add template for pma configuration Signed-off-by: Riddhesh Sanghvi --- templates/pma.config.mustache | 156 ++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 templates/pma.config.mustache diff --git a/templates/pma.config.mustache b/templates/pma.config.mustache new file mode 100644 index 0000000..8b833e9 --- /dev/null +++ b/templates/pma.config.mustache @@ -0,0 +1,156 @@ +. + * + * @package PhpMyAdmin + */ + +/** + * This is needed for cookie based authentication to encrypt password in + * cookie. Needs to be 32 chars long. + */ +$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */ + +/** + * Servers configuration + */ +$i = 0; + +$cfg['AllowArbitraryServer'] = true; + +/** + * First server + */ +$i++; +/* Authentication type */ +$cfg['Servers'][$i]['auth_type'] = 'cookie'; +/* Server parameters */ +$cfg['Servers'][$i]['host'] = 'db'; +$cfg['Servers'][$i]['compress'] = false; +$cfg['Servers'][$i]['AllowNoPassword'] = false; + +/** + * phpMyAdmin configuration storage settings. + */ + +/* User used to manipulate with storage */ +// $cfg['Servers'][$i]['controlhost'] = ''; +// $cfg['Servers'][$i]['controlport'] = ''; +// $cfg['Servers'][$i]['controluser'] = 'pma'; +// $cfg['Servers'][$i]['controlpass'] = 'pmapass'; + +/* Storage database and tables */ +// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; +// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark'; +// $cfg['Servers'][$i]['relation'] = 'pma__relation'; +// $cfg['Servers'][$i]['table_info'] = 'pma__table_info'; +// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords'; +// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages'; +// $cfg['Servers'][$i]['column_info'] = 'pma__column_info'; +// $cfg['Servers'][$i]['history'] = 'pma__history'; +// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs'; +// $cfg['Servers'][$i]['tracking'] = 'pma__tracking'; +// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; +// $cfg['Servers'][$i]['recent'] = 'pma__recent'; +// $cfg['Servers'][$i]['favorite'] = 'pma__favorite'; +// $cfg['Servers'][$i]['users'] = 'pma__users'; +// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups'; +// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding'; +// $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches'; +// $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns'; +// $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings'; +// $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates'; + +/** + * End of servers configuration + */ + +/** + * Directories for saving/loading files from server + */ +$cfg['UploadDir'] = ''; +$cfg['SaveDir'] = ''; + +/** + * Whether to display icons or text or both icons and text in table row + * action segment. Value can be either of 'icons', 'text' or 'both'. + * default = 'both' + */ +//$cfg['RowActionType'] = 'icons'; + +/** + * Defines whether a user should be displayed a "show all (records)" + * button in browse mode or not. + * default = false + */ +//$cfg['ShowAll'] = true; + +/** + * Number of rows displayed when browsing a result set. If the result + * set contains more rows, "Previous" and "Next". + * Possible values: 25, 50, 100, 250, 500 + * default = 25 + */ +//$cfg['MaxRows'] = 50; + +/** + * Disallow editing of binary fields + * valid values are: + * false allow editing + * 'blob' allow editing except for BLOB fields + * 'noblob' disallow editing except for BLOB fields + * 'all' disallow editing + * default = 'blob' + */ +//$cfg['ProtectBinary'] = false; + +/** + * Default language to use, if not browser-defined or user-defined + * (you find all languages in the locale folder) + * uncomment the desired line: + * default = 'en' + */ +//$cfg['DefaultLang'] = 'en'; +//$cfg['DefaultLang'] = 'de'; + +/** + * How many columns should be used for table display of a database? + * (a value larger than 1 results in some information being hidden) + * default = 1 + */ +//$cfg['PropertiesNumColumns'] = 2; + +/** + * Set to true if you want DB-based query history.If false, this utilizes + * JS-routines to display query history (lost by window close) + * + * This requires configuration storage enabled, see above. + * default = false + */ +//$cfg['QueryHistoryDB'] = true; + +/** + * When using DB-based query history, how many entries should be kept? + * default = 25 + */ +//$cfg['QueryHistoryMax'] = 100; + +/** + * Whether or not to query the user before sending the error report to + * the phpMyAdmin team when a JavaScript error occurs + * + * Available options + * ('ask' | 'always' | 'never') + * default = 'ask' + */ +//$cfg['SendErrorReports'] = 'always'; + +/** + * You can find more configuration options in the documentation + * in the doc/ folder or at . + */ From 12e3d00c7d9c446b01aa346f78e6b3c68c4a0d4c Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 8 Aug 2018 18:09:33 +0530 Subject: [PATCH 05/26] Add template for pra configuration Signed-off-by: Riddhesh Sanghvi --- templates/pra.config.mustache | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 templates/pra.config.mustache diff --git a/templates/pra.config.mustache b/templates/pra.config.mustache new file mode 100644 index 0000000..1f47fd6 --- /dev/null +++ b/templates/pra.config.mustache @@ -0,0 +1,84 @@ + array( + array( + 'name' => getenv('VIRTUAL_HOST'), // Optional name. + 'host' => 'redis', + 'port' => 6379, + 'filter' => '*', + 'scheme' => 'tcp', // Optional. Connection scheme. 'tcp' - for TCP connection, 'unix' - for connection by unix domain socket + 'path' => '' // Optional. Path to unix domain socket. Uses only if 'scheme' => 'unix'. Example: '/var/run/redis/redis.sock' + + // Optional Redis authentication. + //'auth' => 'redispasswordhere' // Warning: The password is sent in plain-text to the Redis server. + ), + + /*array( + 'host' => 'localhost', + 'port' => 6380 + ),*/ + + /*array( + 'name' => 'local db 2', + 'host' => 'localhost', + 'port' => 6379, + 'db' => 1, // Optional database number, see http://redis.io/commands/select + 'databases' => 1, // Optional number of databases (prevents use of CONFIG command). + 'filter' => 'something:*', // Show only parts of database for speed or security reasons. + 'seperator' => '/', // Use a different seperator on this database (default uses config default). + 'flush' => false, // Set to true to enable the flushdb button for this instance. + 'charset' => 'cp1251', // Keys and values are stored in redis using this encoding (default utf-8). + 'keys' => false, // Use the old KEYS command instead of SCAN to fetch all keys for this server (default uses config default). + 'scansize' => 1000 // How many entries to fetch using each SCAN command for this server (default uses config default). + ),*/ + ), + + + 'seperator' => ':', + + + // Uncomment to show less information and make phpRedisAdmin fire less commands to the Redis server. Recommended for a really busy Redis server. + //'faster' => true, + + + // Uncomment to enable HTTP authentication + /*'login' => array( + // Username => Password + // Multiple combinations can be used + 'admin' => array( + 'password' => 'adminpassword', + ), + 'guest' => array( + 'password' => '', + 'servers' => array(1) // Optional list of servers this user can access. + ) + ),*/ + + // Use HTML form/cookie-based auth instead of HTTP Basic/Digest auth + 'cookie_auth' => false, + + + /*'serialization' => array( + 'foo*' => array( // Match like KEYS + // Function called when saving to redis. + 'save' => function($data) { return json_encode(json_decode($data)); }, + // Function called when loading from redis. + 'load' => function($data) { return json_encode(json_decode($data), JSON_PRETTY_PRINT); }, + ), + ),*/ + + + // You can ignore settings below this point. + + 'maxkeylen' => 100, + 'count_elements_page' => 100, + + // Use the old KEYS command instead of SCAN to fetch all keys. + 'keys' => false, + + // How many entries to fetch using each SCAN command. + 'scansize' => 1000 +); + +?> From 6f922d7baf2899864daea5f7ea3aafb008cf1bf6 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 8 Aug 2018 18:09:59 +0530 Subject: [PATCH 06/26] Add initial installation, up and down of admin tools Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 273 ++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 src/Admin_Tools_Command.php diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php new file mode 100644 index 0000000..45171aa --- /dev/null +++ b/src/Admin_Tools_Command.php @@ -0,0 +1,273 @@ +command = 'admin-tools'; + $this->fs = new Filesystem(); + define( 'ADMIN_TOOL_DIR', EE_CONF_ROOT . '/admin-tools' ); + } + + /** + * Installs admin-tools for EasyEngine. + */ + public function install() { + + if ( ! $this->is_installed() ) { + EE::log( 'Installing admin-tools. This may take some time.' ); + $this->fs->mkdir( ADMIN_TOOL_DIR ); + } + + $tools = json_decode( file_get_contents( ADMIN_TOOLS_FILE ), true ); + + foreach ( $tools as $tool => $data ) { + if ( ! $this->is_installed( $tool ) ) { + EE::log( "Installing $tool" ); + $tool_path = ADMIN_TOOL_DIR . '/' . $tool; + call_user_func_array( [ $this, "install_$tool" ], [ $data, $tool_path ] ); + EE::log( 'Done.' ); + } + } + } + + + /** + * Enables admin-tools on given site. + * + * ## OPTIONS + * + * [] + * : Name of website to enable admin-tools on. + */ + public function up( $args, $assoc_args ) { + + EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' start' ); + $args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ ); + $this->populate_site_info( $args ); + chdir( $this->site['root'] ); + + $launch = EE::launch( 'docker-compose config --services' ); + $services = explode( PHP_EOL, trim( $launch->stdout ) ); + $min_req_services = [ 'nginx', 'php' ]; + + if ( count( array_intersect( $services, $min_req_services ) ) !== count( $min_req_services ) ) { + EE::error( sprintf( '%s site-type of %s-command does not support admin-tools.', $this->site['type'], $this->site['command'] ) ); + } + + if ( ! $this->is_installed() ) { + EE::log( 'It seems admin-tools have not yet been installed.' ); + $this->install(); + } + + // TODO: services_enabled fnuction after db changes + // if($this->services_enabled()){ + // EE::error('Services are already enabled.'); + // } + + $this->move_config_file( $this->site['root'] . '/docker-compose-admin.yml', 'docker-compose-admin.mustache' ); + + if ( EE::exec( 'docker-compose -f docker-compose.yml -f docker-compose-admin.yml up -d nginx' ) ) { + EE::success( sprintf( 'admin-tools enabled for %s site.', $this->site['name'] ) ); + } else { + EE::error( sprintf( 'Error in enabling admin-tools for %s site. Check logs.', $this->site['name'] ) ); + } + + EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' stop' ); + } + + /** + * Disables admin-tools on given site. + * + * ## OPTIONS + * + * [] + * : Name of website to disable admin-tools on. + */ + public function down( $args, $assoc_args ) { + + EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' start' ); + $args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ ); + $this->populate_site_info( $args ); + + // TODO: services_enabled fnuction after db changes + // if($this->services_enabled()){ + // Then only run this... + // } + + EE::docker()::docker_compose_up( $this->site['root'], [ 'nginx', 'php' ] ); + EE::success( sprintf( 'admin-tools disabled for %s site.', $this->site['name'] ) ); + + EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' stop' ); + } + + /** + * Check if a tools directory is installed. + * + * @param string $tool The tool whose directory has to be checked. + * + * @return bool status. + */ + private function is_installed( $tool = '' ) { + + $tool = in_array( $tool, [ 'index', 'phpinfo' ] ) ? $tool . '.php' : $tool; + + return $this->fs->exists( ADMIN_TOOL_DIR . '/' . $tool ); + } + + /** + * Function to download file to a path. + * + * @param string $path Path to download the file on. + * @param string $download_url Url to download the file from. + */ + private function download( $path, $download_url ) { + + $headers = array(); + $options = array( + 'timeout' => 1200, // 20 minutes ought to be enough for everybody. + 'filename' => $path, + ); + EE\Utils\http_request( 'GET', $download_url, null, $headers, $options ); + } + + /** + * Extract zip files. + * + * @param string $zip_file Path to the zip file. + * @param string $path_to_extract Path where zip needs to be extracted to. + * + * @return bool Success of extraction. + */ + private function extract_zip( $zip_file, $path_to_extract ) { + + $zip = new ZipArchive; + $res = $zip->open( $zip_file ); + if ( true === $res ) { + $zip->extractTo( $path_to_extract ); + $zip->close(); + + return true; + } + + return false; + } + + /** + * Place config files from templates to tools. + * + * @param string $config_file Path where the config file needs to go. + * @param string $template_file Template file from which the config needs to be created. + */ + private function move_config_file( $config_file, $template_file ) { + + $this->fs->dumpFile( $config_file, file_get_contents( ADMIN_TEMPLATE_ROOT . '/' . $template_file ) ); + } + + /** + * Populate basic site info from db. + */ + private function populate_site_info( $args ) { + + $this->site['name'] = EE\Utils\remove_trailing_slash( $args[0] ); + + if ( EE::db()::site_in_db( $this->site['name'] ) ) { + + $db_select = EE::db()::select( [], [ 'sitename' => $this->site['name'] ], 'sites', 1 ); + + $this->site['type'] = $db_select['site_type']; + $this->site['root'] = $db_select['site_path']; + $this->site['command'] = $db_select['site_command']; + } else { + EE::error( sprintf( 'Site %s does not exist.', $this->site['name'] ) ); + } + } + + + /** + * Function to install index.php file. + * + * @param array $data Data about url and version from `tools.json`. + * @param string $tool_path Path to where the tool needs to be installed. + */ + private function install_index( $data, $tool_path ) { + + $this->move_config_file( $tool_path . '.php', 'index.mustache' ); + } + + /** + * Function to install phpinfo.php file. + * + * @param array $data Data about url and version from `tools.json`. + * @param string $tool_path Path to where the tool needs to be installed. + */ + private function install_phpinfo( $data, $tool_path ) { + + $this->move_config_file( $tool_path . '.php', 'phpinfo.mustache' ); + } + + /** + * Function to install phpMyAdmin. + * + * @param array $data Data about url and version from `tools.json`. + * @param string $tool_path Path to where the tool needs to be installed. + */ + private function install_pma( $data, $tool_path ) { + + $temp_dir = EE\Utils\get_temp_dir(); + $download_path = $temp_dir . 'pma.zip'; + $version = str_replace( '.', '_', $data['version'] ); + $download_url = str_replace( '{version}', $version, $data['url'] ); + $this->download( $download_path, $download_url ); + $this->extract_zip( $download_path, $temp_dir ); + $this->fs->rename( $temp_dir . 'phpmyadmin-RELEASE_' . $version, $tool_path ); + $this->move_config_file( $tool_path . '/config.inc.php', 'pma.config.mustache' ); + } + + /** + * Function to install phpRedisAdmin. + * + * @param array $data Data about url and version from `tools.json`. + * @param string $tool_path Path to where the tool needs to be installed. + */ + private function install_pra( $data, $tool_path ) { + + $temp_dir = EE\Utils\get_temp_dir(); + $download_path = $temp_dir . 'pra.zip'; + $download_url = str_replace( '{version}', $data['version'], $data['url'] ); + $this->download( $download_path, $download_url ); + $this->extract_zip( $download_path, $temp_dir ); + $this->fs->rename( $temp_dir . 'phpRedisAdmin-' . $data['version'], $tool_path ); + $this->move_config_file( $tool_path . '/config.inc.php', 'pma.config.mustache' ); + } + +} From e3e5c46d46f481701e13d94b7d419ac63991a1f8 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 8 Aug 2018 18:10:13 +0530 Subject: [PATCH 07/26] Add initial admin-tools Signed-off-by: Riddhesh Sanghvi --- .distignore | 16 +++++++++++++++ .editorconfig | 25 ++++++++++++++++++++++++ .gitignore | 11 +++++++++++ README.md | 1 + admin-tools-command.php | 20 +++++++++++++++++++ composer.json | 25 ++++++++++++++++++++++++ ee.yml | 2 ++ phpcs.xml.dist | 43 +++++++++++++++++++++++++++++++++++++++++ tools.json | 18 +++++++++++++++++ 9 files changed, 161 insertions(+) create mode 100644 .distignore create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 README.md create mode 100644 admin-tools-command.php create mode 100644 composer.json create mode 100644 ee.yml create mode 100644 phpcs.xml.dist create mode 100644 tools.json diff --git a/.distignore b/.distignore new file mode 100644 index 0000000..acbaa32 --- /dev/null +++ b/.distignore @@ -0,0 +1,16 @@ +.DS_Store +.git +.gitignore +.gitlab-ci.yml +.editorconfig +.travis.yml +behat.yml +circle.yml +bin/ +features/ +utils/ +*.zip +*.tar.gz +*.swp +*.txt +*.log diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fa483b1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +# WordPress Coding Standards +# https://make.wordpress.org/core/handbook/coding-standards/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab + +[{.jshintrc,*.json,*.yml,*.feature}] +indent_style = space +indent_size = 2 + +[{*.txt,wp-config-sample.php}] +end_of_line = crlf + +[composer.json] +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b79291 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +.DS_Store +wp-cli.local.yml +node_modules/ +vendor/ +*.zip +*.tar.gz +*.swp +*.txt +*.log +composer.lock +.idea diff --git a/README.md b/README.md new file mode 100644 index 0000000..8f42f92 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# shell-command diff --git a/admin-tools-command.php b/admin-tools-command.php new file mode 100644 index 0000000..185d3ee --- /dev/null +++ b/admin-tools-command.php @@ -0,0 +1,20 @@ + + + WordPress Coding Standards for EE + + + + + + + + + + + . + */ci/* + */features/* + */packages/* + */tests/* + */utils/* + */vendor/* + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools.json b/tools.json new file mode 100644 index 0000000..7cbead5 --- /dev/null +++ b/tools.json @@ -0,0 +1,18 @@ +{ + "index": { + "url": "", + "version": "" + }, + "phpinfo": { + "url": "", + "version": "" + }, + "pma": { + "url": "https://github.com/phpmyadmin/phpmyadmin/archive/RELEASE_{version}.zip", + "version": "4.8.2" + }, + "pra": { + "url": "https://github.com/erikdubbelboer/phpRedisAdmin/archive/v{version}.zip", + "version": "1.10.2" + } +} From 0a842d8131f0ea7914da93c9a83d4744952e159b Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 9 Aug 2018 12:38:44 +0530 Subject: [PATCH 08/26] Add zend opcache gui Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 14 ++++++++++++++ tools.json | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 45171aa..4ccf895 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -270,4 +270,18 @@ private function install_pra( $data, $tool_path ) { $this->move_config_file( $tool_path . '/config.inc.php', 'pma.config.mustache' ); } + /** + * Function to install opcache gui. + * + * @param array $data Data about url and version from `tools.json`. + * @param string $tool_path Path to where the tool needs to be installed. + */ + private function install_opcache( $data, $tool_path ) { + + $temp_dir = EE\Utils\get_temp_dir(); + $download_path = $temp_dir . 'opcache-gui.php'; + $this->download( $download_path, $data['url'] ); + $this->fs->rename( $temp_dir . 'opcache-gui.php', $tool_path . '-gui.php' ); + } + } diff --git a/tools.json b/tools.json index 7cbead5..1b00bce 100644 --- a/tools.json +++ b/tools.json @@ -14,5 +14,9 @@ "pra": { "url": "https://github.com/erikdubbelboer/phpRedisAdmin/archive/v{version}.zip", "version": "1.10.2" + }, + "opcache": { + "url": "https://raw.githubusercontent.com/amnuts/opcache-gui/master/index.php", + "version": "" } } From 8666ee26005f095b617d030c7552d46fab152f26 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 9 Aug 2018 16:39:07 +0530 Subject: [PATCH 09/26] Remove listing of index.php from admin-tools Signed-off-by: Riddhesh Sanghvi --- templates/index.mustache | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/index.mustache b/templates/index.mustache index 7999c77..67cbbf4 100644 --- a/templates/index.mustache +++ b/templates/index.mustache @@ -59,6 +59,8 @@ unset( $services['sitename'] ); $scan = scandir( '/var/www/htdocs/ee-admin' ); $tools = array_slice( $scan, 2 ); +$tools = array_diff( $tools, [ 'index.php' ] ); + if ( ! $services['cache_type'] ) { $tools = array_diff( $tools, [ 'pra' ] ); } From fb6490b0d3fac71e1f9ba84daf54ed57117d9a67 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 10 Aug 2018 19:16:27 +0530 Subject: [PATCH 10/26] Add composer installation Update move config function --- src/Admin_Tools_Command.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 4ccf895..b690e18 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -12,6 +12,8 @@ */ use \Symfony\Component\Filesystem\Filesystem; +use \Composer\Console\Application; +use \Symfony\Component\Console\Input\ArrayInput; class Admin_Tools_Command extends EE_Command { @@ -56,6 +58,8 @@ public function install() { $tool_path = ADMIN_TOOL_DIR . '/' . $tool; call_user_func_array( [ $this, "install_$tool" ], [ $data, $tool_path ] ); EE::log( 'Done.' ); + } else { + EE::log( "$tool already installed." ); } } } @@ -140,6 +144,7 @@ public function down( $args, $assoc_args ) { private function is_installed( $tool = '' ) { $tool = in_array( $tool, [ 'index', 'phpinfo' ] ) ? $tool . '.php' : $tool; + $tool = 'opcache' === $tool ? $tool . '-gui.php' : $tool; return $this->fs->exists( ADMIN_TOOL_DIR . '/' . $tool ); } @@ -185,10 +190,10 @@ private function extract_zip( $zip_file, $path_to_extract ) { /** * Place config files from templates to tools. * - * @param string $config_file Path where the config file needs to go. - * @param string $template_file Template file from which the config needs to be created. + * @param string $config_file Destination Path where the config file needs to go. + * @param string $template_file Source Template file from which the config needs to be created. */ - private function move_config_file( $config_file, $template_file ) { + private function move_config_file( $template_file, $config_file ) { $this->fs->dumpFile( $config_file, file_get_contents( ADMIN_TEMPLATE_ROOT . '/' . $template_file ) ); } @@ -212,6 +217,16 @@ private function populate_site_info( $args ) { } } + private function composer_install( $tool_path ) { + + putenv( 'COMPOSER_HOME=' . EE_VENDOR_DIR . '/bin/composer' ); + chdir( $tool_path ); + $input = new ArrayInput( array( 'command' => 'install' ) ); + $application = new Application(); + $application->setAutoExit( false ); + $application->run( $input ); + } + /** * Function to install index.php file. @@ -221,7 +236,7 @@ private function populate_site_info( $args ) { */ private function install_index( $data, $tool_path ) { - $this->move_config_file( $tool_path . '.php', 'index.mustache' ); + $this->move_config_file( 'index.mustache', $tool_path . '.php' ); } /** @@ -232,7 +247,7 @@ private function install_index( $data, $tool_path ) { */ private function install_phpinfo( $data, $tool_path ) { - $this->move_config_file( $tool_path . '.php', 'phpinfo.mustache' ); + $this->move_config_file( 'phpinfo.mustache', $tool_path . '.php' ); } /** @@ -250,7 +265,8 @@ private function install_pma( $data, $tool_path ) { $this->download( $download_path, $download_url ); $this->extract_zip( $download_path, $temp_dir ); $this->fs->rename( $temp_dir . 'phpmyadmin-RELEASE_' . $version, $tool_path ); - $this->move_config_file( $tool_path . '/config.inc.php', 'pma.config.mustache' ); + $this->move_config_file( 'pma.config.mustache', $tool_path . '/config.inc.php' ); + $this->composer_install( $tool_path ); } /** @@ -267,7 +283,8 @@ private function install_pra( $data, $tool_path ) { $this->download( $download_path, $download_url ); $this->extract_zip( $download_path, $temp_dir ); $this->fs->rename( $temp_dir . 'phpRedisAdmin-' . $data['version'], $tool_path ); - $this->move_config_file( $tool_path . '/config.inc.php', 'pma.config.mustache' ); + $this->move_config_file( 'pra.config.mustache', $tool_path . 'includes/config.inc.php' ); + $this->composer_install( $tool_path ); } /** From 8f3fbade8b893652d2a3c88ae707bb4b1fb75fa1 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 11:06:02 +0530 Subject: [PATCH 11/26] Update according to db refactoring Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 82 ++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index b690e18..8dc3082 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -29,9 +29,9 @@ class Admin_Tools_Command extends EE_Command { private $fs; /** - * @var array $site Associative array containing essential site related information. + * @var array $db Object containing essential site related information. */ - private $site; + private $db; public function __construct() { @@ -72,20 +72,32 @@ public function install() { * * [] * : Name of website to enable admin-tools on. + * + * [--force] + * : Force enabling of admin-tools for a site. */ public function up( $args, $assoc_args ) { EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' start' ); - $args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ ); - $this->populate_site_info( $args ); - chdir( $this->site['root'] ); + $args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ ); + $force = EE\Utils\get_flag_value( $assoc_args, 'force' ); + $this->db = Site::find( EE\Utils\remove_trailing_slash( $args[0] ) ); + if ( ! $this->db || ! $this->db->site_enabled ) { + EE::error( sprintf( 'Site %s does not exist / is not enabled.', $args[0] ) ); + } + + if ( $this->db->admin_tools && ! $force ) { + EE::error( sprintf( 'admin-tools already seem to be enabled for %s', $this->db->site_url ) ); + } + + chdir( $this->db->site_fs_path ); $launch = EE::launch( 'docker-compose config --services' ); $services = explode( PHP_EOL, trim( $launch->stdout ) ); $min_req_services = [ 'nginx', 'php' ]; if ( count( array_intersect( $services, $min_req_services ) ) !== count( $min_req_services ) ) { - EE::error( sprintf( '%s site-type of %s-command does not support admin-tools.', $this->site['type'], $this->site['command'] ) ); + EE::error( sprintf( '%s site-type of %s-command does not support admin-tools.', $this->db->app_sub_type, $this->db->site_type ) ); } if ( ! $this->is_installed() ) { @@ -93,17 +105,14 @@ public function up( $args, $assoc_args ) { $this->install(); } - // TODO: services_enabled fnuction after db changes - // if($this->services_enabled()){ - // EE::error('Services are already enabled.'); - // } - - $this->move_config_file( $this->site['root'] . '/docker-compose-admin.yml', 'docker-compose-admin.mustache' ); + $this->move_config_file( $this->db->site_fs_path . '/docker-compose-admin.yml', 'docker-compose-admin.mustache' ); if ( EE::exec( 'docker-compose -f docker-compose.yml -f docker-compose-admin.yml up -d nginx' ) ) { - EE::success( sprintf( 'admin-tools enabled for %s site.', $this->site['name'] ) ); + EE::success( sprintf( 'admin-tools enabled for %s site.', $this->db->site_url ) ); + $this->db->admin_tools = 1; + $this->db->save(); } else { - EE::error( sprintf( 'Error in enabling admin-tools for %s site. Check logs.', $this->site['name'] ) ); + EE::error( sprintf( 'Error in enabling admin-tools for %s site. Check logs.', $this->db->site_url ) ); } EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' stop' ); @@ -116,21 +125,28 @@ public function up( $args, $assoc_args ) { * * [] * : Name of website to disable admin-tools on. + * + * [--force] + * : Force disabling of admin-tools for a site. */ public function down( $args, $assoc_args ) { EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' start' ); - $args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ ); - $this->populate_site_info( $args ); - - // TODO: services_enabled fnuction after db changes - // if($this->services_enabled()){ - // Then only run this... - // } + $args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ ); + $force = EE\Utils\get_flag_value( $assoc_args, 'force' ); + $this->db = Site::find( EE\Utils\remove_trailing_slash( $args[0] ) ); + if ( ! $this->db || ! $this->db->site_enabled ) { + EE::error( sprintf( 'Site %s does not exist / is not enabled.', $args[0] ) ); + } - EE::docker()::docker_compose_up( $this->site['root'], [ 'nginx', 'php' ] ); - EE::success( sprintf( 'admin-tools disabled for %s site.', $this->site['name'] ) ); + if ( ! $this->db->admin_tools && ! $force ) { + EE::error( sprintf( 'admin-tools already seem to be enabled for %s', $this->db->site_url ) ); + } + EE::docker()::docker_compose_up( $this->db->site_fs_path, [ 'nginx', 'php' ] ); + EE::success( sprintf( 'admin-tools disabled for %s site.', $this->db->site_url ) ); + $this->db->admin_tools = 0; + $this->db->save(); EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' stop' ); } @@ -198,25 +214,6 @@ private function move_config_file( $template_file, $config_file ) { $this->fs->dumpFile( $config_file, file_get_contents( ADMIN_TEMPLATE_ROOT . '/' . $template_file ) ); } - /** - * Populate basic site info from db. - */ - private function populate_site_info( $args ) { - - $this->site['name'] = EE\Utils\remove_trailing_slash( $args[0] ); - - if ( EE::db()::site_in_db( $this->site['name'] ) ) { - - $db_select = EE::db()::select( [], [ 'sitename' => $this->site['name'] ], 'sites', 1 ); - - $this->site['type'] = $db_select['site_type']; - $this->site['root'] = $db_select['site_path']; - $this->site['command'] = $db_select['site_command']; - } else { - EE::error( sprintf( 'Site %s does not exist.', $this->site['name'] ) ); - } - } - private function composer_install( $tool_path ) { putenv( 'COMPOSER_HOME=' . EE_VENDOR_DIR . '/bin/composer' ); @@ -227,7 +224,6 @@ private function composer_install( $tool_path ) { $application->run( $input ); } - /** * Function to install index.php file. * From 6e392332d09620edacd19d14cc07258541573529 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 12:08:48 +0530 Subject: [PATCH 12/26] Add inclusion of site mode Switch from composer install to update Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 8dc3082..57da42c 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -11,6 +11,7 @@ * @package ee-cli */ +use EE\Model\Site; use \Symfony\Component\Filesystem\Filesystem; use \Composer\Console\Application; use \Symfony\Component\Console\Input\ArrayInput; @@ -218,7 +219,7 @@ private function composer_install( $tool_path ) { putenv( 'COMPOSER_HOME=' . EE_VENDOR_DIR . '/bin/composer' ); chdir( $tool_path ); - $input = new ArrayInput( array( 'command' => 'install' ) ); + $input = new ArrayInput( array( 'command' => 'update' ) ); $application = new Application(); $application->setAutoExit( false ); $application->run( $input ); From fb2ba53a6bdba7588d77a5ae22a3af9a0f39d36f Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 12:18:07 +0530 Subject: [PATCH 13/26] Update config file move function call Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 57da42c..d4ebb00 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -106,7 +106,7 @@ public function up( $args, $assoc_args ) { $this->install(); } - $this->move_config_file( $this->db->site_fs_path . '/docker-compose-admin.yml', 'docker-compose-admin.mustache' ); + $this->move_config_file( 'docker-compose-admin.mustache', $this->db->site_fs_path . '/docker-compose-admin.yml' ); if ( EE::exec( 'docker-compose -f docker-compose.yml -f docker-compose-admin.yml up -d nginx' ) ) { EE::success( sprintf( 'admin-tools enabled for %s site.', $this->db->site_url ) ); From aa5c9cfbd8943f13a1eb523df2aede0860b250c0 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 12:25:02 +0530 Subject: [PATCH 14/26] Fix file moving Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index d4ebb00..4dc55d4 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -280,7 +280,7 @@ private function install_pra( $data, $tool_path ) { $this->download( $download_path, $download_url ); $this->extract_zip( $download_path, $temp_dir ); $this->fs->rename( $temp_dir . 'phpRedisAdmin-' . $data['version'], $tool_path ); - $this->move_config_file( 'pra.config.mustache', $tool_path . 'includes/config.inc.php' ); + $this->move_config_file( 'pra.config.mustache', $tool_path . '/includes/config.inc.php' ); $this->composer_install( $tool_path ); } From 2a309912b01fe8d8bf3c1be614dd820e5e9fb476 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 12:25:31 +0530 Subject: [PATCH 15/26] Update index according to db refactoring Signed-off-by: Riddhesh Sanghvi --- templates/index.mustache | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/index.mustache b/templates/index.mustache index 67cbbf4..b9b24c0 100644 --- a/templates/index.mustache +++ b/templates/index.mustache @@ -3,7 +3,7 @@ function populate_site_info() { $site_name = $_SERVER['HTTP_HOST']; - $db_select = select( [], array( 'sitename' => $site_name ), 'sites', 1 ); + $db_select = select( [], array( 'site_url' => $site_name ), 'sites', 1 ); return $db_select[0]; @@ -53,7 +53,7 @@ function select( $columns = array(), $where = array(), $table_name = 'services', $services = populate_site_info(); unset( $services['id'] ); -unset( $services['sitename'] ); +unset( $services['site_url'] ); $scan = scandir( '/var/www/htdocs/ee-admin' ); @@ -61,7 +61,7 @@ $tools = array_slice( $scan, 2 ); $tools = array_diff( $tools, [ 'index.php' ] ); -if ( ! $services['cache_type'] ) { +if ( ! $services['cache_nginx_fullpage'] ) { $tools = array_diff( $tools, [ 'pra' ] ); } From 7cc3538389955253eace3f3793b727be9ff071d3 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 14:34:36 +0530 Subject: [PATCH 16/26] Remove wp-cli specific ignore file Signed-off-by: Riddhesh Sanghvi --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4b79291..6b6c3ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .DS_Store -wp-cli.local.yml node_modules/ vendor/ *.zip From d7bd48877d480c7250290763bb9b542ee0dc3024 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 14:36:46 +0530 Subject: [PATCH 17/26] Update editorconfig Signed-off-by: Riddhesh Sanghvi --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index fa483b1..e14d024 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,7 +17,7 @@ indent_style = tab indent_style = space indent_size = 2 -[{*.txt,wp-config-sample.php}] +[{*.txt}] end_of_line = crlf [composer.json] From 35cde10c8b21218da2e0ff51dc752ebaefe92116 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 16:28:58 +0530 Subject: [PATCH 18/26] Remove extra lines Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 4dc55d4..249e538 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -18,7 +18,6 @@ class Admin_Tools_Command extends EE_Command { - /** * @var string $command Name of the command being run. */ @@ -65,7 +64,6 @@ public function install() { } } - /** * Enables admin-tools on given site. * From 98b82629589371921fc0ac2e357287dca84813b3 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 16:44:06 +0530 Subject: [PATCH 19/26] Update json handling validations Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 249e538..5e0462d 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -50,7 +50,26 @@ public function install() { $this->fs->mkdir( ADMIN_TOOL_DIR ); } - $tools = json_decode( file_get_contents( ADMIN_TOOLS_FILE ), true ); + $tools_file_info = pathinfo( ADMIN_TOOLS_FILE ); + EE::debug( 'admin-tools file: ' . ADMIN_TOOLS_FILE ); + + if ( 'json' !== $tools_file_info['extension'] ) { + EE::error( 'Invalid admin-tools file found. Aborting.' ); + } + + $tools_file = file_get_contents( ADMIN_TOOLS_FILE ); + if ( empty( $tools_file ) ) { + EE::error( 'admin-tools file is empty. Can\'t proceed further.' ); + } + $tools = json_decode( $tools_file, true ); + if ( empty( $tools ) ) { + EE::error( 'No data found in admin-tools file. Can\'t proceed further.' ); + } + $json_error = json_last_error(); + if ( $json_error != JSON_ERROR_NONE ) { + EE::debug( 'Json last error: ' . $json_error ); + EE::error( 'Error decoding admin-tools file.' ); + } foreach ( $tools as $tool => $data ) { if ( ! $this->is_installed( $tool ) ) { From ff6964f0cb22cc2e1aabf49681a188708fa12670 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 16:46:44 +0530 Subject: [PATCH 20/26] Add check before user_call_func Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 5e0462d..16311db 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -75,7 +75,11 @@ public function install() { if ( ! $this->is_installed( $tool ) ) { EE::log( "Installing $tool" ); $tool_path = ADMIN_TOOL_DIR . '/' . $tool; - call_user_func_array( [ $this, "install_$tool" ], [ $data, $tool_path ] ); + if ( method_exists( $this, "install_$tool" ) ) { + call_user_func_array( [ $this, "install_$tool" ], [ $data, $tool_path ] ); + } else { + EE::warning( "No method found to install $tool. Skipping it." ); + } EE::log( 'Done.' ); } else { EE::log( "$tool already installed." ); From 091d2eca7dd10a653c3907e0a90dd63ba98931d1 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 16:49:11 +0530 Subject: [PATCH 21/26] Add doc comment Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 16311db..f8d9b59 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -236,6 +236,11 @@ private function move_config_file( $template_file, $config_file ) { $this->fs->dumpFile( $config_file, file_get_contents( ADMIN_TEMPLATE_ROOT . '/' . $template_file ) ); } + /** + * Function to run install composer dependencies in tools that require it. + * + * @param string $tool_path Directory of the tool that contains `composer.json` file. + */ private function composer_install( $tool_path ) { putenv( 'COMPOSER_HOME=' . EE_VENDOR_DIR . '/bin/composer' ); From e960a6e57bf39a023d6d44087187af1c78999021 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 16:58:37 +0530 Subject: [PATCH 22/26] Update doc-comments in index mustache Signed-off-by: Riddhesh Sanghvi --- templates/index.mustache | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/templates/index.mustache b/templates/index.mustache index b9b24c0..401d89b 100644 --- a/templates/index.mustache +++ b/templates/index.mustache @@ -1,5 +1,11 @@ Date: Tue, 21 Aug 2018 17:41:37 +0530 Subject: [PATCH 23/26] Remove extra variable Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index f8d9b59..1655b46 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -35,7 +35,6 @@ class Admin_Tools_Command extends EE_Command { public function __construct() { - $this->command = 'admin-tools'; $this->fs = new Filesystem(); define( 'ADMIN_TOOL_DIR', EE_CONF_ROOT . '/admin-tools' ); } @@ -100,7 +99,7 @@ public function install() { */ public function up( $args, $assoc_args ) { - EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' start' ); + EE\Utils\delem_log( 'admin-tools ' . __FUNCTION__ . ' start' ); $args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ ); $force = EE\Utils\get_flag_value( $assoc_args, 'force' ); $this->db = Site::find( EE\Utils\remove_trailing_slash( $args[0] ) ); @@ -137,7 +136,7 @@ public function up( $args, $assoc_args ) { EE::error( sprintf( 'Error in enabling admin-tools for %s site. Check logs.', $this->db->site_url ) ); } - EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' stop' ); + EE\Utils\delem_log( 'admin-tools ' . __FUNCTION__ . ' stop' ); } /** @@ -153,7 +152,7 @@ public function up( $args, $assoc_args ) { */ public function down( $args, $assoc_args ) { - EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' start' ); + EE\Utils\delem_log( 'admin-tools ' . __FUNCTION__ . ' start' ); $args = EE\SiteUtils\auto_site_name( $args, $this->command, __FUNCTION__ ); $force = EE\Utils\get_flag_value( $assoc_args, 'force' ); $this->db = Site::find( EE\Utils\remove_trailing_slash( $args[0] ) ); @@ -169,7 +168,7 @@ public function down( $args, $assoc_args ) { EE::success( sprintf( 'admin-tools disabled for %s site.', $this->db->site_url ) ); $this->db->admin_tools = 0; $this->db->save(); - EE\Utils\delem_log( $this->command . ' ' . __FUNCTION__ . ' stop' ); + EE\Utils\delem_log( 'admin-tools ' . __FUNCTION__ . ' stop' ); } /** From 37b0dc9ab00da6afd5705b73afc6a8c09904c777 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 17:50:53 +0530 Subject: [PATCH 24/26] Update important path in index via mustaching Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 9 +++++++-- templates/index.mustache | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 1655b46..573a148 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -35,7 +35,7 @@ class Admin_Tools_Command extends EE_Command { public function __construct() { - $this->fs = new Filesystem(); + $this->fs = new Filesystem(); define( 'ADMIN_TOOL_DIR', EE_CONF_ROOT . '/admin-tools' ); } @@ -258,7 +258,12 @@ private function composer_install( $tool_path ) { */ private function install_index( $data, $tool_path ) { - $this->move_config_file( 'index.mustache', $tool_path . '.php' ); + $index_path_data = [ + 'db_path' => DB, + 'ee_admin_path' => '/var/www/htdocs/ee-admin', + ]; + $index_file = EE\Utils\mustache_render( ADMIN_TEMPLATE_ROOT . '/index.mustache', $index_path_data ); + $this->fs->dumpFile( $tool_path . '.php', $index_file ); } /** diff --git a/templates/index.mustache b/templates/index.mustache index 401d89b..a406200 100644 --- a/templates/index.mustache +++ b/templates/index.mustache @@ -27,7 +27,7 @@ function populate_site_info() { */ function select( $columns = array(), $where = array(), $table_name = 'services', $limit = null ) { - $db_path = '/opt/easyengine/ee.sqlite'; + $db_path = '{{db_path}}'; $db = new SQLite3( $db_path ); $conditions = array(); @@ -72,7 +72,7 @@ unset( $services['id'] ); unset( $services['site_url'] ); -$scan = scandir( '/var/www/htdocs/ee-admin' ); +$scan = scandir( '{{ee_admin_path}}' ); $tools = array_slice( $scan, 2 ); $tools = array_diff( $tools, [ 'index.php' ] ); From 50dd6577d576a4f877ec5c8fddc8b0ae46932795 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 18:24:14 +0530 Subject: [PATCH 25/26] Update flow and warning to error Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 573a148..26ff04c 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -61,14 +61,14 @@ public function install() { EE::error( 'admin-tools file is empty. Can\'t proceed further.' ); } $tools = json_decode( $tools_file, true ); - if ( empty( $tools ) ) { - EE::error( 'No data found in admin-tools file. Can\'t proceed further.' ); - } $json_error = json_last_error(); if ( $json_error != JSON_ERROR_NONE ) { EE::debug( 'Json last error: ' . $json_error ); EE::error( 'Error decoding admin-tools file.' ); } + if ( empty( $tools ) ) { + EE::error( 'No data found in admin-tools file. Can\'t proceed further.' ); + } foreach ( $tools as $tool => $data ) { if ( ! $this->is_installed( $tool ) ) { @@ -77,7 +77,7 @@ public function install() { if ( method_exists( $this, "install_$tool" ) ) { call_user_func_array( [ $this, "install_$tool" ], [ $data, $tool_path ] ); } else { - EE::warning( "No method found to install $tool. Skipping it." ); + EE::error( "No method found to install $tool. Aborting." ); } EE::log( 'Done.' ); } else { From 00fc2532f44c3494dac1633524f38f065cd2f4d2 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Tue, 21 Aug 2018 19:11:39 +0530 Subject: [PATCH 26/26] Update log msg to success Signed-off-by: Riddhesh Sanghvi --- src/Admin_Tools_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Admin_Tools_Command.php b/src/Admin_Tools_Command.php index 26ff04c..bc5b9fe 100644 --- a/src/Admin_Tools_Command.php +++ b/src/Admin_Tools_Command.php @@ -79,7 +79,7 @@ public function install() { } else { EE::error( "No method found to install $tool. Aborting." ); } - EE::log( 'Done.' ); + EE::success( "Installed $tool successfully." ); } else { EE::log( "$tool already installed." ); }