1,7 → 1,7 |
<?php |
# $Id$ |
|
// written by steweb57, Rexy & Tom HOUDAYER |
// written by steweb57, Rexy, Tom HOUDAYER & Pierre RIVAULT |
|
/******************** |
* READ CONF FILES * |
11,6 → 11,8 |
define('ETHERS_INFO_FILE', '/usr/local/etc/alcasar-ethers-info'); |
define('DNS_LOCAL_FILE', '/etc/hosts'); |
define('LETS_ENCRYPT_FILE', '/usr/local/etc/alcasar-letsencrypt'); |
define('TEMP_FILE', '/tmp/alcasar.conf.temp'); |
|
$conf_files = [CONF_FILE, ETHERS_FILE, ETHERS_INFO_FILE, DNS_LOCAL_FILE, LETS_ENCRYPT_FILE]; |
|
// Files reading test |
98,6 → 100,14 |
$l_renew = "Renouveller"; |
$l_renew_force = "Renouveller (forcer)"; |
$l_previous_LE_cert = "Revenir au certificat Let's Encrypt :"; |
$l_gw_weight = "Poids"; |
$l_error = "Erreur"; |
$l_error_bad_ip = "Ceci n'est pas une adresse IP valide"; |
$l_error_bad_ip_CIDR = "Ceci n'est pas une adresse CIDR valide"; |
$l_error_bad_ip_port = "Ceci n'est pas une adresse IP + port valide"; |
$l_error_weight = "Ceci n'est pas un poids valide"; |
$l_change_successful = "Changement effectué avec succès"; |
|
} else if ($Language === 'es') { |
$l_network_title = "Configuración de Red"; |
$l_internet_legend = "INTERNET"; |
153,6 → 163,13 |
$l_renew = "Renovar"; |
$l_renew_force = "Renovar (forzado)"; |
$l_previous_LE_cert = "Volver al certificado de Let's Encrypt :"; |
$l_gw_weight = "";/*TODO Traduction espagnole*/ |
$l_error = "";/*TODO Traduction espagnole*/ |
$l_error_bad_ip = "";/*TODO Traduction espagnole*/ |
$l_error_bad_ip_CIDR = "";/*TODO Traduction espagnole*/ |
$l_error_bad_ip_port = "";/*TODO Traduction espagnole*/ |
$l_error_weight = "";/*TODO Traduction espagnole*/ |
$l_change_successful = "";/*TODO Traduction espagnole*/ |
} else { |
$l_network_title = "Network configuration"; |
$l_internet_legend = "INTERNET"; |
208,15 → 225,24 |
$l_renew = "Renew"; |
$l_renew_force = "Renew (force)"; |
$l_previous_LE_cert = "Back to the Let's Encrypt certificate :"; |
$l_gw_weight = "Weight"; |
$l_error = "Error"; |
$l_error_bad_ip = "This is not a valid IP"; |
$l_error_bad_ip_CIDR = "This is not a valid CIDR IP"; |
$l_error_bad_ip_port = "This is not a valid IP + port"; |
$l_error_weight = "This is not a valid weight"; |
$l_change_successful = "Network updated successfully"; |
} |
|
$reg_ip = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/'; |
$reg_ip_cidr = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/'; |
$reg_ip_port = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\:([1-9]|[1-9][0-9]|[1-9][0-9]{2}|[1-9][0-9]{3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))$/'; |
$reg_mac = '/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/'; |
$reg_host = '/^[a-zA-Z0-9-_]+$/'; |
$reg_weight = '/^[0-9]*$/'; |
$ext_conf_error = false; |
|
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : ''; |
|
switch ($choix) { |
case 'DHCP_On': |
exec('sudo /usr/local/bin/alcasar-dhcp.sh -on'); |
226,7 → 252,6 |
exec('sudo /usr/local/bin/alcasar-dhcp.sh -off'); |
header('Location: '.$_SERVER['PHP_SELF']); |
exit(); |
|
case 'new_mac': |
$new_mac_addr = trim($_POST['add_mac']); |
$new_ip_addr = trim($_POST['add_ip']); |
274,7 → 299,6 |
} |
header('Location: '.$_SERVER['PHP_SELF']); |
exit(); |
|
case 'new_host': |
$add_host = trim($_POST['add_host']); |
$add_ip = trim($_POST['add_ip']); |
340,7 → 364,6 |
} |
} |
break; |
|
case 'https_login': // Set HTTPS login status |
if ($_POST['https_login'] === 'on') { |
exec('sudo /usr/local/bin/alcasar-https.sh --on'); |
353,33 → 376,183 |
|
// Network changes |
if ($choix === 'network_change') { |
$network_modification = false; |
exec('sudo /usr/local/bin/alcasar-network.sh --save'); |
$modification_network = false; |
$modification_dns = false; |
$modification_proxy = false; |
$ext_conf_error_list = []; |
copy(CONF_FILE, TEMP_FILE); |
|
if (isset($_POST['dns1']) && (trim($_POST['dns1']) !== $conf['DNS1']) && preg_match($reg_ip, $_POST['dns1'])) { |
file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'], 'DNS1='.trim($_POST['dns1']), file_get_contents(CONF_FILE))); |
$network_modification = true; |
if (isset($_POST['dns1']) && (trim($_POST['dns1']) !== $conf['DNS1'])) { |
if (!preg_match($reg_ip, $_POST['dns1'])) { |
$ext_conf_error = true; |
$ext_conf_error_list[] = $l_error.': '.$l_ip_dns1.': '.$l_error_bad_ip; |
} |
file_put_contents(TEMP_FILE, str_replace('DNS1='.$conf['DNS1'], 'DNS1='.trim($_POST['dns1']), file_get_contents(TEMP_FILE))); |
$modification_dns = true; |
} |
if (isset($_POST['dns2']) && (trim($_POST['dns2']) !== $conf['DNS2']) && preg_match($reg_ip, $_POST['dns2'])) { |
file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'], 'DNS2='.trim($_POST['dns2']), file_get_contents(CONF_FILE))); |
$network_modification = true; |
if (isset($_POST['dns2']) && (trim($_POST['dns2']) !== $conf['DNS2'])) { |
if (!preg_match($reg_ip, $_POST['dns2'])) { |
$ext_conf_error = true; |
$ext_conf_error_list[] = $l_error.': '.$l_ip_dns2.': '.$l_error_bad_ip; |
} |
file_put_contents(TEMP_FILE, str_replace('DNS2='.$conf['DNS2'], 'DNS2='.trim($_POST['dns2']), file_get_contents(TEMP_FILE))); |
$modification_dns = true; |
} |
if (isset($_POST['ip_public']) && (trim($_POST['ip_public']) !== $conf['PUBLIC_IP']) && preg_match($reg_ip_cidr, $_POST['ip_public'])) { |
file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'], 'PUBLIC_IP='.trim($_POST['ip_public']), file_get_contents(CONF_FILE))); |
$network_modification = true; |
if (isset($_POST['ip_private']) && (trim($_POST['ip_private']) !== $conf['PRIVATE_IP'])) { |
if (!preg_match($reg_ip_cidr, $_POST['ip_private'])) { |
$ext_conf_error = true; |
$ext_conf_error_list[] = $l_error.': '.$l_ip_address.' LAN: '.$l_error_bad_ip_CIDR; |
} |
file_put_contents(TEMP_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'], 'PRIVATE_IP='.trim($_POST['ip_private']), file_get_contents(TEMP_FILE))); |
$modification_network = true; |
} |
if (isset($_POST['ip_public']) && (trim($_POST['ip_public']) !== $conf['PUBLIC_IP'])) { |
if (!preg_match($reg_ip_cidr, $_POST['ip_public'])) { |
$ext_conf_error = true; |
$ext_conf_error_list[] = $l_error.': '.$l_ip_address.' WAN: '.$l_error_bad_ip_CIDR; |
} |
file_put_contents(TEMP_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'], 'PUBLIC_IP='.trim($_POST['ip_public']), file_get_contents(TEMP_FILE))); |
$modification_network = true; |
} |
if (isset($_POST['ip_gw']) && (trim($_POST['ip_gw']) !== $conf['GW']) && preg_match($reg_ip, $_POST['ip_gw'])) { |
file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'], 'GW='.trim($_POST['ip_gw']), file_get_contents(CONF_FILE))); |
$network_modification = true; |
} |
if (isset($_POST['ip_private']) && (trim($_POST['ip_private']) !== $conf['PRIVATE_IP']) && preg_match($reg_ip_cidr, $_POST['ip_private'])) { |
file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'], 'PRIVATE_IP='.trim($_POST['ip_private']), file_get_contents(CONF_FILE))); |
$network_modification = true; |
} |
if (isset($_POST['ip_gw']) && (trim($_POST['ip_gw']) !== $conf['GW'])) { |
if (!preg_match($reg_ip, $_POST['ip_gw'])) { |
$ext_conf_error = true; |
$ext_conf_error_list[] = $l_error.': '.$l_ip_router.' 1: '.$l_error_bad_ip; |
} |
file_put_contents(TEMP_FILE, str_replace('GW='.$conf['GW'], 'GW='.trim($_POST['ip_gw']), file_get_contents(TEMP_FILE))); |
$modification_network = true; |
} |
if (isset($_POST['enable_proxy']) && $_POST['enable_proxy'] == 'P_Enabled') |
{ |
if ($conf['PROXY'] !== 'On') |
{ |
file_put_contents(TEMP_FILE, str_replace('PROXY='.$conf['PROXY'], 'PROXY=On', file_get_contents(TEMP_FILE))); |
$modification_proxy = true; |
} |
if (isset($_POST['proxy']) && (trim($_POST['proxy']) !== $conf['PROXY_IP'])) { |
if (!preg_match($reg_ip_port, $_POST['proxy'])) { |
$ext_conf_error = true; |
$ext_conf_error_list[] = $l_error.': Proxy: '.$l_error_bad_ip_port; |
} |
file_put_contents(TEMP_FILE, str_replace('PROXY_IP='.$conf['PROXY_IP'], 'PROXY_IP='.trim($_POST['proxy']), file_get_contents(TEMP_FILE))); |
$modification_proxy = true; |
} |
if ($conf['MULTIWAN'] !== 'Off') |
{ |
file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], 'MULTIWAN=Off', file_get_contents(TEMP_FILE))); |
$modification_network = true; |
} |
} |
else |
{ |
//set multiwan value to off and delete every "WANx=" line |
if ($_POST['gw_count'] === "1" && $conf['MULTIWAN'] !== 'Off') |
{ |
file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], 'MULTIWAN=Off', file_get_contents(TEMP_FILE))); |
$temp = 1; |
while (isset($conf['WAN'.$temp])) |
{ |
file_put_contents(TEMP_FILE, str_replace('WAN'.$temp.'='.$conf['WAN'.$temp]."\n", '', file_get_contents(TEMP_FILE))); |
$temp++; |
} |
$modification_network = true; |
} |
if ($_POST['gw_count'] !== "1") |
{ |
$changed = false; |
//testing the existence of a change in the routing configuration |
exec("grep \"^WAN\" " . CONF_FILE . " | wc -l", $nb_gw); |
if ($_POST['gw_count'] == ($nb_gw[0] + 1)) |
{ |
if ($_POST['weight'] !== $conf['PUBLIC_WEIGHT']) { |
$changed = true; |
} |
else { |
for($i=1;$i<$_POST['gw_count'];$i++) |
{ |
if( '"'.$_POST['ip_gw_'.$i].','.$_POST['weight_'.$i].'"' != $conf['WAN'.$i]) |
{ |
$changed = true; |
break; |
} |
} |
} |
} |
else |
{ |
$changed = true; |
} |
|
if ($network_modification) { |
exec('sudo /usr/local/bin/alcasar-conf.sh -apply'); |
} |
if ($changed == true) |
{ |
//deleting all the old lines containing "WANx=" |
$temp = 1; |
while (isset($conf['WAN'.$temp])) |
{ |
file_put_contents(TEMP_FILE, str_replace('WAN'.$temp.'='.$conf['WAN'.$temp]."\n", '', file_get_contents(TEMP_FILE))); |
$temp++; |
} |
//setting back the line "WAN1=" which will be our base |
if (!preg_match($reg_weight, $_POST['weight'])) { |
$ext_conf_error = true; |
$ext_conf_error_list[] = $l_error.': '.$l_gw_weight.' 1: '.$l_error_weight; |
} |
file_put_contents(TEMP_FILE, str_replace('PUBLIC_WEIGHT='.$conf['PUBLIC_WEIGHT'], 'PUBLIC_WEIGHT='.(($_POST['weight'] !== '')?$_POST['weight']:1), file_get_contents(TEMP_FILE))); |
//Set Multiwan status |
file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], "MULTIWAN=On\nWAN1=", file_get_contents(TEMP_FILE))); |
//Adding the correct number of "WANx=" lines, numbered |
for($i=2;$i<$_POST['gw_count'];$i++) |
{ |
file_put_contents(TEMP_FILE, str_replace('WAN'.($i-1).'=', 'WAN'.($i-1)."=\nWAN".$i.'=', file_get_contents(TEMP_FILE))); |
} |
//Adding the content |
for($i=1;$i<$_POST['gw_count'];$i++) |
{ |
if (!preg_match($reg_ip, $_POST['ip_gw_'.$i])) { |
$ext_conf_error = true; |
$ext_conf_error_list[] = $l_error.': '.$l_ip_router.' '.($i+1).': '.$l_error_bad_ip; |
} |
if (!preg_match($reg_weight, $_POST['weight_'.$i])) { |
$ext_conf_error = true; |
$ext_conf_error_list[] = $l_error.': '.$l_gw_weight.' '.($i+1).': '.$l_error_weight; |
} |
file_put_contents(TEMP_FILE, str_replace('WAN'.$i.'=', 'WAN'.$i.'="'.$_POST['ip_gw_'.$i].','.(($_POST['weight_'.$i] === "0" || $_POST['weight_'.$i] === "")?"1":$_POST['weight_'.$i]).'"', file_get_contents(TEMP_FILE))); |
} |
$modification_network = true; |
} |
} |
//set proxy value to off |
if ($conf['PROXY'] !== 'Off') |
{ |
file_put_contents(TEMP_FILE, str_replace('PROXY='.$conf['PROXY'], 'PROXY=Off', file_get_contents(TEMP_FILE))); |
if($_POST['gw_count'] !== "1" && $conf['MULTIWAN'] !== 'On') { |
file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], 'MULTIWAN=On', file_get_contents(TEMP_FILE))); |
$modification_network = true; |
} |
$modification_proxy = true; |
} |
} |
|
//if no errors are detected |
if ($ext_conf_error == false) { |
copy(TEMP_FILE, CONF_FILE); |
//DNS values modification, several services needs to be reloading, reloads the full server. |
if ($modification_dns) { |
exec('sudo /usr/local/bin/alcasar-conf.sh -apply'); |
} |
//External network modifications, no service reloading |
if ($modification_network) { |
exec('sudo /usr/local/bin/alcasar-network.sh'); |
exec('sudo /usr/local/bin/alcasar-iptables.sh'); |
} |
//If only the proxy has been modified, only the firewall needs a change |
else if ($modification_proxy) { |
exec('sudo /usr/local/bin/alcasar-iptables.sh'); |
} |
} |
unlink(TEMP_FILE); |
|
// Read CONF_FILE updated |
$file_conf = fopen(CONF_FILE, 'r'); |
if (!$file_conf) { |
453,18 → 626,33 |
$internet_publicIP = '-.-.-.-'; |
} |
|
// Network interfaces |
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['EXTIF'], $conf['INTIF']]; |
// Network interfaces, will be use later for multiple LAN interfaces |
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['INTIF']]; |
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable); |
|
// TODO: Pending the next version |
$externalNetworks = [ |
//retreive gateway(s) parameters |
$gateways = [ |
(object) [ |
'interface' => $conf['EXTIF'], |
'ip' => $conf['PUBLIC_IP'], |
'gateway' => $conf['GW'] |
'gateway' => $conf['GW'], |
'weight' => $conf['PUBLIC_WEIGHT'] |
] |
]; |
exec("grep \"^WAN\" " . CONF_FILE . " | wc -l", $nbIfaces); |
if ($nbIfaces > 0) |
{ |
for ($i = 1; $i <= $nbIfaces[0]; $i++) { |
exec("grep \"WAN" . $i . "=\" " . CONF_FILE . " | awk -F'\"' '{ print $2 }' | awk -F, '{ print $1 }'", $temp_gw); |
exec("grep \"WAN" . $i . "=\" " . CONF_FILE . " | awk -F'\"' '{ print $2 }' | awk -F, '{ print $2 }'", $temp_weight); |
$gateways[] = (object) [ |
'gateway' => $temp_gw[0], |
'weight' => $temp_weight[0] |
]; |
$temp_gw = ""; |
$temp_weight = ""; |
} |
} |
|
//retreive internal networks parameters |
$internalNetworks = [ |
(object) [ |
'interface' => $conf['INTIF'], |
510,7 → 698,7 |
width: 30%; |
} |
.network-configurator .actions { |
position: absolute; |
position: absolute; |
background-color: #ddd; |
padding: 0 2px; |
} |
520,10 → 708,11 |
.network-configurator .actions a:hover { |
font-weight: bold; |
} |
.network-configurator > .alcasar .actions-externals { |
bottom: 0; |
left: 0; |
border-radius: 0 5px; |
.network-configurator .actions-externals { |
right: 0; |
border-radius: 5px; |
position: relative; |
text-decoration: none; |
} |
.network-configurator > .alcasar .actions-internals { |
bottom: 0; |
531,9 → 720,10 |
border-radius: 5px 0; |
} |
.network-configurator .actions-network { |
top: 0; |
right: 0; |
border-radius: 0 5px; |
border-radius: 5px; |
position: relative; |
text-decoration: none; |
} |
.network-configurator .network-box { |
display: inline-block; |
558,10 → 748,10 |
background-color: black; |
} |
.network-configurator .network-connector[data-connector-direction="left"] { |
border-radius: 5px 0px 0px 5px; |
border-radius: 5px 0 0 5px; |
} |
.network-configurator .network-connector[data-connector-direction="right"] { |
border-radius: 0px 5px 5px 0px; |
border-radius: 0 5px 5px 0; |
} |
.network-configurator div[data-network-type] { |
position: relative; |
569,39 → 759,30 |
</style> |
<script> |
$(document).ready(function () { |
const interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>; |
|
const wireStyles = { |
available: { border: '5px double green' } |
}; |
setTimeout(function(){$("#change_success").fadeOut('normal');}, 10000); |
|
// Add external network |
$('.network-configurator .add-external-network').click(function (event) { |
//Will be used later for multiple LAN interfaces |
let interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>; |
const wireStyles = { available: { border: '5px double green' } }; |
|
// Add gateway |
$('.network-configurator').on('click', '.add-external-network', function (event) { |
event.preventDefault(); |
let options = ''; |
if (interfacesAvailable.length === 0) { |
options = '<option value=""></option>'; |
} else { |
for (let i = 0; i < interfacesAvailable.length; i++) { |
options += '<option value="' + interfacesAvailable[i] + '">' + interfacesAvailable[i] + '</option>'; |
} |
} |
$('.network-configurator .externals').append(' \ |
<div data-network-type="external"> \ |
<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div> \ |
<div class="network-box"> \ |
<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \ |
<label for="ext_interface_X"><?= 'Interface' ?></label> <select name="interface" id="ext_interface_X">' + options + '</select><br> \ |
<label for="ext_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_public" id="ext_ip_X" value="" /><br> \ |
<label for="ext_gateway_X"><?= $l_ip_router ?></label> <input style="width:120px" type="text" name="ip_gw" id="ext_gateway_X" value="" /> \ |
</div> \ |
<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div> \ |
</div>'); |
addWire($('div[data-network-type="external"]:last')); |
ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value')); |
$('.network-configurator .externals .network-box #ext_gateways').append(' \ |
<div id="ip_routeur_' + ifaces_count + '" data-info_type="gateway" data-number="'+ ifaces_count +'">\ |
<label for="ext_gateway_' + ifaces_count + '"><?= $l_ip_router.' ' ?></label><span class="gw_number">'+ (ifaces_count + 1) +'</span> <input style="width:100px" type="text" name="ip_gw_' + ifaces_count + '" id="ext_gateway_' + ifaces_count + '" value="" /> \ |
<label for="ext_weight_'+ ifaces_count +'"><?= $l_gw_weight ?></label> <input style="width:20px" type="text" name="weight_' + ifaces_count + '" id="ext_weight_'+ ifaces_count +'" value="0"/> \ |
<div class="actions actions-network" style="display:inline-block; width:11px"><a href="#" style="display:block; text-align:center" class="remove-network" title="Supprimer ce réseau">-</a></div><br></div> '); |
ifaces_count++; |
document.getElementById("gw_count").setAttribute('value', ifaces_count); |
updateGatewayView(); |
$('div.network-connector[data-connector-network]').connections('update'); |
}); |
|
// Add internal network |
$('.network-configurator .add-internal-network').click(function (event) { |
$('.network-configurator').on('click', '.add-internal-network', function (event) { |
event.preventDefault(); |
$('.network-configurator .internals').append(' \ |
<div data-network-type="internal"> \ |
615,38 → 796,123 |
addWire($('div[data-network-type="internal"]:last')); |
}); |
|
// Remove network |
$('.network-configurator').on('click', '.remove-network', function (event) { |
// Remove gateway |
$('.network-box').on('click', '.remove-network', function (event) { |
event.preventDefault(); |
$(this).parent().parent().parent().fadeOut(200, function() { |
const networkType = $(this).data('networkType'); |
$(this).remove(); |
$(this).parent().parent().fadeOut(200, function() { |
|
// Update wires |
if (networkType === 'external') { |
$('div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]').connections('update'); |
$('div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]').connections('update'); |
} else if (networkType === 'internal') { |
$('div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]').connections('update'); |
} |
$(this).remove(); |
//update network numbers |
$('div[data-info_type="gateway"]').each(function (index, value) { |
updateGatewayNumbers($(this), index); |
}); |
ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value')); |
document.getElementById("gw_count").setAttribute('value', (ifaces_count - 1)); |
updateGatewayView(); |
|
$('div.network-connector[data-connector-network]').connections('update'); |
}); |
}); |
|
//proxy enabled or disabled |
$('.network-configurator').on('click', '.enable_proxy', function(event){ |
if ($(this).is(':checked')) |
{ |
document.getElementById("add_external").setAttribute('hidden', 'true'); |
document.getElementById("ext_proxy").removeAttribute('disabled'); |
$('div[id="ip_routeur_0"]').children('span').html(''); |
$('div[data-info_type="gateway"]').each(function(index, value) { |
if ($(this).attr('data-number') !== "0") |
{ |
$(this).attr('hidden', 'true'); |
} |
else |
{ |
$(this).children('input[id="ext_weight_0"]').attr('hidden', 'true'); |
$(this).children('label[for="ext_weight_0"]').attr('hidden', 'true'); |
$(this).children('div[class="actions actions-network"]').css('display', 'none'); |
} |
}); |
} |
else |
{ |
document.getElementById("add_external").removeAttribute('hidden'); |
document.getElementById("ext_proxy").setAttribute('disabled', 'true'); |
$('div[id="ip_routeur_0"]').children('span').html('1'); |
$('div[data-info_type="gateway"]').each(function(index, value) { |
if ($(this).attr('data-number') !== "0") |
{ |
$(this).removeAttr('hidden'); |
} |
else |
{ |
$(this).children('input[id="ext_weight_0"]').removeAttr('hidden'); |
$(this).children('label[for="ext_weight_0"]').removeAttr('hidden'); |
$(this).children('div[class="actions actions-network"]').css('display', 'inline-block'); |
} |
}); |
updateGatewayView(); |
} |
$('div.network-connector[data-connector-network]').connections('update'); |
}); |
|
//Add a wire between two connectors |
const addWire = function (network) { |
const networkType = network.data('networkType'); |
if (networkType === 'external') { |
$().connections({ from: 'div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]', to: 'div[data-network-type="external"]>div.network-connector[data-connector-network="internet"]:last', css: wireStyles.available, within: 'div[data-network-type="external"]:last' }); |
$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]', to: 'div[data-network-type="external"]>div.network-connector[data-connector-network="external"]:last', css: wireStyles.available, within: 'div[data-network-type="external"]:last' }); |
} else if (networkType === 'internal') { |
$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]', to: 'div[data-network-type="internal"]>div.network-connector[data-connector-network="internal"]:last', css: wireStyles.available, within: 'div[data-network-type="internal"]:last' }); |
$().connections({ from: 'div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]', to: network.children('div.network-connector[data-connector-network="internet"]'), css: wireStyles.available, within: network }); |
$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]', to: network.children('div.network-connector[data-connector-network="external"]'), css: wireStyles.available, within: network }); |
} else if (networkType === 'internal') { |
$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]', to: network.children('div.network-connector[data-connector-network="internal"]'), css: wireStyles.available, within: network }); |
} |
}; |
|
//reindex the gateway numbers when a gateway is deleted |
const updateGatewayNumbers = function(gateway, number) { |
old_number = gateway.attr('data-number'); |
gateway.attr('data-number', number); |
gateway.attr('id', 'ip_routeur_'+number); |
if (number === 0) |
{ |
gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('name', 'ip_gw'); |
gateway.children('input[id="ext_weight_'+old_number+'"]').attr('name', 'weight'); |
} |
else |
{ |
gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('name', 'ip_gw_'+number); |
gateway.children('input[id="ext_weight_'+old_number+'"]').attr('name', 'weight_'+number); |
} |
gateway.children('label[for="ext_gateway_'+old_number+'"]').attr('for', 'ext_gateway_'+number); |
gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('id', 'ext_gateway_'+number); |
gateway.children('label[for="ext_weight_'+old_number+'"]').attr('for', 'ext_weight_'+number); |
gateway.children('input[id="ext_weight_'+old_number+'"]').attr('id', 'ext_weight_'+number); |
gateway.children('span[class="gw_number"]').html((number+1)+' '); |
|
}; |
|
//hide the delete button and the weight field when there is only one gateway (or when there is a proxy) |
const updateGatewayView = function() { |
ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value')); |
if (ifaces_count === 1) |
{ |
$('div#ip_routeur_0').children('input[id="ext_weight_0"]').attr('hidden', 'true'); |
$('div#ip_routeur_0').children('label[for="ext_weight_0"]').attr('hidden', 'true'); |
$('div#ip_routeur_0').children('div[class="actions actions-network"]').css('display', 'none'); |
} |
else |
{ |
$('div#ip_routeur_0').children('input[id="ext_weight_0"]').removeAttr('hidden'); |
$('div#ip_routeur_0').children('label[for="ext_weight_0"]').removeAttr('hidden'); |
$('div#ip_routeur_0').children('div[class="actions actions-network"]').css('display', 'inline-block'); |
} |
}; |
|
//resize the connections to fit the window |
window.addEventListener('resize', function () { |
$('div.network-connector[data-connector-network]').connections('update'); |
}); |
|
// Add wires to existing networks |
// Add wires to existing networks at page first render |
$('div[data-network-type="external"]').add('div[data-network-type="internal"]').each(function (index, element) { |
addWire($(this)); |
}); |
669,26 → 935,49 |
</div> |
<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div> |
</div> |
</div><div class="externals"> |
<?php foreach ($externalNetworks as $index => $network): ?> |
</div><div id="externals_id" class="externals"> |
<div data-network-type="external"> |
<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div> |
<div class="network-box"> |
<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> --> |
<label for="ext_interface_<?= $index ?>"><?= 'Interface' ?></label> <select name="ext_interface[<?= $index ?>]" id="ext_interface_<?= $index ?>" disabled><option value="<?= $network->interface ?>"><?= $network->interface ?></option></select><br> |
<label for="ext_ip_<?= $index ?>"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_public" id="ext_ip_<?= $index ?>" value="<?= $network->ip ?>" /><br> |
<label for="ext_gateway_<?= $index ?>"><?= $l_ip_router ?></label> <input style="width:120px" type="text" name="ip_gw" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>" /> |
</div> |
<label for="ext_interface">Interface</label> <input name="ext_interface" id="ext_interface" value="<?= $conf['EXTIF'] ?>" disabled="disabled"/><br> |
<label for="ext_ip"><?= $l_ip_address ?></label> <input style="width:130px" type="text" name="ip_public" id="ext_ip" value="<?= $conf['PUBLIC_IP'] ?>" /><br> |
<input class="enable_proxy" type="checkbox" name="enable_proxy" value="P_Enabled" <?php if($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On') { echo 'checked'; }?>/> |
<label for="proxy">Proxy</label> <input style="width:140px" type="text" name="proxy" id="ext_proxy" value=<?= $conf['PROXY_IP']?> <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? '' : 'disabled'?>/><br> |
<div id="ext_gateways" > |
<input type="text" name="gw_count" id="gw_count" value="<?=count($gateways)?>" hidden="hidden"/> |
<?php foreach ($gateways as $index => $network): |
if ($index == 0) {?> |
<div id="ip_routeur_<?= $index ?>" data-info_type="gateway" data-number="<?= $index ?>"> |
<label for="ext_gateway_<?= $index ?>"><?= $l_ip_router.' ' ?></label> |
<span class="gw_number"><?= ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')?'':($index+1) ?> </span> |
<input style="width:100px" type="text" name="ip_gw" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>" /> |
<label for="ext_weight_<?= $index ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On'|| $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'hidden' : '' ?>><?= $l_gw_weight ?></label> |
<input style="width:20px" type="text" name="weight" id="ext_weight_<?= $index ?>" value="<?= $network->weight ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On' || $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'hidden' : '' ?>/> |
<div class="actions actions-network" style="display: <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On'|| $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'none' : 'inline-block' ?>; width:11px"> |
<a style="display:block; text-align:center" href="#" class="remove-network" title="Supprimer ce réseau">-</a> |
</div><br> |
</div> |
<?php } else {?> |
<div id="ip_routeur_<?= $index ?>" data-info_type="gateway" data-number="<?= $index ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? 'hidden' : '' ?>> |
<label for="ext_gateway_<?= $index ?>"><?= $l_ip_router.' ' ?></label> |
<span class="gw_number"><?= ($index+1) ?> </span> |
<input style="width:100px" type="text" name="ip_gw_<?= $index ?>" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>"/> |
<label for="ext_weight_<?= $index ?>"><?= $l_gw_weight ?></label> |
<input style="width:20px" type="text" name="weight_<?= $index ?>" id="ext_weight_<?= $index ?>" value="<?= $network->weight ?>"/> |
<div class="actions actions-network" style="display:inline-block; width:11px"> |
<a style="display:block; text-align:center" href="#" class="remove-network" title="Supprimer ce réseau">-</a> |
</div><br> |
</div> |
<?php } endforeach; ?> |
</div> |
<div class="actions actions-externals" style="margin: 0 auto; width:11px"><a id="add_external" href="#" class="add-external-network" title="Ajouter un réseau externe" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? 'hidden' : '' ?>>+</a></div> |
</div> |
<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div> |
</div> |
<? endforeach; ?> |
</div><div class="alcasar"> |
<div data-network-type="alcasar"> |
<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div> |
<div class="network-box"> |
<!-- <div class="actions actions-externals"> |
<div><a href="#" class="add-external-network" title="Ajouter un réseau externe">+</a></div> |
</div> --> |
<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div> |
<!-- <div class="actions actions-internals"> |
<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div> |
697,7 → 986,7 |
</div> |
<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div> |
</div> |
</div><div class="internals"> |
</div><div id="internals_id" class="internals" data-count="1"> |
<?php foreach ($internalNetworks as $network): ?> |
<div data-network-type="internal"> |
<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div> |
710,6 → 999,18 |
<? endforeach; ?> |
</div> |
</div> |
<?php if ($ext_conf_error == true) { |
echo '<span style="color:red">'; |
$temp = 0; |
while (isset($ext_conf_error_list[$temp])) { |
echo $ext_conf_error_list[$temp].'<br>'; |
$temp++; |
} |
echo '</span>'; |
} |
else if (($choix === 'network_change') && ($modification_proxy || $modification_dns || $modification_network)) { |
echo '<span id="change_success" style="color:green">'.$l_change_successful.'</span>'; |
}?> |
<hr> |
<div style="text-align: center; margin: 5px"> |
<input type="hidden" name="choix" value="network_change"> |
741,6 → 1042,7 |
$mac_addr = $fields[0]; |
$ip_addr = $fields[1]; |
$info = (isset($fields[2])) ? implode(' ', array_slice($fields, 2)) : ' '; |
|
echo '<tr>'; |
echo "<td>$mac_addr</td>"; |
echo "<td>$ip_addr</td>"; |