'._DIR._FILE_DBCONF.' missing. '; $msgDbConfigMissing .= 'Setup cannot continue. Please check the file exists and is readable by the webserver before continuing.'; // init queries initQueries("install"); // ----------------------------------------------------------------------------- // Main // ----------------------------------------------------------------------------- // ob-start if (@ob_get_level() == 0) @ob_start(); if (isset($_REQUEST["1"])) { // 1 - Database sendHead(" - Database"); send("

"._TITLE."

"); send("

Database

"); send("

In this section you will choose the type of database you wish to use with "._NAME.". You will then be prompted to provide the hostname, database name, username and password that "._NAME." will use to store information.

"); send("

Finally "._NAME." will run some tests to check everything works OK and write the database and server configuration.

"); send("

For more information and support with this installation, please feel free to visit the "._NAME." forum.


"); send("
"); sendButton(11); } elseif (isset($_REQUEST["11"])) { // 11 - Database - type sendHead(" - Database"); send("

"._TITLE."

"); send("

Database - Select Type of Database

"); send("

Please select the type of database you wish to use with your "._NAME." installation below:

"); send('
'); send(''); send('

Note: if you do not see the type of database you wish to use, please visit the '._NAME.' forum to find out about getting your database type added to '._NAME.'.

'); send(''); send(''); send('

'); } elseif (isset($_REQUEST["12"])) { // 12 - Database - type check if ((isset($_REQUEST["db_type"])) && ($databaseTypes[$_REQUEST["db_type"]] != "")) { $type = $_REQUEST["db_type"]; sendHead(" - Database"); send("

"._TITLE."

"); send("

Database - Type Check

"); if (function_exists($databaseTypes[$type])) { $msg = "Your PHP installation supports ".$type; displaySetupMessage($msg, true); send("
"); send('
'); send(''); send(''); send(''); send('
'); } else { $err='Your PHP installation does not have support for '.$type.' built into it. Please reinstall PHP and ensure support for your database is built in.

'; displaySetupMessage($err, false); send("
"); send('
'); send(''); send(''); send('
'); } } else { @header("location: setup.php?11"); exit(); } } elseif (isset($_REQUEST["13"])) { // 13 - Database - config $type = $_REQUEST["db_type"]; sendHead(" - Database"); send("

"._TITLE."

"); send("

Database - Config - ".$type."

"); send("

The installation will now configure and test your database settings.


"); send('
'); send(''); // settings send(''); send(''); switch (strtolower($type)) { case "sqlite": // file $line = ''; $line .= ''; send($line); // break; } // create $line = ''; $line .= ''; send($line); // pcon $line = '
Database Settings
Please enter your '.$type.' database settings below:
Database-File : '; else $line .= '>'; $line .= '
Create Database: Note: the next step will fail if the database already exists.'; $line .= '
Use Persistent Connection:'; $line .= ''); send("
"); send(''); send(''); send(''); send(''); } elseif (isset($_REQUEST["14"])) { // 14 - Database - creation + test $type = $_REQUEST["db_type"]; sendHead(" - Database"); send("

"._TITLE."

"); send("

Database - Creation + Test - ".$type."

"); $paramsOk = true; if (isset($_REQUEST["db_host"])) $host = $_REQUEST["db_host"]; else $paramsOk = false; if (isset($_REQUEST["db_create"])) $create = true; else $create = false; if (isset($_REQUEST["db_pcon"])) $pcon = "true"; else $pcon = "false"; switch (strtolower($type)) { case "sqlite": $name = ""; $user = ""; $pass = ""; break; case "mysql": case "postgres": default: if (!empty($_REQUEST["db_name"])) $name = stripslashes($_REQUEST["db_name"]); else $paramsOk = false; if (!empty($_REQUEST["db_user"])) $user = $_REQUEST["db_user"]; else $paramsOk = false; if (!empty($_REQUEST["db_pass"])) $pass = $_REQUEST["db_pass"]; else $paramsOk = false; } $databaseTestOk = false; $databaseError = ""; // create + test if ($paramsOk) { send("

The installation will now try to connect to the database server, create a new database if applicable and run some tests to check we can create tables in the database.

"); $databaseExists = true; if (($create) && (strtolower($type) != "sqlite")) { $dbCon = getAdoConnection($type, $host, $user, $pass); if (!$dbCon) { $databaseExists = false; $databaseTestOk = false; $databaseError = "Cannot connect to database. Check username, hostname and password?"; } else { $sqlState = "CREATE DATABASE "; if ($type == "mysql") $sqlState .= "`".$name."`"; else $sqlState .= $name; $dbCon->Execute($sqlState); send('
    '); if ($dbCon->ErrorNo() == 0) { send('
  • Ok: Created database '.$name.''); $databaseExists = true; } else { // damn there was an error send('
  • Error: Could not create database '.$name.''); $databaseExists = false; $databaseTestOk = false; $databaseError = "Check the database $name does not exist already to perform this step."; } send('
'); // close ado-connection $dbCon->Close(); } unset($dbCon); } if ($databaseExists) { $dbCon = getAdoConnection($type, $host, $user, $pass, $name); if (!$dbCon) { $databaseTestOk = false; $databaseError = "Cannot connect to database to perform query tests."; } else { $databaseTestCount = 0; send('
    '); foreach ($queries['test'][strtolower($type)] as $databaseTypeName => $databaseQuery) { send('
  • '); $dbCon->Execute($databaseQuery); if ($dbCon->ErrorNo() == 0) { send('Query Ok: '.$databaseQuery); $databaseTestCount++; } else { // damn there was an error send('Query Error: '.$databaseQuery); // close ado-connection $dbCon->Close(); break; } } if ($databaseTestCount == count($queries['test'][strtolower($type)])) { // close ado-connection $dbCon->Close(); $databaseTestOk = true; } else { $databaseTestOk = false; } send('
'); } } } else { $databaseTestOk = false; $databaseError = "Problem found in configuration details supplied - please supply hostname, database name, username and password to continue."; } // output if ($databaseTestOk) { $msg = "Database creation and tests succeeded"; displaySetupMessage($msg, true); send("
"); send("

Next: Write Database Configuration File

"); send("Please ensure this script can write to the directory "._DIR."inc/config/ before continuing.

"); send('

'); send(''); send(''); send(''); send(''); send(''); send(''); send(''); send(''); } else { displaySetupMessage($databaseError, false); send(''); send(''); send(''); if (isset($_REQUEST["db_name"])) send(''); if (isset($_REQUEST["db_name"])) send(''); if (isset($_REQUEST["db_user"])) send(''); if (isset($_REQUEST["db_pass"])) send(''); if (isset($_REQUEST["db_pcon"])) send(''); if (isset($_REQUEST["db_create"])) send(''); send(''); } send('
'); } elseif (isset($_REQUEST["15"])) { // 15 - Database - config-file sendHead(" - Database"); send("

"._TITLE."

"); send("

Database - Config-File

"); send("

The installation will now attempt to write the database configuration file to "._DIR._FILE_DBCONF.".

"); $type = $_REQUEST["db_type"]; $host = $_REQUEST["db_host"]; $name = $_REQUEST["db_name"]; $user = $_REQUEST["db_user"]; $pass = $_REQUEST["db_pass"]; $pcon = $_REQUEST["db_pcon"]; // write file $databaseConfWriteOk = false; $databaseConfWriteError = ""; $databaseConfContent = ""; writeDatabaseConfig($type, $host, $user, $pass, $name, $pcon); // output if ($databaseConfWriteOk) { $msg = 'Database configuration file '._DIR._FILE_DBCONF.' written.'; displaySetupMessage($msg, true); } else { displaySetupMessage($databaseConfWriteError, false); send("
"); send('

To perform this step manually please paste the following content to the database configuration file '._DIR._FILE_DBCONF.' and ensure the file is readable by the user the webserver runs as:

'); send(''); send("

Note: You must write this file before you can continue!

"); } send("
"); send("

Next : Create Tables

"); sendButton(16); } elseif (isset($_REQUEST["16"])) { // 16 - Database - table-creation sendHead(" - Database"); send("

"._TITLE."

"); send("

Database - Create Tables

"); send("

The installation will now attempt to create the database tables required for running "._NAME.".

"); if (is_file(_FILE_DBCONF)) { require_once(_FILE_DBCONF); $databaseTableCreationCount = 0; $databaseTableCreation = false; $databaseError = ""; $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]); if (!$dbCon) { $databaseTableCreation = false; $databaseError = "Cannot connect to database."; } else { send('
    '); foreach ($queries['create'][$cfg["db_type"]] as $databaseTypeName => $databaseQuery) { send('
  • '); $dbCon->Execute($databaseQuery); if ($dbCon->ErrorNo() == 0) { send('Query Ok: '.$databaseQuery.''); $databaseTableCreationCount++; } else { // damn there was an error send('Query Error: '.$databaseQuery.''); $databaseError = "Could not create tables. Note that the database must be empty to perform this step."; // close ado-connection $dbCon->Close(); break; } } if ($databaseTableCreationCount == count($queries['create'][$cfg["db_type"]])) { // close ado-connection $dbCon->Close(); $databaseTableCreation = true; } else { $databaseTableCreation = false; } send('
'); } if ($databaseTableCreation) { $msg = $databaseTableCreationCount.' tables created'; displaySetupMessage($msg, true); send("
"); send("

Next: Insert Data Into Database

"); sendButton(17); } else { displaySetupMessage($databaseError, false); } } else { displaySetupMessage($msgDbConfigMissing, false); } } elseif (isset($_REQUEST["17"])) { // 17 - Database - data sendHead(" - Database"); send("

"._TITLE."

"); send("

Database - Insert Data Into Database

"); send("

The installation will now attempt to insert all the data required for the system into the database.

"); if (is_file(_FILE_DBCONF)) { require_once(_FILE_DBCONF); $databaseDataCount = 0; $databaseData = false; $databaseError = ""; $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]); if (!$dbCon) { $databaseData = false; $databaseError = "cannot connect to database."; } else { send('
    '); foreach ($queries['data'][$cfg["db_type"]] as $databaseTypeName => $databaseQuery) { send('
  • '); $dbCon->Execute($databaseQuery); if ($dbCon->ErrorNo() == 0) { send('Query Ok: '.$databaseQuery); $databaseDataCount++; } else { // damn there was an error send('Query Error: '.$databaseQuery); $databaseError = "Could not import data into database. Database tables must be empty before performing this step."; // close ado-connection $dbCon->Close(); break; } } if ($databaseDataCount == count($queries['data'][$cfg["db_type"]])) { // close ado-connection $dbCon->Close(); $databaseData = true; } else { $databaseData = false; } send('
'); } if ($databaseData) { $msg = $databaseDataCount.' queries executed.'; displaySetupMessage($msg, true); send("
"); send("

Next: Server Configuration

"); sendButton(2); } else { displaySetupMessage($databaseError, false); } } else { displaySetupMessage($err, false); } } elseif (isset($_REQUEST["2"])) { // 2 - Configuration sendHead(" - Configuration"); send("

"._TITLE."

"); send("

Server Configuration

"); send("

The installation will now continue to prompt you for some basic settings required to get "._NAME." running.

"); send("
"); send("

Next : Server Settings

"); sendButton(21); } elseif (isset($_REQUEST["21"])) { // 21 - Configuration - Server Settings input sendHead(" - Configuration"); send("

"._TITLE."

"); send("

Configuration - Server Settings

"); if (is_file(_FILE_DBCONF)) { require_once(_FILE_DBCONF); $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]); if (!$dbCon) { $err = "cannot connect to database."; } else { $tf_settings = loadSettings("tf_settings"); // close ado-connection $dbCon->Close(); if ($tf_settings !== false) { send("

Please enter the path to the directory you want "._NAME." to save your user downloads into below.

"); send("

Important: this path must be writable by the webserver user

"); send('
'); send(''); // path $line = ''; $line .= '
User Download Path:'); // docroot if (isset($_REQUEST["docroot"])) send(''); else send(''); send(''); send(''); send(''); } else { $err = "error loading settings."; displaySetupMessage($err, false); } } } else { displaySetupMessage($msgDbConfigMissing, false); } } elseif (isset($_REQUEST["22"])) { // 22 - Configuration - Server Settings validate sendHead(" - Configuration"); send("

"._TITLE."

"); send("

Configuration - Server Settings Validation

"); $serverSettingsTestCtr = 0; $serverSettingsTestError = ""; $pathExists = false; $path = $_REQUEST["path"]; if(empty($path)){ $serverSettingsTestError = "user download path cannot be empty, please supply the full path to the directory."; } elseif (((strlen($path) > 0)) && (substr($path, -1 ) != "/")){ $path .= "/"; } $docroot = $_REQUEST["docroot"]; if (((strlen($docroot) > 0)) && (substr($docroot, -1 ) != "/")) $docroot .= "/"; // Only go here if no error already: if(empty($serverSettingsTestEror)){ // path if (!(@is_dir($path) === true)) { // dir doesn't exist, try to create if (!((@mkdir($path, 0777)) === true)) $serverSettingsTestError .= "path ".$path." does not exist and cannot be created. Check that the path is writable by the webserver user."; else $pathExists = true; } else { $pathExists = true; } if ($pathExists) { if (!(@is_writable($path) === true)) $serverSettingsTestError .= "path ".$path." is not writable. Check that the path is writable by the webserver user."; else $serverSettingsTestCtr++; } // docroot if (is_file($docroot."version.php")) $serverSettingsTestCtr++; else $serverSettingsTestError .= "docroot ".$docroot." is not valid."; } // output if ($serverSettingsTestCtr == 2) { $msg = "User download directory set to: ".$path.""; displaySetupMessage($msg, true); $msg = "Document root directory set to: ".$docroot.""; displaySetupMessage($msg, true); send("
"); send("

Next: Check For Third Party Utilities

"); send('
'); send(''); send(''); send(''); send(''); } else { displaySetupMessage($serverSettingsTestError, false); send("
"); send(''); send(''); send(''); send(''); send(''); } send('
'); } elseif (isset($_REQUEST["221"])) { $OS = strtolower(exec("uname")); // Check for system tools like grep, awk, netstat, rar, etc: sendHead(" - Configuration"); send("

"._TITLE."

"); send("

Configuration - Check System Tools

"); send("

The installation will now check to locate the system tools required for operating "._NAME." smoothly.


"); $line = ''; $line .= ''; if (is_file(_FILE_DBCONF)) { require_once(_FILE_DBCONF); $databaseError = ""; $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]); if (!$dbCon) { $databaseError = "cannot connect to database."; // stop: displaySetupMessage($databaseError, false); } else { // extra non-standard binary paths to check installed binaries: $binPaths = array( // FreeBSD: '/usr/local/bin', '/usr/local/sbin', // NetBSD: '/usr/pkgsrc/bin', '/usr/pkgsrc/sbin', // OpenBSD (same as fbsd?): // Solaris (unsure): // AN other: ); // Array of binaries => default binary paths: $bins = array( 'grep' => '/bin/grep', 'netstat' => '/bin/netstat', 'php' => '/usr/bin/php', 'awk' => '/usr/bin/awk', 'du' => '/usr/bin/du', 'wget' => '/usr/bin/wget', 'unrar' => '/usr/bin/unrar', 'unzip' => '/usr/bin/unzip', 'cksfv' => '/usr/bin/cksfv', 'sockstat' => '/usr/bin/sockstat', 'vlc' => '/usr/local/bin/vlc', 'uudeview' => '/usr/local/bin/uudeview' ); $pathErrCount = 0; foreach ($bins as $bin => $path){ if($OS == "linux" && $bin == "sockstat"){ continue; } $foundPath = ""; $isExe = false; $line .= ''; $line .= '"; } $line .="
Tool NamePathInfo
'.$bin.''; // see if which finds this binary: $foundPath = trim(exec(escapeshellcmd("which $bin"))); if(empty($foundPath)){ // OK no bin found, let's check the non-standard paths: foreach ($binPaths as $extraPath){ $thisBin = $extraPath."/".$bin; if( is_file($thisBin) ){ // Yay, found the file: $foundPath = $thisBin; // Check executable bit: if ( is_executable($foundPath) ){ $isExe = true; // Done with this exe, move onto next: break; } } } } else { // Check is exe: if(is_executable($foundPath)){ $isExe = true; } } if(!empty($foundPath)){ $line .= $foundPath.'Path found Ok. '; if(!$isExe){ $line .= 'Error: binary '.$foundPath.' is NOT executable. Ensure webserver user can execute this binary before continuing.'; } else { $line .= $foundPath.' is executable.'; } // Update path for this binary: $databaseQuery = "UPDATE tf_settings SET tf_value='$foundPath' WHERE tf_key='bin_$bin'"; $dbCon->Execute($databaseQuery); if ($dbCon->ErrorNo() != 0) { // Problem with query: $line .= "

Error executing query:
$databaseQuery"; } } else { // Didn't find this binary, let the user know: $line .= 'NOT FOUND
Warning: could not find '.$bin.' on your system. Default path '.$path.' used.'; $pathErrCount++; } $line .= "
"; if($pathErrCount > 0){ $line .= "

Important:
There were problems locating the paths to some tools on your server. "; $line .= "Depending on which tools they were, some features may not work as expected.

After installation, check that the tools reported as NOT FOUND above are installed correctly and modify your installation settings to reflect the path of the problematic tools. You can do this by clicking on the 'Admin' link at the top right of the "._NAME." page and then selecting the 'Server Settings' tab.

"; } send($line); send("
"); send('
'); send(''); send(''); send(''); send("
"); send("

Next: Server Settings Save

"); send(''); send('
'); } } else { // stop: displaySetupMessage($msgDbConfigMissing, false); } } elseif (isset($_REQUEST["23"])) { // 23 - Configuration - Server Settings save sendHead(" - Configuration"); send("

"._TITLE."

"); send("

Configuration - Server Settings Save

"); $path = $_REQUEST["path"]; $docroot = $_REQUEST["docroot"]; if (is_file(_FILE_DBCONF)) { require_once(_FILE_DBCONF); $dbCon = getAdoConnection($cfg["db_type"], $cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]); if (!$dbCon) { $err = "cannot connect to database. Check database settings in "._FILE_DBCONF; displaySetupMessage($err); } else { $settingsSaveCtr = 0; if (updateSetting("tf_settings", "path", $path) === true) $settingsSaveCtr++; if (updateSetting("tf_settings", "docroot", $docroot) === true) $settingsSaveCtr++; if ($settingsSaveCtr == 2) { $msg = 'Server settings saved to database.'; displaySetupMessage($msg, true); send("
"); send("

Next: Installation End

"); sendButton(3); } else { $err = 'could not save path and docroot server settings to database.'; displaySetupMessage($err, false); send("
"); send('
'); send(''); send(''); send(''); send(''); send('
'); } // close ado-connection $dbCon->Close(); } } else { displaySetupMessage($msgDbConfigMissing, false); } } elseif (isset($_REQUEST["3"])) { // 3 - End sendHead(" - End"); send("

"._TITLE."

"); send("

Setup Completed

"); send("

Congratulations! "._NAME." has successfully been installed.

"); if ((substr(_VERSION, 0, 3)) != "svn") { $result = @unlink(__FILE__); if ($result !== true) { $err = 'Could not delete '.__FILE__.'. Please delete the file manually.'; $err .= 'Important: '._NAME.' will not run until this file is deleted for security reasons!'; displaySetupMessage($err, false); } else { $msg = 'Deleted '.__FILE__.' successfully.'; displaySetupMessage($msg, true); send("
"); send("

Next: Login

"); send("

To continue on to the "._NAME." login screen, click the button below:

"); send('
'); send(''); send('
'); } } else { $msg = 'This is an svn-version. '.__FILE__.' is untouched. Please remove the file manually to login to your '._NAME.' installation.'; displaySetupMessage($msg, true); } send("

Important:
When logging in for the first time the login username and password you supply there will create the default superadmin user for your "._NAME." installation. For this reason it is important you do this immediately and remember the username and password!!!

"); } else { // default sendHead(); if (is_file(_FILE_DBCONF)) send('


db-config already exists ('._FILE_DBCONF.')

Delete setup.php if you came here after finishing setup to proceed to login.


'); send("

"._TITLE."

"); send("

Welcome to the installation script for ". _NAME.". In the following pages you will be guided through the steps necessary to get your installation of "._NAME." up and running, including database configuration and initial "._NAME." system configuration file creation.

"); send("
"); send("

Next: Database

"); sendButton(1); } // foot sendFoot(); // ob-end + exit @ob_end_flush(); exit(); ?>