File size: 1.9Kb
<?php
namespace xenMade\ACPE\Util;
class Firewall
{
const IP_TYPE_V4 = 0x04;
const IP_TYPE_V6 = 0x06;
static public function getIpType($ip)
{
$status = null;
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
{
$status = self::IP_TYPE_V4;
}
elseif(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
{
$status = self::IP_TYPE_V6;
}
return $status;
}
static public function sendLoginAlertMail($input, $ip, $type, array $emails)
{
$params = [
'ip' => $ip,
'name' => (!empty($input['login']) ? $input['login'] : \XF::phrase('acpe_unknow')),
'hash' => (!empty($input['hash']) ? $input['hash'] : ''),
];
foreach($emails as $email)
{
\XF::app()->mailer()->newMail()
->setTo($email)
->setTemplate('acpe_firewall_email_' . $type, $params)
->send();
}
}
static public function logLogins($userId, $username, $status, $login, $ip)
{
if(!$ip)
{
return false;
}
$hash = '';
if(!$userId)
{
$userId = 0;
}
if($login == 'acp' && $status == 'success')
{
$hash = sha1(md5(\XF::$time . $ip . $userId . \XF::generateRandomString(256, true)));
}
if(utf8_strlen($username) > 50)
{
$username = substr($username, 0, 50);
}
\XF::db()->insert('xf_xenmade_acpe_login_log', [
'user_id' => $userId,
'username' => $username,
'status' => $status,
'login' => $login,
'dateline' => \XF::$time,
'hash' => $hash,
'ip' => $ip
]);
return $hash;
}
}