Last active
February 15, 2016 08:00
-
-
Save privatehosting/89e899858ed329ab9a0a to your computer and use it in GitHub Desktop.
letsencrypt-froxlor-addon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sftp-config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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