fix: use documented directadmin binary
This commit is contained in:
@@ -5,14 +5,19 @@ class DirectAdminVacationApi
|
||||
{
|
||||
/** @var callable|null */
|
||||
private $request;
|
||||
private string $daBinary = '/usr/local/bin/da';
|
||||
private string $daBinary = '/usr/local/directadmin/directadmin';
|
||||
|
||||
public function __construct(string $daBinary = '/usr/local/bin/da', ?callable $request = null)
|
||||
public function __construct(string $daBinary = '/usr/local/directadmin/directadmin', ?callable $request = null)
|
||||
{
|
||||
$this->daBinary = $daBinary;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function directAdminBinary(): string
|
||||
{
|
||||
return $this->daBinary;
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $rule @return array<string,string> */
|
||||
public function buildSavePayload(string $email, array $rule, bool $exists = true): array
|
||||
{
|
||||
@@ -133,7 +138,7 @@ class DirectAdminVacationApi
|
||||
|
||||
private function apiUrl(string $owner): string
|
||||
{
|
||||
$output = $this->run([$this->daBinary, 'api-url', '--user=' . $owner], '');
|
||||
$output = $this->run([$this->resolveDirectAdminBinary(), 'api-url', '--user=' . $owner], '');
|
||||
$url = trim($output);
|
||||
if ($url === '' || !preg_match('#^https?://#', $url)) {
|
||||
throw new RuntimeException('Cannot determine DirectAdmin API URL for user');
|
||||
@@ -141,9 +146,27 @@ class DirectAdminVacationApi
|
||||
return $url;
|
||||
}
|
||||
|
||||
private function resolveDirectAdminBinary(): string
|
||||
{
|
||||
$candidates = array_values(array_unique([
|
||||
$this->daBinary,
|
||||
'/usr/local/directadmin/directadmin',
|
||||
'/usr/bin/da',
|
||||
]));
|
||||
foreach ($candidates as $candidate) {
|
||||
if ($candidate !== '' && is_executable($candidate)) {
|
||||
return $candidate;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException('DirectAdmin binary is not executable. Checked: ' . implode(', ', $candidates));
|
||||
}
|
||||
|
||||
/** @param string[] $args */
|
||||
private function run(array $args, string $stdin): string
|
||||
{
|
||||
if (($args[0] ?? '') !== '' && str_contains($args[0], '/') && !is_executable($args[0])) {
|
||||
throw new RuntimeException('DirectAdmin API command is not executable: ' . $args[0]);
|
||||
}
|
||||
$process = proc_open($args, [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']], $pipes);
|
||||
if (!is_resource($process)) {
|
||||
throw new RuntimeException('Cannot start DirectAdmin API command');
|
||||
|
||||
Reference in New Issue
Block a user