Cleaner ht.php
This commit is contained in:
parent
2401da72c5
commit
5e6da92d01
1 changed files with 8 additions and 33 deletions
41
fn/ht.php
41
fn/ht.php
|
@ -8,12 +8,11 @@ function checkDomainFormat($domain) {
|
||||||
|
|
||||||
function listFsDirs($username) {
|
function listFsDirs($username) {
|
||||||
$absoluteDirs = glob(CONF['ht']['ht_path'] . "/" . $username . "/*/", GLOB_ONLYDIR);
|
$absoluteDirs = glob(CONF['ht']['ht_path'] . "/" . $username . "/*/", GLOB_ONLYDIR);
|
||||||
$relativeDirs = false;
|
$dirs = array();
|
||||||
foreach ($absoluteDirs as $i => $absoluteDir) {
|
foreach ($absoluteDirs as $absoluteDir)
|
||||||
if (preg_match("/^[a-z0-9-]{1,32}$/", basename($absoluteDir)))
|
if (preg_match("/^[a-z0-9-]{1,32}$/", basename($absoluteDir)))
|
||||||
$relativeDirs[$i] = basename($absoluteDir); // The name of the site dir is the before last key
|
array_push($dirs, basename($absoluteDir));
|
||||||
}
|
return $dirs;
|
||||||
return $relativeDirs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
||||||
|
@ -40,7 +39,6 @@ function addSite($username, $siteDir, $domain, $domainType, $protocol) {
|
||||||
|
|
||||||
function listDbDirs($username, $domainType, $protocol) {
|
function listDbDirs($username, $domainType, $protocol) {
|
||||||
$db = new PDO('sqlite:' . DB_PATH);
|
$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 = $db->prepare('SELECT site_dir FROM sites WHERE username = :username AND domain_type = :domain_type AND protocol = :protocol');
|
||||||
$op->bindParam(':username', $username);
|
$op->bindParam(':username', $username);
|
||||||
|
@ -48,43 +46,20 @@ function listDbDirs($username, $domainType, $protocol) {
|
||||||
$op->bindParam(':protocol', $protocol);
|
$op->bindParam(':protocol', $protocol);
|
||||||
$op->execute();
|
$op->execute();
|
||||||
|
|
||||||
$i = 0;
|
return array_column($op->fetchAll(PDO::FETCH_ASSOC), 'site_dir');
|
||||||
$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 dirsStatuses($username, $domainType, $protocol) {
|
function dirsStatuses($username, $domainType, $protocol) {
|
||||||
$dirs = false;
|
$dirs = array();
|
||||||
$fsDirs = listFsDirs($username);
|
$fsDirs = listFsDirs($username);
|
||||||
$dbUsedDirs = listDbDirs($username, $domainType, $protocol);
|
$dbUsedDirs = listDbDirs($username, $domainType, $protocol);
|
||||||
if ($fsDirs) {
|
foreach ($fsDirs as $fsDir)
|
||||||
foreach ($fsDirs as $fsDir) {
|
$dirs[$fsDir] = ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs));
|
||||||
$dirs[$fsDir] = ($dbUsedDirs AND in_array($fsDir, $dbUsedDirs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $dirs;
|
return $dirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectSites($username, $domainType, $protocol, $onlyLeAvailable) {
|
function selectSites($username, $domainType, $protocol, $onlyLeAvailable) {
|
||||||
$db = new PDO('sqlite:' . DB_PATH);
|
$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";
|
$query = "SELECT site_dir,domain FROM sites WHERE username = :username AND domain_type = :domain_type AND protocol = :protocol";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue