librenms-librenms/html/includes/modal/new_service.inc.php
Tony Murray 32a7c50189 Use Laravel authentication (#8702)
* Use Laravel for authentication
Support legacy auth methods
Always create DB entry for users (segregate by auth method)

Port api auth to Laravel

restrict poller errors to devices the user has access to

Run checks on every page load.  But set a 5 minute (configurable) timer.
Only run some checks if the user is an admin

Move toastr down a few pixels so it isn't as annoying.

Fix menu not loaded on laravel pages when twofactor is enabled for the system, but disabled for the user.
Add two missing menu entries in the laravel menu

Rewrite 2FA code
Simplify some and verify code before applying

Get http-auth working
Handle legacy $_SESSION differently.  Allows Auth::once(), etc to work.

* Fix tests and mysqli extension check

* remove duplicate Toastr messages

* Fix new items

* Rename 266.sql to 267.sql
2018-09-11 07:51:35 -05:00

149 lines
5.7 KiB
PHP

<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
use LibreNMS\Authentication\LegacyAuth;
if (LegacyAuth::user()->hasGlobalAdmin()) {
// Build the types list.
$dir = $config['nagios_plugins'];
if (file_exists($dir) && is_dir($dir)) {
$files = scandir($dir);
$dir .= DIRECTORY_SEPARATOR;
foreach ($files as $file) {
if (is_executable($dir.$file) && is_file($dir.$file) && strstr($file, 'check_')) {
list(,$check_name) = explode('_', $file, 2);
$stype .= "<option value='$check_name'>$check_name</option>";
}
}
}
?>
<div class="modal fade bs-example-modal-sm" id="create-service" tabindex="-1" role="dialog" aria-labelledby="Create" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h5 class="modal-title" id="Create">Services</h5>
</div>
<div class="modal-body">
<form method="post" role="form" id="service" class="form-horizontal service-form">
<input type="hidden" name="service_id" id="service_id" value="">
<input type="hidden" name="device_id" id="device_id" value="<?php echo $device['device_id']?>">
<input type="hidden" name="type" id="type" value="create-service">
<div class="form-service">
<div class="col-sm-12">
<span id="ajax_response">&nbsp;</span>
</div>
</div>
<div class="form-service">
<label for='stype' class='col-sm-3 control-label'>Type: </label>
<div class="col-sm-9">
<select id='stype' name='stype' placeholder='type' class='form-control has-feedback'>
<?php echo $stype?>
</select>
</div>
</div>
<div class='form-service'>
<label for='desc' class='col-sm-3 control-label'>Description: </label>
<div class='col-sm-9'>
<textarea id='desc' name='desc' class='form-control'></textarea>
</div>
</div>
<div class="form-service">
<label for='ip' class='col-sm-3 control-label'>IP Address: </label>
<div class="col-sm-9">
<input type='text' id='ip' name='ip' class='form-control has-feedback' placeholder='<?php echo $device['hostname']?>'/>
</div>
</div>
<div class="form-service">
<label for='param' class='col-sm-3 control-label'>Parameters: </label>
<div class="col-sm-9">
<input type='text' id='param' name='param' class='form-control has-feedback' placeholder=''/>
</div>
</div>
<div class="form-service">
<div class="col-sm-offset-3 col-sm-9">
<button class="btn btn-success btn-sm" type="submit" name="service-submit" id="service-submit" value="save">Save Service</button>
</div>
</div>
<div class="clearfix"></div>
</form>
</div>
</div>
</div>
</div>
<script>
// on-hide
$('#create-service').on('hide.bs.modal', function (event) {
$('#stype').val('');
$("#stype").prop("disabled", false);
$('#ip').val('');
$('#desc').val('');
$('#param').val('');
});
// on-load
$('#create-service').on('show.bs.modal', function (e) {
var button = $(e.relatedTarget);
var service_id = button.data('service_id');
var modal = $(this)
$('#service_id').val(service_id);
$.ajax({
type: "POST",
url: "ajax_form.php",
data: { type: "parse-service", service_id: service_id },
dataType: "json",
success: function(output) {
$('#stype').val(output['stype']);
$("#stype").prop("disabled", true);
$('#ip').val(output['ip']);
$('#desc').val(output['desc']);
$('#param').val(output['param']);
}
});
});
// on-submit
$('#service-submit').click('', function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "ajax_form.php",
data: $('form.service-form').serialize(),
success: function(result){
if (result.status == 0) {
// Yay.
$("#create-service").modal('hide');
$('#message').html('<div class="alert alert-info">' + result.message + '</div>');
setTimeout(function() {
location.reload(1);
}, 1500);
}
else {
// Nay.
$("#ajax_response").html('<div class="alert alert-danger">'+result.message+'</div>');
}
},
error: function(){
$("#ajax_response").html('<div class="alert alert-info">An error occurred creating this service.</div>');
}
});
});
</script>
<?php
}