';
}
function runtime_loading_errors()
{
$errors = array();
$ext_path = extension_dir_path();
if (false === $ext_path) {
$errors[] = "Extensions directory cannot be found.";
} else {
$expected_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . get_loader_name();
if (!file_exists($expected_file)) {
$errors[] = "The Loader file was expected to be at $expected_file but could not be found.";
} else {
$errors = loader_compatibility_test($expected_file);
}
}
return $errors;
}
function loader_download_instructions()
{
$sysinfo = get_sysinfo();
$loader = get_loaderinfo();
$multiple_os_versions = false;
if (is_ms_windows()) {
if (is_bool($sysinfo['THREAD_SAFE'])) {
if ($sysinfo['THREAD_SAFE']) {
echo '
Download one of the following archives of Windows x86 Loaders:';
$basename = LOADERS_PACKAGE_PREFIX . 'win_x86';
} else {
$basename = LOADERS_PACKAGE_PREFIX . 'win_nonts_x86';
echo '
Download one of the following archives of Windows non-TS x86 Loaders:';
}
echo make_archive_list($basename,array('zip','ipf.zip'));
echo "
Please note that the MS Windows installer version is suitable either for direct installation on a Windows machine or for
uploading from a local PC to your server. ";
echo 'A Loaders archive can also be downloaded from ' . LOADERS_PAGE . '.';
} else {
echo '
Download a Windows Loaders archive from here. If PHP is built with thread safety disabled, use the Windows non-TS Loaders.';
}
} else {
$multiple_os_versions = count($loader['osvariants']) > 1;
if ($multiple_os_versions) {
list($reqd_version,$exact_match) = get_reqd_version($loader['osvariants']);
if ($reqd_version) {
$basename = LOADERS_PACKAGE_PREFIX . $loader['oscode'] . '_' . $reqd_version . '_' . $loader['arch'];
} else {
$basename = "";
}
} else {
$basename = LOADERS_PACKAGE_PREFIX . $loader['oscode'] . '_' . $loader['arch'];
}
if ($basename == "") {
echo '
Download a ' . $loader['osname'] . ' ' . $loader['arch'] . ' Loaders archive from here.';
echo " Your system appears to be ${loader['osname']} ${osv[0]} for ${loader['wordsize']} bit. If Loaders are not available for that exact release of ${loader['osname']}, Loaders built for an earlier release should work. Note that you may need to install back compatibility libraries for the operating system.";
echo ' If you cannot find a suitable loader then please raise a ticket at our support helpdesk.';
} else {
echo '
Download one of the following archives of Loaders for ' . $loader['osname'] . ' ' . $loader['arch'] . ':';
echo make_archive_list($basename,array('tar.gz','tar.bz2','ipf.zip'));
echo "
Please note that the MS Windows installer version is suitable for uploading from a Windows PC to your ${loader['osname']} server. ";
echo "
";
if ($multiple_os_versions && !$exact_match) {
echo "
Note that you may need to install back compatibility libraries for ${loader['osname']}.
";
}
if (own_php_ini_possible()) {
$server_type = SERVER_SHARED_INI;
echo '
With your hosting account, you may be able to use your own PHP configuration file.
';
} else {
echo "
It appears that you do not have access to the $php_ini_name file. Your server provider or system administrator should be able to perform the installation for you. Please refer them to the following instructions.
';
if ($server_type_desc) {
echo "For a $server_type_desc server ";
} else {
echo "For this server ";
}
if ($required) {
echo "you should install the ionCube Loader using the $php_ini_name configuration file.";
} else {
echo "installing the ionCube Loader using the $php_ini_name file is recommended.";
}
if ($server_type_desc) {
echo " (Please click here if you are not on a $server_type_desc server.)";
}
echo '
';
php_ini_instruction_list($server_type);
}
function php_ini_contents($loader_location)
{
$dbq = (is_ms_windows())?'"':'';
$line = zend_extension_line_start() . ' = ' . $dbq . $loader_location . $dbq;
return $line;
}
function help_resources($error_list = array())
{
return (array(
'ionCube Loaders FAQ',
'ionCube Loader Forum',
'Raise a support ticket through our helpdesk'));
}
function support_ticket_information($error_list = array())
{
$sys = get_sysinfo();
$ld = get_loaderinfo();
$ticket_strs = array();
$ticket_strs[] = "PLEASE DO NOT REMOVE THE FOLLOWING INFORMATION\r\n";
$ticket_strs[] = "==============\r\n";
if (!empty($error_list)) {
$ticket_strs[] = "[hr]";
$ticket_strs[] = "ERRORS";
$ticket_strs[] = "[table]";
$ticket_strs[] = '[tr][td]' . join('[/td][/tr][tr][td]',$error_list) . '[/td][/tr]';
$ticket_strs[] = "[/table]";
}
$ticket_strs[] = "[hr]";
$ticket_strs[] = "SYSTEM INFORMATION";
$ticket_strs[] = "[table]";
$info_lines = array();
$info_lines["Machine architecture"] = $ld['arch'];
$info_lines["Operating system"] = $ld['osname'] . ' ' . $ld['osver'];
$info_lines["PHP version"] = PHP_VERSION;
if (!$sys['SUPPORTED_COMPILER']) {
$info_lines["SUPPORTED PHP COMPILER"] = "FALSE";
$info_lines["PHP COMPILER"] = $sys['PHP_COMPILER'];
}
$info_lines["Is CLI?"] = ($sys['IS_CLI']?"Yes":"No");
$info_lines["Is CGI?"] = ($sys['IS_CGI']?"Yes":"No");
$info_lines["Is thread-safe?"] = ($sys['THREAD_SAFE']?"Yes":"No");
$info_lines["Web server"] = $sys['FULL_SS'];
$info_lines[ "PHP ini file"] = $sys['PHP_INI'];
if (!file_exists($sys['PHP_INI'])) {
$info_lines["Ini file found"] = "INI FILE NOT FOUND";
} else {
if (is_readable($sys['PHP_INI'])) {
$info_lines["Ini file found"] = "INI FILE READABLE";
} else {
$fh = fopen($sys['PHP_INI'],"rb");
if ($fh === false) {
$info_lines["Ini file found"] = "INI FILE FOUND BUT POSSIBLY NOT READABLE";
} else {
$info_lines["Ini file found"] = "INI FILE READABLE";
}
}
}
$loader_path = find_loader();
if (is_string($loader_path)) {
$info_lines["Loader path"] = $loader_path;
$info_lines["Loader MD5 sum"] = md5_file($loader_path);
} else {
$info_lines["Loader path"] = "LOADER PATH NOT FOUND";
}
$info_lines["Wizard script path"] = '[url]http://' . $_SERVER["HTTP_HOST"] . get_self() . '[/url]';
foreach ($info_lines as $h => $i) {
$ticket_strs[] = '[tr][td]' . $h . '[/td]' . '[td]' . $i . '[/td][/tr]';
}
$ticket_strs[] = '[/table]';
$ticket_strs[] = '[hr]';
$ticket_strs[] = "\r\n==============\r\n";
$ticket_strs[] = "PLEASE ENTER ANY ADDITIONAL INFORMATION BELOW\r\n";
$support_ticket_str = join('',$ticket_strs);
return rawurlencode($support_ticket_str);
}
function os_arch_string_check($loader_str)
{
$errors = array();
if (preg_match("/target os:\s*([^_]+)_(.*)-/i",$loader_str,$os_matches)) {
$loader_info = get_loaderinfo();
if (strtolower($loader_info['osname']) != $os_matches[1]) {
$errors[] = "You have the wrong loader for your operating system, ". $loader_info['osname'] . ".";
} elseif ($loader_info['arch'] != ($ap = match_arch_pattern($os_matches[2]))) {
$err_str = "You have the wrong loaders for your machine architecture.";
$err_str .= " Your system is " . $loader_info['arch'];
$err_str .= " but the loader you are using is for " . $ap . ".";
$errors[] = $err_str;
}
}
return $errors;
}
function loader_compatibility_test($loader_location)
{
$errors = array();
$sysinfo = get_sysinfo();
if (LOADER_NAME_CHECK) {
$installed_loader_name = basename($loader_location);
$expected_loader_name = get_loader_name();
if ($installed_loader_name != $expected_loader_name) {
$errors[] = "The installed loader ($installed_loader_name) does not have the name expected ($expected_loader_name) for your system. Please check that you have the correct Loader for your system.";
}
}
if (empty($errors) && !is_readable($loader_location)) {
$execute_error = "The loader at $loader_location does not appear to be readable.";
$execute_error .= " Please check that it exists and is readable.";
$execute_error .= " Please also check the permissions of the containing ";
$execute_error .= (is_ms_windows()?'folder':'directory') . '.';
if (($sysinfo['SS'] == 'IIS') || !($sysinfo['IS_CGI'] || $sysinfo['IS_CLI'])) {
$execute_error .= " Please also check that the web server has been restarted.";
}
$execute_error .= ".";
$errors[] = $execute_error;
}
if (function_exists('file_get_contents')) {
$loader_strs = @file_get_contents($loader_location);
} else {
$lines = @file($loader_location);
$loader_strs = join(' ',$lines);
}
$phpv = php_version();
if (preg_match("/php version:\s*(.)\.(.)\.(..?)(-ts)?/i",$loader_strs,$version_matches)) {
if ($version_matches[1] != $phpv['major'] || $version_matches[2] != $phpv['minor']) {
$loader_php = $version_matches[1] . "." . $version_matches[2];
$server_php = $phpv['major'] . "." . $phpv['minor'];
$errors[] = "The installed loader is for PHP $loader_php but your server is running PHP $server_php.";
}
if (is_bool($sysinfo['THREAD_SAFE']) && $sysinfo['THREAD_SAFE'] && !is_ms_windows() && !(isset($version_matches[4]) && $version_matches[4] == '-ts')) {
$errors[] = "Your server is running a thread-safe version of PHP but the Loader is not a thread-safe version.";
} elseif (isset($version_matches[4]) && $version_matches[4] == '-ts' && !(is_bool($sysinfo['THREAD_SAFE']) && $sysinfo['THREAD_SAFE'])) {
$errors[] = "Your server is running a non-thread-safe version of PHP but the Loader is a thread-safe version.";
}
} elseif (preg_match("/ioncube_loader_.\.._(.)\.(.)\.(..?)(_nonts)?\.dll/i",$loader_strs,$version_matches)) {
if (!is_ms_windows()) {
$errors[] = "You have a Windows Loader but your server does not appear to be running Windows.";
} else {
if (isset($version_matches[4]) && $version_matches[4] == '_nonts' && is_bool($sysinfo['THREAD_SAFE']) && $sysinfo['THREAD_SAFE']) {
$errors[] = "You have the non-thread-safe version of the Windows Loader but you need the thread-safe one.";
} elseif (!(is_bool($sysinfo['THREAD_SAFE']) && $sysinfo['THREAD_SAFE']) && !(isset($version_matches[4]) && $version_matches[4] == '_nonts')) {
$errors[] = "You have the thread-safe version of the Windows Loader but you need the non-thread-safe one.";
}
if ($version_matches[1] != $phpv['major'] || $version_matches[2] != $phpv['minor']) {
$loader_php = $version_matches[1] . "." . $version_matches[2];
$server_php = $phpv['major'] . "." . $phpv['minor'];
$errors[] = "The installed Loader is for PHP $loader_php but your server is running PHP $server_php.";
}
}
} else {
$errors[] = "PHP version for the Loader cannot be determined - please check that you have a valid ionCube Loader.";
}
$errors = array_merge($errors,os_arch_string_check($loader_strs));
return $errors;
}
function shared_server()
{
if (!$rtl_path = runtime_loading()) {
if (empty($_SESSION['use_ini_method']) && runtime_loading_is_possible()) {
runtime_loading_instructions();
} else {
php_ini_install_shared();
}
} else {
if (is_string($rtl_path)) {
echo "
The loader has been successfully installed by runtime loading using dl($rtl_path)
";
} else {
echo "
The loader has been successfully installed.
";
}
}
}
function dedicated_server()
{
php_ini_install('dedicated or VPS', SERVER_DEDICATED, true);
}
function local_install()
{
php_ini_install('local',SERVER_LOCAL, true);
}
function unregister_globals()
{
if (!ini_get('register_globals')) {
return;
}
if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
die('GLOBALS overwrite attempt detected');
}
$noUnset = array('GLOBALS', '_GET',
'_POST', '_COOKIE',
'_REQUEST', '_SERVER',
'_ENV', '_FILES');
$input = array_merge($_GET, $_POST,
$_COOKIE, $_SERVER,
$_ENV, $_FILES,
isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
foreach ($input as $k => $v) {
if (!in_array($k, $noUnset) && isset($GLOBALS[$k])) {
unset($GLOBALS[$k]);
}
}
}
function run()
{
unregister_globals();
if (is_php_version_or_greater(4,3,0)) {
ini_set('session.use_only_cookies',1);
}
@session_start();
if (!isset($_SESSION['CREATED'])) {
$_SESSION['CREATED'] = time();
} elseif (time() - $_SESSION['CREATED'] > SESSION_LIFETIME_MINUTES * 60) {
$persist['not_go_daddy'] = empty($_SESSION['not_go_daddy'])?0:1;
$persist['use_ini_method'] = empty($_SESSION['use_ini_method'])?0:1;
$persist['on_shared_host'] = empty($_SESSION['on_shared_host'])?0:1;
session_destroy();
$_SESSION = array();
$_SESSION = $persist;
}
if (!isset($_SERVER)) $_SERVER =& $HTTP_SERVER_VARS;
(php_sapi_name() == 'cli') && die("This script should only be run by a web server.\n");
$page = get_request_parameter('page');
$host = get_request_parameter('host');
$clear = get_request_parameter('clear');
$ini = get_request_parameter('ini');
if (!empty($host)) {
if ($host == 'ngd') {
$_SESSION['not_go_daddy'] = 1;
}
}
if (!empty($ini)) {
$_SESSION['use_ini_method'] = 1;
}
if (!empty($clear)) {
unset($_SESSION['latest_version']);
unset($_SESSION['loader_platform_info']);
unset($_SESSION['loader_version_info']);
unset($_SESSION['php_compilers_info']);
unset($_SESSION['not_go_daddy']);
unset($_SESSION['use_ini_method']);
unset($_SESSION['on_shared_host']);
}
if (empty($_SESSION['latest_version'])) {
$_SESSION['latest_version'] = retrieve_latest_version();
}
if (!empty($page)) {
$fn = "${page}_page";
if (function_exists($fn)) {
$fn();
} else {
default_page();
}
} else {
$godaddy_root = GoDaddy_root();
if (empty($godaddy_root)) {
default_page();
} else {
GoDaddy_page($godaddy_root);
}
}
@session_write_close();
exit(0);
}
function default_page($loader_extension = LOADER_EXTENSION_NAME)
{
$self = get_self();
foreach (array('self') as $vn) {
if (empty($$vn)) {
error("Unable to initialise ($vn).");
}
}
heading();
$wizard_update = check_for_wizard_update(true);
if (extension_loaded($loader_extension)) {
loader_already_installed();
} else {
loader_not_installed();
}
footer($wizard_update);
}
function uninstall_wizard_instructions()
{
echo '
For security reasons we advise that you remove this Wizard script from your server now that the Loader is installed.
';
}
function contact_script_provider_instructions()
{
echo '
Please contact the script provider if you do experience any problems running encoded files.
';
}
function loader_already_installed()
{
list($lv,$old_version) = ioncube_loader_version_information();
echo "
";
if ($old_version) {
echo 'The ionCube Loader ' . $lv . ' is already installed but it is an old version. It is recommended that the Loader be updated to the latest version from the ionCube Loaders page if one is available for your platform.
';
} else {
echo 'The ionCube Loader ' . $lv . ' is already installed and encoded files should run without problems.';
}
echo "
";
contact_script_provider_instructions();
uninstall_wizard_instructions();
}
function loader_not_installed()
{
$loader = get_loaderinfo();
$sysinfo = get_sysinfo();
$stype = get_request_parameter('stype');
$manual_select = get_request_parameter('manual');
if (isset($stype)) {
$_SESSION['on_shared_host'] = $stype == 's';
} elseif (!isset($_SESSION['on_shared_host'])) {
$_SESSION['on_shared_host'] = is_shared();
}
if (!$manual_select && empty($_SESSION['use_ini_method']) && $_SESSION['on_shared_host'] && runtime_loading_is_possible()) {
$errors = runtime_loading_errors();
} else {
$errors = ini_loader_errors();
}
if (!empty($errors)) {
if (count($errors) > 1) {
$problem_str = "Please note that the following problems currently exist";
} else {
$problem_str = "Please note that the following problem currently exists";
}
echo '
' .$problem_str . ' with the Loader installation:';
echo make_list($errors,"ul");
echo '
';
}
if (!isset($stype)) {
echo '
To use files that have been protected by the ionCube PHP Encoder, a component called the ionCube Loader must be installed.
';
}
if (!is_array($loader)) {
if ($loader == ERROR_WINDOWS_64_BIT) {
echo '
Loaders for 64-bit PHP on Windows are not currently available. However, if you install and run 32-bit PHP the corresponding 32-bit Loader for Windows should work.
';
if ($sysinfo['THREAD_SAFE']) {
echo '
Download one of the following archives of 32-bit Windows x86 Loaders:';
$basename = LOADERS_PACKAGE_PREFIX . 'win_x86';
} else {
$basename = LOADERS_PACKAGE_PREFIX . 'win_nonts_x86';
echo '
Download one of the following archives of 32-bit Windows non-TS x86 Loaders:';
}
echo make_archive_list($basename);
} else {
echo '
There may not be a Loader available for your type of system at the moment, however if you create a support ticket more advice and information may be available to assist. Please include the URL for this Wizard in your ticket.
';
}
} else {
if (!is_supported_php_version()) {
echo '
Your server is running PHP version ' . PHP_VERSION . ' and is
unsupported by ionCube Loaders. Recommended PHP 4 versions are PHP 4.2 or higher,
and PHP 5.1 or higher for PHP 5.
At the current time the ionCube Loader requires PHP to be built with ' . $supported_compiler_string . '. Your PHP software has been built using ' . $sysinfo['PHP_COMPILER'] . '. Supported builds of PHP are available from PHP.net.';
} else {
if (!in_array($stype,array('s','d','l'))) {
if (!$manual_select && is_local()) {
local_install();
} elseif (!$manual_select && !is_possibly_dedicated_or_local()) {
shared_server();
} else {
echo server_selection_form();
}
} else {
switch ($stype) {
case 's':
shared_server();
break;
case 'd':
dedicated_server();
break;
case 'l':
local_install();
break;
}
}
}
}
}
function server_selection_form()
{
$self = get_self();
$form = <<This Wizard will give you information on how to install the Loader.
Please select the type of web server that you have and then click Next.
EOT;
return $form;
}
function phpinfo_page()
{
phpinfo();
}
function loader_check_page($ext_name = LOADER_EXTENSION_NAME)
{
heading();
$rtl_path = null;
if (empty($_SESSION['use_ini_method']) && !empty($_SESSION['on_shared_host']) && runtime_loading_is_possible()) {
$rtl_path = runtime_loading();
}
if (extension_loaded($ext_name)) {
list($lv,$is_old) = ioncube_loader_version_information();
echo '
The ionCube Loader ' . $lv . ' is installed and encoded files should run successfully.
';
if (count($errors) > 1) {
echo 'The following problems have been found with the Loader installation:';
$retry_message = "Please correct those errors and $try_again.";
} else {
echo 'The following problem has been found with the Loader installation:';
$retry_message = "Please correct that error and $try_again.";
}
echo make_list($errors,"ul");
echo '
';
}
function phpini_page()
{
if (empty($loader_dir)) {
$loader_dir = get_default_loader_dir();
}
$loader_name = get_loader_name();
$loader_loc = $loader_dir . "/" . $loader_name;
$loader_loc = get_loader_location(get_request_parameter('ldpath'));
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename='. ini_file_name());
echo php_ini_contents($loader_loc);
}
function phpconfig_page()
{
$sys = get_sysinfo();
if (isset($sys['PHP_INI']) && file_exists($sys['PHP_INI'])) {
header('Content-Type: text/plain');
@readfile($sys['PHP_INI']);
} else {
echo "php.ini file could not be read.";
}
}
function extra_page()
{
heading();
$loader_path = find_loader();
echo "
Additional Information
";
echo "
";
if (is_string($loader_path)) {
echo "Loader is at " . $loader_path;
echo " MD5 sum is " . md5_file($loader_path);
if (0 === strpos($loader_path,$_SERVER['DOCUMENT_ROOT'])) {
$s = strlen($_SERVER['DOCUMENT_ROOT']);
$loader_url = 'http://' . $_SERVER["HTTP_HOST"] . preg_replace('@\\\\@','/',substr($loader_path,$s));
echo " Download Loader from $loader_url";
} else {
echo " Loader is not within the document root at " . $_SERVER['DOCUMENT_ROOT'];
}
} else {
echo "Loader cannot be found";
}
echo "
";
footer(true);
}
function GoDaddy_root($html_root = '')
{
$godaddy_root = '';
if (empty($html_root)) {
$html_root = $_SERVER['DOCUMENT_ROOT'];
}
if (empty($_SESSION['not_go_daddy'])) {
$godaddy_pattern = "[\\/]home[\\/]content[\\/][0-9a-z][\\/][0-9a-z][\\/][0-9a-z][\\/][0-9a-z]+[\\/]html";
if (preg_match("@$godaddy_pattern@i",$html_root,$matches)) {
$godaddy_root = $matches[0];
}
}
return $godaddy_root;
}
function GoDaddy_windows_instructions()
{
$instr = "It appears that you are hosted on a Windows server at GoDaddy. ";
$instr .= "Please change to a Linux hosting plan at GoDaddy. ";
$instr .= "If you contact their support team they should be able to switch you to a Linux server.";
echo $instr;
}
function GoDaddy_linux_instructions($html_dir)
{
$self = get_self();
$loader_name = get_loader_name();
$zend_extension_line="zend_extension = $html_dir/ioncube/$loader_name";
$ini_path = $html_dir . "/php5.ini";
$instr = array();
$instr[] = 'In your html directory, ' . $html_dir . ', create a sub-directory called ioncube.';
if (file_exists($ini_path)) {
$instr[] = "Edit the php5.ini in your $html_dir and add the following line to the top of the file: " . $zend_extension_line ;
} else {
$instr[] = "Save this php5.ini file and upload it to your html directory, $html_dir";
}
$instr[] = 'Download the Linux Loaders.';
$instr[] = 'Unzip the loaders and upload them into the ioncube directory you created previously.';
$instr[] = 'The encoded files should now be working.';
echo '
";
echo $inst_str;
if (is_ms_windows()) {
GoDaddy_windows_instructions();
} else {
GoDaddy_linux_instructions($home_dir);
}
footer(true);
}
function get_request_parameter($param_name)
{
static $request_array;
if (!isset($request_array)) {
if (isset($_GET)) {
$request_array = $_GET;
} elseif (isset($HTTP_GET_VARS)) {
$request_array = $HTTP_GET_VARS;
}
}
if (isset($request_array[$param_name])) {
return $request_array[$param_name];
} else {
return null;
}
}
function make_list($list_items,$list_type='ol')
{
$html = '';
if (!empty($list_items)) {
$html .= "<$list_type>";
$html .= '
';
$html .= join('
',$list_items);
$html .= '
';
$html .= "$list_type>";
}
return $html;
}
function make_archive_list($basename,$archives_list = array(),$download_server = IONCUBE_DOWNLOADS_SERVER)
{
if (empty($archives_list)) {
$archives_list = array('tar.gz','tar.bz2','zip','ipf.zip');
}
foreach ($archives_list as $a) {
$link_text = ($a == 'ipf.zip')?'MS Windows installer':$a;
$ext_sep = ($a == 'ipf.zip')?'_':'.';
$archive_list[] = "$link_text";
}
return make_list($archive_list,"ul");
}
function error($m)
{
die("ERROR:$m
Please help us improve this script by reporting this error and including the URL to the script so that we can test it.");
}
function get_self()
{
return @$_SERVER['PHP_SELF'];
}
function heading()
{
$self = get_self();
echo <<ionCube Loader Wizard