-
Notifications
You must be signed in to change notification settings - Fork 8
/
hda-settings
executable file
·98 lines (81 loc) · 2.24 KB
/
hda-settings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl -w
#
# Amahi Home Server
# Copyright (C) 2007-2009 Amahi Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License v3
# (29 June 2007), as published in the COPYING file.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# file COPYING for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Amahi
# team at http://www.amahi.org/ under "Contact Us."
use strict;
use DBI();
my $dbh;
my %settings;
my $DATABASE_NAME = "hda_production";
my $DATABASE_USER = "amahihda";
my $DATABASE_PASSWORD = "AmahiHDARulez";
sub db_connect {
my $password = $DATABASE_PASSWORD ; # &get_password();
# connect to the database.
$dbh = DBI->connect("DBI:mysql:database=$DATABASE_NAME;host=localhost",
$DATABASE_USER, $password, {RaiseError => 1})
or die $DBI::errstr;
}
sub get_db_settings {
my $sth = $dbh->prepare("SELECT Name, Value, Kind FROM settings");
$sth->execute();
print "General settings:\n";
my @row = ();
while (@row = $sth->fetchrow_array) {
my $name = $row[0];
my $value = $row[1];
my $kind = $row[2];
$value = $value || "";
$settings {$name} = $value;
print "\t$kind/$name: $value\n";
}
}
sub get_db_hosts {
my $sth = $dbh->prepare("SELECT name, address, mac FROM hosts");
$sth->execute();
print "Static hosts:\n";
my @row = ();
while (@row = $sth->fetchrow_array) {
my $name = $row[0];
my $address = $row[1];
my $mac = $row[2];
print "\tInterface $mac <- $name/$address\n";
}
}
sub get_db_aliases {
my $sth = $dbh->prepare("SELECT name, address FROM dns_aliases");
$sth->execute();
print "Alias names:\n";
my @row = ();
while (@row = $sth->fetchrow_array) {
my $alias = $row[0];
my $address = $row[1];
my $addr = 'undefined!';
if ($address eq '') {
$addr = $settings{'self-address'} if (defined($settings{'self-address'}));
} else {
$addr = $address;
}
print "\tAlias $alias -> $addr\n";
}
}
sub main {
&db_connect ();
&get_db_settings ();
&get_db_hosts ();
&get_db_aliases ();
}
&main();