@@ -29,17 +29,20 @@ class APIServicesDDNSRead extends APIModel {
2929 if (!empty ($ this ->config ['dyndnses ' ]['dyndns ' ])) {
3030 $ this ->validated_data = $ this ->config ['dyndnses ' ]['dyndns ' ];
3131 # Loop through each entry and check if it's address is current
32- foreach ($ this ->validated_data as $ id =>$ dyndns_ent ) {
33- $ this ->validated_data [$ id ]["current " ] = $ this ->__is_dyndns_current ($ dyndns_ent );
32+ foreach ($ this ->validated_data as $ id =>$ ddns_ent ) {
33+ $ this ->validated_data [$ id ]["cached_ip " ] = $ this ->__get_cached_ip ($ ddns_ent );
34+ $ this ->validated_data [$ id ]["cached_ipv6 " ] = $ this ->__get_cached_ip ($ ddns_ent , true );
35+ $ this ->validated_data [$ id ]["current " ] = $ this ->__is_dyndns_current ($ ddns_ent );
3436 }
3537 } else {
3638 $ this ->validated_data = [];
3739 }
3840 return APIResponse \get (0 , $ this ->validated_data );
3941 }
4042
41- private function __is_dyndns_current ($ ddns_ent ) {
43+ private function __get_cached_ip ($ ddns_ent, $ ipv6 = false ) {
4244 global $ dyndns_split_domain_types ;
45+
4346 # Determine our DDNS hostname
4447 if (in_array ($ ddns_ent ['type ' ], $ dyndns_split_domain_types )) {
4548 $ host = $ ddns_ent ['host ' ] . ". " . $ ddns_ent ['domainname ' ];
@@ -50,26 +53,43 @@ class APIServicesDDNSRead extends APIModel {
5053 $ file = "/conf/dyndns_ " .$ ddns_ent ['interface ' ].$ ddns_ent ['type ' ].escapeshellarg ($ host ).$ ddns_ent ['id ' ].".cache " ;
5154 $ file_v6 = "/conf/dyndns_ " .$ ddns_ent ['interface ' ].$ ddns_ent ['type ' ].escapeshellarg ($ host ).$ ddns_ent ['id ' ]."_v6.cache " ;
5255
53- # Check if either the IPv4 or IPv6 files exist, otherwise return false.
54- if (file_exists ($ file )) {
55- $ ipaddr = dyndnsCheckIP ($ ddns_ent ['interface ' ]);
56+ # Get our cached IPv4 address
57+ if (!$ ipv6 and file_exists ($ file )) {
5658 $ cached_ip_s = explode ("| " , file_get_contents ($ file ));
57- $ cached_ip = $ cached_ip_s [0 ];
58- if ($ ipaddr != $ cached_ip ) {
59- return false ;
60- } else {
61- return true ;
62- }
63- } else if (file_exists ($ file_v6 )) {
64- $ ipv6addr = get_interface_ipv6 ($ ddns_ent ['interface ' ]);
59+ return $ cached_ip_s [0 ];
60+ }
61+ # Check our cached IPv6 address +
62+ if ($ ipv6 and file_exists ($ file_v6 )) {
6563 $ cached_ipv6_s = explode ("| " , file_get_contents ($ file_v6 ));
66- $ cached_ipv6 = $ cached_ipv6_s [0 ];
67- if ($ ipv6addr != $ cached_ipv6 ) {
68- return false ;
64+ return $ cached_ipv6_s [0 ];
65+ }
66+ }
67+
68+ private function __is_dyndns_current ($ ddns_ent ) {
69+ # Local variables
70+ $ cached_ip = $ this ->__get_cached_ip ($ ddns_ent );
71+ $ cached_ipv6 = $ this ->__get_cached_ip ($ ddns_ent , true );
72+
73+ # Check if we found a cached IPv4 address
74+ if ($ cached_ip ) {
75+ # Check if our interfaces IP matches our cached DDNS IP
76+ if (dyndnsCheckIP ($ ddns_ent ['interface ' ]) === $ cached_ip ) {
77+ return true ;
6978 } else {
79+ return false ;
80+ }
81+ }
82+ # Otherwise, check if we found a cached IPv6 address
83+ elseif ($ cached_ipv6 ) {
84+ # Check if our interfaces IPv6 matches our cached DDNS IPv6
85+ if (get_interface_ipv6 ($ ddns_ent ['interface ' ]) === $ cached_ipv6 ) {
7086 return true ;
87+ } else {
88+ return false ;
7189 }
72- } else {
90+ }
91+ # If no DDNS cache was found, simply return false
92+ else {
7393 return false ;
7494 }
7595 }
0 commit comments