diff options
author | Kristian Lyngstol <kristian@bohemians.org> | 2016-05-16 16:13:33 +0200 |
---|---|---|
committer | Kristian Lyngstol <kristian@bohemians.org> | 2016-05-16 16:13:33 +0200 |
commit | 5b2a63f65edd13f182787ebb997ceaa493f61665 (patch) | |
tree | 8769496b970cdd374358e60cf91cb397874a6627 /web/api/public/config | |
parent | 948b1e9558479846c2ddd52be5483ab8b44be77c (diff) |
Add config read-api and use it to detect public access
Currently no way to modify the settings except by manual SQL, but it's
coming.
This allows us to have event-specific configuration in the database. This
commit adds js that uses this to detect if the frontend is a public vhost
or not.
There are currently only three columns provided in addition to ID.
publicvhost: The domain name of the publicly accessible version of Gondul.
shortname: code name for the vent. e.g dx16, tg17, etc.
data: jsonb to contain most other settings as we see fit.
Most settings will be stored in 'data' if it's only or mainly used by the
frontend. This will allow frontend developers to supply arbitrary
configuration options without the need for API or database changes in the
future.
Fixes #51
References #54
Still need the GUI for it.
Diffstat (limited to 'web/api/public/config')
-rwxr-xr-x | web/api/public/config | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/web/api/public/config b/web/api/public/config new file mode 100755 index 0000000..dd8ccc1 --- /dev/null +++ b/web/api/public/config @@ -0,0 +1,28 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use DBI; +use lib '/opt/gondul/include'; +use nms; +use nms::web; +use strict; +use warnings; +use Data::Dumper; + +$nms::web::cc{'max-age'} = "3600"; + +my $hostname = $ENV{'HTTP_HOST'} || ""; +my $q2 = $nms::web::dbh->prepare('select id, publicvhost, shortname, data from config order by id desc limit 1;'); + +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + $nms::web::json{'config'} = $ref; + $nms::web::json{'config'}{'data'} = JSON::XS::decode_json($ref->{'data'}); + if ($ref->{'publicvhost'} eq $hostname) { + $nms::web::json{'config'}{'public'} = "true"; + } else { + $nms::web::json{'config'}{'public'} = "false"; + } +} + +finalize_output(); |