TXT.pm 1.9 KB

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