bd06fc7fbf
- Allows customization through .htaccess - No need to configure or reload a server when adding a site - Content negotiation
41 lines
2.2 KiB
PHP
41 lines
2.2 KiB
PHP
<?php
|
|
|
|
$_POST['domain'] = formatDomain($_POST['domain']);
|
|
|
|
if (dirsStatuses('dns')[$_POST['dir']] !== false)
|
|
output(403, 'Wrong value for <code>dir</code>.');
|
|
|
|
if (query('select', 'sites', ['domain' => $_POST['domain']], 'domain') !== [])
|
|
output(403, _('This domain already exists on this service. Use another one.'));
|
|
|
|
$remoteAaaaRecords = dns_get_record($_POST['domain'], DNS_AAAA);
|
|
if (is_array($remoteAaaaRecords) !== true)
|
|
output(500, sprintf(_('Can\'t retrieve the %s record.'), 'AAAA'));
|
|
if (equalArrays([CONF['ht']['ipv6_address']], array_column($remoteAaaaRecords, 'ipv6')) !== true)
|
|
output(403, sprintf(_('This domain must have %2$s as its only %1$s record.'), 'AAAA', '<code>' . CONF['ht']['ipv6_address'] . '</code>'));
|
|
|
|
$remoteARecords = dns_get_record($_POST['domain'], DNS_A);
|
|
if (is_array($remoteARecords) !== true)
|
|
output(500, sprintf(_('Can\'t retrieve the %s record.'), 'A'));
|
|
if (equalArrays([CONF['ht']['ipv4_address']], array_column($remoteARecords, 'ip')) !== true)
|
|
output(403, sprintf(_('This domain must have %2$s as its only %1$s record.'), 'A', '<code>' . CONF['ht']['ipv4_address'] . '</code>'));
|
|
|
|
$remoteTXTRecords = dns_get_record($_POST['domain'], DNS_TXT);
|
|
if (is_array($remoteTXTRecords) !== true)
|
|
output(500, sprintf(_('Can\'t retrieve the %s record.'), 'TXT'));
|
|
if (preg_match('/^' . preg_quote(SERVER_NAME, '/') . '_domain-verification=([0-9a-f]{8})-([0-9a-f]{32})$/Dm', implode(LF, array_column($remoteTXTRecords, 'txt')), $matches) !== 1)
|
|
output(403, _('No TXT record with the expected format has been found.'));
|
|
|
|
checkAuthToken($matches[1], $matches[2]);
|
|
|
|
rateLimit();
|
|
|
|
addSite($_SESSION['id'], $_POST['dir'], $_POST['domain'], 'dns');
|
|
|
|
exec('2>&1 ' . CONF['ht']['sudo_path'] . ' ' . CONF['ht']['certbot_path'] . ' certonly' . (($_SESSION['type'] === 'approved') ? '' : ' --test-cert') . ' --key-type rsa --rsa-key-size 3072 --webroot --webroot-path ' . CONF['ht']['acme_path'] . ' --domain ' . $_POST['domain'], $output, $returnCode);
|
|
if ($returnCode !== 0)
|
|
output(500, 'Certbot failed to get a Let\'s Encrypt certificate.', $output);
|
|
|
|
htRelativeSymlink('../fs/' . $_SESSION['id'] . '/' . $_POST['dir'], CONF['ht']['ht_path'] . '/uri/' . $_POST['domain']);
|
|
|
|
output(200, sprintf(_('%s added on this directory.'), PAGE_METADATA['title']));
|