mirror of
https://github.com/ovh/the-bastion.git
synced 2025-10-30 23:37:36 +08:00
feat: add UTF-8 chars to output when supported and allowed
To enhance the readability and visibility of important messages (such as critical ones). This can be disabled with the `allowUTF8` global option set to `false`. It's never enabled if the user locale or their terminal don't seem to support it.
This commit is contained in:
parent
60ad30ce5b
commit
adb9d8c374
6 changed files with 61 additions and 19 deletions
|
|
@ -22,7 +22,7 @@ my $remainingOptions = OVH::Bastion::Plugin::begin(
|
||||||
);
|
);
|
||||||
|
|
||||||
sub help {
|
sub help {
|
||||||
print <<"EOF";
|
my $text = <<"EOF";
|
||||||
Create a new public + private key pair on your bastion account
|
Create a new public + private key pair on your bastion account
|
||||||
|
|
||||||
Usage: --osh $scriptName --algo ALGO --size SIZE [--encrypted]
|
Usage: --osh $scriptName --algo ALGO --size SIZE [--encrypted]
|
||||||
|
|
@ -37,6 +37,7 @@ Usage: --osh $scriptName --algo ALGO --size SIZE [--encrypted]
|
||||||
--encrypted if specified, a passphrase will be prompted for the new key
|
--encrypted if specified, a passphrase will be prompted for the new key
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
osh_info($text);
|
||||||
OVH::Bastion::Plugin::generateEgressKey::help_algos();
|
OVH::Bastion::Plugin::generateEgressKey::help_algos();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,11 +89,11 @@ if (!-r $ttyrecfile) {
|
||||||
osh_exit R('ERR_NOT_FOUND', msg => "Recorded session for ID $id couldn't be found, it might have been archived");
|
osh_exit R('ERR_NOT_FOUND', msg => "Recorded session for ID $id couldn't be found, it might have been archived");
|
||||||
}
|
}
|
||||||
|
|
||||||
osh_warn "Press '+' to play faster";
|
osh_info "Press '+' to play faster";
|
||||||
osh_warn "Press '-' to play slower";
|
osh_info "Press '-' to play slower";
|
||||||
osh_warn "Press '1' to restore normal playing speed";
|
osh_info "Press '1' to restore normal playing speed";
|
||||||
osh_warn "\nWhen you're ready to replay session $id, press ENTER.";
|
osh_info "\nWhen you're ready to replay session $id, press ENTER.";
|
||||||
osh_warn "Starting from the next line, the Total Recall begins. Press CTRL+C to jolt awake.";
|
osh_info "Starting from the next line, the Total Recall begins. Press CTRL+C to jolt awake.";
|
||||||
<STDIN>;
|
<STDIN>;
|
||||||
my $sysret = system('ttyplay', $ttyrecfile);
|
my $sysret = system('ttyplay', $ttyrecfile);
|
||||||
osh_ok {};
|
osh_ok {};
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ use POSIX qw(strftime);
|
||||||
use Term::ANSIColor;
|
use Term::ANSIColor;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
$ENV{'LANG'} = 'C';
|
|
||||||
$| = 1;
|
$| = 1;
|
||||||
my $fnret;
|
my $fnret;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -262,6 +262,11 @@
|
||||||
# DEFAULT: true
|
# DEFAULT: true
|
||||||
"displayLastLogin": 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,
|
||||||
|
#
|
||||||
# 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.
|
||||||
# DEFAULT: true
|
# DEFAULT: true
|
||||||
|
|
|
||||||
|
|
@ -367,9 +367,18 @@ 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 = '';
|
||||||
$output .= colored('---' . $hostname . '-' x (80 - length($hostname) - length($versionline) - 6) . "$versionline---" . "\n", 'bold blue');
|
if (OVH::Bastion::can_use_utf8()) {
|
||||||
$output .= colored("=> $text\n", "blue");
|
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('-' x 80 . "\n", 'blue');
|
$output .= colored($line, 'bold blue');
|
||||||
|
$output .= colored("\N{U+2502} \N{U+25B6} $text\n", 'blue');
|
||||||
|
$output .= colored("\N{U+251C}" . "\N{U+2500}" x 79 . "\n", 'blue');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my $line = '-' x 3 . $hostname . '-' x (80 - length($hostname) - length($versionline) - 6) . $versionline . '-' x 3 . "\n";
|
||||||
|
$output .= colored($line, 'bold blue');
|
||||||
|
$output .= colored("=> $text\n", 'blue');
|
||||||
|
$output .= colored('-' x 80 . "\n", 'blue');
|
||||||
|
}
|
||||||
|
|
||||||
print $output unless ($ENV{'PLUGIN_QUIET'});
|
print $output unless ($ENV{'PLUGIN_QUIET'});
|
||||||
return;
|
return;
|
||||||
|
|
@ -381,8 +390,13 @@ sub osh_footer {
|
||||||
$text = $ENV{'PLUGIN_NAME'};
|
$text = $ENV{'PLUGIN_NAME'};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $output = '';
|
my $output;
|
||||||
$output .= colored('-' x (80 - length($text) - 6) . "</$text>---" . "\n", 'bold blue');
|
if (OVH::Bastion::can_use_utf8()) {
|
||||||
|
$output = colored("\N{U+2570}" . "\N{U+2500}" x (79 - length($text) - 6) . "</$text>" . "\N{U+2500}" x 3 . "\n", 'bold blue');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$output = colored('-' x (80 - length($text) - 6) . "</$text>---" . "\n", 'bold blue');
|
||||||
|
}
|
||||||
|
|
||||||
print $output unless ($ENV{'PLUGIN_QUIET'});
|
print $output unless ($ENV{'PLUGIN_QUIET'});
|
||||||
return;
|
return;
|
||||||
|
|
@ -472,15 +486,16 @@ sub osh_debug {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub osh_info {
|
sub osh_info {
|
||||||
return _osh_log(text => shift, color => 'blue', onlyPrefix => 1);
|
return _osh_log(text => shift, type => 'info');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub osh_warn {
|
sub osh_warn {
|
||||||
return _osh_log(text => shift, color => 'magenta');
|
return _osh_log(text => shift, type => 'warn');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub osh_crit {
|
sub osh_crit {
|
||||||
return _osh_log(text => shift, color => 'red bold');
|
my $text = shift;
|
||||||
|
return _osh_log(text => "\n$text", type => 'crit');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _osh_log {
|
sub _osh_log {
|
||||||
|
|
@ -491,14 +506,30 @@ 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 $prefixIfNotEmpty = '';
|
||||||
|
my $color;
|
||||||
|
if ($params{'type'} eq 'crit') {
|
||||||
|
$prefixIfNotEmpty = (OVH::Bastion::can_use_utf8() ? "\N{U+26D4}" : "[!]");
|
||||||
|
$color = 'red bold';
|
||||||
|
}
|
||||||
|
elsif ($params{'type'} eq 'warn') {
|
||||||
|
$prefixIfNotEmpty = (OVH::Bastion::can_use_utf8() ? "\N{U+2757}" : "[#]");
|
||||||
|
$color = 'yellow';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$color = 'blue';
|
||||||
|
}
|
||||||
foreach my $line (split /^/, $params{'text'}) {
|
foreach my $line (split /^/, $params{'text'}) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
|
my $realPrefix = $prefix;
|
||||||
|
$realPrefix .= ' ' . $prefixIfNotEmpty if (length($line) && $prefixIfNotEmpty);
|
||||||
|
|
||||||
if ($params{'onlyPrefix'}) {
|
if ($params{'type'} eq 'info') {
|
||||||
print $output colored('~ ', $params{'color'}) . "$line\n";
|
print $output colored("$realPrefix ", $color) . "$line\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print $output colored("~ $line", $params{'color'}) . "\n";
|
print $output colored("$realPrefix $line", $color) . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1019,4 +1050,10 @@ sub do_pamtester {
|
||||||
return R('OK_MFA_SUCCESS');
|
return R('OK_MFA_SUCCESS');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ sub load_configuration {
|
||||||
options => [
|
options => [
|
||||||
qw{
|
qw{
|
||||||
enableSyslog enableGlobalAccessLog enableAccountAccessLog enableGlobalSqlLog enableAccountSqlLog displayLastLogin
|
enableSyslog enableGlobalAccessLog enableAccountAccessLog enableGlobalSqlLog enableAccountSqlLog displayLastLogin
|
||||||
interactiveModeByDefault
|
interactiveModeByDefault allowUTF8
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue