diff options
author | Steven Schubiger <stsc@refcnt.org> | 2013-09-01 18:37:24 +0200 |
---|---|---|
committer | Steven Schubiger <stsc@refcnt.org> | 2013-09-01 18:37:24 +0200 |
commit | 9ca8c76cd6d2db1f6da1f6f6bcd828f7f01a9897 (patch) | |
tree | 8d2e991ecb18c5e3bbdfc5165caffdbc41843aac /server.cgi | |
parent | 90bacfc27fa61cbe3d39f95385e040c5d566077b (diff) | |
download | distdns-9ca8c76cd6d2db1f6da1f6f6bcd828f7f01a9897.tar.gz distdns-9ca8c76cd6d2db1f6da1f6f6bcd828f7f01a9897.tar.bz2 |
Move config data to files
Diffstat (limited to 'server.cgi')
-rwxr-xr-x | server.cgi | 35 |
1 files changed, 24 insertions, 11 deletions
@@ -19,23 +19,18 @@ use strict; use warnings; +use lib qw(lib); use CGI (); +use Config::Tiny (); use Fcntl ':flock'; +use File::Spec::Functions qw(catfile rel2abs); +use FindBin qw($Bin); use JSON qw(decode_json encode_json); -my $VERSION = '0.04'; +my $VERSION = '0.05'; -#----------------------- -# Start of configuration -#----------------------- - -my $json_file = 'data.json'; -my $session_file = 'session.dat'; - -#--------------------- -# End of configuration -#--------------------- +my $conf_file = catfile($Bin, 'server.conf'); my $query = CGI->new; @@ -56,6 +51,24 @@ if ($params{debug}) { }; } +my $config = Config::Tiny->new; + $config = Config::Tiny->read($conf_file); + +my $section = 'path'; + +die "Section $section missing in $conf_file\n" unless exists $config->{$section}; + +my @options = qw(json_file session_file); + +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}; +} + +my ($json_file, $session_file) = map rel2abs($options{$_}, $Bin), @options; + if ($params{init}) { die "Delete server-side $session_file first\n" if -e $session_file; |