TXT.pm 1.8 KB

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