Skip to content
Snippets Groups Projects
Commit 937d5d91 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

add monitoring-dedicated status page

parent 6a0ef149
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,10 @@ templates_dir = @templatesdir@
templates_theme = edugain
accounts_file = /var/lib/access-check/accounts.php
[status]
allow = 127.0.0.1, ::1, 10.45.0.0/16
disabled = 0
[federations]
# list of all federations from which to fetch metadata
edugain = https://mds.edugain.org/
......
......@@ -8,6 +8,7 @@ use CGI::Simple::Cookie;
use DateTime;
use English qw(-no_match_vars);
use Log::Any::Adapter;
use List::Util qw(any);
use List::MoreUtils qw(uniq);
use Template;
use Template::Constants qw(:chomp);
......@@ -35,6 +36,7 @@ my %patterns = (
my %actions = (
home => 'req_home',
status => 'req_status',
select_sp => 'req_select_sp',
select_email => 'req_select_email',
complete_challenge => 'req_complete_challenge',
......@@ -703,6 +705,42 @@ sub req_home {
);
}
sub req_status {
my ($self) = @_;
Net::IP->require();
my $source_ip_string = $ENV{HTTP_X_FORWARDED_FOR} ?
(split(/, /, $ENV{HTTP_X_FORWARDED_FOR}))[0] :
$ENV{REMOTE_ADDR};
my $source_ip = Net::IP->new($source_ip_string);
my @allowed_ips_strings = $self->{configuration}->{status}->{allow} ?
split(/, */, $self->{configuration}->{status}->{allow}) : ();
my @allowed_ips = map { Net::IP->new($_) } @allowed_ips_strings;
if (any { $_->overlaps($source_ip) } @allowed_ips) {
Sys::Hostname->require();
JSON->require();
print $self->{cgi}->header(
-type => 'application/json',
-charset => 'utf8',
);
my $status = $self->{configuration}->{status}->{disabled} ? 'disabled' : 'available';
print JSON->new()->encode({
status => $status,
host => Sys::Hostname::hostname()
});
} else {
$self->{logger}->errorf("Unauthorized access from %s", $source_ip_string);
print $self->{cgi}->header(
-status => '403 unauthorized',
-type => 'text/plain',
);
print "Unauthorized access";
}
exit 0;
}
sub get_parameter {
my ($self, %args) = @_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment