Exemplo n.º 1
0
function del_device()
{
    // This will add a device using the data passed encoded with json
    global $config;
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $hostname = $router['hostname'];
    // Default status to error and change it if we need to.
    $status = 'error';
    $code = 500;
    if (empty($hostname) || $config['api_demo'] == 1) {
        $message = 'No hostname has been provided to delete';
        if ($config['api_demo'] == 1) {
            $message = "This feature isn\\'t available in the demo";
        }
        $output = array('status' => $status, 'message' => $message);
    } else {
        // allow deleting by device_id or hostname
        $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
        $device = null;
        if ($device_id) {
            // save the current details for returning to the client on successful delete
            $device = device_by_id_cache($device_id);
        }
        if ($device) {
            $response = delete_device($device_id);
            if (empty($response)) {
                // FIXME: Need to provide better diagnostics out of delete_device
                $output = array('status' => $status, 'message' => 'Device deletion failed');
            } else {
                // deletion succeeded - include old device details in response
                $code = 200;
                $status = 'ok';
                $output = array('status' => $status, 'message' => $response, 'devices' => array($device));
            }
        } else {
            // no device matching the name
            $code = 404;
            $output = array('status' => $status, 'message' => "Device {$hostname} not found");
        }
    }
    $app->response->setStatus($code);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Exemplo n.º 2
0
if ($_SESSION['userlevel'] < 10) {
    require 'includes/error-no-perm.inc.php';
    exit;
}
$pagetitle[] = "Delete device";
if ($_SESSION['userlevel'] == 11) {
    demo_account();
} else {
    if (is_numeric($_REQUEST['id'])) {
        echo '
            <div class="row">
            <div class="col-sm-offset-2 col-sm-7">
            ';
        if ($_REQUEST['confirm']) {
            print_message(nl2br(delete_device(mres($_REQUEST['id']))) . "\n");
        } else {
            $device = device_by_id_cache($_REQUEST['id']);
            print_error("Are you sure you want to delete device " . $device['hostname'] . "?");
            ?>
<br />
<center>
  <font color="red"></font><i class="fa fa-exclamation-triangle fa-3x"></i></font>
  <br>
  <form name="form1" method="post" action="" class="form-horizontal" role="form">
    <div class="form-group">
      <input type="hidden" name="id" value="<?php 
            echo $_REQUEST['id'];
            ?>
" />
      <input type="hidden" name="confirm" value="1" />
 * @package    observium
 * @subpackage webui
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
if ($_SESSION['userlevel'] < 10) {
    include "includes/error-no-perm.inc.php";
    exit;
}
$page_title[] = "删除设备";
if (is_numeric($vars['id'])) {
    $device = device_by_id_cache($vars['id']);
    if ($device && $vars['confirm']) {
        $delete_rrd = $vars['deleterrd'] == 'confirm' ? TRUE : FALSE;
        print_message(delete_device($vars['id'], $delete_rrd), 'console');
        //echo('<div class="btn-group ">
        //        <button type="button" class="btn btn-default"><a href="/"><i class="oicon-globe-model"></i> 概述</a></button>
        //        <button type="button" class="btn btn-default"><a href="/devices/"><i class="oicon-servers"></i> 设备列表</a></button>
        //      </div>');
    } else {
        print_warning("您确定需要删除该设备吗 <strong>" . $device['hostname'] . "</strong>?");
        ?>
<br />
<form name="form1" method="post" action="" class="form-horizontal" >
  <input type="hidden" name="id" value="<?php 
        echo $vars['id'];
        ?>
" />
  <input type="hidden" name="confirm" value="1" />
  <!--<input type="submit" class="submit" name="Submit" value="确认删除主机" />-->
Exemplo n.º 4
0
#!/usr/bin/env php
<?php 
/**
 * LibreNMS
 *
 *   This file is part of LibreNMS.
 *
 * @package    LibreNMS
 * @subpackage cli
 * @copyright  (C) 2006 - 2012 Adam Armstrong
 */
$init_modules = array();
require __DIR__ . '/includes/init.php';
// Remove a host and all related data from the system
if ($argv[1]) {
    $host = strtolower($argv[1]);
    $id = getidbyname($host);
    if ($id) {
        echo delete_device($id) . "\n";
    } else {
        echo "Host doesn't exist!\n";
    }
} else {
    echo "Host Removal Tool\nUsage: ./delhost.php <hostname>\n";
}
Exemplo n.º 5
0
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage cli
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
chdir(dirname($argv[0]));
include "includes/defaults.inc.php";
include "config.php";
include "includes/definitions.inc.php";
include "includes/functions.inc.php";
$scriptname = basename($argv[0]);
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WRemove Device%n\n", 'color');
// Remove a host and all related data from the system
if ($argv[1]) {
    $host = strtolower($argv[1]);
    $id = getidbyname($host);
    $delete_rrd = isset($argv[2]) && strtolower($argv[2]) == 'rrd' ? TRUE : FALSE;
    // Test if a valid id was fetched from getidbyname.
    if (isset($id) && is_numeric($id)) {
        print_warning(delete_device($id, $delete_rrd));
        print_success("Device {$host} removed.");
    } else {
        print_error("Device {$host} doesn't exist!");
    }
} else {
    print_message("%n\nUSAGE:\n{$scriptname} <hostname> [rrd]\n\nEXAMPLE:\n%WKeep RRDs%n:   {$scriptname} <hostname>\n%WRemove RRDs%n: {$scriptname} <hostname> rrd\n\n%rInvalid arguments!%n", 'color', FALSE);
}
// EOF
Exemplo n.º 6
0
<h2>Delete Device</h2>

<?php 
if ($_SESSION['userlevel'] < 10) {
    include "includes/error-no-perm.inc.php";
    exit;
}
$pagetitle[] = "Delete device";
if (is_numeric($_REQUEST['id'])) {
    if ($_REQUEST['confirm']) {
        print_message(delete_device(mres($_REQUEST['id'])));
    } else {
        $device = device_by_id_cache($_REQUEST['id']);
        print_message("Are you sure you want to delete device " . $device['hostname'] . "?");
        ?>
<br />
<form name="form1" method="post" action="" class="form-horizontal" >
    <input type="hidden" name="id" value="<?php 
        echo $_REQUEST['id'];
        ?>
" />
    <input type="hidden" name="confirm" value="1" />
    <input type="submit" class="submit" name="Submit" value="Confirm host deletion" />

<?php 
    }
} else {
    ?>

<form name="form1" method="post" action="" class="form-horizontal" >
Exemplo n.º 7
0
#!/usr/bin/env php
<?php 
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage cli
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006 - 2012 Adam Armstrong
 *
 */
chdir(dirname($argv[0]));
include "includes/defaults.inc.php";
include "config.php";
include "includes/definitions.inc.php";
include "includes/functions.php";
# Remove a host and all related data from the system
if ($argv[1]) {
    $host = strtolower($argv[1]);
    $id = getidbyname($host);
    if ($id) {
        echo delete_device($id);
        echo "Removed {$host}\n";
    } else {
        echo "Host doesn't exist!\n";
    }
} else {
    echo "Host Removal Tool\nUsage: ./delhost.php <hostname>\n";
}
 *
 * @package    observium
 * @subpackage webui
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
if ($_SESSION['userlevel'] < 10) {
    include "includes/error-no-perm.inc.php";
    exit;
}
$pagetitle[] = "删除设备";
if (is_numeric($_REQUEST['id'])) {
    if ($_REQUEST['confirm']) {
        $delete_rrd = $_REQUEST['deleterrd'] == 'confirm' ? TRUE : FALSE;
        print_success(delete_device(mres($_REQUEST['id']), $delete_rrd));
        echo '<div class="btn-group ">
            <button type="button" class="btn btn-default"><a href="/"><i class="oicon-globe-model"></i> 概述</a></button>
            <button type="button" class="btn btn-default"><a href="/devices/"><i class="oicon-servers"></i> 设备列表</a></button>
          </div>';
    } else {
        $device = device_by_id_cache($_REQUEST['id']);
        print_warning("您确定需要删除该设备吗 <strong>" . $device['hostname'] . "</strong>?");
        ?>
<br />
<form name="form1" method="post" action="" class="form-horizontal" >
  <input type="hidden" name="id" value="<?php 
        echo $_REQUEST['id'];
        ?>
" />
  <input type="hidden" name="confirm" value="1" />
Exemplo n.º 9
0
 * @package    observium
 * @subpackage webui
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
if ($_SESSION['userlevel'] < 10) {
    include "includes/error-no-perm.inc.php";
    exit;
}
$pagetitle[] = "Delete devices";
if (is_numeric($vars['id'])) {
    $device = device_by_id_cache($vars['id']);
    if ($device && $vars['confirm']) {
        $delete_rrd = $vars['deleterrd'] == 'confirm' ? TRUE : FALSE;
        print_warning(delete_device($vars['id'], $delete_rrd));
        //echo('<div class="btn-group ">
        //        <button type="button" class="btn btn-default"><a href="/"><i class="oicon-globe-model"></i> Overview</a></button>
        //        <button type="button" class="btn btn-default"><a href="/devices/"><i class="oicon-servers"></i> Devices List</a></button>
        //      </div>');
    } else {
        print_warning("Are you sure you want to delete device <strong>" . $device['hostname'] . "</strong>?");
        ?>
<br />
<form name="form1" method="post" action="" class="form-horizontal" >
  <input type="hidden" name="id" value="<?php 
        echo $vars['id'];
        ?>
" />
  <input type="hidden" name="confirm" value="1" />
  <!--<input type="submit" class="submit" name="Submit" value="Confirm host deletion" />-->
Exemplo n.º 10
0
function dbase_parse($cmd, $message)
{
    global $pisql, $dbhost, $dbuser, $dbpass, $dbname;
    global $log;
    // Used by daemon
    global $apperr, $appmsg;
    // For ajax usage
    if (!$pisql || !$pisql->ping()) {
        $log->lwrite("dbase_parse:: Ping failed, making new pisql connection to server", 1);
        $pisql = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    }
    // If there is an error
    if ($pisql->connect_errno) {
        $log->lwrite("dbase_parse:: Failed to connect to MySQL: (" . $pisql->connect_errno . ") " . $pisql->connect_error, 1);
        return -1;
    }
    // For logging only
    if (is_array($message)) {
        $str = "";
        foreach ($message as $key => $val) {
            $str .= " {" . $key . ":" . $val . "},";
        }
        $log->lwrite("dbase_parse:: " . $cmd . ": " . $str, 1);
    } else {
        $log->lwrite("dbase_parse:: message: " . $cmd . ": " . $message, 1);
    }
    //
    // Depending on $cmd execute database function
    switch ($cmd) {
        // Database
        case "load_database":
            $ret = load_database();
            break;
            // Device
        // Device
        case "load_devices":
            $ret = load_devices();
            break;
        case "add_device":
            $ret = add_device($message);
            break;
        case "delete_device":
            $ret = delete_device($message);
            break;
        case "store_device":
            $ret = store_device($message);
            break;
            // Room
        // Room
        case "add_room":
            $ret = add_room($message);
            break;
        case "delete_room":
            $ret = delete_room($message);
            break;
            // Scene
        // Scene
        case "read_scene":
            $ret = load_scene($message);
            break;
        case "load_scenes":
            $ret = load_scenes();
            break;
        case "add_scene":
            $ret = add_scene($message);
            break;
        case "delete_scene":
            $ret = delete_scene($message);
            break;
        case "upd_scene":
            $ret = upd_scene($message);
            break;
        case "store_scene":
            $ret = store_scene($message);
            break;
            // Timer
        // Timer
        case "add_timer":
            $ret = add_timer($message);
            break;
        case "delete_timer":
            $ret = delete_timer($message);
            break;
        case "store_timer":
            $ret = store_timer($message);
            break;
            // Handset
        // Handset
        case "add_handset":
            $ret = add_handset($message);
            break;
        case "delete_handset":
            $ret = delete_handset($message);
            break;
        case "store_handset":
            $ret = store_handset($message);
            break;
            // Weather
        // Weather
        case "add_weather":
            $ret = add_weather($message);
            break;
        case "delete_weather":
            $ret = delete_weather($message);
            break;
            // Setting
        // Setting
        case "store_setting":
            $ret = store_setting($message);
            break;
        default:
    }
    if ($ret >= 0) {
        // Prepare structure to send back to the calling ajax client (in stdout)
        $send = array('tcnt' => $ret, 'appmsg' => $appmsg, 'status' => 'OK', 'apperr' => $apperr);
        $output = json_encode($send);
    } else {
        //	Functions need to fill apperr themselves!
        $send = array('tcnt' => $ret, 'appmsg' => $appmsg, 'status' => 'ERR', 'apperr' => $apperr);
        $output = json_encode($send);
    }
    return $output;
}
Exemplo n.º 11
0
if ($_SESSION['userlevel'] < 10) {
    require 'includes/error-no-perm.inc.php';
    exit;
}
$pagetitle[] = "Delete device";
if ($_SESSION['userlevel'] == 11) {
    demo_account();
} else {
    if (is_numeric($vars['id'])) {
        echo '
            <div class="row">
            <div class="col-sm-offset-2 col-sm-7">
            ';
        if ($vars['confirm']) {
            print_message(nl2br(delete_device(mres($vars['id']))) . "\n");
        } else {
            $device = device_by_id_cache($vars['id']);
            print_error("Are you sure you want to delete device " . $device['hostname'] . "?");
            ?>
<br />
<center>
  <font color="red"></font><i class="fa fa-exclamation-triangle fa-3x"></i></font>
  <br>
  <form name="form1" method="post" action="" class="form-horizontal" role="form">
    <div class="form-group">
      <input type="hidden" name="id" value="<?php 
            echo $vars['id'];
            ?>
" />
      <input type="hidden" name="confirm" value="1" />
Exemplo n.º 12
0
function dbase_parse($cmd, $message)
{
    //
    switch ($cmd) {
        case "add_device":
            $ret = add_device($message);
            break;
        case "delete_device":
            $ret = delete_device($message);
            break;
        case "add_room":
            $ret = add_room($message);
            break;
        case "delete_room":
            $ret = delete_room($message);
            break;
        case "add_scene":
            break;
        case "delete_scene":
            break;
        case "upd_scene":
            break;
        case "add_timer":
            break;
        case "delete_timer":
            break;
        case "store_timer":
            break;
        case "add_handset":
            break;
        case "delete_handset":
            break;
        case "store_handset":
            break;
        case "add_weather":
            break;
        case "delete_weather":
            break;
        case "store_setting":
            break;
        default:
    }
    if ($ret >= 0) {
        // Prepare structure to send back to the calling ajax client (in stdout)
        $send = array('tcnt' => $ret, 'appmsg' => $appmsg, 'status' => 'OK', 'apperr' => $apperr);
        $output = json_encode($send);
    } else {
        //	Functions need to fill apperr themselves!
        $send = array('tcnt' => $ret, 'appmsg' => $appmsg, 'status' => 'ERR', 'apperr' => $apperr);
        $output = json_encode($send);
    }
    return $output;
}