TXT.pm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package Trog::Routes::JSON;
  2. use 5.040;
  3. use re '/aasx';
  4. use Clone qw{clone};
  5. use JSON::MaybeXS();
  6. use Scalar::Util();
  7. use Trog::Utils();
  8. use Trog::Config();
  9. use Trog::Auth();
  10. use Trog::Routes::HTML();
  11. use Trog::Log::Metrics();
  12. my $conf = Trog::Config::get();
  13. # TODO de-duplicate this, it's shared in html
  14. my $theme_dir = '';
  15. $theme_dir = "themes/" . $conf->param('general.theme') if $conf->param('general.theme') && -d "www/themes/" . $conf->param('general.theme');
  16. our %routes = (
  17. '/text/zone' => {
  18. method => 'GET',
  19. callback => \&zone,
  20. parameters => {},
  21. admin => 1,
  22. },
  23. );
  24. =head1 Trog::Routes::TXT
  25. Routes which render as text/plain.
  26. =head1 CAVEATS
  27. This module is not wired up to anything. TCMS.pm builds its routing table out
  28. of Trog::Routes::HTML and Trog::Routes::JSON only, so nothing here is reachable
  29. and /text/zone will 404.
  30. Worse, the package statement in this file says Trog::Routes::JSON rather than
  31. Trog::Routes::TXT, so loading it would quietly replace the JSON routing table
  32. with this one. Fix that before wiring it in.
  33. =head1 VARIABLES
  34. =over 4
  35. =item %routes
  36. The usual tCMS routing table -- path to method, callback, parameters and
  37. whether the route requires admin.
  38. =back
  39. =head1 ROUTES
  40. =head2 zone
  41. Render zone.tx, this instance's DNS zone file. Admin only.
  42. Note that it passes the query through as-is; zone.tx wants $ip, $nameservers,
  43. $subdomains and friends, so it needs a data gathering pass before it will
  44. render anything.
  45. =cut
  46. sub zone ($query) {
  47. return _render( 200, {}, $query );
  48. }
  49. sub _render ( $code, $headers, %data ) {
  50. return Trog::Renderer->render(
  51. code => 200,
  52. data => \%data,
  53. template => 'zone.tx',
  54. contenttype => 'text/plain',
  55. headers => $headers,
  56. );
  57. }
  58. 1;