initial commit of file from CVS for e-smith-hosts on Wed 12 Jul 08:56:08 BST 2023
This commit is contained in:
38
root/etc/e-smith/db/hosts/migrate/10reformat
Normal file
38
root/etc/e-smith/db/hosts/migrate/10reformat
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
foreach my $host ($DB->get_all)
|
||||
{
|
||||
next if defined $host->prop('HostType');
|
||||
|
||||
my %properties;
|
||||
$properties{'InternalIP'} = $host->prop('InternalIP') || '';
|
||||
$properties{'ExternalIP'} = $host->prop('ExternalIP') || '';
|
||||
$properties{'MACAddress'} = $host->prop('MACAddress') || '';
|
||||
|
||||
# If defined as host 'self', change to new format
|
||||
if (($properties{'InternalIP'} eq 'self') &&
|
||||
($properties{'ExternalIP'} eq 'self'))
|
||||
{
|
||||
$properties{'HostType'} = 'Self';
|
||||
$properties{'InternalIP'} = '';
|
||||
$properties{'ExternalIP'} = '';
|
||||
$properties{'MACAddress'} = '';
|
||||
}
|
||||
# defined as 'local' entry in new format
|
||||
elsif( $properties{InternalIP} ne 'self' )
|
||||
{
|
||||
$properties{'HostType'} = 'Local';
|
||||
$properties{ExternalIP} = '';
|
||||
}
|
||||
elsif( $properties{ExternalIP} ne 'self' )
|
||||
{
|
||||
$properties{'HostType'} = 'Remote';
|
||||
$properties{InternalIP} = '';
|
||||
}
|
||||
else {
|
||||
warn "$host has no InternalIP or ExternalIP!\n";
|
||||
}
|
||||
|
||||
$host->delete_prop('Visibility');
|
||||
$host->merge_props(%properties);
|
||||
}
|
||||
}
|
22
root/etc/e-smith/db/hosts/migrate/10sanitise-db
Normal file
22
root/etc/e-smith/db/hosts/migrate/10sanitise-db
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
foreach my $host ($DB->get_all)
|
||||
{
|
||||
my $lc_key = lc($host->key);
|
||||
|
||||
next if ( $lc_key eq $host->key );
|
||||
|
||||
my $rec = $DB->get($lc_key);
|
||||
|
||||
if ($rec)
|
||||
{
|
||||
warn "HostsDB: " . $host->key .
|
||||
" NOT migrated as $lc_key exists\n";
|
||||
next;
|
||||
}
|
||||
|
||||
$rec = $DB->new_record($lc_key);
|
||||
$rec->merge_props($host->props);
|
||||
|
||||
$host->delete;
|
||||
}
|
||||
}
|
20
root/etc/e-smith/db/hosts/migrate/20eachdomain
Normal file
20
root/etc/e-smith/db/hosts/migrate/20eachdomain
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
use esmith::DomainsDB;
|
||||
my $ddb = esmith::DomainsDB->open_ro;
|
||||
# If there's no domains db, there's nothing to do
|
||||
return unless $ddb;
|
||||
|
||||
# For any bare hostname, create a qualified host record
|
||||
# for each domain, then delete the bare host record
|
||||
foreach my $host (grep { $_->key !~ /\./ } $DB->get_all)
|
||||
{
|
||||
my $key = $host->key;
|
||||
foreach my $d ($ddb->domains)
|
||||
{
|
||||
$d = $d->key;
|
||||
next if $DB->get("$key.$d");
|
||||
$DB->new_record("$key.$d", { $host->props });
|
||||
}
|
||||
$host->delete;
|
||||
}
|
||||
}
|
10
root/etc/e-smith/db/hosts/migrate/30sanitise_host_comment
Normal file
10
root/etc/e-smith/db/hosts/migrate/30sanitise_host_comment
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
# Purge quoting chars in comments to fix bug 8723 & bug 8806
|
||||
foreach my $host ($DB->get_all)
|
||||
{
|
||||
my $comment = $host->prop('Comment');
|
||||
next unless $comment;
|
||||
$comment =~ s/[^a-zA-Z0-9\ \_\-\,\.]+//g;
|
||||
$host->merge_props(Comment => $comment);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user