mirror of
https://github.com/ovh/the-bastion.git
synced 2025-10-06 11:35:44 +08:00
enh: replace 'allowUTF8' (introduced in rc1) by 'fanciness'
This commit is contained in:
parent
5415ed2793
commit
2193ee487d
4 changed files with 36 additions and 19 deletions
|
@ -91,7 +91,7 @@ Session policies
|
||||||
Options to customize the established sessions behaviour
|
Options to customize the established sessions behaviour
|
||||||
|
|
||||||
- :ref:`displayLastLogin`
|
- :ref:`displayLastLogin`
|
||||||
- :ref:`allowUTF8`
|
- :ref:`fanciness`
|
||||||
- :ref:`interactiveModeAllowed`
|
- :ref:`interactiveModeAllowed`
|
||||||
- :ref:`interactiveModeTimeout`
|
- :ref:`interactiveModeTimeout`
|
||||||
- :ref:`interactiveModeByDefault`
|
- :ref:`interactiveModeByDefault`
|
||||||
|
@ -611,16 +611,20 @@ displayLastLogin
|
||||||
|
|
||||||
If ``true``, display their last login information on connection to your users.
|
If ``true``, display their last login information on connection to your users.
|
||||||
|
|
||||||
.. _allowUTF8:
|
.. _fanciness:
|
||||||
|
|
||||||
allowUTF8
|
fanciness
|
||||||
*********
|
*********
|
||||||
|
|
||||||
:Type: ``boolean``
|
:Type: ``string``
|
||||||
|
|
||||||
:Default: ``true``
|
:Default: ``full``
|
||||||
|
|
||||||
When ``true``, The Bastion will use some UTF-8 characters on the output, for a more pleasant experience (for warnings, critical messages, etc.). Note that if the terminal doesn't advertise UTF-8 support, UTF-8 will not be used, even when enabled here.
|
Customize to which extent the text output by the program will use decorations to enhance human-friendliness and highlight warnings or critical messages. Note that if a given session's terminal doesn't advertise UTF-8 support, UTF-8 will not be used, regardless of what is set here.
|
||||||
|
|
||||||
|
- "none": Text will only consist of us-ascii characters
|
||||||
|
- "basic": UTF-8 characters will be used to draw tables, instead of ---'s, among other things
|
||||||
|
- "full": Some emoticons may appear to highlight important messages
|
||||||
|
|
||||||
.. _interactiveModeAllowed:
|
.. _interactiveModeAllowed:
|
||||||
|
|
||||||
|
|
|
@ -262,10 +262,14 @@
|
||||||
# DEFAULT: true
|
# DEFAULT: true
|
||||||
"displayLastLogin": true,
|
"displayLastLogin": true,
|
||||||
#
|
#
|
||||||
# allowUTF8 (boolean)
|
# fanciness (string)
|
||||||
# DESC: When ``true``, The Bastion will use some UTF-8 characters on the output, for a more pleasant experience (for warnings, critical messages, etc.). Note that if the terminal doesn't advertise UTF-8 support, UTF-8 will not be used, even when enabled here.
|
# DESC: Customize to which extent the text output by the program will use decorations to enhance human-friendliness and highlight warnings or critical messages. Note that if a given session's terminal doesn't advertise UTF-8 support, UTF-8 will not be used, regardless of what is set here.
|
||||||
# DEFAULT: true
|
#
|
||||||
"allowUTF8": true,
|
# - "none": Text will only consist of us-ascii characters
|
||||||
|
# - "basic": UTF-8 characters will be used to draw tables, instead of ---'s, among other things
|
||||||
|
# - "full": Some emoticons may appear to highlight important messages
|
||||||
|
# DEFAULT: full
|
||||||
|
"fanciness": "full",
|
||||||
#
|
#
|
||||||
# interactiveModeAllowed (boolean)
|
# interactiveModeAllowed (boolean)
|
||||||
# DESC: If set to ``true``, ``--interactive`` mode is allowed. Otherwise, this feature is disabled.
|
# DESC: If set to ``true``, ``--interactive`` mode is allowed. Otherwise, this feature is disabled.
|
||||||
|
|
|
@ -371,7 +371,8 @@ sub osh_header {
|
||||||
my $hostname = Sys::Hostname::hostname();
|
my $hostname = Sys::Hostname::hostname();
|
||||||
my $versionline = 'the-bastion-' . $VERSION;
|
my $versionline = 'the-bastion-' . $VERSION;
|
||||||
my $output = '';
|
my $output = '';
|
||||||
if (OVH::Bastion::can_use_utf8()) {
|
my $fanciness = OVH::Bastion::config('fanciness')->value;
|
||||||
|
if (OVH::Bastion::can_use_utf8() && grep { $fanciness eq $_ } qw{ basic full }) {
|
||||||
my $line = "\N{U+256D}\N{U+2500}\N{U+2500}" . $hostname . "\N{U+2500}" x (80 - length($hostname) - length($versionline) - 6) . $versionline . "\N{U+2500}" x 3 . "\n";
|
my $line = "\N{U+256D}\N{U+2500}\N{U+2500}" . $hostname . "\N{U+2500}" x (80 - length($hostname) - length($versionline) - 6) . $versionline . "\N{U+2500}" x 3 . "\n";
|
||||||
$output .= colored($line, 'bold blue');
|
$output .= colored($line, 'bold blue');
|
||||||
$output .= colored("\N{U+2502} \N{U+25B6} $text\n", 'blue');
|
$output .= colored("\N{U+2502} \N{U+25B6} $text\n", 'blue');
|
||||||
|
@ -395,7 +396,8 @@ sub osh_footer {
|
||||||
}
|
}
|
||||||
|
|
||||||
my $output;
|
my $output;
|
||||||
if (OVH::Bastion::can_use_utf8()) {
|
my $fanciness = OVH::Bastion::config('fanciness')->value;
|
||||||
|
if (OVH::Bastion::can_use_utf8() && grep { $fanciness eq $_ } qw{ basic full }) {
|
||||||
$output = colored("\N{U+2570}" . "\N{U+2500}" x (79 - length($text) - 6) . "</$text>" . "\N{U+2500}" x 3 . "\n", 'bold blue');
|
$output = colored("\N{U+2570}" . "\N{U+2500}" x (79 - length($text) - 6) . "</$text>" . "\N{U+2500}" x 3 . "\n", 'bold blue');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -510,15 +512,15 @@ sub _osh_log {
|
||||||
print $output $params{'text'} . "\n";
|
print $output $params{'text'} . "\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $prefix = OVH::Bastion::can_use_utf8() ? "\N{U+2502}" : '~';
|
my $prefix = OVH::Bastion::can_use_utf8() && OVH::Bastion::config('fanciness')->value eq 'full' ? "\N{U+2502}" : '~';
|
||||||
my $prefixIfNotEmpty = '';
|
my $prefixIfNotEmpty = '';
|
||||||
my $color;
|
my $color;
|
||||||
if ($params{'type'} eq 'crit') {
|
if ($params{'type'} eq 'crit') {
|
||||||
$prefixIfNotEmpty = (OVH::Bastion::can_use_utf8() ? "\N{U+26D4}" : "[!]");
|
$prefixIfNotEmpty = (OVH::Bastion::can_use_utf8() && OVH::Bastion::config('fanciness')->value eq 'full' ? "\N{U+26D4}" : "[!]");
|
||||||
$color = 'red bold';
|
$color = 'red bold';
|
||||||
}
|
}
|
||||||
elsif ($params{'type'} eq 'warn') {
|
elsif ($params{'type'} eq 'warn') {
|
||||||
$prefixIfNotEmpty = (OVH::Bastion::can_use_utf8() ? "\N{U+2757}" : "[#]");
|
$prefixIfNotEmpty = (OVH::Bastion::can_use_utf8() && OVH::Bastion::config('fanciness')->value eq 'full' ? "\N{U+2757}" : "[#]");
|
||||||
$color = 'yellow';
|
$color = 'yellow';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1056,8 +1058,8 @@ sub do_pamtester {
|
||||||
|
|
||||||
sub can_use_utf8 {
|
sub can_use_utf8 {
|
||||||
|
|
||||||
# only use UTF-8 if allowed in the config, if user LANG seems to support it, and if TERM is defined and not dumb
|
# only use UTF-8 if user LANG seems to support it, and if TERM is defined and not dumb
|
||||||
return (OVH::Bastion::config('allowUTF8')->value && $ENV{'LANG'} && ($ENV{'LANG'} =~ /utf-?8/i) && $ENV{'TERM'} && $ENV{'TERM'} !~ /dumb|unknown/i);
|
return ($ENV{'LANG'} && ($ENV{'LANG'} =~ /utf-?8/i) && $ENV{'TERM'} && $ENV{'TERM'} !~ /dumb|unknown/i);
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -133,7 +133,8 @@ sub load_configuration {
|
||||||
{name => 'syslogDescription', default => 'bastion', validre => qr/^([a-zA-Z0-9_.-]+)$/},
|
{name => 'syslogDescription', default => 'bastion', validre => qr/^([a-zA-Z0-9_.-]+)$/},
|
||||||
{name => 'ttyrecFilenameFormat', default => '%Y-%m-%d.%H-%M-%S.#usec#.&uniqid.&account.&user.&ip.&port.ttyrec', validre => qr/^([a-zA-Z0-9%&#_.-]+)$/},
|
{name => 'ttyrecFilenameFormat', default => '%Y-%m-%d.%H-%M-%S.#usec#.&uniqid.&account.&user.&ip.&port.ttyrec', validre => qr/^([a-zA-Z0-9%&#_.-]+)$/},
|
||||||
{name => 'accountExpiredMessage', default => '', validre => qr/^(.*)$/, emptyok => 1},
|
{name => 'accountExpiredMessage', default => '', validre => qr/^(.*)$/, emptyok => 1},
|
||||||
{name => 'accountExternalValidationProgram', default => '', validre => qr'^([a-zA-Z0-9/$_.-]*)$', emptyok => 1},
|
{name => 'fanciness', default => 'full', validre => qr/^((none|boomer)|(basic|millenial)|(full|genz))$/},
|
||||||
|
{name => 'accountExternalValidationProgram', default => '', validre => qr'^([a-zA-Z0-9/$_.-]*)$', emptyok => 1},
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!$C->{$o->{'name'}} && !$o->{'emptyok'}) {
|
if (!$C->{$o->{'name'}} && !$o->{'emptyok'}) {
|
||||||
|
@ -226,7 +227,7 @@ sub load_configuration {
|
||||||
options => [
|
options => [
|
||||||
qw{
|
qw{
|
||||||
enableSyslog enableGlobalAccessLog enableAccountAccessLog enableGlobalSqlLog enableAccountSqlLog displayLastLogin
|
enableSyslog enableGlobalAccessLog enableAccountAccessLog enableGlobalSqlLog enableAccountSqlLog displayLastLogin
|
||||||
interactiveModeByDefault allowUTF8
|
interactiveModeByDefault
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -512,6 +513,11 @@ sub load_configuration {
|
||||||
}
|
}
|
||||||
delete $unknownkeys{'ingressToEgressRules'};
|
delete $unknownkeys{'ingressToEgressRules'};
|
||||||
|
|
||||||
|
# ... normalize fanciness
|
||||||
|
$C->{'fanciness'} = 'none' if $C->{'fanciness'} eq 'boomer';
|
||||||
|
$C->{'fanciness'} = 'basic' if $C->{'fanciness'} eq 'millenial';
|
||||||
|
$C->{'fanciness'} = 'full' if $C->{'fanciness'} eq 'genz';
|
||||||
|
|
||||||
# OK we're done
|
# OK we're done
|
||||||
$_cache_config = $C;
|
$_cache_config = $C;
|
||||||
|
|
||||||
|
@ -791,6 +797,7 @@ sub json_load {
|
||||||
# Load file content
|
# Load file content
|
||||||
my $rawConf;
|
my $rawConf;
|
||||||
if (open(my $fh, '<', $file)) {
|
if (open(my $fh, '<', $file)) {
|
||||||
|
local $_ = undef;
|
||||||
while (<$fh>) {
|
while (<$fh>) {
|
||||||
chomp;
|
chomp;
|
||||||
s/^((?:(?:[^"]*"){2}|[^"]*)*[^"]*)\/\/.*$/$1/; # Remove comment that start with //
|
s/^((?:(?:[^"]*"){2}|[^"]*)*[^"]*)\/\/.*$/$1/; # Remove comment that start with //
|
||||||
|
|
Loading…
Add table
Reference in a new issue