<?php
session_start();
error_reporting(0);
$lis = $_GET['v'];	

If (!isset($_GET['v'])){    
	header("location:./");
	exit;
}

?>
<html lang="en">
  <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="Yanto Naim">

    <title>Instalasi Auto BiznisTop</title>

    <!-- Bootstrap core CSS -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
    
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    
    <link href="css/cssinstal.css" rel="stylesheet" type="text/css">

  </head>

  <body>
  <div class="container register">
    <div class="row">
    <div class="col-md-3 register-left">
        <img src="https://image.ibb.co/n7oTvU/logo_white.png" alt=""/>
        <h3>Konfigurasi Instalasi</h3>
        <p>Anda membutuhkan waktu kurang dari 5 menit untuk proses instalasi</p>
    </div>
	<div class="col-md-9 register-right">
	<div class="tab-content" id="myTabContent">
	        		
<?php
if (!file_exists('config.php')) {
	if (isset($_POST['dbname']) && isset($_POST['dbuser'])) {
		
		If(!empty($lis)){
			$content2 = '';
			$handle2 = fopen(md5($lis) .".php", "w+");
			if (fwrite($handle2, $content2) === FALSE) {}
			}
		
		$content = '<?php
		$weburl = "'.$_POST['weburl'].'";
		$dbhost     = "'.$_POST['dbhost'].'";
		$dbname = "'.$_POST['dbname'].'";
		$dbuser	  = "'.$_POST['dbuser'].'";
		$dbpassword = "'.$_POST['dbpassword'].'";
		
		$download ="Y";
		$versi ="20201103";
		
		$lisensi = "'.$_POST['lis'].'";
		
		$coder="PGZvb3RlciBjbGFzcz0ic3RpY2t5LWZvb3RlciI+DQogICAgICAgICAgPGRpdiBjbGFzcz0iY29udGFpbmVyIG15LWF1dG8iPg0KICAgICAgICAgICAgPGRpdiBjbGFzcz0iY29weXJpZ2h0IHRleHQtY2VudGVyIG15LWF1dG8iPg0KICAgICAgICAgICAgICA8c3Bhbj5Db3B5cmlnaHQgwqkgPGEgY2xhc3M9ImNoYW5nZSIgaHJlZj0iaHR0cHM6Ly9iaXpuaXMudG9wLyIgaWQ9ImNoYW5nZSIgdGl0bGU9IllhbnRvIE5haW0iPkF1dG8gQml6bmlzVG9wIDIwMTktMjAyMDwvYT48L3NwYW4+DQogICAgICAgICAgICA8L2Rpdj4NCiAgICAgICAgICA8L2Rpdj4NCiAgICAgICAgPC9mb290ZXI+DQogIA==";
		
		?>';
		$handle = fopen("config.php", "w+");
		if (fwrite($handle, $content) === FALSE) {
		    unlink("config.php");
		    echo '
		    <div class="row register-form">
		<div class="alert alert-success alert-dismissable" style="margin-top:20px">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h6><i class="icon glyphicon glyphicon-remove"></i> Lakukan instalasi kembali. <a href="./">KLIK DISINI</a>. Cek penulisan nama database, user database dan password database kembali.  
                </div> </div>';
			exit;
		}
		
		echo '
		<div class="row register-form">
		<div class="alert alert-success alert-dismissable" style="margin-top:20px">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h6><i class="icon glyphicon glyphicon-remove"></i> Klik <a href="install.php?v='.$lis.'">NEXT</a> ke proses instalasi
                </div> </div>';
				
	} else {
		function cekpageurl() {
			$pageURL = 'http';
			$parse = parse_url($_SERVER["REQUEST_URI"]);
			$path = $parse['path'];
			if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
				$pageURL .= "://";
			if (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] != "80") {
				$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$path;
				$jml = strlen($pageURL); 
				$pageURL = substr($pageURL, 0,$jml-11);
			} else {
				$pageURL .= $_SERVER["SERVER_NAME"].$path;
				$jml = strlen($pageURL); 
				$pageURL = substr($pageURL, 0,$jml-11);
			}    
		 	return $pageURL;
		}
		
		echo '
		 <h3 class="register-heading">Database</h3>
         <form action="" method="post">
            <div class="row register-form">
                <div class="col-md-6">
                <div class="form-group">
                <input type="text" name="weburl" value="'.cekpageurl().'" class="form-control" readonly/>
                </div>
                <div class="form-group">
                <input type="text" name="dbhost" value="localhost" class="form-control">
                </div>
                <div class="form-group">
                <input type="text" name="dbname" class="form-control" placeholder="Nama Database"/>
                </div>
                </div>
                                    
                <div class="col-md-6">
                <div class="form-group">
                <input type="text" name="dbuser" class="form-control" placeholder="User Database" />
                </div>
                <div class="form-group">
                <input type="password" name="dbpassword" class="form-control" placeholder="Password Database"/>
                </div>
                <input type="hidden" name="lis" value="'.$lis.'" />
                                        
                <input type="submit" class="btnRegister"  value="Next"/>
                </div>
                </div>
        </form>
		';
	}
	
} else {
		include('config.php');
		$con = mysqli_connect("$dbhost","$dbuser","$dbpassword","$dbname");
	if (mysqli_connect_errno()){  
	
	    unlink("config.php");
		echo '
		<div class="row register-form">
		<div class="alert alert-success alert-dismissable" style="margin-top:20px">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h6><i class="icon glyphicon glyphicon-remove"></i> Lakukan instalasi kembali. <a href="./">KLIK DISINI</a>. Cek penulisan nama database, user database dan password database kembali.  
                </div> 
        </div>        ';
	die ("");  
		
	}
	
	$url3 = 'https://app.biznis.top/install1.php?ver='.$lis;
    $json_url3 = $url3;
    $ch3 = curl_init ($json_url3);
    $options3 = array(
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => array('Content-type: application/json'),
    );
    curl_setopt_array ($ch3, $options3); 
    $result3 = curl_exec($ch3); 
    $decode3 = json_decode($result3, true);
    
    IF(isset($decode3['install1'])){
        foreach ($decode3['install1'] as $row) {
            $up = $row['install1'];
            $content = $up;
    		$handle = fopen("db.php", "w+");
    		if (fwrite($handle, $content) === FALSE) {}
        }
    } 
    include 'db.php';
    unlink("db.php");

		echo '
		<div class="row register-form">
		<div class="alert alert-success alert-dismissable" style="margin-top:20px">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h6><i class="icon glyphicon glyphicon-remove"></i> Instalasi Sukses Auto BiznisTop v3.0 update 20201103. Silahkan <a href="login/">login</a> User: admin, password: admin. Anda dapat mengganti user dan password standart tersebut.</div> </div>
        </div></div>';
}
?>
</div>
 </div>
</div>
</div>
</body>
</html>
<?php

?>