]> git.refcnt.org Git - distdns.git/blobdiff - server.cgi
Mention all copyright years
[distdns.git] / server.cgi
index e581a8732ad922acffaa6bffd40725abef5858f6..1adcf0933b6ee9d71425fcd7cf503292e7a7de2a 100755 (executable)
@@ -62,7 +62,7 @@ my $config = Config::Tiny->new;
 
 my $section = 'path';
 
-die "Section $section missing in $conf_file\n" unless exists $config->{$section};
+die "Section '$section' missing in $conf_file\n" unless exists $config->{$section};
 
 my @options = qw(json_file session_file);
 
@@ -70,7 +70,7 @@ my %options;
 @options{@options} = @{$config->{$section}}{@options};
 
 foreach my $option (@options) {
-    die "Option $option not set in $conf_file\n" unless defined $options{$option} && length $options{$option};
+    die "Option '$option' not set in $conf_file\n" unless defined $options{$option} && length $options{$option};
 }
 
 my ($json_file, $session_file) = map rel2abs($options{$_}, $Bin), @options;
@@ -81,11 +81,14 @@ if ($params{init}) {
     open(my $fh, '>', $session_file) or die "Cannot open $session_file for writing: $!\n";
     print {$fh} "$params{session}\n";
     close($fh);
+
+    print $query->header('application/json');
+    print encode_json({ entries => [], error => undef });
+    exit;
 }
 else {
     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);
 
     die "Session ID mismatch\n" unless $params{session} eq $session;
@@ -130,6 +133,7 @@ if (exists $access{$params{name}} && grep /^$params{pc}$/i, @{$access{$params{na
             }
         }
         push @$data, { map { $_ => $params{$_} } qw(netz pc name ip) };
+        $data->[-1]->{time} = time;
 
         seek($fh, 0, 0)  or die "Cannot seek to start of $json_file: $!\n";
         truncate($fh, 0) or die "Cannot truncate $json_file: $!\n";