diff --git a/doc/sphinx/administration/bastion_conf.rst b/doc/sphinx/administration/bastion_conf.rst index 71e2d66..0b4a5bd 100644 --- a/doc/sphinx/administration/bastion_conf.rst +++ b/doc/sphinx/administration/bastion_conf.rst @@ -91,7 +91,7 @@ Session policies Options to customize the established sessions behaviour - :ref:`displayLastLogin` -- :ref:`allowUTF8` +- :ref:`fanciness` - :ref:`interactiveModeAllowed` - :ref:`interactiveModeTimeout` - :ref:`interactiveModeByDefault` @@ -611,16 +611,20 @@ displayLastLogin 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: diff --git a/etc/bastion/bastion.conf.dist b/etc/bastion/bastion.conf.dist index 5e26c99..c4e5746 100644 --- a/etc/bastion/bastion.conf.dist +++ b/etc/bastion/bastion.conf.dist @@ -262,10 +262,14 @@ # DEFAULT: true "displayLastLogin": true, # -# allowUTF8 (boolean) -# 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. -# DEFAULT: true -"allowUTF8": true, +# fanciness (string) +# 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. +# +# - "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) # DESC: If set to ``true``, ``--interactive`` mode is allowed. Otherwise, this feature is disabled. diff --git a/lib/perl/OVH/Bastion.pm b/lib/perl/OVH/Bastion.pm index 98c5b61..1c1d739 100644 --- a/lib/perl/OVH/Bastion.pm +++ b/lib/perl/OVH/Bastion.pm @@ -371,7 +371,8 @@ sub osh_header { my $hostname = Sys::Hostname::hostname(); my $versionline = 'the-bastion-' . $VERSION; 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"; $output .= colored($line, 'bold blue'); $output .= colored("\N{U+2502} \N{U+25B6} $text\n", 'blue'); @@ -395,7 +396,8 @@ sub osh_footer { } 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) . "" . "\N{U+2500}" x 3 . "\n", 'bold blue'); } else { @@ -510,15 +512,15 @@ sub _osh_log { print $output $params{'text'} . "\n"; } 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 $color; 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'; } 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'; } else { @@ -1056,8 +1058,8 @@ sub do_pamtester { 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 - return (OVH::Bastion::config('allowUTF8')->value && $ENV{'LANG'} && ($ENV{'LANG'} =~ /utf-?8/i) && $ENV{'TERM'} && $ENV{'TERM'} !~ /dumb|unknown/i); + # only use UTF-8 if user LANG seems to support it, and if TERM is defined and not dumb + return ($ENV{'LANG'} && ($ENV{'LANG'} =~ /utf-?8/i) && $ENV{'TERM'} && $ENV{'TERM'} !~ /dumb|unknown/i); } 1; diff --git a/lib/perl/OVH/Bastion/configuration.inc b/lib/perl/OVH/Bastion/configuration.inc index ac44c9a..f699317 100644 --- a/lib/perl/OVH/Bastion/configuration.inc +++ b/lib/perl/OVH/Bastion/configuration.inc @@ -133,7 +133,8 @@ sub load_configuration { {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 => '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'}) { @@ -226,7 +227,7 @@ sub load_configuration { options => [ qw{ enableSyslog enableGlobalAccessLog enableAccountAccessLog enableGlobalSqlLog enableAccountSqlLog displayLastLogin - interactiveModeByDefault allowUTF8 + interactiveModeByDefault } ], }, @@ -512,6 +513,11 @@ sub load_configuration { } 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 $_cache_config = $C; @@ -791,6 +797,7 @@ sub json_load { # Load file content my $rawConf; if (open(my $fh, '<', $file)) { + local $_ = undef; while (<$fh>) { chomp; s/^((?:(?:[^"]*"){2}|[^"]*)*[^"]*)\/\/.*$/$1/; # Remove comment that start with //