App-Netdisco

 view release on metacpan or  search on metacpan

bin/netdisco-deploy  view on Meta::CPAN

This script deploys the Netdisco database schema, OUI data, and MIBs. Each of
these is an optional service which the user is asked to confirm.

Pre-existing requirements are that there be a database table created and a
user with rights to create tables in that database. Both the table and user
name must match those configured in your environment YAML file (default
F<~/environments/deployment.yml>).

This script will download the latest MAC address vendor prefix data from the
Internet, and update the OUI table in the database. Hence Internet access is
required to run the script.

Similarly the latest Netdisco MIB bundle is also downloaded and placed into
the user's home directory (or C<$ENV{NETDISCO_HOME}>).

If you upgrade Netdisco make sure you run this script again to make sure
your config remains compatible.

Before each upgrade also review the
L<Release notes|https://github.com/netdisco/netdisco/wiki/Release-Notes> since
additional steps might be required!

=head1 SESSION COOKIE KEY

Deploying the database stores the key which encrypts and authenticates every
Netdisco web session cookie, in the C<sessions> table under the id
C<dancer_session_cookie_key>. The key is read from the operating system random
source using L<Crypt::URandom>.

It is written only when that row is absent, so running this script again,
including on upgrade, never replaces the key and never signs anybody out.

To rotate the key, for instance if you believe it has been disclosed, delete
the row:

  DELETE FROM sessions WHERE id = 'dancer_session_cookie_key';

then run this script again and answer yes to the database schema update, and
restart the Netdisco web service. Every logged-in user is signed out and must
log in again.

An earlier release took this key from PostgreSQL's C<random()>, which is not a
cryptographically secure generator. Such a key is 32 characters long where a
key from this release is 64, so:

  SELECT length(a_session) FROM sessions
    WHERE id = 'dancer_session_cookie_key';

reports which of the two your deployment holds. Rotate as above if it reports
32.

=cut

print color 'bold cyan';
say 'This is the Netdisco 2 deployment script.';
say '';
say 'Before we continue, the following prerequisites must be in place:';
say ' * Database added to PostgreSQL for Netdisco';
say ' * User added to PostgreSQL with rights to the Netdisco Database';
say ' * "~/environments/deployment.yml" file configured with Database dsn/user/pass';
say ' * A full backup of any existing Netdisco database data';
say ' * Internet access (for OUIs and MIBs)';
say '';
say 'If you are upgrading Netdisco 2 read the release notes:';
say 'https://github.com/netdisco/netdisco/wiki/Release-Notes';
say 'There you will find required and incompatible changes';
say 'which are not covered by this script.';
say '';
say 'You will be asked to confirm all changes to your system.';
say '';
print color 'reset';

# explicit: HTTP::Tiny before 0.083 neither verifies by default nor reads this variable
my $verify_SSL = (($ENV{PERL_HTTP_TINY_SSL_INSECURE_BY_DEFAULT} || '') ne '1');

my $term = Term::ReadLine->new('netdisco');
my $bool = $term->ask_yn(
  prompt => 'So, is all of the above in place?', default => 'n',
);

exit(0) unless $bool;

say '';
$bool = $term->ask_yn(
  prompt => 'Would you like to update the database schema?', default => 'n',
);
deploy_db() if $bool;

say '';
$bool = $term->ask_yn(
  prompt => 'Download and update vendor MAC prefixes (OUI data)?', default => 'n',
);
deploy_oui() if $bool;

say '';
my $default_mibhome = dir($home, 'netdisco-mibs');
if (setting('mibhome') and setting('mibhome') ne $default_mibhome) {
    my $mibhome = $term->get_reply(
      print_me => "MIB home options:",
      prompt   => "Download and update MIB files to...?",
      choices  => [setting('mibhome'), $default_mibhome, 'Skip this.'],
      default  => 'Skip this.',
    );
    deploy_mibs($mibhome) if $mibhome and $mibhome ne 'Skip this.';
}
else {
    $bool = $term->ask_yn(
      prompt => "Download and update MIB files?", default => 'n',
    );
    deploy_mibs($default_mibhome) if $bool;
}

sub deploy_db {
  system('netdisco-db-deploy') == 0 or die "\n";
  print color 'bold blue';
  say 'DB schema update complete.';
  print color 'reset';

  print color 'bold blue';
  print 'Updating statistics... ';
  App::Netdisco::Util::Statistics::update_stats();



( run in 0.854 second using v1.01-cache-2.11-cpan-99fa8243a42 )