2010-06-20 17:21:35 +00:00
|
|
|
<?php
|
|
|
|
|
2017-11-02 15:38:17 -05:00
|
|
|
use LibreNMS\Config;
|
|
|
|
|
2011-03-25 11:45:05 +00:00
|
|
|
// Load our list of available applications
|
2017-03-22 09:59:39 -05:00
|
|
|
$applications = [];
|
2017-11-02 15:38:17 -05:00
|
|
|
foreach (glob(Config::get('install_dir') . '/includes/polling/applications/*.inc.php') as $file) {
|
2017-03-22 09:59:39 -05:00
|
|
|
$name = basename($file, '.inc.php');
|
|
|
|
$applications[$name] = $name;
|
2011-03-16 12:12:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 09:59:39 -05:00
|
|
|
// Generate a list of enabled apps with a value of whether they are discovered or not
|
|
|
|
$enabled_apps = array_reduce(dbFetchRows(
|
2023-09-06 16:34:39 -05:00
|
|
|
'SELECT `app_type`,`discovered` FROM `applications` WHERE `device_id`=? AND deleted_at IS NULL ORDER BY `app_type`',
|
2017-03-22 09:59:39 -05:00
|
|
|
[$device['device_id']]
|
|
|
|
), function ($result, $app) {
|
|
|
|
$result[$app['app_type']] = $app['discovered'];
|
2011-03-26 19:12:24 +00:00
|
|
|
|
2017-03-22 09:59:39 -05:00
|
|
|
return $result;
|
2020-09-21 15:40:17 +02:00
|
|
|
}, []);
|
2011-03-26 19:12:24 +00:00
|
|
|
|
2017-03-22 09:59:39 -05:00
|
|
|
echo '<ul class="list-group row">';
|
|
|
|
foreach ($applications as $app) {
|
|
|
|
$modifiers = '';
|
2021-03-28 17:25:30 -05:00
|
|
|
$app_text = \LibreNMS\Util\StringHelpers::niceCase($app);
|
2017-03-22 09:59:39 -05:00
|
|
|
// check if the app exists in the enable apps array and check if it was automatically enabled
|
|
|
|
if (isset($enabled_apps[$app])) {
|
|
|
|
$modifiers = ' checked';
|
2017-11-02 15:38:17 -05:00
|
|
|
if ($enabled_apps[$app]
|
2019-11-14 21:56:06 +00:00
|
|
|
&& (get_dev_attrib($device, 'poll_applications') || Config::getOsSetting($device['os'], 'poller_modules.applications'))
|
2017-11-02 15:38:17 -05:00
|
|
|
) {
|
2017-03-22 09:59:39 -05:00
|
|
|
$app_text .= '<span class="text-success"> (Discovered)</span>';
|
|
|
|
$modifiers .= ' disabled';
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
2010-06-20 17:21:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 09:59:39 -05:00
|
|
|
echo '<li class="list-group-item col-xs-12 col-md-6 col-lg-4">';
|
|
|
|
echo "<input style='visibility:hidden;width:100px;' type='checkbox' name='application' data-size='small'";
|
|
|
|
echo " data-application='$app' data-device_id='{$device['device_id']}'$modifiers>";
|
|
|
|
echo '<span style="font-size:medium;padding-left:5px;"> ' . $app_text . '</span>';
|
|
|
|
echo '</li>';
|
2011-03-16 12:12:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 09:59:39 -05:00
|
|
|
echo '</ul>';
|
|
|
|
?>
|
2010-06-20 17:21:35 +00:00
|
|
|
|
2017-03-22 09:59:39 -05:00
|
|
|
<script>
|
|
|
|
$('[name="application"]').bootstrapSwitch('offColor', 'danger');
|
|
|
|
$('input[name="application"]').on('switchChange.bootstrapSwitch', function (event, state) {
|
|
|
|
event.preventDefault();
|
|
|
|
var $this = $(this);
|
|
|
|
var application = $this.data("application");
|
|
|
|
var device_id = $this.data("device_id");
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: 'ajax_form.php',
|
|
|
|
data: {type: "application-update", application: application, device_id: device_id, state: state},
|
|
|
|
success: function(result){
|
|
|
|
if (result.status == 0) {
|
|
|
|
toastr.success(result.message);
|
|
|
|
} else {
|
|
|
|
toastr.error(result.message);
|
|
|
|
$this.bootstrapSwitch('state', !state, true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
toastr.error('Problem with backend');
|
|
|
|
$this.bootstrapSwitch('state', !state, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|