b64 pour les mdp et changement de mdp via l'interface web
This commit is contained in:
parent
ea6a062720
commit
d61cacc435
@ -3,6 +3,8 @@ use strict;
|
||||
use warnings;
|
||||
use v5.14;
|
||||
|
||||
use MIME::Base64 qw(encode_base64);
|
||||
|
||||
# the website sending your current IP address
|
||||
our $checkip = "http://t.karchnu.fr/ip.php";
|
||||
|
||||
@ -17,7 +19,7 @@ our $login = "idtest";
|
||||
our $pass = "mdptest";
|
||||
|
||||
# Your entry to change
|
||||
our $name = 'www';
|
||||
our $name = 'www'; # here, the entry is www.test.netlib.re
|
||||
our $type = 'A'; # could be AAAA
|
||||
|
||||
# The CA certificate, to authenticate the website (should be provided)
|
||||
@ -41,12 +43,15 @@ sub update {
|
||||
my $ip = get_ip;
|
||||
|
||||
say "UPDATE :: domain $name.$domain => IP $ip, type $type";
|
||||
my $passb64 = encode_base64($pass);
|
||||
chomp $passb64;
|
||||
|
||||
my $cmd = "wget -O - ";
|
||||
$cmd .=
|
||||
"https://$nddservice/domain/cliup/$login/$pass/$domain/$name/$type/$ip ";
|
||||
"https://$nddservice/domain/cliup/$login/$passb64/$domain/$name/$type/$ip ";
|
||||
$cmd .= "--ca-certificate=$cacert";
|
||||
say `$cmd`;
|
||||
say "CMD :: $cmd";
|
||||
`$cmd`;
|
||||
}
|
||||
|
||||
update;
|
||||
|
@ -35,6 +35,7 @@ sub what_is_next {
|
||||
}
|
||||
|
||||
for(keys %{$$res{addsession}}) {
|
||||
say "ajout de la session $_ : $$res{addsession}{$_}";
|
||||
session $_ => $$res{addsession}{$_};
|
||||
}
|
||||
|
||||
@ -200,6 +201,12 @@ prefix '/user' => sub {
|
||||
get_session( qw/login/ );
|
||||
};
|
||||
|
||||
post '/changepasswd' => sub {
|
||||
what_is_next rt_user_changepasswd
|
||||
get_session( qw/login/ )
|
||||
, get_param( qw/password/ );
|
||||
};
|
||||
|
||||
get '/toggleadmin/:user' => sub {
|
||||
what_is_next rt_user_toggleadmin
|
||||
get_session( qw/login passwd/ )
|
||||
|
@ -9,6 +9,7 @@ use utf8;
|
||||
use Dancer ':syntax';
|
||||
use Data::Dump qw( dump );
|
||||
use Data::Validate::IP qw(is_ipv4 is_ipv6);
|
||||
use MIME::Base64 qw(encode_base64 decode_base64);
|
||||
|
||||
use Exporter 'import';
|
||||
# what we want to export eventually
|
||||
@ -66,7 +67,19 @@ sub rt_dom_cli_autoupdate {
|
||||
my $pass = encrypt($$param{pass});
|
||||
my $app = app->new(get_cfg());
|
||||
|
||||
my $user = $app->auth($$param{login}, $pass);
|
||||
my $user;
|
||||
|
||||
eval {
|
||||
$user = $app->auth($$param{login}, $pass);
|
||||
};
|
||||
|
||||
# if the mdp is in base64
|
||||
# useful for cli and http GET messages
|
||||
if( $@ ) {
|
||||
my $passb64 = decode_base64($$param{pass});
|
||||
$pass = encrypt($passb64);
|
||||
$user = $app->auth($$param{login}, $pass);
|
||||
}
|
||||
|
||||
unless ( $user && ( $$user{admin} ||
|
||||
$app->is_owning_domain($$user{login}, $$param{domain}))) {
|
||||
|
@ -15,6 +15,7 @@ rt_user_login
|
||||
rt_user_del
|
||||
rt_user_toggleadmin
|
||||
rt_user_subscribe
|
||||
rt_user_changepasswd
|
||||
rt_user_add
|
||||
rt_user_home
|
||||
/;
|
||||
@ -25,6 +26,7 @@ our %EXPORT_TAGS = ( all => [qw/
|
||||
rt_user_del
|
||||
rt_user_toggleadmin
|
||||
rt_user_subscribe
|
||||
rt_user_changepasswd
|
||||
rt_user_add
|
||||
rt_user_home
|
||||
/] );
|
||||
@ -169,6 +171,37 @@ sub rt_user_subscribe {
|
||||
$res
|
||||
}
|
||||
|
||||
sub rt_user_changepasswd {
|
||||
my ($session, $param, $request) = @_;
|
||||
my $res;
|
||||
|
||||
unless ( $$session{login} && $$param{password} ) {
|
||||
$$res{deferred}{errmsg} = q{Identifiant ou mot de passe non renseigné.};
|
||||
$$res{route} = '/user/home';
|
||||
return $res;
|
||||
}
|
||||
|
||||
eval {
|
||||
my $pass = encrypt($$param{password});
|
||||
my $app = app->new(get_cfg());
|
||||
|
||||
$app->update_passwd($$session{login}, $pass);
|
||||
$app->disconnect();
|
||||
|
||||
$$res{deferred}{succmsg} = q{Changement de mot de passe effectué !};
|
||||
$$res{addsession}{passwd} = $pass;
|
||||
$$res{route} = '/user/home';
|
||||
};
|
||||
|
||||
if($@) {
|
||||
$$res{deferred}{errmsg} = q{Changement de mot de passe impossible !.};
|
||||
$$res{route} = '/user/subscribe';
|
||||
return $res;
|
||||
}
|
||||
|
||||
$res
|
||||
}
|
||||
|
||||
sub rt_user_add {
|
||||
my ($session, $param, $request) = @_;
|
||||
my $res;
|
||||
@ -245,7 +278,7 @@ sub rt_user_home {
|
||||
|
||||
if( $@ ) {
|
||||
$$res{sessiondestroy} = 1;
|
||||
$$res{deferred}{errmsg} = q{On a chié quelque-part.} . $@;
|
||||
$$res{deferred}{errmsg} = q{Problème d'authentification.} . $@;
|
||||
$$res{route} = '/';
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,6 @@
|
||||
<div class="row">
|
||||
<div class="col-sm-4 col-sm-offset-1">
|
||||
<h3>Ajouter un nouveau domaine :</h3>
|
||||
|
||||
<form class="form" action='/domain/add/' method="post" >
|
||||
<% IF domainName.defined %>
|
||||
<input type='text' name='domain' value="<% domainName %>" />
|
||||
@ -51,10 +50,21 @@
|
||||
<input type='submit' name='submit' value="Créer mon domaine!"
|
||||
class='btn btn-primary' />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-4 col-sm-offset-1">
|
||||
<h3>Changer son mot de passe :</h3>
|
||||
|
||||
<form class="form" action='/user/changepasswd' method="post" >
|
||||
<input type='password' name='password'/>
|
||||
<input type='submit' name='submit' value="Changer mon mot de passe"
|
||||
class='btn btn-primary' />
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div> <!-- fin de colonne -->
|
||||
|
Reference in New Issue
Block a user