Files
librenms-librenms/includes/html/pages/device/edit/apps.inc.php
Zane C. Bowers-Hadley 2618a99be5 Application Soft Delete (#15270)
* add the softdeletes migrations for applications

* add working migration file

* add deleted_at to db schema.yaml for applications

* update includes/html/forms/application-update.inc.php to work with softdeletes

* update includes/html/pages/device/edit/apps.inc.php for softdelete

* update includes/discovery/applications.inc.php to work with softdelete

* minor updates to application-update.inc.php for disabling

* style cleanup

* set discovered when running discovery

* update application tests to include deleted_at

* add deleted_at to a missed test

* a few more tweaks for opensips

* add a missing deleted_at for linux_suricata_extract-v1

* fix fillable for Application model

* massive cleanup of the application update widget thingy

* improve the code for discovery and using Laravel

* add a missing line to app/Models/Application

* add a missing include to app/Models/Application.php

* record includes for Application model

* remove apps from the applications table when a device is deleted

* revert to using upcert and where for discovery to fix CI

* make discovered fillable and set it when running discovery... convert back to firstOrNew

* clean up application discovery a bit and use observer

* style fix

* spelling fix... disablaed -> disabled

* rever removal to just use where

* cleanup app removal on delete

* add restored to ModuleModelObserver

* delete -> forcedelete fix

* apply the suggested changes

* use murrants other suggestion

* style fix
2023-09-06 16:34:39 -05:00

73 lines
2.6 KiB
PHP

<?php
use LibreNMS\Config;
// Load our list of available applications
$applications = [];
foreach (glob(Config::get('install_dir') . '/includes/polling/applications/*.inc.php') as $file) {
$name = basename($file, '.inc.php');
$applications[$name] = $name;
}
// Generate a list of enabled apps with a value of whether they are discovered or not
$enabled_apps = array_reduce(dbFetchRows(
'SELECT `app_type`,`discovered` FROM `applications` WHERE `device_id`=? AND deleted_at IS NULL ORDER BY `app_type`',
[$device['device_id']]
), function ($result, $app) {
$result[$app['app_type']] = $app['discovered'];
return $result;
}, []);
echo '<ul class="list-group row">';
foreach ($applications as $app) {
$modifiers = '';
$app_text = \LibreNMS\Util\StringHelpers::niceCase($app);
// check if the app exists in the enable apps array and check if it was automatically enabled
if (isset($enabled_apps[$app])) {
$modifiers = ' checked';
if ($enabled_apps[$app]
&& (get_dev_attrib($device, 'poll_applications') || Config::getOsSetting($device['os'], 'poller_modules.applications'))
) {
$app_text .= '<span class="text-success"> (Discovered)</span>';
$modifiers .= ' disabled';
}
}
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>';
}
echo '</ul>';
?>
<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>