@@ -83,7 +83,7 @@ |
||
| 83 | 83 | public function deleteAccounts(array $usernames) |
| 84 | 84 | { |
| 85 | 85 | $options = ['confirmed' => 'Confirm', 'delete' => 'yes']; |
| 86 | - foreach (array_values($usernames) as $idx => $username) { |
|
| 86 | + foreach(array_values($usernames) as $idx => $username) { |
|
| 87 | 87 | $options["select{$idx}"] = $username; |
| 88 | 88 | } |
| 89 | 89 | $this->invokePost('SELECT_USERS', $options); |
@@ -83,7 +83,8 @@ |
||
| 83 | 83 | public function deleteAccounts(array $usernames) |
| 84 | 84 | { |
| 85 | 85 | $options = ['confirmed' => 'Confirm', 'delete' => 'yes']; |
| 86 | - foreach (array_values($usernames) as $idx => $username) { |
|
| 86 | + foreach (array_values($usernames) as $idx => $username) |
|
| 87 | + { |
|
| 87 | 88 | $options["select{$idx}"] = $username; |
| 88 | 89 | } |
| 89 | 90 | $this->invokePost('SELECT_USERS', $options); |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | public function __construct(DirectAdmin $connection, $validate = false) |
| 35 | 35 | { |
| 36 | 36 | parent::__construct($connection); |
| 37 | - if ($validate) { |
|
| 37 | + if($validate) { |
|
| 38 | 38 | $classMap = [ |
| 39 | 39 | DirectAdmin::ACCOUNT_TYPE_ADMIN => AdminContext::class, |
| 40 | 40 | DirectAdmin::ACCOUNT_TYPE_RESELLER => ResellerContext::class, |
| 41 | 41 | DirectAdmin::ACCOUNT_TYPE_USER => self::class, |
| 42 | 42 | ]; |
| 43 | - if ($classMap[$this->getType()] != get_class($this)) { |
|
| 43 | + if($classMap[$this->getType()] != get_class($this)) { |
|
| 44 | 44 | throw new DirectAdminException('Validation mismatch on context construction'); |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public function getContextUser() |
| 65 | 65 | { |
| 66 | - if (!isset($this->user)) { |
|
| 66 | + if(!isset($this->user)) { |
|
| 67 | 67 | $this->user = User::fromConfig($this->invokeGet('SHOW_USER_CONFIG'), $this); |
| 68 | 68 | } |
| 69 | 69 | return $this->user; |
@@ -34,13 +34,15 @@ discard block |
||
| 34 | 34 | public function __construct(DirectAdmin $connection, $validate = false) |
| 35 | 35 | { |
| 36 | 36 | parent::__construct($connection); |
| 37 | - if ($validate) { |
|
| 37 | + if ($validate) |
|
| 38 | + { |
|
| 38 | 39 | $classMap = [ |
| 39 | 40 | DirectAdmin::ACCOUNT_TYPE_ADMIN => AdminContext::class, |
| 40 | 41 | DirectAdmin::ACCOUNT_TYPE_RESELLER => ResellerContext::class, |
| 41 | 42 | DirectAdmin::ACCOUNT_TYPE_USER => self::class, |
| 42 | 43 | ]; |
| 43 | - if ($classMap[$this->getType()] != get_class($this)) { |
|
| 44 | + if ($classMap[$this->getType()] != get_class($this)) |
|
| 45 | + { |
|
| 44 | 46 | throw new DirectAdminException('Validation mismatch on context construction'); |
| 45 | 47 | } |
| 46 | 48 | } |
@@ -63,7 +65,8 @@ discard block |
||
| 63 | 65 | */ |
| 64 | 66 | public function getContextUser() |
| 65 | 67 | { |
| 66 | - if (!isset($this->user)) { |
|
| 68 | + if (!isset($this->user)) |
|
| 69 | + { |
|
| 67 | 70 | $this->user = User::fromConfig($this->invokeGet('SHOW_USER_CONFIG'), $this); |
| 68 | 71 | } |
| 69 | 72 | return $this->user; |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | */ |
| 71 | 71 | public static function toDomainObjectArray(array $items, $class, Domain $domain) |
| 72 | 72 | { |
| 73 | - array_walk($items, function (&$value, $name) use ($class, $domain) { |
|
| 73 | + array_walk($items, function(&$value, $name) use ($class, $domain) { |
|
| 74 | 74 | $value = new $class($name, $domain, $value); |
| 75 | 75 | }); |
| 76 | 76 | return $items; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | public function __construct($name, UserContext $context, $config = null) |
| 44 | 44 | { |
| 45 | 45 | parent::__construct($name, $context); |
| 46 | - if (isset($config)) { |
|
| 46 | + if(isset($config)) { |
|
| 47 | 47 | $this->setCache(self::CACHE_CONFIG, $config); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public function getDefaultDomain() |
| 165 | 165 | { |
| 166 | - if (empty($name = $this->getConfig('domain'))) { |
|
| 166 | + if(empty($name = $this->getConfig('domain'))) { |
|
| 167 | 167 | return null; |
| 168 | 168 | } |
| 169 | 169 | return $this->getDomain($name); |
@@ -204,11 +204,11 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public function getDatabases() |
| 206 | 206 | { |
| 207 | - return $this->getCache(self::CACHE_DATABASES, function () { |
|
| 207 | + return $this->getCache(self::CACHE_DATABASES, function() { |
|
| 208 | 208 | $databases = []; |
| 209 | - foreach ($this->getSelfManagedContext()->invokeGet('DATABASES') as $fullName) { |
|
| 209 | + foreach($this->getSelfManagedContext()->invokeGet('DATABASES') as $fullName) { |
|
| 210 | 210 | list($user, $db) = explode('_', $fullName, 2); |
| 211 | - if ($this->getUsername() != $user) { |
|
| 211 | + if($this->getUsername() != $user) { |
|
| 212 | 212 | throw new DirectAdminException('Username incorrect on database ' . $fullName); |
| 213 | 213 | } |
| 214 | 214 | $databases[$db] = new Database($db, $this, $this->getSelfManagedContext()); |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | */ |
| 224 | 224 | public function getDomain($domainName) |
| 225 | 225 | { |
| 226 | - if (!isset($this->domains)) { |
|
| 226 | + if(!isset($this->domains)) { |
|
| 227 | 227 | $this->getDomains(); |
| 228 | 228 | } |
| 229 | 229 | return isset($this->domains[$domainName]) ? $this->domains[$domainName] : null; |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | public function getDomains() |
| 236 | 236 | { |
| 237 | - if (!isset($this->domains)) { |
|
| 238 | - if (!$this->isSelfManaged()) { |
|
| 237 | + if(!isset($this->domains)) { |
|
| 238 | + if(!$this->isSelfManaged()) { |
|
| 239 | 239 | $this->domains = $this->impersonate()->getDomains(); |
| 240 | 240 | } else { |
| 241 | 241 | $this->domains = Object::toRichObjectArray($this->getContext()->invokeGet('ADDITIONAL_DOMAINS'), Domain::class, $this->getContext()); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | public function impersonate() |
| 283 | 283 | { |
| 284 | 284 | /** @var ResellerContext $context */ |
| 285 | - if (!($context = $this->getContext()) instanceof ResellerContext) { |
|
| 285 | + if(!($context = $this->getContext()) instanceof ResellerContext) { |
|
| 286 | 286 | throw new DirectAdminException('You need to be at least a reseller to impersonate'); |
| 287 | 287 | } |
| 288 | 288 | return $context->impersonateUser($this->getUsername()); |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | public static function fromConfig($config, UserContext $context) |
| 349 | 349 | { |
| 350 | 350 | $name = $config['username']; |
| 351 | - switch ($config['usertype']) { |
|
| 351 | + switch($config['usertype']) { |
|
| 352 | 352 | case DirectAdmin::ACCOUNT_TYPE_USER: |
| 353 | 353 | return new self($name, $context, $config); |
| 354 | 354 | case DirectAdmin::ACCOUNT_TYPE_RESELLER: |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | private function getConfig($item) |
| 370 | 370 | { |
| 371 | - return $this->getCacheItem(self::CACHE_CONFIG, $item, function () { |
|
| 371 | + return $this->getCacheItem(self::CACHE_CONFIG, $item, function() { |
|
| 372 | 372 | return $this->loadConfig(); |
| 373 | 373 | }); |
| 374 | 374 | } |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | */ |
| 382 | 382 | private function getUsage($item) |
| 383 | 383 | { |
| 384 | - return $this->getCacheItem(self::CACHE_USAGE, $item, function () { |
|
| 384 | + return $this->getCacheItem(self::CACHE_USAGE, $item, function() { |
|
| 385 | 385 | return $this->getContext()->invokeGet('SHOW_USER_USAGE', ['user' => $this->getUsername()]); |
| 386 | 386 | }); |
| 387 | 387 | } |
@@ -43,7 +43,8 @@ discard block |
||
| 43 | 43 | public function __construct($name, UserContext $context, $config = null) |
| 44 | 44 | { |
| 45 | 45 | parent::__construct($name, $context); |
| 46 | - if (isset($config)) { |
|
| 46 | + if (isset($config)) |
|
| 47 | + { |
|
| 47 | 48 | $this->setCache(self::CACHE_CONFIG, $config); |
| 48 | 49 | } |
| 49 | 50 | } |
@@ -163,7 +164,8 @@ discard block |
||
| 163 | 164 | */ |
| 164 | 165 | public function getDefaultDomain() |
| 165 | 166 | { |
| 166 | - if (empty($name = $this->getConfig('domain'))) { |
|
| 167 | + if (empty($name = $this->getConfig('domain'))) |
|
| 168 | + { |
|
| 167 | 169 | return null; |
| 168 | 170 | } |
| 169 | 171 | return $this->getDomain($name); |
@@ -206,9 +208,11 @@ discard block |
||
| 206 | 208 | { |
| 207 | 209 | return $this->getCache(self::CACHE_DATABASES, function () { |
| 208 | 210 | $databases = []; |
| 209 | - foreach ($this->getSelfManagedContext()->invokeGet('DATABASES') as $fullName) { |
|
| 211 | + foreach ($this->getSelfManagedContext()->invokeGet('DATABASES') as $fullName) |
|
| 212 | + { |
|
| 210 | 213 | list($user, $db) = explode('_', $fullName, 2); |
| 211 | - if ($this->getUsername() != $user) { |
|
| 214 | + if ($this->getUsername() != $user) |
|
| 215 | + { |
|
| 212 | 216 | throw new DirectAdminException('Username incorrect on database ' . $fullName); |
| 213 | 217 | } |
| 214 | 218 | $databases[$db] = new Database($db, $this, $this->getSelfManagedContext()); |
@@ -223,7 +227,8 @@ discard block |
||
| 223 | 227 | */ |
| 224 | 228 | public function getDomain($domainName) |
| 225 | 229 | { |
| 226 | - if (!isset($this->domains)) { |
|
| 230 | + if (!isset($this->domains)) |
|
| 231 | + { |
|
| 227 | 232 | $this->getDomains(); |
| 228 | 233 | } |
| 229 | 234 | return isset($this->domains[$domainName]) ? $this->domains[$domainName] : null; |
@@ -234,10 +239,14 @@ discard block |
||
| 234 | 239 | */ |
| 235 | 240 | public function getDomains() |
| 236 | 241 | { |
| 237 | - if (!isset($this->domains)) { |
|
| 238 | - if (!$this->isSelfManaged()) { |
|
| 242 | + if (!isset($this->domains)) |
|
| 243 | + { |
|
| 244 | + if (!$this->isSelfManaged()) |
|
| 245 | + { |
|
| 239 | 246 | $this->domains = $this->impersonate()->getDomains(); |
| 240 | - } else { |
|
| 247 | + } |
|
| 248 | + else |
|
| 249 | + { |
|
| 241 | 250 | $this->domains = Object::toRichObjectArray($this->getContext()->invokeGet('ADDITIONAL_DOMAINS'), Domain::class, $this->getContext()); |
| 242 | 251 | } |
| 243 | 252 | } |
@@ -282,7 +291,8 @@ discard block |
||
| 282 | 291 | public function impersonate() |
| 283 | 292 | { |
| 284 | 293 | /** @var ResellerContext $context */ |
| 285 | - if (!($context = $this->getContext()) instanceof ResellerContext) { |
|
| 294 | + if (!($context = $this->getContext()) instanceof ResellerContext) |
|
| 295 | + { |
|
| 286 | 296 | throw new DirectAdminException('You need to be at least a reseller to impersonate'); |
| 287 | 297 | } |
| 288 | 298 | return $context->impersonateUser($this->getUsername()); |
@@ -348,7 +358,8 @@ discard block |
||
| 348 | 358 | public static function fromConfig($config, UserContext $context) |
| 349 | 359 | { |
| 350 | 360 | $name = $config['username']; |
| 351 | - switch ($config['usertype']) { |
|
| 361 | + switch ($config['usertype']) |
|
| 362 | + { |
|
| 352 | 363 | case DirectAdmin::ACCOUNT_TYPE_USER: |
| 353 | 364 | return new self($name, $context, $config); |
| 354 | 365 | case DirectAdmin::ACCOUNT_TYPE_RESELLER: |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | public function impersonate() |
| 36 | 36 | { |
| 37 | 37 | /** @var AdminContext $context */ |
| 38 | - if (!($context = $this->getContext()) instanceof AdminContext) { |
|
| 38 | + if(!($context = $this->getContext()) instanceof AdminContext) { |
|
| 39 | 39 | throw new DirectAdminException('You need to be an admin to impersonate another admin'); |
| 40 | 40 | } |
| 41 | 41 | return $context->impersonateAdmin($this->getUsername()); |
@@ -35,7 +35,8 @@ |
||
| 35 | 35 | public function impersonate() |
| 36 | 36 | { |
| 37 | 37 | /** @var AdminContext $context */ |
| 38 | - if (!($context = $this->getContext()) instanceof AdminContext) { |
|
| 38 | + if (!($context = $this->getContext()) instanceof AdminContext) |
|
| 39 | + { |
|
| 39 | 40 | throw new DirectAdminException('You need to be an admin to impersonate another admin'); |
| 40 | 41 | } |
| 41 | 42 | return $context->impersonateAdmin($this->getUsername()); |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | public function __construct($prefix, Domain $domain, $config = null) |
| 32 | 32 | { |
| 33 | 33 | parent::__construct($prefix, $domain); |
| 34 | - if (isset($config)) { |
|
| 34 | + if(isset($config)) { |
|
| 35 | 35 | $this->setCache(self::CACHE_DATA, is_string($config) ? \GuzzleHttp\Psr7\parse_query($config) : $config); |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | protected function getData($key) |
| 120 | 120 | { |
| 121 | - return $this->getCacheItem(self::CACHE_DATA, $key, function () { |
|
| 121 | + return $this->getCacheItem(self::CACHE_DATA, $key, function() { |
|
| 122 | 122 | $result = $this->getContext()->invokeGet('POP', [ |
| 123 | 123 | 'domain' => $this->getDomainName(), |
| 124 | 124 | 'action' => 'full_list', |
@@ -31,7 +31,8 @@ |
||
| 31 | 31 | public function __construct($prefix, Domain $domain, $config = null) |
| 32 | 32 | { |
| 33 | 33 | parent::__construct($prefix, $domain); |
| 34 | - if (isset($config)) { |
|
| 34 | + if (isset($config)) |
|
| 35 | + { |
|
| 35 | 36 | $this->setCache(self::CACHE_DATA, is_string($config) ? \GuzzleHttp\Psr7\parse_query($config) : $config); |
| 36 | 37 | } |
| 37 | 38 | } |
@@ -77,7 +77,7 @@ |
||
| 77 | 77 | */ |
| 78 | 78 | public function getAliases() |
| 79 | 79 | { |
| 80 | - return array_map(function ($domain) { |
|
| 80 | + return array_map(function($domain) { |
|
| 81 | 81 | return $this->getPrefix() . '@' . $domain; |
| 82 | 82 | }, $this->getDomain()->getDomainNames()); |
| 83 | 83 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | 'action' => 'create', |
| 58 | 58 | 'name' => $name, |
| 59 | 59 | ]; |
| 60 | - if (!empty($password)) { |
|
| 60 | + if(!empty($password)) { |
|
| 61 | 61 | $options += ['user' => $username, 'passwd' => $password, 'passwd2' => $password]; |
| 62 | 62 | } else { |
| 63 | 63 | $options += ['userlist' => $username]; |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function getAccessHosts() |
| 85 | 85 | { |
| 86 | - return $this->getCache(self::CACHE_ACCESS_HOSTS, function () { |
|
| 86 | + return $this->getCache(self::CACHE_ACCESS_HOSTS, function() { |
|
| 87 | 87 | $accessHosts = $this->getContext()->invokeGet('DATABASES', [ |
| 88 | 88 | 'action' => 'accesshosts', |
| 89 | 89 | 'db' => $this->getDatabaseName(), |
| 90 | 90 | ]); |
| 91 | 91 | |
| 92 | - return array_map(function ($name) { |
|
| 92 | + return array_map(function($name) { |
|
| 93 | 93 | return new Database\AccessHost($name, $this); |
| 94 | 94 | }, $accessHosts); |
| 95 | 95 | }); |
@@ -57,9 +57,12 @@ |
||
| 57 | 57 | 'action' => 'create', |
| 58 | 58 | 'name' => $name, |
| 59 | 59 | ]; |
| 60 | - if (!empty($password)) { |
|
| 60 | + if (!empty($password)) |
|
| 61 | + { |
|
| 61 | 62 | $options += ['user' => $username, 'passwd' => $password, 'passwd2' => $password]; |
| 62 | - } else { |
|
| 63 | + } |
|
| 64 | + else |
|
| 65 | + { |
|
| 63 | 66 | $options += ['userlist' => $username]; |
| 64 | 67 | } |
| 65 | 68 | $user->getContext()->invokePost('DATABASES', $options); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | $ukey = "u{$key}"; |
| 41 | 41 | unset($options[$ukey]); |
| 42 | - if (array_key_exists($key, $options) && ($options[$key] === 'unlimited' || !isset($options[$key]))) { |
|
| 42 | + if(array_key_exists($key, $options) && ($options[$key] === 'unlimited' || !isset($options[$key]))) { |
|
| 43 | 43 | $options[$ukey] = 'ON'; |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public static function processUnlimitedOptions(array $options) |
| 54 | 54 | { |
| 55 | - foreach (['bandwidth', 'domainptr', 'ftp', 'mysql', 'nemailf', 'nemailml', 'nemailr', 'nemails', |
|
| 55 | + foreach(['bandwidth', 'domainptr', 'ftp', 'mysql', 'nemailf', 'nemailml', 'nemailr', 'nemails', |
|
| 56 | 56 | 'nsubdomains', 'quota', 'vdomains', ] as $key) { |
| 57 | 57 | self::processUnlimitedOption($options, $key); |
| 58 | 58 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public static function responseToArray($data) |
| 69 | 69 | { |
| 70 | - $unescaped = preg_replace_callback('/&#([0-9]{2})/', function ($val) { |
|
| 70 | + $unescaped = preg_replace_callback('/&#([0-9]{2})/', function($val) { |
|
| 71 | 71 | return chr($val[1]); |
| 72 | 72 | }, $data); |
| 73 | 73 | return \GuzzleHttp\Psr7\parse_query($unescaped); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public static function sanitizeArray($result) |
| 83 | 83 | { |
| 84 | - if (count($result) == 1 && isset($result['list[]'])) { |
|
| 84 | + if(count($result) == 1 && isset($result['list[]'])) { |
|
| 85 | 85 | $result = $result['list[]']; |
| 86 | 86 | } |
| 87 | 87 | return is_array($result) ? $result : [$result]; |
@@ -39,7 +39,8 @@ discard block |
||
| 39 | 39 | { |
| 40 | 40 | $ukey = "u{$key}"; |
| 41 | 41 | unset($options[$ukey]); |
| 42 | - if (array_key_exists($key, $options) && ($options[$key] === 'unlimited' || !isset($options[$key]))) { |
|
| 42 | + if (array_key_exists($key, $options) && ($options[$key] === 'unlimited' || !isset($options[$key]))) |
|
| 43 | + { |
|
| 43 | 44 | $options[$ukey] = 'ON'; |
| 44 | 45 | } |
| 45 | 46 | } |
@@ -53,7 +54,8 @@ discard block |
||
| 53 | 54 | public static function processUnlimitedOptions(array $options) |
| 54 | 55 | { |
| 55 | 56 | foreach (['bandwidth', 'domainptr', 'ftp', 'mysql', 'nemailf', 'nemailml', 'nemailr', 'nemails', |
| 56 | - 'nsubdomains', 'quota', 'vdomains', ] as $key) { |
|
| 57 | + 'nsubdomains', 'quota', 'vdomains', ] as $key) |
|
| 58 | + { |
|
| 57 | 59 | self::processUnlimitedOption($options, $key); |
| 58 | 60 | } |
| 59 | 61 | return $options; |
@@ -81,7 +83,8 @@ discard block |
||
| 81 | 83 | */ |
| 82 | 84 | public static function sanitizeArray($result) |
| 83 | 85 | { |
| 84 | - if (count($result) == 1 && isset($result['list[]'])) { |
|
| 86 | + if (count($result) == 1 && isset($result['list[]'])) |
|
| 87 | + { |
|
| 85 | 88 | $result = $result['list[]']; |
| 86 | 89 | } |
| 87 | 90 | return is_array($result) ? $result : [$result]; |