DDNS: Send proper user agent.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 12 Jun 2013 13:22:48 +0000 (15:22 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 12 Jun 2013 13:22:48 +0000 (15:22 +0200)
config/cfgroot/general-functions.pl
src/scripts/setddns.pl

index 56fc602..9c6d460 100644 (file)
@@ -857,10 +857,11 @@ sub FetchPublicIp {
         my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
         Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
     }
+    my $user_agent = &MakeUserAgent();
     my ($out, $response) = Net::SSLeay::get_http(  'checkip.dns.lightningwirelabs.com',
                                                    80,
                                                    "/",
-                                                   Net::SSLeay::make_headers('User-Agent' => 'IPFire' )
+                                                   Net::SSLeay::make_headers('User-Agent' => $user_agent )
                                                );
     if ($response =~ m%HTTP/1\.. 200 OK%) {
        $out =~ /Your IP address is: (\d+.\d+.\d+.\d+)/;
@@ -980,4 +981,29 @@ sub GetIcmpDescription ($) {
     'Experimental');
     if ($index>41) {return 'unknown'} else {return @icmp_description[$index]};
 }
+
+sub GetCoreUpdateVersion() {
+       my $core_update;
+
+       open(FILE, "/opt/pakfire/db/core/mine");
+       while (<FILE>) {
+               $core_update = $_;
+               last;
+       }
+       close(FILE);
+
+       return $core_update;
+}
+
+sub MakeUserAgent() {
+       my $user_agent = "IPFire/$General::version";
+
+       my $core_update = &GetCoreUpdateVersion();
+       if ($core_update ne "") {
+               $user_agent .= "/$core_update";
+       }
+
+       return $user_agent;
+}
+
 1;
index 8794ca6..6c4c369 100644 (file)
@@ -260,9 +260,10 @@ if ($ip ne $ipcache) {
                                $authstring = "username=$settings{'LOGIN'}&password=$settings{'PASSWORD'}";
                            }
 
+                           my $user_agent = &General::MakeUserAgent();
                            my ($out, $response) = Net::SSLeay::get_https("dns.lightningwirelabs.com", 443,
                                "/update?hostname=$settings{'HOSTDOMAIN'}&address4=$ip&$authstring",
-                               Net::SSLeay::make_headers('User-Agent' => 'IPFire')
+                               Net::SSLeay::make_headers('User-Agent' => $user_agent)
                            );
 
                            # Valid response are 'ok'   'nochange'