Fixed some folder structures and worked on ban retrieval
This commit is contained in:
parent
e1176ec4ee
commit
ecbd2fd94a
@ -12,7 +12,7 @@ use DataAccess\CategoryGateway;
|
||||
|
||||
class CategoryRetriever {
|
||||
static function get_all_categories($hesk_settings) {
|
||||
require_once(__DIR__ . '/../../dao/CategoryGateway.php');
|
||||
require_once(__DIR__ . '/../../dao/category/CategoryGateway.php');
|
||||
|
||||
return CategoryGateway::getAllCategories($hesk_settings);
|
||||
}
|
||||
|
46
api/businesslogic/security/BanRetriever.php
Normal file
46
api/businesslogic/security/BanRetriever.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace BusinessLogic\Security;
|
||||
|
||||
|
||||
use DataAccess\Security\BanGateway;
|
||||
|
||||
class BanRetriever {
|
||||
/**
|
||||
* @param $email
|
||||
* @param $heskSettings
|
||||
* @return bool
|
||||
*/
|
||||
static function isEmailBanned($email, $heskSettings) {
|
||||
require_once(__DIR__ . '/../../dao/security/BanGateway.php');
|
||||
|
||||
$bannedEmails = BanGateway::getEmailBans($heskSettings);
|
||||
|
||||
foreach ($bannedEmails as $bannedEmail) {
|
||||
if ($bannedEmail->email === $email) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ip int the IP address, converted beforehand using ip2long()
|
||||
* @param $heskSettings
|
||||
* @return bool
|
||||
*/
|
||||
static function isIpAddressBanned($ip, $heskSettings) {
|
||||
require_once(__DIR__ . '/../../dao/security/BanGateway.php');
|
||||
|
||||
$bannedIps = BanGateway::getIpBans($heskSettings);
|
||||
|
||||
foreach ($bannedIps as $bannedIp) {
|
||||
if ($bannedIp->ipFrom <= $ip && $bannedIp->ipTo >= $ip) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
32
api/businesslogic/security/BannedEmail.php
Normal file
32
api/businesslogic/security/BannedEmail.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 1/27/2017
|
||||
* Time: 9:25 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Security;
|
||||
|
||||
|
||||
class BannedEmail {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $email;
|
||||
|
||||
/**
|
||||
* @var int|null The user who banned the email, or null if the user was deleted
|
||||
*/
|
||||
public $bannedById;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $dateBanned;
|
||||
}
|
42
api/businesslogic/security/BannedIp.php
Normal file
42
api/businesslogic/security/BannedIp.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 1/27/2017
|
||||
* Time: 9:51 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Security;
|
||||
|
||||
|
||||
class BannedIp {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var int the lower bound of the IP address range
|
||||
*/
|
||||
public $ipFrom;
|
||||
|
||||
/**
|
||||
* @var int the upper bound of the IP address range
|
||||
*/
|
||||
public $ipTo;
|
||||
|
||||
/**
|
||||
* @var string the display of the IP ban to be shown to the user
|
||||
*/
|
||||
public $ipDisplay;
|
||||
|
||||
/**
|
||||
* @var int|null The user who banned the IP, or null if the user was deleted
|
||||
*/
|
||||
public $bannedById;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $dateBanned;
|
||||
}
|
@ -3,12 +3,14 @@
|
||||
namespace BusinessLogic\Security;
|
||||
|
||||
|
||||
use DataAccess\Security\UserDao;
|
||||
use DataAccess\Security\UserGateway;
|
||||
|
||||
class UserContextBuilder {
|
||||
static function buildUserContext($authToken, $hesk_settings) {
|
||||
require_once(__DIR__ . '/../../dao/security/UserGateway.php');
|
||||
|
||||
$hashedToken = hash('sha512', $authToken);
|
||||
return UserDao::getUserForAuthToken($hashedToken, $hesk_settings);
|
||||
return UserGateway::getUserForAuthToken($hashedToken, $hesk_settings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ class TicketCreator {
|
||||
*/
|
||||
function validate($ticketRequest, $staff, $heskSettings, $modsForHeskSettings) {
|
||||
require_once(__DIR__ . '/../email_validators.php');
|
||||
require_once(__DIR__ . '/../../dao/category_dao.php');
|
||||
require_once(__DIR__ . '/../category/CategoryRetriever.php');
|
||||
//require_once('../category/retriever.php');
|
||||
//require_once('../bans/retriever.php');
|
||||
|
||||
@ -73,7 +73,6 @@ class TicketCreator {
|
||||
}
|
||||
|
||||
foreach ($heskSettings['custom_fields'] as $key => $value) {
|
||||
// TODO Only check categories that apply to this custom field
|
||||
if ($value['use'] == 1 && hesk_is_custom_field_in_category($key, intval($ticketRequest->category))) {
|
||||
$custom_field_value = $ticketRequest->customFields[$key];
|
||||
if (empty($custom_field_value)) {
|
||||
|
@ -13,7 +13,7 @@ use Exception;
|
||||
|
||||
class CategoryGateway {
|
||||
static function getAllCategories($hesk_settings) {
|
||||
require_once(__DIR__ . '/../businesslogic/category/Category.php');
|
||||
require_once(__DIR__ . '/../../businesslogic/category/Category.php');
|
||||
|
||||
if (!function_exists('hesk_dbConnect')) {
|
||||
throw new Exception('Database not loaded!');
|
77
api/dao/security/BanGateway.php
Normal file
77
api/dao/security/BanGateway.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 1/27/2017
|
||||
* Time: 9:05 PM
|
||||
*/
|
||||
|
||||
namespace DataAccess\Security;
|
||||
|
||||
|
||||
use BusinessLogic\Security\BannedEmail;
|
||||
use BusinessLogic\Security\BannedIp;
|
||||
|
||||
class BanGateway {
|
||||
|
||||
/**
|
||||
* @param $heskSettings
|
||||
* @return BannedEmail[]
|
||||
*/
|
||||
static function getEmailBans($heskSettings) {
|
||||
require_once(__DIR__ . '/../../businesslogic/security/BannedEmail.php');
|
||||
|
||||
$rs = hesk_dbQuery("SELECT `bans`.`id` AS `id`, `bans`.`email` AS `email`,
|
||||
`users`.`id` AS `banned_by`, `bans`.`dt` AS `dt`
|
||||
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "_banned_emails` AS `bans`
|
||||
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "_users` AS `users`
|
||||
ON `bans`.`banned_by` = `users`.`id`
|
||||
AND `users`.`active` = '1'");
|
||||
|
||||
$bannedEmails = array();
|
||||
|
||||
while ($row = hesk_dbFetchAssoc($rs)) {
|
||||
$bannedEmail = new BannedEmail();
|
||||
$bannedEmail->id = intval($row['id']);
|
||||
$bannedEmail->email = $row['email'];
|
||||
$bannedEmail->bannedById = $row['banned_by'] === null ? null : intval($row['banned_by']);
|
||||
$bannedEmail->dateBanned = $row['dt'];
|
||||
|
||||
$bannedEmails[$bannedEmail->id] = $bannedEmail;
|
||||
}
|
||||
|
||||
return $bannedEmails;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $heskSettings
|
||||
* @return BannedIp[]
|
||||
*/
|
||||
static function getIpBans($heskSettings) {
|
||||
require_once(__DIR__ . '/../../businesslogic/security/BannedIp.php');
|
||||
|
||||
$rs = hesk_dbQuery("SELECT `bans`.`id` AS `id`, `bans`.`ip_from` AS `ip_from`,
|
||||
`bans`.`ip_to` AS `ip_to`, `bans`.`ip_display` AS `ip_display`,
|
||||
`users`.`id` AS `banned_by`, `bans`.`dt` AS `dt`
|
||||
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "_banned_ips` AS `bans`
|
||||
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "_users` AS `users`
|
||||
ON `bans`.`banned_by` = `users`.`id`
|
||||
AND `users`.`active` = '1'");
|
||||
|
||||
$bannedIps = array();
|
||||
|
||||
while ($row = hesk_dbFetchAssoc($rs)) {
|
||||
$bannedIp = new BannedIp();
|
||||
$bannedIp->id = intval($row['id']);
|
||||
$bannedIp->ipFrom = intval($row['ip_from']);
|
||||
$bannedIp->ipTo = intval($row['ip_to']);
|
||||
$bannedIp->ipDisplay = $row['ip_display'];
|
||||
$bannedIp->bannedById = $row['banned_by'] === null ? null : intval($row['banned_by']);
|
||||
$bannedIp->dateBanned = $row['dt'];
|
||||
|
||||
$bannedIps[$bannedIp->id] = $bannedIp;
|
||||
}
|
||||
|
||||
return $bannedIps;
|
||||
}
|
||||
}
|
@ -12,9 +12,9 @@ namespace DataAccess\Security;
|
||||
use BusinessLogic\Security\UserContextBuilder;
|
||||
use Exception;
|
||||
|
||||
class UserDao {
|
||||
class UserGateway {
|
||||
static function getUserForAuthToken($hashedToken, $hesk_settings) {
|
||||
require_once(__DIR__ . '/../businesslogic/security/UserContextBuilder.php');
|
||||
require_once(__DIR__ . '/../../businesslogic/security/UserContextBuilder.php');
|
||||
|
||||
if (!function_exists('hesk_dbConnect')) {
|
||||
throw new Exception('Database not loaded!');
|
Loading…
x
Reference in New Issue
Block a user