forked from .cyb/cyberman
Don't keep updating the SOA every minute, it's not nice
This commit is contained in:
parent
1d160990d9
commit
4be5a07e86
|
@ -15,6 +15,16 @@ my $yml = YAML::Tiny->read("$Bin/../config.yml");
|
|||
my $tld = $yml->[0]->{"tld"};
|
||||
my $conf = $yml->[0]->{"zonewriter"};
|
||||
|
||||
die "Unsupported database!"
|
||||
unless $yml->[0]->{"plugins"}->{"Database"}->{"driver"} eq "SQLite";
|
||||
my $dbfile = "$Bin/../$yml->[0]->{plugins}->{Database}->{dbname}";
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
|
||||
|
||||
my $sth = $dbh->prepare("SELECT * from cyberman");
|
||||
$sth->execute;
|
||||
my $cyberman = $sth->fetchrow_hashref;
|
||||
exit unless $cyberman->{"intserial"} > $cyberman->{"lastserial"};
|
||||
|
||||
open my $out, ">", $conf->{"file"} or die $!;
|
||||
|
||||
# Introduction
|
||||
|
@ -41,12 +51,7 @@ if ($conf->{"include"}->{"enabled"}) {
|
|||
}
|
||||
|
||||
# Time to get the records
|
||||
die "Unsupported database!"
|
||||
unless $yml->[0]->{"plugins"}->{"Database"}->{"driver"} eq "SQLite";
|
||||
my $dbfile = "$Bin/../$yml->[0]->{plugins}->{Database}->{dbname}";
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
|
||||
|
||||
my $sth = $dbh->prepare("SELECT * FROM record");
|
||||
$sth = $dbh->prepare("SELECT * FROM record");
|
||||
$sth->execute;
|
||||
|
||||
while (my $r = $sth->fetchrow_hashref) {
|
||||
|
@ -71,3 +76,7 @@ while (my $r = $sth->fetchrow_hashref) {
|
|||
}
|
||||
|
||||
close $out;
|
||||
|
||||
$sth = $dbh->prepare("UPDATE cyberman SET lastserial=?");
|
||||
$sth->bind_param(1, $cyberman->{"intserial"});
|
||||
$sth->execute;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
alter table cyberman add column intserial integer not null default 1;
|
||||
alter table cyberman add column lastserial integer not null default 0;
|
||||
update cyberman set dbrev=7;
|
|
@ -1,6 +1,7 @@
|
|||
package cyberman::Helper;
|
||||
use base qw(Exporter);
|
||||
use Dancer2 appname => "cyberman";
|
||||
use Dancer2::Plugin::Database;
|
||||
|
||||
use Math::Random::Secure qw(irand);
|
||||
use Digest::Bcrypt;
|
||||
|
@ -10,7 +11,7 @@ use Email::Simple::Creator;
|
|||
|
||||
use Exporter qw(import);
|
||||
|
||||
our @EXPORT = qw(auth_test randstring hash_password check_name send_email);
|
||||
our @EXPORT = qw(auth_test randstring hash_password check_name send_email incr_serial);
|
||||
|
||||
# Helper functions
|
||||
|
||||
|
@ -97,4 +98,19 @@ sub send_email {
|
|||
sendmail($email) if config->{"mail"}->{"enabled"};
|
||||
}
|
||||
|
||||
sub incr_serial {
|
||||
my $cyberman = database->quick_select(
|
||||
"cyberman",
|
||||
{},
|
||||
);
|
||||
database->quick_update(
|
||||
"cyberman",
|
||||
{},
|
||||
{
|
||||
"intserial" => $cyberman->{"intserial"} + 1,
|
||||
},
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -126,6 +126,8 @@ post '/domains/:name/records/add' => sub {
|
|||
},
|
||||
);
|
||||
|
||||
incr_serial();
|
||||
|
||||
template 'redir' => {
|
||||
"redir" => "../records?added=1",
|
||||
};
|
||||
|
@ -165,6 +167,8 @@ post '/domains/:name/records/:sid/remove' => sub {
|
|||
},
|
||||
);
|
||||
|
||||
incr_serial();
|
||||
|
||||
template 'redir' => {
|
||||
"redir" => "../../records?removed=1",
|
||||
};
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
drop table if exists cyberman;
|
||||
create table cyberman (
|
||||
id integer primary key,
|
||||
dbrev integer not null
|
||||
dbrev integer not null,
|
||||
intserial integer not null default 1,
|
||||
lastserial integer not null default 0
|
||||
);
|
||||
insert into cyberman (dbrev) values (6);
|
||||
insert into cyberman (dbrev) values (7);
|
||||
|
||||
drop table if exists user;
|
||||
create table user (
|
||||
|
|
Loading…
Reference in New Issue