<commit_before><?php

$DOMAIN="__DOMAIN__";

// resolve ip for domain
$ip = resolveIp($DOMAIN);
if (empty($ip)) {
    file_put_contents('/home/ssl.log', 'Could not resolve IP for ' . $DOMAIN);
    exit(1);
}

$response = file_get_contents('http://' . $DOMAIN . '/system/health');
if (empty($response)) {
    file_put_contents('/home/ssl.log', 'The domain ' . $DOMAIN . ' is not reachable');
    exit(1);
}

// check that the response is valid
$data = \json_decode($response);
if (!$data instanceof stdClass) {
    file_put_contents('/home/ssl.log', 'The domain ' . $DOMAIN . ' returned an invalid response');
    exit(1);
}

// check that the system is healthy
$healthy = $data->healthy ?? false;
if ($healthy !== true) {
    file_put_contents('/home/ssl.log', 'The domain ' . $DOMAIN . ' is unhealthy');
    exit(1);
}

// register cert for domain
exec('certbot --apache -d ' . $DOMAIN, $output, $exitCode);
if ($exitCode !== 0) {
    file_put_contents('/home/ssl.log', implode("\n", $output));
    exit(1);
}

// remove ssl-cron on success
unlink('/etc/cron.d/ssl');


function resolveIp(string $domain): ?string
{
    $records = dns_get_record($domain, DNS_A | DNS_AAAA);
    foreach ($records as $row) {
        if ($row['type'] === 'A') {<commit_msg>get host from env<commit_after><?php

// get host
$host = getenv('FUSIO_HOST');
if (empty($host)) {
    file_put_contents('/home/ssl.log', 'Environment variable FUSIO_HOST does not exist');
    exit(1);
}

// get domain from host
$domain = $host;
if (strpos($domain, ':') !== false) {
    $domain = explode(':', $domain)[0];
}

// resolve ip for domain
$ip = resolveIp($domain);
if (empty($ip)) {
    file_put_contents('/home/ssl.log', 'Could not resolve IP for ' . $domain);
    exit(1);
}

$response = file_get_contents('http://' . $host . '/system/health');
if (empty($response)) {
    file_put_contents('/home/ssl.log', 'The host ' . $host . ' is not reachable');
    exit(1);
}

// check that the response is valid
$data = \json_decode($response);
if (!$data instanceof stdClass) {
    file_put_contents('/home/ssl.log', 'The host ' . $host . ' returned an invalid response');
    exit(1);
}

// check that the system is healthy
$healthy = $data->healthy ?? false;
if ($healthy !== true) {
    file_put_contents('/home/ssl.log', 'The host ' . $host . ' is unhealthy');
    exit(1);
}

// register cert for domain
exec('certbot --apache -d ' . $domain, $output, $exitCode);
if ($exitCode !== 0) {
    file_put_contents('/home/ssl.log', 'Could not obtain cert for domain ' . $domain . "\n" . implode("\n", $output));
    exit(1);
}

// remove ssl-cron on success
unlink('/etc/cron.d/ssl');


function resolveIp(string $domain): ?string
{
    $records = dns_get_record($domain, DNS_A | DNS_AAAA);
    foreach ($records as $row) {
        if ($row['type'] === 'A') {
{'fraction_non_alphanumeric': 0.19489723600283487, 'fraction_numerical': 0.004961020552799433, 'mean_word_length': 3.5977198697068404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3799346', 'n_tokens_mistral': 981, 'n_tokens_neox': 965, 'n_words': 254}