Commit 52f6018f authored by fv3rdugo's avatar fv3rdugo
Browse files

[#669] Add handle proxy requests

Follow this code https://github.com/UPC/ravada/issues/181
it does not work yet, js dependency problems I think
parent a25fa845
......@@ -7,6 +7,7 @@ use locale ':not_characters';
use Carp qw(confess);
use Data::Dumper;
use Digest::SHA qw(sha256_hex);
use File::Path qw(make_path);
use Hash::Util qw(lock_hash);
use Mojolicious::Lite 'Ravada::I18N';
use Time::Piece;
......@@ -131,6 +132,7 @@ hook before_routes => sub {
,host => $host
);
return handle_proxy($c) if $url =~ m{^/netdata/};
return access_denied($c)
if $url =~ /(screenshot|\.json)/
&& !_logged_in($c);
......@@ -149,6 +151,29 @@ hook before_routes => sub {
};
sub handle_proxy {
my $c = shift;
my $url = $c->req->url->to_abs->path;
my $host = $c->req->url->to_abs->host;
my ($ip,$path,$file, $extension)
= $url =~ m{^/netdata/};
#return access_denied($c) if !$path || $path =~ m{\?};
#return access_denied($c) if $path =~ m{\?};
#return access_denied($c) if !$file || $file =~ m{\?};
my $ua = Mojo::UserAgent->new();
#my $url_req = "https://$host:19999/";
my $url_req = "https://$host:19999/";
my $tx = $ua->get($url_req);
if ( my $res = $tx->success) {
#This is the final url /netdata/#menu_system_submenu_cpu;theme=slate
return $c->render(data => $tx->res->body);
} else {
warn $url_req." ".Dumper($tx->error);
return $c->render(data => "$url_req ".$tx->error);
}
}
############################################################################3
......
......@@ -19,7 +19,12 @@
% if ($monitoring) {
<script>var netdataNoBootstrap = true;</script>
<script type="text/javascript" src="https://<%= $host %>:19999/dashboard.js"></script>
<script type="text/javascript" src="/netdata/dashboard.js"></script>
<script type="text/javascript" src="/netdata/lib/perfect-scrollbar-0.6.15.min.js"></script>
<script type="text/javascript" src="/netdata/lib/dygraph-c91c859.min.js"></script>
<script type="text/javascript" src="/netdata/lib/jquery.easypiechart-97b5824.min.js"></script>
<script type="text/javascript" src="/netdata/lib/jquery.easypiechart-97b5824.min.js"></script>
<script type="text/javascript" src="/netdata/lib/gauge-1.3.2.min.js"></script>
% }
<script src="https://cdnjs.cloudflare.com/ajax/libs/intro.js/2.7.0/intro.js"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment