From 1c00314b33b85d04a7519f66555ca08f5421b3e9 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Tue, 4 Mar 2014 00:45:33 +0100 Subject: [PATCH] =?UTF-8?q?Net::OpenSSH=20+=20readme=20+=20script=20pour?= =?UTF-8?q?=20les=20libs=20et=20modules=20n=C3=A9cessaires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.pm | 20 +++++++++++------- app/zone/edit.pm | 14 +++++++------ get_libs.sh | 32 +++++++++++++++++++++++++++++ readme.md | 48 +++++++++++++++++-------------------------- t/scp.pl | 18 ++++++++++------ t/tpl.zone | 6 ++++-- www/conf/config.ini | 12 ++++++----- www/lib/DNSManager.pm | 1 + 8 files changed, 96 insertions(+), 55 deletions(-) create mode 100755 get_libs.sh diff --git a/app/app.pm b/app/app.pm index 922ff04..306f062 100644 --- a/app/app.pm +++ b/app/app.pm @@ -17,7 +17,7 @@ use Moose; has dbh => ( is => 'rw', builder => '_void'); has dnsi => ( is => 'rw', builder => '_void'); has um => ( is => 'rw', builder => '_void'); -has [ qw/zdir dbname dbhost dbport dbuser dbpass sgbd dnsapp sshhost sshuser/ ] => qw/is ro required 1/; +has [ qw/zdir dbname dbhost dbport dbuser dbpass sgbd dnsapp sshhost sshuser sshport/ ] => qw/is ro required 1/; sub _void { my $x = ''; \$x; } ### users @@ -94,7 +94,8 @@ sub add_domain { my $ze = app::zone::edit->new(zname => $domain , zdir => $self->zdir , host => $self->sshhost - , user => $self->sshuser ); + , user => $self->sshuser + , port => $self->sshport ); $ze->addzone(); } @@ -109,7 +110,8 @@ sub delete_domain { my $ze = app::zone::edit->new(zname => $domain , zdir => $self->zdir , host => $self->sshhost - , user => $self->sshuser ); + , user => $self->sshuser + , port => $self->sshport ); $ze->del(); 1; @@ -121,7 +123,8 @@ sub update_domain_raw { my $ze = app::zone::edit->new(zname => $domain , zdir => $self->zdir , host => $self->sshhost - , user => $self->sshuser ); + , user => $self->sshuser + , port => $self->sshport ); $ze->update_raw($zone); } @@ -130,7 +133,8 @@ sub update_domain { my $ze = app::zone::edit->new(zname => $domain , zdir => $self->zdir , host => $self->sshhost - , user => $self->sshuser ); + , user => $self->sshuser + , port => $self->sshport ); $ze->update($zone); } @@ -139,7 +143,8 @@ sub get_domain { my $ze = app::zone::edit->new(zname => $domain , zdir => $self->zdir , host => $self->sshhost - , user => $self->sshuser ); + , user => $self->sshuser + , port => $self->sshport ); $ze->get(); } @@ -165,7 +170,8 @@ sub new_tmp { my $ze = app::zone::edit->new(zname => $domain , zdir => $self->zdir , host => $self->sshhost - , user => $self->sshuser ); + , user => $self->sshuser + , port => $self->sshport ); $ze->new_tmp(); } diff --git a/app/zone/edit.pm b/app/zone/edit.pm index 52f8ccd..30d85b5 100644 --- a/app/zone/edit.pm +++ b/app/zone/edit.pm @@ -2,7 +2,7 @@ use Modern::Perl; use Data::Dump "dump"; use DNS::ZoneParse; use File::Copy; -use Net::SCP; +use Net::OpenSSH; use Net::SSH q; use v5.14; @@ -11,7 +11,7 @@ use app::zone::rndc_interface; package app::zone::edit; use Moose; -has [ qw/zname zdir host user/ ] => qw/is ro required 1/; +has [ qw/zname zdir host user port/ ] => qw/is ro required 1/; sub get { my ($self) = @_; @@ -140,15 +140,17 @@ sub _cp { sub _scp_put { my ($self, $src, $dest) = @_; - my $scp = Net::SCP->new( { host => $self->host, user => $self->user } ); - $scp->put($src, $dest) or die $scp->{errstr}; + my $co = $self->user . '@' . $self->host . ':' . $self->port; + my $ssh = Net::OpenSSH->new($co); + $ssh->scp_put($src, $dest) or die "scp failed: " . $ssh->error; } sub _scp_get { my ($self, $src, $dest) = @_; - my $scp = Net::SCP->new( { host => $self->host, user => $self->user } ); - $scp->get($src, $dest) or die $scp->{errstr}; + my $co = $self->user . '@' . $self->host . ':' . $self->port; + my $ssh = Net::OpenSSH->new($co); + $ssh->scp_get($src, $dest) or die "scp failed: " . $ssh->error; } sub _sed { diff --git a/get_libs.sh b/get_libs.sh new file mode 100755 index 0000000..123f609 --- /dev/null +++ b/get_libs.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +sudo apt-get update +sudo apt-get install libssl1.0.0 libssl-dev cpanminus make gcc + +## En attendant de faire de vrais paquets pour l'application + +cpanm YAML +cpanm Data::Dump +cpanm File::Basename +cpanm Find::Lib +cpanm Test::More +cpanm String::ShellQuote +cpanm Data::Structure::Util +cpanm Modern::Perl +cpanm Config::Simple +cpanm Crypt::Digest::SHA256 +cpanm Dancer::Session::Storable + +cpanm Moose +cpanm Template +cpanm Template::Toolkit +cpanm Dancer +cpanm Dancer::Test + +cpanm ExtUtils::MakeMaker +cpanm Storable + +cpanm Plack::Handler::FCGI +cpanm Plack::Runner +cpanm DNS::ZoneParse +cpanm Net::OpenSSH diff --git a/readme.md b/readme.md index e3c8208..0f23421 100644 --- a/readme.md +++ b/readme.md @@ -1,31 +1,21 @@ -## FR trame du projet / TODO / brainstorming / brouillon - -### page d'inscription - -* login -* captcha -- todo - -### utilisateurs - * un login - * des domaines - * un mdp chiffré -- todo - * peuvent modifier leurs zones -- todo - * leur compte doit être activé par un admin -- todo - * réservation d'un ou plusieurs ndd en X.DOMAIN.TLD -- todo - * vérifier qu'ils ne sont pas déjà réservés ou attribués -- todo - -### admins - * Valident les comptes des utilisateurs. -- todo - * en activant une zone d'un utilisateur. -- todo - * Doit être automatisé. -- todo - * Créent et suppriment d'autres administrateurs. -- todo - * Possèdent une page pour voir les comptes non activés. -- todo +Gérer la création de zones par des utilisateurs. +Les utilisateurs s'enregistrent, crééent des zones et les modifient comme ils le souhaitent. +Des administrateurs peuvent supprimer des utilisateurs avec leurs zones. ## outils - * [Dancer](http://perldancer.org/) - * [DNS::ZoneParse](http://search.cpan.org/~mschilli/DNS-ZoneParse-1.10/lib/DNS/ZoneParse.pm) - * [Bootstrap](http://twitter.github.io/bootstrap/) -- todo - * [DBD::mysql](https://metacpan.org/module/DBD::mysql) - * [Net::HTTPS::Any](https://metacpan.org/module/IVAN/Net-HTTPS-Any-0.10/lib/Net/HTTPS/Any.pm) -- todo - * [Moose](https://metacpan.org/module/ETHER/Moose-2.0802/lib/Moose.pm) - * voir pour le chiffrement + + * [Dancer](http://perldancer.org/) + * [DNS::ZoneParse](http://search.cpan.org/~mschilli/DNS-ZoneParse-1.10/lib/DNS/ZoneParse.pm) + * [Bootstrap](http://twitter.github.io/bootstrap/) -- todo + * [DBD::mysql](https://metacpan.org/module/DBD::mysql) + * [Moose](https://metacpan.org/module/ETHER/Moose-2.0802/lib/Moose.pm) + * [Crypt::Digest::SHA256](http://search.cpan.org/~mik/CryptX-0.021/lib/Crypt/Digest/SHA256.pm) + +## TODO + + * captcha + * demander confirmation avant suppression d'une zone + +Si on souhaite faire un client pour mettre à jour automatiquement une zone avec son IP: + + * [Net::HTTPS::Any](https://metacpan.org/module/IVAN/Net-HTTPS-Any-0.10/lib/Net/HTTPS/Any.pm) diff --git a/t/scp.pl b/t/scp.pl index c5ca5d4..8487ce9 100755 --- a/t/scp.pl +++ b/t/scp.pl @@ -4,13 +4,19 @@ use warnings; use v5.14; use autodie; use Modern::Perl; -use Net::SCP; +use Net::OpenSSH; -my $hostname = "pizza"; -my $username = "karchnu"; +my $hostname = "ns0.arn-fai.net"; +my $username = "dnsmanager"; -my $scp = Net::SCP->new( { host => $hostname, user => $username } ); -$scp->get("/etc/resolv.conf", "kikoo") or die $scp->{errstr}; -$scp->put("kikoo", "lolwat") or die $scp->{errstr}; +my $co = "$username\@$hostname:2222"; +say $co; + +my $ssh = Net::OpenSSH->new($co); +$ssh->scp_put("tpl.zone", "/home/$username/") or die "scp failed: " . $ssh->error; + +#use Net::SCP; # ne fonctionne pas avec des ports :/ +#my $scp = Net::SCP->new( { host => $hostname, user => $username, port => 2222} ); +#$scp->put("tpl.zone", "lolwat") or die $scp->{errstr}; # $scp->put("filename") or die $scp->{errstr}; diff --git a/t/tpl.zone b/t/tpl.zone index b47432d..23ba858 100644 --- a/t/tpl.zone +++ b/t/tpl.zone @@ -1,6 +1,6 @@ ; ; Database file tpl.zone for tpl.zone. zone. -; Zone version: 2014011815 +; Zone version: 2014030200 ; $ORIGIN CHANGEMEORIGIN. @@ -8,7 +8,7 @@ $ORIGIN CHANGEMEORIGIN. $TTL 3600 @ 3600 IN SOA ns0.netlib.re. postmaster.netlib.re. ( - 2014011815 ; serial number + 2014030200 ; serial number 3600 ; refresh 600 ; retry 86400 ; expire @@ -16,3 +16,5 @@ $TTL 3600 ) ; ; Zone NS Records + +@ IN NS ns0.arn-fai.net. diff --git a/www/conf/config.ini b/www/conf/config.ini index 08977bc..6748cdb 100644 --- a/www/conf/config.ini +++ b/www/conf/config.ini @@ -9,13 +9,15 @@ host = localhost # default port for mysql port = 3306 -user = bla -passwd = HardPass4bla +user = monutilisateur +passwd = motdepasse # other options : see DBI module # possible options for dnsserver : bind rndc dnsapp = rndc -zones_path = "/etc/bind/named/" +zones_path = "/var/named/rndczones/" -sshhost = localhost -sshuser = karchnu +# to access zones on the server +sshhost = host +sshuser = dnsmanager +sshport = 2222 diff --git a/www/lib/DNSManager.pm b/www/lib/DNSManager.pm index f9168d9..dd1a05f 100755 --- a/www/lib/DNSManager.pm +++ b/www/lib/DNSManager.pm @@ -41,6 +41,7 @@ sub initco { , sgbd => $cfg->param('sgbd') , sshhost => $cfg->param('sshhost') , sshuser => $cfg->param('sshuser') + , sshport => $cfg->param('sshport') , dnsapp => $cfg->param('dnsapp') ); $app->init();