2021-02-16 18:20:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function listFsDirs($username) {
|
2022-04-18 14:05:00 +00:00
|
|
|
exec(LS_PATH . " --format=single-column -d " . HT_PATH . "/" . $username . "/ht/*/", $absoluteDirs);
|
|
|
|
$relativeDirs = false;
|
|
|
|
foreach ($absoluteDirs as $i => $absoluteDir) {
|
|
|
|
$tree = explode("/", $absoluteDir); // The last key is NULL
|
|
|
|
end($tree);
|
|
|
|
$relativeDirs[$i] = prev($tree); // The name of the site dir is the before last key
|
|
|
|
}
|
|
|
|
return $relativeDirs;
|
2021-02-16 18:20:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
2022-04-18 14:05:00 +00:00
|
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
2021-02-16 18:20:19 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
$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)");
|
2021-02-16 18:20:19 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
$time = date("Y-m-d H:i:s");
|
|
|
|
if ($domainType === "dns" AND $protocol === "http")
|
|
|
|
$le_enabled = 0;
|
|
|
|
else
|
|
|
|
$le_enabled = NULL;
|
2021-02-16 18:20:19 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
$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);
|
2021-02-16 18:20:19 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
$op->execute();
|
2021-02-16 18:20:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function listDbDirs($username, $domainType, $protocol) {
|
2022-04-18 14:05:00 +00:00
|
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
|
|
|
$usernameArray[0] = $username;
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
$data = $op->fetch();
|
|
|
|
if (isset($data['site_dir']))
|
|
|
|
$siteDir = $data['site_dir'];
|
|
|
|
else
|
|
|
|
$siteDir = NULL;
|
|
|
|
|
|
|
|
while ($siteDir != NULL) {
|
|
|
|
$siteDirs[$i] = $siteDir;
|
|
|
|
$i++;
|
|
|
|
$data = $op->fetch();
|
|
|
|
if (isset($data['site_dir']))
|
|
|
|
$siteDir = $data['site_dir'];
|
|
|
|
else
|
|
|
|
$siteDir = NULL;
|
|
|
|
}
|
|
|
|
if (isset($siteDirs))
|
|
|
|
return $siteDirs;
|
|
|
|
else
|
|
|
|
return false;
|
2021-02-16 18:20:19 +00:00
|
|
|
}
|
2021-02-17 21:48:49 +00:00
|
|
|
|
|
|
|
function sftpStatus($username) {
|
2022-04-18 14:05:00 +00:00
|
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
|
|
|
$usernameArr[0] = $username;
|
2021-02-17 21:48:49 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
$op = $db->prepare('SELECT sftp_enabled FROM users WHERE username = ?');
|
|
|
|
$op->execute($usernameArr);
|
2021-02-17 21:48:49 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
$status = $op->fetch()['sftp_enabled'];
|
2021-02-17 21:48:49 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
if ($status == "0") {
|
|
|
|
return false;
|
|
|
|
} else if ($status == "1") {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
exit("Wrong value for sftp_enabled");
|
|
|
|
}
|
2021-02-17 21:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function enableSftp($username) {
|
2022-04-18 14:05:00 +00:00
|
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
2021-02-17 21:48:49 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
$op = $db->prepare("UPDATE users SET sftp_enabled = 1 WHERE username = :username");
|
2021-02-17 21:48:49 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
$op->bindParam(':username', $username);
|
2021-02-17 21:48:49 +00:00
|
|
|
|
2022-04-18 14:05:00 +00:00
|
|
|
$op->execute();
|
2021-10-03 16:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectSites($username, $domainType, $protocol, $onlyLeAvailable) {
|
2022-04-18 14:05:00 +00:00
|
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
|
|
|
$usernameArray[0] = $username;
|
|
|
|
|
|
|
|
$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;
|
2021-02-17 21:48:49 +00:00
|
|
|
}
|