Skip to content

Commit

Permalink
Fix stats return correctly encoded data webmin/webmin#2237
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Jul 28, 2024
1 parent c2c064f commit 53bca06
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions stats.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
use lib ("$ENV{'PERLLIB'}/vendor_perl");
use Net::WebSocket::Server;
use utf8;
my $json;
eval "use JSON::XS";
if ($@) {
if (!$@) {
$json = JSON::XS->new->latin1;
} else {
eval "use JSON::PP";
$json = JSON::PP->new->latin1;
}

our ($current_theme);
Expand Down Expand Up @@ -62,7 +66,8 @@
# clients unless paused for some client
my $stats_now = get_stats_now();
my $stats_now_graphs = $stats_now->{'graphs'};
my $stats_now_json = encode_json($stats_now);
my $stats_now_json = $json->encode($stats_now);
utf8::decode($stats_now_json);
foreach my $conn_id (keys %{$serv->{'conns'}}) {
my $conn = $serv->{'conns'}->{$conn_id}->{'conn'};
if ($conn->{'verified'} && !$conn->{'paused'}) {
Expand Down Expand Up @@ -93,7 +98,8 @@
merge_stats($stats_now->{'graphs'},
$stats_now_graphs);
}
$stats_now_json = encode_json($stats_now);
$stats_now_json = $json->encode($stats_now);
utf8::decode($stats_now_json);
}
$conn->send_utf8($stats_now_json);
}
Expand Down Expand Up @@ -136,7 +142,7 @@
# Decode JSON message
my ($conn, $msg) = @_;
utf8::encode($msg) if (utf8::is_utf8($msg));
my $data = decode_json($msg);
my $data = $json->decode($msg);
# Connection permission test unless already verified
if (!$conn->{'verified'}) {
my $user = verify_session_id($data->{'session'});
Expand Down

0 comments on commit 53bca06

Please sign in to comment.