<commit_before><?php
//Instalation Related Functions

/*
* Creates or replaces the database configuration file
*
*/
function write_db_config($host, $name, $user, $pass, $prefix, $file){
$buffer = <<<EOF
<?php
define("DB_HOST", "$host");
define("DB_NAME", "$name");
define("DB_USER", "$user");
define("DB_PASS", "$<PASSWORD>");
define("TB_PRFX", "$prefix");
?>
EOF;
if (!file_put_contents($file, $buffer)){throw new Exception("Could not wrtite configuration.", 2);}
}

/*
* Creates or replaces the wallet configuration file
*
*/
function write_wallet_config($type, $host, $port, $user, $pass, $address_version, $coldwallet_file, $encr, $file){
//Hot or Cold Wallet
if($type == 'cold'){$host = ""; $port = "";}

//Clean up the variables a bit
if(!strcmp($host,"1. RPC Server (default - localhost)")){$host = "localhost";}
if(!strcmp($user,"2. RPC Username.")){$user = "";}
if(!strcmp($pass,"3. RPC Password.")){$pass = "";}
if(!strcmp($port,"4. RPC Port")){$port = "";}
if(!strcmp($address_version,"5. Address Version")){$address_version = "";}
if(!strcmp($encr,"7. If wallet encrypted, Enter PASS")){$encr = "";}
if(!strcmp($coldwallet_file,"6. Cold Wallet Datafile")){$coldwallet_file = "";}

$buffer = <<<EOF
<?php
define("ADDRESS_VERSION", "$address_version"); // Found in src/base58.h:CBitcoinAddress.PUBKEY_ADDRESS

//Hot Wallet Authetication Info
//The cold wallet also has a username/password component that's used by the push/pull client and server
define("PAYMENT_GW_RPC_USER", "$user");
define("PAYMENT_GW_RPC_PASS", "$pass");

//For cold Wallet
define("PAYMENT_GW_DATAFILE", "$coldwallet_file");

//For Hot Wallet - Leave PAYMENT_GW_RPC_HOST empty to use Cold Wallet
define("PAYMENT_GW_RPC_HOST", "$host");
define("PAYMENT_GW_RPC_PORT", "$port");
// If the wallet is encrypted, enter the PASSPHRASE here. Leave it blank otherwise!
define("PAYMENT_GW_RPC_ENCR", "$encr");
?>
EOF;
if (!file_put_contents($file, $buffer)){throw new Exception("Could not wrtite configuration.", 2);}

//Make sure we have what we need
if(empty($coldwallet_file) && $type == 'cold'){throw new Exception("No Datafile");}
if(empty($port) && $type == 'hot'){throw new Exception("No Port Given");}
if($type == 'cold' && (empty($user) || empty($pass))){throw new Exception("Cold wallet needs user and password");}
}


/*
* Creates or replaces the faucet configuration file
*
*/
function write_faucet_config($settings,  $file){
//Clean up the format of some variables
$settings['use_promo_codes'] = $settings['use_promo_codes'] == true ? 'true' : 'false';
$settings['captcha'] = $settings['use_captcha'] == 'false' ? '' : $settings['use_captcha'];
$settings['use_captcha'] = $settings['use_captcha'] == 'false' ? 'false' : 'true';
$settings['use_spammerslapper'] = $settings['use_spammerslapper'] ? 'true' : 'false';

$buffer = <<<EOF
<?php
// Modify these settings to suit your needs.
\$config = array(
	"mysql_table_prefix" => TB_PRFX, // table prefix to use

	"minimum_payout" => {$settings['minimum_payout']}, // minimum to be awarded
	"maximum_payout" => {$settings['maximum_payout']}, // maximum to be awarded
	"payout_threshold" => {$settings['payout_threshold']}, // payout threshold, if the faucet contains less than this, display the 'dry_faucet' message
	"payout_interval" => "{$settings['payout_interval']}", // payout interval, the wait time for a user between payouts. Type any numerical value with either a "m" (minutes), "h" (hours), or "d" (days), attached. Examples: 50m for a 50 minute delay, 7h for a 7 hour delay, etc.

	// this option has 3 possible values: "ip_address", "wallet_address", and "both". It defines what to check for when a user enters an address in order to decide whether or not to award to this user.
	// "ip_address": checks the user IP address in the payout history.
	// "wallet_address": checks the wallet address in the payout history.
	// "both": check both the IP and wallet address in the payout history.
	"user_check" => "{$settings['user_check']}",

	"use_captcha" => {$settings['use_captcha']}, // require the user to enter a captcha
	"use_spammerslapper" => {$settings['use_spammerslapper']}, // Prevent The use of Proxies and check the IP against Blacklists

	"captcha" => "{$settings['captcha']}", // which CAPTCHA to use, possible values are: "recaptcha", "solvemedia", and "simple-captcha".

	"captcha_config" => array(
		//Simple Captcha Session Name
		"simple_captcha_session_name" => "{$settings['captcha_config']['simple_captcha_session_name']}",
		// if you're using reCAPTCHA, enter your private and public keys here:
		"recpatcha_private_key" => "{$settings['captcha_config']['recpatcha_private_key']}",
		"recpatcha_public_key" => "{$settings['captcha_config']['recpatcha_public_key']}",
		// if you're using Solve MEDIA, enter your private, challenge, and hash keys here:
		"solvemedia_private_key" => "{$settings['captcha_config']['solvemedia_private_key']}",
		"solvemedia_challenge_key" => "{$settings['captcha_config']['solvemedia_challenge_key']}",
		"solvemedia_hash_key" => "{$settings['captcha_config']['solvemedia_hash_key']}",
	),

	"spammerslapper_key" => "{$settings['spammerslapper_key']}", // SpammerSlapper API key.

	// promo codes:
	"use_promo_codes" => {$settings['use_promo_codes']}, // accept promo codes

	// Donation address:
	"donation_address" => "{$settings['donation_address']}", // donation address to display

	// Faucet look and feel:
	"title" => "{$settings['title']}", // page title, may be used by the template too
	"sitename" => "{$settings['sitename']}", // page title, may be used by the template too
	"sitedesc" => "{$settings['sitedesc']}", // page title, may be used by the template too
	"coin_code" => "{$settings['coin_code']}",
	"template" => "{$settings['template']}", // template to use (see the templates directory)
	"lang" => "{$settings['lang']}",
);
?>
EOF;

if (!file_put_contents($file, $buffer)){throw new Exception("Could not wrtite configuration.", 2);}

//Validate some settings
//CAPTCHA - Yeah, it's complicated

//Normalize Variables
$settings['captcha_config']['solvemedia_private_key'] = $settings['captcha_config']['solvemedia_private_key'] == 'PRIVATE_KEY_HERE' ? '' : $settings['captcha_config']['solvemedia_private_key'];
$settings['captcha_config']['solvemedia_challenge_key'] = $settings['captcha_config']['solvemedia_challenge_key'] == 'CHALLENGE_KEY_HERE' ? '' : $settings['captcha_config']['solvemedia_challenge_key'];
$settings['captcha_config']['solvemedia_hash_key'] = $settings['captcha_config']['solvemedia_hash_key'] == 'HASH_KEY_HERE' ? '' : $settings['captcha_config']['solvemedia_hash_key'];
$settings['captcha_config']['recpatcha_private_key'] = $settings['captcha_config']['recpatcha_private_key'] == 'PRIVATE_KEY_HERE' ? '' : $settings['captcha_config']['recpatcha_private_key'];
$settings['captcha_config']['recpatcha_public_key'] = $settings['captcha_config']['recpatcha_public_key'] == 'PUBLIC_KEY_HERE' ? '' : $settings['captcha_config']['recpatcha_public_key'];

//Ensure we have the required settings
if(
	//Solve Media
	($settings['captcha'] == 'solvemedia' && 
	(empty($settings['captcha_config']['solvemedia_private_key']) ||
	empty($settings['captcha_config']['solvemedia_challenge_key']) ||
	empty($settings['captcha_config']['solvemedia_hash_key']))
	) ||
	//re-CAPTCHA
	($settings['captcha'] == 'recaptcha' && 
	(empty($settings['captcha_config']['recpatcha_private_key']) ||
	empty($settings['captcha_config']['recpatcha_public_key']))
	) ||
	//Simple Captcha
	($settings['captcha'] == 'simple-captcha' && 
	empty($settings['captcha_config']['simple_captcha_session_name'])
	)
){
	throw new Exception("CAPTACH configuration incomplete.", 3);
}

// Make sure SpammerSlapper is setup properly
if(
	//SpammerSlapper
	((bool)$settings['use_spammerslapper'] && 
	empty($settings['spammerslapper_key'])
	)
){
	throw new Exception("SpammerSlapper configuration incomplete.", 4);
}
}

function check_wallet($type){
	//Attempt to verify wallet 
	
	//Load Required Libraries (Yeah we need ALL this stuff)
	require_once("classes/wallet.interface.php");
	
	if($type == 'hot'){
		//Load Hot Wallet Libraries
		require_once("classes/jsonRPCClient.class.php");
		require_once("classes/hotwallet.class.php");
	}
	else{
		//Attempt to connect to database<commit_msg>Fix dumb error<commit_after><?php
//Instalation Related Functions

/*
* Creates or replaces the database configuration file
*
*/
function write_db_config($host, $name, $user, $pass, $prefix, $file){
$buffer = <<<EOF
<?php
define("DB_HOST", "$host");
define("DB_NAME", "$name");
define("DB_USER", "$user");
define("DB_PASS", "$<PASSWORD>");
define("TB_PRFX", "$prefix");
?>
EOF;
if (!file_put_contents($file, $buffer)){throw new Exception("Could not wrtite configuration.", 2);}
}

/*
* Creates or replaces the wallet configuration file
*
*/
function write_wallet_config($type, $host, $port, $user, $pass, $address_version, $coldwallet_file, $encr, $file){
//Hot or Cold Wallet
if($type == 'cold'){$host = ""; $port = "";}

//Clean up the variables a bit
if(!strcmp($host,"1. RPC Server (default - localhost)")){$host = "localhost";}
if(!strcmp($user,"2. RPC Username.")){$user = "";}
if(!strcmp($pass,"3. RPC Password.")){$pass = "";}
if(!strcmp($port,"4. RPC Port")){$port = "";}
if(!strcmp($address_version,"5. Address Version")){$address_version = "";}
if(!strcmp($encr,"7. If wallet encrypted, Enter PASS")){$encr = "";}
if(!strcmp($coldwallet_file,"6. Cold Wallet Datafile")){$coldwallet_file = "";}

$buffer = <<<EOF
<?php
define("ADDRESS_VERSION", "$address_version"); // Found in src/base58.h:CBitcoinAddress.PUBKEY_ADDRESS

//Hot Wallet Authetication Info
//The cold wallet also has a username/password component that's used by the push/pull client and server
define("PAYMENT_GW_RPC_USER", "$user");
define("PAYMENT_GW_RPC_PASS", "$pass");

//For cold Wallet
define("PAYMENT_GW_DATAFILE", "$coldwallet_file");

//For Hot Wallet - Leave PAYMENT_GW_RPC_HOST empty to use Cold Wallet
define("PAYMENT_GW_RPC_HOST", "$host");
define("PAYMENT_GW_RPC_PORT", "$port");
// If the wallet is encrypted, enter the PASSPHRASE here. Leave it blank otherwise!
define("PAYMENT_GW_RPC_ENCR", "$encr");
?>
EOF;
if (!file_put_contents($file, $buffer)){throw new Exception("Could not wrtite configuration.", 2);}

//Make sure we have what we need
if(empty($coldwallet_file) && $type == 'cold'){throw new Exception("No Datafile");}
if(empty($port) && $type == 'hot'){throw new Exception("No Port Given");}
if($type == 'cold' && (empty($user) || empty($pass))){throw new Exception("Cold wallet needs user and password");}
}


/*
* Creates or replaces the faucet configuration file
*
*/
function write_faucet_config($settings,  $file){
//Clean up the format of some variables
$settings['use_promo_codes'] = $settings['use_promo_codes'] == true ? 'true' : 'false';
$settings['captcha'] = $settings['use_captcha'] == 'false' ? '' : $settings['use_captcha'];
$settings['use_captcha'] = $settings['use_captcha'] == 'false' ? 'false' : 'true';
$settings['use_spammerslapper'] = $settings['use_spammerslapper'] ? 'true' : 'false';

$buffer = <<<EOF
<?php
// Modify these settings to suit your needs.
\$config = array(
	"mysql_table_prefix" => TB_PRFX, // table prefix to use

	"minimum_payout" => {$settings['minimum_payout']}, // minimum to be awarded
	"maximum_payout" => {$settings['maximum_payout']}, // maximum to be awarded
	"payout_threshold" => {$settings['payout_threshold']}, // payout threshold, if the faucet contains less than this, display the 'dry_faucet' message
	"payout_interval" => "{$settings['payout_interval']}", // payout interval, the wait time for a user between payouts. Type any numerical value with either a "m" (minutes), "h" (hours), or "d" (days), attached. Examples: 50m for a 50 minute delay, 7h for a 7 hour delay, etc.

	// this option has 3 possible values: "ip_address", "wallet_address", and "both". It defines what to check for when a user enters an address in order to decide whether or not to award to this user.
	// "ip_address": checks the user IP address in the payout history.
	// "wallet_address": checks the wallet address in the payout history.
	// "both": check both the IP and wallet address in the payout history.
	"user_check" => "{$settings['user_check']}",

	"use_captcha" => {$settings['use_captcha']}, // require the user to enter a captcha
	"use_spammerslapper" => {$settings['use_spammerslapper']}, // Prevent The use of Proxies and check the IP against Blacklists

	"captcha" => "{$settings['captcha']}", // which CAPTCHA to use, possible values are: "recaptcha", "solvemedia", and "simple-captcha".

	"captcha_config" => array(
		//Simple Captcha Session Name
		"simple_captcha_session_name" => "{$settings['captcha_config']['simple_captcha_session_name']}",
		// if you're using reCAPTCHA, enter your private and public keys here:
		"recpatcha_private_key" => "{$settings['captcha_config']['recpatcha_private_key']}",
		"recpatcha_public_key" => "{$settings['captcha_config']['recpatcha_public_key']}",
		// if you're using Solve MEDIA, enter your private, challenge, and hash keys here:
		"solvemedia_private_key" => "{$settings['captcha_config']['solvemedia_private_key']}",
		"solvemedia_challenge_key" => "{$settings['captcha_config']['solvemedia_challenge_key']}",
		"solvemedia_hash_key" => "{$settings['captcha_config']['solvemedia_hash_key']}",
	),

	"spammerslapper_key" => "{$settings['spammerslapper_key']}", // SpammerSlapper API key.

	// promo codes:
	"use_promo_codes" => {$settings['use_promo_codes']}, // accept promo codes

	// Donation address:
	"donation_address" => "{$settings['donation_address']}", // donation address to display

	// Faucet look and feel:
	"title" => "{$settings['title']}", // page title, may be used by the template too
	"sitename" => "{$settings['sitename']}", // page title, may be used by the template too
	"sitedesc" => "{$settings['sitedesc']}", // page title, may be used by the template too
	"coin_code" => "{$settings['coin_code']}",
	"template" => "{$settings['template']}", // template to use (see the templates directory)
	"lang" => "{$settings['lang']}",
);
?>
EOF;

if (!file_put_contents($file, $buffer)){throw new Exception("Could not wrtite configuration.", 2);}

//Validate some settings
//CAPTCHA - Yeah, it's complicated

//Normalize Variables
$settings['captcha_config']['solvemedia_private_key'] = $settings['captcha_config']['solvemedia_private_key'] == 'PRIVATE_KEY_HERE' ? '' : $settings['captcha_config']['solvemedia_private_key'];
$settings['captcha_config']['solvemedia_challenge_key'] = $settings['captcha_config']['solvemedia_challenge_key'] == 'CHALLENGE_KEY_HERE' ? '' : $settings['captcha_config']['solvemedia_challenge_key'];
$settings['captcha_config']['solvemedia_hash_key'] = $settings['captcha_config']['solvemedia_hash_key'] == 'HASH_KEY_HERE' ? '' : $settings['captcha_config']['solvemedia_hash_key'];
$settings['captcha_config']['recpatcha_private_key'] = $settings['captcha_config']['recpatcha_private_key'] == 'PRIVATE_KEY_HERE' ? '' : $settings['captcha_config']['recpatcha_private_key'];
$settings['captcha_config']['recpatcha_public_key'] = $settings['captcha_config']['recpatcha_public_key'] == 'PUBLIC_KEY_HERE' ? '' : $settings['captcha_config']['recpatcha_public_key'];

//Ensure we have the required settings
if(
	//Solve Media
	($settings['captcha'] == 'solvemedia' && 
	(empty($settings['captcha_config']['solvemedia_private_key']) ||
	empty($settings['captcha_config']['solvemedia_challenge_key']) ||
	empty($settings['captcha_config']['solvemedia_hash_key']))
	) ||
	//re-CAPTCHA
	($settings['captcha'] == 'recaptcha' && 
	(empty($settings['captcha_config']['recpatcha_private_key']) ||
	empty($settings['captcha_config']['recpatcha_public_key']))
	) ||
	//Simple Captcha
	($settings['captcha'] == 'simple-captcha' && 
	empty($settings['captcha_config']['simple_captcha_session_name'])
	)
){
	throw new Exception("CAPTACH configuration incomplete.", 3);
}

// Make sure SpammerSlapper is setup properly
if(
	//SpammerSlapper
	($settings['use_spammerslapper'] == 'true' && 
	empty($settings['spammerslapper_key'])
	)
){
	throw new Exception("SpammerSlapper configuration incomplete.", 4);
}
}

function check_wallet($type){
	//Attempt to verify wallet 
	
	//Load Required Libraries (Yeah we need ALL this stuff)
	require_once("classes/wallet.interface.php");
	
	if($type == 'hot'){
		//Load Hot Wallet Libraries
		require_once("classes/jsonRPCClient.class.php");
		require_once("classes/hotwallet.class.php");
	}
	else{
		//Attempt to connect to database
{'fraction_non_alphanumeric': 0.17880195451529227, 'fraction_numerical': 0.0025336309344272186, 'mean_word_length': 6.573321151210599, 'pattern_counts': {'":': 6, '<': 31, '<?xml version=': 0, '>': 61, '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': '5085528', 'n_tokens_mistral': 5623, 'n_tokens_neox': 5340, 'n_words': 1314}