Skip to content

Commit

Permalink
conf: add verify option to backend gui editor
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Feb 12, 2025
1 parent cb14796 commit d84d5a2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
14 changes: 12 additions & 2 deletions plugins/plugins-available/conf/lib/Thruk/Controller/conf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ sub _process_backends_page {
my $type = $c->req->parameters->{'type'};
my $auth = $c->req->parameters->{'auth'};
my $proxy = $c->req->parameters->{'proxy'};
my $verify = $c->req->parameters->{'verify'};
my $remote_name = $c->req->parameters->{'remote_name'};
my @test;
my $con;
Expand All @@ -841,7 +842,13 @@ sub _process_backends_page {
$con = Thruk::Backend::Peer->new({
type => $type,
name => 'test connection',
options => { peer => $peer, auth => $auth, proxy => $proxy, remote_name => $remote_name },
options => {
peer => $peer,
auth => $auth,
proxy => $proxy,
remote_name => $remote_name,
verify => $verify,
},
}, $c->config);
@test = $con->{'class'}->get_processinfo();
};
Expand Down Expand Up @@ -875,6 +882,7 @@ sub _process_backends_page {
$b->{'addr'} = ref $p ne "HASH" ? $p->peer_list() : '';
$b->{'auth'} = $b->{'options'}->{'auth'} || '';
$b->{'proxy'} = $b->{'options'}->{'proxy'} || '';
$b->{'verify'} = $b->{'options'}->{'verify'} // '1';
$b->{'remote_name'} = $b->{'options'}->{'remote_name'} || '';
$b->{'hidden'} = $b->{'hidden'} // 0;
$b->{'section'} = $b->{'section'} // '';
Expand Down Expand Up @@ -2819,6 +2827,7 @@ sub _write_backends_to_thruk_local {
$backend->{'options'}->{'auth'} = $params->{'auth'.$x} if $params->{'auth'.$x};
$backend->{'options'}->{'proxy'} = $params->{'proxy'.$x} if $params->{'proxy'.$x};
$backend->{'options'}->{'remote_name'} = $params->{'remote_name'.$x} if $params->{'remote_name'.$x};
$backend->{'options'}->{'verify'} = defined $params->{'verify'.$x} ? $params->{'verify'.$x} : 0;
$x++;
$backend->{'name'} = 'backend '.$x if(!$backend->{'name'} && $backend->{'options'}->{'peer'});
next unless $backend->{'name'};
Expand All @@ -2832,8 +2841,9 @@ sub _write_backends_to_thruk_local {
}
}

# that's the default anyway
# cleanup keys with are the default already
delete $backend->{'active'} if $backend->{'active'};
delete $backend->{'options'}->{'verify'} if $backend->{'options'}->{'verify'};

# add values from existing backend config
my $savefile = $file;
Expand Down
1 change: 1 addition & 0 deletions plugins/plugins-available/conf/lib/Thruk/Utils/Conf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ sub get_component_as_string {
$string .= " auth = ".$b->{'options'}->{'auth'}."\n" if $b->{'options'}->{'auth'};
$string .= " proxy = ".$b->{'options'}->{'proxy'}."\n" if $b->{'options'}->{'proxy'};
$string .= " remote_name = ".$b->{'options'}->{'remote_name'}."\n" if $b->{'options'}->{'remote_name'};
$string .= " verify = ".$b->{'options'}->{'verify'}."\n" if defined $b->{'options'}->{'verify'};
if($b->{options}->{fallback_peer}) {
for my $p (@{$b->{options}->{fallback_peer}}) {
$string .= " fallback_peer = ".$p."\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
</div>
</td>
</tr>
<tr class="backend_conf_[% x %] backend_verify">
<th class="px-2">Verify SSL</th>
<td>
<div class="radiogroup">
<input type="radio" name="verify[% x %]" id="verify[% x %]_1" value="1"[% IF b.verify == 1 %] checked[% END %]><label for="verify[% x %]_1">Yes</label>
<input type="radio" name="verify[% x %]" id="verify[% x %]_0" value="0"[% IF b.verify == 0 %] checked[% END %]><label for="verify[% x %]_0">No</label>
</div>
</td>
</tr>
<tr class="backend_conf_[% x %] backend_proxy">
<th class="px-2">Proxy</th>
<td>
Expand Down
23 changes: 22 additions & 1 deletion plugins/plugins-available/conf/templates/conf_backends.tt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,24 @@
<tr>
<td colspan=3><hr></td>
</tr>
[% PROCESS _conf_backends_backend.tt b = { name => '', addr => '', auth => '', proxy => '', remote_name => '', id => '', hidden => 0, type => 'livestatus', section => '', file => '', lineno => '', active => 1 } x = 0 %]
[% PROCESS _conf_backends_backend.tt
x = 0
b = {
name => '',
addr => '',
auth => '',
proxy => '',
verify => 1,
remote_name => '',
id => '',
hidden => 0,
type => 'livestatus',
section => '',
file => '',
lineno => '',
active => 1
}
%]
<tr>
<td colspan=3>
<button class="w-32 mx-auto m-2" [% IF readonly %]disabled[% ELSE %]onclick="setBtnSpinner(this);"[% END %]>
Expand Down Expand Up @@ -98,6 +115,7 @@
var typ = jQuery('SELECT[name=type'+nr+']').val();
var auth = jQuery('INPUT[name=auth'+nr+']').val();
var proxy = jQuery('INPUT[name=proxy'+nr+']').val();
var verify = jQuery('INPUT[name=verify'+nr+']:checked').val();
var remote_name = jQuery('INPUT[name=remote_name'+nr+']').val();
jQuery('.testimg_c_'+loopid).removeClass("hidden");
jQuery('.testimg_e_'+loopid).addClass("hidden");
Expand All @@ -114,6 +132,7 @@
type: typ,
auth: auth,
proxy: proxy,
verify: verify,
remote_name: remote_name,
CSRFtoken: CSRFtoken
},
Expand Down Expand Up @@ -164,13 +183,15 @@

jQuery('.backend_conf_'+nr+'.backend_auth').hide();
jQuery('.backend_conf_'+nr+'.backend_proxy').hide();
jQuery('.backend_conf_'+nr+'.backend_verify').hide();
jQuery('.backend_conf_'+nr+'.backend_remote_name').hide();
jQuery('.backend_conf_'+nr+'.backend_connection').hide();

if(value == 'http') {
jQuery('.backend_conf_'+nr+'.backend_connection').show();
jQuery('.backend_conf_'+nr+'.backend_auth').show();
jQuery('.backend_conf_'+nr+'.backend_proxy').show();
jQuery('.backend_conf_'+nr+'.backend_verify').show();
jQuery('.backend_conf_'+nr+'.backend_remote_name').show();
jQuery('INPUT[name=peer'+nr+']').attr('placeholder', 'https://server/[sitename]');
}
Expand Down

0 comments on commit d84d5a2

Please sign in to comment.