diff --git a/install/migrations/core.php b/install/migrations/core.php index aadf0b09..864377ff 100644 --- a/install/migrations/core.php +++ b/install/migrations/core.php @@ -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(), ); } \ No newline at end of file diff --git a/install/migrations/v200/MigrateIpAndEmailBans.php b/install/migrations/v200/MigrateIpAndEmailBans.php new file mode 100644 index 00000000..5d2f1534 --- /dev/null +++ b/install/migrations/v200/MigrateIpAndEmailBans.php @@ -0,0 +1,53 @@ +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`"); + } +} \ No newline at end of file diff --git a/install/mods-for-hesk/sql/installSql.php b/install/mods-for-hesk/sql/installSql.php index 5345902b..46a95982 100644 --- a/install/mods-for-hesk/sql/installSql.php +++ b/install/mods-for-hesk/sql/installSql.php @@ -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() {