Commit b9e1ea40 authored by Luc Didry's avatar Luc Didry

Add hashed_adminpwd option

This commit is dedicated to Schoumi, who is supporting me on Tipeee.
Many thanks :-)
parent 3e63f59c
Pipeline #10270 passed with stage
in 3 minutes and 59 seconds
......@@ -6,7 +6,10 @@ test:
- echo yes | cpan Carton
- carton install
- cp lstu.conf.template lstu.conf
- sed -i -e "s@#contact@contact@" -e "s@#adminpwd.*@adminpwd => '31f7a65e315586ac198bd798b6629ce4903d0899476d5741a9f32e2e521b6a66',@" -e "s@#db_path.*@db_path => 'test.db',@" lstu.conf
- sed -i -e "s@#contact@contact@" -e "s@#adminpwd.*@adminpwd => 'toto',@" -e "s@#db_path.*@db_path => 'test.db',@" lstu.conf
- rm -f test.db
- make test
- sed -i -e "s@ \(adminpwd.*\)@ \#\1@" -e "s@#hashed_adminpwd.*@hashed_adminpwd => '31f7a65e315586ac198bd798b6629ce4903d0899476d5741a9f32e2e521b6a66',@" lstu.conf
- rm -f test.db
- make test
tags:
......
......@@ -27,7 +27,10 @@ sub login {
$c->flash('banned' => 1);
$c->redirect_to('stats');
} else {
if (defined($c->config('adminpwd')) && defined($pwd) && sha256_hex($pwd) eq $c->config('adminpwd')) {
if (
(defined($c->config('adminpwd')) && defined($pwd) && $pwd eq $c->config('adminpwd')) ||
(defined($c->config('hashed_adminpwd')) && defined($pwd) && sha256_hex($pwd) eq $c->config('hashed_adminpwd'))
) {
my $token = $c->shortener(32);
LstuModel::Sessions->create(
......
......@@ -21,9 +21,15 @@
#secret => ['fdjsofjoihrei'],
# secret passphrase to access some admin features
# The passphrase should be encoded in SHA256 (hex)
# optional, but you won't have access to admin /stats if not set
#adminpwd => '4e738ca5563c06cfd0018299933d58db1dd8bf97f6973dc99bf6cdc64b5550bd',
# If you don't want to have a plain text password in configuration,
# use hashed_adminpwd instead
# optional, but you won't have access to admin /stats if not set and if hashed_adminpwd is not set either
#adminpwd => 's3cr3T',
# secret hashed passphrase to access some admin features
# Hash your password by issuing `echo -n s3cr3T | sha256sum` on your terminal
# optional, but you won't have access to admin /stats if not set and if adminpwd is not set either
#hashed_adminpwd => '94b2feede6ea5e2eec62f457ecb7d3f719b24d19c29d4e5466246a31908fc23b',
# choose a theme. See the available themes in `themes` directory
# optional, default is 'default'
......
......@@ -2,7 +2,7 @@
% title 'Lstu stats';
% use Mojo::Date;
<h2><%= l('Statistics') %></h2>
% if (defined(config('adminpwd'))) {
% if (defined(config('adminpwd')) || defined(config('hashed_adminpwd'))) {
% if (!flash('banned')) {
<form class="form" role="form" method="POST" action="<%== url_for 'stats' %>">
% if (defined(stash('admin'))) {
......@@ -30,7 +30,7 @@
<th><%= l('Shortened URL') %></th>
<th><%= l('Counter') %></th>
<th><%= l('Created') %></th>
% if (defined(config('adminpwd'))) {
% if (defined(config('adminpwd')) || defined(config('hashed_adminpwd'))) {
% if (defined(stash('admin'))) {
<th><%= l('Delete') %></th>
% }
......@@ -48,7 +48,7 @@
<td><%= link_to $prefix.$url->{short} => $prefix.$url->{short} %></td>
<td><%= $url->{counter} %></td>
<td><%= Mojo::Date->new($url->{timestamp})->to_string %></td>
% if (defined(config('adminpwd'))) {
% if (defined(config('adminpwd')) || defined(config('hashed_adminpwd'))) {
% if (defined(stash('admin'))) {
<td><a href="<%= url_for('delete', {short => $url->{short}}) %>"><span class="icon icon-trash"></span></a></td>
% }
......@@ -56,7 +56,7 @@
</tr>
% }
</table>
% if (defined(config('adminpwd'))) {
% if (defined(config('adminpwd')) || defined(config('hashed_adminpwd'))) {
% if (defined(stash('admin'))) {
<nav>
<ul class="pager">
......
......@@ -2,7 +2,7 @@
% title 'Lstu stats';
% use Mojo::Date;
<h2><%= l('Statistics') %></h2>
% if (defined(config('adminpwd'))) {
% if (defined(config('adminpwd')) || defined(config('hashed_adminpwd'))) {
% if (!flash('banned')) {
<form class="form" role="form" method="POST" action="<%== url_for 'stats' %>">
<fieldset>
......@@ -30,7 +30,7 @@
<th><%= l('Shortened URL') %></th>
<th><%= l('Counter') %></th>
<th><%= l('Created') %></th>
% if (defined(config('adminpwd'))) {
% if (defined(config('adminpwd')) || defined(config('hashed_adminpwd'))) {
% if (defined(stash('admin'))) {
<th><%= l('Delete') %></th>
% }
......@@ -48,7 +48,7 @@
<td><%= link_to $prefix.$url->{short} => $prefix.$url->{short} %></td>
<td><%= $url->{counter} %></td>
<td><%= Mojo::Date->new($url->{timestamp})->to_string %></td>
% if (defined(config('adminpwd'))) {
% if (defined(config('adminpwd')) || defined(config('hashed_adminpwd'))) {
% if (defined(stash('admin'))) {
<td><a href="<%= url_for('delete', {short => $url->{short}}) %>"><h5><span class="icon icon-trash"></span></h5></a></td>
% }
......@@ -56,7 +56,7 @@
</tr>
% }
</table>
% if (defined(config('adminpwd'))) {
% if (defined(config('adminpwd')) || defined(config('hashed_adminpwd'))) {
% if (defined(stash('admin'))) {
<nav>
<ul class="pager">
......
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