TXT.pm 1.7 KB

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