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. my sub _render ( $code, $headers, %data ) {
  19. return Trog::Renderer->render(
  20. code => $code,
  21. data => \%data,
  22. template => 'zone.tx',
  23. contenttype => 'text/plain',
  24. headers => $headers,
  25. );
  26. }
  27. =head1 Trog::Routes::TXT
  28. Routes which render as text/plain.
  29. =head1 CAVEATS
  30. This module is not wired up to anything. TCMS.pm builds its routing table out
  31. of Trog::Routes::HTML and Trog::Routes::JSON only, so nothing here is reachable
  32. and /text/zone will 404.
  33. Worse, the package statement in this file says Trog::Routes::JSON rather than
  34. Trog::Routes::TXT, so loading it would quietly replace the JSON routing table
  35. with this one. Fix that before wiring it in.
  36. =head1 VARIABLES
  37. =over 4
  38. =item %routes
  39. The usual tCMS routing table -- path to method, callback, parameters and
  40. whether the route requires admin.
  41. =back
  42. =head1 ROUTES
  43. =head2 zone
  44. Render zone.tx, this instance's DNS zone file. Admin only.
  45. Note that it passes the query through as-is; zone.tx wants $ip, $nameservers,
  46. $subdomains and friends, so it needs a data gathering pass before it will
  47. render anything.
  48. =cut
  49. sub zone ($query) {
  50. return _render( 200, {}, $query );
  51. }
  52. 1;