data_path = "astra-install.json"; $this->response = array( 'success' => false, 'msg' => "", ); $this->log = ""; $this->run(); } function __destruct() { //$this->print_log(); } protected function log($msg) { $this->log .= "
" . $msg . "
\r\n"; $this->log_count++; } public function getLogs() { return $this->log; } public function getInstalled(){ return file_exists('astra/astra-inc.php') || $this->installed; } protected function print_log() { echo $this->log; } protected function respond($success, $msg = '') { $this->response['success'] = $success; if (!empty($msg)) { $this->response['msg'] = $msg; } header('Content-Type: application/json'); echo json_encode($this->response, JSON_PRETTY_PRINT); exit; } protected function load_json() { if (file_exists($this->data_path)) { $string = file_get_contents($this->data_path); $json_data = json_decode($string, true); } if (!empty($json_data) && is_array($json_data)) { return $json_data; } return array(); } protected function save_json() { return true; $saved = file_put_contents($this->data_path, json_encode($this->websites)); return is_int($saved); } public function is_astra_installed($path) { return file_exists($path . 'astra'); } protected function clean_install($path) { $zip_path = $this->get_astra_zip_path($path); unlink($zip_path); $this->log('Deleting the ZIP file.'); return !file_exists($zip_path); } protected function do_install($path = '') { $key = 0; $this->websites[$key]['installed_astra'] = FALSE; if ($this->is_astra_installed($path)) { $this->log("Astra already installed. Nothing to do! :)"); return $this->websites[$key]; } $this->log("-----------"); $this->log("Installing for " . $_SERVER['HTTP_HOST']); $function_name = "install_default"; if (method_exists($this, $function_name)) { $installed = $this->$function_name($path); if ($installed == true) { $this->websites[$key]['installed_astra'] = TRUE; $this->log("Installed for $path"); //$this->respond(true, 'Installed for ' . $website['user']); } else { $this->websites[$key]['installed_astra'] = FALSE; $this->websites[$key]['reason_for_failure'] = $installed; $this->log("Unable to install. Please email help@getastra.com if you need help"); //$this->respond(false, 'Unable to install for ' . $website['user']); } } return $this->websites[$key]; } protected function meets_requirements() { if (!defined('PDO::ATTR_DRIVER_NAME')) { $this->log('PDO Driver Missing. Please install or enable in cPanel.'); return FALSE; } if(!class_exists('ZipArchive')){ $this->log('ZipArchive Default Class is missing. Please install or enable in cPanel.'); return FALSE; } if (!extension_loaded('sqlite3')) { $this->log('sqlite3 extension not loaded. Please install or enable in cPanel. Find installation guides here.'); return FALSE; } $pdo_drivers = PDO::getAvailableDrivers(); if(!is_array($pdo_drivers) || !in_array('sqlite', $pdo_drivers)){ $this->log('pdo_sqlite extension not loaded. Please install or enable in cPanel. Find installation guides here.'); } return TRUE; } protected function is_astra_included_in_user_ini($file_path) { if (!file_exists($file_path)) { return false; } $contents = file_get_contents($file_path); if (strpos($contents, 'astra-inc') !== false) { return true; } return false; } protected function update_user_ini($path, $astra_inc_path) { $path_user_ini = $path . '.user.ini'; if ($this->is_astra_included_in_user_ini($path_user_ini)) { return true; } $file_content = "auto_prepend_file=$astra_inc_path\n\r"; $write = false; if (!file_exists($path_user_ini)) { $write = file_put_contents($path_user_ini, $file_content); } else { $old_contents = file_get_contents($path_user_ini); $file_content .= "\r\n" . $old_contents; $write = file_put_contents($path_user_ini, $file_content); $this->log("Updated existing .user.ini"); } return $write; } protected function install_default($path, $plugin_folder_path = '') { if (empty($plugin_folder_path)) { $plugin_folder_path = $path; } $plugin_zip_path = $this->get_astra_zip_path($path); $username = ""; if (file_exists($plugin_zip_path . 'astra')) { $this->log("Astra is already installed"); return false; } if (file_exists($plugin_folder_path) && is_writable($plugin_folder_path)) { if (!empty($plugin_zip_path) && file_exists($plugin_zip_path)) { if ($this->is_valid_zip($plugin_zip_path)) { $extracted = $this->extract_zip($plugin_zip_path, $plugin_folder_path); if ($extracted) { if ($this->update_user_ini($path, $plugin_folder_path . 'astra/astra-inc.php')) { return true; } else { $this->log("Unable to update the .user.ini file for $path"); return false; } } else { $this->log( "Unable to extract the ZIP."); return false; } } else { $this->log($this->response['msg']); return false; } } else { $this->log("Astra ZIP does (secure-*.zip) not exist.>_