92 lines
2.5 KiB
PHP
92 lines
2.5 KiB
PHP
<?php
|
|
if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
|
|
exit("This file is meant to be included.");
|
|
|
|
function listFsDirs($username) {
|
|
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;
|
|
}
|
|
|
|
function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
|
|
|
$op = $db->prepare("INSERT INTO sites(username, site_dir, domain, domain_type, protocol, creation_date) VALUES(:username, :site_dir, :domain, :domain_type, :protocol, :creation_date)");
|
|
|
|
$time = date("Y-m-d H:i:s");
|
|
|
|
$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->execute();
|
|
}
|
|
|
|
function listDbDirs($username, $domainType, $protocol) {
|
|
$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;
|
|
}
|
|
|
|
function sftpStatus($username) {
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
|
$usernameArr[0] = $username;
|
|
|
|
$op = $db->prepare('SELECT sftp_enabled FROM users WHERE username = ?');
|
|
$op->execute($usernameArr);
|
|
|
|
$status = $op->fetch()['sftp_enabled'];
|
|
|
|
if ($status == "0") {
|
|
return false;
|
|
} else if ($status == "1") {
|
|
return true;
|
|
} else {
|
|
exit("Wrong value for sftp_enabled");
|
|
}
|
|
}
|
|
|
|
function enableSftp($username) {
|
|
$db = new PDO('sqlite:' . DB_PATH);
|
|
|
|
$op = $db->prepare("UPDATE users SET sftp_enabled = 1 WHERE username = :username");
|
|
|
|
$op->bindParam(':username', $username);
|
|
|
|
$op->execute();
|
|
|
|
}
|