lang = $_GET['lang']; setcookie('lang',$this->lang); }elseif( isset($_COOKIE['lang']) && isset($languages[$_COOKIE['lang']]) ){ $this->lang = $_COOKIE['lang']; } \gp\tool::GetLangFile('main.inc',$this->lang); // installation checks $this->CheckDataFolder(); $this->CheckPHPVersion(); $this->CheckEnv(); $this->CheckMemory(); $this->CheckImages(); $this->CheckArchives(); $this->CheckPath(); $this->CheckIndexHtml(); } public function Run(){ global $langmessage; echo '

'; echo $langmessage['Installation']; echo ' - v'.\gpversion; echo '

'; $installed = false; $cmd = \gp\tool::GetCommand(); switch($cmd){ case 'Continue': $this->FTP_Prepare(); break; case 'Install': $installed = $this->Install_Normal(); break; } if( !$installed ){ $this->LanguageForm(); $this->DisplayStatus(); }else{ $this->Installed(); } } /** * Display check statuses * */ public function DisplayStatus(){ global $langmessage; echo '

'.$langmessage['Checking_server'].'...

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; foreach($this->statuses as $row){ echo ''; if( $row['can_install'] === 2 ){ $class = 'passed'; $label = 'Passed'; }elseif( $row['can_install'] === 1 ){ $class = 'passed_orange'; $label = 'Passed'; }elseif( $row['can_install'] === 0 ){ $class = 'passed_orange'; $label = 'Failed'; }else{ $class = 'passed_orange'; $label = 'Failed'; } if( !empty($row['label']) ){ $label = $row['label']; } echo ''; echo ''; echo ''; echo ''; } echo ''; echo '
'.$langmessage['Checking'].'...'.$langmessage['Status'].''.$langmessage['Current_Value'].''.$langmessage['Expected_Value'].'
'; echo $row['checking']; echo ''.$label.''.$row['curr_value'].''.$row['expected'].'
'; echo '

'; echo \gp\tool::Link('',$langmessage['Refresh']); echo '

'; echo '
'; if( $this->can_install > 0 ){ $this->Form_Entry(); return; } if( !$this->can_write_data ){ $this->Form_Permissions(); }else{ echo '

'.$langmessage['Notes'].'

'; echo '
'; echo $langmessage['Install_Conflict']; echo '
'; echo '

'; echo sprintf($langmessage['Install_Fix'],''); echo '

'; } } public function SetStatus($checking, $can_install, $curr_value, $expected = '', $status_label = ''){ if( $can_install < $this->can_install ){ $this->can_install = $can_install; } $this->statuses[] = [ 'checking' => $checking, 'can_install' => $can_install, 'curr_value' => $curr_value, 'expected' => $expected, 'label' => $status_label ]; } /** * Check the data folder to see if it's writable * */ public function CheckDataFolder(){ global $dataDir,$langmessage; $folder = $dataDir.'/data'; if( strlen($folder) > 33 ){ $show = '...'.substr($folder,-30); }else{ $show = $folder; } $status = null; $class = 'passed'; $can_install = 2; if( !is_dir($folder)){ if( !@mkdir($folder) ){ $status = $langmessage['See_Below'].' (0)'; $this->can_write_data = false; } }elseif( !gp_is_writable($folder) ){ $status = $langmessage['See_Below'].' (1)'; $this->can_write_data = false; } if( $this->can_write_data ){ $current = $langmessage['Writable']; }else{ $current = $langmessage['Not Writable']; $can_install = 0; } $this->SetStatus( $show, $can_install, $current, $langmessage['Writable'], $status); } /** * Check the php version * */ private function CheckPHPVersion(){ global $langmessage; $version = phpversion(); $can_install = 2; if( version_compare($version,'8.0','<') ){ $can_install = -1; } $this->SetStatus($langmessage['PHP_Version'], $can_install, $version, '7.3+'); } /** * Check the env for server variables * */ private function CheckEnv(){ global $langmessage; //make sure $_SERVER['SCRIPT_NAME'] is set $checking = 'SCRIPT_NAME or PHP_SELF'; $can_install = 2; $expected = $langmessage['Set']; $curr = $langmessage['Set']; if( !\gp\tool::GetEnv('SCRIPT_NAME','index.php') && !\gp\tool::GetEnv('PHP_SELF','index.php') ){ $curr = $langmessage['Not_Set']; $can_install = -1; } $this->SetStatus($checking, $can_install, $curr, $expected); } /** * Check php's memory limit * LESS compilation uses a fair amount of memory */ private function CheckMemory(){ $checkValue = ini_get('memory_limit'); $expected = '16M+ or Adjustable'; $checking = 'Memory Limit'; // adjustable if( @ini_set('memory_limit','96M') !== false ){ $this->SetStatus( $checking, 2, $checkValue .' and adjustable', $expected); return; } // cant check memory if( !$checkValue ){ $this->SetStatus( $checking, 1, '???', $expected); return; } $byte_value = \gp\tool::getByteValue($checkValue); $mb_16 = \gp\tool::getByteValue('16M'); if( $byte_value > 100663296 ){ $this->SetStatus( $checking, 2, $checkValue, $expected); }elseif( $byte_value >= $mb_16 ){ $this->SetStatus( $checking, 1, $checkValue, $expected); }else{ $this->SetStatus( $checking, 0, $checkValue, $expected); } } /** * Very unlikely, ".php" cannot be in the directory name. see SetGlobalPaths() * */ public function CheckPath(){ global $langmessage; $dir = dirname(__FILE__); $checking = 'Install Directory'; $curr = str_replace('.php','.php',$dir); if( strpos($dir,'.php') === false ){ $this->SetStatus( $checking, 2, $curr ); return; } $this->SetStatus( $checking, 0, $curr , 'Rename your file structure so that directories do not use ".php".'); } /** * Warn user if there's an index.html file * */ public function CheckIndexHtml(){ global $langmessage, $dataDir; $show = 'Existing index.html'; $index = $dataDir.'/index.html'; if( file_exists($index) ){ $this->SetStatus( $show, 1, $index, $langmessage['index.html exists']); }else{ $this->SetStatus( $show, 2, '', ''); } } /** * Check for image manipulation functions * */ public function CheckImages(){ global $langmessage; $supported = array(); if( function_exists('imagetypes') ){ $supported_types = imagetypes(); if( $supported_types & IMG_JPG ){ $supported[] = 'jpg'; } if( $supported_types & IMG_PNG){ $supported[] = 'png'; } if( $supported_types & IMG_WBMP){ $supported[] = 'bmp'; } if( $supported_types & IMG_GIF){ $supported[] = 'gif'; } if( defined('IMG_WEBP') && ($supported_types & IMG_WEBP) ){ $supported[] = 'webp'; } } $checking = ''.$langmessage['image_functions'].''; $supported_string = implode(', ',$supported); if( count($supported) >= 4 ){ $this->SetStatus( $checking, 2, $supported_string); }elseif( count($supported) > 0 ){ $this->SetStatus( $checking, 1, $supported_string,'',$langmessage['partially_available']); }else{ $this->SetStatus( $checking, 1, $supported_string,'',$langmessage['unavailable']); } } /** * Check for archive processing capabilities * */ public function CheckArchives(){ global $langmessage; $supported = array(); if( class_exists('\ZipArchive') ){ $supported['zip'] = 'zip'; } if( class_exists('\PharData') ){ if( !defined('HHVM_VERSION') || !ini_get('phar.readonly') ){ if( function_exists('gzopen') ){ $supported['tgz'] = 'gzip'; } if( function_exists('bzopen') ){ $supported['tbz'] = 'bzip'; } $supported['tar'] = 'tar'; } } $checking = 'Archive Extensions'; $supported_string = implode(', ',$supported); if( count($supported) == 4 ){ $this->SetStatus( $checking, 2, $supported_string); }elseif( count($supported) > 0 ){ $this->SetStatus( $checking, 1, $supported_string, '', $langmessage['partially_available'] ); }else{ $this->SetStatus( $checking, 1, $supported_string, '', $langmessage['unavailable'] ); } } /** * Change the permissions of the data directory * */ public function FTP_Prepare(){ global $langmessage; echo '

'.$langmessage['Using_FTP'].'...

'; echo ''; } public function _FTP_Prepare(){ if( !$this->FTPConnection() ){ return; } if( $this->FTP_DataFolder() ){ return; } } /** * Create the data folder with appropriate permissions * * 1) make parent directory writable * 2) delete existing /data folder * 3) create /data folder with php's mkdir() (so it has the correct owner) * 4) restore parent directory * */ public function FTP_DataFolder(){ global $dataDir, $langmessage; $this->root_mode = fileperms($dataDir); if( !$this->root_mode ){ return false; } // (1) $modDir = ftp_site($this->ftp_connection, 'CHMOD 0777 '. $this->ftp_root ); if( !$modDir ){ echo '
  • '; echo sprintf($langmessage['Could_Not_'],'CHMOD 0777 '. $this->ftp_root.''); echo '
  • '; return false; } // (2) use rename instead of trying to delete recursively $php_dir = $dataDir.'/data'; $php_del = false; if( file_exists($php_dir) ){ $ftp_dir = rtrim($this->ftp_root,'/').'/data'; $del_name = '/data-delete-'.rand(0,10000); $ftp_del = rtrim($this->ftp_root,'/').$del_name; $php_del = $dataDir.$del_name; $changed = ftp_rename($this->ftp_connection, $ftp_dir , $ftp_del ); if( !$changed ){ echo '
  • '; echo sprintf($langmessage['Could_Not_'],'Remove '. $this->ftp_root.'/data'); echo '
  • '; return false; } } // (3) use rename instead of trying to delete recursively $mode = 0755; if( defined(gp_chmod_dir) ){ $mode = gp_chmod_dir; } if( !mkdir($php_dir,$mode) ){ echo '
  • '; echo sprintf($langmessage['Could_Not_'],'mkdir('.$php_dir.')'); echo '
  • '; return false; } // (4) will be done afterwards // make sure it's writable ? clearstatcache(); if( !gp_is_writable($php_dir) ){ return false; } echo '
  • '; echo $langmessage['Success_continue_below']; echo '
  • '; if( $php_del ){ $this->CopyData($php_del, $php_dir); } return true; } /** * Copy files from the "deleted" data folder to the new data folder * */ public function CopyData($from_dir, $to_dir){ $files = scandir($from_dir); foreach($files as $file){ if( $file === '..' || $file === '.' ){ continue; } $from = $from_dir.'/'.$file; //no directories if( is_dir($from) ){ continue; } $to = $to_dir.'/'.$file; copy($from,$to); } } /** * Restore the mode of the root directory to it's original mode * */ public function FTP_RestoreMode(){ global $langmessage; if( !$this->root_mode || !$this->ftp_connection ){ return; } $mode = $this->root_mode & 0777; $mode = '0'.decoct($mode); $ftp_cmd = 'CHMOD '.$mode.' '.$this->ftp_root; if( !ftp_site($this->ftp_connection, $ftp_cmd ) ){ echo '
  • '; echo sprintf($langmessage['Could_Not_'],'Restore mode for '. $this->ftp_root.': '.$ftp_cmd.''); echo '
  • '; return; } } /** * Establish an FTP connection to be used by the installer * */ public function FTPConnection(){ global $dataDir, $langmessage; //test for functions if( !function_exists('ftp_connect') ){ echo '
  • '; echo $langmessage['FTP_UNAVAILABLE']; echo '
  • '; return false; } //Try to connect $this->ftp_connection = @ftp_connect($_POST['ftp_server'],21,6); if( !$this->ftp_connection ){ echo '
  • '; echo sprintf($langmessage['FAILED_TO_CONNECT'],''.htmlspecialchars($_POST['ftp_server']).''); echo '
  • '; return false; } echo '
  • '; echo sprintf($langmessage['CONNECTED_TO'],''.htmlspecialchars($_POST['ftp_server']).''); echo '
  • '; //Log in $login_result = @ftp_login($this->ftp_connection, $_POST['ftp_user'], $_POST['ftp_pass']); if( !$login_result ){ echo '
  • '; echo sprintf($langmessage['NOT_LOOGED_IN'],''.htmlspecialchars($_POST['ftp_user']).''); echo '
  • '; return false; } echo '
  • '; echo sprintf($langmessage['LOGGED_IN'],''.htmlspecialchars($_POST['ftp_user']).''); echo '
  • '; //Get FTP Root $this->ftp_root = \gp\tool\FileSystemFtp::GetFTPRoot($this->ftp_connection,$dataDir); if( $this->ftp_root === false ){ echo '
  • '; echo $langmessage['ROOT_DIRECTORY_NOT_FOUND']; echo '
  • '; return false; } echo '
  • '; echo sprintf($langmessage['FTP_ROOT'],''.$this->ftp_root.''); echo '
  • '; return true; } public function Form_Permissions(){ global $langmessage,$dataDir; echo '
    '; echo '

    '.$langmessage['Changing_File_Permissions'].'

    '; echo '

    '; echo $langmessage['REFRESH_AFTER_CHANGE']; echo '

    '; echo ''; //manual method echo ''; echo ''; //ftp echo ''; echo ''; // if( function_exists('ftp_connect') ){ echo ''; echo ''; } echo '
    '; echo $langmessage['manual_method']; echo '

    '; echo $langmessage['LINUX_CHOWN']; echo '

    '; $owner = $this->GetPHPOwner(); if( is_null($owner) ){ echo 'chown ?? "'.$dataDir.'/data"'; echo 'Replace ?? with the owner uid of PHP on your server'; }else{ echo 'chown '.$owner.' "'.$dataDir.'/data"'; echo 'Note: "'.$owner.'" appears to be the owner uid of PHP on your server'; } echo '

    '.$langmessage['Refresh'].'

    '; echo '
    FTP

    '; echo $langmessage['MOST_FTP_CLIENTS']; echo '

    '; echo '

    Using your FTP client, we recommend the following steps to make the data directory writable

    '; echo '
      '; echo '
    1. Make "'.$dataDir.'" writable
    2. '; echo '
    3. Delete "'.$dataDir.'/data"
    4. '; echo '
    5. Run '.\CMS_NAME.' Installer by refreshing this page
    6. '; echo '
    7. Restore the permissions of "'.$dataDir.'"
    8. '; echo '
    '; echo '
    '; echo $langmessage['Installer']; echo '
    '; echo '

    '; echo $langmessage['FTP_CHMOD']; echo '

    '; $this->Form_FTPDetails(); echo '
    '; echo '
    '; } /** * Attempt to get the owner of php * */ public function GetPHPOwner(){ global $dataDir; if( !function_exists('fileowner') ){ return; } $name = tempnam( sys_get_temp_dir(), 'gpinstall-' ); if( !$name ){ return; } return fileowner($name); } public function Form_FTPDetails(){ global $langmessage; $_POST += array('ftp_server'=>\gp\tool\FileSystemFtp::GetFTPServer(),'ftp_user'=>''); echo '
    '; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
    '.$langmessage['FTP_Server'].' '; echo ''; echo '
    '.$langmessage['FTP_Username'].' '; echo ''; echo '
    '.$langmessage['FTP_Password'].' '; echo ''; echo '
     '; echo ''; echo ''; echo '
    '; echo '
    '; } public function LanguageForm(){ global $languages; echo '
    '; echo '
    '; echo ''; echo ''; echo '
    '; echo '
    '; } public function Installed(){ global $langmessage; echo '

    '.$langmessage['Installation_Was_Successfull'].'

    '; echo '

    '; echo \gp\tool::Link('',$langmessage['View_your_web_site']); echo '

    '; echo ''; echo '

    '; echo 'For added security, you may delete the /include/install/install.php file from your server.'; echo '

    '; } public function Form_Entry(){ global $langmessage; echo '
    '; echo ''; \gp\install\Tools::Form_UserDetails(); \gp\install\Tools::Form_Configuration(); echo '
    '; echo '

    '; echo ''; echo ''; echo '

    '; echo '
    '; } public function Install_Normal(){ global $langmessage; echo '

    '.$langmessage['Installing'].'

    '; echo ''; return $success; } }