]> git.ipfire.org Git - thirdparty/pdns.git/blame - contrib/remotebackend-pipe-test.pl
Make sure we can install unsigned packages.
[thirdparty/pdns.git] / contrib / remotebackend-pipe-test.pl
CommitLineData
62b38b0f
PD
1#!/usr/bin/perl
2### This script is intended for testing/developing remotebackend scripts
3### To use, please install libjson-any-perl (JSON::Any) and libjson-xs-perl (JSON::XS)
4### (c) Aki Tuomi 2013 - Distributed under same license as PowerDNS Authoritative Server
5use strict;
6use warnings;
7use 5.005;
8use IPC::Open2;
9use JSON::Any;
10
11### CONFIGURATION SECTION
12
13## Full path to your remotebackend script
14my $script = "/home/cmouse/projects/pdns-v6-autorev/rev.pl";
15
16## These are used to send initialize method before your actual code
17my $initparams = { value => "foo", value2 => "bar" };
18
19## END CONFIGURATION
20
21$|=1;
22my $in;
23my $out;
24my $pid = open2($in,$out,$script);
25
26my $j = JSON::Any->new;
27
28sub rpc {
29 my $meth = shift;
30 my %p = @_;
31
32 print $j->encode({method => $meth, parameters => \%p}),"\r\n";
33 print $out $j->encode({method => $meth, parameters => \%p}),"\r\n";
34 my $res = <$in>;
35 if ($res) {
36 chomp $res;
37 print $res,"\n";
38 }
39}
40
41rpc 'initialize', %$initparams;
42
43if (@ARGV>1) {
44
45## this lets you call whatever method with simple parameters
46## like this:
47
48# perl remotebackend-pipe-test.pl lookup qtype SOA qname powerdns.com
49
50## this will execute
51## {"parameters":{"qname":"powerdns.com","qtype":"SOA"},"method":"lookup"}
52## on your remotebackend
53
54my $meth = shift;
55rpc $meth, @ARGV;
56
57
58} else {
59
60## Put whatever you want to run here. Or leave it empty if you
61## only want to use the command line
62
63#rpc 'lookup', qname => 'powerdns.com', qtype => 'SOA';
64
65}