4 # Copyright (C) 2008 Andrew Bartlett <abartlet@samba.org>
5 # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
29 my ($class, $filename) = @_;
31 my $dbh = DBI->connect("dbi:SQLite:$filename") or return undef;
33 my $self = { filename => $filename, dbh => $dbh };
42 $self->{dbh}->do("CREATE TABLE host ( name text, owner text, owner_email text, password text, ssh_access int, fqdn text, platform text, permission text );");
44 $self->{dbh}->do("CREATE UNIQUE INDEX unique_hostname ON host (name);");
47 sub createhost($$$$$$)
49 my ($self, $name, $platform, $owner, $owner_email, $password, $permission) = @_;
50 my $sth = $self->{dbh}->prepare("INSERT INTO host (name, platform, owner, owner_email, password, permission) VALUES (?,?,?,?,?,?)");
52 $sth->execute($name, $platform, $owner, $owner_email, $password, $permission);
57 my ($self, $name) = @_;
59 my $sth = $self->{dbh}->prepare("DELETE FROM host WHERE name = ?");
61 my $ret = $sth->execute($name);
70 return $self->{dbh}->selectall_arrayref("SELECT * FROM host", { Slice => {} });
75 my ($self, $name) = @_;
77 my $hosts = $self->hosts();
80 return $_ if ($_->{name} eq $name);
86 sub update_platform($$$)
88 my ($self, $name, $new_platform) = @_;
90 my $changed = $self->{dbh}->do("UPDATE host SET platform = ? WHERE name = ?", undef,
91 ($new_platform, $name));
93 return ($changed == 1);
96 sub update_owner($$$$)
98 my ($self, $name, $new_owner, $new_owner_email) = @_;
100 my $changed = $self->{dbh}->do("UPDATE host SET owner = ?, owner_email = ? WHERE name = ?",
101 undef, ($new_owner, $new_owner_email, $name));
103 return ($changed == 1);
106 # Write out the rsyncd.secrets
107 sub create_rsync_secrets($)
111 my $hosts = $db->hosts();
115 $res .= "# rsyncd.secrets file\n";
116 $res .= "# automatically generated by textfiles.pl. DO NOT EDIT!\n\n";
119 $res .= "# $_->{name}, owner: $_->{owner} <$_->{owner_email}>\n";
120 $res .= "$_->{name}:$_->{password}\n\n";
127 sub create_hosts_list($)
133 my $hosts = $self->hosts();
136 $res .= "$_->{name}: $_->{platform}\n";