Example #1
0
        }
    }
    // All ok, let's save settings
    hesk_iSaveSettings();
    // Now install HESK database tables
    hesk_iTables();
    // And move to the next step
    $_SESSION['step'] = 4;
}
// Which step are we at?
switch ($_SESSION['step']) {
    case 2:
        hesk_iCheckSetup();
        break;
    case 3:
        hesk_iDatabase();
        break;
    case 4:
        hesk_iFinish();
        break;
    default:
        hesk_iStart();
}
// ******* FUNCTIONS ******* //
function hesk_iFinish()
{
    global $hesk_settings;
    hesk_iHeader();
    ?>
	
	<div class="row">
Example #2
0
function hesk_iDetectVersion()
{
    global $hesk_settings, $hesklang;
    // Get a list of tables from the database
    $tables = array();
    $res = hesk_dbQuery('SHOW TABLES FROM `' . hesk_dbEscape($hesk_settings['db_name']) . '`');
    while ($row = hesk_dbFetchRow($res)) {
        $tables[] = $row[0];
    }
    // Version 2.4/2.5 tables installed?
    if (in_array($hesk_settings['db_pfix'] . 'pipe_loops', $tables)) {
        // Version 2.4 didn't have articles_private in kb_categories
        $res = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "kb_categories` WHERE `id`=1 LIMIT 1");
        $row = hesk_dbFetchAssoc($res);
        if (isset($row['articles_private'])) {
            // Version 2.5.0 doesn't have file "inc/zip/pclzip.lib.php"
            if (!file_exists(HESK_PATH . 'inc/zip/pclzip.lib.php')) {
                return '2.5';
            } elseif (file_exists(HESK_PATH . 'inc/tiny_mce/3.5.9/tiny_mce.js')) {
                return '2.5.2';
            } else {
                return '2.5.1';
            }
        } else {
            return '2.4';
        }
    } elseif (in_array($hesk_settings['db_pfix'] . 'online', $tables) || in_array($hesk_settings['db_pfix'] . 'logins', $tables)) {
        return '2.3';
    } elseif (in_array($hesk_settings['db_pfix'] . 'mail', $tables)) {
        return '2.2';
    } elseif (in_array($hesk_settings['db_pfix'] . 'kb_attachments', $tables)) {
        return '2.1';
    } elseif (in_array($hesk_settings['db_pfix'] . 'kb_articles', $tables)) {
        return '2.0';
    } elseif (in_array('hesk_attachments', $tables)) {
        return '0.94.1';
    } elseif (in_array('hesk_std_replies', $tables)) {
        return '0.94';
    } else {
        // If we don't have four basic tables this is not a valid HESK install
        if (!in_array('hesk_categories', $tables) || !in_array('hesk_replies', $tables) || !in_array('hesk_tickets', $tables) || !in_array('hesk_users', $tables)) {
            hesk_iDatabase(3);
        }
        // Version 0.90 didn't have the notify column in users table
        $res = hesk_dbQuery("SELECT * FROM `hesk_users` WHERE `id`=1 LIMIT 1");
        $row = hesk_dbFetchAssoc($res);
        if (isset($row['notify'])) {
            return '0.91-0.93.1';
        } else {
            // Wow, we found someone using the very first HESK version :-)
            return '0.90';
        }
    }
}
function hesk_iCheckSetup()
{
    global $hesk_settings;
    $correct_these = array();
    // 1. PHP 5+ required
    if (function_exists('version_compare') && version_compare(PHP_VERSION, REQUIRE_PHP_VERSION, '<')) {
        $correct_these[] = '
		PHP version <b>' . REQUIRE_PHP_VERSION . '+</b> required, you are using: <b>' . PHP_VERSION . '</b><br /><br />
		You are using and old and insecure PHP version with known bugs, security issues and outdated functionality.<br /><br />
		Ask your hosting company to update your PHP version.
		';
    }
    // 2. File hesk_settings.inc.php must be writable
    if (!is__writable(HESK_PATH . 'hesk_settings.inc.php')) {
        // -> try to CHMOD it
        if (function_exists('chmod')) {
            @chmod(HESK_PATH . 'hesk_settings.inc.php', 0666);
        }
        // -> test again
        if (!is__writable(HESK_PATH . 'hesk_settings.inc.php')) {
            $correct_these[] = '
			File <b>hesk_settings.inc.php</b> is not writable by PHP.<br /><br />
			Make sure PHP has permission to write to file <b>hesk_settings.inc.php</b><br /><br />
			&raquo; on <b>Linux</b> servers <a href="http://www.phpjunkyard.com/tutorials/ftp-chmod-tutorial.php">CHMOD</a> this file to 666 (rw-rw-rw-)<br />
	        &raquo; on <b>Windows</b> servers allow Internet Guest Account to modify the file<br />
	        &raquo; contact your hosting company for help with setting up file permissions.
			';
        }
    }
    // 3. Folder attachments must exist
    $hesk_settings['attach_dir_name'] = isset($hesk_settings['attach_dir']) ? $hesk_settings['attach_dir'] : 'attachments';
    $hesk_settings['attach_dir'] = HESK_PATH . $hesk_settings['attach_dir_name'];
    // -> Try to create it
    if (!file_exists($hesk_settings['attach_dir'])) {
        @mkdir($hesk_settings['attach_dir'], 0755);
    }
    // -> Is the folder now there?
    if (is_dir($hesk_settings['attach_dir'])) {
        // -> Is it writable?
        if (!is__writable($hesk_settings['attach_dir'])) {
            // -> try to CHMOD it
            @chmod($hesk_settings['attach_dir'], 0777);
            // -> test again
            if (!is__writable($hesk_settings['attach_dir'])) {
                $correct_these[] = '
				Folder <b>' . $hesk_settings['attach_dir_name'] . '</b> is not writable by PHP.<br /><br />
				Make sure PHP has permission to write to folder <b>' . $hesk_settings['attach_dir_name'] . '</b><br /><br />
				&raquo; on <b>Linux</b> servers <a href="http://www.phpjunkyard.com/tutorials/ftp-chmod-tutorial.php">CHMOD</a> this folder to 777 (rwxrwxrwx)<br />
		        &raquo; on <b>Windows</b> servers allow Internet Guest Account to modify the folder<br />
		        &raquo; contact your hosting company for help with setting up folder permissions.
				';
            }
        }
    } else {
        $correct_these[] = '
		Folder <b>' . $hesk_settings['attach_dir_name'] . '</b> is missing.<br /><br />
		Create a folder called <b>' . $hesk_settings['attach_dir_name'] . '</b> inside your main HESK folder.<br /><br />
		';
    }
    // 4. MySQL must be available
    if (!function_exists('mysql_connect') && !function_exists('mysqli_connect')) {
        $correct_these[] = '
		MySQL is disabled.<br /><br />
		HESK requires MySQL to be installed and enabled.<br /><br />
        Ask your hosting company to enable MySQL for PHP.
		';
    }
    // 5. Can we use GD library?
    $GD_LIB = extension_loaded('gd') && function_exists('gd_info') ? true : false;
    // 6. Make sure old files are deleted
    $old_files = array('hesk_settings.inc', 'hesk.sql', 'inc/common.inc', 'inc/database.inc', 'inc/footer.inc', 'inc/header.inc', 'inc/print_tickets.inc', 'inc/show_admin_nav.inc', 'inc/show_search_form.inc', 'install.php', 'update.php', 'admin.php', 'admin_change_status.php', 'admin_main.php', 'admin_move_category', 'admin_reply_ticket.php', 'admin_settings.php', 'admin_settings_save.php', 'admin_ticket.php', 'archive.php', 'delete_tickets.php', 'find_tickets.php', 'manage_canned.php', 'manage_categories.php', 'manage_users.php', 'profile.php', 'show_tickets.php', 'emails/', 'language/english.php', 'secimg.inc.php', 'hesk_style_v23.css', 'help_files/', 'TreeMenu.js', 'inc/tiny_mce/utils/r00t10.php', 'language/en/help_files/r00t10.php', 'hesk_style_v24.css', 'hesk_javascript_v24.js', 'hesk_style_v25.css', 'hesk_javascript_v25.js');
    sort($old_files);
    $still_exist = array();
    foreach ($old_files as $f) {
        if (file_exists(HESK_PATH . $f)) {
            $still_exist[] = $f;
        }
    }
    if (count($still_exist)) {
        $correct_these[] = '
		Outdated files and folders<br /><br />
		For security reasons please delete these legacy files and folders:<br />
        <ul><li><b>' . implode('</b></li><li><b>', $still_exist) . '</b></li></ul>
		';
    }
    // Do we have any errors?
    if (count($correct_these)) {
        hesk_iHeader();
        ?>

        &nbsp;

        <div style="margin-left:40px;margin-right:40px">
            <?php 
        foreach ($correct_these as $correct_this) {
            hesk_show_error($correct_this);
            echo "&nbsp;";
        }
        ?>
        </div>

		<form method="post" action="<?php 
        echo INSTALL_PAGE;
        ?>
">
		<p align="center"><input type="submit" value="Click here to test again" class="btn btn-default" /></p>
		</form>
        <p>&nbsp;</p>
        <?php 
        hesk_iFooter();
    }
    // If all tests were successful, we can continue to the next step
    $_SESSION['set_attachments'] = 1;
    $_SESSION['set_captcha'] = $GD_LIB ? 1 : 0;
    $_SESSION['use_spamq'] = $GD_LIB ? 0 : 1;
    $_SESSION['step'] = 3;
    // When updating, first try saved MySQL info
    if (INSTALL_PAGE == 'update.php') {
        header('Location: ' . INSTALL_PAGE);
    } else {
        hesk_iDatabase();
    }
    exit;
}
function hesk_iTestDatabaseConnection()
{
    global $hesk_settings, $hesklang;
    $db_success = 1;
    $hesk_settings['db_host'] = hesk_input(hesk_POST('host'));
    $hesk_settings['db_name'] = hesk_input(hesk_POST('name'));
    $hesk_settings['db_user'] = hesk_input(hesk_POST('user'));
    $hesk_settings['db_pass'] = hesk_input(hesk_POST('pass'));
    // Allow & in password
    $hesk_settings['db_pass'] = str_replace('&amp;', '&', $hesk_settings['db_pass']);
    // Use MySQLi extension to connect?
    $use_mysqli = function_exists('mysqli_connect') ? true : false;
    // Start output buffering
    ob_start();
    // Connect to database
    if ($use_mysqli) {
        // Do we need a special port? Check and connect to the database
        if (strpos($hesk_settings['db_host'], ':')) {
            list($hesk_settings['db_host'], $hesk_settings['db_port']) = explode(':', $hesk_settings['db_host']);
            $hesk_db_link = mysqli_connect($hesk_settings['db_host'], $hesk_settings['db_user'], $hesk_settings['db_pass'], $hesk_settings['db_name'], intval($hesk_settings['db_port'])) or $db_success = 0;
        } else {
            $hesk_db_link = mysqli_connect($hesk_settings['db_host'], $hesk_settings['db_user'], $hesk_settings['db_pass'], $hesk_settings['db_name']) or $db_success = 0;
        }
    } else {
        $hesk_db_link = mysql_connect($hesk_settings['db_host'], $hesk_settings['db_user'], $hesk_settings['db_pass']) or $db_success = 0;
        // Select database works OK?
        if ($db_success == 1 && !mysql_select_db($hesk_settings['db_name'], $hesk_db_link)) {
            // No, try to create the database
            if (function_exists('mysql_create_db') && mysql_create_db($hesk_settings['db_name'], $hesk_db_link)) {
                if (mysql_select_db($hesk_settings['db_name'], $hesk_db_link)) {
                    $db_success = 1;
                } else {
                    $db_success = 0;
                }
            } else {
                $db_success = 0;
            }
        }
    }
    ob_end_clean();
    // Any errors?
    if (!$db_success) {
        global $mysql_log;
        $mysql_log = $use_mysqli ? mysqli_connect_error() : mysql_error();
        hesk_iDatabase(1);
    }
    return $hesk_db_link;
}