191 lines
4.9 KiB
PHP
191 lines
4.9 KiB
PHP
<?php
|
|
// https://www.daprogs.com/api/ipban199/blacklist.php?a=add&ip=192.168.2.0/24&type=1&date=20191025120000&reason=Hello%20There2
|
|
// https://www.daprogs.com/api/ipban199/blacklist.php?a=rem&ip=192.168.2.0/24
|
|
|
|
include('conn.php');
|
|
/*
|
|
if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) {
|
|
//return true;
|
|
$ht=true;
|
|
}
|
|
else {
|
|
echo "Service only available via https!";
|
|
die();
|
|
}
|
|
*/
|
|
$SQL2 ="SELECT info.last FROM info WHERE info.list = 0";
|
|
$result2 = mysqli_query($con,$SQL2);
|
|
$UpdateDate2 = mysqli_fetch_array($result2);
|
|
$UpdateDate = $UpdateDate2['last'];
|
|
|
|
$dStamp = date_create_from_format ( 'YmdHis' , $UpdateDate );
|
|
$fStamp = $dStamp->format('D, d M Y H:i:s T');
|
|
|
|
$lMod = "Last-Modified: " . $fStamp;
|
|
header($lMod);
|
|
if($_SERVER['REQUEST_METHOD']=='HEAD') {
|
|
$con->close();
|
|
echo("Something to make php quit and return head..");
|
|
}
|
|
|
|
$dPart = date("YmdHis");
|
|
|
|
if(!isset($_GET["a"]))
|
|
{
|
|
$action = "display";
|
|
}
|
|
if(isset($_GET["a"]))
|
|
{
|
|
$action = strtolower($_GET["a"]);
|
|
}
|
|
|
|
if ($action == "display") {
|
|
|
|
//echo "; Expires: Sun, 29 Sep 2019 05:01:00 GMT";
|
|
//echo "\r\n";
|
|
|
|
$SQL ="SELECT blacklist.ip, blacklist.adddate, blacklist.reason FROM blacklist WHERE blacklist.adddate < ".$dPart." AND blacklist.enddate > ".$dPart." ORDER BY blacklist.ip ASC";
|
|
$result = mysqli_query($con,$SQL);
|
|
$num_rows = mysqli_num_rows($result);
|
|
|
|
header("Content-Type: text/plain");
|
|
|
|
echo "; https://www.home.daprogs.net/api/ipban199/blacklist.php";
|
|
echo "\r\n";
|
|
|
|
// echo "; DAProgs BlackList ".date("Y/m/d")." - (c) 2019 DAProgs.com";
|
|
echo "; DAProgs BlackList - (c) 2019 DAProgs.com";
|
|
echo "\r\n";
|
|
|
|
echo "; Last-Modified: ".$fStamp;
|
|
// echo "; Last-Modified: ".substr($UpdateDate,0,4)."/".substr($UpdateDate,4,2)."/".substr($UpdateDate,6,2)." ".substr($UpdateDate,8,2).":".substr($UpdateDate,10,2).":".substr($UpdateDate,12,2)." EST.";
|
|
echo "\r\n";
|
|
|
|
echo "; Blacklist contains ".$num_rows." elements.";
|
|
echo "\r\n";
|
|
|
|
while($row = mysqli_fetch_array($result))
|
|
{
|
|
echo $row['ip']." ; ".$row['reason']." - ".substr($row['adddate'],0,4)."/".substr($row['adddate'],4,2)."/".substr($row['adddate'],6,2)."";
|
|
echo "\r\n";
|
|
//echo $row['ip'];
|
|
//echo "\r\n";
|
|
}
|
|
mysqli_close($con);
|
|
|
|
//echo "";
|
|
//echo "\r\n";
|
|
}
|
|
elseif ($action == "add") {
|
|
if(!isset($_GET["ip"]))
|
|
{
|
|
die("Missing parameters 1.");
|
|
}
|
|
$ip = strtolower($_GET["ip"]);
|
|
|
|
if(!isset($_GET["type"]))
|
|
{
|
|
die("Missing parameters 2.");
|
|
}
|
|
$type = $_GET["type"];
|
|
|
|
if(!isset($_GET["date"]))
|
|
{
|
|
die("Missing parameters 3.");
|
|
}
|
|
$enddate = $_GET["date"];
|
|
|
|
if(!isset($_GET["reason"]))
|
|
{
|
|
die("Missing parameters 4.");
|
|
}
|
|
$reason = urldecode($_GET["reason"]);
|
|
|
|
$SQL = "INSERT INTO blacklist (ip, type, adddate, enddate, reason) VALUES ('".$ip."', ".$type.", ".$dPart.", ".$enddate.", '".$reason."') ON DUPLICATE KEY UPDATE enddate=".$enddate.", type=".$type.", reason='".$reason."'";
|
|
|
|
if ($con->query($SQL) === TRUE) {
|
|
$SQL = "UPDATE info SET last=".$dPart." WHERE list=0;";
|
|
$con->query($SQL);
|
|
if ($con->affected_rows == 1) {
|
|
echo "SUCCESS";
|
|
} else {
|
|
echo "SUCCESS UPDATE";
|
|
}
|
|
} else {
|
|
echo "Error: " . $SQL . "<br>" . $con->error;
|
|
}
|
|
|
|
|
|
$con->close();
|
|
}
|
|
elseif ($action == "log") {
|
|
|
|
//'50.238.150.110 [1C28] 09:12:06 Authentication [IMAP] - Result=1 User=miniservice@theautomaster.com Method=4
|
|
//'0 1 2 3 4 5 6 7 8
|
|
|
|
// time
|
|
// ip
|
|
// type
|
|
// sf
|
|
// account
|
|
|
|
if(!isset($_GET["ip"]))
|
|
{
|
|
die("Missing parameters 1.");
|
|
}
|
|
$ip = strtolower($_GET["ip"]);
|
|
|
|
if(!isset($_GET["date"]))
|
|
{
|
|
die("Missing parameters 2.");
|
|
}
|
|
$datetime = $_GET["date"];
|
|
|
|
if(!isset($_GET["sf"]))
|
|
{
|
|
die("Missing parameters 3.");
|
|
}
|
|
$sf = $_GET["sf"];
|
|
|
|
if(!isset($_GET["type"]))
|
|
{
|
|
die("Missing parameters 4.");
|
|
}
|
|
$logtype = $_GET["type"];
|
|
|
|
if(!isset($_GET["account"]))
|
|
{
|
|
die("Missing parameters 5.");
|
|
}
|
|
$account = urldecode($_GET["account"]);
|
|
|
|
$SQL ="INSERT INTO iplog (time, ip, type, sf, account) VALUES ('".$datetime."', '".$ip."', '".$logtype."', ".$sf.", '".$account."')";
|
|
|
|
if ($con->query($SQL) === TRUE) {
|
|
echo "SUCCESS";
|
|
} else {
|
|
echo "Error: " . $SQL . "<br>" . $con->error;
|
|
}
|
|
$con->close();
|
|
}
|
|
elseif ($action == "rem") {
|
|
if(!isset($_GET["ip"]))
|
|
{
|
|
die("Missing parameters 1.");
|
|
}
|
|
$ip = strtolower($_GET["ip"]);
|
|
|
|
$SQL ="DELETE FROM blacklist WHERE blacklist.ip = '".$ip."';";
|
|
|
|
if ($con->query($SQL) === TRUE) {
|
|
$SQL = "UPDATE info SET last=".$dPart." WHERE list=0;";
|
|
$con->query($SQL);
|
|
echo "SUCCESS";
|
|
} else {
|
|
echo "Error: " . $SQL . "<br>" . $con->error;
|
|
}
|
|
$con->close();
|
|
}
|
|
?>
|
|
|