use Mojo::Client;
use Mojo::JSON;
use Time::HiRes qw(time);
+use Data::Dump qw(dump);
-my $url = 'http://localhost:5984/monitor';
+my ( $url, $trigger_path ) = @ARGV;
-sub _trigger {
- my $trigger = $_[0]->{trigger};
- if ( my $command = $trigger->{command} ) {
- # FIXME SECURITY HOLE
- my $output = $trigger->{output} = `$command`;
+$url ||= 'http://localhost:5984/monitor';
+$trigger_path ||= 'trigger/shell.pm' ;
- $trigger->{output} =
- [ map { [ split (/\s+/,$_) ] } split(/\n/,$output) ]
- if $trigger->{format} =~ m/table/i;
- }
- return $trigger;
-}
+require $trigger_path if -e $trigger_path;
my $seq = 0;
debug 'change' => $change;
- if ( my $trigger = $change->{doc}->{trigger} ) {
- if ( exists $trigger->{active} ) {
+ if ( filter($change) ) {
+ if ( exists $change->{doc}->{trigger}->{active} ) {
debug 'trigger.active', $change->{doc}->{trigger}->{active};
} else {
- $trigger->{active} = [ time() ];
+ $change->{doc}->{trigger}->{active} = [ time() ];
debug 'TRIGGER start PUT ', $change->{doc};
$client->put( "$url/$id" => $json->encode( $change->{doc} ) => sub {
$change->{doc}->{_rev} = $res->{rev};
debug "TRIGGER execute ", $change->{doc};
- _trigger( $change->{doc} );
+ trigger( $change );
- push @{ $trigger->{active} }, time(), 0; # last timestamp
+ push @{ $change->{doc}->{trigger}->{active} }, time(), 0; # last timestamp
$client->put( "$url/$id" => $json->encode( $change->{doc} ) => sub {
my ($client,$tx) = @_;
--- /dev/null
+<!DOCTYPE HTML>
+<html xmlns:ng="http://angularjs.org">
+<head>
+<meta charset="utf-8">
+<script src="angular.js" ng:autobind></script>
+
+<script>
+Registrations.$inject = ['$xhr'];
+
+function Registrations(xhr){
+ this.xhr = xhr;
+ var self = this;
+ this.xhr("JSON"
+ , "/data/drzb2011/Registration?callback=JSON_CALLBACK"
+ , function(code, response){
+ console.log('xhr JSON', code, response);
+ self.data = response;
+ }
+ );
+
+}
+
+</script>
+
+<title>DRZB2011 Registrations</title>
+
+<style>
+.address {
+ font-size: 80%;
+}
+</style>
+
+</head>
+<body>
+
+<div ng:controller="Registrations">
+
+<ul>
+<li ng:repeat="registration in data">
+{{registration.person.name}}
+{{registration.person.surname}}
+<{{registration.person.email}}>
+<div class=address>{{registration.person.inst}}</div>
+<div class=address>{{registration.person.zip}} {{registration.person.city}}</div>
+</li>
+</ul>
+
+<input name=debug type=checkbox>
+<pre ng:show="debug">
+data={{data}}
+</pre>
+
+</div>
+
+
+</body>
+</html>
--- /dev/null
+sub filter {
+ my $change = shift;
+ return 1 if $change->{doc}->{trigger}->{command};
+}
+
+
+sub trigger {
+ my $change = shift;
+ my $trigger = $change->{doc}->{trigger};
+ if ( my $command = $trigger->{command} ) {
+ # FIXME SECURITY HOLE
+ my $output = $trigger->{output} = `$command`;
+
+ $trigger->{output} =
+ [ map { [ split (/\s+/,$_) ] } split(/\n/,$output) ]
+ if $trigger->{format} =~ m/table/i;
+ }
+}
+
+1;