<?php
// главная страница админки
if(!defined('ANTIBOT')) die('access denied');

$title = abTranslate('Home');

if ($ab_config['ip'] == '127.0.0.1') {
$content .= '<div class="alert alert-danger" role="alert">'.abTranslate('Your IP address is 127.0.0.1, there is likely a problem with correctly determining your IP.').'</div>';
}

if ($ab_config['ip'] == $_SERVER['SERVER_ADDR']) {
$content .= '<div class="alert alert-danger" role="alert">'.abTranslate('Your IP address is the same as the website server\'s IP address, there may be an issue with correctly identifying your IP.').'</div>';
}

$size = filesize(__DIR__.'/../data/sqlite.db');
if ($ab_config['secondpass'] == '') {
$content .= '<div class="alert alert-danger" role="alert">'.abTranslate('You do not have an Second Password set up.').' <a href="?'.$abw.$abp.'=conf#secondpass">'.abTranslate('Set password.').'</a> '.abTranslate('This will reduce the risk of the AntiBot control panel being hacked.').'</div>';
}
if (!file_exists(__DIR__.'/../data/cronlog')) {
$content .= '<div class="alert alert-danger" role="alert">'.abTranslate('Set up a CRON job to automatically delete old records from the log and cache:').'<br />
<code>0 1 * * * /usr/bin/php -q '.dirname(dirname(__FILE__)).'/code/clear_old_hits.php > /dev/null 2>&1</code>
<br /><small>'.abTranslate('Please check with your hosting provider on how to run PHP scripts via Cron.').'</small></div>';
}
$content .= '
<span id="warning"></span>
<span id="auth_msg"></span>
<!-- новости -->
<span id="other_ab_msg"></span>
<div id="new_version_msg" class="alert alert-success" role="alert" style="display:none">'.abTranslate('A new version of Antibot is available. To update, please go to the following page:').' <a href="?'.$abw.$abp.'=update">'.abTranslate('Update').'</a></div>
<p><div class="fflag fflag-'.$ab_config['country'].' ff-md" title="'.$ab_config['country'].'"></div> <strong>'.$ab_config['ip'].'</strong> - '.abTranslate('Is this your IP?').' <a href="?'.$abw.$abp.'=proxy">'.abTranslate('If not, it needs to be configured.').'</a> [<a href="?'.$abw.$abp.'=authlog">'.abTranslate('Authorization Log').'</a>]</p>
';
if(function_exists('sys_getloadavg')) {
$content .= '<p>Load average: ';
foreach(sys_getloadavg() as $la) {$content .= round($la, 2).' ';}
$content .= '</p>';
}

$content .= '<p>'.abTranslate('Database file size:').' sqlite.db: '.round($size / 1024 / 1024, 2).' MiB [<a href="?'.$abw.$abp.'=backup">'.abTranslate('Backup').'</a>]</p>
<hr />
';
// кол-во записей в ptr логе:
$ptrcache_count = $antibot_db->querySingle("SELECT count(ip) FROM ptrcache;");
$ptrcache_count = (string)$ptrcache_count;
$content .= '<p>'.abTranslate('Number of entries in the PTR cache:').' '.$ptrcache_count.'
<form id="clear_ptr_all" action="?'.$abw.$abp.'=clearptr" method="post" style="display: inline-block;" onsubmit="return check()">
<input name="time" type="hidden" value="all">
<input name="clearptr_submit" type="hidden" value="1">
<span style="cursor:pointer;" class="badge badge-danger" onclick="document.getElementById(\'clear_ptr_all\').submit();">'.abTranslate('Delete all records').'</span>
</form>
<form id="clear_ptr_conf" action="?'.$abw.$abp.'=clearptr" method="post" style="display: inline-block;" onsubmit="return check()">
<input name="time" type="hidden" value="conf">
<input name="clearptr_submit" type="hidden" value="1">
<span style="cursor:pointer;" class="badge badge-danger" onclick="document.getElementById(\'clear_ptr_conf\').submit();">'.abTranslate('Delete older than (days):').' '.$ab_config['ptrcache_time'].'</span>
</form>
</p>
<hr />
';

if (file_exists(__DIR__.'/../data/errorlog.txt')) {
$phperrorsize = filesize(__DIR__.'/../data/errorlog.txt');
$content .= '<p class="text-danger">PHP error log: '.abTranslate('file size').' '.round($phperrorsize / 1024 / 1024, 2).' MiB - '.abTranslate('We have problems!').'</p>';
if ($phperrorsize < 1500) {$indent = 0;} else {$indent = $phperrorsize - 1500;}
$handle = fopen(__DIR__.'/../data/errorlog.txt', "r");
fseek($handle, $indent);
$last_lines = fread($handle, 1500);
fclose($handle);
$last_lines = explode("\n", $last_lines, 2);
if (count($last_lines) > 3) {unset($last_lines[0]);}
$last_lines = implode("\n", $last_lines);
$content .= '<pre>'.htmlentities($last_lines).'</pre>
<small class="form-text text-muted">'.abTranslate('These are the last 1500 bytes of the log, there may be additional lines. The entire log is located in the file data/errorlog.txt').'</small>
<form id="removephperrorlog" action="?'.$abw.$abp.'=removephperrorlog" method="post" onsubmit="return check()">
<input name="removephperrorlog_submit" type="hidden" value="1">
<span style="cursor:pointer;" class="badge badge-danger" onclick="document.getElementById(\'removephperrorlog\').submit();">'.abTranslate('Delete log file').'</span>
</form>
';
} else {
$content .= '<p class="text-success">PHP error log: '.abTranslate('The file does not exist and that\'s a good thing!').'</p>';
}

$content .= '<hr />
<p>Last cron log:</p>
<pre>'.@file_get_contents(__DIR__.'/../data/cronlog').'</pre>
<hr />
';
$content .= '<script>var current_version = '.$ab_version.';</script>
<script src="https://antibot.cloud/version8.php?h1='.hash('sha256', $ab_config['email'].$ab_config['pass'].$ab_config['useragent'].$ab_config['accept_lang'].$ab_config['time']).'&h2='.md5('Antibot:'.$ab_config['email']).'&date='.$ab_config['time'].'&v='.$ab_version.'&lang='.$lang_code.'" async></script>

<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 2 && this.status == 200) {
document.getElementById("warning").innerHTML = "<div class=\"alert alert-danger\"><a href=\"data/sqlite.db\" target=\"_blank\">data/sqlite.db</a> - '.abTranslate('The SQLite3 database file has a server response code of 200. It may be available for download, which is unsafe since the database may contain confidential information. Protect the database file from web access.').' <a href=\"https://antibot.cloud/FAQ.php?page=nginx-php-fpm&lang='.$lang_code.'\" target=\"_blank\" rel=\"noopener\">'.abTranslate('Protecting directories using NGINX.').'</a></div>";
}
};
xmlhttp.timeout = 1000;
xmlhttp.open("GET", "data/sqlite.db", true);
xmlhttp.send();
</script>
';
