<?php 
session_start();
require('../module/controller.php');
if($_GET['route'] == "update"){
	if(isset($_SESSION['granted']) == false){
		header("location: login");
	}
	$file = fopen("../files/config/config.json", "w") or die("no");
	fwrite($file, json_encode($_POST, JSON_PRETTY_PRINT));
	fclose($file);
	die("ok");
}

if($_GET['route'] == "signin"){
	$json = json_decode(file_get_contents('../files/config/config.json'), true);
	if($_POST['username'] == $json['username_panel'] && $_POST['password'] == $json['password_panel']){
		$_SESSION['granted'] = true;
		die("ok");
	}else{
		die("no");
	}
}
if($_GET['route'] == "logout"){
	unset($_SESSION['granted']);
	header("location: login");
}

if($_GET['route'] == "clearbot"){
	if(isset($_SESSION['granted']) == false){
		header("location: login");
	}
	clearLogs('bot');
	die("ok");
}

if($_GET['route'] == "clearvisitor"){
	if(isset($_SESSION['granted']) == false){
		header("location: login");
	}
	clearLogs('visitor');
	die("ok");
}

if($_GET['route'] == "clearall"){
	if(isset($_SESSION['granted']) == false){
		header("location: login");
	}
	clearLogs('visitor');
	clearLogs('click');
	clearLogs('login');
	clearLogs('document');
	clearLogs('bot');
	clearLogs('email');
	die("ok");
}