Skip to content

Commit 8a7fbe5

Browse files
committed
Merge branch 'custom-ip-address-url'
2 parents 4a6e7ce + 03afe97 commit 8a7fbe5

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

config.dist.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@
2828
// define('HOST', 'server');
2929

3030

31+
// Enter a URL to use to determine the public IPv4 address.
32+
// [Optional; will be set to default value 'https://api.ipify.org' if missing.]
33+
define('IPV4_ADDRESS_URL', 'https://api.ipify.org');
34+
35+
// Enter a URL to use as fallback to determine the public IPv4 address.
36+
// [Optional; will be set to default value 'https://ipv4.seeip.org' if missing.]
37+
define('IPV4_ADDRESS_URL_FALLBACK', 'https://ipv4.seeip.org');
38+
39+
// Enter a URL to use to determine the public IPv6 address.
40+
// [Optional; will be set to default value 'https://ipv6.seeip.org' if missing.]
41+
define('IPV6_ADDRESS_URL', 'https://ipv6.seeip.org');
42+
43+
// Enter a URL to use as fallback to determine the public IPv6 address.
44+
// [Optional; will be set to default value 'https://v6.ident.me' if missing.]
45+
define('IPV6_ADDRESS_URL_FALLBACK', 'https://v6.ident.me');
46+
47+
3148
// If set to true, the script will check for your public IPv4 address and add it as an A-Record / change an existing A-Record for the host.
3249
// You may want to deactivate this, for example, when using a carrier grade NAT (CGNAT).
3350
// Most likely though, you should keep this active, unless you know otherwise.

functions.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ function getCurrentPublicIPv4()
297297
return $providedIPv4;
298298
}
299299

300-
outputStdout('Getting IPv4 address from API.');
300+
outputStdout('Getting IPv4 address from ' . IPV4_ADDRESS_URL . '.');
301301

302-
$url = 'https://api.ipify.org';
302+
$url = IPV4_ADDRESS_URL;
303303
$ch = initializeCurlHandlerGetIP($url);
304304
$publicIP = trim(curl_exec($ch));
305305

@@ -312,8 +312,8 @@ function getCurrentPublicIPv4()
312312
}
313313

314314
if (!isIPV4Valid($publicIP) || $publicIP === false) {
315-
outputWarning("https://api.ipify.org didn't return a valid IPv4 address (Try $retryCount / $retryLimit). Trying fallback API https://ipv4.seeip.org");
316-
$url = 'https://ipv4.seeip.org';
315+
outputWarning(IPV4_ADDRESS_URL . " didn't return a valid IPv4 address (Try $retryCount / $retryLimit). Trying fallback " . IPV4_ADDRESS_URL_FALLBACK);
316+
$url = IPV4_ADDRESS_URL_FALLBACK;
317317
$ch = initializeCurlHandlerGetIP($url);
318318
$publicIP = trim(curl_exec($ch));
319319
if (!wasCurlSuccessful($ch) || !isIPV4Valid($publicIP)) {
@@ -344,9 +344,9 @@ function getCurrentPublicIPv6()
344344
return $providedIPv6;
345345
}
346346

347-
outputStdout('Getting IPv6 address from API.');
347+
outputStdout('Getting IPv6 address from ' . IPV6_ADDRESS_URL . '.');
348348

349-
$url = 'https://ipv6.seeip.org';
349+
$url = IPV6_ADDRESS_URL;
350350
$ch = initializeCurlHandlerGetIP($url);
351351
$publicIP = trim(curl_exec($ch));
352352

@@ -359,8 +359,8 @@ function getCurrentPublicIPv6()
359359
}
360360

361361
if (!isIPV6Valid($publicIP) || $publicIP === false) {
362-
outputWarning("https://ipv6.seeip.org didn't return a valid IPv6 address (Try $retryCount / $retryLimit). Trying fallback API https://v6.ident.me/");
363-
$url = 'https://v6.ident.me/';
362+
outputWarning(IPV6_ADDRESS_URL . " didn't return a valid IPv6 address (Try $retryCount / $retryLimit). Trying fallback " . IPV6_ADDRESS_URL_FALLBACK);
363+
$url = IPV6_ADDRESS_URL_FALLBACK;
364364
$ch = initializeCurlHandlerGetIP($url);
365365
$publicIP = trim(curl_exec($ch));
366366
if (!wasCurlSuccessful($ch) || !isIPV6Valid($publicIP)) {

update.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
exit(1);
2525
}
2626

27+
if (!defined('IPV4_ADDRESS_URL')) {
28+
define('IPV4_ADDRESS_URL', 'https://api.ipify.org');
29+
}
30+
31+
if (!defined('IPV4_ADDRESS_URL_FALLBACK')) {
32+
define('IPV4_ADDRESS_URL_FALLBACK', 'https://ipv4.seeip.org');
33+
}
34+
35+
if (!defined('IPV6_ADDRESS_URL')) {
36+
define('IPV6_ADDRESS_URL', 'https://ipv6.seeip.org');
37+
}
38+
39+
if (!defined('IPV6_ADDRESS_URL_FALLBACK')) {
40+
define('IPV6_ADDRESS_URL_FALLBACK', 'https://v6.ident.me/');
41+
}
42+
2743
if (USE_IPV4 === true) {
2844
// Get current IPv4 address
2945
if (!$publicIPv4 = getCurrentPublicIPv4()) {

0 commit comments

Comments
 (0)