More migrations
This commit is contained in:
parent
92713506e6
commit
f54c9bbd03
@ -33,7 +33,7 @@ function getAllMigrations() {
|
||||
22 => new \v200\RemoveEditInfoFromNotes(),
|
||||
23 => new \v200\RemoveDefaultNotifyCustomerEmailPreference(),
|
||||
24 => new \v200\AddMissingKeyToTickets(),
|
||||
25 => new \v200\UpdateVersion(),
|
||||
|
||||
25 => new \v200\MigrateIpAndEmailBans(),
|
||||
26 => new \v200\UpdateVersion(),
|
||||
);
|
||||
}
|
53
install/migrations/v200/MigrateIpAndEmailBans.php
Normal file
53
install/migrations/v200/MigrateIpAndEmailBans.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace v200;
|
||||
|
||||
|
||||
class MigrateIpAndEmailBans extends \AbstractMigration {
|
||||
|
||||
function up($hesk_settings) {
|
||||
// Insert the email bans
|
||||
$emailBanRS = executeQuery("SELECT `Email` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails`");
|
||||
while ($row = hesk_dbFetchAssoc($emailBanRS)) {
|
||||
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_emails` (`email`, `banned_by`, `dt`)
|
||||
VALUES ('" . hesk_dbEscape($row['Email']) . "', 1, NOW())");
|
||||
}
|
||||
|
||||
// Insert the IP bans
|
||||
$ipBanRS = executeQuery("SELECT `RangeStart`, `RangeEnd` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips`");
|
||||
while ($row = hesk_dbFetchAssoc($ipBanRS)) {
|
||||
$ipFrom = long2ip($row['RangeStart']);
|
||||
$ipTo = long2ip($row['RangeEnd']);
|
||||
$ipDisplay = $ipFrom == $ipTo ? $ipFrom : $ipFrom . ' - ' . $ipTo;
|
||||
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_ips` (`ip_from`, `ip_to`, `ip_display`, `banned_by`, `dt`)
|
||||
VALUES (" . $row['RangeStart'] . ", " . $row['RangeEnd'] . ", '" . $ipDisplay . "', 1, NOW())");
|
||||
}
|
||||
// Migration Complete. Drop Tables.
|
||||
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips`");
|
||||
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails`");
|
||||
}
|
||||
|
||||
function down($hesk_settings) {
|
||||
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips` (
|
||||
`ID` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`RangeStart` VARCHAR(100) NOT NULL,
|
||||
`RangeEnd` VARCHAR(100) NOT NULL)");
|
||||
|
||||
$this->executeQuery("CREATE TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails` (
|
||||
ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
Email VARCHAR(100) NOT NULL);");
|
||||
|
||||
$emails = $this->executeQuery("SELECT `email` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_emails`");
|
||||
while ($row = hesk_dbFetchAssoc($emails)) {
|
||||
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails` (Email) VALUES ('" . hesk_dbEscape($row['email']) . "')");
|
||||
}
|
||||
|
||||
$ips = $this->executeQuery("SELECT `ip_from`, `ip_to` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_ips`");
|
||||
while ($row = hesk_dbFetchAssoc($ips)) {
|
||||
$this->executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips` (`RangeStart`, `RangeEnd`) VALUES (" . $row['ip_from'] . ", " . $row['ip_to'] . ")");
|
||||
}
|
||||
|
||||
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_ips`");
|
||||
$this->executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_emails`");
|
||||
}
|
||||
}
|
@ -37,60 +37,6 @@ function executeQuery($sql)
|
||||
}
|
||||
}
|
||||
|
||||
function checkForIpOrEmailBans()
|
||||
{
|
||||
global $hesk_settings;
|
||||
|
||||
hesk_dbConnect();
|
||||
$banRS = executeQuery("SELECT `ID` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails`
|
||||
UNION ALL SELECT `ID` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips`");
|
||||
|
||||
return hesk_dbNumRows($banRS);
|
||||
}
|
||||
|
||||
function getUsers()
|
||||
{
|
||||
global $hesk_settings;
|
||||
|
||||
hesk_dbConnect();
|
||||
$users = array();
|
||||
$usersRS = executeQuery("SELECT `id`, `name` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `active` = '1' ORDER BY `name`");
|
||||
while ($row = hesk_dbFetchAssoc($usersRS)) {
|
||||
array_push($users, $row);
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
function migrateBans($creator)
|
||||
{
|
||||
global $hesk_settings;
|
||||
|
||||
hesk_dbConnect();
|
||||
|
||||
// Insert the email bans
|
||||
$emailBanRS = executeQuery("SELECT `Email` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails`");
|
||||
while ($row = hesk_dbFetchAssoc($emailBanRS)) {
|
||||
executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_emails` (`email`, `banned_by`, `dt`)
|
||||
VALUES ('" . hesk_dbEscape($row['Email']) . "', " . $creator . ", NOW())");
|
||||
}
|
||||
|
||||
// Insert the IP bans
|
||||
$ipBanRS = executeQuery("SELECT `RangeStart`, `RangeEnd` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips`");
|
||||
while ($row = hesk_dbFetchAssoc($ipBanRS)) {
|
||||
$ipFrom = long2ip($row['RangeStart']);
|
||||
$ipTo = long2ip($row['RangeEnd']);
|
||||
$ipDisplay = $ipFrom == $ipTo ? $ipFrom : $ipFrom . ' - ' . $ipTo;
|
||||
executeQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "banned_ips` (`ip_from`, `ip_to`, `ip_display`, `banned_by`, `dt`)
|
||||
VALUES (" . $row['RangeStart'] . ", " . $row['RangeEnd'] . ", '" . $ipDisplay . "', " . $creator . ", NOW())");
|
||||
}
|
||||
// Migration Complete. Drop Tables.
|
||||
executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_ips`");
|
||||
executeQuery("DROP TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "denied_emails`");
|
||||
}
|
||||
|
||||
// END Version 2.0.0
|
||||
|
||||
// Version 2.0.1
|
||||
function execute201Scripts()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user