diff options
author | Kristian Lyngstol <kristian@bohemians.org> | 2016-05-18 18:34:28 +0200 |
---|---|---|
committer | Kristian Lyngstol <kristian@bohemians.org> | 2016-05-18 18:34:28 +0200 |
commit | 81397bfd9fa54c60a8568812fc0ad99802a4e360 (patch) | |
tree | 26da570df1e43dc0304ad7ca88a42da252dcbecf /web/api | |
parent | e371b456f6a3872bd691e45ef6f7b52094d811f7 (diff) |
Add basic oplog
It still needs to be integrated with switches/info box, but this is a good
start.
Shows the last 5 log messages in an overlay on the map, with the rest
visible in an oplog tab.
Fixes #20
Diffstat (limited to 'web/api')
-rwxr-xr-x | web/api/read/oplog | 22 | ||||
-rwxr-xr-x | web/api/write/oplog | 22 |
2 files changed, 44 insertions, 0 deletions
diff --git a/web/api/read/oplog b/web/api/read/oplog new file mode 100755 index 0000000..d56890a --- /dev/null +++ b/web/api/read/oplog @@ -0,0 +1,22 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use lib '/opt/gondul/include'; +use nms::web; +use strict; +use warnings; + +my $query = $nms::web::dbh->prepare('select id,time as timestamp,extract(hour from time) as h, extract(minute from time) as m,systems,username,log from oplog order by id desc;'); +$query->execute(); +while (my $ref = $query->fetchrow_hashref()) { + my %meh; + $meh{'time'} = $ref->{'h'} . ":" . $ref->{'m'}; + $meh{'log'} = $ref->{'log'}; + $meh{'username'} = $ref->{'username'}; + $meh{'id'} = $ref->{'id'}; + $meh{'systems'} = $ref->{'systems'}; + $meh{'timestamp'} = $ref->{'timestamp'}; + push @{$nms::web::json{'oplog'}},\%meh; +} + +nms::web::finalize_output(); diff --git a/web/api/write/oplog b/web/api/write/oplog new file mode 100755 index 0000000..736ba2b --- /dev/null +++ b/web/api/write/oplog @@ -0,0 +1,22 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 +use lib '/opt/gondul/include'; +use utf8; +use nms::web qw($dbh db_safe_quote get_input finalize_output); +use strict; +use warnings; + +my $in = get_input(); +my %tmp = %{JSON::XS::decode_json($in)}; + +my $user = $ENV{'REMOTE_USER'} || "undefined"; + +my $q = $nms::web::dbh->prepare("INSERT INTO oplog (username, systems, log) values (?,?,?);"); +$q->execute($user, $tmp{'systems'}, $tmp{'log'}); + +$nms::web::cc{'max-age'} = '0'; +$nms::web::cc{'stale-while-revalidate'} = '0'; +$nms::web::json{'state'} = 'ok'; + +print "X-ban: /api/read/oplog\n"; +finalize_output(); |