Implement node flags

This commit is contained in:
2023-03-07 14:56:32 +01:00
parent 78b97c5094
commit bfbdc16036
15 changed files with 200 additions and 38 deletions

View File

@@ -83,14 +83,24 @@ switch ($submit = form_get_action()) {
$node_dns2 = sanitize($_POST['node_dns2']);
$node_info = sanitize($_POST['node_info']);
$zone_id = sanitize($_POST['zone_id']);
$flag_deleted = isset($_POST['flag_deleted']) or false;
$flag_reserved = isset($_POST['flag_reserved']) or false;
// construct flags
$flags = array();
if ($flag_deleted) $flags[] = 'deleted';
if ($flag_reserved) $flags[] = 'reserved';
$flags = empty($flags) ? NULL : implode(',', $flags);
$sql = "UPDATE node SET
asset_id=?, node_ip=?, subnet_id=?, node_mac=?,
node_dns1=?, node_dns2=?, node_info=?, zone_id=?
node_dns1=?, node_dns2=?, node_info=?, zone_id=?,
node_flags=?
WHERE node_id=?";
$sth = $dbh->prepare($sql);
$sth->execute([$asset_id, $node_ip, $subnet_id, $node_mac,
$node_dns1, $node_dns2, $node_info, $zone_id,
$flags,
$id]);
$action = ACT_VIEW;
break;
@@ -138,19 +148,24 @@ if(isset($_GET['subnet_id'])) {
$smarty->assign("subnet_id", '');
}
// deleted records only for admin or manager
if (($_SESSION['suser_role_admin'] == 0) and ($_SESSION['suser_role_manage'] == 0)) {
$w[] = "((n.node_flags IS NULL) OR (n.node_flags & 0x1 = 0))";
}
// create sql with optional filter
$where = join(' AND ', $w);
$sql = "SELECT a.asset_id,
CONCAT(LEFT(a.asset_info,30), IF(CHAR_LENGTH(a.asset_info)>30,'...','')) AS asset_info,
REPLACE(a.asset_name, ' ', ' ') AS asset_name,
n.node_id, n.node_ip,
n.node_id, n.node_ip, (n.node_flags & 0x1)=1 AS deleted,
CONCAT(LEFT(n.node_info,30), IF(CHAR_LENGTH(n.node_info)>30,'...','')) AS node_info,
c.assetclass_id, c.assetclass_name
FROM node AS n LEFT JOIN asset AS a USING (asset_id)
LEFT JOIN assetclass AS c USING (assetclass_id)";
if ($where) {
$sql .= ' WHERE ' . $where;
$sql .= ' WHERE ' . $where . ' ';
}
$sql .= "GROUP BY n.node_id ORDER BY INET_ATON(n.node_ip)";
$sth = $dbh->prepare($sql);
@@ -201,7 +216,8 @@ elseif ($action == ACT_VIEW):
// node
$sql = "SELECT n.node_id AS id, n.node_ip AS ip, n.node_mac AS mac,
n.node_dns1 AS dns1, n.node_dns2 AS dns2, n.node_info AS info,
n.node_type AS type,
n.node_type AS type, n.node_flags AS flags,
(n.node_flags & 0x1)=1 AS deleted, (n.node_flags & 0x2)=2 AS reserved,
a.asset_id, a.asset_name,
c.assetclass_id, c.assetclass_name,
s.subnet_id, s.subnet_address, s.subnet_mask,
@@ -259,12 +275,14 @@ elseif ($action == ACT_EDIT):
$sql = "SELECT node_id AS id, node_ip AS ip, node_mac AS mac,
node_dns1 AS dns1, node_dns2 AS dns2, node_info AS info,
zone_id, asset_id, subnet_id
zone_id, asset_id, subnet_id, node_flags AS flags
FROM node
WHERE node_id=?";
$sth = $dbh->prepare($sql);
$sth->execute([$id]);
$smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ));
$node = $sth->fetch(PDO::FETCH_OBJ);
$node->flags = explode(',', $node->flags);
$smarty->assign("node", $node);
$smarty->assign("asset_options", db_get_options_asset());
$smarty->assign("subnet_options", db_get_options_subnet());