/** * Performs host check and then does a backup of the DB * * * @author Jeff Behnke <*****@*****.**> * @copyright (c) 2009-15 ValidWebs.com * * Created: 11/22/15, 2:45 PM * * @param $host * * @return bool|string */ function vvv_dash_wp_backup($host) { if (isset($host)) { $type = check_host_type($host); if (isset($type['key'])) { if (isset($type['path'])) { $path = VVV_WEB_ROOT . '/' . $type['key'] . $type['path']; $db_settings = get_wp_db_settings($path); } else { $path = VVV_WEB_ROOT . '/' . $type['key'] . '/'; $db_settings = get_wp_db_settings($path); } } else { $host = strstr($host, '.', true); $path = VVV_WEB_ROOT . '/' . $host . '/htdocs'; $db_settings = get_wp_db_settings($path); } if (is_array($db_settings) && $path) { $file_name = 'dumps/' . $host . '_' . date('m-d-Y_g-i-s', time()) . '.sql'; $export = shell_exec('wp db export --add-drop-table --path=' . $path . ' ' . $file_name); if (file_exists($file_name)) { return vvv_dash_notice('Your backup is ready at www/default/dashboard/' . $file_name); } } else { return false; } } return false; }
} } if (isset($_POST['create_child']) && isset($_POST['child']) && !empty($_POST['child'])) { $themes_array = get_csv_names($themes); $host_info = $vvv_dash->set_host_info($_POST['host']); $host_path = VVV_WEB_ROOT . '/' . $host_info['host'] . $host_info['path']; $child = strtolower(str_replace(' ', '_', $_POST['child'])); if (in_array($child, $themes_array)) { echo vvv_dash_error('Error: That theme already exists!'); } else { $cmd = 'wp scaffold child-theme ' . $child . ' --theme_name="' . $_POST['theme_name'] . '" --parent_theme=' . $_POST['item'] . ' --path=' . $host_path . ' --debug'; $new_theme = shell_exec($cmd); if ($new_theme) { $purge_status = $cache->purge('-themes'); echo vvv_dash_notice($purge_status . ' files were purged from cache!'); echo vvv_dash_notice($new_theme); } else { echo vvv_dash_error('<strong>Error:</strong> Something went wrong!'); } } } $host_info = $vvv_dash->set_host_info($_GET['host']); $themes = $vvv_dash->get_themes_data($host_info['host'], $host_info['path']); echo format_table($themes, $_GET['host'], 'themes'); } } if ($debug_log_path && file_exists($debug_log_path) && !empty($debug_log_lines)) { if (isset($_GET['host'])) { ?> <h4>Debug Log for <span class="red"><?php
* LICENSE: * * @author Jeff Behnke <*****@*****.**> * @copyright (c) 2015 ValidWebs.com * * dashboard * notices.php */ //if($purge_status) { // purge_status( $purge_status ); //} if (VVV_DASH_VERSION < version_check()) { ?> <div class="alert alert-danger alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> <p>A new version of <em> VVV Dashboard</em> is available. <br />Your current version: <?php echo VVV_DASH_VERSION; ?> <br /> <strong> New version: <?php echo version_check(); ?> </strong></p> </div><?php echo vvv_dash_notice('<h3>New Features in the new release.</h3>' . vvv_dash_new_features()); } if ($status) { echo $status; } // End notices.php
/** * Process $_POST supper globals used in the dashboard * * @author Jeff Behnke <*****@*****.**> * @copyright (c) 2009-15 ValidWebs.com * * Created: 12/8/15, 4:01 PM * * @return bool|string */ public function process_post() { $status = false; if (isset($_POST)) { if (isset($_POST['install_dev_plugins']) && isset($_POST['host'])) { $status = $this->install_dev_plugins($_POST); } if (isset($_POST['backup']) && isset($_POST['host'])) { $status = $this->create_db_backup($_POST['host']); } if (isset($_POST['roll_back']) && $_POST['roll_back'] == 'Roll Back') { $status = $this->db_roll_back($_POST['host'], $_POST['file_path']); if ($status) { $status = vvv_dash_notice($status); } } if (isset($_POST['purge_hosts'])) { $purge_status = $this->_cache->purge('host-sites'); $status = vvv_dash_notice($purge_status . ' files were purged from cache!'); } if (isset($_POST['purge_themes'])) { $purge_status = $this->_cache->purge('-themes'); $status = vvv_dash_notice($purge_status . ' files were purged from cache!'); } if (isset($_POST['purge_plugins'])) { $purge_status = $this->_cache->purge('-plugins'); $status = vvv_dash_notice($purge_status . ' files were purged from cache!'); } if (isset($_POST['update_item']) && isset($_POST['host'])) { $type = check_host_type($_POST['host']); if (isset($type['key'])) { if (isset($type['path'])) { if (!empty($_POST['type']) && 'plugins' == $_POST['type']) { $update_status = shell_exec('wp plugin update ' . $_POST['item'] . ' --path=' . VVV_WEB_ROOT . '/' . $type['key'] . $type['path']); $purge_status = $_POST['item'] . ' was updated!<br />'; $purge_status .= $this->_cache->purge('-plugins'); $status = vvv_dash_notice($purge_status . ' files were purged from cache!'); } if (!empty($_POST['type']) && 'themes' == $_POST['type']) { $status = shell_exec('wp theme update ' . $_POST['item'] . ' --path=' . VVV_WEB_ROOT . '/' . $type['key'] . $type['path']); $purge_status = $_POST['item'] . ' was updated!<br />'; $purge_status .= $this->_cache->purge('-themes'); $status = vvv_dash_notice($purge_status . ' files were purged from cache!'); } } else { if (!empty($_POST['type']) && 'plugins' == $_POST['type']) { $update_status = shell_exec('wp plugin update ' . $_POST['item'] . ' --path=' . VVV_WEB_ROOT . '/' . $type['key'] . '/'); $purge_status = $_POST['item'] . ' was updated!<br />'; $purge_status .= $this->_cache->purge('-plugins'); $status = vvv_dash_notice($purge_status . ' files were purged from cache!'); } if (!empty($_POST['type']) && 'themes' == $_POST['type']) { $update_status = shell_exec('wp theme update ' . $_POST['item'] . ' --path=' . VVV_WEB_ROOT . '/' . $type['key'] . '/'); $purge_status = $_POST['item'] . ' was updated!<br />'; $purge_status .= $this->_cache->purge('-themes'); $status = vvv_dash_notice($purge_status . ' files were purged from cache!'); } } } else { $host_info = $this->set_host_info($_POST['host']); $is_env = isset($host_info['is_env']) ? $host_info['is_env'] : false; $host = $host_info['host']; // WP Starter if ($is_env) { $host_path = VVV_WEB_ROOT . '/' . $host . '/public/wp'; } else { // Normal WP $host_path = VVV_WEB_ROOT . '/' . $host . '/' . $host_info['path']; } if (!empty($_POST['type']) && 'plugins' == $_POST['type']) { $update_status = shell_exec('wp plugin update ' . $_POST['item'] . ' --path=' . $host_path); $purge_status = $_POST['item'] . ' was updated!<br />'; $purge_status .= $this->_cache->purge('-plugins'); $status = vvv_dash_notice($purge_status . ' files were purged from cache!'); } if (!empty($_POST['type']) && 'themes' == $_POST['type']) { $status = shell_exec('wp theme update ' . $_POST['item'] . ' --path=' . $host_path); $purge_status = $_POST['item'] . ' was updated!<br />'; $purge_status .= $this->_cache->purge('-themes'); $status = vvv_dash_notice($purge_status . ' files were purged from cache!'); } } } } return $status; }
/** * Get all backups and list them in a nice table * * @author Jeff Behnke <*****@*****.**> * @copyright (c) 2009-15 ValidWebs.com * * Created: 12/3/15, 1:10 AM * * @return string */ function get_backups_table() { if (isset($_POST['file_path'])) { if (isset($_POST['delete_backup']) && $_POST['delete_backup'] == 'Delete') { $file = urldecode($_POST['file_path']); if (file_exists($file)) { // @ToDo verify with the user (Are you sure!) unlink($file); $notice = $file . ' was deleted.'; } } // @ToDo create roll back function // if ( isset( $_POST['roll_back'] ) && $_POST['roll_back'] == 'Roll Back' ) { // $notice = 'DB roll backs are not quite ready yet. Will be coming in a release soon!'; // } } $backups = dir_to_array(VVV_WEB_ROOT . '/default/dashboard/dumps'); $file_info = array(); $table_data = array(); $table = ''; if (!empty($notice)) { $table .= vvv_dash_notice($notice); } $table .= '<table class="table table-responsive table-striped table-bordered table-hover">'; $table .= '<thead><tr>'; $table .= '<th>Host</th>'; $table .= '<th>Date <small>( M-D-Y )</small></th>'; $table .= '<th>Time <small>( H : M : S )</small></th>'; $table .= '<th>Actions</th>'; $table .= '</tr></thead>'; foreach ($backups as $key => $file_path) { $file = str_replace('dumps/', '', strstr($file_path, 'dumps/')); $file_info[$key]['file'] = $file; $file_info[$key]['file_path'] = VVV_WEB_ROOT . '/default/dashboard/dumps/' . $file; $file_parts = explode('_', $file); $file_info[$key]['file_host'] = $file_parts[0]; $file_info[$key]['file_date'] = $file_parts[1]; $file_info[$key]['file_time'] = str_replace('.sql', '', $file_parts[2]); $host = strpos($file_parts[0], '.dev') == true ? $file_parts[0] : strpos($file_parts[0], '.com') == true ? $file_parts[0] : $file_parts[0] . '.dev'; // Table data $table_data[] .= '<tr>'; $table_data[] .= '<td>' . $host . '</td>'; $table_data[] .= '<td>' . $file_parts[1] . '</td>'; $table_data[] .= '<td>' . str_replace(array('.sql', '-'), array('', ':'), $file_parts[2]) . '</td>'; $table_data[] .= '<td> <a class="btn btn-primary btn-xs" href="dumps/' . $file . '">Save As</a> <form class="" action="" method="post"> <input type="hidden" name="get_backups" value="Backups" /> <input type="hidden" name="host" value="' . $host . '" /> <input type="hidden" name="file_path" value="' . urlencode($file_info[$key]['file_path']) . '" /> '; if (strpos($file_parts[0], '.com') == false) { $table_data[] .= '<input type = "submit" class="btn btn-warning btn-xs" name = "roll_back" value = "Roll Back" /> '; } $table_data[] .= '<input type="submit" class="btn btn-danger btn-xs" name="delete_backup" value="Delete" /> </form> </td>'; $table_data[] .= '</tr>'; } // end foreach $table .= implode('', $table_data); $table .= '</table>'; return $table; }