diff --git a/install/tpl/server.ini.master b/install/tpl/server.ini.master
index 5f19aa8e74d21896493832ffbe372669414980e0..559f5eeab934e4232c34ee4f27529ea9e861a400 100644
--- a/install/tpl/server.ini.master
+++ b/install/tpl/server.ini.master
@@ -4,6 +4,7 @@ mailserver=postfix
dnsserver=mydns
[server]
+auto_network_configuration=n
ip_address=192.168.0.105
netmask=255.255.255.0
gateway=192.168.0.1
diff --git a/interface/web/admin/form/server.tform.php b/interface/web/admin/form/server.tform.php
index f4ebd4c7708a6b96603ca67bb24aac6d1033dcf2..80b672ef1e7e5e1665244818c1fdb001c384a0c0 100644
--- a/interface/web/admin/form/server.tform.php
+++ b/interface/web/admin/form/server.tform.php
@@ -39,7 +39,7 @@ $form["name"] = "server";
$form["action"] = "server_edit.php";
$form["db_table"] = "server";
$form["db_table_idx"] = "server_id";
-$form["db_history"] = "no";
+$form["db_history"] = "yes";
$form["tab_default"] = "services";
$form["list_default"] = "server_list.php";
$form["auth"] = 'yes';
diff --git a/interface/web/admin/form/server_config.tform.php b/interface/web/admin/form/server_config.tform.php
index f3e2a5a581f14d75d1883a7446c91d9b3da328ab..19bfb9a492704121a264de9cdbcfb9695dd11a71 100644
--- a/interface/web/admin/form/server_config.tform.php
+++ b/interface/web/admin/form/server_config.tform.php
@@ -58,6 +58,12 @@ $form["tabs"]['server'] = array (
##################################
# Begin Datatable fields
##################################
+ 'auto_network_configuration' => array (
+ 'datatype' => 'VARCHAR',
+ 'formtype' => 'CHECKBOX',
+ 'default' => 'n',
+ 'value' => array(0 => 'n',1 => 'y')
+ ),
'ip_address' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
diff --git a/interface/web/admin/lib/lang/en_server_config.lng b/interface/web/admin/lib/lang/en_server_config.lng
index 5c046b84b2bb4a389a8cbb5d2feb316a940c11bf..b4f18427424954841fa082881ea0c5db28ef0741 100644
--- a/interface/web/admin/lib/lang/en_server_config.lng
+++ b/interface/web/admin/lib/lang/en_server_config.lng
@@ -33,4 +33,5 @@ $wb["netmask_txt"] = 'Netmask';
$wb["gateway_txt"] = 'Gateway';
$wb["hostname_txt"] = 'Hostname';
$wb["nameservers_txt"] = 'Nameservers';
+$wb["auto_network_configuration_txt"] = 'Network Configuration';
?>
\ No newline at end of file
diff --git a/interface/web/admin/templates/server_config_server_edit.htm b/interface/web/admin/templates/server_config_server_edit.htm
index 6200fbc6ca4548d3d6077f20f5b1c926cd00483a..0d9d72202dd8b55d386b90a628b5fdc3eb0bc100 100644
--- a/interface/web/admin/templates/server_config_server_edit.htm
+++ b/interface/web/admin/templates/server_config_server_edit.htm
@@ -1,4 +1,8 @@
+
+
\ No newline at end of file
diff --git a/server/conf/debian_network_interfaces.master b/server/conf/debian_network_interfaces.master
new file mode 100644
index 0000000000000000000000000000000000000000..08c713691cbec3578bc5676c766692a48d330632
--- /dev/null
+++ b/server/conf/debian_network_interfaces.master
@@ -0,0 +1,27 @@
+# This file describes the network interfaces available on your system
+# and how to activate them. For more information, see interfaces(5).
+
+# The loopback network interface
+auto lo
+iface lo inet loopback
+
+# The primary network interface
+auto eth0
+iface eth0 inet static
+ address
+ netmask
+ network
+ broadcast
+ gateway
+
+
+
+auto eth0:
+iface eth0: inet static
+ address
+ netmask
+ network
+ broadcast
+ gateway
+
+
diff --git a/server/plugins-available/network_settings_plugin.inc.php b/server/plugins-available/network_settings_plugin.inc.php
new file mode 100644
index 0000000000000000000000000000000000000000..94e37b44bb0bf43277852c3e57d25575e24401eb
--- /dev/null
+++ b/server/plugins-available/network_settings_plugin.inc.php
@@ -0,0 +1,166 @@
+plugins->registerEvent('server_insert','network_settings_plugin','insert');
+ $app->plugins->registerEvent('server_update','network_settings_plugin','update');
+
+ $app->plugins->registerEvent('server_ip_insert','network_settings_plugin','insert');
+ $app->plugins->registerEvent('server_ip_update','network_settings_plugin','update');
+
+
+
+ }
+
+ function insert($event_name,$data) {
+ global $app, $conf;
+
+ $this->update($event_name,$data);
+
+ }
+
+ // The purpose of this plugin is to rewrite the main.cf file
+ function update($event_name,$data) {
+ global $app, $conf;
+
+ // get the config
+ $app->uses("getconf");
+ $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~');
+
+ $app->load('tpl');
+
+ $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"]));
+ $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'],
+ '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++;
+ }
+ }
+
+ $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');
+ }
+
+ }
+
+ function network($ip, $netmask){
+ $netmask = $this->netmask($netmask);
+ list($f1,$f2,$f3,$f4) = explode(".", $netmask);
+ $netmask_bin = str_pad(decbin($f1),8,"0",STR_PAD_LEFT).str_pad(decbin($f2),8,"0",STR_PAD_LEFT).str_pad(decbin($f3),8,"0",STR_PAD_LEFT).str_pad(decbin($f4),8,"0",STR_PAD_LEFT);
+ list($f1,$f2,$f3,$f4) = explode(".", $ip);
+ $ip_bin = str_pad(decbin($f1),8,"0",STR_PAD_LEFT).str_pad(decbin($f2),8,"0",STR_PAD_LEFT).str_pad(decbin($f3),8,"0",STR_PAD_LEFT).str_pad(decbin($f4),8,"0",STR_PAD_LEFT);
+ for($i=0;$i<32;$i++){
+ $network_bin .= substr($netmask_bin,$i,1) * substr($ip_bin,$i,1);
+ }
+ $network_bin = wordwrap($network_bin, 8, ".", 1);
+ list($f1,$f2,$f3,$f4) = explode(".", trim($network_bin));
+ return bindec($f1).".".bindec($f2).".".bindec($f3).".".bindec($f4);
+ }
+
+ function broadcast($ip, $netmask){
+ $netmask = $this->netmask($netmask);
+ $binary_netmask = $this->binary_netmask($netmask);
+ list($f1,$f2,$f3,$f4) = explode(".", $ip);
+ $ip_bin = str_pad(decbin($f1),8,"0",STR_PAD_LEFT).str_pad(decbin($f2),8,"0",STR_PAD_LEFT).str_pad(decbin($f3),8,"0",STR_PAD_LEFT).str_pad(decbin($f4),8,"0",STR_PAD_LEFT);
+ $broadcast_bin = str_pad(substr($ip_bin, 0, $binary_netmask),32,"1",STR_PAD_RIGHT);
+ $broadcast_bin = wordwrap($broadcast_bin, 8, ".", 1);
+ list($f1,$f2,$f3,$f4) = explode(".", trim($broadcast_bin));
+ return bindec($f1).".".bindec($f2).".".bindec($f3).".".bindec($f4);
+ }
+
+ function netmask($netmask){
+ list($f1,$f2,$f3,$f4) = explode(".", trim($netmask));
+ $bin = str_pad(decbin($f1),8,"0",STR_PAD_LEFT).str_pad(decbin($f2),8,"0",STR_PAD_LEFT).str_pad(decbin($f3),8,"0",STR_PAD_LEFT).str_pad(decbin($f4),8,"0",STR_PAD_LEFT);
+ $parts = explode("0", $bin);
+ $bin = str_pad($parts[0], 32, "0", STR_PAD_RIGHT);
+ $bin = wordwrap($bin, 8, ".", 1);
+ list($f1,$f2,$f3,$f4) = explode(".", trim($bin));
+ return bindec($f1).".".bindec($f2).".".bindec($f3).".".bindec($f4);
+ }
+
+ function binary_netmask($netmask){
+ list($f1,$f2,$f3,$f4) = explode(".", trim($netmask));
+ $bin = str_pad(decbin($f1),8,"0",STR_PAD_LEFT).str_pad(decbin($f2),8,"0",STR_PAD_LEFT).str_pad(decbin($f3),8,"0",STR_PAD_LEFT).str_pad(decbin($f4),8,"0",STR_PAD_LEFT);
+ $parts = explode("0", $bin);
+ return substr_count($parts[0], "1");
+ }
+
+} // end class
+
+
+
+?>
\ No newline at end of file