diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2012-10-09 11:31:07 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2012-10-09 11:31:07 +0200 |
commit | 81e909e9031d8f8a68101080f225b4a977ec0015 (patch) | |
tree | eeec2d7996a33f5031a47e83bc2ac73148c5dfb1 | |
parent | d13e60f230ba540ee1df2e1495145307135006c6 (diff) |
Make use of Module::Build for the build script.
-rw-r--r-- | .gitignore | 11 | ||||
-rw-r--r-- | MANIFEST | 14 | ||||
-rw-r--r-- | build.PL | 36 | ||||
-rw-r--r-- | lib/Net/MulkyID.pm | 5 | ||||
-rw-r--r-- | lib/Net/MulkyID/Builder.pm | 24 | ||||
-rwxr-xr-x | lib/Net/MulkyID/Setup.pm | 128 | ||||
-rwxr-xr-x | setup.pl | 118 |
7 files changed, 220 insertions, 116 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d33db40 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*~ +www/config.pl +www/jquery +etc +_build +MYMETA.json +MYMETA.yml +Build +browserid.json +blib + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..0c359d8 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,14 @@ +lib/Net/MulkyID.pm +lib/Net/MulkyID/Builder.pm +lib/Net/MulkyID/Setup.pm +www/login.pl +www/provision.html +www/provision.js +www/authenticate.html +www/authenticate.js +www/common.pl +www/logged_in_p.pl +www/sign.pl +COPYING.AGPL +README.md +build.PL diff --git a/build.PL b/build.PL new file mode 100644 index 0000000..f891784 --- /dev/null +++ b/build.PL @@ -0,0 +1,36 @@ +#! /usr/bin/env perl + +use lib q(./lib); +use Net::MulkyID::Builder; # Or whatever you want to call it + +my $build = Net::MulkyID::Builder->new + ( + module_name => 'Net::MulkyID', + #license => 'agpl_3', + dist_author => 'Matthias Andreas Benkard <code@mulk.eu>', + dist_abstract => 'A simple Persona IdP.', + requires => { + "Carp" => 0, + "CGI" => 0, + "CGI::Fast" => 0, + "CGI::Session" => 0, + "common::sense" => 0, + "Crypt::OpenSSL::RSA" => 0, + "File::Slurp" => 0, + "JSON" => 0, + "MIME::Base64" => 0, + "Mail::ExpandAliases" => 0, + "Mail::IMAPTalk" => 0, + "Modern::Perl" => 0, + "Time::HiRes" => 0, + }, + build_requires => { + "LWP::Simple" => 0, + "Modern::Perl" => 0, + "Crypt::OpenSSL::RSA" => 0, + "File::Slurp" => 0, + "JSON" => 0, + "common::sense" => 0 + }, + ); +$build->create_build_script; diff --git a/lib/Net/MulkyID.pm b/lib/Net/MulkyID.pm new file mode 100644 index 0000000..58168ff --- /dev/null +++ b/lib/Net/MulkyID.pm @@ -0,0 +1,5 @@ +#! /usr/bin/env perl + +package Net::MulkyID; + +1; diff --git a/lib/Net/MulkyID/Builder.pm b/lib/Net/MulkyID/Builder.pm new file mode 100644 index 0000000..a1c000d --- /dev/null +++ b/lib/Net/MulkyID/Builder.pm @@ -0,0 +1,24 @@ +#! /usr/bin/env perl + +package Net::MulkyID::Builder; + +use Module::Build; + +our @ISA = 'Module::Build'; + +sub new { + my ($class, @args) = @_; + my $self = $class->SUPER::new(@args); + return bless $self, $class; + #my $self = $self->SUPER::new(); + #return $self; + #return bless {}, shift; +} + +sub ACTION_build { + my ($self, @args) = @_; + eval "use Net::MulkyID::Setup; setup();"; + #return SUPER::ACTION_build($self, @args); +} + +1; diff --git a/lib/Net/MulkyID/Setup.pm b/lib/Net/MulkyID/Setup.pm new file mode 100755 index 0000000..8c58013 --- /dev/null +++ b/lib/Net/MulkyID/Setup.pm @@ -0,0 +1,128 @@ +#! /usr/bin/env perl +# Copyright 2012, Matthias Andreas Benkard <code@mail.matthias.benkard.de>. + +package Net::MulkyID::Setup; + +use common::sense; +use Modern::Perl; +use JSON; +use Crypt::OpenSSL::RSA; +use File::Slurp qw(write_file read_file); +use File::Path qw(make_path); +use File::Copy; +use LWP::Simple qw(getstore); +use Data::Dumper; + +use base 'Exporter'; +our @EXPORT = qw(setup); + +sub prompt($$) { + my ($question, $default) = @_; + $|++; + print "${question} \[${default}\] "; + $_ = <>; + chomp; + if ($_) { + return $_; + } else { + return $default; + } +} + +sub makespec($) { + my ($key) = @_; + my ($n, $e, @stuff) = $key->get_key_parameters; + return + encode_json({"public-key" => {e => $e->to_decimal, n => $n->to_decimal, algorithm => "RS"}, + "authentication" => "/browserid/authenticate.html", + "provisioning" => "/browserid/provision.html"}); +}; + +sub setup() { + my $conffile = "www/config.pl"; + + # Generate configuration file. + $::MULKONF = { }; + if (stat($conffile)) { + say "Found existing configuration ($conffile)."; + do $conffile; + } + + my $configpath = $::MULKONF->{configpath} // "/etc/mulkyid"; + $configpath = prompt("Where shall I put configuration files?", $configpath); + my $pemfile = $::MULKONF->{pemfile} // "$configpath/rsa2048.pem"; + $pemfile = prompt("Where shall I put the private key?", $pemfile); + my $aliases_file = $::MULKONF->{aliases_file} // "/etc/aliases"; + $aliases_file = prompt("Where is the aliases file? Type a single dot for none.", $aliases_file); + my $imap_server = $::MULKONF->{imap_server} // "localhost"; + $imap_server = prompt("What is the IMAP server's address?", $imap_server); + my $imap_port = $::MULKONF->{imap_port} // 143; + $imap_port = int(prompt("What is the IMAP server's port?", $imap_port)); + + say "OK."; + + # Download jQuery. + make_path("www/jquery"); + if (stat("www/jquery/jquery.js")) { + say "Using existing copy of jQuery (www/jquery/jquery.js)."; + } else { + say "Fetching jQuery..."; + getstore("http://code.jquery.com/jquery-1.7.2.min.js", "www/jquery/jquery.js") + or die "Could not fetch jQuery"; + say "jQuery saved to: www/jquery/jquery.js"; + } + + # Generate the private key. + my $key; + if (stat($pemfile)) { + say "Using existing private key ($pemfile)."; + $key = Crypt::OpenSSL::RSA->new_private_key(scalar read_file($pemfile)); + } else { + say "Generating private key..."; + $key = Crypt::OpenSSL::RSA->generate_key(2048); + make_path($configpath); + write_file($pemfile, $key->get_private_key_string()) + or die "Could not write private key to $pemfile: $!"; + say "Private key saved to: $pemfile"; + chmod 0440, $pemfile; + } + + # Generate spec file. + write_file("browserid.json", makespec $key) + or die "Could not write spec to browserid.json: $!"; + say "Persona spec file saved to: browserid.json"; + + # Generate configuration file. + $::MULKONF = { + configpath => $configpath, + pemfile => $pemfile, + aliases_file => $aliases_file, + imap_server => $imap_server, + imap_port => $imap_port + }; + write_file($conffile, <<EOF +#! /usr/bin/env perl +# NB. Do not edit this file directly. It is overwritten with each run of setup.pl. +@{[Data::Dumper->Dump([$::MULKONF], ["::MULKONF"])]} +1; +EOF + ) or die "Could not write configuration to $conffile: $!"; + say "Configuration saved to: $conffile"; + + say ""; + say "******************************************************************"; + say "* FINISHED. *"; + say "* *"; + say "* Please put browserid.json where it will be served as *"; + say "* https://<whatever>/.well-known/browserid *"; + say "* with a content type of: *"; + say "* application/json *"; + say "* *"; + say "* In addition, please ensure that the private key file can be *"; + say "* read by the web server by assigning the file to the *"; + say "* appropriate owner. *"; + say "******************************************************************"; +} + +1; + @@ -1,118 +1,4 @@ #! /usr/bin/env perl -# Copyright 2012, Matthias Andreas Benkard <code@mail.matthias.benkard.de>. +system "perl build.PL"; +system "perl Build"; -use common::sense; -use Modern::Perl; -use JSON; -use Crypt::OpenSSL::RSA; -use File::Slurp qw(write_file read_file); -use File::Path qw(make_path); -use File::Copy; -use LWP::Simple qw(getstore); -use Data::Dumper; - -sub prompt($$) { - my ($question, $default) = @_; - $|++; - print "${question} \[${default}\] "; - $_ = <>; - chomp; - if ($_) { - return $_; - } else { - return $default; - } -} - -sub makespec($) { - my ($key) = @_; - my ($n, $e, @stuff) = $key->get_key_parameters; - return - encode_json({"public-key" => {e => $e->to_decimal, n => $n->to_decimal, algorithm => "RS"}, - "authentication" => "/browserid/authenticate.html", - "provisioning" => "/browserid/provision.html"}); -}; - -my $conffile = "www/config.pl"; - -# Generate configuration file. -$::MULKONF = { }; -if (stat($conffile)) { - say "Found existing configuration ($conffile)."; - do $conffile; -} - -my $configpath = $::MULKONF->{configpath} // "/etc/mulkyid"; -$configpath = prompt("Where shall I put configuration files?", $configpath); -my $pemfile = $::MULKONF->{pemfile} // "$configpath/rsa2048.pem"; -$pemfile = prompt("Where shall I put the private key?", $pemfile); -my $aliases_file = $::MULKONF->{aliases_file} // "/etc/aliases"; -$aliases_file = prompt("Where is the aliases file? Type a single dot for none.", $aliases_file); -my $imap_server = $::MULKONF->{imap_server} // "localhost"; -$imap_server = prompt("What is the IMAP server's address?", $imap_server); -my $imap_port = $::MULKONF->{imap_port} // 143; -$imap_port = int(prompt("What is the IMAP server's port?", $imap_port)); - -say "OK."; - -# Download jQuery. -make_path("www/jquery"); -if (stat("www/jquery/jquery.js")) { - say "Using existing copy of jQuery (www/jquery/jquery.js)."; -} else { - say "Fetching jQuery..."; - getstore("http://code.jquery.com/jquery-1.7.2.min.js", "www/jquery/jquery.js") - or die "Could not fetch jQuery"; - say "jQuery saved to: www/jquery/jquery.js"; -} - -# Generate the private key. -my $key; -if (stat($pemfile)) { - say "Using existing private key ($pemfile)."; - $key = Crypt::OpenSSL::RSA->new_private_key(scalar read_file($pemfile)); -} else { - say "Generating private key..."; - $key = Crypt::OpenSSL::RSA->generate_key(2048); - make_path($configpath); - write_file($pemfile, $key->get_private_key_string()) - or die "Could not write private key to $pemfile: $!"; - say "Private key saved to: $pemfile". - chmod 0440, $pemfile; -} - -# Generate spec file. -write_file("browserid.json", makespec $key) - or die "Could not write spec to browserid.json: $!"; -say "Persona spec file saved to: browserid.json"; - -# Generate configuration file. -$::MULKONF = { - configpath => $configpath, - pemfile => $pemfile, - aliases_file => $aliases_file, - imap_server => $imap_server, - imap_port => $imap_port -}; -write_file($conffile, <<EOF -#! /usr/bin/env perl -# NB. Do not edit this file directly. It is overwritten with each run of setup.pl. -@{[Data::Dumper->Dump([$::MULKONF], ["::MULKONF"])]} -1; -EOF -) or die "Could not write configuration to $conffile: $!"; -say "Configuration saved to: $conffile"; - -say ""; -say "******************************************************************"; -say "* FINISHED. *"; -say "* *"; -say "* Please put browserid.json where it will be served as *"; -say "* https://<whatever>/.well-known/browserid *"; -say "* with a content type of: *"; -say "* application/json *"; -say "* *"; -say "* In addition, please ensure that the private key file can be *"; -say "* read by the web server by assigning the file to the *"; -say "* appropriate owner. *"; -say "******************************************************************"; |