';
$this->ShowSimple();
}
/**
* About this plugin
*
*/
public function About($full){
global $langmessage;
$this->Heading($langmessage['about']);
echo '';
echo '
';
}
public function Search(&$array){
$result = array();
$key = $_GET['q'];
foreach($array as $path => $info){
if( strpos($path,$key) !== false ){
$result[$path] = $info;
continue;
}
}
return $result;
}
public function SearchRow(){
$_GET += array('q'=>'');
echo '
';
echo '
';
echo '';
echo '
';
echo '
';
echo '';
echo '';
echo '
';
echo '
';
}
/**
* Remove the files and folders of an installation as determined by the post request
*
*/
public function UninstallSite(){
global $langmessage, $config;
$site =& $_POST['site'];
if( empty($site) ){
return false;
}
if( !isset($this->siteData['sites'][$site]) ){
msg($langmessage['OOPS'].' (Invalid Site)');
return false;
}
if( !$this->RmSite($site) ){
msg($langmessage['OOPS'].'(Files not completely removed)');
return false;
}
msg($langmessage['SAVED']);
unset($this->siteData['sites'][$site]);
$this->SaveSiteData();
}
/**
* Remove the files and folders of an installation
*
*/
public function RmSite($site){
global $config;
if( !$this->EmptyDir($site) ){
return false;
}
return $this->RmDir($site);
}
/**
* Remove a folder that was created by the multi-site manager
*
*/
public function RmDir($dir){
global $config;
if( @rmdir($dir) ){
return true;
}
if( empty($config['ftp_server']) ){
return false;
}
if( !function_exists('ftp_connect') ){
return false;
}
$conn_id = self::FTPConnect();
if( !$conn_id ){
return false;
}
$ftp_site = \gp\tool\FileSystemFtp::GetFTPRoot($conn_id,$dir);
if( $ftp_site === false ){
return false;
}
return ftp_rmdir($conn_id,$ftp_site);
}
/**
* Remove all the contents of a directory
*
*/
public function EmptyDir($dir){
if( !file_exists($dir) ){
return true;
}
if( is_link($dir) ){
return unlink($dir);
}
$dh = @opendir($dir);
if( !$dh ){
return false;
}
$dh = @opendir($dir);
if( !$dh ){
return false;
}
$success = true;
$subDirs = array();
while( ($file = readdir($dh)) !== false){
if( $file == '.' || $file == '..' ){
continue;
}
$fullPath = $dir.'/'.$file;
if( is_link($fullPath) ){
if( !unlink($fullPath) ){
$success = false;
}
continue;
}
if( is_dir($fullPath) ){
$subDirs[] = $fullPath;
continue;
}
if( !unlink($fullPath) ){
$success = false;
}
}
closedir($dh);
foreach($subDirs as $subDir){
if( !$this->EmptyDir($subDir) ){
$success = false;
}
if( !\gp\tool\Files::RmDir($subDir) ){
$success = false;
}
}
return $success;
}
public function GetSiteData(){
global $addonPathData;
$this->dataFile = $addonPathData.'/data.php';
$this->siteData = \gp\tool\Files::Get($this->dataFile,'siteData');
$this->siteData += array('sites'=>array());
$this->checksum = $this->CheckSum($this->siteData);
}
public function SaveSiteData(){
$check = $this->CheckSum($this->siteData);
if( $check === $this->checksum ){
return true;
}
unset($this->siteData['destination']); //no longer used
return \gp\tool\Files::SaveData( $this->dataFile,'siteData',$this->siteData );
}
public function CheckSum($array){
return crc32( serialize($array) );
}
public function CreatePlugins($destination,$args = false){
global $rootDir;
if( $args === false ){
$args = $_POST;
}
//may be valid even if plugins is not set
$args += array('plugins'=>array());
//selection of themes
if( !\gp\tool\Files::CheckDir($destination.'/addons') ){
msg('Failed to create '.$destination.'/addons'.'');
return false;
}
foreach($args['plugins'] as $plugin){
$target = $rootDir.'/addons/'.$plugin;
if( !file_exists($target) ){
continue;
}
$name = $destination.'/addons/'.$plugin;
$this->Create_Symlink($target,$name);
}
return true;
}
//Don't create symlink for /themes, users may want to add to their collection of themes
public function CopyThemes($destination,$args=false){
global $rootDir;
if( $args === false ){
$args = $_POST;
}
//selection of themes
if( !\gp\tool\Files::CheckDir($destination.'/themes') ){
msg('Failed to create '.$destination.'/themes'.'');
return false;
}
$count = 0;
foreach($args['themes'] as $theme){
$target = $rootDir.'/themes/'.$theme;
if( !file_exists($target) ){
continue;
}
$name = $destination.'/themes/'.$theme;
if( $this->Create_Symlink($target,$name) ){
$count++;
}
}
if( $count == 0 ){
msg('Failed to populate '.$destination.'/themes'.'');
return false;
}
return true;
}
//create the index.php file
public function CreateIndex($destination,$unique){
$path = $destination.'/index.php';
$indexA = array();
$indexA[] = '<'.'?'.'php';
if( isset($this->siteData['service_provider_id']) ){
$indexA[] = 'define(\'service_provider_id\',\''.(int)$this->siteData['service_provider_id'].'\');';
}
if( isset($this->siteData['service_provider_name']) ){
$indexA[] = 'define(\'service_provider_name\',\''.addslashes($this->siteData['service_provider_name']).'\');';
}
$indexA[] = 'define(\'multi_site_unique\',\''.$unique.'\');';
$indexA[] = 'require_once(\'include/main.php\');';
$index = implode("\n",$indexA);
if( !\gp\tool\Files::Save($path,$index) ){
return false;
}
@chmod($path,0644); //to prevent 500 Internal Server Errors on some servers
return true;
}
public function NewId(){
do{
$unique = \gp\tool::RandomString(20);
foreach($this->siteData['sites'] as $array){
if( isset($array['unique']) && ($array['unique'] == $unique) ){
$unique = false;
break;
}
}
}while($unique==false);
return $unique;
}
//create a symbolic link and test for $test_file
public function Create_Symlink($target,$path,$test_file = false ){
echo '
Create Symlink: '.$path.'
';
if( !symlink($target,$path) ){
msg('Oops, Symlink creation failed (1)');
return false;
}
if( $test_file && !file_exists($path.'/'.$test_file) ){
msg('Oops, Symlink creation failed (2)');
return false;
}
return true;
}
/**
* Save the ftp connection information if a connection can be made
*
*/
public function SaveFTPInformation(){
global $config, $langmessage;
$_POST += array('ftp_server'=>'','ftp_user'=>'','ftp_pass'=>'');
//try to connect and login if ftp_server is not empty
if( !empty($_POST['ftp_server']) ){
$conn_id = @ftp_connect($_POST['ftp_server'],21,6);
if( !$conn_id ){
msg('Oops, could not connect using ftp_connect() for server '.htmlspecialchars($_POST['ftp_server']).'');
return false;
}
ob_start();
$login_result = @ftp_login($conn_id,$_POST['ftp_user'],$_POST['ftp_pass'] );
if( !$login_result ){
msg('Oops, could not login using ftp_login() for server '.$_POST['ftp_server'].' and user '.$_POST['ftp_user'].'');
@ftp_close($conn_id);
ob_end_clean();
return false;
}
@ftp_close($conn_id);
ob_end_clean();
}
$config['ftp_user'] = $_POST['ftp_user'];
$config['ftp_server'] = $_POST['ftp_server'];
$config['ftp_pass'] = $_POST['ftp_pass'];
if( !admin_tools::SaveConfig() ){
msg('Oops, there was an error saving your ftp information.');
return false;
}
return true;
}
/*
* New Installation Functions
*
*
*
*/
public function InstallStatus($cmd){
global $rootDir;
$default_theme = explode('/',gp_default_theme);
//make sure default theme exists
$path = $rootDir.'/themes/'.$default_theme[0];
if( !file_exists($path) ){
msg('The default theme for gpEasy "'.$default_theme[0].'" does not exist. Please make sure it exists before continuing.');
return;
}
if( empty($cmd) || $cmd == 'Continue' ){
$cmd = false;
}elseif( $cmd == 'Install Now' ){
if( $this->NewCreate() ){
return;
}else{
$cmd = false;
}
}
$this->CheckFolder();
$this->Heading('Installation');
$this->InstallStatus_Steps($cmd);
echo '
';
switch($cmd){
case 'subfolder':
case 'new':
case 'new_destination':
$this->NewDestination();
break;
case 'new_themes':
$this->NewThemes($_REQUEST['install']);
break;
case 'new_plugins':
$this->NewPlugins($_REQUEST['install']);
break;
case 'new_install':
$this->NewInstall();
break;
}
echo '
';
}
public function InstallStatus_Steps(&$cmd){
echo '';
echo '
';
return $ready;
}
/**
* Make sure the install folder is writable before continuing with the installation process
*
*/
public function CheckFolder(){
global $config;
if( empty($_REQUEST['install']['folder']) ){
return;
}
$folder = $_REQUEST['install']['folder'];
if( is_writable($folder) ){
return true;
}
if( !function_exists('ftp_connect') ){
$this->FolderNotWritable('FTP Extension Not Available');
return false;
}
if( empty($config['ftp_server']) ){
$this->FolderNotWritable('FTP connection values not set');
return false;
}
$conn_id = self::FTPConnect();
if( !$conn_id ){
$this->FolderNotWritable('FTP connection could not be made with the supplied values');
return false;
}
$ftp_root = \gp\tool\FileSystemFtp::GetFTPRoot($conn_id,$folder);
if( $ftp_root === false ){
$this->FolderNotWritable('Root folder not found by FTP');
return false;
}
}
/**
* Display message to user about not being able to write to the installation folder
*
*/
public function FolderNotWritable($reason = ''){
global $langmessage;
$message = '
Sorry, the selected folder could not be written to.
';
$message .= ''.$reason.' ';
$message .= '
You may still be able to install in this folder by doing one of the following:
';
$message .= '
';
$message .= '
Make the folder writable by changing it\'s permissions.
';
$langmessage['not_created'] = sprintf($langmessage['not_created'],\gp\tool::GetUrl('Admin_Site_Setup','cmd=settings'));
$new_folder = $parent.'/'.$new_name;
if( mkdir($new_folder,0755) ){
chmod($new_folder,0755); //some systems need more than just the 0755 in the mkdir() function
return true;
}
if( $this->HasFTP() ){
msg($langmessage['not_created']);
return false;
}
$conn_id = self::FTPConnect();
if( !$conn_id ){
msg($langmessage['not_created'].' (FTP Connection Failed)');
return false;
}
$ftp_parent = \gp\tool\FileSystemFtp::GetFTPRoot($conn_id,$parent);
if( $ftp_parent === false ){
msg('Oops, could not find the ftp location of '.$parent.' using the current ftp login.');
return false;
}
$ftp_destination = $ftp_parent.'/'.$new_name;
if( !ftp_mkdir($conn_id,$ftp_destination) ){
msg('Oops, could not create the folder using the current ftp login.');
return false;
}
ftp_site($conn_id, 'CHMOD 0755 '. $ftp_destination );
return true;
}
public function NewCreate(){
global $rootDir,$config,$checkFileIndex;
global $dataDir; //for SaveTitle(), SaveConfig()
$_POST += array('themes'=>array(),'plugins'=>array());
$destination = $_REQUEST['install']['folder'];
$this->site_uniq_id = $this->NewId();
$checkFileIndex = false;
//prevent reposting
if( isset($this->siteData['sites'][$destination]) ){
msg('Oops, there\'s already an installation in '.htmlspecialchars($destination));
return false;
}
echo '
';
echo '
Starting Installation
';
//check user values first
if( !\gp\install\Tools::gpInstall_Check() ){
$this->Install_Aborted($destination);
return false;
}
// Create index.php file
echo '
';
if( $destination ){
$this->EmptyDir($destination);
}
}
public function Install_Success(){
echo '';
echo '';
echo 'Installation was completed successfully. ';
//show the options
$_REQUEST['site'] = $_REQUEST['install']['folder'];
$this->Options();
}
/**
* Return true if FTP can be used
*
*/
public function HasFTP(){
global $config;
if( empty($config['ftp_server']) || !function_exists('ftp_connect') ){
return false;
}
return true;
}
/**
* Multi Site Heading
*
*/
public function Heading($sub_heading=false){
echo '