|
@@ -8,7 +8,7 @@ function checkDomainFormat($domain) {
|
|
|
|
|
|
function listFsDirs($username) {
|
|
|
$absoluteDirs = glob(CONF['ht']['ht_path'] . "/" . $username . "/*/", GLOB_ONLYDIR);
|
|
|
- $dirs = array();
|
|
|
+ $dirs = [];
|
|
|
foreach ($absoluteDirs as $absoluteDir)
|
|
|
if (preg_match("/^[a-z0-9-]{1,32}$/", basename($absoluteDir)))
|
|
|
array_push($dirs, basename($absoluteDir));
|
|
@@ -20,69 +20,30 @@ function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
|
|
|
|
|
$op = $db->prepare("INSERT INTO sites(username, site_dir, domain, domain_type, protocol, creation_date, le_enabled) VALUES(:username, :site_dir, :domain, :domain_type, :protocol, :creation_date, :le_enabled)");
|
|
|
|
|
|
- $time = date("Y-m-d H:i:s");
|
|
|
if ($domainType === "dns" AND $protocol === "http")
|
|
|
$le_enabled = 0;
|
|
|
else
|
|
|
$le_enabled = NULL;
|
|
|
|
|
|
- $op->bindParam(':username', $username);
|
|
|
- $op->bindParam(':site_dir', $siteDir);
|
|
|
- $op->bindParam(':domain', $domain);
|
|
|
- $op->bindParam(':domain_type', $domainType);
|
|
|
- $op->bindParam(':protocol', $protocol);
|
|
|
- $op->bindParam(':creation_date', $time);
|
|
|
- $op->bindParam(':le_enabled', $le_enabled);
|
|
|
+ $op->bindValue(':username', $username);
|
|
|
+ $op->bindValue(':site_dir', $siteDir);
|
|
|
+ $op->bindValue(':domain', $domain);
|
|
|
+ $op->bindValue(':domain_type', $domainType);
|
|
|
+ $op->bindValue(':protocol', $protocol);
|
|
|
+ $op->bindValue(':creation_date', date("Y-m-d H:i:s"));
|
|
|
+ $op->bindValue(':le_enabled', $le_enabled);
|
|
|
|
|
|
$op->execute();
|
|
|
}
|
|
|
|
|
|
-function listDbDirs($username, $domainType, $protocol) {
|
|
|
- $db = new PDO('sqlite:' . DB_PATH);
|
|
|
-
|
|
|
- $op = $db->prepare('SELECT site_dir FROM sites WHERE username = :username AND domain_type = :domain_type AND protocol = :protocol');
|
|
|
- $op->bindParam(':username', $username);
|
|
|
- $op->bindParam(':domain_type', $domainType);
|
|
|
- $op->bindParam(':protocol', $protocol);
|
|
|
- $op->execute();
|
|
|
-
|
|
|
- return array_column($op->fetchAll(PDO::FETCH_ASSOC), 'site_dir');
|
|
|
-}
|
|
|
-
|
|
|
function dirsStatuses($username, $domainType, $protocol) {
|
|
|
- $dirs = array();
|
|
|
- $fsDirs = listFsDirs($username);
|
|
|
- $dbUsedDirs = listDbDirs($username, $domainType, $protocol);
|
|
|
- foreach ($fsDirs as $fsDir)
|
|
|
- $dirs[$fsDir] = ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs));
|
|
|
+ $dbDirs = query('select', 'sites', [
|
|
|
+ 'username' => $username,
|
|
|
+ 'domain_type' => $domainType,
|
|
|
+ 'protocol' => $protocol,
|
|
|
+ ], 'site_dir');
|
|
|
+ $dirs = [];
|
|
|
+ foreach (listFsDirs($username) as $fsDir)
|
|
|
+ $dirs[$fsDir] = in_array($fsDir, $dbDirs);
|
|
|
return $dirs;
|
|
|
}
|
|
|
-
|
|
|
-function selectSites($username, $domainType, $protocol, $onlyLeAvailable) {
|
|
|
- $db = new PDO('sqlite:' . DB_PATH);
|
|
|
-
|
|
|
- $query = "SELECT site_dir,domain FROM sites WHERE username = :username AND domain_type = :domain_type AND protocol = :protocol";
|
|
|
-
|
|
|
- if ($onlyLeAvailable === true)
|
|
|
- $query = $query . " AND le_enabled = 0";
|
|
|
-
|
|
|
- $op = $db->prepare($query);
|
|
|
- $op->bindParam(':username', $username);
|
|
|
- $op->bindParam(':domain_type', $domainType);
|
|
|
- $op->bindParam(':protocol', $protocol);
|
|
|
- $op->execute();
|
|
|
-
|
|
|
- $i = 0;
|
|
|
- $entry = $op->fetch();
|
|
|
- while (isset($entry['site_dir'])) {
|
|
|
- $result[$i]["siteDir"] = $entry['site_dir'];
|
|
|
- $result[$i]["domain"] = $entry['domain'];
|
|
|
- $i++;
|
|
|
- $entry = $op->fetch();
|
|
|
- }
|
|
|
-
|
|
|
- if (isset($result))
|
|
|
- return $result;
|
|
|
- else
|
|
|
- return false;
|
|
|
-}
|