<commit_before><?php

$quit = "Goodbye. Installation aborted.\n";
$mysqldatabase = "";
$mysqlport = "";
$mysqlserver = "";
$mysqluser = "";
$mysqlpass = "";
$fcport = "";
$fcssl = false;

// Set up the mysql database name

mysql:

$result = readline( "Please enter a MySQL database name: " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto mysql;

$mysqldatabase = $result;

// Setup the mysql hostname or IP

mysqlhost:

$result = readline( "Please enter your mysql database hostname or IP: " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto mysqlhost;

$mysqlserver = strtolower( trim( $result ) );

// Setup the mysql port number

mysqlport:

$result = readline( "Please enter your mysql port number (default is 3306): " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto mysqlport;

$mysqlport = trim( $result );

// Setup username for mysql

mysqlusername:

$result = readline( "Please enter mysql username: " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto mysqlusername;

$mysqluser = trim( $result );

mysqlpassword:

$result = readline( "Please enter mysql password: " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto mysqlpassword;

$mysqlpass = trim( $result );

// Setup friend core port

fcport:

echo( "Please enter the port number for the Friend Core server. If\n" );

$result = readline( "you are not root, it must be higher than 1024 (1025+): " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto fcport;

$fcport = trim( $result );

// Setup friend core ssl

$yn = readline( "Will you run the server using SSL (HTTPS) (Yes/No/Quit)? " );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

$yn = strtolower( trim( $yn ) );

$fcssl = $yn == 'y' || $yn == 'yes' ? true : false;

// Now start installing

echo( "---\n\nWe are now ready to install...\n" );

$conn = @mysql_connect( $mysqlserver . ':' . $mysqlport, $mysqluser, $mysqlpass )
	or die( "Failed to connect to mysql server. Please use another username or password.\n" );

$result = mysql_query( 'CREATE DATABASE `' . $mysqldatabase . '`' );

if( substr( mysql_error(), 0, 5 ) == 'Can\'t' )
{
	die( "The database could not be created.\n" );
}

mysql_query( 'USE ' . $mysqldatabase );

if( !( $db = file_get_contents( 'docs/FriendCoreDatabase.sql' ) ) )
	die( "Could not locate friend core database template.\n" );

// Remove comments
$db = preg_replace( '/\-\-[^\n]*?\n/i', '', $db );
$db = preg_replace( '/\/\*[^*]*?\*\/[\;]{0,1}/i', '', $db );

// Install db
if( $rows = explode( ";", $db ) )
{
	foreach( $rows as $row )
	{
		$row = trim( $row );
		if( !$row ) continue;
		if( substr( $row, 0, 3 ) == 'SET' ) continue;
		
		
		mysql_query( $row );
	}	
}

// Set config
$conf = file_get_contents( 'docs/ConfigTemplate.ini' );

$setup = array(
	'{user}'   => $mysqluser,
	'{pass}'   => $mysql<PASSWORD>,
	'{host}'   => $mysqlserver,
	'{db}'     => $mysqldatabase,
	'{dbport}' => $mysqlport,
	'{fchost}' => $mysqlserver,
	'{fcport}' => $fcport,
	'{fcssl}'  => $fcssl ? '1' : '0'
);

foreach( $setup as $k=>$v )
	$conf = str_replace( $k, $v, $conf );

// Some folders
if( !file_exists( 'build' ) )
	mkdir( 'build' );
if( !file_exists( 'build/cfg' ) )
	mkdir( 'build/cfg' );
if( !file_exists( 'build/cfg/crt' ) )
	mkdir( 'build/cfg/crt' );

// Write config
if( $f = fopen( 'build/cfg/cfg.ini', 'w+' ) )
{
	fwrite( $f, $conf );
	fclose( $f );
}

mysql_close( $conn );

echo( "Now go and start FriendCore. You are all set.\n" );

?><commit_msg>Say which pw and username<commit_after><?php

$quit = "Goodbye. Installation aborted.\n";
$mysqldatabase = "";
$mysqlport = "";
$mysqlserver = "";
$mysqluser = "";
$mysqlpass = "";
$fcport = "";
$fcssl = false;

// Set up the mysql database name

mysql:

$result = readline( "Please enter a MySQL database name: " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto mysql;

$mysqldatabase = $result;

// Setup the mysql hostname or IP

mysqlhost:

$result = readline( "Please enter your mysql database hostname or IP: " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto mysqlhost;

$mysqlserver = strtolower( trim( $result ) );

// Setup the mysql port number

mysqlport:

$result = readline( "Please enter your mysql port number (default is 3306): " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto mysqlport;

$mysqlport = trim( $result );

// Setup username for mysql

mysqlusername:

$result = readline( "Please enter mysql username: " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto mysqlusername;

$mysqluser = trim( $result );

mysqlpassword:

$result = readline( "Please enter mysql password: " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto mysqlpassword;

$mysqlpass = trim( $result );

// Setup friend core port

fcport:

echo( "Please enter the port number for the Friend Core server. If\n" );

$result = readline( "you are not root, it must be higher than 1024 (1025+): " );

echo( "You entered \"$result\", is this correct?" );

$yn = strtolower( trim( readline( " (Yes/No/Quit)\n" ) ) );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

if( $yn == 'no' || $yn == 'n' )
	goto fcport;

$fcport = trim( $result );

// Setup friend core ssl

$yn = readline( "Will you run the server using SSL (HTTPS) (Yes/No/Quit)? " );

if( $yn == 'quit' || $yn == 'q' || $yn == '' ) die( $quit );

$yn = strtolower( trim( $yn ) );

$fcssl = $yn == 'y' || $yn == 'yes' ? true : false;

// Now start installing

echo( "---\n\nWe are now ready to install...\n" );

$conn = @mysql_connect( $mysqlserver . ':' . $mysqlport, $mysqluser, $mysqlpass )
	or die( "Failed to connect to mysql server. Please use another username or password.\n" );

$result = mysql_query( 'CREATE DATABASE `' . $mysqldatabase . '`' );

if( substr( mysql_error(), 0, 5 ) == 'Can\'t' )
{
	die( "The database could not be created.\n" );
}

mysql_query( 'USE ' . $mysqldatabase );

if( !( $db = file_get_contents( 'docs/FriendCoreDatabase.sql' ) ) )
	die( "Could not locate friend core database template.\n" );

// Remove comments
$db = preg_replace( '/\-\-[^\n]*?\n/i', '', $db );
$db = preg_replace( '/\/\*[^*]*?\*\/[\;]{0,1}/i', '', $db );

// Install db
if( $rows = explode( ";", $db ) )
{
	foreach( $rows as $row )
	{
		$row = trim( $row );
		if( !$row ) continue;
		if( substr( $row, 0, 3 ) == 'SET' ) continue;
		
		
		mysql_query( $row );
	}	
}

// Set config
$conf = file_get_contents( 'docs/ConfigTemplate.ini' );

$setup = array(
	'{user}'   => $mysqluser,
	'{pass}'   => $mysqlpass,
	'{host}'   => $mysqlserver,
	'{db}'     => $mysqldatabase,
	'{dbport}' => $mysqlport,
	'{fchost}' => $mysqlserver,
	'{fcport}' => $fcport,
	'{fcssl}'  => $fcssl ? '1' : '0'
);

foreach( $setup as $k=>$v )
	$conf = str_replace( $k, $v, $conf );

// Some folders
if( !file_exists( 'build' ) )
	mkdir( 'build' );
if( !file_exists( 'build/cfg' ) )
	mkdir( 'build/cfg' );
if( !file_exists( 'build/cfg/crt' ) )
	mkdir( 'build/cfg/crt' );

// Write config
if( $f = fopen( 'build/cfg/cfg.ini', 'w+' ) )
{
	fwrite( $f, $conf );
	fclose( $f );
}

mysql_close( $conn );

echo( "Now go and start FriendCore. You are all set.\n" );
echo( "Your username is: friendadmin\n" );
echo( "Your password is: <PASSWORD>" );

?>
{'fraction_non_alphanumeric': 0.23296531727445077, 'fraction_numerical': 0.004460800713728114, 'mean_word_length': 3.4177339901477835, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5161738', 'n_tokens_mistral': 3594, 'n_tokens_neox': 3506, 'n_words': 1008}