]> git.refcnt.org Git - distdns.git/blobdiff - client.pl
Mention all copyright years
[distdns.git] / client.pl
index aab5ea47f89691473f728b1ffd9b1c197e4ddd68..2a73f4e6de5f0f9218a98c69758224f40aed0841 100755 (executable)
--- a/client.pl
+++ b/client.pl
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 #
-# Copyright (c) 2013 Michel Ketterle, Steven Schubiger
+# Copyright (c) 2013, 2015 Michel Ketterle, Steven Schubiger
 #
 # This file is part of distdns.
 #
@@ -21,18 +21,41 @@ use strict;
 use warnings;
 use constant false => 0;
 
-use Config::Tiny;
-use Digest::MD5 qw(md5_hex);
-use Fcntl ':flock';
-use File::Spec::Functions qw(catfile rel2abs);
-use FindBin qw($Bin);
-use Getopt::Long qw(:config no_auto_abbrev no_ignore_case);
-use JSON qw(decode_json);
-use LWP::UserAgent;
-use Sys::Hostname qw(hostname);
-use Tie::File;
+BEGIN
+{
+    my @modules = (
+        [ 'Config::Tiny',          [                                           ] ],
+        [ 'Digest::MD5',           [ qw(md5_hex)                               ] ],
+        [ 'Fcntl',                 [ qw(:flock)                                ] ],
+        [ 'File::Spec::Functions', [ qw(catfile rel2abs)                       ] ],
+        [ 'FindBin',               [ qw($Bin)                                  ] ],
+        [ 'Getopt::Long',          [ qw(:config no_auto_abbrev no_ignore_case) ] ],
+        [ 'JSON',                  [ qw(decode_json)                           ] ],
+        [ 'LWP::UserAgent',        [                                           ] ],
+        [ 'POSIX',                 [ qw(strftime)                              ] ],
+        [ 'Sys::Hostname',         [ qw(hostname)                              ] ],
+        [ 'Tie::File',             [                                           ] ],
+    );
+    my (@missing, @import);
+    foreach my $module (@modules) {
+        unless (eval "require $module->[0]; 1") {
+            push @missing, $module->[0];
+            next;
+        }
+        unless (eval { $module->[0]->import(@{$module->[1]}); 1 }) {
+            push @import, $module->[0];
+        }
+    }
+    if (@missing || @import) {
+        warn <<"EOT";
+Modules missing: @missing
+Import failures: @import
+EOT
+        exit 1;
+    }
+}
 
-my $VERSION = '0.06';
+my $VERSION = '0.07';
 
 my $conf_file = catfile($Bin, 'client.conf');
 
@@ -93,8 +116,7 @@ my $save_session = sub
 my $get_session = sub
 {
     open(my $fh, '<', $session_file) or _die "Cannot open $session_file for reading: $!\nPerhaps try running --init\n";
-    my $session = do { local $/; <$fh> };
-    chomp $session;
+    chomp(my $session = <$fh>);
     close($fh);
 
     return $session;
@@ -130,13 +152,14 @@ if ($response->is_success) {
     }
     elsif ($opts{l}) {
         format STDOUT_TOP =
-IP                 Name               PC                      Netz
-=============================================================================
+IP                 Name               PC                      Netz               Aktualisiert
+====================================================================================================
 .
         foreach my $entry (sort { $a->{netz} cmp $b->{netz} } @{$data->{entries}}) {
+            my $updated = strftime '%Y-%m-%d %H:%M:%S', localtime $entry->{time};
             format STDOUT =
-@<<<<<<<<<<<<<<    @<<<<<<<<<<<<<<    @<<<<<<<<<<<<<<<<<<<    @<<<<<<<<<<<<<<
-@$entry{qw(ip name pc netz)}
+@<<<<<<<<<<<<<<    @<<<<<<<<<<<<<<    @<<<<<<<<<<<<<<<<<<<    @<<<<<<<<<<<<<<    @<<<<<<<<<<<<<<<<<<
+@$entry{qw(ip name pc netz)}, $updated
 .
             write;
         }