mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: instance IP address envvar
This commit is contained in:
5
.env
5
.env
@@ -67,6 +67,11 @@ OAUTH_TOKEN_URL=
|
|||||||
OAUTH_USERINFO_URL=
|
OAUTH_USERINFO_URL=
|
||||||
OAUTH_SCOPE=
|
OAUTH_SCOPE=
|
||||||
|
|
||||||
|
# Typically your IP address, this envvar is required for
|
||||||
|
# some connectors that need to be provided with your host's
|
||||||
|
# outgoing IP address.
|
||||||
|
OUTGOING_IP=
|
||||||
|
|
||||||
LIMITED_FEATURES=false
|
LIMITED_FEATURES=false
|
||||||
LIMIT_MAX_WATCHLIST=0
|
LIMIT_MAX_WATCHLIST=0
|
||||||
LIMIT_MAX_WATCHLIST_DOMAINS=0
|
LIMIT_MAX_WATCHLIST_DOMAINS=0
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import {request} from "./index";
|
|||||||
|
|
||||||
export enum ConnectorProvider {
|
export enum ConnectorProvider {
|
||||||
OVH = 'ovh',
|
OVH = 'ovh',
|
||||||
GANDI = 'gandi'
|
GANDI = 'gandi',
|
||||||
|
NAMECHEAP = 'namecheap'
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Connector = {
|
export type Connector = {
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ export const helpGetTokenLink = (provider?: string) => {
|
|||||||
return <Typography.Link target='_blank' href="https://admin.gandi.net/organizations/account/pat">
|
return <Typography.Link target='_blank' href="https://admin.gandi.net/organizations/account/pat">
|
||||||
{t`Retrieve a Personal Access Token from your customer account on the Provider's website`}
|
{t`Retrieve a Personal Access Token from your customer account on the Provider's website`}
|
||||||
</Typography.Link>
|
</Typography.Link>
|
||||||
|
case ConnectorProvider.NAMECHEAP:
|
||||||
|
return <Typography.Link target='_blank' href="">
|
||||||
|
{t`Retreive an API key and whitelist this instance's IP address on Namecheap's website`}
|
||||||
|
</Typography.Link>
|
||||||
default:
|
default:
|
||||||
return <></>
|
return <></>
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ services:
|
|||||||
bind:
|
bind:
|
||||||
$mailerSenderEmail: '%mailer_sender_email%'
|
$mailerSenderEmail: '%mailer_sender_email%'
|
||||||
$mailerSenderName: '%mailer_sender_name%'
|
$mailerSenderName: '%mailer_sender_name%'
|
||||||
|
$outgoingIp: '%env(string:OUTGOING_IP)%'
|
||||||
|
|
||||||
# makes classes in src/ available to be used as services
|
# makes classes in src/ available to be used as services
|
||||||
# this creates a service per class whose id is the fully-qualified class name
|
# this creates a service per class whose id is the fully-qualified class name
|
||||||
|
|||||||
@@ -11,20 +11,20 @@ class NamecheapConnector extends AbstractConnector
|
|||||||
|
|
||||||
public const SANDBOX_BASE_URL = 'http://api.sandbox.namecheap.com/xml.response';
|
public const SANDBOX_BASE_URL = 'http://api.sandbox.namecheap.com/xml.response';
|
||||||
|
|
||||||
public function __construct(private HttpClientInterface $client)
|
public function __construct(private HttpClientInterface $client, private string $outgoingIp)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orderDomain(Domain $domain, $dryRun): void
|
public function orderDomain(Domain $domain, $dryRun): void
|
||||||
{
|
{
|
||||||
$addresses = $this->call('namecheap.users.address.getList');
|
$addresses = $this->call('namecheap.users.address.getList', [], $dryRun);
|
||||||
|
|
||||||
if (count($addresses) < 1) {
|
if (count($addresses) < 1) {
|
||||||
throw new \Exception('Namecheap account requires at least one address to purchase a domain');
|
throw new \Exception('Namecheap account requires at least one address to purchase a domain');
|
||||||
}
|
}
|
||||||
|
|
||||||
$addressId = $addresses->{0}->AddressId;
|
$addressId = $addresses->{0}->AddressId;
|
||||||
$address = $this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId]);
|
$address = $this->call('namecheap.users.address.getinfo', ['AddressId' => $addressId], $dryRun);
|
||||||
|
|
||||||
$domainAddresses = [];
|
$domainAddresses = [];
|
||||||
|
|
||||||
@@ -38,30 +38,26 @@ class NamecheapConnector extends AbstractConnector
|
|||||||
'Years' => 1,
|
'Years' => 1,
|
||||||
'AddFreeWhoisguard' => 'yes',
|
'AddFreeWhoisguard' => 'yes',
|
||||||
'WGEnabled' => 'yes',
|
'WGEnabled' => 'yes',
|
||||||
], $domainAddresses));
|
], $domainAddresses), $dryRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function mergePrefixKeys(string $prefix, array|object $src, array &$dest)
|
private static function mergePrefixKeys(string $prefix, array|object $src, array &$dest)
|
||||||
{
|
{
|
||||||
foreach ($src as $key => $value) {
|
foreach ($src as $key => $value) {
|
||||||
$dest[$prefix.$key] = $value;
|
$dest[$prefix . $key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function call(string $command, array $parameters = [], ?array $authData = null): object
|
private function call(string $command, array $parameters = [], bool $dryRun = true): object
|
||||||
{
|
{
|
||||||
if (is_null($authData)) {
|
|
||||||
$authData = $this->authData;
|
|
||||||
}
|
|
||||||
|
|
||||||
$actualParams = array_merge([
|
$actualParams = array_merge([
|
||||||
'Command' => $command,
|
'Command' => $command,
|
||||||
'ApiUser' => $authData['ApiUser'],
|
'ApiUser' => $this->authData['ApiUser'],
|
||||||
'ApiKey' => $authData['ApiKey'],
|
'ApiKey' => $this->authData['ApiKey'],
|
||||||
'ClientIp' => '', // TODO DW instance IP envvar
|
'ClientIp' => $this->outgoingIp,
|
||||||
], $parameters);
|
], $parameters);
|
||||||
|
|
||||||
$response = $this->client->request('POST', self::BASE_URL, [
|
$response = $this->client->request('POST', $dryRun ? self::SANDBOX_BASE_URL : self::BASE_URL, [
|
||||||
'query' => $actualParams,
|
'query' => $actualParams,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user