1
0
mirror of https://gitlab.com/depesz/explain.depesz.com.git synced 2024-11-28 08:58:52 +02:00

Add /info page

This is only for users logged in, with granted "admin" privileges
(is_admin column in users table in database, by default false for
everybody, has to be manually changed in database).

Info page shows loaded modules, perl version and paths to used perl
interpreter and top level of explain.depesz.com application.
This commit is contained in:
Hubert depesz Lubaczewski 2014-10-31 22:03:11 +01:00
parent 930f22b1c6
commit f185e5c746
5 changed files with 57 additions and 3 deletions

View File

@ -71,6 +71,9 @@ sub startup {
# route: 'help'
$routes->route( '/help' )->to( 'controller#help' )->name( 'help' );
# route: 'info'
$routes->route( '/info' )->to( 'controller#info' )->name( 'info' );
return;
}

View File

@ -7,10 +7,12 @@ use English -no_match_vars;
use Pg::Explain;
use Encode;
use Email::Valid;
use Config;
sub logout {
my $self = shift;
delete $self->session->{ 'user' };
delete $self->session->{ 'admin' };
$self->redirect_to( 'new-explain' );
}
@ -149,9 +151,10 @@ sub login {
return;
}
if ( $self->database->user_login( $username, $password ) ) {
if ( my $user = $self->database->user_login( $username, $password ) ) {
$self->flash( 'message' => 'User logged in.' );
$self->session( 'user' => $username );
$self->session( 'admin' => $user->{ 'admin' } );
$self->redirect_to( 'new-explain' );
}
$self->stash->{ 'message' } = 'Bad username or password.';
@ -357,6 +360,30 @@ sub contact {
$self->redirect_to( 'contact' );
}
sub info {
my $self = shift;
$self->redirect_to( 'new-explain' ) unless $self->session->{ 'user' };
$self->redirect_to( 'new-explain' ) unless $self->session->{ 'admin' };
my @versions = ();
for my $module ( sort keys %INC ) {
next if $module =~ m{^\.?/};
$module =~ s/\.pm$//;
$module =~ s#/#::#g;
push @versions, {
'module' => $module,
'version' => $module->VERSION,
};
}
$self->stash( 'modules' => \@versions );
$self->stash( 'perl' => {
'version' => $PERL_VERSION,
'binary' => $Config{'perlpath'} . $Config{'_exe'},
}
);
}
sub help {
# direct to template

View File

@ -75,7 +75,7 @@ sub user_login {
my ( $username, $password ) = @_;
my @row = $self->dbh->selectrow_array(
'SELECT password FROM users where username = ?',
'SELECT password, is_admin FROM users where username = ?',
undef,
$username,
);
@ -83,7 +83,7 @@ sub user_login {
my $crypted = crypt( $password, $row[ 0 ] );
return if $crypted ne $row[ 0 ];
return 1;
return { 'admin' => $row[1] };
}
sub user_change_password {

1
sql/patch-003.sql Normal file
View File

@ -0,0 +1 @@
ALTER TABLE users ADD COLUMN is_admin BOOL DEFAULT false;

View File

@ -0,0 +1,23 @@
% layout 'default';
% my $title = 'System information';
% title $title;
<h1><%= $title =%></h1>
<ul>
<li>Perl version: <%= $perl->{'version'} %></li>
<li>Perl binary: <%= $perl->{'binary'} %></li>
<li>App home: <%= app()->home() %>
<li>Loaded modules:
<ul>
% for my $item ( @{ $modules } ) {
<li><%= $item->{'module'} %>
% if ( $item->{'version'} ) {
version <%= $item->{'version'} %>
% }
</li>
% }
</ul>
</li>
</ul>