Skip to content

Instantly share code, notes, and snippets.

@atmoner
Created March 26, 2015 19:45
Show Gist options
  • Save atmoner/35f609e4c001380e0688 to your computer and use it in GitHub Desktop.
Save atmoner/35f609e4c001380e0688 to your computer and use it in GitHub Desktop.
<?php
// Run: php install.php
//ENTER THE RELEVANT INFO BELOW
$mysqlDatabaseName ='torrentDb';
$mysqlUserName ='root';
$mysqlPassword ='toor';
$mysqlHostName ='localhost';
$mysqlImportFilename ='libs/db.sql';
// CONFIG BITTYTORRENT
$path = 'http://localhost';
$sessionName = 'sessionDomain';
// CONFIG ADMIN
$username = 'admin';
$pass = 'admin';
$mail = 'test@gmail.com';
$pathFile = dirname(__FILE__);
//DONT EDIT BELOW THIS LINE
//Export the database and output the status to the page
$command='mysql -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' < ' .$mysqlImportFilename;
exec($command,$output=array(),$worked);
switch($worked){
case 0:
echo 'Import file ' .$mysqlImportFilename .' successfully imported to database ' .$mysqlDatabaseName .'';
break;
case 1:
echo 'There was an error during import. Please make sure the import file is saved in the same folder as this script and check your values.';
break;
}
if ($worked === 0) {
if (is_writable($pathFile."/libs/db.php"))
{
$fd = fopen($pathFile."/libs/db.php", "w+");
$foutput = "<?php\n";
$foutput.= "// Generate the ".date("j F, Y, h:i:s")."\n";
$foutput.= "// For Bittytorrent\n";
$foutput.= "\$dbhost = \"".$mysqlHostName."\";\n";
$foutput.= "\$dbuser = \"".$mysqlUserName."\";\n";
$foutput.= "\$dbpass = \"".$mysqlPassword."\";\n";
$foutput.= "\$dbname = \"".$mysqlDatabaseName."\";\n";
$foutput.= "// Please ! manipulate this file if you know what you made​​!\n";
$foutput.= "";
fwrite($fd,$foutput);
fclose($fd);
}
function addUser($name,$mail,$pass,$redirect='NULL',$sendMail='NULL',$isadmin="NULL") {
global $db;
$hash = makeId(15);
if ($isadmin!="NULL")
$level = "6";
else
$level = "2";
$query = "INSERT INTO users (id,name,pass,mail,level,private_id)
VALUES (
'NULL',
'".$db->escape($name)."',
'".obscure($pass)."',
'".$db->escape($mail)."',
'$level',
'".md5(uniqid(rand(), true))."'
)";
$db->query($query);
return true;
}
###
function makeId($car=8) {
$string = "";
$chaine = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnpqrstuvwxy1234567890";
srand((double)microtime()*1000000);
for($i=0; $i<$car; $i++) {
$string .= $chaine[rand()%strlen($chaine)];
}
return $string;
}
//Obscure
function obscure($password, $algorythm = "sha1"){
global $db;
$db->query("SELECT * FROM `settings` WHERE `key` = 'salt' ");
$dbSalt = $db->get_row();
$password = strtolower($password);
$salt = hash($algorythm, $dbSalt->value);
$hash_length = strlen($salt);
$password_length = strlen($password);
$password_max_length = $hash_length / 2;
if ($password_length >= $password_max_length){
$salt = substr($salt, 0, $password_max_length);
} else {
$salt = substr($salt, 0, $password_length);
}
$salt_length = strlen($salt);
$salted_password = hash($algorythm, $salt . $password);
$used_chars = ($hash_length - $salt_length) * -1;
$final_result = $salt . substr($salted_password, $used_chars);
return $final_result;
}
require($pathFile.'/libs/db.php');
require($pathFile.'/libs/database/ez_sql_core.php');
require($pathFile.'/libs/database/ez_sql_mysql.php');
$db = new ezSQL_mysql($dbuser,$dbpass,$dbname,$dbhost);
$db->query("UPDATE settings SET value = '".$path."' WHERE `settings`.`key` = 'baseurl';");
$db->query("UPDATE settings SET value = '".$sessionName."' WHERE `settings`.`key` = 'sessionName';");
$db->query("UPDATE settings SET value = '".makeId(32)."' WHERE `settings`.`key` = 'salt';");
addUser($username,$mail,$pass,'NULL','NULL','TRUE');
echo 'Bittytorrent installed!!';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment