55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
|
<?php
|
||
|
if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
|
||
|
exit("This file is meant to be included.");
|
||
|
|
||
|
function listFsDirs($username) {
|
||
|
exec("/usr/bin/ls ls --format=single-column -d /srv/hyper/" . $username . "/hyper/*/", $absoluteDirs);
|
||
|
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;
|
||
|
$siteDir = $op->fetch()['site_dir'];
|
||
|
|
||
|
while ($siteDir != NULL) {
|
||
|
$siteDirs[$i] = $siteDir;
|
||
|
$i++;
|
||
|
$siteDir = $op->fetch()['site_dir'];
|
||
|
}
|
||
|
if (isset($siteDirs))
|
||
|
return $siteDirs;
|
||
|
else
|
||
|
return false;
|
||
|
}
|