3
0

b64 pour les mdp et changement de mdp via l'interface web

This commit is contained in:
karchnu 2015-12-28 01:29:24 +01:00
parent ea6a062720
commit d61cacc435
5 changed files with 74 additions and 6 deletions

View File

@ -3,6 +3,8 @@ use strict;
use warnings; use warnings;
use v5.14; use v5.14;
use MIME::Base64 qw(encode_base64);
# the website sending your current IP address # the website sending your current IP address
our $checkip = "http://t.karchnu.fr/ip.php"; our $checkip = "http://t.karchnu.fr/ip.php";
@ -17,7 +19,7 @@ our $login = "idtest";
our $pass = "mdptest"; our $pass = "mdptest";
# Your entry to change # Your entry to change
our $name = 'www'; our $name = 'www'; # here, the entry is www.test.netlib.re
our $type = 'A'; # could be AAAA our $type = 'A'; # could be AAAA
# The CA certificate, to authenticate the website (should be provided) # The CA certificate, to authenticate the website (should be provided)
@ -41,12 +43,15 @@ sub update {
my $ip = get_ip; my $ip = get_ip;
say "UPDATE :: domain $name.$domain => IP $ip, type $type"; say "UPDATE :: domain $name.$domain => IP $ip, type $type";
my $passb64 = encode_base64($pass);
chomp $passb64;
my $cmd = "wget -O - "; my $cmd = "wget -O - ";
$cmd .= $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"; $cmd .= "--ca-certificate=$cacert";
say `$cmd`; say "CMD :: $cmd";
`$cmd`;
} }
update; update;

View File

@ -35,6 +35,7 @@ sub what_is_next {
} }
for(keys %{$$res{addsession}}) { for(keys %{$$res{addsession}}) {
say "ajout de la session $_ : $$res{addsession}{$_}";
session $_ => $$res{addsession}{$_}; session $_ => $$res{addsession}{$_};
} }
@ -200,6 +201,12 @@ prefix '/user' => sub {
get_session( qw/login/ ); 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 { get '/toggleadmin/:user' => sub {
what_is_next rt_user_toggleadmin what_is_next rt_user_toggleadmin
get_session( qw/login passwd/ ) get_session( qw/login passwd/ )

View File

@ -9,6 +9,7 @@ use utf8;
use Dancer ':syntax'; use Dancer ':syntax';
use Data::Dump qw( dump ); use Data::Dump qw( dump );
use Data::Validate::IP qw(is_ipv4 is_ipv6); use Data::Validate::IP qw(is_ipv4 is_ipv6);
use MIME::Base64 qw(encode_base64 decode_base64);
use Exporter 'import'; use Exporter 'import';
# what we want to export eventually # what we want to export eventually
@ -66,7 +67,19 @@ sub rt_dom_cli_autoupdate {
my $pass = encrypt($$param{pass}); my $pass = encrypt($$param{pass});
my $app = app->new(get_cfg()); 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} || unless ( $user && ( $$user{admin} ||
$app->is_owning_domain($$user{login}, $$param{domain}))) { $app->is_owning_domain($$user{login}, $$param{domain}))) {

View File

@ -15,6 +15,7 @@ rt_user_login
rt_user_del rt_user_del
rt_user_toggleadmin rt_user_toggleadmin
rt_user_subscribe rt_user_subscribe
rt_user_changepasswd
rt_user_add rt_user_add
rt_user_home rt_user_home
/; /;
@ -25,6 +26,7 @@ our %EXPORT_TAGS = ( all => [qw/
rt_user_del rt_user_del
rt_user_toggleadmin rt_user_toggleadmin
rt_user_subscribe rt_user_subscribe
rt_user_changepasswd
rt_user_add rt_user_add
rt_user_home rt_user_home
/] ); /] );
@ -169,6 +171,37 @@ sub rt_user_subscribe {
$res $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 { sub rt_user_add {
my ($session, $param, $request) = @_; my ($session, $param, $request) = @_;
my $res; my $res;
@ -245,7 +278,7 @@ sub rt_user_home {
if( $@ ) { if( $@ ) {
$$res{sessiondestroy} = 1; $$res{sessiondestroy} = 1;
$$res{deferred}{errmsg} = q{On a chié quelque-part.} . $@; $$res{deferred}{errmsg} = q{Problème d'authentification.} . $@;
$$res{route} = '/'; $$res{route} = '/';
} }

View File

@ -36,7 +36,6 @@
<div class="row"> <div class="row">
<div class="col-sm-4 col-sm-offset-1"> <div class="col-sm-4 col-sm-offset-1">
<h3>Ajouter un nouveau domaine :</h3> <h3>Ajouter un nouveau domaine :</h3>
<form class="form" action='/domain/add/' method="post" > <form class="form" action='/domain/add/' method="post" >
<% IF domainName.defined %> <% IF domainName.defined %>
<input type='text' name='domain' value="<% domainName %>" /> <input type='text' name='domain' value="<% domainName %>" />
@ -51,10 +50,21 @@
<input type='submit' name='submit' value="Créer mon domaine!" <input type='submit' name='submit' value="Créer mon domaine!"
class='btn btn-primary' /> class='btn btn-primary' />
</form> </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>
</div> </div>
</div> <!-- fin de colonne --> </div> <!-- fin de colonne -->