initial commit of file from CVS for e-smith-base on Thu 26 Oct 11:24:52 BST 2023

This commit is contained in:
2023-10-26 11:24:52 +01:00
parent bbc22988a8
commit 9510d1a360
678 changed files with 22721 additions and 2 deletions

View File

@@ -0,0 +1,38 @@
{
open F, "/etc/locale.conf";
my ($line) = grep(/^LANG/, <F>);
close F;
my $lang = ($line =~ /^LANG="?([a-zA-Z0-9_.-]*)"?/) ? $1 : "en_US.UTF-8";
my $kbdtype = "pc";
my $keytable = "us";
if (open F, "/etc/X11/xorg.conf.d/00-keyboard.conf")
{
my @lines = <F>;
close F;
#($line) = grep(/^KEYBOARDTYPE/, @lines);
#if ($line =~ /^KEYBOARDTYPE="(.*)"/)
#{
# $kbdtype = $1;
#}
($line) = grep(/^\s+Option "XkbLayout"/, @lines);
if ($line =~ /^\s+Option "XkbLayout"\s+"(.*)"/)
{
$keytable = $1;
}
}
my $sysconfig = $DB->get('sysconfig') ||
$DB->new_record('sysconfig',
{ type => 'configuration'}
);
$sysconfig->merge_props(
Language => $lang,
KeyboardType => $kbdtype,
Keytable => $keytable,
);
}

View File

@@ -0,0 +1,10 @@
{
my $syslog = $DB->get("syslog") or return;
my $rsyslog = $DB->get("rsyslog") ||
$DB->new_record("rsyslog", { type => "service" });
$rsyslog->merge_props($syslog->props);
$syslog->delete;
}

View File

@@ -0,0 +1,80 @@
{
=head1 NAME
set-access-defaults -- Set services to appropriate defaults for SystemMode
=head1 DESCRIPTION
The SystemMode can be changed through the console. When it is changed,
console-save is called, which causes services to be reconfigured in
accordance with the new SystemMode.
In servergateway mode, the following services are enabled on the
external interface: HTTP, HTTPS, SMTP, AUTH/IDENT
In servergateway-private mode, all external services are disabled
This script is a no-op if the SystemMode has not been changed.
=cut
my $conf = $DB;
my $current_mode = $conf->get_value('SystemMode') or return;
my $sysconfig = $conf->get("sysconfig") or return;
my $previous_mode = $sysconfig->prop('PreviousSystemMode')
|| "unknown";
if ($previous_mode eq "unknown")
{
$sysconfig->set_prop('PreviousSystemMode', $current_mode);
return;
}
return unless ( $previous_mode eq 'servergateway-private' or
$current_mode eq 'servergateway-private' );
#------------------------------------------------------------
# OK, we have a new SystemMode, go for it
#------------------------------------------------------------
my %service2access =
(
oidentd => "public",
'httpd-e-smith' => "public",
'qpsmtpd' => "public",
'sqpsmtpd' => "public",
ftp => "private",
imap => "private",
imaps => "private",
modSSL => "public",
pop3s => "private",
popd => "private",
sshd => "private",
telnet => "private",
);
if ( $current_mode eq 'servergateway-private' )
{
foreach my $key (keys %service2access)
{
$service2access{$key} = 'private';
}
}
#------------------------------------------------------------
# Enforce the default access rights
#------------------------------------------------------------
foreach my $service ( keys %service2access )
{
my $entry = $conf->get($service);
next unless ($entry);
$entry->set_prop("access", $service2access{$service});
}
$sysconfig->set_prop('PreviousSystemMode', $current_mode);
}

View File

@@ -0,0 +1,7 @@
{
use Data::UUID;
my $sysconfig = $DB->get('sysconfig') || $DB->new_record('sysconfig', { type => 'configuration'});
$sysconfig->prop('SystemID') || $sysconfig->set_prop("SystemID", new Data::UUID->create_str);
}

View File

@@ -0,0 +1,46 @@
{
use esmith::util;
use esmith::NetworksDB;
my $LocalIP = $DB->get('LocalIP');
return unless defined $LocalIP; # Nothing to migrate yet
$LocalIP = $LocalIP->value;
my $LocalNetmask = $DB->get('LocalNetmask');
return unless defined $LocalNetmask;
$LocalNetmask = $LocalNetmask->value;
my $ndb = esmith::NetworksDB->open
|| esmith::NetworksDB->create;
# And update networks db shadow
my ($localnet) = $ndb->get_all_by_prop( SystemLocalNetwork => 'yes' );
my ($local_network) =
esmith::util::computeNetworkAndBroadcast( $LocalIP, $LocalNetmask );
if ( defined $localnet && $localnet->key ne $local_network )
{
# We need to delete the old record
$localnet->delete;
$localnet = undef;
}
if ( !defined $localnet )
{
# We need to convert an existing local network to system network
$localnet = $ndb->get($local_network) ||
# or we need to create a new system network record
$ndb->new_record( $local_network, { type => 'network', } );
}
# Update the netmask while we are at it
$localnet->merge_props(
SystemLocalNetwork => 'yes',
Mask => $LocalNetmask,
);
# Make sure that localnetwork does not have a leftover
# Router property if it was previously an additional
# local network. Will fail silently if there is no
# Router property
$localnet->delete_prop('Router');
}

View File

@@ -0,0 +1,46 @@
{
use esmith::DomainsDB;
my $domain = $DB->get('DomainName');
return unless defined $domain; # Can't migrate without domain name
my $DomainName = $domain->value;
# Force lower case
$DomainName = lc($DomainName);
$domain->set_value($DomainName);
# Force lower case for SystemName as well, while we are at it
my $system = $DB->get('SystemName');
if ($system)
{
my $SystemName = lc($system->value);
$system->set_value($SystemName);
}
my $domains = esmith::DomainsDB->open ||
esmith::DomainsDB->create;
# And update domains db shadow
($domain) = $domains->get_all_by_prop(SystemPrimaryDomain => 'yes');
if (defined $domain)
{
# Nothing to do if it hasn't changed.
return if (lc($domain->key) eq "$DomainName");
# Otherwise we need to delete the old domain
$domain->delete;
}
# And create the new.
$domain = $domains->get($DomainName) ||
$domains->new_record($DomainName,
{
type => 'domain',
Content => 'Primary',
Description => 'Primary domain',
Nameservers => 'localhost',
});
$domain->merge_props(SystemPrimaryDomain => 'yes', Removable => 'no');
}

View File

@@ -0,0 +1,167 @@
{
#----------------------------------------------------------------------
# copyright (C) 1999-2005 Mitel Networks Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#----------------------------------------------------------------------
# Migrate old config db singletons into "interface" specifications:
#
# DHCPClient=dhi ExternalInterface=...|Configuration|DHCPHostname
# DHCPClient=(d|dh| ExternalInterface=...|Configuration|DHCPEthernetAddress
#
# EthernetDriver1=eepro100 LocalInterface=...|Name|eth0|Driver|eepro100
# EthernetDriver2=ne2k-pci ExternalInterface=...|Name|eth1|Driver|ne2k-pci
# EthernetDriver2=unknown ExternalInterface=...|Name|eth0.4094|Driver|unknown
# ExternalDHCP=off ExternalInterface=...|Configuration|static
# ExternalNetmask=255.255.255.0 ExternalInterface=...|Netmask|255.255.255.0
# GatewayIP=192.168.116.1 ExternalInterface=...|Gateway|192.168.116.1
# LocalIP=192.168.116.2 LocalInterface=...|IPAddress|192.168.116.2
# LocalNetmask=255.255.255.0 LocalInterface=...|Netmask|255.255.255.0
use esmith::util;
# No need to run this unless we have valid settings
return unless $DB->get_value("LocalIP");
my $internal = $DB->get("InternalInterface") ||
$DB->new_record("InternalInterface", {type => "interface"});
if (my $assign = $DB->get('EthernetAssign')){
$assign->delete;
}
my $diald = $DB->get("diald");
$diald->delete if $diald;
my $dhcpcd = $DB->get("dhcpcd");
$dhcpcd->delete if $dhcpcd;
my $wan = $DB->get("wan") || $DB->new_record("wan", {type => 'service'});
my $mode = $DB->get_value("SystemMode") || "servergateway";
my $bonding = $internal->prop('NICBonding') || "disabled";
my %int_props =
(
type => "interface",
Configuration => 'static',
Driver => $DB->get_value("EthernetDriver1"),
IPAddress => $DB->get_value("LocalIP"),
Netmask => $DB->get_value("LocalNetmask")
);
($int_props{Network}, $int_props{Broadcast}) =
esmith::util::computeNetworkAndBroadcast($int_props{IPAddress},
$int_props{Netmask} );
$internal->merge_props(%int_props);
my $external = $DB->get("ExternalInterface") ||
$DB->new_record("ExternalInterface", {type => 'interface'});
if ( $mode eq "serveronly" )
{
$external->merge_props(Configuration => 'disabled', Name => 'none');
$wan->merge_props(status => 'disabled');
return;
}
$wan->merge_props(status => 'enabled');
my $pppoe_status = $DB->get_prop('pppoe', 'status') || "disabled";
my $access_type = $DB->get_value('AccessType') || "unknown";
# Get the existing props
my %ext_props = $external->props;
my $second_interface = $ext_props{'Name'};
# Delete ones which may no longer apply
delete $ext_props{Driver};
delete $ext_props{Configuration};
# Set values which always apply
$ext_props{type} = "interface";
$ext_props{IPAddress} = $DB->get_value("ExternalIP");
$ext_props{Netmask} = $DB->get_value("ExternalNetmask");
$ext_props{Gateway} = $DB->get_value("GatewayIP");
if (defined $ext_props{IPAddress} && defined $ext_props{Gateway})
{
($ext_props{Network}, $ext_props{Broadcast}) =
esmith::util::computeNetworkAndBroadcast($ext_props{IPAddress},
$ext_props{Netmask} );
}
# Now determine others we need
if ($access_type eq 'dialup')
{
my $isdn = $DB->get_prop('isdn', 'status') || "disabled";
my $sync_isdn = $DB->get_prop('isdn', 'UseSyncPPP') || "no";
$ext_props{Name} = ($isdn eq "enabled" and $sync_isdn eq "yes") ?
"ippp0" : "ppp0";
# XXX FIXME - we should probably have dialup vs. isdn here
$ext_props{Configuration} = "dialup";
}
elsif ($pppoe_status eq 'enabled' )
{
$ext_props{Name} = "ppp0";
$ext_props{Configuration} = "pppoe";
my $pppoe = $DB->get('pppoe');
unless ($pppoe)
{
warn "pppoe record vanished\n";
return;
}
# Only update PhysicalInterface
# if we just switched to pppoe
# ($second_interface is the name of the real external interface)
$pppoe->set_prop("PhysicalInterface", $second_interface)
if ($second_interface ne 'ppp0');
}
else
{
$ext_props{Name} = $second_interface;
$ext_props{Driver} = $DB->get_value("EthernetDriver2");
}
my $external_dhcp = $DB->get_value("ExternalDHCP") || "off";
if ($external_dhcp eq "on")
{
my $dhcp_config = $DB->get_value("DHCPClient") || "d";
if ($dhcp_config eq "dhi")
{
# XXX FIXME - I think this should be "dhcpcd", which
# should be a new "service" type and the Hostname/MAC
# choice should be a property of that service
$ext_props{Configuration} = "DHCPHostname";
}
else
{
$ext_props{Configuration} = "DHCPEthernetAddress";
}
}
$ext_props{Configuration} ||= "static" ;
# And write back the changes to the config db
$external->merge_props(%ext_props);
}

View File

@@ -0,0 +1,6 @@
{
unlink "/etc/rc.d/rc7.d/S75keytable";
my $keytable = $DB->get('keytable');
return unless $keytable;
$keytable->delete;
}

View File

@@ -0,0 +1,19 @@
{
my $AccessType = $DB->get('AccessType');
my $DialupUserAccount = $DB->get('DialupUserAccount');
my $SystemName = $DB->get('SystemName');
return unless ($AccessType && $DialupUserAccount && $SystemName);
if ($AccessType->value eq 'dedicated'
&& $DialupUserAccount->value eq 'useraccount'
&& $SystemName->value ne 'e-smith')
{
# Heuristic to migrate DHCP client identifier - we used to use SystemName
# and now we use DialupUserAccount
# So we migrate SystemName to DialupUserAccount, unless DialupUserAccount
# is already set, or the SystemName appears not set (default setting)
$DialupUserAccount->merge_props(type => $SystemName->value);
}
}

View File

@@ -0,0 +1,56 @@
{
# Make sure that dhcpd service is sanely set up, using
# legacy values if they are available
my $dhcpd = $DB->get('dhcpd');
my $status = 'enabled';
my $old = $DB->get('DHCPServer');
if (defined $old)
{
$status = $old->value;
$old->delete;
}
# Define the dhcpd service unless it is already
# defined. Make it enabled, unless $DHCPServer
# told us otherwise.
$dhcpd ||= $DB->new_record('dhcpd', {
type => 'service',
status => $status,
});
my $oldstart = '0.0.0.65';
$old = $DB->get('DHCPServerStart');
if (defined $old)
{
$oldstart = $old->value;
$old->delete;
}
my $oldend = '0.0.0.250';
$old = $DB->get('DHCPServerEnd');
if (defined $old)
{
$oldend = $old->value;
$old->delete;
}
my $start = $dhcpd->prop('start') || $oldstart;
my $end = $dhcpd->prop('end') || $oldend;
$start = esmith::util::IPquadToAddr($start);
$end = esmith::util::IPquadToAddr($end);
my $netmask = esmith::util::IPquadToAddr($LocalNetmask);
my $localnet = esmith::util::IPquadToAddr($LocalIP) & $netmask;
# AND-out the host bits from the start and end ips.
# And, OR our local network with our start and end host values.
$start = $localnet | ($start & ~$netmask);
$end = $localnet | ($end & ~$netmask);
# Make sure that $start is less than $end (might not be if netmask has changed
if ($start > $end)
{
my $temp = $start;
$start = $end;
$end = $temp;
}
# Now save new values
$dhcpd->merge_props(start => esmith::util::IPaddrToQuad($start),
end => esmith::util::IPaddrToQuad($end));
}

View File

@@ -0,0 +1,20 @@
{
my %changes = (
rtl8139 => "8139too",
old_tulip => "tulip",
);
foreach my $n (qw (1 2 ))
{
my $driver = $DB->get("EthernetDriver$n");
if (defined $driver)
{
foreach my $old (keys %changes)
{
if ($driver->prop('type') eq $old)
{
$driver->merge_props(type => $changes{$old});
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
{
my $ntp = $DB->get('NTPServer');
if (defined $ntp)
{
$DB->new_record('ntpd', {
type => 'service',
status => 'enabled',
NTPServer => $ntp->value,
});
$ntp->delete;
}
}

View File

@@ -0,0 +1,18 @@
{
my $old = $DB->get('TelnetServerMode');
return unless defined $old;
my $status = $old->value;
$old->delete;
my %props = (
type => 'service',
'status' => (($status eq 'off') ? 'disabled' : 'enabled'),
access => 'private',
);
unless ($status =~ /off|on/)
{
# The other options are public and private.
$props{access} = $status;
}
$DB->new_record('telnet', \%props);
}

View File

@@ -0,0 +1,14 @@
{
# Add configuration database entry for TimeZone if there is not one already
return if defined $DB->get('TimeZone');
if (-l "/etc/localtime")
{
# get timezone information from the system /etc/localtime
my $localtime = readlink "/etc/localtime" || "US/Eastern";
# Make a relative link into an absolute one
$localtime =~ s:^\.\.::;
# Extract timezone from absolute path
$localtime =~ s:^/usr/share/zoneinfo/::;
$DB->new_record('TimeZone', {type => $localtime});
}
}

View File

@@ -0,0 +1,8 @@
{
foreach my $iface ( qw(InternalInterface ExternalInterface) )
{
my $iface = $DB->get($iface) || next;
next unless $iface->prop('HWAddress');
$iface->delete_prop('HWAddress');
}
}

View File

@@ -0,0 +1,9 @@
{
# Migrate old servers to new defaults if not customized
return unless defined $InternalInterface{NICBondingOptions};
if($InternalInterface{NICBondingOptions} eq "miimon=200")
{
$DB->get('InternalInterface')->set_prop('NICBondingOptions',
'miimon=200 mode=active-backup');
}
}

View File

@@ -0,0 +1,8 @@
{
# Remove NICBonding property unless conditions are met
return unless defined $InternalInterface{NICBonding};
return if($SystemMode eq "serveronly" and
$EthernetDriver1 eq $EthernetDriver2);
$DB->get('InternalInterface')->delete_prop('NICBonding');
}

View File

@@ -0,0 +1,9 @@
{
# Remove CipherSuite if it is the last insecure value
# Will not change CipherSuite if it has been modified from the original default, or deleted.
return unless defined $modSSL{CipherSuite};
if($modSSL{CipherSuite} eq 'HIGH:!SSLv2')
{
$DB->get('modSSL')->delete_prop ('CipherSuite');
}
}

View File

@@ -0,0 +1,10 @@
{
# Remove old, unused services from the configuration database
my @services = qw(haldaemon smolt udev-post messagebus ctrlaltdel pptpd klogd);
foreach my $service (@services){
my $entry = $DB->get($service);
$entry->delete if $entry;
}
}

View File

@@ -0,0 +1,12 @@
{
# set status as enabled starting SME10
# remove the -m option from the property email
my $email = $DB->get_prop('smartd','email') or return;
if ($email =~ /^-m (.*)$/)
{
$DB->set_prop('smartd','email', $1);
$DB->set_prop('smartd','status', 'enabled');
}
}