Skip to content

Instantly share code, notes, and snippets.

@privatehosting
Last active February 15, 2016 08:00
Show Gist options
  • Save privatehosting/89e899858ed329ab9a0a to your computer and use it in GitHub Desktop.
Save privatehosting/89e899858ed329ab9a0a to your computer and use it in GitHub Desktop.
letsencrypt-froxlor-addon
sftp-config.json
<?php
$letsencrypt_direction = "/usr/local/letsencrypt/";
$froxlor_direction = "/var/www/clients/froxlor/froxlor";
$certpath = "/etc/ssl/letsencrypt";
$froxlor_userdata = "userdata.inc.php";
$email = "dpilichiewicz@gmail.com";
$userdata = join(DIRECTORY_SEPARATOR, array($froxlor_direction, "lib", "userdata.inc.php"));
if (!file_exists($userdata) && !is_readable($userdata)) {
exit(output("Froxlor userdata.inc.php not found or not readable!"));
}
require $userdata;
$dsn = "mysql:dbname={$sql['db']};host={$sql['host']}";
try {
$dbh = new PDO($dsn, $sql['user'], $sql['password']);
} catch (PDOException $e) {
die(output('Connection failed: ' . $e->getMessage()));
}
$sql = 'SELECT id,domain,documentroot FROM panel_domains WHERE documentroot LIKE "/var/www/%" ORDER BY id;';
foreach ($dbh->query($sql) as $row) {
$topleveldomain = topDomainFromURL("http://$row[1]/");
if (trim($topleveldomain) == $row[1]) {
$domains[$topleveldomain] = $row[2];
}
}
foreach ($domains as $domain => $value) {
$cmd = join(";", array(
join(" ", array("cd", $letsencrypt_direction)),
join(" ", array("/bin/mkdir", "-p", join(DIRECTORY_SEPARATOR, array($certpath, $domain)))),
join(" ", array("./letsencrypt-auto", "renew", "--webroot", "--agree-tos", "-t", "--text", "--non-interactive", "--debug", "--renew-by-default",
join(" ", array("--webroot-path", $value)),
join(" ", array("--domain", $domain)),
join(" ", array("--email", $email)),
)),
));
output($cmd);
shell_exec($cmd);
}
function output($text)
{
print "{$text}\r\n";
}
function topDomainFromURL($url)
{
$url_parts = parse_url($url);
$domain_parts = explode('.', $url_parts['host']);
$top_domain_parts = array_slice($domain_parts, -2);
$top_domain = implode('.', $top_domain_parts);
return $top_domain;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment