Subversion Repositories ALCASAR

Rev

Rev 3302 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3302 Rev 3326
Line 1... Line 1...
1
<?php
1
<?php
2
# $Id: network.php 3302 2025-10-20 22:47:58Z rexy $
2
# $Id: network.php 3326 2026-03-01 22:35:33Z rexy $
3
// written by steweb57, Rexy, Tom HOUDAYER & Pierre RIVAULT
3
// written by steweb57, Rexy, Tom HOUDAYER & Pierre RIVAULT
4
 
4
 
5
/********************
5
/********************
6
*  READ CONF FILES  *
6
*  READ CONF FILES  *
7
*********************/
7
*********************/
Line 629... Line 629...
629
 
629
 
630
// Let's Encrypt actions
630
// Let's Encrypt actions
631
if ($choix === 'le_issueCert') {
631
if ($choix === 'le_issueCert') {
632
	$email      = $_POST['email'];
632
	$email      = $_POST['email'];
633
	$domainName = $_POST['domainname'];
633
	$domainName = $_POST['domainname'];
634
	if ((!empty($domainname)) && (preg_match($reg_domain, $domainname))) {
634
	if ((!empty($domainName)) && (preg_match($reg_domain, $domainName))) {
635
			if ((!empty($email)) && (preg_match($reg_email, $email))) {
635
			if ((!empty($email)) && (preg_match($reg_email, $email))) {
636
				exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --domain '.escapeshellarg($domainName), $output, $exitCode);}
-
 
637
			else {
-
 
638
				exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);}
636
				exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);}
-
 
637
			else {
-
 
638
				exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --domain '.escapeshellarg($domainName), $output, $exitCode);}
639
			$cmdResponse = implode("<br>\n", $output);}
639
			$cmdResponse = implode("<br>\n", $output);}
640
}
640
}
641
if ($choix === 'le_renewCert') {
-
 
642
	if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) {
-
 
643
		$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : '';
-
 
644
 
-
 
645
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
-
 
646
 
641
 
647
		$cmdResponse = implode("<br>\n", $output);
642
if ($choix === 'le_renewCert') {
648
	} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
643
	if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
649
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
644
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
650
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
645
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
-
 
646
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/email=.*/','email=', file_get_contents(LETS_ENCRYPT_FILE)));
-
 
647
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/dateIssueRequest=.*/','dateIssueRequest=', file_get_contents(LETS_ENCRYPT_FILE)));	
-
 
648
	}
-
 
649
	else {
-
 
650
		if ((isset($_POST['recheck_force'])) && (!empty($_POST['recheck_force']))) {
-
 
651
			$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : ''; }
-
 
652
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
-
 
653
		$cmdResponse = implode("<br>\n", $output);
651
	}
654
	}
652
}
655
}
653
 
656
 
654
// Read Let's Encrypt configuration file
657
// Read Let's Encrypt configuration file
655
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
658
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
Line 1303... Line 1306...
1303
<div class="panel">
1306
<div class="panel">
1304
	<div class="panel-header"><?= $l_import_cert ?></div>
1307
	<div class="panel-header"><?= $l_import_cert ?></div>
1305
	<div class="panel-row">
1308
	<div class="panel-row">
1306
		<div class="panel-cell">
1309
		<div class="panel-cell">
1307
			<?php
1310
			<?php
1308
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
1311
			$certificateInfos     = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
1309
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
1312
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
1310
			$domain               = $certificateInfos['subject']['CN'];
1313
			$domain               = $certificateInfos['subject']['CN'];
1311
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
1314
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
1312
			$CAdomain             = $certificateInfos['issuer']['CN'];
1315
			$CAdomain             = $certificateInfos['issuer']['CN'];
1313
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
1316
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
Line 1319... Line 1322...
1319
			<b><?= $l_validated ?></b> <?= $CAdomain ?> (<?= $CAorganization ?>)<br>
1322
			<b><?= $l_validated ?></b> <?= $CAdomain ?> (<?= $CAorganization ?>)<br>
1320
		</div>
1323
		</div>
1321
		<div class="panel-cell">
1324
		<div class="panel-cell">
1322
			<?
1325
			<?
1323
			if (file_exists('/etc/pki/tls/certs/alcasar.crt.old') && file_exists('/etc/pki/tls/private/alcasar.key.old')){ // An old default certificate exist ?
1326
			if (file_exists('/etc/pki/tls/certs/alcasar.crt.old') && file_exists('/etc/pki/tls/private/alcasar.key.old')){ // An old default certificate exist ?
1324
				$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt.old'));
1327
				$certificateInfos     = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt.old'));
1325
				$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
1328
				$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
1326
				$domain               = $certificateInfos['subject']['CN'];
1329
				$domain               = $certificateInfos['subject']['CN'];
1327
				$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
1330
				$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
1328
				$CAdomain             = $certificateInfos['issuer']['CN'];
1331
				$CAdomain             = $certificateInfos['issuer']['CN'];
1329
				$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
1332
				$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
Line 1350... Line 1353...
1350
			</form>
1353
			</form>
1351
		</div>
1354
		</div>
1352
		<div class="panel-cell">
1355
		<div class="panel-cell">
1353
			<?php
1356
			<?php
1354
			// Get step
1357
			// Get step
-
 
1358
			$domain=$conf['HOSTNAME'].".".$conf['DOMAIN'];
1355
			if (empty($LE_conf['domainRequest'])) {
1359
			if (empty($LE_conf['domainRequest'])) {
1356
				$step = 1;
1360
				$step = 1;
1357
			} else if (!empty($LE_conf['challenge'])) {
1361
			} else if (!empty($LE_conf['challenge'])) {
1358
				$step = 2;
1362
				$step = 2;
1359
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
1363
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
Line 1365... Line 1369...
1365
			<h3><?= $l_le_integration ?></h3>
1369
			<h3><?= $l_le_integration ?></h3>
1366
			<?php if ($step === 1): ?>
1370
			<?php if ($step === 1): ?>
1367
				<form name="new_LE"  method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" onSubmit="document.getElementById('ldoverlay').style.display='block';">
1371
				<form name="new_LE"  method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" onSubmit="document.getElementById('ldoverlay').style.display='block';">
1368
					<input type="hidden" name="choix" value="le_issueCert">
1372
					<input type="hidden" name="choix" value="le_issueCert">
1369
					<?= $l_le_status ?> <?= $l_disabled ?><br>
1373
					<?= $l_le_status ?> <?= $l_disabled ?><br>
1370
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
-
 
1371
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
1374
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
-
 
1375
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
1372
					<input type="submit" onClick="return (Domain_Control('new_LE'))" class="button" name="issue" value="<?= $l_send ?>"><br>
1376
					<input type="submit" onClick="return (Domain_Control('new_LE'))" class="button" name="issue" value="<?= $l_send ?>"><br>
1373
				</form>
1377
				</form>
1374
			<?php elseif ($step === 2): ?>
1378
			<?php elseif ($step === 2): ?>
1375
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1379
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1376
					<input type="hidden" name="choix" value="le_renewCert">
1380
					<input type="hidden" name="choix" value="le_renewCert">