Esempio n. 1
0
<?php 
require 'connectionBD.php';
session_start();
//validamos si se ha hecho o no el inicio de sesion correctamente
//si no se ha hecho la sesion nos regresará a login.php
if (!isset($_SESSION['usuario'])) {
    header('Location: login.html');
    exit;
}
$conn = connection();
$actualizar = $_POST["actualizar"];
if ($actualizar != null && $actualizar != "false") {
    $id = $_POST["id"];
    updateInterface($conn, $id);
}
?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Arduino project</title>

    <!-- Bootstrap Core CSS -->
function deleteInterface($hostName, $ip)
{
    # host id
    $hostid = searchHost($hostName)[$hostName];
    # get interface of host
    $interfaces = searchInterfaces($hostid);
    $interfaceid = -1;
    $flag = false;
    $length = count($interfaces);
    for ($i = 0; $i < $length; $i++) {
        if ($interfaces[$i]['ip'] == $ip) {
            # interface id
            $interfaceid = $interfaces[$i]['interfaceid'];
            if ($interfaces[$i]['main'] == 1) {
                # if deleted interface type is main, change main interface into next interface.
                if ($length > 1) {
                    $mainIndex = $i + 1 >= $length ? $i + 1 - $length : $i + 1;
                    updateInterface($interfaces[$mainIndex]['interfaceid'], 1);
                } else {
                    updateInterface($interfaceid, 0, '127.0.0.1');
                    return;
                }
            }
            # delete interface
            $params = array($interfaceid);
            doPost('hostinterface.delete', $params);
            $flag = true;
        }
    }
    if ($flag) {
        return array('result' => 'OK');
    } else {
        return array('error' => "interface {$ip} is not exists.");
    }
}