1,41 → 1,56 |
<?php |
# $Id$ |
|
/* written by steweb57 & Rexy */ |
// written by steweb57, Rexy & Tom HOUDAYER |
|
/******************** |
* READ CONF FILES * |
* READ CONF FILES * |
*********************/ |
define ("CONF_FILE", "/usr/local/etc/alcasar.conf"); |
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers"); |
define ("ETHERS_INFO_FILE", "/usr/local/etc/alcasar-ethers-info"); |
define ("DNS_LOCAL_FILE", "/usr/local/etc/alcasar-dns-name"); |
define('CONF_FILE', '/usr/local/etc/alcasar.conf'); |
define('ETHERS_FILE', '/usr/local/etc/alcasar-ethers'); |
define('ETHERS_INFO_FILE', '/usr/local/etc/alcasar-ethers-info'); |
define('DNS_LOCAL_FILE', '/usr/local/etc/alcasar-dns-name'); |
define('LETS_ENCRYPT_FILE', '/usr/local/etc/alcasar-letsencrypt'); |
$conf_files=array(CONF_FILE,ETHERS_FILE,ETHERS_INFO_FILE,DNS_LOCAL_FILE, LETS_ENCRYPT_FILE); |
$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]))$/'; |
$network_modification=0; |
foreach ($conf_files as $file){ |
if (!file_exists($file)){ |
exit("Requested file ".$file." isn't present");} |
if (!is_readable($file)){ |
exit("Can't read the file ".$file);} |
$conf_files = [CONF_FILE, ETHERS_FILE, ETHERS_INFO_FILE, DNS_LOCAL_FILE, LETS_ENCRYPT_FILE]; |
|
// Files reading test |
foreach ($conf_files as $file) { |
if (!file_exists($file)) { |
exit("Requested file $file isn't present"); |
} |
if (!is_readable($file)) { |
exit("Can't read the file $file"); |
} |
} |
# Choice of language |
|
// Read ALCASAR CONF_FILE |
$file_conf = fopen(CONF_FILE, 'r'); |
if (!$file_conf) { |
exit('Error opening the file '.CONF_FILE); |
} |
while (!feof($file_conf)) { |
$buffer = fgets($file_conf, 4096); |
if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) { |
$tmp = explode('=', $buffer); |
$conf[trim($tmp[0])] = trim($tmp[1]); |
} |
} |
fclose($file_conf); |
|
// Choice of language |
$Language = 'en'; |
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){ |
$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']); |
$Language = strtolower(substr(chop($Langue[0]),0,2)); } |
if($Language == 'fr'){ |
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
$Langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); |
$Language = strtolower(substr(chop($Langue[0]), 0, 2)); |
} |
if ($Language === 'fr') { // French |
$l_network_title = "Configuration réseau"; |
$l_extif_legend = " (Interface connectée à Internet)"; |
$l_intif_legend = " (Réseau de consultation)"; |
$l_internet_legend = "INTERNET"; |
$l_ip_mask = "Masque"; |
$l_ip_router = "Passerelle"; |
$l_ip_public = "Adresse IP publique"; |
$l_ip_dns1 = "DNS1"; |
$l_ip_dns2 = "DNS2"; |
$l_ip_dns1 = "DNS n°1"; |
$l_ip_dns2 = "DNS n°2"; |
$l_dhcp_title = "Service DHCP"; |
$l_dhcp_state = "Mode actuel"; |
$l_DHCP_on = "actif"; |
57,16 → 72,15 |
$l_import = "Importer"; |
$l_current_certificate = "Certificat actuel"; |
$l_validated = "Validé par :"; |
} else { |
$l_empty = "Vide"; |
} else { // English |
$l_network_title = "Network configuration"; |
$l_extif_legend = " (Internet connected interface)"; |
$l_intif_legend = " (Private network)"; |
$l_internet_legend = "INTERNET"; |
$l_ip_mask = "Mask"; |
$l_ip_router = "Gateway"; |
$l_ip_public = "Public IP address"; |
$l_ip_dns1 = "DNS1"; |
$l_ip_dns2 = "DNS2"; |
$l_ip_dns1 = "DNS n°1"; |
$l_ip_dns2 = "DNS n°2"; |
$l_dhcp_title = "DHCP service"; |
$l_dhcp_state = "Current mode"; |
$l_DHCP_on = "enabled"; |
88,353 → 102,600 |
$l_import = "Import"; |
$l_current_certificate = "Current certificate"; |
$l_validated = "Validated by :"; |
$l_empty = "Empty"; |
} |
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";} |
switch ($choix) |
{ |
case 'DHCP_On' : |
exec ("sudo /usr/local/bin/alcasar-dhcp.sh -on"); |
break; |
case 'DHCP_Off' : |
exec ("sudo /usr/local/bin/alcasar-dhcp.sh -off"); |
break; |
case 'new_mac' : |
if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != "")) |
{ |
$tab=file(ETHERS_FILE); |
if ($tab) # the file isn't empty |
{ |
$insert="True"; |
$new_mac_addr=trim($_POST['add_mac'],"\x00..\x20"); |
$new_ip_addr=trim($_POST['add_ip'],"\x00..\x20"); |
foreach ($tab as $line) # verify that MAC or IP address doesn't exist |
{ |
$field=explode(" ", $line); |
$mac_addr=trim($field[0]);$ip_addr=trim($field[1]); |
if (strcasecmp($new_mac_addr, $mac_addr) == 0) |
{ |
$insert="False"; |
break; |
|
$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]))$/'; |
|
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : ''; |
|
switch ($choix) { |
case 'DHCP_On': |
exec('sudo /usr/local/bin/alcasar-dhcp.sh -on'); |
break; |
case 'DHCP_Off': |
exec('sudo /usr/local/bin/alcasar-dhcp.sh -off'); |
break; |
|
case 'new_mac': |
if ((!empty(trim($_POST['add_mac']))) && (!empty(trim($_POST['add_ip'])))) { |
$tab = file(ETHERS_FILE); |
if ($tab) { // the file isn't empty |
$insert = true; |
$new_mac_addr = trim($_POST['add_mac'], "\x00..\x20"); |
$new_ip_addr = trim($_POST['add_ip'], "\x00..\x20"); |
foreach ($tab as $line) { // verify that MAC or IP address doesn't exist |
$field = explode(' ', $line); |
$mac_addr = trim($field[0]); |
$ip_addr = trim($field[1]); |
if (strcasecmp($new_mac_addr, $mac_addr) === 0) { |
$insert = false; |
break; |
} |
if (strcasecmp($new_ip_addr, $ip_addr) == 0) |
{ |
$insert="False"; |
break; |
if (strcasecmp($new_ip_addr, $ip_addr) === 0) { |
$insert = false; |
break; |
} |
} |
if ($insert == "True") |
{ |
$line = $new_mac_addr . " " . $new_ip_addr . "\n"; |
$pointeur=fopen(ETHERS_FILE,"a"); |
fwrite ($pointeur, $line); |
fclose ($pointeur); |
$pointeur=fopen(ETHERS_INFO_FILE,"a"); |
$line = $new_mac_addr . " " . $new_ip_addr . " #" . trim($_POST['info'],"\x00..\x20") . "\n"; |
fwrite ($pointeur, $line); |
fclose ($pointeur); |
exec ("sudo /usr/bin/systemctl reload chilli"); |
if ($insert) { |
$line = $new_mac_addr . ' ' . $new_ip_addr . "\n"; |
$pointeur = fopen(ETHERS_FILE, 'a'); |
fwrite($pointeur, $line); |
fclose($pointeur); |
$pointeur = fopen(ETHERS_INFO_FILE, 'a'); |
$line = "$new_mac_addr $new_ip_addr #" . trim($_POST['info'],"\x00..\x20") . "\n"; |
fwrite($pointeur, $line); |
fclose($pointeur); |
exec('sudo /usr/bin/systemctl reload chilli'); |
} |
} |
} |
break; |
case 'del_mac' : |
foreach ($_POST as $key => $value) |
{ |
if ($value == 'on') |
{ |
$ether_file=ETHERS_FILE; |
exec("/bin/sed -i \"/^$key/d\" $ether_file"); |
$ether_file=ETHERS_INFO_FILE; |
exec("/bin/sed -i \"/^$key/d\" $ether_file"); |
exec ("sudo /usr/bin/systemctl reload chilli"); |
break; |
case 'del_mac': |
foreach ($_POST as $key => $value) { |
if ($value == 'on') { |
$ether_file = ETHERS_FILE; |
$ether_file_info = ETHERS_INFO_FILE; |
exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file"); |
exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info"); |
exec('sudo /usr/bin/systemctl reload chilli'); |
} |
} |
break; |
case 'new_host' : |
if ((trim($_POST['add_host']) != "") and (trim($_POST['add_ip']) != "")) |
{ |
$tab=file(DNS_LOCAL_FILE); |
$insert="True"; |
if ($tab) # the file isn't empty |
{ |
foreach ($tab as $line) # verify that host or IP address doesn't exist |
{ |
if (preg_match ('/^address/', $line)) |
{ |
$field=explode("/", $line); |
$host_name=trim($field[1]);$ip_addr=trim($field[2]); |
if (strcasecmp(trim($_POST['add_host']),trim($host_name)) == 0) |
{ |
$insert="False"; |
break; |
break; |
|
case 'new_host': |
if ((!empty(trim($_POST['add_host']))) and (!empty(trim($_POST['add_ip'])))) { |
$tab = file(DNS_LOCAL_FILE); |
if ($tab) { // the file isn't empty |
$insert = true; |
foreach ($tab as $line) { // verify that host or IP address doesn't exist |
if (preg_match('/^address/', $line)) { |
$field = explode('/', $line); |
$host_name = trim($field[1]); |
$ip_addr = trim($field[2]); |
if (strcasecmp(trim($_POST['add_host']), trim($host_name)) === 0) { |
$insert = false; |
break; |
} |
if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0) |
{ |
$insert="False"; |
break; |
if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) === 0) { |
$insert = false; |
break; |
} |
} |
} |
if ($insert == "True") |
{ |
$line1 = "address=/".trim($_POST['add_host'])."/".trim($_POST['add_ip'])."\n"; |
$explode_ip=explode('.',trim($_POST['add_ip'])); |
$reverse_ip=implode('.',array_reverse($explode_ip)); |
$line2 = "ptr-record=".$reverse_ip.".in-addr.arpa,".trim($_POST['add_host'])."\n"; |
$pointeur=fopen(DNS_LOCAL_FILE,"a"); |
fwrite ($pointeur, $line1); |
fwrite ($pointeur, $line2); |
fclose ($pointeur); |
exec ("sudo /usr/bin/systemctl restart dnsmasq"); |
exec ("sudo /usr/bin/systemctl restart dnsmasq-blacklist"); |
exec ("sudo /usr/bin/systemctl restart dnsmasq-whitelist"); |
if ($insert) { |
$line1 = 'address=/'.trim($_POST['add_host']).'/'.trim($_POST['add_ip'])."\n"; |
$explode_ip = explode('.', trim($_POST['add_ip'])); |
$reverse_ip = implode('.', array_reverse($explode_ip)); |
$line2 = 'ptr-record='.$reverse_ip.'.in-addr.arpa,'.trim($_POST['add_host'])."\n"; |
$pointeur=fopen(DNS_LOCAL_FILE, 'a'); |
fwrite($pointeur, $line1); |
fwrite($pointeur, $line2); |
fclose($pointeur); |
exec('sudo /usr/bin/systemctl restart dnsmasq'); |
exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist'); |
exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist'); |
} |
} |
} |
break; |
case 'del_host': |
foreach ($_POST as $key => $value) { |
if ($value == 'on') { |
$dns_local_file = DNS_LOCAL_FILE; |
exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $dns_local_file"); |
exec('sudo /usr/bin/systemctl restart dnsmasq'); |
exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist'); |
exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist'); |
} |
} |
break; |
case 'del_host' : |
foreach ($_POST as $key => $value) |
{ |
if ($value == 'on') |
{ |
$dns_local_file=DNS_LOCAL_FILE; |
exec("/bin/sed -i \"/$key/d\" $dns_local_file"); |
exec ("sudo /usr/bin/systemctl restart dnsmasq"); |
exec ("sudo /usr/bin/systemctl restart dnsmasq-blacklist"); |
exec ("sudo /usr/bin/systemctl restart dnsmasq-whitelist"); |
break; |
|
case 'default_cert': // Restore default certificate |
exec('sudo alcasar-importcert.sh -d'); |
break; |
|
case 'import_cert': // Import certificate |
if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) { |
if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) { |
if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt') { |
$dest = '/tmp/'; |
$scpath = ""; |
if (isset($_FILES['sc']) && (pathinfo($_FILES['sc']['name'])['extension'] == 'crt')) { |
$scpath = $dest.'server-chain.crt'; |
move_uploaded_file($_FILES['sc']['tmp_name'], $scpath); |
} |
$keypath = $dest."alcasar.key"; |
$crtpath = $dest."alcasar.crt"; |
move_uploaded_file($_FILES['key']['tmp_name'], $keypath); |
move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath); |
exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath"); |
if (file_exists($crtpath)) unlink($crtpath); |
if (file_exists($keypath)) unlink($keypath); |
if (file_exists($scpath)) unlink($scpath); |
} |
} |
} |
break; |
break; |
} |
|
// Fonction de test de connectivité internet |
function internetTest(){ |
$host = "www.google.fr"; # Google Test |
$port = "80"; |
//var $num; //not used |
//var $error; //not used |
// Network changes |
if ($choix === 'network_change') { |
$network_modification = false; |
|
if (! $sock = @fsockopen($host, $port, $num, $error, 5)) { |
return false; |
} else { |
fclose($sock); |
return true; |
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; |
} |
} |
/*********************************** |
* Update ALCASAR_CONF_FILE * |
***********************************/ |
/******************************************* |
* Read ALCASAR_CONF_FILE Before * |
********************************************/ |
$file_conf = fopen(CONF_FILE, 'r'); |
if (!$file_conf) { |
exit('Error opening the file '.CONF_FILE); |
} |
while (!feof($file_conf)) { |
$buffer = fgets($file_conf, 4096); |
if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) { |
$tmp = explode('=', $buffer); |
$conf[trim($tmp[0])] = trim($tmp[1]); |
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['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_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 ($network_modification) { |
exec('sudo /usr/local/bin/alcasar-conf.sh -apply'); |
} |
|
// Read CONF_FILE updated |
$file_conf = fopen(CONF_FILE, 'r'); |
if (!$file_conf) { |
exit('Error opening the file '.CONF_FILE); |
} |
while (!feof($file_conf)) { |
$buffer = fgets($file_conf, 4096); |
if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) { |
$tmp = explode('=', $buffer); |
$conf[trim($tmp[0])] = trim($tmp[1]); |
} |
} |
fclose($file_conf); |
} |
fclose($file_conf); |
|
// Let's Encrypt actions |
if ($choix === 'le_issueCert') { |
// TODO: check ndd & mail format |
|
$email = $_POST['email']; |
$domainName = $_POST['domainname']; |
|
exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode); |
|
if(isset($_POST['dns1']) && preg_match($reg_ip,$_POST['dns1'])) |
{ |
file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'],'DNS1='.$_POST['dns1']."\n",file_get_contents(CONF_FILE))); |
$network_modification=1; |
$cmdResponse = implode("<br>\n", $output); |
} |
if(isset($_POST['dns2']) && preg_match($reg_ip,$_POST['dns2'])) |
{ |
file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'],'DNS2='.$_POST['dns2']."\n",file_get_contents(CONF_FILE))); |
$network_modification=1; |
} |
if ($choix === 'le_renewCert') { |
if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) { |
$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : ''; |
|
if(isset($_POST['ip_public']) && preg_match($reg_ip_cidr,$_POST['ip_public'])) |
{ |
file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'],'PUBLIC_IP='.$_POST['ip_public']."\n",file_get_contents(CONF_FILE))); |
$network_modification=1; |
} |
exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode); |
|
if(isset($_POST['ip_gw']) && preg_match($reg_ip,$_POST['ip_gw'])) |
{ |
file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'],'GW='.$_POST['ip_gw']."\n",file_get_contents(CONF_FILE))); |
$network_modification=1; |
$cmdResponse = implode("<br>\n", $output); |
} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) { |
file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE))); |
file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE))); |
} |
} |
|
if(isset($_POST['ip_private']) && preg_match($reg_ip_cidr,$_POST['ip_private'])) |
{ |
file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'],'PRIVATE_IP='.$_POST['ip_private']."\n",file_get_contents(CONF_FILE))); |
$network_modification=1; |
} |
if($network_modification) |
{ |
exec("sudo /usr/local/bin/alcasar-conf.sh -apply"); |
} |
|
/******************************************* |
* Read ALCASAR_CONF_FILE Updated * |
********************************************/ |
$file_conf = fopen(CONF_FILE, 'r'); |
if (!$file_conf) { |
exit('Error opening the file '.CONF_FILE); |
// Read Let's Encrypt configuration file |
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r'); |
if (!$file_conf_LE) { |
exit('Error opening the file '.LETS_ENCRYPT_FILE); |
} |
while (!feof($file_conf)) { |
$buffer = fgets($file_conf, 4096); |
while (!feof($file_conf_LE)) { |
$buffer = fgets($file_conf_LE, 4096); |
if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) { |
$tmp = explode('=', $buffer); |
$conf[trim($tmp[0])] = trim($tmp[1]); |
$LE_conf[trim($tmp[0])] = trim($tmp[1]); |
} |
} |
fclose($file_conf); |
fclose($file_conf_LE); |
|
|
// Fonction de test de connectivité internet |
function internetTest() { |
$host = 'www.google.fr'; # Google Test |
$port = '80'; |
|
if (! $sock = @fsockopen($host, $port, $num, $error, 5)) { |
return false; |
} else { |
fclose($sock); |
return true; |
} |
} |
|
$internet_connected = InternetTest(); |
if ($internet_connected) { |
$internet_publicIP = file_get_contents('http://ipecho.net/plain'); |
} else { |
$internet_publicIP = '-.-.-.-'; |
} |
|
|
// Network interfaces |
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['EXTIF'], $conf['INTIF']]; |
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable); |
|
// TODO: Pending the next version |
$externalNetworks = [ |
(object) [ |
'interface' => $conf['EXTIF'], |
'ip' => $conf['PUBLIC_IP'], |
'gateway' => $conf['GW'] |
] |
]; |
$internalNetworks = [ |
(object) [ |
'interface' => $conf['INTIF'], |
'ip' => $conf['PRIVATE_IP'] |
] |
]; |
|
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
<html><!-- written by steweb57 & rexy --> |
<html> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
<title><?php echo $l_network_title; ?></title> |
<link rel="stylesheet" href="/css/style.css" type="text/css"> |
<script type="text/javascript"> |
function MAC_Control(formulaire){ |
/*MAC control (upper case and '-' separator*/ |
var regex1 = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/; //vérification adresse mac |
if (regex1.test(document.forms[formulaire].add_mac.value)){ |
document.forms[formulaire].add_mac.value=document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-'); |
return true; |
} else { |
alert("Invalid MAC address");//non internationnalisé |
return false; |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
<title><?= $l_network_title ?></title> |
<link rel="stylesheet" href="/css/style.css" type="text/css"> |
<link rel="stylesheet" href="/css/acc.css" type="text/css"> |
<script src="/js/jquery.min.js"></script> |
<script src="/js/jquery.connections.js"></script> |
<script type="text/javascript"> |
function MAC_Control(formulaire){ |
// MAC control (upper case and '-' separator) |
var regex_mac = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/; |
if (regex_mac.test(document.forms[formulaire].add_mac.value)){ |
document.forms[formulaire].add_mac.value = document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-'); |
return true; |
} else { |
alert('Invalid MAC address'); |
return false; |
} |
} |
} |
</script> |
</script> |
<style> |
.network-configurator { |
width: 100%; |
} |
.network-configurator > * { |
display: inline-block; |
vertical-align: top; |
text-align: center; |
} |
.network-configurator > .internet, .network-configurator > .alcasar { |
width: 20%; |
} |
.network-configurator > .externals, .network-configurator > .internals { |
width: 30%; |
} |
.network-configurator .actions { |
position: absolute; |
background-color: #ddd; |
padding: 0 2px; |
} |
.network-configurator .actions a { |
text-decoration: none; |
} |
.network-configurator .actions a:hover { |
font-weight: bold; |
} |
.network-configurator > .alcasar .actions-externals { |
bottom: 0; |
left: 0; |
border-radius: 0 5px; |
} |
.network-configurator > .alcasar .actions-internals { |
bottom: 0; |
right: 0; |
border-radius: 5px 0; |
} |
.network-configurator .actions-network { |
top: 0; |
right: 0; |
border-radius: 0 5px; |
} |
.network-configurator .network-box { |
display: inline-block; |
min-height: 100px; |
margin: 5px; |
padding: 3px; |
text-align: left; |
background-color: #f7f3ef; |
position: relative; |
border-radius: 5px; |
border: 2px solid grey; |
} |
.network-configurator .network-connector { |
display: inline-block; |
position: absolute; |
top: 50%; |
margin-top: -5px; |
margin-left: -5px; |
width: 10px; |
height: 10px; |
border-radius: 5px; |
background-color: black; |
} |
.network-configurator .network-connector[data-connector-direction="left"] { |
border-radius: 5px 0px 0px 5px; |
} |
.network-configurator .network-connector[data-connector-direction="right"] { |
border-radius: 0px 5px 5px 0px; |
} |
.network-configurator div[data-network-type] { |
position: relative; |
} |
</style> |
<script> |
$(document).ready(function () { |
const interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>; |
|
const wireStyles = { |
available: { border: '5px double green' } |
} |
|
// Add external network |
$('.network-configurator .add-external-network').click(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')); |
}); |
|
// Add internal network |
$('.network-configurator .add-internal-network').click(function (event) { |
event.preventDefault(); |
$('.network-configurator .internals').append(' \ |
<div data-network-type="internal"> \ |
<div class="network-connector" data-connector-network="internal" 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="int_interface_X"><?= 'Interface' ?></label> <select name="interface" id="int_interface_X" disabled><option value=""></option></select><br> \ |
<label for="int_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_X" value="" /><br> \ |
</div> \ |
</div>'); |
addWire($('div[data-network-type="internal"]:last')); |
}); |
|
// Remove network |
$('.network-configurator').on('click', '.remove-network', function (event) { |
event.preventDefault(); |
$(this).parent().parent().parent().fadeOut(200, function() { |
const networkType = $(this).data('networkType'); |
$(this).remove(); |
|
// 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'); |
} |
}); |
}); |
|
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' }); |
} |
} |
|
// Add wires to existing networks |
$('div[data-network-type="external"]').add('div[data-network-type="internal"]').each(function (index, element) { |
addWire($(this)); |
}) |
}); |
</script> |
</head> |
<body> |
<div class="panel"> |
<div class="panel-header"><?= $l_network_title ?></div> |
<div class="panel-body"> |
<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post"> |
<div class="network-configurator"> |
<div class="internet"> |
<div data-network-type="internet"> |
<div class="network-box"> |
<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br> |
<?= $l_ip_public ?> : <?= $internet_publicIP ?><br> |
<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br> |
<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" /> |
</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 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> |
<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> |
<div><a href="#" class="add-internal-wifi-network">++</a></div> |
</div> --> |
</div> |
<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div> |
</div> |
</div><div class="internals"> |
<?php foreach ($internalNetworks as $network): ?> |
<div data-network-type="internal"> |
<div class="network-connector" data-connector-network="internal" 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="int_interface_<?= $index ?>"><?= 'Interface' ?></label> <select name="int_interface[<?= $index ?>]" id="int_interface_<?= $index ?>" disabled><option value="<?= $network->interface ?>"><?= $network->interface ?></option></select><br> |
<label for="int_ip_<?= $index ?>"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_<?= $index ?>" value="<?= $network->ip ?>" /><br> |
</div> |
</div> |
<? endforeach; ?> |
</div> |
</div> |
<hr> |
<div style="text-align: center; margin: 5px"> |
<input type="hidden" name="choix" value="network_change"> |
<input type="submit" value="<?= $l_apply ?>"> |
</div> |
</form> |
</div> |
</div> |
<br> |
|
<table width="100%" cellspacing="0" cellpadding="0" border="0"> |
<tr><th><?php echo $l_network_title; ?></th></tr> |
<tr><th><?= $l_dhcp_title?></th></tr> |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr> |
</table> |
<? echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";?> |
<table width="100%" cellspacing="0" cellpadding="5" border="1"> |
<tr><td valign="middle" align="left"> |
<fieldset> |
<legend><?php echo $l_internet_legend; |
if (InternetTest()){ |
echo " <img src='/images/state_ok.gif'>"; |
$IP_PUB = exec ("wget http://ipecho.net/plain -O - -o /dev/null");} |
else { |
echo " <img src='/images/state_error.gif'>"; |
$IP_PUB = "-.-.-.-";} |
?></legend> |
<table> |
<tr><td><?php echo $l_ip_public." : ".$IP_PUB;?></td></tr> |
<?php |
echo '<tr><td>'.$l_ip_dns1.' <input style="width:120px" type="text" name="dns1" value="'.$conf['DNS1'].'" /></td></tr>'; |
echo '<tr><td>'.$l_ip_dns2.' <input style="width:120px" type="text" name="dns2" value="'.$conf['DNS2'].'" /></td></tr>'; |
?> |
</table> |
</fieldset> |
</td><td> |
<fieldset> |
<legend><?php echo $conf['EXTIF'].$l_extif_legend; ?></legend> |
<table> |
<?php |
echo '<tr><td>'.$l_ip_address.' <input style="width:150px" type="text" name="ip_public" value="'.$conf['PUBLIC_IP'].'" /></td></tr>'; |
echo '<tr><td>'.$l_ip_router.' <input style="width:120px" type="text" name="ip_gw" value="'.$conf['GW'].'" /></td></tr>'; |
?> |
</table> |
</fieldset> |
</td><td> |
<fieldset> |
<legend><?php echo $conf['INTIF'].$l_intif_legend; ?></legend> |
<table> |
<tr><td colspan="2" valign="middle" align="left"> |
<center><h3><?= $l_dhcp_state ?> : <?= ${'l_DHCP_'.$conf['DHCP']} ?></h3></center> |
<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST"> |
<select name="choix">"; |
<option value="DHCP_Off"<?= ((!strcmp($conf['DHCP'], 'off')) ? ' selected' : '') ?>><?= $l_DHCP_off ?></option> |
<option value="DHCP_On"<?= ((!strcmp($conf['DHCP'], 'on')) ? ' selected' : '') ?>><?= $l_DHCP_on ?></option> |
</select> |
<input type="submit" value="<?= $l_apply ?>"> |
<br><?= $l_DHCP_off_explain ?> |
</form> |
</td></tr> |
|
<?php |
echo '<tr><td>'.$l_ip_address.'</td><td> <input style="width:150px" type="text" name="ip_private" value="'.$conf['PRIVATE_IP'].'" /></td></tr>'; |
if ($conf['DHCP'] === 'on') { |
require('network2.php'); |
} |
?> |
</table> |
</fieldset> |
</td></tr> |
<tr><td colspan="3" align="center"> |
<?php echo "<input type='submit' value='$l_apply'>";?> |
</td></tr> |
</table> |
</form> |
<table width="100%" cellspacing="0" cellpadding="0" border="0"> |
<tr><th><?php echo $l_dhcp_title;?></th></tr> |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr> |
</table> |
<table width="100%" cellspacing="0" cellpadding="5" border="1"> |
<tr><td colspan="2" valign="middle" align="left"> |
<? |
$dhcp_state=trim($conf["DHCP"]); |
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>"; |
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>"; |
echo "<select name='choix'>"; |
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off"; |
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on"; |
echo "</select>"; |
echo "<input type=submit value='$l_apply'>"; |
echo "<br>$l_DHCP_off_explain"; |
<br> |
|
echo "</FORM>"; |
echo "</td></tr>"; |
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');} |
else { echo "</table>"; } |
$maxsize=100000; |
?> |
|
<table width="100%" cellspacing="0" cellpadding="0" border="0"> |
<tr><th><?php echo $l_local_dns;?></th></tr> |
<tr><th><?= $l_local_dns?></th></tr> |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr> |
</table> |
<table width="100%" cellspacing="0" cellpadding="5" border="1"> |
<tr><td width="50%" align="center"> |
<? |
echo "<FORM action='network.php' method='POST'>"; |
echo "<table cellspacing=2 cellpadding=3 border=1>"; |
echo "<tr><th>$l_host_name<th>$l_ip_address<th>$l_del</tr>"; |
// Read the "dns_local" file |
$line_exist=False; |
$tab=file(DNS_LOCAL_FILE); |
if ($tab) # not empty |
{ |
foreach ($tab as $line) |
{ |
if (preg_match ('/^address/', $line)) |
{ |
$line_exist=True; |
$field=explode("/", $line); |
$host_name=$field[1]; |
$ip_addr=$field[2]; |
echo "<tr><td>$host_name"; |
echo "<td>$ip_addr"; |
echo "<td><input type='checkbox' name='$host_name'>"; |
echo "</tr>"; |
<tr> |
<td width="50%" align="center"> |
<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST"> |
<table cellspacing="2" cellpadding="3" border="1"> |
<tr><th><?= $l_host_name ?></th><th><?= $l_ip_address ?></th><th><?= $l_del ?></th></tr> |
<?php |
// Read the "dns_local" file |
$line_exist = false; |
$tab = file(DNS_LOCAL_FILE); |
if ($tab) { // not empty |
foreach ($tab as $line) { |
if (preg_match ('/^address/', $line)) { |
$line_exist = true; |
$field = explode('/', $line); |
$host_name = $field[1]; |
$ip_addr = $field[2]; |
echo "<tr><td>$host_name</td>"; |
echo "<td>$ip_addr</td>"; |
echo "<td><input type=\"checkbox\" name=\"$host_name\"></td>"; |
echo "</tr>"; |
} |
} |
} |
} |
echo "</table>"; |
if ($line_exist) |
{ |
echo "<input type='hidden' name='choix' value='del_host'>"; |
echo "<input type='submit' value='$l_apply'>"; |
} |
echo "</form></td><td width=\"50%\" valign='middle' align='center'>"; |
echo "<FORM name='new_host' action='network.php' method='POST'>"; |
echo "<table cellspacing=2 cellpadding=3 border=1>"; |
echo "<tr><th>$l_host_name<th>$l_ip_address"; |
?> |
<td></td></tr> |
<tr><td>Ex. : my_nas</td><td>Ex. : 192.168.182.10</td><td></td></tr> |
<tr><td><input type='text' name='add_host' size='17'></td> |
<td><input type='text' name='add_ip' size='10'><input type='hidden' name='choix' value='new_host'></td> |
<td><? echo "<input type=submit class=button value=\"$l_add_to_list\">"?></td> |
</tr></table> |
</form> |
</td></tr> |
if (!$line_exist) { |
echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>'; |
} |
?> |
</table> |
<?php if ($line_exist): ?> |
<input type="hidden" name="choix" value="del_host"> |
<input type="submit" value="<?= $l_apply ?>"> |
<?php endif; ?> |
</form> |
</td> |
<td width="50%" valign="middle" align="center"> |
<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST"> |
<table cellspacing="2" cellpadding="3" border="1"> |
<tr> |
<th><?= $l_host_name ?></th><th><?= $l_ip_address ?></th><td></td> |
</tr> |
<tr> |
<td>Ex. : my_nas</td><td>Ex. : 192.168.182.10</td><td></td> |
</tr> |
<tr> |
<td><input type="text" name="add_host" size="17"></td> |
<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td> |
<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td> |
</tr> |
</table> |
</form> |
</td> |
</tr> |
</table> |
<br> |
|
<table width="100%" cellspacing="0" cellpadding="0" border="0"> |
<tr><th><?php echo $l_import_cert;?></th></tr> |
<tr><th><?= $l_import_cert ?></th></tr> |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr> |
</table> |
<table width="100%" cellspacing="0" cellpadding="5" border="1"> |
441,12 → 702,12 |
<tr> |
<td width="50%"> |
<h3>Importer un certificat existant</h3> |
<form method="post" action="network.php" enctype="multipart/form-data"> |
<?php echo $l_private_key;?> <input type="file" name="key"><br> |
<?php echo $l_certificate;?> <input type="file" name="crt"><br> |
<?php echo $l_server_chain;?> <input type="file" name="sc"> |
<input type="hidden" name="MAX_FILE_SIZE" value=<?php echo $maxsize;?>><br> |
<input type="submit" <?php echo "value=\"".$l_import."\""?>> |
<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data"> |
<?= $l_private_key;?> <input type="file" name="key"><br> |
<?= $l_certificate;?> <input type="file" name="crt"><br> |
<?= $l_server_chain;?> <input type="file" name="sc"><br> |
<input type="hidden" name="choix" value="import_cert"> |
<input type="submit" value="<?= $l_import ?>"> |
</form> |
|
<?php |
458,7 → 719,10 |
$CAdomain = $certificateInfos['issuer']['CN']; |
$CAorganization = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : ''; |
?> |
|
<br> |
<hr> |
|
<h3><?= $l_current_certificate ?></h3> |
Expiration Date : <?= $cert_expiration_date ?><br> |
Common name : <?= $domain ?><br> |
468,51 → 732,13 |
Organization : <?= $CAorganization ?><br> |
|
<br> |
<form method="post" action="network.php"> |
<input type="hidden" name="default"> |
<input type="submit" <?php echo "value=\"".$l_default_cert."\""; if(!file_exists("/etc/pki/tls/certs/alcasar.crt.old") || !file_exists("/etc/pki/tls/private/alcasar.key.old")){ echo " disabled";}?>> |
<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>"> |
<input type="hidden" name="choix" value="default_cert"> |
<input type="submit" value="<?= $l_default_cert ?>" <?= (!file_exists('/etc/pki/tls/certs/alcasar.crt.old') || !file_exists('/etc/pki/tls/private/alcasar.key.old')) ? ' disabled' : '' ?>> |
</form> |
</td> |
<td width="50%" valign="top"> |
<?php |
// Let's Encrypt actions |
if ((isset($_POST['action']) && ($_POST['action'] === 'le_issueCert'))) { |
// TODO: check ndd & mail format |
|
$email = $_POST['email']; |
$domainName = $_POST['domainname']; |
|
exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode); |
|
$cmdResponse = implode("<br>\n", $output); |
} |
if ((isset($_POST['action']) && ($_POST['action'] === 'le_renewCert'))) { |
if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) { |
$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : ''; |
|
exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode); |
|
$cmdResponse = implode("<br>\n", $output); |
} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) { |
file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE))); |
file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE))); |
} |
} |
|
// Read Let's Encrypt configuration file |
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r'); |
if (!$file_conf_LE) { |
exit('Error opening the file '.LETS_ENCRYPT_FILE); |
} |
while (!feof($file_conf_LE)) { |
$buffer = fgets($file_conf_LE, 4096); |
if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) { |
$tmp = explode('=', $buffer); |
$LE_conf[trim($tmp[0])] = trim($tmp[1]); |
} |
} |
fclose($file_conf_LE); |
|
// Get step |
if (empty($LE_conf['domainRequest'])) { |
$step = 1; |
526,8 → 752,8 |
?> |
<h3>Intégration Let's Encrypt</h3> |
<?php if ($step === 1) : ?> |
<form method="post" action="network.php"> |
<input type="hidden" name="action" value="le_issueCert"> |
<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>"> |
<input type="hidden" name="choix" value="le_issueCert"> |
Status : Inactif<br> |
Email : <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br> |
Nom de domaine : <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br> |
534,8 → 760,8 |
<input type="submit" name="issue" value="Envoyer"><br> |
</form> |
<?php elseif ($step === 2): ?> |
<form method="post" action="network.php"> |
<input type="hidden" name="action" value="le_renewCert"> |
<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>"> |
<input type="hidden" name="choix" value="le_renewCert"> |
Status : En attente de validation<br> |
Nom de domaine : <?= $LE_conf['domainRequest'] ?><br> |
Demandé le : <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br> |
544,8 → 770,8 |
<input type="submit" name="recheck" value="Revérifier"> <input type="submit" name="cancel" value="Annuler"><br> |
</form> |
<?php elseif ($step === 3): ?> |
<form method="post" action="network.php"> |
<input type="hidden" name="action" value="le_renewCert"> |
<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>"> |
<input type="hidden" name="choix" value="le_renewCert"> |
Status : Actif<br> |
Nom de domaine : <?= $LE_conf['domainRequest'] ?><br> |
API : <?= $LE_conf['dnsapi'] ?><br> |
565,37 → 791,3 |
</table> |
</body> |
</html> |
|
<?php |
if(isset($_POST['default'])){ |
echo "$l_default_cert"; |
exec("sudo alcasar-importcert.sh -d"); |
} |
if(isset($_POST['MAX_FILE_SIZE'])){ |
$maxsize = 100000; |
if(isset($_FILES['key']) && isset($_FILES['crt']) && $_FILES['key']['error'] == 0 && $_FILES['crt']['error'] == 0){ |
$dest = "/tmp/"; |
if($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) |
{ |
if(pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt') |
{ |
$scpath = ""; |
if(isset($_FILES['sc']) && pathinfo($_FILES['sc']['name'])['extension'] == 'crt') |
{ |
$scpath = $dest."server-chain.crt"; |
move_uploaded_file($_FILES['sc']['tmp_name'], $scpath); |
} |
$keypath = $dest."alcasar.key"; |
$crtpath = $dest."alcasar.crt"; |
move_uploaded_file($_FILES['key']['tmp_name'], $keypath); |
move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath); |
exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath"); |
if (file_exists($crtpath)) unlink($crtpath); |
if (file_exists($keypath)) unlink($keypath); |
if (file_exists($scpath)) unlink($scpath); |
} |
} |
} |
} |
?> |
|