From 23a904844d8b8573723dcd8a64b7e05412c6e5d8 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Wed, 08 Sep 2010 02:48:46 -0400
Subject: [PATCH] Temporarily FS#1315 - After svn update, domain table is gone
---
server/plugins-available/network_settings_plugin.inc.php | 186 ++++++++++++++++++++++++++++++++++++---------
1 files changed, 147 insertions(+), 39 deletions(-)
diff --git a/server/plugins-available/network_settings_plugin.inc.php b/server/plugins-available/network_settings_plugin.inc.php
index 53619b2..961e2cd 100644
--- a/server/plugins-available/network_settings_plugin.inc.php
+++ b/server/plugins-available/network_settings_plugin.inc.php
@@ -80,54 +80,162 @@
$server_config = $app->getconf->get_server_config($conf["server_id"], 'server');
// Configure the debian network card settings
- if(is_file('/etc/debian_version') && $server_config['auto_network_configuration'] == 'y') {
- copy('/etc/network/interfaces','/etc/network/interfaces~');
+ if($server_config['auto_network_configuration'] == 'y') {
- $app->load('tpl');
+ if (is_file('/etc/debian_version'))
+ {
+ copy('/etc/network/interfaces','/etc/network/interfaces~');
- $network_tpl = new tpl();
- $network_tpl->newTemplate("debian_network_interfaces.master");
+ $app->load('tpl');
- $network_tpl->setVar('ip_address',$server_config["ip_address"]);
- $network_tpl->setVar('netmask',$server_config["netmask"]);
- $network_tpl->setVar('gateway',$server_config["gateway"]);
- $network_tpl->setVar('broadcast',$this->broadcast($server_config["ip_address"],$server_config["netmask"]));
- $network_tpl->setVar('network',$this->network($server_config["ip_address"],$server_config["netmask"]));
-
- $records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = ".intval($conf["server_id"]));
- $ip_records = array();
- $additionl_ip_records = 0;
- $n = 0;
- if(is_array($records)) {
- foreach($records as $rec) {
- $ip_records[] = array(
- 'id' => $n,
- 'ip_address' => $rec['ip_address'],
+ $network_tpl = new tpl();
+ $network_tpl->newTemplate("debian_network_interfaces.master");
+
+ $network_tpl->setVar('ip_address',$server_config["ip_address"]);
+ $network_tpl->setVar('netmask',$server_config["netmask"]);
+ $network_tpl->setVar('gateway',$server_config["gateway"]);
+ $network_tpl->setVar('broadcast',$this->broadcast($server_config["ip_address"],$server_config["netmask"]));
+ $network_tpl->setVar('network',$this->network($server_config["ip_address"],$server_config["netmask"]));
+
+ $records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = ".intval($conf["server_id"]) . " order by ip_address");
+ $ip_records = array();
+ $additionl_ip_records = 0;
+ $n = 0;
+ if(is_array($records)) {
+ foreach($records as $rec) {
+ /*
+ * don't insert the main-ip again!
+ */
+ if ($rec['ip_address'] != $server_config["ip_address"])
+ {
+ $ip_records[$n] = array(
+ 'id' => $n,
+ 'ip_address' => $rec['ip_address'],
+ 'netmask' => $server_config["netmask"],
+ 'gateway' => $server_config["gateway"],
+ 'broadcast' => $this->broadcast($rec['ip_address'],$server_config["netmask"]),
+ 'network' => $this->network($rec['ip_address'],$server_config["netmask"])
+ );
+ $additionl_ip_records = 1;
+ $n++;
+ }
+ }
+ }
+
+ /*
+ * If we have more than 1 IP we have to add the main-ip at the end
+ * of the network-ip-list. If we don't do so, there may be problems
+ * in multi-server-settings (with the acces from other server to the
+ * main-server) because the LAST IP in the list is the IP mysql uses
+ * to determine the host, the user is logging in from.
+ */
+ if ($additionl_ip_records != 0)
+ {
+ $swap["ip_address"] = $ip_records[$n-1]["ip_address"];
+ $swap["netmask"] = $ip_records[$n-1]["netmask"];
+ $swap["gateway"] = $ip_records[$n-1]["gateway"];
+
+ $ip_records[$n-1] = array(
+ 'id' => $n-1,
+ 'ip_address' => $server_config['ip_address'],
'netmask' => $server_config["netmask"],
'gateway' => $server_config["gateway"],
- 'broadcast' => $this->broadcast($rec['ip_address'],$server_config["netmask"]),
- 'network' => $this->network($rec['ip_address'],$server_config["netmask"])
+ 'broadcast' => $this->broadcast($server_config['ip_address'],$server_config["netmask"]),
+ 'network' => $this->network($server_config['ip_address'],$server_config["netmask"])
);
- $additionl_ip_records = 1;
- $n++;
+ $network_tpl->setVar('ip_address',$swap["ip_address"]);
+ $network_tpl->setVar('netmask',$swap["netmask"]);
+ $network_tpl->setVar('gateway',$swap["gateway"]);
+ $network_tpl->setVar('broadcast',$this->broadcast($swap["ip_address"],$swap["netmask"]));
+ $network_tpl->setVar('network',$this->network($swap["ip_address"],$swap["netmask"]));
}
+
+ $network_tpl->setVar('additionl_ip_records',$additionl_ip_records);
+ $network_tpl->setLoop('interfaces',$ip_records);
+ file_put_contents('/etc/network/interfaces',$network_tpl->grab());
+ unset($network_tpl);
+
+ $app->log("Changed Network settings",LOGLEVEL_DEBUG);
+ exec($conf['init_scripts'] . '/' . 'networking force-reload');
+ }
+ elseif (is_file('/etc/gentoo-release'))
+ {
+ copy('/etc/conf.d/net','/etc/conf.d/net~');
+
+ $app->load('tpl');
+
+ $network_tpl = new tpl();
+ $network_tpl->newTemplate("gentoo_network_interfaces.master");
+
+ $network_tpl->setVar('ip_address',$server_config["ip_address"]);
+ $network_tpl->setVar('netmask',$server_config["netmask"]);
+ $network_tpl->setVar('gateway',$server_config["gateway"]);
+ $network_tpl->setVar('broadcast',$this->broadcast($server_config["ip_address"],$server_config["netmask"]));
+
+ $records = $app->db->queryAllRecords("SELECT ip_address FROM server_ip WHERE server_id = ".intval($conf["server_id"]) . " order by ip_address");
+ $ip_records = array();
+ $additionl_ip_records = 0;
+ $n = 0;
+ if(is_array($records)) {
+ foreach($records as $rec) {
+ /*
+ * don't insert the main-ip again!
+ */
+ if ($rec['ip_address'] != $server_config["ip_address"])
+ {
+ $ip_records[$n] = array(
+ 'id' => $n,
+ 'ip_address' => $rec['ip_address'],
+ 'netmask' => $server_config["netmask"],
+ 'gateway' => $server_config["gateway"],
+ 'broadcast' => $this->broadcast($rec['ip_address'],$server_config["netmask"])
+ );
+ $additionl_ip_records = 1;
+ $n++;
+ }
+ }
+ }
+
+ /*
+ * If we have more than 1 IP we have to add the main-ip at the end
+ * of the network-ip-list. If we don't do so, there may be problems
+ * in multi-server-settings (with the acces from other server to the
+ * main-server) because the LAST IP in the list is the IP mysql uses
+ * to determine the host, the user is logging in from.
+ */
+ if ($additionl_ip_records != 0)
+ {
+ $swap["ip_address"] = $ip_records[$n-1]["ip_address"];
+ $swap["netmask"] = $ip_records[$n-1]["netmask"];
+ $swap["gateway"] = $ip_records[$n-1]["gateway"];
+
+ $ip_records[$n-1] = array(
+ 'id' => $n-1,
+ 'ip_address' => $server_config['ip_address'],
+ 'netmask' => $server_config["netmask"],
+ 'gateway' => $server_config["gateway"],
+ 'broadcast' => $this->broadcast($server_config['ip_address'],$server_config["netmask"])
+ );
+ $network_tpl->setVar('ip_address',$swap["ip_address"]);
+ $network_tpl->setVar('netmask',$swap["netmask"]);
+ $network_tpl->setVar('gateway',$swap["gateway"]);
+ $network_tpl->setVar('broadcast',$this->broadcast($swap["ip_address"],$swap["netmask"]));
+ }
+
+ $network_tpl->setVar('additionl_ip_records',$additionl_ip_records);
+ $network_tpl->setLoop('interfaces',$ip_records);
+ file_put_contents('/etc/conf.d/net',$network_tpl->grab());
+ unset($network_tpl);
+
+ $app->log("Changed Network settings",LOGLEVEL_DEBUG);
+ exec($conf['init_scripts'] . '/' . 'net.eth0 restart');
+ }
+ else {
+ $app->log("Network configuration not available for this Linux distribution.",LOGLEVEL_DEBUG);
}
- $network_tpl->setVar('additionl_ip_records',$additionl_ip_records);
- $network_tpl->setLoop('interfaces',$ip_records);
-
- file_put_contents('/etc/network/interfaces',$network_tpl->grab());
- unset($network_tpl);
-
- $app->log("Changed Network settings",LOGLEVEL_DEBUG);
-
- exec('/etc/init.d/networking force-reload');
} else {
- if(is_file('/etc/debian_version')) {
- $app->log("Network configuration disabled in server settings.",LOGLEVEL_WARN);
- } else {
- $app->log("Network configuration not available for this linux distribution.",LOGLEVEL_DEBUG);
- }
+ $app->log("Network configuration disabled in server settings.",LOGLEVEL_WARN);
}
}
@@ -178,4 +286,4 @@
-?>
\ No newline at end of file
+?>
--
Gitblit v1.9.1