Resolve KASM-4489 "Feature/ watermark time"
This commit is contained in:
committed by
Matthew McClaskey
parent
9450157af1
commit
25a996cb97
37
unix/KasmVNC/CallbackValidator.pm
Normal file
37
unix/KasmVNC/CallbackValidator.pm
Normal file
@@ -0,0 +1,37 @@
|
||||
package KasmVNC::CallbackValidator;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use v5.10;
|
||||
use Data::Dumper;
|
||||
|
||||
use KasmVNC::Utils;
|
||||
|
||||
sub new {
|
||||
my ($class, $args) = @_;
|
||||
my $self = bless {
|
||||
isValidCallback => $args->{isValidCallback},
|
||||
errorMessage => $args->{errorMessage}
|
||||
}, $class;
|
||||
}
|
||||
|
||||
sub validate {
|
||||
my $self = shift;
|
||||
$self->{configKey} = shift;
|
||||
my @values = @{ listify($self->{configKey}->value()) };
|
||||
|
||||
foreach my $value (@values) {
|
||||
$self->validateValue($value);
|
||||
}
|
||||
}
|
||||
|
||||
sub validateValue {
|
||||
my $self = shift;
|
||||
my $value = shift;
|
||||
|
||||
unless ($self->{isValidCallback}($value)) {
|
||||
$self->{configKey}->addErrorMessage($self->{errorMessage});
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -45,6 +45,8 @@ sub isPresent {
|
||||
sub deriveBoolean {
|
||||
my $value = shift;
|
||||
|
||||
return $value if containsWideSymbols($value);
|
||||
|
||||
switch($value) {
|
||||
case 'true' {
|
||||
return 1;
|
||||
@@ -63,4 +65,12 @@ sub printStackTrace {
|
||||
print { *STDERR } $trace->as_string;
|
||||
}
|
||||
|
||||
sub containsWideSymbols {
|
||||
my $string = shift;
|
||||
|
||||
return 1 unless defined($string);
|
||||
|
||||
$string =~ /[^\x00-\xFF]/;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@@ -92,6 +92,11 @@ data_loss_prevention:
|
||||
# location: 10,10
|
||||
# tint: 255,20,20,128
|
||||
# repeat_spacing: 10
|
||||
text:
|
||||
template: "${USER} %H:%M"
|
||||
font: auto
|
||||
font_size: 48
|
||||
timezone_name: Australia/Adelaide
|
||||
logging:
|
||||
# "verbose" SETTING LOGS YOUR PRIVATE INFORMATION. Keypresses and clipboard content
|
||||
level: off
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
use v5.10;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
sub DEVENV() { $ENV{KASMVNC_DEVELOPMENT} };
|
||||
use if DEVENV, Devel::StackTrace;
|
||||
@@ -38,11 +39,14 @@ use List::Util qw(first);
|
||||
use List::MoreUtils qw(any uniq);
|
||||
use Data::Dumper;
|
||||
use Try::Tiny;
|
||||
use DateTime;
|
||||
use DateTime::TimeZone;
|
||||
|
||||
use KasmVNC::CliOption;
|
||||
use KasmVNC::ConfigKey;
|
||||
use KasmVNC::PatternValidator;
|
||||
use KasmVNC::EnumValidator;
|
||||
use KasmVNC::CallbackValidator;
|
||||
use KasmVNC::Config;
|
||||
use KasmVNC::Users;
|
||||
use KasmVNC::TextOption;
|
||||
@@ -56,6 +60,7 @@ use constant {
|
||||
OPTIONAL_ARG_VALUE => 2
|
||||
};
|
||||
|
||||
UseUtfStdio();
|
||||
InitLogger();
|
||||
|
||||
CheckWeCanRunInThisEnvironment();
|
||||
@@ -1765,6 +1770,79 @@ sub DefineConfigToCLIConversion {
|
||||
})
|
||||
]
|
||||
}),
|
||||
KasmVNC::CliOption->new({
|
||||
name => 'DLP_WatermarkText',
|
||||
configKeys => [
|
||||
KasmVNC::ConfigKey->new({
|
||||
name => "data_loss_prevention.watermark.text.template",
|
||||
validator => KasmVNC::CallbackValidator->new({
|
||||
isValidCallback => sub {
|
||||
my $value = shift;
|
||||
|
||||
isBlank(ConfigValue("data_loss_prevention.watermark.image"));
|
||||
},
|
||||
errorMessage => "Watermark image and text can't be used at the same time"
|
||||
}),
|
||||
})
|
||||
]
|
||||
}),
|
||||
KasmVNC::CliOption->new({
|
||||
name => 'DLP_WatermarkFont',
|
||||
configKeys => [
|
||||
KasmVNC::ConfigKey->new({
|
||||
name => "data_loss_prevention.watermark.text.font",
|
||||
type => KasmVNC::ConfigKey::ANY
|
||||
})
|
||||
],
|
||||
isActiveSub => sub {
|
||||
$self = shift;
|
||||
|
||||
my $value = $self->configValue();
|
||||
isPresent($value) && $value ne "auto";
|
||||
}
|
||||
}),
|
||||
KasmVNC::CliOption->new({
|
||||
name => 'DLP_WatermarkFontSize',
|
||||
configKeys => [
|
||||
KasmVNC::ConfigKey->new({
|
||||
name => "data_loss_prevention.watermark.text.font_size",
|
||||
validator => KasmVNC::CallbackValidator->new({
|
||||
isValidCallback => sub {
|
||||
my $value = shift;
|
||||
|
||||
return 0 unless $value =~ /^\d+$/;
|
||||
|
||||
$value >= 8 && $value <= 256;
|
||||
},
|
||||
errorMessage => "must be in range 8..256"
|
||||
}),
|
||||
})
|
||||
]
|
||||
}),
|
||||
KasmVNC::CliOption->new({
|
||||
name => 'DLP_WatermarkTimeOffsetMinutes',
|
||||
configKeys => [
|
||||
KasmVNC::ConfigKey->new({
|
||||
name => "data_loss_prevention.watermark.text.timezone_name",
|
||||
validator => KasmVNC::CallbackValidator->new({
|
||||
isValidCallback => sub {
|
||||
my $timezone_name = shift;
|
||||
|
||||
DateTime::TimeZone->is_valid_name($timezone_name);
|
||||
},
|
||||
errorMessage => "must be a valid timezone name like Australia/Adelaide"
|
||||
})
|
||||
})
|
||||
],
|
||||
deriveValueSub => sub {
|
||||
my $self = shift;
|
||||
my $timezone_name = $self->configValue();
|
||||
my $dt = DateTime->now(time_zone => $timezone_name);
|
||||
my $offset_in_seconds = $dt->offset();
|
||||
|
||||
$offset_in_seconds/60;
|
||||
}
|
||||
}),
|
||||
KasmVNC::CliOption->new({
|
||||
name => 'DLP_Log',
|
||||
configKeys => [
|
||||
@@ -2835,3 +2913,7 @@ sub InitLogger {
|
||||
my $debugEnabled = any { $_ eq "-debug" } @ARGV;
|
||||
$logger = KasmVNC::Logger->new({ level => $debugEnabled ? "debug" : "warn" });
|
||||
}
|
||||
|
||||
sub UseUtfStdio {
|
||||
use open qw( :std :encoding(UTF-8) );
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ Xvnc_CPPFLAGS = $(XVNC_CPPFLAGS) -DKASMVNC -DNO_MODULE_EXTS \
|
||||
-I$(top_srcdir)/dri3 @LIBDRM_CFLAGS@
|
||||
|
||||
Xvnc_LDADD = $(XVNC_LIBS) libvnccommon.la $(COMMON_LIBS) \
|
||||
$(XSERVER_LIBS) $(XSERVER_SYS_LIBS) $(XVNC_SYS_LIBS) -lX11 -lwebp -lssl -lcrypto -lcrypt
|
||||
$(XSERVER_LIBS) $(XSERVER_SYS_LIBS) $(XVNC_SYS_LIBS) -lX11 -lwebp -lssl -lcrypto -lcrypt \
|
||||
-lfreetype
|
||||
|
||||
Xvnc_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG) -fopenmp
|
||||
|
||||
|
||||
@@ -243,6 +243,8 @@ Default \fB-1\fP.
|
||||
.B \-WebpVideoQuality \fInum\fP
|
||||
The WEBP quality to use when in video mode.
|
||||
Default \fB-1\fP.
|
||||
.
|
||||
.TP
|
||||
.B \-MaxVideoResolution \fI1920x1080\fP
|
||||
When in video mode, downscale the screen to max this size. Keeps aspect ratio.
|
||||
Default \fB1920x1080\fP.
|
||||
@@ -372,6 +374,28 @@ The color components can be used to colorize the greyscale watermark, and the al
|
||||
can be used to make it fainter.
|
||||
.
|
||||
.TP
|
||||
.B \-DLP_WatermarkText \fI"foo %H:%M"\fP
|
||||
Instead of an image, render this text as the watermark. Takes time formatting options
|
||||
for \fBstrftime\fP.
|
||||
.
|
||||
.TP
|
||||
.B \-DLP_WatermarkFont \fI/path/to/font.ttf\fP
|
||||
Use a different font for -DLP_WatermarkText than the bundled one. TTF and OTF fonts
|
||||
are accepted.
|
||||
.
|
||||
.TP
|
||||
.B \-DLP_WatermarkFontSize \fI48\fP
|
||||
Font size for -DLP_WatermarkText. Default \fI48\fP.
|
||||
.
|
||||
.TP
|
||||
.B \-DLP_WatermarkTimeOffset \fI0\fP
|
||||
Time offset from UTC, hours. Default \fI0\fP.
|
||||
.
|
||||
.TP
|
||||
.B \-DLP_WatermarkTimeOffsetMinutes \fI0\fP
|
||||
Time offset from UTC, minutes. Default \fI0\fP.
|
||||
.
|
||||
.TP
|
||||
.B \-selfBench
|
||||
Run a set of self-benchmarks and exit.
|
||||
.
|
||||
|
||||
Reference in New Issue
Block a user