Enable multiple standard IPs

This commit is contained in:
Johannes Feichtner
2016-02-10 00:21:07 +01:00
parent d7ca3a0f1c
commit 32c32a7e7a
6 changed files with 60 additions and 37 deletions

View File

@@ -55,7 +55,7 @@ return array(
'settinggroup' => 'system',
'varname' => 'defaultip',
'type' => 'option',
'option_mode' => 'one',
'option_mode' => 'multiple',
'option_options_method' => 'getIpPortCombinations',
'default' => '',
'save_method' => 'storeSettingDefaultIp',

View File

@@ -913,10 +913,13 @@ if ($page == 'customers'
$domainid = Database::lastInsertId();
// set ip <-> domain connection
$defaultips = explode(',', Settings::Get('system.defaultip'));
foreach ($defaultips as $defaultip) {
$ins_stmt = Database::prepare("
INSERT INTO `".TABLE_DOMAINTOIP."` SET `id_domain` = :domainid, `id_ipandports` = :ipid"
INSERT INTO `" . TABLE_DOMAINTOIP . "` SET `id_domain` = :domainid, `id_ipandports` = :ipid"
);
Database::pexecute($ins_stmt, array('domainid' => $domainid, 'ipid' => Settings::Get('system.defaultip')));
Database::pexecute($ins_stmt, array('domainid' => $domainid, 'ipid' => $defaultip));
}
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `standardsubdomain` = :domainid WHERE `customerid` = :customerid"
@@ -937,7 +940,7 @@ if ($page == 'customers'
SELECT ip, port FROM `".TABLE_PANEL_IPSANDPORTS."`
WHERE `id` = :defaultip
");
$srv_ip = Database::pexecute_first($srv_ip_stmt, array('defaultip' => Settings::Get('system.defaultip')));
$srv_ip = Database::pexecute_first($srv_ip_stmt, array('defaultip' => reset(explode(',', Settings::Get('system.defaultip')))));
$replace_arr = array(
'FIRSTNAME' => $firstname,
@@ -1272,10 +1275,13 @@ if ($page == 'customers'
$domainid = Database::lastInsertId();
// set ip <-> domain connection
$defaultips = explode(',', Settings::Get('system.defaultip'));
foreach ($defaultips as $defaultip) {
$ins_stmt = Database::prepare("
INSERT INTO `".TABLE_DOMAINTOIP."` SET `id_domain` = :domainid, `id_ipandports` = :ipid"
INSERT INTO `" . TABLE_DOMAINTOIP . "` SET `id_domain` = :domainid, `id_ipandports` = :ipid"
);
Database::pexecute($ins_stmt, array('domainid' => $domainid, 'ipid' => Settings::Get('system.defaultip')));
Database::pexecute($ins_stmt, array('domainid' => $domainid, 'ipid' => $defaultip));
}
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `standardsubdomain` = :domainid WHERE `customerid` = :customerid"

View File

@@ -83,7 +83,7 @@ if ($page == 'ipsandports'
$result_checkdomain = Database::pexecute_first($result_checkdomain_stmt, array('id' => $id));
if ($result_checkdomain['id'] == '') {
if ($result['id'] != Settings::Get('system.defaultip')) {
if (!in_array($result['id'], explode(',', Settings::Get('system.defaultip')))) {
$result_sameipotherport_stmt = Database::prepare("
SELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "`

View File

@@ -130,9 +130,9 @@ class IntegrityCheck {
while ($row = $adm_stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row['ip'] < 0 || is_null($row['ip']) || empty($row['ip'])) {
// Admin uses default-IP
$admips[$row['adminid']] = Settings::Get('system.defaultip');
$admips[$row['adminid']] = explode(',', Settings::Get('system.defaultip'));
} else {
$admips[$row['adminid']] = $row['ip'];
$admips[$row['adminid']] = [ $row['ip'] ];
}
}
}
@@ -181,7 +181,9 @@ class IntegrityCheck {
foreach ($domains as $domainid => $adminid) {
if (!array_key_exists($domainid, $ipstodomains)) {
if ($fix) {
Database::pexecute($ins_stmt, array('domainid' => $domainid, 'ipandportid' => $admips[$adminid]));
foreach ($admips[$adminid] as $defaultip) {
Database::pexecute($ins_stmt, array('domainid' => $domainid, 'ipandportid' => $defaultip));
}
$this->_log->logAction(ADM_ACTION, LOG_WARNING, "found a domain-id with no entry in domain <> ip table, integrity check fixed this");
} else {
$this->_log->logAction(ADM_ACTION, LOG_NOTICE, "found a domain-id with no entry in domain <> ip table, integrity check can fix this");

View File

@@ -97,7 +97,7 @@ return array(
'desc' => $lng['domains']['ipandport_multi']['description'],
'type' => 'checkbox',
'values' => $ipsandports,
'value' => array(Settings::Get('system.defaultip')),
'value' => explode(',', Settings::Get('system.defaultip')),
'is_array' => 1,
'mandatory' => true
),

View File

@@ -17,6 +17,7 @@
*
*/
function storeSettingDefaultIp($fieldname, $fielddata, $newfieldvalue) {
$defaultips_old = Settings::Get('system.defaultip');
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
@@ -40,13 +41,27 @@ function storeSettingDefaultIp($fieldname, $fielddata, $newfieldvalue) {
}
if (count($ids) > 0) {
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_DOMAINTOIP . "` SET
`id_ipandports` = :newval
WHERE `id_domain` IN ('" . implode(', ', $ids) . "')
AND `id_ipandports` = :defaultip
$defaultips_new = explode(',', $newfieldvalue);
// Delete the existing mappings linking to default IPs
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_DOMAINTOIP . "`
WHERE `id_domain` IN (" . implode(', ', $ids) . ")
AND `id_ipandports` IN (" . $defaultips_old . ")
");
Database::pexecute($upd_stmt, array('newval' => $newfieldvalue, 'defaultip' => Settings::Get('system.defaultip')));
Database::pexecute($del_stmt);
// Insert the new mappings
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_DOMAINTOIP . "`
SET `id_domain` = :domainid, `id_ipandports` = :ipandportid
");
foreach ($ids as $id) {
foreach ($defaultips_new as $defaultip_new) {
Database::pexecute($ins_stmt, array('domainid' => $id, 'ipandportid' => $defaultip_new));
}
}
}
}