line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zonemaster::GUI::Dancer::Frontend; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
54550
|
use 5.14.2; |
|
2
|
|
|
|
|
12
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
57
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
934
|
use Encode qw[decode_utf8]; |
|
2
|
|
|
|
|
15784
|
|
|
2
|
|
|
|
|
122
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0.7'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
### |
11
|
|
|
|
|
|
|
### Fetch the FAQ source documents |
12
|
|
|
|
|
|
|
### |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
978
|
use Text::Markdown 'markdown'; |
|
2
|
|
|
|
|
40977
|
|
|
2
|
|
|
|
|
88
|
|
15
|
2
|
|
|
2
|
|
1121
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
63538
|
|
|
2
|
|
|
|
|
247
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $faq_url_base = 'https://raw.githubusercontent.com/dotse/zonemaster-gui/master/docs/FAQ/gui-faq-%s.md'; |
18
|
|
|
|
|
|
|
my %faqs; |
19
|
|
|
|
|
|
|
my $http = HTTP::Tiny->new; |
20
|
|
|
|
|
|
|
for my $lang ( qw[sv en fr da] ) { |
21
|
|
|
|
|
|
|
my $r = $http->get( sprintf( $faq_url_base, $lang ) ); |
22
|
|
|
|
|
|
|
if ( $r->{success} and $r->{headers}{'content-type'} eq 'text/plain; charset=utf-8' ) { |
23
|
|
|
|
|
|
|
$faqs{$lang} = markdown( decode_utf8( $r->{content} ) ); |
24
|
|
|
|
|
|
|
$faqs{$lang} =~ s/
|
25
|
|
|
|
|
|
|
$faqs{$lang} =~ s/
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
elsif ( $r->{success} ) { |
28
|
|
|
|
|
|
|
$faqs{$lang} = 'Unexpected content-type for FAQ: ' . $r->{headers}{'content-type'}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
|
|
|
|
|
|
$faqs{$lang} = 'FAQ content missing.'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
### |
36
|
|
|
|
|
|
|
### Proceed with Dancer stuff |
37
|
|
|
|
|
|
|
### |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
2
|
|
1024
|
use Dancer ':syntax'; |
|
2
|
|
|
|
|
341060
|
|
|
2
|
|
|
|
|
8
|
|
40
|
2
|
|
|
2
|
|
1291
|
use Zonemaster::GUI::Dancer::Client; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
1194
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $backend_port = 5000; |
43
|
|
|
|
|
|
|
$backend_port = $ENV{ZONEMASTER_BACKEND_PORT} if ($ENV{ZONEMASTER_BACKEND_PORT}); |
44
|
|
|
|
|
|
|
my $url = "http://localhost:$backend_port"; |
45
|
|
|
|
|
|
|
my $client = Zonemaster::GUI::Dancer::Client->new( { url => $url } ); |
46
|
|
|
|
|
|
|
set logger => 'console'; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
set logger => 'console'; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
get '/' => sub { |
51
|
|
|
|
|
|
|
template 'index'; |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
get '/test/:id' => sub { |
55
|
|
|
|
|
|
|
my $lang = request->{'accept_language'}; |
56
|
|
|
|
|
|
|
$lang =~ s/,.*$//; |
57
|
|
|
|
|
|
|
my $result = $client->get_test_results( { params, language => $lang } ); |
58
|
|
|
|
|
|
|
template 'index', { test_id => param( 'id' ) }; |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
get '/parent' => sub { |
62
|
|
|
|
|
|
|
my $result = $client->get_data_from_parent_zone( param( 'domain' ) ); |
63
|
|
|
|
|
|
|
content_type 'application/json'; |
64
|
|
|
|
|
|
|
return to_json( { result => $result } ); |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub get_ip { |
68
|
0
|
|
|
0
|
0
|
|
my $ip = request->address; |
69
|
0
|
0
|
0
|
|
|
|
$ip = request->header('X-Forwarded-For') if (($ip =~ /127\.0\.0\.1/ || $ip =~ /::1/) && request->header('X-Forwarded-For')); |
|
|
|
0
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
$ip =~ s/::ffff:// if ( $ip =~ /::ffff:/ ); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return $ip; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
get '/version' => sub { |
76
|
|
|
|
|
|
|
my $data = $client->version_info( {} ); |
77
|
|
|
|
|
|
|
my $ip = get_ip(); |
78
|
|
|
|
|
|
|
content_type 'application/json'; |
79
|
|
|
|
|
|
|
my $version; |
80
|
|
|
|
|
|
|
if ($ENV{ZONEMASTER_ENVIRONMENT}) { |
81
|
|
|
|
|
|
|
$version = $ENV{ZONEMASTER_ENVIRONMENT}." [Engine:".$data->{zonemaster_engine} . " / Frontend:$VERSION / Backend:".$data->{zonemaster_backend} . " / IP address: $ip]"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
|
|
|
|
|
|
$version = "Zonemaster Test Engine Version:".$data->{zonemaster_engine} . ", IP address: $ip"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return to_json( { result => $version } ); |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
get '/check_syntax' => sub { |
91
|
|
|
|
|
|
|
my $data = from_json( param( 'data' ), { utf8 => 0 } ); |
92
|
|
|
|
|
|
|
my $result = $client->validate_syntax( {%$data} ); |
93
|
|
|
|
|
|
|
content_type 'application/json'; |
94
|
|
|
|
|
|
|
return to_json( { result => $result } ); |
95
|
|
|
|
|
|
|
}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
get '/history' => sub { |
98
|
|
|
|
|
|
|
my $data = from_json( param( 'data' ), { utf8 => 0 } ); |
99
|
|
|
|
|
|
|
my $result = $client->get_test_history( { frontend_params => {%$data}, limit => 200, offset => 0 } ); |
100
|
|
|
|
|
|
|
content_type 'application/json'; |
101
|
|
|
|
|
|
|
return to_json( { result => $result } ); |
102
|
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
get '/resolve' => sub { |
105
|
|
|
|
|
|
|
my $data = param( 'data' ); |
106
|
|
|
|
|
|
|
my $result = $client->get_ns_ips( $data ); |
107
|
|
|
|
|
|
|
content_type 'application/json'; |
108
|
|
|
|
|
|
|
return to_json( { result => $result } ); |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
post '/run' => sub { |
112
|
|
|
|
|
|
|
my $data = from_json( param( 'data' ), { utf8 => 0 } ); |
113
|
|
|
|
|
|
|
$data->{client_id} = 'Zonemaster Dancer Frontend'; |
114
|
|
|
|
|
|
|
$data->{client_version} = __PACKAGE__->VERSION; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$data->{user_ip} = get_ip(); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $job_id = $client->start_domain_test( {%$data} ); |
119
|
|
|
|
|
|
|
content_type 'application/json'; |
120
|
|
|
|
|
|
|
return to_json( { job_id => $job_id } ); |
121
|
|
|
|
|
|
|
}; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
get '/progress' => sub { |
124
|
|
|
|
|
|
|
my $progress = $client->test_progress( param( 'id' ) ); |
125
|
|
|
|
|
|
|
header( 'Cache-Control' => 'no-store, no-cache, must-revalidate' ); |
126
|
|
|
|
|
|
|
content_type 'application/json'; |
127
|
|
|
|
|
|
|
return to_json( { progress => $progress } ); |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
get '/result' => sub { |
131
|
|
|
|
|
|
|
my $result = $client->get_test_results( {params} ); |
132
|
|
|
|
|
|
|
content_type 'application/json'; |
133
|
|
|
|
|
|
|
return to_json( { result => $result } ); |
134
|
|
|
|
|
|
|
}; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
get '/faq' => sub { |
137
|
|
|
|
|
|
|
return to_json( { FAQ_CONTENT => $faqs{ param('lang') } } ); |
138
|
|
|
|
|
|
|
}; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
true; |