"._TITLE.""); send("

Database

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

"._TITLE."

"); send("

Database - Type

"); send('
'); send(''); 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])) { send('Ok
'); send('This PHP does support '.$type.'.

'); send('

'); send(''); send(''); send(''); send('
'); } else { send('Error
'); send('This PHP does not support '.$type.'.

'); 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('
'); send(''); // settings send(''); switch ($type) { case "mysql": // host $line = ''; $line .= ''; send($line); // break; case "sqlite": // file $line = ''; $line .= '
Database Settings :
Host : '; else $line .= '>'; $line .= '
Database-File : '); send(''); send(''); send(''); send(''); } elseif (isset($_REQUEST["14"])) { // 14 - Database - test $type = $_REQUEST["db_type"]; sendHead(" - Database"); send("

"._TITLE."

"); send("

Database - Test - ".$type."

"); $paramsOk = true; if (isset($_REQUEST["db_host"])) $host = $_REQUEST["db_host"]; else $paramsOk = false; if (isset($_REQUEST["db_pcon"])) $pcon = "true"; else $pcon = "false"; switch ($type) { case "mysql": if (isset($_REQUEST["db_name"])) $name = $_REQUEST["db_name"]; else $paramsOk = false; if (isset($_REQUEST["db_user"])) $user = $_REQUEST["db_user"]; else $paramsOk = false; if (isset($_REQUEST["db_pass"])) $pass = $_REQUEST["db_pass"]; else $paramsOk = false; break; case "sqlite": $name = ""; $user = ""; $pass = ""; } $databaseTestOk = false; $databaseError = ""; // test if ($paramsOk) { $dbCon = getAdoConnection($type, $host, $user, $pass, $name); if (!$dbCon) { $databaseTestOk = false; $databaseError = "cannot connect to database."; } else { send('
    '); $databaseTestCount = 0; foreach ($queries['test'][$type] as $databaseTypeName => $databaseQuery) { send('
  • '.$databaseQuery.' : '); $dbCon->Execute($databaseQuery); if ($dbCon->ErrorNo() == 0) { send('Ok
  • '); $databaseTestCount++; } else { // damn there was an error send('Error'); // close ado-connection $dbCon->Close(); break; } } if ($databaseTestCount == count($queries['test'][$type])) { $databaseTestOk = true; } else { $databaseTestOk = false; } send('
'); } } else { $databaseTestOk = false; $databaseError = "config error."; } // output if ($databaseTestOk) { // load path $tf_settings = loadSettings("tf_settings"); if ($tf_settings !== false) { $oldpath = $tf_settings["path"]; if (((strlen($oldpath) > 0)) && (substr($oldpath, -1 ) != "/")) $oldpath .= "/"; } else { $oldpath = _DEFAULT_PATH; } // close ado-connection $dbCon->Close(); send('Ok
'); send("

Next : Write Config File

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

"); send('

'); send(''); send(''); send(''); send(''); send(''); send(''); send(''); send(''); send(''); } else { send('Error
'); send($databaseError."

"); 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(''); send(''); } send('

'); } elseif (isset($_REQUEST["15"])) { // 15 - Database - config-file sendHead(" - Database"); send("

"._TITLE."

"); send("

Database - Config-File

"); $oldpath = $_REQUEST["oldpath"]; $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) { send('Ok
'); send('database-config-file '._DIR._FILE_DBCONF.' written.'); } else { send('Error
'); send($databaseConfWriteError."

"); send('to perform this step manual paste the following content to the database-config-file '._DIR._FILE_DBCONF.' :

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

Note : You must write this file before you can continue !"); } send("

Next : Create/Alter Tables

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

"._TITLE."

"); send("

Database - Create/Alter Tables

"); $oldpath = $_REQUEST["oldpath"]; 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('
  • '.$databaseQuery.' : '); $dbCon->Execute($databaseQuery); if ($dbCon->ErrorNo() == 0) { send('Ok
  • '); $databaseTableCreationCount++; } else { // damn there was an error send('Error'); $databaseError = "error creating tables."; // 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) { send('Ok
'); send($databaseTableCreationCount.' queries executed.'); send("

Next : Data

"); send('
'); send(''); send(''); send(''); send('
'); } else { send('Error
'); send($databaseError."

"); } } else { send('Error
'); send('database-config-file '._DIR._FILE_DBCONF.' missing. setup cannot continue.'); } } elseif (isset($_REQUEST["17"])) { // 17 - Database - data sendHead(" - Database"); send("

"._TITLE."

"); send("

Database - Data

"); $oldpath = $_REQUEST["oldpath"]; 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('
    '); // add path array_unshift($queries['data'][$cfg["db_type"]], "INSERT INTO tf_settings VALUES ('path','".$oldpath."')"); // add delete-state array_unshift($queries['data'][$cfg["db_type"]], "DELETE FROM tf_settings"); // exec foreach ($queries['data'][$cfg["db_type"]] as $databaseTypeName => $databaseQuery) { send('
  • '.$databaseQuery.' : '); $dbCon->Execute($databaseQuery); if ($dbCon->ErrorNo() == 0) { send('Ok
  • '); $databaseDataCount++; } else { // damn there was an error send('Error'); $databaseError = "error importing data."; // 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) { send('Ok
'); send($databaseDataCount.' queries executed.'); send("

Next : Configuration

"); sendButton(2); } else { send('Error
'); send($databaseError."

"); } } else { send('Error
'); send('database-config-file '._DIR._FILE_DBCONF.' missing. setup cannot continue.'); } } elseif (isset($_REQUEST["2"])) { // 2 - Configuration sendHead(" - Configuration"); send("

"._TITLE."

"); send("

Configuration

"); send("

Next : Server Settings

"); sendButton(21); send(''); } 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) { send('Error
'); send("cannot connect to database.

"); } else { $tf_settings = loadSettings("tf_settings"); // close ado-connection $dbCon->Close(); if ($tf_settings !== false) { send('

'); send(''); // docroot /* $line = ''; $line .= '
docroot : '); // docroot if (isset($_REQUEST["docroot"])) send(''); else send(''); send(''); send(''); send(''); } else { send('Error
'); send("error loading settings.

"); } } } else { send('Error
'); send('database-config-file '._DIR._FILE_DBCONF.' missing. setup cannot continue.'); } } elseif (isset($_REQUEST["22"])) { // 22 - Configuration - Server Settings validate sendHead(" - Configuration"); send("

"._TITLE."

"); send("

Configuration - Server Settings Validation

"); $docroot = $_REQUEST["docroot"]; if (((strlen($docroot) > 0)) && (substr($docroot, -1 ) != "/")) $docroot .= "/"; $serverSettingsTestCtr = 0; $serverSettingsTestError = ""; // docroot if (is_file($docroot."version.php")) $serverSettingsTestCtr++; else $serverSettingsTestError .= "docroot ".$docroot." is not valid."; // output if ($serverSettingsTestCtr == 1) { send('Ok
'); send("docroot : ".$docroot."
"); send("

Next : Save Server Settings

"); send('
'); send(''); send(''); send(''); } else { send('Error
'); send($serverSettingsTestError."

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

'); } elseif (isset($_REQUEST["23"])) { // 23 - Configuration - Server Settings save sendHead(" - Configuration"); send("

"._TITLE."

"); send("

Configuration - Server Settings Save

"); $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) { send('Error
'); send("cannot connect to database.

"); } else { $settingsSaveCtr = 0; if (updateSetting("tf_settings", "docroot", $docroot) === true) $settingsSaveCtr++; if ($settingsSaveCtr == 1) { send('Ok
'); send('Server Settings saved.'); send("

Next : Rename Files and Dirs

"); sendButton(3); } else { send('Error
'); send('could not save Server Settings.'); send('
'); send(''); send(''); send(''); send('
'); } // close ado-connection $dbCon->Close(); } } else { send('Error
'); send('database-config-file '._DIR._FILE_DBCONF.' missing. setup cannot continue.'); } } elseif (isset($_REQUEST["3"])) { // 3 - rename files and dirs sendHead(" - Rename Files and Dirs"); send("

"._TITLE."

"); send("

Rename Files and Dirs

"); 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) { send('Error
'); send("cannot connect to database.

"); } else { $tf_settings = loadSettings("tf_settings"); // close ado-connection $dbCon->Close(); if ($tf_settings !== false) { $path = $tf_settings["path"]; $pathExists = false; $renameOk = false; $allDone = true; if ((@is_dir($path) === true) && (@is_dir($path.".torrents") === true)) { $pathExists = true; send('

    '); // transfers-dir send('
  • '.$path.".torrents -> ".$path.".transfers".' : '); $renameOk = rename($path.".torrents", $path.".transfers"); if ($renameOk === true) { send('Ok
  • '); } else { $allDone = false; send('Error'); } // old queue-dir if ($renameOk) { if (@is_dir($path.".transfers/queue")) { $files = array(); if ($dirHandle = opendir($path.".transfers/queue")) { while (false !== ($file = readdir($dirHandle))) { if ((strlen($file) > 4) && ((substr($file, -4)) == "stat")) array_push($files, $file); } closedir($dirHandle); } $filesCount = count($files); $filesCtr = 0; if ($filesCount > 0) { foreach ($files as $file) { $fileSource = $path.".transfers/queue/".$file; send('
  • delete : '.$fileSource.' : '); $fileUnlinkOk = @unlink($fileSource); if ($fileUnlinkOk === true) { $filesCtr++; send('Ok
  • '); } else { send('Error'); } } if ($filesCount != $filesCtr) $allDone = false; } send('
  • delete : '.$path.".transfers/queue".' : '); $rmdirOk = @rmdir($path.".transfers/queue"); if ($rmdirOk === true) { send('Ok
  • '); } else { $allDone = false; send('Error'); } } } // transfer-files (should not be here anymore if transfers // were deleted like required and written in the docu) if ($renameOk) { $fileTypes = array(".torrent", ".stat", ".pid", ".prio", ".url"); $files = array(); if ($dirHandle = opendir($path.".transfers")) { while (false !== ($file = readdir($dirHandle))) { $stringLength = strlen($file); foreach ($fileTypes as $ftype) { $extLength = strlen($ftype); $extIndex = 0 - $extLength; if (($stringLength > $extLength) && (strtolower(substr($file, $extIndex)) === ($ftype))) array_push($files, $file); } } closedir($dirHandle); } $filesCount = count($files); $filesCtr = 0; if ($filesCount > 0) { foreach ($files as $file) { $fileSource = $path.".transfers/".$file; send('
  • delete : '.$fileSource.' : '); $fileUnlinkOk = @unlink($fileSource); if ($fileUnlinkOk === true) { $filesCtr++; send('Ok
  • '); } else { send('Error'); } } if ($filesCount != $filesCtr) $allDone = false; } } send('
'); if ($allDone) { send('Ok
'); send('Files and Dirs renamed.'); send("

Next : End

"); sendButton(4); } else { // damn there was an error send('Error'); send("error renaming Files and Dirs. you have to re-inject all torrents.

"); } } else { send('Error'); send("path ".$path.".torrents does not exist. you have to re-inject all torrents.

"); } } else { send('Error
'); send("error loading settings.

"); } } } else { send('Error
'); send('database-config-file '._DIR._FILE_DBCONF.' missing. setup cannot continue.'); } } elseif (isset($_REQUEST["4"])) { // 4 - End sendHead(" - End"); send("

"._TITLE."

"); send("

End

"); send("

Upgrade completed.

"); if ((substr(_VERSION, 0, 3)) != "svn") { $result = @unlink(__FILE__); if ($result !== true) send('

Could not delete '.__FILE__.'
Please delete the file manual.

'); else send('

Deleted '.__FILE__.'

'); } else { send('

This is a svn-version. '.__FILE__.' is untouched.

'); } send("

Next : Login

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


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

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


'); send("

"._TITLE."

"); send("

This script will upgrade "._NAME." from "._UPGRADE_FROM." to "._UPGRADE_TO."

"); send("

Next : Database

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