Files
librenms-librenms/includes/html/pages/device/edit/modules.inc.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

253 lines
7.1 KiB
PHP
Raw Normal View History

2014-06-20 23:01:21 +01:00
<div class="row">
<div class="col-sm-6">
<strong>Poller Modules</strong>
</div>
<div class="col-sm-6">
<strong>Discovery Modules</strong>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<table class="table table-striped">
<tr>
<th>Module</th>
<th>Global</th>
<th>OS</th>
2014-06-20 23:01:21 +01:00
<th>Device</th>
<th></th>
</tr>
<?php
use LibreNMS\Config;
$language = \config('app.locale');
Laravel 9.x Shift (#14504) * Move `resources/lang` folder * Shift registered middleware * Remove `fruitcake/laravel-cors` dependency * Streamline `$commands` property * Upgrade to Flysystem 3.0 * Shift core files * Convert `optional()` to nullsafe operator * Remove unnecessary `$model` property * Convert route options to fluent methods Laravel 8 adopts the tuple syntax for controller actions. Since the old options array is incompatible with this syntax, Shift converted them to use modern, fluent methods. * Convert deprecated `$dates` property to `$casts` * Shift config files * Default config files In an effort to make upgrading the constantly changing config files easier, Shift defaulted them and merged your true customizations - where ENV variables may not be used. * Bump Laravel dependencies * Use `<env>` tags for configuration `<env>` tags have a lower precedence than system environment variables making it easier to overwrite PHPUnit configuration values in additional environments, such a CI. Review this blog post for more details on configuration precedence when testing Laravel: https://jasonmccreary.me/articles/laravel-testing-configuration-precedence/ * Fix error provider * Match new symfony syntax * Match upstream syntax * Fix route syntax * generate composer.lock * Sync back configs * routes * composer * Fix more flare * fix cors * sync lang * Apply fixes from StyleCI (#14517) Co-authored-by: StyleCI Bot <bot@styleci.io> * bump larastan * update packages * wip * Temporarily lower phpstan level * Update phpstan.neon * wip * wip * wip * Apply fixes from StyleCI (#14592) Co-authored-by: StyleCI Bot <bot@styleci.io> * test * Update CiHelper.php * Update test.yml * Update CiHelper.php * Update CiHelper.php * Apply fixes from StyleCI (#14616) Co-authored-by: StyleCI Bot <bot@styleci.io> * test? * fix phpstan problems * dont run snmpsim on github ci * Fix whitespace * More whitespace * More whitespace ??? * I think the space broke it * fix the reset of the whitespace * hard code auth guard --------- Co-authored-by: Shift <shift@laravelshift.com> Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Tony Murray <murraytony@gmail.com>
2023-04-17 13:51:35 +02:00
$settings = (include Config::get('install_dir') . '/lang/' . $language . '/settings.php')['settings'];
2020-05-06 10:09:14 -04:00
$attribs = get_dev_attribs($device['device_id']);
$poller_module_names = $settings['poller_modules'];
$discovery_module_names = $settings['discovery_modules'];
$poller_modules = Config::get('poller_modules');
unset($poller_modules['core']); // core cannot be toggled
ksort($poller_modules);
foreach ($poller_modules as $module => $module_status) {
$module_name = $poller_module_names[$module]['description'] ?: $module;
2014-06-20 23:01:21 +01:00
echo '
<tr>
<td><strong>' . $module_name . '</strong></td>
2014-06-20 23:01:21 +01:00
<td>
';
if ($module_status == 1) {
2014-06-20 23:01:21 +01:00
echo '<span class="text-success">Enabled</span>';
} else {
2014-06-20 23:01:21 +01:00
echo '<span class="text-danger">Disabled</span>';
}
echo '
</td>
<td>';
if (Config::has("os.{$device['os']}.poller_modules.$module")) {
if (Config::get("os.{$device['os']}.poller_modules.$module")) {
echo '<span class="text-success">Enabled</span>';
$module_status = 1;
} else {
echo '<span class="text-danger">Disabled</span>';
$module_status = 0;
}
} else {
echo '<span>Unset</span>';
}
2014-06-20 23:01:21 +01:00
echo '
</td>
<td>
';
2015-07-13 20:10:26 +02:00
if (isset($attribs['poll_' . $module])) {
2014-06-20 23:01:21 +01:00
if ($attribs['poll_' . $module]) {
echo '<span id="poller-module-' . $module . '" class="text-success">Enabled</span>';
$module_checked = 'checked';
} else {
2014-06-20 23:01:21 +01:00
echo '<span id="poller-module-' . $module . '"class="text-danger">Disabled</span>';
$module_checked = '';
2015-07-13 20:10:26 +02:00
}
} else {
echo '<span id="poller-module-' . $module . '">Unset</span>';
if ($module_status == 1) {
2014-06-20 23:01:21 +01:00
$module_checked = 'checked';
} else {
2014-06-20 23:01:21 +01:00
$module_checked = '';
2015-07-13 20:10:26 +02:00
}
2014-06-20 23:01:21 +01:00
}
2014-06-20 23:01:21 +01:00
echo '
</td>
<td>
';
echo '<input type="checkbox" style="visibility:hidden;width:100px;" name="poller-module" data-poller_module="'
. $module . '" data-device_id="' . $device['device_id'] . '" ' . $module_checked . '>';
2014-06-20 23:01:21 +01:00
echo '
</td>
</tr>
';
}
2014-06-20 23:01:21 +01:00
?>
</table>
</div>
<div class="col-sm-6">
<table class="table table-striped">
<tr>
<th>Module</th>
<th>Global</th>
<th>OS</th>
2014-06-20 23:01:21 +01:00
<th>Device</th>
<th></th>
</tr>
<?php
$discovery_modules = Config::get('discovery_modules');
unset($discovery_modules['core']); // core cannot be toggled
ksort($discovery_modules);
foreach ($discovery_modules as $module => $module_status) {
$module_name = $discovery_module_names[$module]['description'] ?: $module;
2014-06-20 23:01:21 +01:00
echo '
<tr>
<td>
<strong>' . $module_name . '</strong>
2014-06-20 23:01:21 +01:00
</td>
<td>
';
if ($module_status == 1) {
2014-06-20 23:01:21 +01:00
echo '<span class="text-success">Enabled</span>';
} else {
2014-06-20 23:01:21 +01:00
echo '<span class="text-danger">Disabled</span>';
}
2015-07-13 20:10:26 +02:00
echo '
</td>
<td>';
if (Config::has("os.{$device['os']}.discovery_modules.$module")) {
if (Config::get("os.{$device['os']}.discovery_modules.$module")) {
echo '<span class="text-success">Enabled</span>';
$module_status = 1;
} else {
echo '<span class="text-danger">Disabled</span>';
$module_status = 0;
}
} else {
echo '<span>Unset</span>';
}
2014-06-20 23:01:21 +01:00
echo '
2015-07-13 20:10:26 +02:00
</td>
<td>';
2014-06-20 23:01:21 +01:00
if (isset($attribs['discover_' . $module])) {
if ($attribs['discover_' . $module]) {
2014-06-20 23:01:21 +01:00
echo '<span id="discovery-module-' . $module . '" class="text-success">Enabled</span>';
$module_checked = 'checked';
} else {
2014-06-20 23:01:21 +01:00
echo '<span id="discovery-module-' . $module . '" class="text-danger">Disabled</span>';
$module_checked = '';
2015-07-13 20:10:26 +02:00
}
} else {
echo '<span id="discovery-module-' . $module . '">Unset</span>';
if ($module_status == 1) {
2014-06-20 23:01:21 +01:00
$module_checked = 'checked';
} else {
2014-06-20 23:01:21 +01:00
$module_checked = '';
2015-07-13 20:10:26 +02:00
}
2014-06-20 23:01:21 +01:00
}
2014-06-20 23:01:21 +01:00
echo '
</td>
<td>';
echo '<input type="checkbox" style="visibility:hidden;width:100px;" name="discovery-module" data-discovery_module="'
. $module . '" data-device_id="' . $device['device_id'] . '" ' . $module_checked . '>';
2014-06-20 23:01:21 +01:00
echo '
</td>
</tr>';
}
2014-06-20 23:01:21 +01:00
echo '
</table>
</div>
';
?>
2014-06-20 23:01:21 +01:00
<script>
$("[name='poller-module']").bootstrapSwitch('offColor','danger');
$('input[name="poller-module"]').on('switchChange.bootstrapSwitch', function(event, state) {
event.preventDefault();
var $this = $(this);
var poller_module = $(this).data("poller_module");
var device_id = $(this).data("device_id");
$.ajax({
type: 'POST',
url: 'ajax_form.php',
2014-06-20 23:01:21 +01:00
data: { type: "poller-module-update", poller_module: poller_module, device_id: device_id, state: state},
dataType: "html",
success: function(data){
//alert('good');
if(state)
{
$('#poller-module-'+poller_module).removeClass('text-danger');
$('#poller-module-'+poller_module).addClass('text-success');
$('#poller-module-'+poller_module).html('Enabled');
}
else
{
$('#poller-module-'+poller_module).removeClass('text-success');
$('#poller-module-'+poller_module).addClass('text-danger');
$('#poller-module-'+poller_module).html('Disabled');
}
},
error:function(){
//alert('bad');
}
});
});
$("[name='discovery-module']").bootstrapSwitch('offColor','danger');
$('input[name="discovery-module"]').on('switchChange.bootstrapSwitch', function(event, state) {
event.preventDefault();
var $this = $(this);
var discovery_module = $(this).data("discovery_module");
var device_id = $(this).data("device_id");
$.ajax({
type: 'POST',
url: 'ajax_form.php',
2014-06-20 23:01:21 +01:00
data: { type: "discovery-module-update", discovery_module: discovery_module, device_id: device_id, state: state},
dataType: "html",
success: function(data){
//alert('good');
if(state)
{
$('#discovery-module-'+discovery_module).removeClass('text-danger');
$('#discovery-module-'+discovery_module).addClass('text-success');
$('#discovery-module-'+discovery_module).html('Enabled');
}
else
{
$('#discovery-module-'+discovery_module).removeClass('text-success');
$('#discovery-module-'+discovery_module).addClass('text-danger');
$('#discovery-module-'+discovery_module).html('Disabled');
}
},
error:function(){
//alert('bad');
}
});
});
</script>