cexec 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env perl
  2. BEGIN {
  3. use File::Basename 'dirname';
  4. use File::Spec;
  5. push @INC, join('/', File::Spec->splitdir(dirname(__FILE__)), '..', 'lib');
  6. }
  7. use CJDNS;
  8. use JSON;
  9. unless ($ARGV[0]) {
  10. die "Usage: cexec <cjdns-admin-method> <arg1> .. <argN>\n";
  11. }
  12. if (open(CFG, '<', $ENV{HOME} . "/.cjdnsadmin")) {
  13. local $/;
  14. my $cfg = from_json(<CFG>); # slurrrrp!
  15. my $cjdns = CJDNS->new($cfg->{addr}, $cfg->{port}, $cfg->{password});
  16. my $method = $ARGV[0];
  17. my @args = @ARGV[1..$#ARGV];
  18. if ($method eq "capabilities") {
  19. print $cjdns->$method(@args) . "\n";
  20. } else {
  21. print to_json($cjdns->$method(@args)) . "\n";
  22. }
  23. } else {
  24. print("Please create a file named .cjdnsadmin in your home directory with\n");
  25. print("ip, port, and password of your cjdns engine in json.\n");
  26. print("for example:\n");
  27. print("{\n");
  28. print(" \"addr\": \"127.0.0.1\",\n");
  29. print(" \"port\": 11234,\n");
  30. print(" \"password\": \"You tell me! (you\'ll find it in your cjdroute.conf)\"\n");
  31. print("}\n");
  32. }