Skip to content

Commit 890bef6

Browse files
committed
migrate sound files to webm && add test page for sound file in user preferences
1 parent 8fd035a commit 890bef6

17 files changed

+111
-31
lines changed

Changes

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
This file documents the revision history for the Monitoring Webinterface Thruk.
22

33
next:
4+
- migrate sound files to webm
5+
- add test page for sound file in user preferences
46
- Rest:
57
- add peer_section attribute
68

MANIFEST

+4-4
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,10 @@ root/thruk/cache/thruk-panorama-3.20.2.js
691691
root/thruk/images/trendshost.png
692692
root/thruk/images/trendssvc.png
693693
root/thruk/javascript/thruk-3.20.2.js
694-
root/thruk/media/critical.wav
695-
root/thruk/media/ok.wav
696-
root/thruk/media/unknown.wav
697-
root/thruk/media/warning.wav
694+
root/thruk/media/critical.webm
695+
root/thruk/media/ok.webm
696+
root/thruk/media/unknown.webm
697+
root/thruk/media/warning.webm
698698
root/thruk/themes
699699
root/thruk/usercontent/backgrounds/europa.png
700700
root/thruk/usercontent/backgrounds/europa.svg

cgi.cfg

+6-6
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ lock_author_names=1
220220
# Note: All audio files use relative paths from /thruk/cgi-bin/status.cgi
221221
# and must be accessible by web
222222

223-
host_unreachable_sound=../media/critical.wav
224-
host_down_sound=../media/critical.wav
225-
service_critical_sound=../media/critical.wav
226-
service_warning_sound=../media/warning.wav
227-
service_unknown_sound=../media/unknown.wav
228-
#normal_sound=../media/ok.wav
223+
host_unreachable_sound=../media/critical.webm
224+
host_down_sound=../media/critical.webm
225+
service_critical_sound=../media/critical.webm
226+
service_warning_sound=../media/warning.webm
227+
service_unknown_sound=../media/unknown.webm
228+
#normal_sound=../media/ok.webm

lib/Thruk.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ sub startup {
8686
path => sub {
8787
my $p = Thruk::Context::translate_request_path($_, config());
8888
return unless $p =~ m%^/thruk/plugins/%mx;
89-
return unless $p =~ /\.(css|png|js|gif|jpg|ico|html|wav|mp3|ogg|ttf|svg|woff|woff2|eot|map)$/mx;
89+
return unless $p =~ /\.(css|png|js|gif|jpg|ico|html|wav|webm|mp3|ogg|ttf|svg|woff|woff2|eot|map)$/mx;
9090
$p =~ s%^/thruk/plugins/([^/]+)/%$1/root/%mx;
9191
$_ =~ s%^.*$%$p%mx; # replace $_ with actual path
9292
return 1;
@@ -98,7 +98,7 @@ sub startup {
9898
path => sub {
9999
my $p = Thruk::Context::translate_request_path($_, config());
100100
return if $p =~ m%^/thruk/cgi\-bin/(remote|proxy)\.cgi%mx;
101-
return unless $p =~ /\.(css|png|js|gif|jpg|ico|html|wav|mp3|ogg|ttf|svg|woff|woff2|eot|map)$/mx;
101+
return unless $p =~ /\.(css|png|js|gif|jpg|ico|html|wav|webm|mp3|ogg|ttf|svg|woff|woff2|eot|map)$/mx;
102102
$_ =~ s%^.*$%$p%mx; # replace $_ with actual path
103103
return 1;
104104
},

lib/Thruk/Controller/Root.pm

+8-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,14 @@ sub parts_cgi {
291291
}
292292

293293
if($part eq '_summary_prompt') {
294-
$c->stash->{'template'} = '_parts_summary_prompt.tt';
294+
$c->stash->{'template'} = '_parts_summary_prompt.tt';
295+
return;
296+
}
297+
298+
if($part eq '_sounds') {
299+
my $audio = $c->req->parameters->{'audio'} // 'normal';
300+
$c->stash->{'audiofile'} = $c->config->{$audio.'_sound'} // $c->config->{'normal_sound'} // 'nosound';
301+
$c->stash->{'template'} = '_sounds.tt';
295302
return;
296303
}
297304

root/thruk/javascript/thruk-3.20.2.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,14 @@ function setBtnNoSpinner(btn) {
690690
setBtnClearTimer(btn);
691691
}
692692

693+
function setBtnReset(btn) {
694+
setBtnClearTimer(btn);
695+
jQuery(btn).find('div.spinner').remove();
696+
jQuery(btn).find('I.fa-exclamation').remove();
697+
jQuery(btn).find('I.fa-check').remove();
698+
jQuery(btn).find("I").css("display", "");
699+
}
700+
693701
function setBtnError(btn, title) {
694702
setBtnClearTimer(btn);
695703
jQuery(btn).find('div.spinner').remove();
@@ -5430,8 +5438,23 @@ function setTableSearchFilter(filter, inputId) {
54305438
}
54315439
jQuery(inputId).val(filter);
54325440
jQuery(inputId).focus();
5433-
}
5441+
}
54345442

5443+
function play_test_audio(btn, audio) {
5444+
resetRefresh();
5445+
setBtnSpinner(btn);
5446+
jQuery('#testsound').load(url_prefix+'cgi-bin/parts.cgi?part=_sounds&audio='+audio, {},
5447+
function(text, status, jqXHR) {
5448+
resetRefresh();
5449+
if(status == "error") {
5450+
var msg = getXHRerrorMsg(text, status, jqXHR, false);
5451+
setBtnError(btn, msg);
5452+
} else {
5453+
setBtnReset(btn);
5454+
}
5455+
}
5456+
)
5457+
}
54355458

54365459
/*******************************************************************************
54375460
* ,ad8888ba, ,ad8888ba, 88b d88 88888888ba 88 88888888888 888888888888 88 ,ad8888ba, 888b 88

root/thruk/media/critical.wav

-33.3 KB
Binary file not shown.

root/thruk/media/critical.webm

25.5 KB
Binary file not shown.

root/thruk/media/ok.wav

-17.6 KB
Binary file not shown.

root/thruk/media/ok.webm

14.1 KB
Binary file not shown.

root/thruk/media/unknown.wav

-9.99 KB
Binary file not shown.

root/thruk/media/unknown.webm

1.91 KB
Binary file not shown.

root/thruk/media/warning.wav

-23.9 KB
Binary file not shown.

root/thruk/media/warning.webm

2.85 KB
Binary file not shown.

t/083-xss.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ my $whitelist_vars = Thruk::Base::array2hash([qw/
2727
has_bp bp.fullid r.fullid hex rd.file b.basefile
2828
host_health_pic service_health_pic health_perc service_perc
2929
a.t1 a.t2 nr id first_remaining tblID start_with backlink type typename
30-
s_status f d i j x key size head_height image_width state hoststate status image_height
30+
s_status f d i j x s key size head_height image_width state hoststate status image_height
3131
div_id graph_url index loop_index filterprefix center extra_classes
3232
c.config.jquery_ui c.config.start_page c.config.home_link
3333
host_health_cls service_health_cls host_perc opt_class ok_pct w_pct u_pct c_pct p_pct

templates/_header_prefs.tt

+35-11
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,41 @@
3535
</td>
3636
</tr>
3737
[% IF show_sounds %]
38-
<tr>
39-
<th class="align-middle">[% IF play_sounds %]<i class="uil uil-volume"></i>[% ELSE %]<i class="uil uil-volume-mute"></i>[% END %]</th>
40-
<th class="align-middle">Sounds</th>
41-
<td>
42-
[% IF has_cgi_sounds %]
43-
<input type="button" name="submit" value="[% IF play_sounds %]sound is on[% ELSE %]sound is off[% END %]" onClick="prefSubmitSound(full_uri, '[% IF play_sounds %]off[% ELSE %]on[% END %]')" class="w-40">
44-
[% ELSE %]
45-
<input type="button" name="submit" value="no sound files configured in cgi.cfg" disabled class="w-40">
46-
[% END %]
47-
</td>
48-
</tr>
38+
<tr>
39+
<th class="align-middle">[% IF play_sounds %]<i class="uil uil-volume"></i>[% ELSE %]<i class="uil uil-volume-mute"></i>[% END %]</th>
40+
<th class="align-middle">Sounds</th>
41+
<td>
42+
<div class="flexrow">
43+
[% IF has_cgi_sounds %]
44+
<input type="button" name="submit" value="[% IF play_sounds %]sound is on[% ELSE %]sound is off[% END %]" onClick="prefSubmitSound(full_uri, '[% IF play_sounds %]off[% ELSE %]on[% END %]')" class="w-40">
45+
[% IF play_sounds %]
46+
<button class="ml-5" onClick="toggleElement('testsound_panel')">play test sound<i class="uil uil-angle-down ml-1 mr-0"></i></button>
47+
[% END %]
48+
[% ELSE %]
49+
<input type="button" name="submit" value="no sound files configured in cgi.cfg" disabled class="w-40">
50+
[% END %]
51+
</div>
52+
</td>
53+
</tr>
54+
55+
[% IF has_cgi_sounds && play_sounds %]
56+
<tr>
57+
<th class="align-middle"></th>
58+
<th class="align-middle"></th>
59+
<td>
60+
<div id="audiomsg"></div>
61+
<table class="hidden w-fit mb-2" id="testsound_panel">
62+
[% FOREACH s = ['normal', 'host_down', 'host_unreachable', 'service_warning', 'service_critical', 'service_unknown' ] %]
63+
<tr>
64+
<td><button class="w-fit [% IF !c.config.defined(s _ "_sound") %]disabled[% END %]" [% IF !c.config.defined(s _ "_sound") %]disabled[% END %] onClick="play_test_audio(this, '[% s %]')"><i class="uil uil-play m-0"></i></button></td>
65+
<td>[% s.replace("_", " ") %][% IF !c.config.defined(s _ "_sound") %] <span class="textHINT">(cgi.cfg: no audio file configured)</span>[% END %]</td>
66+
</tr>
67+
[% END %]
68+
</table>
69+
<div id="testsound"></div>
70+
</td>
71+
</tr>
72+
[% END %]
4973
[% END %]
5074
<tr>
5175
<th class="align-middle"><i class="uil uil-star"></i></th>

templates/_sounds.tt

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
[% IF audiofile %]
2-
<object type="audio/x-wav" height="0" width="0" data="[% audiofile | html %]">
3-
<param name="filename" value="[% audiofile | html %]">
4-
<param name="autostart" value="true">
5-
<param name="playcount" value="1">
6-
</object>
2+
<audio id="audiofileid">
3+
<source src="[% audiofile | html %]" [% IF audiofile.match("\.wav$") %]type="audio/wav"[% ELSIF audiofile.match("\.mp3$") %]type="audio/mpeg"[% ELSIF audiofile.match("\.ogg$") %]type="audio/ogg"[% END %]>
4+
</audio>
5+
<script>
6+
var el = document.getElementById("audiofileid");
7+
if(el) {
8+
try {
9+
el.play();
10+
} catch (error) {
11+
console.log(error);
12+
}
13+
}
14+
var error = "";
15+
try {
16+
if(navigator.getAutoplayPolicy("mediaelement") !== "allowed") {
17+
error = "cannot play audio file, auto play is disabled by your browser";
18+
}
19+
} catch (error) {
20+
console.log(error);
21+
}
22+
console.log(error);
23+
if(error != "") {
24+
if(jQuery("#audiomsg").length > 0) {
25+
jQuery("#audiomsg").text(error);
26+
} else {
27+
thruk_message(1, error);
28+
}
29+
}
30+
</script>
731
[% END %]

0 commit comments

Comments
 (0)