Add checks for correct reverse proxy configuration
[regano.git] / db_init.pl
blob88538ef0422761f8b8a91873a94395f600accc7e
1 #!/usr/bin/perl
3 # Database intialization for Regano
5 # Regano is free software. You can redistribute it and/or modify
6 # it under the same terms as Perl itself.
8 use DBI;
9 use strict;
10 use warnings;
12 my $dbh;
14 $dbh = DBI->connect('dbi:Pg:db=template1', undef, undef,
15 {AutoCommit => 1, RaiseError => 1})
16 or die $DBI::errstr;
18 eval {
19 local $dbh->{PrintError};
20 print "ensure 'regano' user exists\n";
21 $dbh->do(q[CREATE ROLE "regano" WITH LOGIN]);
23 eval {
24 local $dbh->{PrintError};
25 print "ensure 'regano-www' user exists\n";
26 $dbh->do(q[CREATE ROLE "regano-www" WITH LOGIN]);
29 eval {
30 local $dbh->{PrintError};
31 $dbh->do(q[DROP DATABASE "regano"]);
32 print "erase database 'regano'\n";
33 } if defined $ARGV[0] and $ARGV[0] eq 'erasedb';
34 $dbh->do(q[CREATE DATABASE "regano" WITH OWNER = "regano"]);
35 print "create database 'regano'\n";
37 $dbh->disconnect;
39 foreach my $part (qw(types tables functions config api antiskid)) {
40 system {'psql'} qw(psql -d regano -f), "db_${part}.sql"
43 $dbh = DBI->connect('dbi:Pg:db=regano', undef, undef,
44 {AutoCommit => 1, RaiseError => 1})
45 or die $DBI::errstr;
47 print "reserve \"@\" domain for storing TLD records\n";
48 $dbh->do
49 (q[INSERT INTO regano.reserved_domains (domain_name, reason)
50 VALUES ('@', 'Reserved for storing TLD records')]);
52 print "reserve \"@@\" domain for storing NS records for hosted zones\n";
53 $dbh->do
54 (q[INSERT INTO regano.reserved_domains (domain_name, reason)
55 VALUES ('@@', 'Reserved for storing NS records for host mirrors')]);
57 print "reserve \"example\" domain\n";
58 $dbh->do
59 (q[INSERT INTO regano.reserved_domains (domain_name, reason)
60 VALUES ('example', 'Reserved for use in documentation')]);
62 print "reserve IANA names:";
63 foreach (qw/rfc-editor gtld-servers iana-servers root-servers
64 aso dnso pso iab iana icann iesg ietf irtf istf
65 internic afrinic arin apnic lacnic latnic ripe/) {
66 print ' '.$_;
67 $dbh->do
68 (q[INSERT INTO regano.reserved_domains (domain_name, reason)
69 VALUES (?, 'Reserved to avoid confusion with IANA')], {}, $_);
71 print "\n";
73 print "reserve OpenNIC names:";
74 foreach (qw/register registrar opennic openic nic dot/) {
75 print ' '.$_;
76 $dbh->do
77 (q[INSERT INTO regano.reserved_domains (domain_name, reason)
78 VALUES (?, 'Reserved for OpenNIC')], {}, $_);
80 print "\n";
82 $dbh->disconnect;
84 __END__