mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Updated services edit / delete pages
This commit is contained in:
@ -14,6 +14,10 @@
|
||||
color: #357ebd;
|
||||
}
|
||||
|
||||
.fa-col-danger {
|
||||
color: #e30613;
|
||||
}
|
||||
|
||||
.twitter-typeahead .tt-hint {
|
||||
border-color: #000 !important;
|
||||
}
|
||||
|
@ -14,6 +14,10 @@
|
||||
color: #357ebd;
|
||||
}
|
||||
|
||||
.fa-col-danger {
|
||||
color: #e30613;
|
||||
}
|
||||
|
||||
.pace {
|
||||
-webkit-pointer-events: none;
|
||||
pointer-events: none;
|
||||
|
@ -14,6 +14,10 @@
|
||||
color: #357ebd;
|
||||
}
|
||||
|
||||
.fa-col-danger {
|
||||
color: #e30613;
|
||||
}
|
||||
|
||||
.twitter-typeahead .tt-hint {
|
||||
border-color: #000 !important;
|
||||
}
|
||||
|
@ -185,7 +185,8 @@ if ($_SESSION['userlevel'] >= '10')
|
||||
echo('
|
||||
<li role="presentation" class="divider"></li>
|
||||
<li><a href="addsrv/"><i class="fa fa-cog fa-col-success fa-fw fa-lg"></i> Add Service</a></li>
|
||||
<li><a href="delsrv/"><i class="fa fa-cog fa-col-info fa-fw fa-lg"></i> Delete Service</a></li>');
|
||||
<li><a href="editsrv/"><i class="fa fa-cog fa-col-primary fa-fw fa-lg"></i> Edit Service</a></li>
|
||||
<li><a href="delsrv/"><i class="fa fa-cog fa-col-danger fa-fw fa-lg"></i> Delete Service</a></li>');
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
54
html/includes/print-service-add.inc.php
Normal file
54
html/includes/print-service-add.inc.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
echo("
|
||||
<h3><span class='label label-success threeqtr-width'>Add Service</span></h3>
|
||||
<form id='addsrv' name='addsrv' method='post' action='' class='form-horizontal' role='form'>
|
||||
<div class='well well-lg'>
|
||||
<div class='form-group'>
|
||||
<input type='hidden' name='addsrv' value='yes'>
|
||||
<label for='device' class='col-sm-2 control-label'>Device</label>
|
||||
<div class='col-sm-5'>
|
||||
<select name='device' class='form-control input-sm'>
|
||||
$devicesform
|
||||
</select>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='type' class='col-sm-2 control-label'>Type</label>
|
||||
<div class='col-sm-5'>
|
||||
<select name='type' id='type' class='form-control input-sm'>
|
||||
$servicesform
|
||||
</select>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='descr' class='col-sm-2 control-label'>Description</label>
|
||||
<div class='col-sm-5'>
|
||||
<textarea name='descr' id='descr' class='form-control input-sm' rows='5'></textarea>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='ip' class='col-sm-2 control-label'>IP Address</label>
|
||||
<div class='col-sm-5'>
|
||||
<input name='ip' id='ip' class='form-control input-sm' placeholder='IP Address'>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='params' class='col-sm-2 control-label'>Parameters</label>
|
||||
<div class='col-sm-5'>
|
||||
<input name='params' id='params' class='form-control input-sm'>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<button type='submit' name='Submit' class='btn btn-success input-sm'>Add Service</button>
|
||||
</div>
|
||||
</form>");
|
35
html/includes/print-service-edit.inc.php
Normal file
35
html/includes/print-service-edit.inc.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
if (isset($_POST['service']) && is_numeric($_POST['service'])) {
|
||||
|
||||
$service = dbFetchRow("SELECT * FROM `services` WHERE `service_id`=?", array($_POST['service']));
|
||||
|
||||
echo("
|
||||
<h3><span class='label label-primary threeqtr-width'>Edit Service</span></h3>
|
||||
<form id='confirm-editsrv' name='confirm-editsrv' method='post' action='' class='form-horizontal' role='form'>
|
||||
<input type='hidden' name='device' value='" . $service['device_id'] . "'>
|
||||
<input type='hidden' name='service' value='" . $service['service_id'] . "'>
|
||||
<div class='well well-lg'>
|
||||
<div class='form-group'>
|
||||
<label for='descr' class='col-sm-2 control-label'>Description</label>
|
||||
<div class='col-sm-5'>
|
||||
<textarea name='descr' id='descr' class='form-control input-sm' rows='5'>" . $service['service_desc'] . "</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='ip' class='col-sm-2 control-label'>IP Address</label>
|
||||
<div class='col-sm-5'>
|
||||
<input name='ip' id='ip' value='" . $service['service_ip'] . "' class='form-control input-sm' placeholder='IP Address'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='params' class='col-sm-2 control-label'>Parameters</label>
|
||||
<div class='col-sm-5'>
|
||||
<input name='params' id='params' value='" . $service['service_param'] . "' class='form-control input-sm'>
|
||||
</div>
|
||||
</div>
|
||||
<button type='submit' id='confirm-editsrv' name='confirm-editsrv' value='yes' class='btn btn-primary input-sm'>Edit Service</button>
|
||||
</div>
|
||||
</form>");
|
||||
|
||||
}
|
10
html/includes/service-add.inc.php
Normal file
10
html/includes/service-add.inc.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$updated = '1';
|
||||
|
||||
$service_id = add_service(mres($_POST['device']), mres($_POST['type']), mres($_POST['descr']), mres($_POST['ip']), mres($_POST['params']));
|
||||
|
||||
if ($service_id) {
|
||||
$message .= $message_break . "Service added (".$service_id.")!";
|
||||
$message_break .= "<br />";
|
||||
}
|
5
html/includes/service-edit.inc.php
Normal file
5
html/includes/service-edit.inc.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
$updated = '1';
|
||||
|
||||
$updated = edit_service(mres($_POST['service']), mres($_POST['descr']), mres($_POST['ip']), mres($_POST['params']));
|
@ -44,58 +44,14 @@ else
|
||||
|
||||
$pagetitle[] = "Add service";
|
||||
|
||||
echo("
|
||||
<h4>Add Service</h4>
|
||||
<form id='addsrv' name='addsrv' method='post' action='' class='form-horizontal' role='form'>
|
||||
<div class='well well-lg'>
|
||||
<div class='form-group'>
|
||||
<input type='hidden' name='addsrv' value='yes'>
|
||||
<label for='device' class='col-sm-2 control-label'>Device</label>
|
||||
<div class='col-sm-5'>
|
||||
<select name='device' class='form-control input-sm'>
|
||||
$devicesform
|
||||
</select>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='type' class='col-sm-2 control-label'>Type</label>
|
||||
<div class='col-sm-5'>
|
||||
<select name='type' id='type' class='form-control input-sm'>
|
||||
$servicesform
|
||||
</select>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='descr' class='col-sm-2 control-label'>Description</label>
|
||||
<div class='col-sm-5'>
|
||||
<textarea name='descr' id='descr' class='form-control input-sm' rows='5'></textarea>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='ip' class='col-sm-2 control-label'>IP Address</label>
|
||||
<div class='col-sm-5'>
|
||||
<input name='ip' id='ip' class='form-control input-sm' placeholder='IP Address'>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='params' class='col-sm-2 control-label'>Parameters</label>
|
||||
<div class='col-sm-5'>
|
||||
<input name='params' id='params' class='form-control input-sm'>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<button type='submit' name='Submit' class='btn btn-default input-sm'>Add Service</button>
|
||||
</div>
|
||||
</form>");
|
||||
echo "<div class='row'>
|
||||
<div class='col-sm-6'>";
|
||||
|
||||
require_once "includes/print-service-add.inc.php";
|
||||
|
||||
echo "</div>
|
||||
</div>";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ if ($_SESSION['userlevel'] < '5')
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<button type='submit' name='Submit' class='btn btn-default input-sm'>Delete</button>
|
||||
<button type='submit' name='Submit' class='btn btn-danger input-sm'>Delete</button>
|
||||
</div>
|
||||
</form>");
|
||||
|
||||
|
@ -25,7 +25,7 @@ if ($_SESSION['userlevel'] < '7')
|
||||
$panes['alert-rules'] = 'Alert Rules';
|
||||
$panes['modules'] = 'Modules';
|
||||
|
||||
if ($config['enable_services'])
|
||||
if ($config['show_services'])
|
||||
{
|
||||
$panes['services'] = 'Services';
|
||||
}
|
||||
|
@ -1,101 +1,85 @@
|
||||
<?php
|
||||
|
||||
echo('<div style="padding: 10px;">');
|
||||
if (is_admin() === TRUE || is_read() === TRUE) {
|
||||
|
||||
if ($_POST['addsrv']) {
|
||||
if ($_SESSION['userlevel'] >= '10') {
|
||||
include("includes/service-add.inc.php");
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST['delsrv']) {
|
||||
if ($_SESSION['userlevel'] >= '10') {
|
||||
include("includes/service-delete.inc.php");
|
||||
}
|
||||
}
|
||||
|
||||
if ($handle = opendir($config['install_dir'] . "/includes/services/"))
|
||||
{
|
||||
while (false !== ($file = readdir($handle)))
|
||||
{
|
||||
if ($file != "." && $file != ".." && !strstr($file, "."))
|
||||
{
|
||||
$servicesform .= "<option value='$file'>$file</option>";
|
||||
if ($_POST['addsrv']) {
|
||||
if ($_SESSION['userlevel'] >= '10') {
|
||||
include("includes/service-add.inc.php");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
if ($_POST['delsrv']) {
|
||||
if ($_SESSION['userlevel'] >= '10') {
|
||||
include("includes/service-delete.inc.php");
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST['confirm-editsrv']) {
|
||||
echo "yeah";
|
||||
if ($_SESSION['userlevel'] >= '10') {
|
||||
include("includes/service-edit.inc.php");
|
||||
}
|
||||
}
|
||||
|
||||
if ($handle = opendir($config['install_dir'] . "/includes/services/")) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != "." && $file != ".." && !strstr($file, ".")) {
|
||||
$servicesform .= "<option value='$file'>$file</option>";
|
||||
}
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
$dev = device_by_id_cache($device['device_id']);
|
||||
$devicesform = "<option value='" . $dev['device_id'] . "'>" . $dev['hostname'] . "</option>";
|
||||
|
||||
if ($updated) {
|
||||
print_message("Device Settings Saved");
|
||||
}
|
||||
|
||||
if (dbFetchCell("SELECT COUNT(*) from `services` WHERE `device_id` = ?", array($device['device_id'])) > '0') {
|
||||
$i = "1";
|
||||
foreach (dbFetchRows("select * from services WHERE device_id = ? ORDER BY service_type", array($device['device_id'])) as $service) {
|
||||
$existform .= "<option value='" . $service['service_id'] . "'>" . $service['service_type'] . "</option>";
|
||||
}
|
||||
}
|
||||
|
||||
echo '<div class="row">';
|
||||
|
||||
if ($existform) {
|
||||
echo '<div class="col-sm-6">';
|
||||
if ($_POST['editsrv'] == "yes") {
|
||||
include_once "includes/print-service-edit.inc.php";
|
||||
} else {
|
||||
echo "
|
||||
<h3><span class='label label-info threeqtr-width'>Edit / Delete Service</span></h3>
|
||||
<form method='post' action='' class='form-horizontal'>
|
||||
<div class='well well-lg'>
|
||||
<div class='form-group'>
|
||||
<label for='service' class='col-sm-2 control-label'>Type: </label>
|
||||
<div class='col-sm-4'>
|
||||
<select name='service' class='form-control input-sm'>
|
||||
$existform
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<div class='col-sm-offset-2 col-sm-4'>
|
||||
<button type='submit' class='btn btn-primary btn-sm' name='editsrv' id='editsrv' value='yes'>Edit</button> <button type='submit' class='btn btn-danger btn-sm' name='delsrv' id='delsrv' value='yes'>Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>";
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '<div class="col-sm-6">';
|
||||
|
||||
require_once "includes/print-service-add.inc.php";
|
||||
|
||||
} else {
|
||||
include("includes/error-no-perm.inc.php");
|
||||
}
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `devices` ORDER BY `hostname`") as $dev);
|
||||
{
|
||||
$devicesform .= "<option value='" . $dev['device_id'] . "'>" . $dev['hostname'] . "</option>";
|
||||
}
|
||||
|
||||
if ($updated) { print_message("Device Settings Saved"); }
|
||||
|
||||
if (dbFetchCell("SELECT COUNT(*) from `services` WHERE `device_id` = ?", array($device['device_id'])) > '0')
|
||||
{
|
||||
$i = "1";
|
||||
foreach (dbFetchRows("select * from services WHERE device_id = ? ORDER BY service_type", array($device['device_id'])) as $service)
|
||||
{
|
||||
$existform .= "<option value='" . $service['service_id'] . "'>" . $service['service_type'] . "</option>";
|
||||
}
|
||||
}
|
||||
|
||||
if($existform)
|
||||
{
|
||||
echo('<div style="float: left;">');
|
||||
echo("
|
||||
|
||||
<h1>Remove Service</h1>
|
||||
|
||||
<form id='delsrv' name='delsrv' method='post' action=''>
|
||||
<input type=hidden name='delsrv' value='yes'>
|
||||
<table width='200' border='0'>
|
||||
<option type=hidden name=device value='".$device['device_id']."'>
|
||||
<tr>
|
||||
<td>
|
||||
Type
|
||||
</td>
|
||||
<td>
|
||||
<select name='service'>
|
||||
$existform
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type='submit' name='Submit' value='Delete' />
|
||||
</label>
|
||||
</form>");
|
||||
|
||||
echo('</div>');
|
||||
}
|
||||
|
||||
echo('<div style="width: 45%; float: right;">');
|
||||
|
||||
echo("
|
||||
<h1>Add Service</h1>
|
||||
|
||||
<form id='addsrv' name='addsrv' method='post' action=''>
|
||||
<input type=hidden name='addsrv' value='yes'>
|
||||
<table width='200' border='0'>
|
||||
<option type=hidden name=device value='".$device['device_id']."'>
|
||||
<tr>
|
||||
<td>
|
||||
Type
|
||||
</td>
|
||||
<td>
|
||||
<select name='type'>
|
||||
$servicesform
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type='submit' name='Submit' value='Add' />
|
||||
<label><br />
|
||||
</label>
|
||||
</form>
|
||||
</div>");
|
||||
|
||||
?>
|
||||
|
52
html/pages/editsrv.inc.php
Normal file
52
html/pages/editsrv.inc.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
if (is_admin() === FALSE && is_read() === FALSE) {
|
||||
|
||||
include "includes/error-no-perm.inc.php";
|
||||
|
||||
} else {
|
||||
|
||||
$pagetitle[] = "Edit service";
|
||||
|
||||
if ($_POST['confirm-editsrv'])
|
||||
{
|
||||
if ($_SESSION['userlevel'] > "5")
|
||||
{
|
||||
include("includes/service-edit.inc.php");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id ORDER BY hostname") as $device)
|
||||
{
|
||||
$servicesform .= "<option value='" . $device['service_id'] . "'>" . $device['hostname'] . " - " . $device['service_type'] . "</option>";
|
||||
}
|
||||
|
||||
if ($updated) { print_message("Service updated!"); }
|
||||
|
||||
if ($_POST['editsrv'] == 'yes') {
|
||||
|
||||
require_once "includes/print-service-edit.inc.php";
|
||||
|
||||
} else {
|
||||
|
||||
echo("
|
||||
<h4>Delete Service</h4>
|
||||
<form id='editsrv' name='editsrv' method='post' action='' class='form-horizontal' role='form'>
|
||||
<input type=hidden name='delsrv' value='yes'>
|
||||
<div class='well well-lg'>
|
||||
<div class='form-group'>
|
||||
<label for='service' class='col-sm-2 control-label'>Device - Service</label>
|
||||
<div class='col-sm-5'>
|
||||
<select name='service' id='service' class='form-control input-sm'>
|
||||
$servicesform
|
||||
</select>
|
||||
</div>
|
||||
<div class='col-sm-5'>
|
||||
</div>
|
||||
</div>
|
||||
<button type='submit' name='editsrv' id='editsrv' value='yes' class='btn btn-primary input-sm'>Edit</button>
|
||||
</div>
|
||||
</form>");
|
||||
}
|
||||
|
||||
}
|
@ -561,12 +561,35 @@ function is_valid_hostname($hostname)
|
||||
return ctype_alnum(str_replace('_','',str_replace('-','',str_replace('.','',$hostname))));
|
||||
}
|
||||
|
||||
function add_service($device, $service, $descr)
|
||||
{
|
||||
$insert = array('device_id' => $device['device_id'], 'service_ip' => $device['hostname'], 'service_type' => $service,
|
||||
'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $descr, 'service_param' => "", 'service_ignore' => "0");
|
||||
function add_service($device, $service, $descr, $service_ip, $service_param = "", $service_ignore = 0) {
|
||||
|
||||
if (!is_array($device)) {
|
||||
$device = device_by_id_cache($device);
|
||||
}
|
||||
|
||||
if (empty($service_ip)) {
|
||||
$service_ip = $device['hostname'];
|
||||
}
|
||||
|
||||
$insert = array('device_id' => $device['device_id'], 'service_ip' => $service_ip, 'service_type' => $service,
|
||||
'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $descr, 'service_param' => $service_param, 'service_ignore' => $service_ignore);
|
||||
|
||||
return dbInsert($insert, 'services');
|
||||
}
|
||||
|
||||
function edit_service($service, $descr, $service_ip, $service_param = "", $service_ignore = 0) {
|
||||
|
||||
if (!is_numeric($service)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$update = array('service_ip' => $service_ip,
|
||||
'service_changed' => array('UNIX_TIMESTAMP(NOW())'),
|
||||
'service_desc' => $descr,
|
||||
'service_param' => $service_param,
|
||||
'service_ignore' => $service_ignore);
|
||||
return dbUpdate($update, 'services', '`service_id`=?', array($service));
|
||||
|
||||
echo dbInsert($insert, 'services');
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user