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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,49 @@
package esmith::console::quitConsole;
use strict;
use warnings;
use Locale::gettext;
sub new
{
my $class = shift;
my $self = {
name => gettext("Exit from the server console"),
order => 100,
};
bless $self, $class;
return $self;
}
sub name
{
return $_[0]->{name};
}
sub order
{
return $_[0]->{order};
}
sub doit
{
my ($self, $console, $db) = @_;
if ( $db->get_value('UnsavedChanges') ne 'no' )
{
my ($rc, $choice) = $console->yesno_page
(
title => gettext("*** THERE ARE UNACTIVATED CHANGES - QUIT ANYWAY? ***"),
defaultno => 1,
text =>
gettext("Your configuration changes have been saved but have not yet been activated. This may result in unpredictable system behavior. We recommend that you complete the configuration process and activate the changes before exiting the console.") .
"\n\n" .
gettext("Are you sure you want to quit with unactivated changes?"),
);
return unless ($rc == 0);
}
system("/usr/bin/tput", "clear");
exit (0);
}
1;

View File

@@ -0,0 +1,33 @@
package esmith::console::save_config;
use Locale::gettext;
use esmith::console;
use strict;
use warnings;
sub new
{
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}
sub doit
{
my ($self, $console, $db) = @_;
#------------------------------------------------------------
SAVE_CONFIG:
#------------------------------------------------------------
# After saving config we don't need to run it again on the next reboot.
$db->set_prop("bootstrap-console", "ForceSave", "no");
$db->set_prop("bootstrap-console", "Run", "no");
$db->set_prop("bootstrap-console", "Restore", "enabled"); # Allow console restores
$console->infobox(
title => gettext("Activating configuration settings"),
text => gettext("Please stand by while your configuration settings are activated ..."),
);
system("/sbin/e-smith/signal-event", 'bootstrap-console-save');
}
1;

View File

@@ -0,0 +1,132 @@
package esmith::console::startup;
use Locale::gettext;
use esmith::console;
use esmith::ConfigDB;
use strict;
use warnings;
sub new
{
my $class = shift;
my $self = {
@_,
};
bless $self, $class;
return $self;
}
sub startup_callback {
my $fd = shift;
my @out = ();
my $done = 0;
use DirHandle;
my $d = DirHandle->new("/etc/rc7.d");
my @services = sort
{
$a =~ /^S(\d+)/; my $A = $1;
$b =~ /^S(\d+)/; my $B = $1;
$A <=> $B
} grep { /^S/ } $d->read;
my $rows = 12;
my $status_col = 65;
my $db = esmith::ConfigDB->open_ro;
my $rec = $db->get('smb');
my $i=0;
foreach (@services) {
$i=$i+1;
next unless /^S(\d+)([^\.][\.\w\-]+)$/;
next unless $2 eq "smb";
splice @services,$i-1 , 1, "S${1}4smbd", "S${1}5nmbd" unless ($rec and $rec->prop('status') eq 'disabled');
last;
}
open(STDOUT, ">&STDERR");
foreach (@services)
{
sleep 1;
my $percent = int(($done * 100) / ($#services + 1));
$done += 1;
my $link = $_;
#warn "Looking at symlink $_\n";
next unless /^S\d+([^\.][\.\w\-]+)$/; # Untaint service name
my $service = $1;
#my $db = esmith::ConfigDB->open_ro;
$rec = $db->get($service);
do
{
warn "not starting disabled service $service\n";
next;
} unless ($rec and $rec->prop('status') eq 'enabled');
my $prompt = "starting ";
my $supervised = -x "/service/$service/run";
my @cmd;
if (-x "/service/$service/run")
{
$prompt .= " supervised service $service";
warn "starting supervised service $service\n";
@cmd = ("sv", "up", "/service/$service");
}
elsif (-x "/etc/init.d/$service")
{
$prompt .= " unsupervised service $service";
warn "starting unsupervised service $service\n";
@cmd = ("/etc/init.d/$service", "start");
}
else
{
warn "ignoring unknown service $service: bogus start symlink $link\n";
next;
}
push @out, "$prompt\n";
print $fd "XXX\n";
print $fd "$percent\n";
my @show = $#out > $rows ? @out[$#out - $rows .. $#out] : @out;
do { print $fd $_ } foreach @show;
print $fd "XXX\n";
$prompt .= " " x ($status_col - length($prompt));
$prompt .= system(@cmd) ? "\\Z1FAILED\\Zn" : "\\Z2OK\\Zn";
$out[-1] = "$prompt\n";
@show = $#out > $rows ? @out[$#out - $rows .. $#out] : @out;
print $fd "XXX\n";
print $fd "$percent\n";
do { print $fd $_ } foreach @show;
print $fd "XXX\n";
}
print $fd "100\n";
sleep 2;
return undef;
};
my $console = esmith::console->new;
sub doit
{
my ($self, $console, $db) = @_;
$console->infobox
(
title => gettext("Starting system services"),
text => "\n" .
gettext("Please standby while system services are started ..."
),
);
system(qw(touch /var/lock/subsys/backup-running));
system(qw(chown admin /var/lock/subsys/backup-running));
sleep(6); # Wait to be certain that all runsv services have been started.
$console->gauge(\&startup_callback,
text => '',
title => 'Starting system services',
colors => 1,
no_collapse => 1);
}
#use esmith::console;
#use esmith::ConfigDB;
#esmith::console::startup->new->doit(esmith::console->new(),
# esmith::ConfigDB->open);
1;

View File

@@ -0,0 +1,148 @@
package esmith::console::system_password;
use esmith::util;
use Locale::gettext;
use strict;
use warnings;
sub new
{
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}
sub doit
{
my ($self, $console, $db) = @_;
return if ($db->get_value('PasswordSet') eq 'yes');
#------------------------------------------------------------
INITIAL_PASSWORD:
#------------------------------------------------------------
my $rc;
my $choice;
my $choice1;
my $choice2;
($rc, $choice1) = $console->password_page
(
title => gettext("Choose administrator password"),
text =>
gettext("Welcome to the server console!") .
"\n\n" .
gettext("You will now be taken through a sequence of screens to perform basic networking configuration on this server.") .
"\n\n" .
gettext("You can make your selections in each screen using the Arrow and Tab keys. At any point, if you select Back you will be returned to the previous screen.") .
"\n\n" .
gettext("Before you start, you must first choose the administrator password for your system and enter it below. You will not see the password as you enter it."),
);
unless ($rc == 0)
{
($rc, $choice) = $console->message_page
(
title => gettext("Administrator password not set"),
text => gettext("Sorry, you must set the administrator password now."),
);
goto INITIAL_PASSWORD;
}
unless ($choice1 =~ /^([ -~]+)$/)
{
($rc, $choice) = $console->message_page
(
title => gettext("Unprintable characters in password"),
text => gettext("The password must contain only printable characters."),
);
goto INITIAL_PASSWORD;
}
use Crypt::Cracklib;
#--------------------------------------------------------
# These are just to ensure that xgettext knows about the
# Cracklib strings.
# Note the extra space here and in the gettext call below. This
# allows the French localization to properly generate qu'il
gettext("it is based on your username");
gettext("it is based upon your password entry");
gettext("it is derived from your password entry");
gettext("it is derivable from your password entry");
gettext("it is too short");
gettext("it is all whitespace");
gettext("it is too simplistic/systematic");
gettext("it is based on a dictionary word");
gettext("it is based on a (reversed) dictionary word");
gettext("it does not contain numbers");
gettext("it does not contain uppercase characters");
gettext("it does not contain lowercase characters");
gettext("it does not contain special characters");
#--------------------------------------------------------
my $strength = $db->get_prop("passwordstrength", "Admin");
my $reason = esmith::util::validatePassword($choice1,$strength);
# Untaint return data from cracklib, so we can use it later. We
# trust the library, so we accept anything.
$reason =~ /(.+)/; $reason = $1;
$reason ||= gettext("Software error: password check failed");
unless ($reason eq 'ok')
{
($rc, $choice) = $console->yesno_page
(
title => gettext("Bad Password Choice"),
text =>
gettext("The password you have chosen is not a good choice, because ") .
gettext($reason) . "." .
"\n\n" .
gettext("Do you wish to choose a better one?"),
);
goto INITIAL_PASSWORD if ($rc == 0);
}
($rc, $choice2) = $console->password_page
(
title => gettext("Choose administrator password"),
text => gettext("Please type your administrator password again to verify."),
);
unless ($rc == 0)
{
($rc, $choice) = $console->message_page
(
title => gettext("Administrator password not set"),
text => gettext("Sorry, you must set the administrator password now."),
);
goto INITIAL_PASSWORD;
}
if ($choice1 ne $choice2)
{
($rc, $choice) = $console->message_page
(
title => gettext("Passwords do not match"),
text => gettext("The two passwords did not match"),
);
goto INITIAL_PASSWORD;
}
#--------------------------------------------------
# Set system password
#--------------------------------------------------
esmith::util::setUnixSystemPassword ($choice1);
esmith::util::setServerSystemPassword ($choice1);
my $old = $db->get_value('UnsavedChanges');
$db->set_value('PasswordSet', 'yes');
$db->set_value('UnsavedChanges', $old);
}
1;