From 78b97c50948e3cc18057b7bd9a19b985fd4f7445 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Mon, 6 Mar 2023 19:25:21 +0100 Subject: [PATCH] Refactored, no more redirects. Improved error messaging system --- about.php | 2 +- asset.php | 34 +- assigniptonode.php | 29 -- assignnodetoasset.php | 28 -- cable.php | 51 ++- comments.php | 22 - index.php | 2 +- lib.php | 2 + location.php | 94 ++++- locationadd.php | 75 ---- locationdel.php | 24 -- locationedit.php | 98 ----- locationsubnetadd.php | 28 -- locationsubnetdel.php | 44 -- locationsubnetedit.php | 26 -- locationview.php | 67 --- nat.php | 163 +++++++- natadd.php | 65 --- natdel.php | 40 -- natedit.php | 24 -- node.php | 246 ++++++++++- nodeadd.php | 27 -- nodedel.php | 24 -- nodeedit.php | 32 -- nodeview.php | 89 ---- options.php | 212 +++++++++- optionseditdisplay.php | 99 ----- optionseditpassword.php | 16 - submit.php | 815 ------------------------------------ subnet.php | 726 +++++++++++++++++++++++++++++++- subnetadd.php | 21 - subnetdel.php | 36 -- subnetedit.php | 29 -- subnetlocationadd.php | 28 -- subnetlocationdel.php | 42 -- subnetlocationedit.php | 27 -- subnetview.php | 364 ---------------- subnetvlanadd.php | 43 -- subnetvlandel.php | 36 -- subnetvlanedit.php | 26 -- tpl/asset.tpl | 4 +- tpl/assetclassview.tpl | 4 +- tpl/assetedit.tpl | 20 + tpl/assetview.tpl | 4 +- tpl/assigniptonode.tpl | 11 +- tpl/assignnodetoasset.tpl | 5 +- tpl/cableadd.tpl | 10 +- tpl/comments.tpl | 23 - tpl/header.tpl | 2 +- tpl/locationsubnetadd.tpl | 11 +- tpl/locationsubnetdel.tpl | 12 +- tpl/locationsubnetedit.tpl | 8 +- tpl/locationview.tpl | 4 +- tpl/nat.tpl | 4 +- tpl/natadd.tpl | 7 +- tpl/natdel.tpl | 7 +- tpl/natedit.tpl | 9 +- tpl/node.tpl | 14 +- tpl/nodeadd.tpl | 7 +- tpl/nodedel.tpl | 10 +- tpl/nodeedit.tpl | 7 +- tpl/nodeview.tpl | 24 +- tpl/options.tpl | 4 +- tpl/optionseditdisplay.tpl | 5 +- tpl/optionseditpassword.tpl | 6 +- tpl/style.css | 8 +- tpl/subnet.tpl | 4 +- tpl/subnetadd.tpl | 5 +- tpl/subnetdel.tpl | 11 +- tpl/subnetedit.tpl | 11 +- tpl/subnetlocationadd.tpl | 9 +- tpl/subnetlocationdel.tpl | 7 +- tpl/subnetlocationedit.tpl | 13 +- tpl/subnetview.tpl | 20 +- tpl/subnetvlanadd.tpl | 9 +- tpl/subnetvlandel.tpl | 9 +- tpl/subnetvlanedit.tpl | 9 +- tpl/vlansubnetadd.tpl | 9 +- tpl/vlansubnetdel.tpl | 9 +- tpl/vlansubnetedit.tpl | 9 +- tpl/vlanview.tpl | 4 +- tpl/zoneedit.tpl | 11 + user.php | 11 +- vlan.php | 93 +++- vlansubnetadd.php | 43 -- vlansubnetdel.php | 27 -- vlansubnetedit.php | 25 -- 87 files changed, 1801 insertions(+), 2633 deletions(-) delete mode 100644 assigniptonode.php delete mode 100644 assignnodetoasset.php delete mode 100644 comments.php delete mode 100644 locationadd.php delete mode 100644 locationdel.php delete mode 100644 locationedit.php delete mode 100644 locationsubnetadd.php delete mode 100644 locationsubnetdel.php delete mode 100644 locationsubnetedit.php delete mode 100644 locationview.php delete mode 100644 natadd.php delete mode 100644 natdel.php delete mode 100644 natedit.php delete mode 100644 nodeadd.php delete mode 100644 nodedel.php delete mode 100644 nodeedit.php delete mode 100644 nodeview.php delete mode 100644 optionseditdisplay.php delete mode 100644 optionseditpassword.php delete mode 100644 submit.php delete mode 100644 subnetadd.php delete mode 100644 subnetdel.php delete mode 100644 subnetedit.php delete mode 100644 subnetlocationadd.php delete mode 100644 subnetlocationdel.php delete mode 100644 subnetlocationedit.php delete mode 100644 subnetview.php delete mode 100644 subnetvlanadd.php delete mode 100644 subnetvlandel.php delete mode 100644 subnetvlanedit.php delete mode 100644 tpl/comments.tpl delete mode 100644 vlansubnetadd.php delete mode 100644 vlansubnetdel.php delete mode 100644 vlansubnetedit.php diff --git a/about.php b/about.php index c063027..6998c67 100644 --- a/about.php +++ b/about.php @@ -12,5 +12,5 @@ include("header.php"); $smarty->display("about.tpl"); -include("footer.php"); +$smarty->display("footer.tpl"); ?> \ No newline at end of file diff --git a/asset.php b/asset.php index 131849a..27e60b6 100644 --- a/asset.php +++ b/asset.php @@ -58,6 +58,24 @@ switch ($submit = form_get_action()) { $sth->execute([$asset_name, $asset_info, $asset_hostname, $assetclass_id, $asset_intf, $asset_type, $id]); + + // Ext. links + if ($config_ext['zabbix']['enabled'] and isset($_POST['x_zbx_host'])) { + $zbx_host = sanitize($_POST['x_zbx_host']); + $sql = "SELECT extlink_id FROM extlink WHERE asset_id=? AND extlink_type='zabbix'"; + $sth = $dbh->prepare($sql); + $sth->execute([$id]); + if ($linkid = $sth->fetchColumn()) { + $sql = "UPDATE extlink SET extlink_refid=? WHERE extlink_id=?"; + $sth = $dbh->prepare($sql); + $sth->execute([$zbx_host, $linkid]); + } else { + $sql = "INSERT INTO extlink (asset_id, extlink_type, extlink_refid) VALUES (?, 'zabbix', ?)"; + $sth = $dbh->prepare($sql); + $sth->execute([$id, $zbx_host]); + } + } + $action = ACT_VIEW; break; @@ -165,7 +183,19 @@ $smarty->assign("nodes", $sth->fetchAll(PDO::FETCH_ASSOC)); // ID: extlink_refid int // extlink_uid string -// $sql = "SELECT extlink_id, extlink_type, extlink_refid, extlink_uid FROM extline WHERE extlink_asset_id=?"; +if ($config_ext['zabbix']['enabled']) { + $smarty->assign("zabbix", true); + $sql = "SELECT extlink_refid FROM extlink WHERE extlink_type='zabbix' AND asset_id=?"; + $sth = $dbh->prepare($sql); + $sth->execute([$id]); + $refid = $sth->fetchColumn(); + // TODO fetch ext data here + //$zbx = new PDO('mysql:host='.$config_ext['zabbix']['host'].';dbname='.$config_ext['zabbix']['db'].';', $config_ext['zabbix']['user'], $config_ext['zabbix']['pass']); + //$zbx->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + //$zbx->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); + $smarty->assign('refid', $refid); +} + $smarty->display("assetview.tpl"); @@ -186,6 +216,8 @@ $smarty->assign("type_names", ['Active', 'Passive']); $smarty->assign("assetclass_options", db_get_options_assetclass()); + + $smarty->display("assetedit.tpl"); elseif ($action == ACT_DELETE): diff --git a/assigniptonode.php b/assigniptonode.php deleted file mode 100644 index 89de0d4..0000000 --- a/assigniptonode.php +++ /dev/null @@ -1,29 +0,0 @@ -prepare($sql); -$sth->execute([$subnet_id]); - -$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); -$smarty->assign("node_ip", $node_ip); - -$smarty->display("assigniptonode.tpl"); - -include("footer.php"); -?> diff --git a/assignnodetoasset.php b/assignnodetoasset.php deleted file mode 100644 index 035b43a..0000000 --- a/assignnodetoasset.php +++ /dev/null @@ -1,28 +0,0 @@ -assign("node_ip", $node_ip); -$smarty->assign("asset_id", $asset_id); -$smarty->assign("subnet_id", $subnet_id); - -$smarty->assign("asset_options", db_get_options_asset()); -$smarty->assign("subnet_options", db_get_options_subnet()); - -$smarty->display("assignnodetoasset.tpl"); - -include("footer.php"); -?> diff --git a/cable.php b/cable.php index a7d8d53..bb25d2c 100644 --- a/cable.php +++ b/cable.php @@ -10,7 +10,8 @@ SPDX-License-Identifier: GPL-3.0-or-later include("includes.php"); if ($_SESSION['suser_role_admin'] == 0) { - header_location('comments.php?comments=accessdenied'); + $g_error->add('Access denied!'); + $action = ACT_ERR_DENIED; } if (isset($_REQUEST['id'])) { @@ -33,23 +34,43 @@ switch ($submit = form_get_action()) { case 'insert': $description = sanitize($_POST['description']); + $length = sanitize($_POST['length']); $color = sanitize($_POST['color']); $type = sanitize($_POST['cable_type']); $links = sanitize($_POST['links']); $info = sanitize($_POST['info']); $sql = "INSERT INTO cable - (cable_description, cable_color, cable_type, cable_links, cable_info) + (cable_description, cable_color, cable_type, cable_links, + cable_length, cable_info) VALUES - (:description, :color, :type, :links, :info)"; + (:description, :color, :type, :links, + :length, :info)"; $sth = $dbh->prepare($sql); - $sth->bindValue(':description', $description, PDO::PARAM_STR); - $sth->bindValue(':color', $color, PDO::PARAM_STR); - $sth->bindValue(':type', $type, PDO::PARAM_STR); - $sth->bindValue(':links', $info, PDO::PARAM_INT); - $sth->bindValue(':info', $info, PDO::PARAM_STR); - $sth->execute(); - $id = $dbh->lastInsertId(); - $action = ACT_VIEW; + try { + $sth->bindValue(':description', $description, PDO::PARAM_STR); + $sth->bindValue(':length', $length, PDO::PARAM_INT); + $sth->bindValue(':color', $color, PDO::PARAM_STR); + $sth->bindValue(':type', $type, PDO::PARAM_STR); + $sth->bindValue(':links', $info, PDO::PARAM_INT); + $sth->bindValue(':info', $info, PDO::PARAM_STR); + $sth->execute(); + $id = $dbh->lastInsertId(); + $action = ACT_VIEW; + } catch (PDOException $e) { + $g_error->Add($e->getMessage()); + if ($e->getCode() == 23000) { + // duplicate key + $g_warning->Add("Save failed"); + $g_warning->Add("Cable description '$description' already in use!"); + } + // reassign entered values + $smarty->assign('length', $length); + $smarty->assign('type', $type); + $smarty->assign('links', $links); + $smarty->assign('color', $color); + $smarty->assign('info', $info); + $action = ACT_ADD; + } break; case 'update': @@ -156,6 +177,14 @@ $smarty->assign('description', $sth->fetchColumn()); $smarty->display('cabledel.tpl'); +elseif ($action == ACT_ERR_DENIED): +// ========== ERROR ACCESS TO PAGE DENIED ===================================== + +if (isset($_SERVER['HTTP_REFERER'])) { + echo '', "Back to last page

\n"; +} +echo "

"; + else: // ========== ERROR UNKNOWN VARIANT =========================================== diff --git a/comments.php b/comments.php deleted file mode 100644 index f450c38..0000000 --- a/comments.php +++ /dev/null @@ -1,22 +0,0 @@ -assign("comments", $lang['lang_comments_' . $comments]); - -$smarty->display("comments.tpl"); - -include("footer.php"); -?> diff --git a/index.php b/index.php index 031717f..5086928 100644 --- a/index.php +++ b/index.php @@ -55,5 +55,5 @@ $smarty->assign("cable_counter", $sth->fetchColumn()); $smarty->display("index.tpl"); -include("footer.php"); +$smarty->display("footer.tpl"); ?> diff --git a/lib.php b/lib.php index 8f8f1eb..cd26015 100644 --- a/lib.php +++ b/lib.php @@ -10,6 +10,7 @@ SPDX-License-Identifier: GPL-3.0-or-later // ========== CONSTANT DEFINITIONS ============================================ // page actions +define ('ACT_ERR_DENIED', -1); define ('ACT_DEFAULT', 0); define ('ACT_ADD', 1); define ('ACT_VIEW', 2); @@ -24,6 +25,7 @@ define ('ACT_LINK', 10); define ('ACT_UNLINK', 11); define ('ACT_MAIL', 12); define ('ACT_VIEW_LIST', 13); +define ('ACT_PASSWORD', 14); // ========== GLOBAL PAGE START CODE ========================================== diff --git a/location.php b/location.php index d317ef3..4da2f16 100644 --- a/location.php +++ b/location.php @@ -46,6 +46,12 @@ function checkchildren($locations, $level) { } } +// ========== ADDITIONAL ACTION DEFINITIONS =================================== + +define ('ACT_SUBNET_EDIT', 100); +define ('ACT_SUBNET_ADD', 101); +define ('ACT_SUBNET_DEL', 102); + // ========== ACTIONS START =================================================== switch ($submit = form_get_action()) { @@ -55,6 +61,17 @@ switch ($submit = form_get_action()) { case 'view': $action = ACT_VIEW; break; case 'edit': $action = ACT_EDIT; break; case 'del': $action = ACT_DELETE; break; + case 'link': $action = ACT_SUBNET_EDIT; break; + + case 'exec-link': + if ($_POST['action'] == 'locationsubnetadd') { + $action = ACT_SUBNET_ADD; + } elseif ($_POST['action'] == 'locationsubnetdel') { + $action = ACT_SUBNET_DEL; + } else { + $g_warning->Add('invalid action!'. $_POST['action']); + } + break; case 'insert': $name = sanitize($_POST['location_name']); @@ -84,6 +101,22 @@ switch ($submit = form_get_action()) { $action = ACT_VIEW; break; + case 'subnetlink': + $subnet_id = sanitize($_POST['subnet_id']); + $sql = "INSERT INTO subnetlocation (location_id, subnet_id) VALUE (?, ?)"; + $sth = $dbh->prepare($sql); + $sth->execute([$id, $subnet_id]); + $action = ACT_VIEW; + break; + + case 'subnetunlink': + $subnet_id = sanitize($_POST['subnet_id']); + $sth = $dbh->prepare("DELETE FROM subnetlocation WHERE location_id=? AND subnet_id=?"); + $sth->execute([$id, $subnet_id]); + $g_message->Add('Link removed'); + $action = ACT_VIEW; + break; + case 'delete': $sth = $dbh->prepare("DELETE FROM location WHERE location_id=?"); $sth->execute([$id]); @@ -118,7 +151,7 @@ function build_tree($parent_id, $level) { unset($location['parent_id']); $location['children'] = build_tree($location['id'], $level+1); $location['level'] = $level; - $location['href'] = 'locationview.php?location_id=' . $location['id']; + $location['href'] = 'location.php?f=view&id=' . $location['id']; $children[] = $location; } } @@ -166,7 +199,7 @@ elseif ($action == ACT_VIEW): // base location $sql = "SELECT location_id AS id, location_name AS name, location_parent AS parent_id, location_info AS info, - CONCAT('locationview.php?location_id=', location_id) AS url + CONCAT('location.php?f=view&id=', location_id) AS url FROM location WHERE location_id=?"; $sth = $dbh->prepare($sql); @@ -178,7 +211,7 @@ $smarty->assign("location", $location); $crumbs[] = $location; $sql = "SELECT location_id AS id, location_name AS name, location_parent AS parent_id, - CONCAT('locationview.php?location_id=', location_id) AS url + CONCAT('location.php?f=view&id=', location_id) AS url FROM location WHERE location_id=?"; $sth = $dbh->prepare($sql); @@ -243,7 +276,7 @@ $location_counter = count($locations); $smarty->assign("location_counter", $location_counter); -// any loactions? +// any locations? if ($location_counter>0) { foreach($locations AS $location) { $location_names[$location['location_id']] = $location['location_name']; @@ -259,6 +292,59 @@ $smarty->assign("location_parent", $location_parent); $smarty->display("locationedit.tpl"); +elseif ($action == ACT_SUBNET_EDIT): +// ========== VARIANT: location to subnet ===================================== + +$sql = "SELECT location_id AS id, location_name AS name + FROM location + WHERE location_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("location", $sth->fetch(PDO::FETCH_OBJ)); + +$smarty->display("locationsubnetedit.tpl"); + +elseif ($action == ACT_SUBNET_ADD): +// ========== VARIANT: add location to subnet ================================= + +$sql = "SELECT location_id AS id, location_name AS name + FROM location + WHERE location_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("location", $sth->fetch(PDO::FETCH_OBJ)); + +// TODO Filter für bereits zugeordnete Subnetze +$smarty->assign("subnet_options", db_get_options_subnet()); + +$smarty->display("locationsubnetadd.tpl"); + +elseif ($action == ACT_SUBNET_DEL): +// ========== VARIANT: del location to subnet ================================= + +// location +$sql = "SELECT location_id AS id, location_name AS name + FROM location + WHERE location_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("location", $sth->fetch(PDO::FETCH_OBJ)); + +// subnet +$sql = "SELECT s.subnet_id, CONCAT_WS('/', s.subnet_address, s.subnet_mask) + FROM subnetlocation AS l LEFT JOIN subnet AS s USING (subnet_id) + WHERE l.location_id=? + ORDER BY INET_ATON(s.subnet_address)"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$options = array(); +foreach ($sth->fetchAll(PDO::FETCH_NUM) as $rec) { + $options[$rec[0]] = $rec[1]; +} +$smarty->assign("subnet_options", $options); + +$smarty->display("locationsubnetdel.tpl"); + elseif ($action == ACT_DELETE): // ========== VARIANT: delete record ========================================== diff --git a/locationadd.php b/locationadd.php deleted file mode 100644 index db5c8ba..0000000 --- a/locationadd.php +++ /dev/null @@ -1,75 +0,0 @@ -{$lang_option_none} - -$sql = "SELECT location_id AS id, location_name AS name, - location_parent AS parent, location_sort AS sort - FROM location - ORDER BY location_parent, location_sort, location_name"; -$sth = $dbh->query($sql); -$locations = $sth->fetchAll(); - -if (count($locations) > 0) { - foreach ($locations AS $location) { - $location_names[$location['id']] = $location['name']; - $parents[$location['parent']][] = $location['id']; - } -} - -// look for parents -// function to look for parents and create a new array for every child -function location($parents, $parent = 0) { - foreach ($parents[$parent] as $child) { - if (isset($parents[$child])) { - // element has children - $children[$child] = location($parents, $child); - } else { - // no children, set NULL - $children[$child] = NULL; - } - } - return $children; -} - -// recursive children check to template -function checkchildren($locations, $level) { - global $location_options; - global $location_names; - global $location_parent; - - foreach ($locations as $parent=>$child) { - $row = str_repeat("-  ", $level) . $location_names[$parent]; - $location_options[$parent] = $row; - if (isset($child)) { - checkchildren($child, $level+1); - } - } -} - -$tree = location($parents); - -// create tree option list -$location_options = array(0 => '-'); -checkchildren($tree, 0); - -$smarty->assign("location_options", $location_options); -$smarty->assign("location_parent", $location_parent); - -$smarty->display("locationadd.tpl"); - -include("footer.php"); -?> diff --git a/locationdel.php b/locationdel.php deleted file mode 100644 index bebea1e..0000000 --- a/locationdel.php +++ /dev/null @@ -1,24 +0,0 @@ -prepare($sql); -$sth->execute([$location_id]); -$smarty->assign("location", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->display("locationdel.tpl"); - -include("footer.php"); -?> diff --git a/locationedit.php b/locationedit.php deleted file mode 100644 index a9cc492..0000000 --- a/locationedit.php +++ /dev/null @@ -1,98 +0,0 @@ -prepare($sql); -$sth->execute([$location_id]); -$location = $sth->fetch(PDO::FETCH_OBJ); - -$location_parent = $location->parent; - -$smarty->assign("location", $location); - -/*$smarty->assign("location_id", $location_id); -$smarty->assign("location_name", $location[0]['location_name']); -$smarty->assign("location_info", $location[0]['location_info']); -$smarty->assign("location_sort", $location[0]['location_sort']); */ - -// parent location -$sql = "SELECT location_id, location_name, location_parent - FROM location - WHERE location_id != ? - ORDER BY location_name"; -$sth = $dbh->prepare($sql); -$sth->execute([$location_id]); - -$locations = $sth->fetchAll(); - -$location_counter = count($locations); - -$smarty->assign("location_counter", $location_counter); - -// any loactions? -if ($location_counter>0) { - foreach($locations AS $location) { - $location_names[$location['location_id']] = $location['location_name']; - $parents[$location['location_parent']][] = $location['location_id']; - } -} - -// look for parents -// function to look for parents and create a new array for every child -function location($parents, $parent = 0) { - // loop array to check - foreach($parents[$parent] as $child) { - if(isset($parents[$child])) { - // element has children - $children[$child] = location($parents, $child); - } else { - // no children, set NULL - $children[$child] = NULL; - } - } - - // and again... - return $children; -} - -// recursive children check to template -function checkchildren($locations, $level) { - global $location_options; - global $location_names; - global $location_parent; - - foreach ($locations as $parent=>$child) { - $row = str_repeat("-  ", $level) . $location_names[$parent]; - $location_options[$parent] = $row; - if(isset($child)) { - checkchildren($child, $level+1); - } - } -} - -$tree = location($parents); -$location_options = array(0 => '-'); -checkchildren($tree, 0); -$smarty->assign("location_options", $location_options); -$smarty->assign("location_parent", $location_parent); - -$smarty->display("locationedit.tpl"); - -include("footer.php"); -?> diff --git a/locationsubnetadd.php b/locationsubnetadd.php deleted file mode 100644 index 8e91434..0000000 --- a/locationsubnetadd.php +++ /dev/null @@ -1,28 +0,0 @@ -prepare($sql); -$sth->execute([$location_id]); -$smarty->assign("location", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->assign("subnet_options", db_get_options_subnet()); - -$smarty->display("locationsubnetadd.tpl"); - -include("footer.php"); -?> diff --git a/locationsubnetdel.php b/locationsubnetdel.php deleted file mode 100644 index 4d7eb02..0000000 --- a/locationsubnetdel.php +++ /dev/null @@ -1,44 +0,0 @@ -prepare($sql); -$sth->execute([$location_id]); -$smarty->assign("location", $sth->fetch(PDO::FETCH_OBJ)); - - -// subnet -$sql = "SELECT - s.subnet_id, - s.subnet_address, - s.subnet_mask - FROM - subnetlocation AS l LEFT JOIN subnet AS s USING (subnet_id) - WHERE - l.location_id=? - ORDER BY - INET_ATON(s.subnet_address)"; -$sth = $dbh->prepare($sql); -$sth->execute([$location_id]); - -$smarty->assign($sth->fetchAll()); - -$smarty->display("locationsubnetdel.tpl"); - -include("footer.php"); -?> diff --git a/locationsubnetedit.php b/locationsubnetedit.php deleted file mode 100644 index 213592e..0000000 --- a/locationsubnetedit.php +++ /dev/null @@ -1,26 +0,0 @@ -prepare($sql); -$sth->execute([$location_id]); -$smarty->assign("location", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->display("locationsubnetedit.tpl"); - -include("footer.php"); -?> diff --git a/locationview.php b/locationview.php deleted file mode 100644 index 50b1fad..0000000 --- a/locationview.php +++ /dev/null @@ -1,67 +0,0 @@ -prepare($sql); -$sth->execute([$location_id]); -$location = $sth->fetch(PDO::FETCH_OBJ); -$smarty->assign("location", $location); - -// crumbs -$crumbs[] = $location; -$sql = "SELECT location_id AS id, location_name AS name, - location_parent AS parent_id, - CONCAT('locationview.php?location_id=', location_id) AS url - FROM location - WHERE location_id=?"; -$sth = $dbh->prepare($sql); -while ($crumbs[0]->parent_id != 0) { - $sth->execute([$crumbs[0]->parent_id]); - $result = $sth->fetch(PDO::FETCH_OBJ); - array_unshift($crumbs, $result); -} -$smarty->assign("crumbs", $crumbs); - -// sublocations -$sql = "SELECT location_id AS sublocation_id, location_name AS sublocation_name, - LEFT(location_info, 40) AS info_short, - CHAR_LENGTH(location_info) AS info_length - FROM location - WHERE location_parent=? - ORDER BY location_name"; -$sth = $dbh->prepare($sql); -$sth->execute([$location_id]); -$smarty->assign("sublocations", $sth->fetchAll()); - -// subnets -$sql = "SELECT s.subnet_id, s.subnet_address, s.subnet_mask - FROM subnet AS s LEFT JOIN subnetlocation AS l USING (subnet_id) - WHERE l.location_id=? - ORDER BY INET_ATON(s.subnet_address)"; -$sth = $dbh->prepare($sql); -$sth->execute([$location_id]); -$smarty->assign("subnets", $sth->fetchAll()); - -$smarty->display("locationview.tpl"); - -include("footer.php"); -?> diff --git a/nat.php b/nat.php index b9d8c26..61138e1 100644 --- a/nat.php +++ b/nat.php @@ -8,7 +8,50 @@ SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ include("includes.php"); - + +if (isset($_REQUEST['id'])) { + $id = (int) $_REQUEST['id'] or $id = 0; +} + +// ========== ACTIONS START =================================================== +switch ($submit = form_get_action()) { + + case NULL: break; + + case 'add': $action = ACT_ADD; break; + case 'view': $action = ACT_VIEW; break; + case 'edit': $action = ACT_EDIT; break; + case 'del': $action = ACT_DELETE; break; + + case 'insert': + $node_id_ext = sanitize($_POST['node_id_ext']); + $node_id_int = sanitize($_POST['node_id_int']); + $nat_type = sanitize($_POST['nat_type']); + + $sql = "INSERT INTO nat (nat_ext, nat_int, nat_type) + VALUE (?, ?, ?)"; + $sth = $dbh->prepare($sql); + $sth->execute([$node_id_ext, $node_id_int, $nat_type]); + + header_location("node.php?f=view&id=$node_id_ext"); + break; + + case 'delete': + $node_id_ext = sanitize($_POST['node_id_ext']); + $sth = $dbh->prepare("DELETE FROM nat WHERE nat_id=?"); + $sth->execute([$id]); + // TODO + // header_location("node.php?f=view&id=" . $node_id_ext); + $action = ACT_DEFAULT; + break; + + default: + $g_error->Add(submit_error($submit)); + $valid = FALSE; +} + +// ========== ACTIONS END ===================================================== + include("header.php"); $sql = "SELECT n.nat_id AS id, n.nat_type, n.nat_ext, n.nat_int, @@ -24,5 +67,121 @@ $smarty->assign("nats", $sth->fetchAll()); $smarty->display("nat.tpl"); -include("footer.php"); +if ($action == ACT_DEFAULT): +// ========== VARIANT: default behavior ======================================= + + +elseif ($action == ACT_ADD): +// ========== VARIANT: add record ============================================= + +$node_id = sanitize($_GET['node_id']); + +// node_ext +$sql = "SELECT node_ip AS node_ip_ext + FROM node + WHERE node_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$node_id]); + +$node = $sth->fetch(PDO::FETCH_OBJ); + +$smarty->assign("node_id_ext", $node_id); +$smarty->assign("node_ip_ext", $node->node_ip_ext); + +// node_int +$sql = "SELECT + a.asset_name, + n.node_id AS node_id_int, + n.node_ip AS node_ip_int + FROM + asset AS a LEFT JOIN node AS n USING (asset_id) + WHERE + n.node_id NOT IN ( + SELECT + nat_int + FROM + nat + WHERE + nat_ext=? + ) + AND n.node_id!=? + ORDER BY + INET_ATON(n.node_ip)"; +$sth = $dbh->prepare($sql); +$sth->execute([$node_id, $node_id]); + +$nodes = $sth->fetchAll(); + +foreach ($nodes as $rec) { + $node_options[$rec['node_id_int']] = $rec['node_ip_int'] . '/' . $rec['asset_name']; +} +$smarty->assign("node_options", $node_options); + +$nat_type_options[1] = $lang['lang_nat_type_1']; +$nat_type_options[2] = $lang['lang_nat_type_2']; +$nat_type_options[3] = $lang['lang_nat_type_3']; +$smarty->assign("nat_type_options", $nat_type_options); + +$smarty->display("natadd.tpl"); + +elseif ($action == ACT_VIEW): +// ========== VARIANT: view single record ===================================== + +$sql = "SELECT nat_id AS id, nat_type AS type, nat_ext, nat_int FROM nat WHERE nat_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("nat", $sth->fetch(PDO::FETCH_OBJ)); + +$smarty->display("natview.tpl"); + +elseif ($action == ACT_EDIT): +// ========== VARIANT: edit single record ===================================== + +$node_id = sanitize($_GET['node_id']); + +$sql = "SELECT node_id AS id, node_ip AS ip FROM node WHERE node.node_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$node_id]); +$smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ)); + +$smarty->display("natedit.tpl"); + +elseif ($action == ACT_DELETE): +// ========== VARIANT: delete record ========================================== + +$node_id = sanitize($_GET['node_id']); + +// node_ext +$sth = $dbh->prepare("SELECT node_id AS id_ext, node_ip AS ip_ext FROM node WHERE node_id=?"); +$sth->execute([$node_id]); +$smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ)); + +// options +$sql = "SELECT x.nat_id, n.node_ip, a.asset_name + FROM nat AS x + LEFT JOIN node AS n ON (x.nat_int=n.node_id) + LEFT JOIN asset AS a USING (asset_id) + WHERE x.nat_ext=? + ORDER BY INET_ATON(n.node_ip)"; +$sth = $dbh->prepare($sql); +$sth->execute([$node_id]); +$nats = $sth->fetchAll(); + +$options = array(); +foreach ($nats as $rec) { + $options[$rec['nat_id']] = $rec['node_ip'] . '/' . $rec['asset_name']; +} +$smarty->assign("nat_options", $options); + +$smarty->display("natdel.tpl"); + +else: +// ========== ERROR UNKNOWN VARIANT =========================================== + +echo "

Unknown function call: Please report to system development!

\n"; + +endif; // $action == ... +// ========== END OF VARIANTS ================================================= + +$smarty->display('footer.tpl'); ?> diff --git a/natadd.php b/natadd.php deleted file mode 100644 index 02f480e..0000000 --- a/natadd.php +++ /dev/null @@ -1,65 +0,0 @@ -prepare($sql); -$sth->execute([$node_id]); - -$node = $sth->fetch(PDO::FETCH_OBJ); - -$smarty->assign("node_id_ext", $node_id); -$smarty->assign("node_ip_ext", $node->node_ip_ext); - -// node_int -$sql = "SELECT - a.asset_name, - n.node_id AS node_id_int, - n.node_ip AS node_ip_int - FROM - asset AS a LEFT JOIN node AS n USING (asset_id) - WHERE - n.node_id NOT IN ( - SELECT - nat_int - FROM - nat - WHERE - nat_ext=? - ) - AND n.node_id!=? - ORDER BY - INET_ATON(n.node_ip)"; -$sth = $dbh->prepare($sql); -$sth->execute([$node_id, $node_id]); - -$nodes = $sth->fetchAll(); - -foreach ($nodes as $rec) { - $node_options[$rec['node_id_int']] = $rec['node_ip_int'] . '/' . $rec['asset_name']; -} -$smarty->assign("node_options", $node_options); - -$nat_type_options[1] = $lang['lang_nat_type_1']; -$nat_type_options[2] = $lang['lang_nat_type_2']; -$nat_type_options[3] = $lang['lang_nat_type_3']; -$smarty->assign("nat_type_options", $nat_type_options); - -$smarty->display("natadd.tpl"); - -include("footer.php"); -?> diff --git a/natdel.php b/natdel.php deleted file mode 100644 index 96a8f80..0000000 --- a/natdel.php +++ /dev/null @@ -1,40 +0,0 @@ -prepare("SELECT node_id AS id_ext, node_ip AS ip_ext FROM node WHERE node_id=?"); -$sth->execute([$node_id]); -$smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ)); - -// options -$sql = "SELECT x.nat_id, n.node_ip, a.asset_name - FROM nat AS x - LEFT JOIN node AS n ON (x.nat_int=n.node_id) - LEFT JOIN asset AS a USING (asset_id) - WHERE x.nat_ext=? - ORDER BY INET_ATON(n.node_ip)"; -$sth = $dbh->prepare($sql); -$sth->execute([$node_id]); -$nats = $sth->fetchAll(); - -$options = array(); -foreach ($nats as $rec) { - $options[$rec['nat_id']] = $rec['node_ip'] . '/' . $rec['asset_name']; -} -$smarty->assign("nat_options", $options); -$smarty->display("natdel.tpl"); - -include("footer.php"); -?> diff --git a/natedit.php b/natedit.php deleted file mode 100644 index 63c46b6..0000000 --- a/natedit.php +++ /dev/null @@ -1,24 +0,0 @@ -prepare($sql); -$sth->execute([$node_id]); -$smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->display("natedit.tpl"); - -include("footer.php"); -?> diff --git a/node.php b/node.php index 196b7ce..b7eb48e 100644 --- a/node.php +++ b/node.php @@ -8,8 +8,115 @@ SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ include("includes.php"); + +if (isset($_REQUEST['id'])) { + $id = (int) $_REQUEST['id'] or $id = 0; +} + +// ========== ACTIONS START =================================================== +switch ($submit = form_get_action()) { + + case NULL: break; + + case 'add': $action = ACT_ADD; break; + case 'link': $action = ACT_LINK; break; + case 'view': $action = ACT_VIEW; break; + case 'edit': $action = ACT_EDIT; break; + case 'del': $action = ACT_DELETE; break; + + case 'insert': + // node with asset or link node to asset + + $asset_name = sanitize($_POST['asset_name']); + $asset_hostname = sanitize($_POST['asset_hostname']); + $assetclass_id = sanitize($_POST['assetclass_id']); + $ip = sanitize($_POST['node_ip']); + $mac = strip_mac(sanitize($_POST['node_mac'])); + if ((!empty($_POST['node_dns1']) && isset($_POST['dns1suffix'])) ? $dns1 = sanitize($_POST['node_dns1']) . $config_dns1suffix : $dns1 = sanitize($_POST['node_dns1'])); + if ((!empty($_POST['node_dns2']) && isset($_POST['dns2suffix'])) ? $dns2 = sanitize($_POST['node_dns2']) . $config_dns2suffix : $dns2 = sanitize($_POST['node_dns2'])); + $node_info = sanitize($_POST['node_info']); + $subnet_id = $_POST['subnet_id']; + + $sql = "INSERT INTO asset (asset_name, asset_hostname, assetclass_id) + VALUE (?, ?, ?)"; + $sth = $dbh->prepare($sql); + $sth->execute([$asset_name, $asset_hostname, $assetclass_id]); + $asset_id = $dbh->lastInsertId(); + + $sql = "INSERT INTO node ( + node_ip, node_mac, node_dns1, node_dns2, node_info, + subnet_id, asset_id + ) + VALUES (?, ?, ?, ?, ?, ?, ?)"; + $sth = $dbh->prepare($sql); + $sth->execute([$ip, $mac, $dns1, $dns2, $node_info, $subnet_id, $asset_id]); + + $action = ACT_VIEW; + break; + + case 'exec-link': + $node_ip = sanitize($_POST['node_ip']); + $subnet_id = sanitize($_POST['subnet_id']); + $asset_id = sanitize($_POST['asset_id']); + $node_mac = strip_mac(sanitize($_POST['node_mac'])); + if ((!empty($_POST['node_dns1']) && isset($_POST['node_dns1suffix'])) ? $node_dns1 = sanitize($_POST['node_dns1']) . $config_dns1suffix : $node_dns1 = sanitize($_POST['node_dns1'])); + if ((!empty($_POST['node_dns2']) && isset($_POST['node_dns2suffix'])) ? $node_dns2 = sanitize($_POST['node_dns2']) . $config_dns2suffix : $node_dns2 = sanitize($_POST['node_dns2'])); + $node_info = $_POST['node_info']; + $sql = "INSERT INTO node ( + node_ip, node_mac, node_dns1, node_dns2, node_info, + subnet_id, asset_id + ) + VALUES (?, ?, ?, ?, ?, ?, ?)"; + $sth = $dbh->prepare($sql); + $sth->execute([$node_ip, $node_mac, $node_dns1, $node_dns2, $node_info, + $subnet_id, $asset_id]); + $id = $dbh->lastInsertId(); + $action = ACT_VIEW; + break; + + case 'update': + $asset_id = sanitize($_POST['asset_id']); + $node_ip = sanitize($_POST['node_ip']); + $subnet_id = sanitize($_POST['subnet_id']); + $node_mac = strip_mac(sanitize($_POST['node_mac'])); + $node_dns1 = sanitize($_POST['node_dns1']); + $node_dns2 = sanitize($_POST['node_dns2']); + $node_info = sanitize($_POST['node_info']); + $zone_id = sanitize($_POST['zone_id']); + + $sql = "UPDATE node SET + asset_id=?, node_ip=?, subnet_id=?, node_mac=?, + node_dns1=?, node_dns2=?, node_info=?, zone_id=? + 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, + $id]); + $action = ACT_VIEW; + break; + + case 'delete': + $sth = $dbh->prepare("SELECT node_ip FROM node WHERE node_id=?"); + $sth->execute([$id]); + $node_ip = $sth->fetchColumn(); + $sth = $dbh->prepare("DELETE FROM node WHERE node_id=?"); + $sth->execute([$id]); + $action = ACT_DEFAULT; + $g_message->Add(sprintf(_('Node %s deleted'), $node_ip)); + break; + + default: + $g_error->Add(submit_error($submit)); + $valid = FALSE; +} + +// ========== ACTIONS END ===================================================== + include("header.php"); +if ($action == ACT_DEFAULT): +// ========== VARIANT: default behavior ======================================= + // filter preparation $p = array(); $w = array(); @@ -38,8 +145,10 @@ $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, - CONCAT(LEFT(n.node_info,30), IF(CHAR_LENGTH(n.node_info)>30,'...','')) AS node_info - FROM node AS n LEFT JOIN asset AS a USING (asset_id)"; + 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; } @@ -50,5 +159,136 @@ $smarty->assign("nodes", $sth->fetchAll()); $smarty->display("node.tpl"); -include("footer.php"); +elseif ($action == ACT_ADD): +// ========== VARIANT: add record ============================================= + +// add node and asset + +if ((isset($_GET['node_ip'])) ? $node_ip = sanitize($_GET['node_ip']) : $node_ip = ''); +if ((isset($_GET['subnet_id'])) ? $subnet_id = sanitize($_GET['subnet_id']) : $subnet_id = ''); + +$smarty->assign("user_dns1suffix", $_SESSION['suser_dns1suffix']); +$smarty->assign("user_dns2suffix", $_SESSION['suser_dns2suffix']); +$smarty->assign("node_ip", $node_ip); +$smarty->assign("subnet_id", $subnet_id); + +$smarty->assign("subnet_options", db_get_options_subnet()); +$smarty->assign("assetclass_options", db_get_options_assetclass()); + +$smarty->display("nodeadd.tpl"); + +elseif ($action == ACT_LINK): +// ========== VARIANT: add node with existing asset =========================== + +// addnodetoasset +// same as node add but with existing object +$asset_id = sanitize($_REQUEST['asset_id']); +$node_ip = sanitize($_REQUEST['node_ip']); +$subnet_id = sanitize($_REQUEST['subnet_id']); + +$smarty->assign("node_ip", $node_ip); +$smarty->assign("asset_id", $asset_id); +$smarty->assign("subnet_id", $subnet_id); + +$smarty->assign("asset_options", db_get_options_asset()); +$smarty->assign("subnet_options", db_get_options_subnet()); + +$smarty->display("assignnodetoasset.tpl"); + +elseif ($action == ACT_VIEW): +// ========== VARIANT: view single record ===================================== + +// 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, + a.asset_id, a.asset_name, + c.assetclass_id, c.assetclass_name, + s.subnet_id, s.subnet_address, s.subnet_mask, + z.zone_origin + FROM node AS n LEFT JOIN asset AS a USING (asset_id) + LEFT JOIN assetclass AS c USING (assetclass_id) + LEFT JOIN subnet AS s USING (subnet_id) + LEFT JOIN zone AS z USING (zone_id) + WHERE n.node_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); + +$node = $sth->fetch(PDO::FETCH_OBJ); +$node->mac = write_mac($node->mac); +$smarty->assign("node", $node); + +// nat +$sql = "SELECT + asset_ext.asset_id AS asset_id_ext, + asset_int.asset_id AS asset_id_int, + asset_ext.asset_name AS asset_name_ext, + asset_int.asset_name AS asset_name_int, + nat.nat_id AS nat_id, + nat.nat_type AS nat_type, + nat.nat_ext AS nat_ext, + nat.nat_int AS nat_int, + node_ext.node_ip AS node_ip_ext, + node_int.node_ip AS node_ip_int, + node_int.node_id AS node_id_int, + node_ext.node_id AS node_id_ext + FROM + asset AS asset_ext, + asset AS asset_int, + nat, + node AS node_ext, + node AS node_int + WHERE + (nat.nat_ext=:node_id OR nat.nat_int=:node_id) + AND node_ext.node_id=nat.nat_ext + AND node_int.node_id=nat.nat_int + AND asset_ext.asset_id=node_ext.asset_id + AND asset_int.asset_id=node_int.asset_id + ORDER BY + INET_ATON(node_ext.node_ip), + INET_ATON(node_int.node_ip)"; + +$sth = $dbh->prepare($sql); +$sth->execute(['node_id' => $id]); +$smarty->assign("natrules", $sth->fetchAll()); + +$smarty->display("nodeview.tpl"); + +elseif ($action == ACT_EDIT): +// ========== VARIANT: edit single record ===================================== + +$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 + FROM node + WHERE node_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ)); + +$smarty->assign("asset_options", db_get_options_asset()); +$smarty->assign("subnet_options", db_get_options_subnet()); +$smarty->assign("zone_options", db_get_options_zone('(keine)')); + +$smarty->display("nodeedit.tpl"); + +elseif ($action == ACT_DELETE): +// ========== VARIANT: delete record ========================================== + +$sql = "SELECT node_id AS id, node_ip AS ip, asset_id FROM node WHERE node_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ)); + +$smarty->display("nodedel.tpl"); + +else: +// ========== ERROR UNKNOWN VARIANT =========================================== + +echo "

Unknown function call: Please report to system development!

\n"; + +endif; // $action == ... +// ========== END OF VARIANTS ================================================= + +$smarty->display('footer.tpl'); ?> diff --git a/nodeadd.php b/nodeadd.php deleted file mode 100644 index 2822677..0000000 --- a/nodeadd.php +++ /dev/null @@ -1,27 +0,0 @@ -assign("user_dns1suffix", $_SESSION['suser_dns1suffix']); -$smarty->assign("user_dns2suffix", $_SESSION['suser_dns2suffix']); -$smarty->assign("node_ip", $node_ip); -$smarty->assign("subnet_id", $subnet_id); - -$smarty->assign("subnet_options", db_get_options_subnet()); -$smarty->assign("assetclass_options", db_get_options_assetclass()); -$smarty->display("nodeadd.tpl"); - -include("footer.php"); -?> diff --git a/nodedel.php b/nodedel.php deleted file mode 100644 index 5a750ab..0000000 --- a/nodedel.php +++ /dev/null @@ -1,24 +0,0 @@ -prepare($sql); -$sth->execute([$node_id]); -$smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->display("nodedel.tpl"); - -include("footer.php"); -?> diff --git a/nodeedit.php b/nodeedit.php deleted file mode 100644 index c0ff61f..0000000 --- a/nodeedit.php +++ /dev/null @@ -1,32 +0,0 @@ -prepare($sql); -$sth->execute([$node_id]); -$smarty->assign("node", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->assign("asset_options", db_get_options_asset()); -$smarty->assign("subnet_options", db_get_options_subnet()); -$smarty->assign("zone_options", db_get_options_zone('(keine)')); - -$smarty->display("nodeedit.tpl"); - -include("footer.php"); -?> diff --git a/nodeview.php b/nodeview.php deleted file mode 100644 index e240124..0000000 --- a/nodeview.php +++ /dev/null @@ -1,89 +0,0 @@ -prepare($sql); -$sth->execute([$node_id]); - -$node = $sth->fetch(PDO::FETCH_OBJ); -$node->mac = write_mac($node->mac); -$smarty->assign("node", $node); - -// nat -$sql = "SELECT - asset_ext.asset_id AS asset_id_ext, - asset_int.asset_id AS asset_id_int, - asset_ext.asset_name AS asset_name_ext, - asset_int.asset_name AS asset_name_int, - nat.nat_id AS nat_id, - nat.nat_type AS nat_type, - nat.nat_ext AS nat_ext, - nat.nat_int AS nat_int, - node_ext.node_ip AS node_ip_ext, - node_int.node_ip AS node_ip_int, - node_int.node_id AS node_id_int, - node_ext.node_id AS node_id_ext - FROM - asset AS asset_ext, - asset AS asset_int, - nat, - node AS node_ext, - node AS node_int - WHERE - (nat.nat_ext=:node_id OR nat.nat_int=:node_id) - AND node_ext.node_id=nat.nat_ext - AND node_int.node_id=nat.nat_int - AND asset_ext.asset_id=node_ext.asset_id - AND asset_int.asset_id=node_int.asset_id - ORDER BY - INET_ATON(node_ext.node_ip), - INET_ATON(node_int.node_ip)"; - -$sth = $dbh->prepare($sql); -$sth->execute(['node_id' => $node_id]); - -$smarty->assign("natrules", $sth->fetchAll()); - -$smarty->display("nodeview.tpl"); - -include("footer.php"); -?> diff --git a/options.php b/options.php index 769e22c..d8501b0 100644 --- a/options.php +++ b/options.php @@ -8,8 +8,119 @@ SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ include("includes.php"); + +// ========== ACTIONS START =================================================== +switch ($submit = form_get_action()) { + + case NULL: break; + + case 'edit': $action = ACT_EDIT; break; + case 'pass': $action = ACT_PASSWORD; break; + + case 'update': + $id = $_SESSION['suser_id']; + $language = $_POST['user_language']; + $imagesize = sanitize($_POST['user_imagesize']); + $imagecount = sanitize($_POST['user_imagecount']); + $mac = sanitize($_POST['user_mac']); + $dateformat = sanitize($_POST['user_dateformat']); + $dns1suffix = sanitize($_POST['user_dns1suffix']); + $dns2suffix = sanitize($_POST['user_dns2suffix']); + $tooltips = sanitize($_POST['user_tooltips']); + + $menu_assets = sanitize($_POST['user_menu_assets']); + $menu_assetclasses = sanitize($_POST['user_menu_assetclasses']); + $menu_assetclassgroups = sanitize($_POST['user_menu_assetclassgroups']); + $menu_cables = sanitize($_POST['user_menu_cables']); + $menu_locations = sanitize($_POST['user_menu_locations']); + $menu_nodes = sanitize($_POST['user_menu_nodes']); + $menu_subnets = sanitize($_POST['user_menu_subnets']); + $menu_vlans = sanitize($_POST['user_menu_vlans']); + $menu_zones = sanitize($_POST['user_menu_zones']); + + // construct menu set + $menu = array(); + if ($menu_assets) $menu[] = 'asset'; + if ($menu_assetclasses) $menu[] = 'class'; + if ($menu_assetclassgroups) $menu[] = 'group'; + if ($menu_cables) $menu[] = 'cable'; + if ($menu_locations) $menu[] = 'location'; + if ($menu_nodes) $menu[] = 'node'; + if ($menu_subnets) $menu[] = 'subnet'; + if ($menu_vlans) $menu[] = 'vlan'; + if ($menu_zones) $menu[] = 'zone'; + + $sql = "UPDATE user SET + user_language=?, user_imagesize=?, user_imagecount=?, + user_mac=?, user_dateformat=?, user_dns1suffix=?, + user_dns2suffix=?, user_tooltips=?, user_menu=? + WHERE + user_id=?"; + $sth = $dbh->prepare($sql); + $sth->execute([$language, $imagesize, $imagecount, + $mac, $dateformat, $dns1suffix, + $dns2suffix, $tooltips, implode(',', $menu), + $id]); + + $_SESSION['suser_language'] = $language; + $_SESSION['suser_imagesize'] = $imagesize; + $_SESSION['suser_imagecount'] = $imagecount; + $_SESSION['suser_mac'] = $mac; + $_SESSION['suser_dateformat'] = $dateformat; + $_SESSION['suser_dns1suffix'] = $dns1suffix; + $_SESSION['suser_dns2suffix'] = $dns2suffix; + $_SESSION['suser_menu_assets'] = $menu_assets; + $_SESSION['suser_menu_assetclasses'] = $menu_assetclasses; + $_SESSION['suser_menu_assetclassgroups'] = $menu_assetclassgroups; + $_SESSION['suser_menu_cables'] = $menu_cables; + $_SESSION['suser_menu_locations'] = $menu_locations; + $_SESSION['suser_menu_nodes'] = $menu_nodes; + $_SESSION['suser_menu_subnets'] = $menu_subnets; + $_SESSION['suser_menu_vlans'] = $menu_vlans; + $_SESSION['suser_menu_zones'] = $menu_zones; + $_SESSION['suser_tooltips'] = $tooltips; + + $action = ACT_DEFAULT; + break; + + case 'exec-pass': + $user_id = $_SESSION['suser_id']; + $currentpass = sanitize($_POST['user_currentpass']); + $newpass1 = sanitize($_POST['user_newpass1']); + $newpass2 = sanitize($_POST['user_newpass2']); + $sth = $dbh->prepare("SELECT user_pass FROM user WHERE user_id=?"); + $sth->execute([$user_id]); + $userpass = $sth->fetchColumn(); + $action = ACT_PASSWORD; + if (password_verify($currentpass, $userpass)) { + if (strlen($newpass1) >= 5) { + if (!strcmp($newpass1, $newpass2)) { + $sth = $dbh->prepare("UPDATE user SET user_pass=? WHERE user_id=?"); + $newhash = password_hash($newpass1, PASSWORD_BCRYPT); + $sth->execute([$newhash, $user_id]); + $action = ACT_DEFAULT; + } else { + $g_error->Add('New passwords do not match!'); + } + } else { + $g_error->Add('New password is to simple!'); + } + } else { + $g_error->Add('Current password wrong!'); + } + break; + + default: + $g_error->Add(submit_error($submit)); + $valid = FALSE; +} + +// ========== ACTIONS END ===================================================== include("header.php"); +if ($action == ACT_DEFAULT): +// ========== VARIANT: default behavior ======================================= + $smarty->assign('realm', $_SESSION['suser_realm']); $smarty->assign('role_add', $_SESSION['suser_role_add']); $smarty->assign('role_edit', $_SESSION['suser_role_edit']); @@ -18,5 +129,104 @@ $smarty->assign('role_manage', $_SESSION['suser_role_manage']); $smarty->assign('role_admin', $_SESSION['suser_role_admin']); $smarty->display("options.tpl"); -include("footer.php"); +elseif ($action == ACT_EDIT): +// ========== VARIANT: edit display options =================================== + +$smarty->assign("language", $language); + +if($_SESSION['suser_menu_assets']=='on') { + $user_menu_assets_checked = 'checked'; +} else { + $user_menu_assets_checked = ''; +} +// assetclasses +if($_SESSION['suser_menu_assetclasses']=='on') { + $user_menu_assetclasses_checked = 'checked'; +} else { + $user_menu_assetclasses_checked = ''; +} +// assetclassgroups +if($_SESSION['suser_menu_assetclassgroups']=='on') { + $user_menu_assetclassgroups_checked = 'checked'; +} else { + $user_menu_assetclassgroups_checked = ''; +} +// cables +if($_SESSION['suser_menu_cables']=='on') { + $user_menu_cables_checked = 'checked'; +} else { + $user_menu_cables_checked = ''; +} +// locations +if($_SESSION['suser_menu_locations']=='on') { + $user_menu_locations_checked = 'checked'; +} else { + $user_menu_locations_checked = ''; +} +// nodes +if($_SESSION['suser_menu_nodes']=='on') { + $user_menu_nodes_checked = 'checked'; +} else { + $user_menu_nodes_checked = ''; +} +// subnets +if($_SESSION['suser_menu_subnets']=='on') { + $user_menu_subnets_checked = 'checked'; +} else { + $user_menu_subnets_checked = ''; +} +// vlans +if($_SESSION['suser_menu_vlans']=='on') { + $user_menu_vlans_checked = 'checked'; +} else { + $user_menu_vlans_checked = ''; +} +// zones +if($_SESSION['suser_menu_zones']=='on') { + $user_menu_zones_checked = 'checked'; +} else { + $user_menu_zones_checked = ''; +} +// tooltips +if($_SESSION['suser_tooltips']=='on') { + $user_tooltips_checked = 'checked'; +} else { + $user_tooltips_checked = ''; +} + +$smarty->assign("user_id", $_SESSION['suser_id']); +$smarty->assign("user_imagesize", $_SESSION['suser_imagesize']); +$smarty->assign("user_imagecount", $_SESSION['suser_imagecount']); +$smarty->assign("user_mac", $_SESSION['suser_mac']); +$smarty->assign("user_dateformat", $_SESSION['suser_dateformat']); +$smarty->assign("user_dns1suffix", $_SESSION['suser_dns1suffix']); +$smarty->assign("user_dns2suffix", $_SESSION['suser_dns2suffix']); +$smarty->assign("user_language", $_SESSION['suser_language']); +$smarty->assign("user_menu_assets_checked", $user_menu_assets_checked); +$smarty->assign("user_menu_assetclasses_checked", $user_menu_assetclasses_checked); +$smarty->assign("user_menu_assetclassgroups_checked", $user_menu_assetclassgroups_checked); +$smarty->assign("user_menu_cables_checked", $user_menu_cables_checked); +$smarty->assign("user_menu_locations_checked", $user_menu_locations_checked); +$smarty->assign("user_menu_nodes_checked", $user_menu_nodes_checked); +$smarty->assign("user_menu_subnets_checked", $user_menu_subnets_checked); +$smarty->assign("user_menu_vlans_checked", $user_menu_vlans_checked); +$smarty->assign("user_menu_zones_checked", $user_menu_zones_checked); +$smarty->assign("user_tooltips_checked", $user_tooltips_checked); + +$smarty->display("optionseditdisplay.tpl"); + +elseif ($action == ACT_PASSWORD): +// ========== VARIANT: password =============================================== + +$smarty->display("optionseditpassword.tpl"); + +else: +// ========== ERROR UNKNOWN VARIANT =========================================== + +echo "

Unknown function call: Please report to system development!

\n"; + +endif; // $action == ... +// ========== END OF VARIANTS ================================================= + +$smarty->display('footer.tpl'); ?> diff --git a/optionseditdisplay.php b/optionseditdisplay.php deleted file mode 100644 index ae868f9..0000000 --- a/optionseditdisplay.php +++ /dev/null @@ -1,99 +0,0 @@ -assign("language", $language); - - -if($_SESSION['suser_menu_assets']=='on') { - $user_menu_assets_checked = 'checked'; -} else { - $user_menu_assets_checked = ''; -} -// assetclasses -if($_SESSION['suser_menu_assetclasses']=='on') { - $user_menu_assetclasses_checked = 'checked'; -} else { - $user_menu_assetclasses_checked = ''; -} -// assetclassgroups -if($_SESSION['suser_menu_assetclassgroups']=='on') { - $user_menu_assetclassgroups_checked = 'checked'; -} else { - $user_menu_assetclassgroups_checked = ''; -} -// cables -if($_SESSION['suser_menu_cables']=='on') { - $user_menu_cables_checked = 'checked'; -} else { - $user_menu_cables_checked = ''; -} -// locations -if($_SESSION['suser_menu_locations']=='on') { - $user_menu_locations_checked = 'checked'; -} else { - $user_menu_locations_checked = ''; -} -// nodes -if($_SESSION['suser_menu_nodes']=='on') { - $user_menu_nodes_checked = 'checked'; -} else { - $user_menu_nodes_checked = ''; -} -// subnets -if($_SESSION['suser_menu_subnets']=='on') { - $user_menu_subnets_checked = 'checked'; -} else { - $user_menu_subnets_checked = ''; -} -// vlans -if($_SESSION['suser_menu_vlans']=='on') { - $user_menu_vlans_checked = 'checked'; -} else { - $user_menu_vlans_checked = ''; -} -// zones -if($_SESSION['suser_menu_zones']=='on') { - $user_menu_zones_checked = 'checked'; -} else { - $user_menu_zones_checked = ''; -} -// tooltips -if($_SESSION['suser_tooltips']=='on') { - $user_tooltips_checked = 'checked'; -} else { - $user_tooltips_checked = ''; -} - -$smarty->assign("user_id", $_SESSION['suser_id']); -$smarty->assign("user_imagesize", $_SESSION['suser_imagesize']); -$smarty->assign("user_imagecount", $_SESSION['suser_imagecount']); -$smarty->assign("user_mac", $_SESSION['suser_mac']); -$smarty->assign("user_dateformat", $_SESSION['suser_dateformat']); -$smarty->assign("user_dns1suffix", $_SESSION['suser_dns1suffix']); -$smarty->assign("user_dns2suffix", $_SESSION['suser_dns2suffix']); -$smarty->assign("user_language", $_SESSION['suser_language']); -$smarty->assign("user_menu_assets_checked", $user_menu_assets_checked); -$smarty->assign("user_menu_assetclasses_checked", $user_menu_assetclasses_checked); -$smarty->assign("user_menu_assetclassgroups_checked", $user_menu_assetclassgroups_checked); -$smarty->assign("user_menu_cables_checked", $user_menu_cables_checked); -$smarty->assign("user_menu_locations_checked", $user_menu_locations_checked); -$smarty->assign("user_menu_nodes_checked", $user_menu_nodes_checked); -$smarty->assign("user_menu_subnets_checked", $user_menu_subnets_checked); -$smarty->assign("user_menu_vlans_checked", $user_menu_vlans_checked); -$smarty->assign("user_menu_zones_checked", $user_menu_zones_checked); -$smarty->assign("user_tooltips_checked", $user_tooltips_checked); - -$smarty->display("optionseditdisplay.tpl"); - -include("footer.php"); -?> diff --git a/optionseditpassword.php b/optionseditpassword.php deleted file mode 100644 index a949347..0000000 --- a/optionseditpassword.php +++ /dev/null @@ -1,16 +0,0 @@ -display("optionseditpassword.tpl"); - -include("footer.php"); -?> diff --git a/submit.php b/submit.php deleted file mode 100644 index 6b40a08..0000000 --- a/submit.php +++ /dev/null @@ -1,815 +0,0 @@ -prepare($sql); - $sth->execute([$name, $hostname, $assetclass_id, $info, $intf, $asset_type]); - - header_location("assetview.php?asset_id=" . $dbh->lastInsertId()); - break; - - case ("assetclass") : - $name = sanitize($_POST['assetclass_name']); - $description = sanitize($_POST['assetclass_description']); - $group_id = sanitize($_POST['assetclassgroup_id']); - - $sql = "INSERT INTO assetclass - (assetclass_name, assetclass_description, assetclassgroup_id) - VALUE - (?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$name, $description, $group_id]); - - header_location("assetclassview.php?assetclass_id=" . $dbh->lastInsertId()); - break; - - case ("assetclassgroup") : - $name = sanitize($_POST['acg_name']); - $color = preg_replace("|[^a-zA-Z0-9]|", "", strtoupper(sanitize($_POST['acg_color']))); - $desc = sanitize($_POST['acg_description']); - - $sql = "INSERT INTO assetclassgroup - (assetclassgroup_name, assetclassgroup_color, assetclassgroup_description) - VALUE - (?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$name, $color, $desc]); - - header_location("assetclassgroupview.php?assetclassgroup_id=" . $dbh->lastInsertId()); - break; */ - - case ("assignnodetoasset") : - $node_ip = sanitize($_POST['node_ip']); - $subnet_id = sanitize($_POST['subnet_id']); - $asset_id = sanitize($_POST['asset_id']); - $node_mac = strip_mac(sanitize($_POST['node_mac'])); - if ((!empty($_POST['node_dns1']) && isset($_POST['node_dns1suffix'])) ? $node_dns1 = sanitize($_POST['node_dns1']) . $config_dns1suffix : $node_dns1 = sanitize($_POST['node_dns1'])); - if ((!empty($_POST['node_dns2']) && isset($_POST['node_dns2suffix'])) ? $node_dns2 = sanitize($_POST['node_dns2']) . $config_dns2suffix : $node_dns2 = sanitize($_POST['node_dns2'])); - $node_info = $_POST['node_info']; - - $sql = "INSERT INTO node ( - node_ip, - node_mac, - node_dns1, - node_dns2, - subnet_id, - asset_id, - node_info) - VALUE - (?, ?, ?, ?, ?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$node_ip, $node_mac, $node_dns1, $node_dns2, - $subnet_id, $asset_id, $node_info]); - - header_location("nodeview.php?node_id=" . $dbh->lastInsertId()); - break; - - case ("assignlocationtosubnet") : - $location_id = sanitize($_POST['location_id']); - $subnet_id = sanitize($_POST['subnet_id']); - - $sql = "INSERT INTO subnetlocation (location_id, subnet_id) - VALUE (?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$location_id, $subnet_id]); - - header_location("Location: location.php?location_id=" . $dbh->lastInsertId()); - break; - - case ("assignsubnettovlan") : - $subnet_id = sanitize($_POST['subnet_id']); - $vlan_id = sanitize($_POST['vlan_id']); - - $sql = "UPDATE subnet SET vlan_id=? WHERE subnet_id=?"; - $sth = $dbh->prepare($sql); - $sth->execute([$vlan_id, $subnet_id]); - - header_location("subnetview.php?subnet_id=" . $subnet_id); - break; - -/* case ("location") : - $name = sanitize($_POST['location_name']); - $parent = sanitize($_POST['location_parent']); - $info = sanitize($_POST['location_info']); - - $sql = "INSERT INTO location ( - location_name, location_parent, location_info - ) - VALUE (?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$name, $parent, $info]); - - header_location("locationview.php?location_id=" . $dbh->lastInsertId()); - break; */ - - case ("locationsubnet") : - $location_id = sanitize($_POST['location_id']); - $subnet_id = sanitize($_POST['subnet_id']); - - $sql = "INSERT INTO subnetlocation (location_id, subnet_id) - VALUE (?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$location_id, $subnet_id]); - - header_location("locationview.php?location_id=" . $location_id); - break; - - case ("nat") : - $node_id_ext = sanitize($_POST['node_id_ext']); - $node_id_int = sanitize($_POST['node_id_int']); - $nat_type = sanitize($_POST['nat_type']); - - $sql = "INSERT INTO nat (nat_ext, nat_int, nat_type) - VALUE (?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$node_id_ext, $node_id_int, $nat_type]); - - header_location("nodeview.php?node_id=" . $node_id_ext); - break; - - case ("node") : - $asset_name = sanitize($_POST['asset_name']); - $asset_hostname = sanitize($_POST['asset_hostname']); - $assetclass_id = sanitize($_POST['assetclass_id']); - $ip = sanitize($_POST['node_ip']); - $mac = strip_mac(sanitize($_POST['node_mac'])); - if ((!empty($_POST['node_dns1']) && isset($_POST['dns1suffix'])) ? $dns1 = sanitize($_POST['node_dns1']) . $config_dns1suffix : $dns1 = sanitize($_POST['node_dns1'])); - if ((!empty($_POST['node_dns2']) && isset($_POST['dns2suffix'])) ? $dns2 = sanitize($_POST['node_dns2']) . $config_dns2suffix : $dns2 = sanitize($_POST['node_dns2'])); - $node_info = sanitize($_POST['node_info']); - $subnet_id = $_POST['subnet_id']; - - $sql = "INSERT INTO asset (asset_name, asset_hostname, assetclass_id) - VALUE (?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$asset_name, $asset_hostname, $assetclass_id]); - $asset_id = $dbh->lastInsertId(); - - $sql = "INSERT INTO node ( - node_ip, node_mac, node_dns1, node_dns2, node_info, - subnet_id, asset_id - ) - VALUE (?, ?, ?, ?, ?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$ip, $mac, $dns1, $dns2, $node_info, $subnet_id, $asset_id]); - - header_location("nodeview.php?node_id=" . $dbh->lastInsertId()); - break; - - case ("subnet") : - $subnet_address= sanitize($_POST['subnet_address']); - $subnet_mask = sanitize($_POST['subnet_mask']); - $subnet_info = sanitize($_POST['subnet_info']); - - $sql = "INSERT INTO subnet (subnet_address, subnet_mask, subnet_info) - VALUE (?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$subnet_address, $subnet_mask, $subnet_info]); - - header_location("subnetview.php?subnet_id=" . $dbh->lastInsertId()); - break; - - case ("subnetlocation") : - $location_id = sanitize($_POST['location_id']); - $subnet_id = sanitize($_POST['subnet_id']); - - $sql = "INSERT INTO subnetlocation (location_id, subnet_id) - VALUE (?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$location_id, $subnet_id]); - - header_location("subnetview.php?subnet_id=" . $subnet_id); - break; - - case ("subnetvlan") : - $subnet_id = sanitize($_POST['subnet_id']); - $vlan_id = sanitize($_POST['vlan_id']); - - $sql = "INSERT INTO subnetvlan (subnet_id, vlan_id) - VALUE (?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$subnet_id, $vlan_id]); - - header_location("subnetview.php?subnet_id=" . $subnet_id); - break; - -/* case ("user") : - $user_name = strtolower(sanitize($_POST['user_name'])); - $user_displayname = sanitize($_POST['user_displayname']); - $user_password = md5(sanitize($_POST['user_password'])); - - // check if username exists - $sth = $dbh->prepare("SELECT COUNT(*) FROM user WHERE user_name=?"); - $sth->execute([$user_name]); - - if ($sth->fetchColumn() == 0) { - $sql = "INSERT INTO user (user_name, user_displayname, user_pass) - VALUE (?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$user_name, $user_displayname, $user_password]); - - header_location("userview.php?user_id=" . $dbh->lastInsertId()); - break; - } - - $comments = "usernameinuse"; - break; - - case ("vlan") : - $vlan_name = sanitize($_POST['vlan_name']); - $vlan_number = sanitize($_POST['vlan_number']); - $vlan_info = sanitize($_POST['vlan_info']); - $vlan_color = sanitize($_POST['vlan_color']); - - $sql = "INSERT INTO vlan (vlan_name, vlan_number, vlan_color, vlan_info) - VALUE (?, ?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$vlan_name, $vlan_number, $vlan_color, $vlan_info]); - - header_location("vlanview.php?vlan_id=" . $dbh->lastInsertId()); - break; */ - - case ("vlansubnet") : - $subnet_id = sanitize($_POST['subnet_id']); - $vlan_id = sanitize($_POST['vlan_id']); - - $sql = "INSERT INTO subnetvlan (subnet_id, vlan_id) - VALUE (?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$subnet_id, $vlan_id]); - - header_location("vlanview.php?vlan_id=" . $vlan_id); - break; - -/* case ("zone") : - $zone_origin = sanitize($_POST['zone_origin']); - $zone_ttl_default = sanitize($_POST['zone_ttl_default']); - $zone_soa = sanitize($_POST['zone_soa']); - $zone_hostmaster = sanitize($_POST['zone_hostmaster']); - $zone_refresh = sanitize($_POST['zone_refresh']); - $zone_retry = sanitize($_POST['zone_retry']); - $zone_expire = sanitize($_POST['zone_expire']); - $zone_ttl = sanitize($_POST['zone_ttl']); - $zone_serial = sanitize($_POST['zone_serial']); - $zone_ns1 = sanitize($_POST['zone_ns1']); - $zone_ns2 = sanitize($_POST['zone_ns2']); - $zone_ns3 = sanitize($_POST['zone_ns3']); - $zone_mx1 = sanitize($_POST['zone_mx1']); - $zone_mx2 = sanitize($_POST['zone_mx2']); - $zone_info = sanitize($_POST['zone_info']); - - $sql = "INSERT INTO zone ( - zone_origin, zone_ttl_default, zone_soa, zone_hostmaster, - zone_refresh, zone_retry, zone_expire, zone_ttl, zone_serial, - zone_ns1, zone_ns2, zone_ns3, zone_mx1, zone_mx2, zone_info) - VALUE (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - $sth = $dbh->prepare($sql); - $sth->execute([$zone_origin, $zone_ttl_default, $zone_soa, $zone_hostmaster, - $zone_refresh, $zone_retry, $zone_expire, $zone_ttl, $zone_serial, - $zone_ns1, $zone_ns2, $zone_ns3, $zone_mx1, $zone_mx2, $zone_info]); - - header_location("zoneview.php?zone_id=" . $dbh->lastInsertId()); - break; */ - } -} - -if (isset($_POST['del'])) { - switch ($_POST['del']) { -/* - case ("asset") : - $asset_id = sanitize($_POST['asset_id']); - - $sth = $dbh->prepare("DELETE FROM asset WHERE asset_id=?"); - $sth->execute([$asset_id]); - - $sth = $dbh->prepare("DELETE FROM node WHERE asset_id=?"); - $sth->execute([$asset_id]); - - header_location("asset.php"); - break; - - case ("assetclass") : - $assetclass_id = sanitize($_POST['assetclass_id']); - - $sth = $dbh->prepare("DELETE FROM assetclass WHERE assetclass_id=?"); - $sth->execute([$assetclass_id]); - - header_location("assetclass.php"); - break; - - case ("assetclassgroup") : - $assetclassgroup_id = sanitize($_POST['assetclassgroup_id']); - - $sth = $dbh->prepare("DELETE FROM assetclassgroup WHERE assetclassgroup_id=?"); - $sth->execute([$assetclassgroup_id]); - - header_location("assetclassgroup.php"); - break; - - case ("location") : - $location_id = sanitize($_POST['location_id']); - - $sth = $dbh->prepare("DELETE FROM location WHERE location_id=?"); - $sth->execute([$location_id]); - - header_location("location.php"); - break; */ - - case ("locationsubnet") : - $location_id = sanitize($_POST['location_id']); - $subnet_id = sanitize($_POST['subnet_id']); - - $sth = $dbh->prepare("DELETE FROM subnetlocation WHERE location_id=? AND subnet_id=?"); - $sth->execute([$location_id, $subnet_id]); - - header_location("locationview.php?location_id=" . $location_id); - break; - - case ("nat") : - $nat_id = sanitize($_POST['nat_id']); - $node_id_ext = sanitize($_POST['node_id_ext']); - - $sth = $dbh->prepare("DELETE FROM nat WHERE nat_id=?"); - $sth->execute([$nat_id]); - - header_location("nodeview.php?node_id=" . $node_id_ext); - break; - - case ("node") : - $node_id = sanitize($_POST['node_id']); - - $sth = $dbh->prepare("DELETE FROM node WHERE node_id=?"); - $sth->execute([$node_id]); - - header_location("assetview.php?asset_id=" . $asset_id); - break; - - case ("subnet") : - $subnet_id = sanitize($_POST['subnet_id']); - - $sth = $dbh->prepare("DELETE FROM subnet WHERE subnet_id=?"); - $sth->execute([$subnet_id]); - - $sth = $dbh->prepare("DELETE FROM node WHERE subnet_id=?"); - $sth->execute([$subnet_id]); - - header_location("subnet.php"); - break; - - case ("subnetlocation") : - $location_id = sanitize($_POST['location_id']); - $subnet_id = sanitize($_POST['subnet_id']); - - $sth = $dbh->prepare("DELETE FROM subnetlocation WHERE location_id=? AND subnet_id=?"); - $sth->execute([$location_id, $subnet_id]); - - header_location("subnetview.php?subnet_id=" . $subnet_id); - break; - - case ("subnetvlan") : - $subnet_id = sanitize($_POST['subnet_id']); - $vlan_id = sanitize($_POST['vlan_id']); - - $sth = $dbh->prepare("DELETE FROM subnetvlan WHERE subnet_id=? AND vlan_id=?"); - $sth->execute([$subnet_id, $vlan_id]); - - header_location("subnetview.php?subnet_id=" . $subnet_id); - break; - -/* case ("user") : - $user_id = sanitize($_POST['user_id']); - - $sth = $dbh->prepare("DELETE FROM user WHERE user_id=?"); - $sth->execute([$user_id]); - - header_location("user.php"); - break; - - case ("vlan") : - $vlan_id = sanitize($_POST['vlan_id']); - - $sth = $dbh->prepare("DELETE FROM vlan WHERE vlan_id=?"); - $sth->execute([$vlan_id]); - - header_location("vlan.php"); - break; */ - - case ("vlansubnet") : - $subnet_id = sanitize($_POST['subnet_id']); - $vlan_id = sanitize($_POST['vlan_id']); - - $sth = $dbh->prepare("DELETE FROM subnetvlan WHERE subnet_id=? AND vlan_id=?"); - $sth->execute([$subnet_id, $vlan_id]); - - header_location("vlanview.php?vlan_id=" . $vlan_id); - break; - -/* case ("zone") : - $zone_id = sanitize($_POST['zone_id']); - - $sth = $dbh->prepare("DELETE FROM zone WHERE zone_id=?"); - $sth->execute([$zone_id]); - - header_location("zone.php"); - break; */ - } -} - -if (isset($_POST['edit'])) { - switch ($_POST['edit']) { -/* - case ("asset") : - $asset_id = sanitize($_POST['asset_id']); - $asset_name = sanitize($_POST['asset_name']); - $asset_info = sanitize($_POST['asset_info']); - $asset_intf = sanitize($_POST['asset_intf']); - $asset_hostname = sanitize($_POST['asset_hostname']); - $assetclass_id = sanitize($_POST['assetclass_id']); - $asset_type = sanitize($_POST['asset_type']); - - $sql = "UPDATE asset SET - asset_name=?, asset_info=?, asset_hostname=?, - assetclass_id=?, asset_intf=?, asset_type=? - WHERE asset_id=?"; - $sth = $dbh->prepare($sql); - $sth->execute([$asset_name, $asset_info, $asset_hostname, - $assetclass_id, $asset_intf, $asset_type, - $asset_id]); - - header_location("assetview.php?asset_id=" . $asset_id); - - case ("assetclass") : - $id = sanitize($_POST['assetclass_id']); - $name = sanitize($_POST['assetclass_name']); - $description = sanitize($_POST['assetclass_description']); - $group_id = sanitize($_POST['assetclassgroup_id']); - - $sql = "UPDATE assetclass SET - assetclass_name=?, assetclass_description=?, - assetclassgroup_id=? - WHERE assetclass_id=?"; - $sth = $dbh->prepare($sql); - $sth->execute([$name, $description, $group_id, $id]); - - header_location("assetclassview.php?assetclass_id=" . $id); - break; - - case ("assetclassgroup") : - $acg_id = sanitize($_POST['acg_id']); - $acg_name = sanitize($_POST['acg_name']); - $acg_desc = sanitize($_POST['acg_description']); - $acg_color = preg_replace("|[^a-zA-Z0-9]|", "", strtoupper(sanitize($_POST['acg_color']))); - - $sql = "UPDATE assetclassgroup SET - assetclassgroup_name=?, assetclassgroup_color=?, assetclassgroup_description=? - WHERE assetclassgroup_id=?"; - $sth = $dbh->prepare($sql); - $sth->execute([$acg_name, $acg_color, $acg_desc, $acg_id]); - - header_location("assetclassgroupview.php?assetclassgroup_id=" . $acg_id); - break; - - case ("location") : - $location_id = sanitize($_POST['location_id']); - $location_name = sanitize($_POST['location_name']); - $location_info = sanitize($_POST['location_info']); - $parentlocation_id = sanitize($_POST['parentlocation_id']); - - $sql = "UPDATE location SET - location_name=?, location_parent=?, location_info=? - WHERE location_id=?"; - $sth = $dbh->prepare($sql); - $sth->execute([$location_name, $parentlocation_id, $location_info, $location_id]); - - header_location("locationview.php?location_id=" . $location_id); - break; */ - - case ("node") : - $node_id = sanitize($_POST['node_id']); - $asset_id = sanitize($_POST['asset_id']); - $node_ip = sanitize($_POST['node_ip']); - $subnet_id = sanitize($_POST['subnet_id']); - $node_mac = strip_mac(sanitize($_POST['node_mac'])); - $node_dns1 = sanitize($_POST['node_dns1']); - $node_dns2 = sanitize($_POST['node_dns2']); - $node_info = sanitize($_POST['node_info']); - $zone_id = sanitize($_POST['zone_id']); - - $sql = "UPDATE node SET - asset_id=?, node_ip=?, subnet_id=?, node_mac=?, - node_dns1=?, node_dns2=?, node_info=?, zone_id=? - 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, - $node_id]); - - header_location("nodeview.php?node_id=" . $node_id); - break; - - case ("optionsdisplay") : - $id = $_SESSION['suser_id']; - $language = $_POST['user_language']; - $imagesize = sanitize($_POST['user_imagesize']); - $imagecount = sanitize($_POST['user_imagecount']); - $mac = sanitize($_POST['user_mac']); - $dateformat = sanitize($_POST['user_dateformat']); - $dns1suffix = sanitize($_POST['user_dns1suffix']); - $dns2suffix = sanitize($_POST['user_dns2suffix']); - $tooltips = sanitize($_POST['user_tooltips']); - - $menu_assets = sanitize($_POST['user_menu_assets']); - $menu_assetclasses = sanitize($_POST['user_menu_assetclasses']); - $menu_assetclassgroups = sanitize($_POST['user_menu_assetclassgroups']); - $menu_cables = sanitize($_POST['user_menu_cables']); - $menu_locations = sanitize($_POST['user_menu_locations']); - $menu_nodes = sanitize($_POST['user_menu_nodes']); - $menu_subnets = sanitize($_POST['user_menu_subnets']); - $menu_vlans = sanitize($_POST['user_menu_vlans']); - $menu_zones = sanitize($_POST['user_menu_zones']); - - // construct menu set - $menu = array(); - if ($menu_assets) $menu[] = 'asset'; - if ($menu_assetclasses) $menu[] = 'class'; - if ($menu_assetclassgroups) $menu[] = 'group'; - if ($menu_cables) $menu[] = 'cable'; - if ($menu_locations) $menu[] = 'location'; - if ($menu_nodes) $menu[] = 'node'; - if ($menu_subnets) $menu[] = 'subnet'; - if ($menu_vlans) $menu[] = 'vlan'; - if ($menu_zones) $menu[] = 'zone'; - - $sql = "UPDATE user SET - user_language=?, user_imagesize=?, user_imagecount=?, - user_mac=?, user_dateformat=?, user_dns1suffix=?, - user_dns2suffix=?, user_tooltips=?, user_menu=? - WHERE - user_id=?"; - $sth = $dbh->prepare($sql); - $sth->execute([$language, $imagesize, $imagecount, - $mac, $dateformat, $dns1suffix, - $dns2suffix, $tooltips, implode(',', $menu), - $id]); - - $_SESSION['suser_language'] = $language; - $_SESSION['suser_imagesize'] = $imagesize; - $_SESSION['suser_imagecount'] = $imagecount; - $_SESSION['suser_mac'] = $mac; - $_SESSION['suser_dateformat'] = $dateformat; - $_SESSION['suser_dns1suffix'] = $dns1suffix; - $_SESSION['suser_dns2suffix'] = $dns2suffix; - $_SESSION['suser_menu_assets'] = $menu_assets; - $_SESSION['suser_menu_assetclasses'] = $menu_assetclasses; - $_SESSION['suser_menu_assetclassgroups'] = $menu_assetclassgroups; - $_SESSION['suser_menu_cables'] = $menu_cables; - $_SESSION['suser_menu_locations'] = $menu_locations; - $_SESSION['suser_menu_nodes'] = $menu_nodes; - $_SESSION['suser_menu_subnets'] = $menu_subnets; - $_SESSION['suser_menu_vlans'] = $menu_vlans; - $_SESSION['suser_menu_zones'] = $menu_zones; - $_SESSION['suser_tooltips'] = $tooltips; - - header_location("options.php"); - break; - - case ("optionspassword") : - $user_id = $_SESSION['suser_id']; - $currentpass = sanitize($_POST['user_currentpass']); - $newpass1 = sanitize($_POST['user_newpass1']); - $newpass2 = sanitize($_POST['user_newpass2']); - - $sth = $dbh->prepare("SELECT user_pass FROM user WHERE user_id=?"); - $sth->execute([$user_id]); - - $userpass = $sth->fetchColumn();; - - if (password_verify($currentpass, $userpass)) { - if (!strcmp($newpass1, $newpass2)) { - $sth = $dbh->prepare("UPDATE user SET user_pass=? WHERE user_id=?"); - $newhash = password_hash($newpass1, PASSWORD_BCRYPT); - $sth->execute([$newhash, $user_id]); - header_location("options.php"); - } - } - // TODO generate errormessages here - break; - - case ("subnet") : - $subnet_id = sanitize($_POST['subnet_id']); - $subnet_address= sanitize($_POST['subnet_address']); - $subnet_proto_vers = sanitize($_POST['subnet_proto_vers']); - $subnet_mask = sanitize($_POST['subnet_mask']); - $subnet_dhcpstart = sanitize($_POST['subnet_dhcpstart']); - $subnet_dhcpend = sanitize($_POST['subnet_dhcpend']); - $subnet_ntp_server = sanitize($_POST['subnet_ntp_server']); - $subnet_info = sanitize($_POST['subnet_info']); - - $sql = "UPDATE subnet SET - subnet_address=?, subnet_mask=?, subnet_dhcp_start=?, - subnet_dhcp_end=?, subnet_info=?, protocol_version=?, - ntp_server=? - WHERE subnet_id=?"; - $sth = $dbh->prepare($sql); - $sth->execute([$subnet_address, $subnet_mask, $subnet_dhcpstart, - $subnet_dhcpend, $subnet_info, $subnet_proto_vers, - $subnet_ntp_server, $subnet_id]); - - header_location("subnetview.php?subnet_id=" . $subnet_id); - break; - -/* case ("user") : - $user_id = sanitize($_POST['user_id']); - $user_name = sanitize($_POST['user_name']); - $user_displayname = sanitize($_POST['user_displayname']); - $user_realm = sanitize($_POST['user_realm']); - // roles - $role_add = sanitize($_POST['role_add']); - $role_edit = sanitize($_POST['role_edit']); - $role_delete = sanitize($_POST['role_delete']); - $role_manage = sanitize($_POST['role_manage']); - $role_admin = sanitize($_POST['role_admin']); - - // construct menu set - $role = array(); - if ($role_add) $role[] = 'add'; - if ($role_edit) $role[] = 'edit'; - if ($role_delete) $role[] = 'delete'; - if ($role_manage) $role[] = 'manage'; - if ($role_admin) $role[] = 'admin'; - - - $sql = "UPDATE user SET - user_name=?, user_displayname=?, user_realm=?, - user_role=? - WHERE user_id=?"; - $sth = $dbh->prepare($sql); - $sth->execute([$user_name ,$user_displayname, $user_realm, - implode(',', $role), $user_id]); - - header_location("userview.php?user_id=" . $user_id); - break; - - case ("vlan") : - $vlan_id = sanitize($_POST['vlan_id']); - $vlan_name = sanitize($_POST['vlan_name']); - $vlan_number = sanitize($_POST['vlan_number']); - $vlan_info = sanitize($_POST['vlan_info']); - $vlan_color = sanitize($_POST['vlan_color']); - - $sql = "UPDATE vlan SET vlan_name=?, vlan_number=?, vlan_color=?, vlan_info=? WHERE vlan_id=?"; - $sth = $dbh->prepare($sql); - $sth->execute([$vlan_name, $vlan_number, $vlan_color, $vlan_info, $vlan_id]); - - header_location("vlanview.php?vlan_id=" . $vlan_id); - break; - - case ("zone") : - $id = sanitize($_POST['zone_id']); - $origin = sanitize($_POST['zone_origin']); - $ttl_default = sanitize($_POST['zone_ttl_default']); - $soa = sanitize($_POST['zone_soa']); - $hostmaster = sanitize($_POST['zone_hostmaster']); - $refresh = sanitize($_POST['zone_refresh']); - $retry = sanitize($_POST['zone_retry']); - $expire = sanitize($_POST['zone_expire']); - $ttl = sanitize($_POST['zone_ttl']); - $serial = sanitize($_POST['zone_serial']); - $ns1 = sanitize($_POST['zone_ns1']); - $ns2 = sanitize($_POST['zone_ns2']); - $ns3 = sanitize($_POST['zone_ns3']); - $mx1 = sanitize($_POST['zone_mx1']); - $mx2 = sanitize($_POST['zone_mx2']); - $info = sanitize($_POST['zone_info']); - $sql = "UPDATE zone SET - zone_origin=?, zone_ttl_default=?, zone_soa=?, zone_hostmaster=?, - zone_refresh=?, zone_retry=?, zone_expire=?, zone_ttl=?, zone_serial=?, - zone_ns1=?, zone_ns2=?, zone_ns3=?, zone_mx1=?, zone_mx2=?, zone_info=? - WHERE zone_id=?"; - $sth = $dbh->prepare($sql); - $sth->execute([$origin, $ttl_default, $soa, $hostmaster, $refresh, $retry, - $expire, $ttl, $serial, $ns1, $ns2, $ns3, $mx1, $mx2, $info, - $id]); - - header_location("zoneview.php?zone_id=" . $zone_id); - break; */ - } -} - -// still not redirected, check for error -if(empty($comments)) { - $comments = "error"; -} -header_location("comments.php?comments=" . $comments); -?> diff --git a/subnet.php b/subnet.php index 50b418e..dc4596f 100644 --- a/subnet.php +++ b/subnet.php @@ -8,8 +8,183 @@ SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ include("includes.php"); + +if (isset($_REQUEST['id'])) { + $id = (int) $_REQUEST['id'] or $id = 0; +} + +// ========== ADDITIONAL ACTION DEFINITIONS =================================== + +define ('ACT_LOCATION_EDIT', 100); +define ('ACT_LOCATION_ADD', 101); +define ('ACT_LOCATION_DEL', 102); + +define ('ACT_VLAN_EDIT', 103); +define ('ACT_VLAN_ADD', 104); +define ('ACT_VLAN_DEL', 105); + +// ========== ACTIONS START =================================================== +switch ($submit = form_get_action()) { + + case NULL: break; + + case 'add': $action = ACT_ADD; break; + case 'view': $action = ACT_VIEW; break; + case 'edit': $action = ACT_EDIT; break; + case 'del': $action = ACT_DELETE; break; + case 'link': $action = ACT_LINK; break; + + // Location + case 'ledit': $action = ACT_LOCATION_EDIT; break; + case 'ladd': $action = ACT_LOCATION_ADD; break; + case 'ldel': $action = ACT_LOCATION_DEL; break; + + // VLAN + case 'vedit': $action = ACT_VLAN_EDIT; break; + case 'vadd': $action = ACT_VLAN_ADD; break; + case 'vdel': $action = ACT_VLAN_DEL; break; + + case 'exec-ledit': + if ($_POST['action'] == 'subnetlocationadd') { + $action = ACT_LOCATION_ADD; + } elseif ($_POST['action'] == 'subnetlocationdel') { + $action = ACT_LOCATION_DEL; + } else { + $g_warning->Add('Invalid action: '. $_POST['action']); + } + break; + + case 'exec-ladd': + $location_id = sanitize($_POST['location_id']); + $sql = "INSERT INTO subnetlocation (location_id, subnet_id) VALUES (?, ?)"; + $sth = $dbh->prepare($sql); + $sth->execute([$location_id, $id]); + $action = ACT_VIEW; + break; + + case 'exec-ldel': + $location_id = sanitize($_POST['location_id']); + $sth = $dbh->prepare("DELETE FROM subnetlocation WHERE location_id=? AND subnet_id=?"); + $sth->execute([$location_id, $id]); + $g_message->Add('Removed link to location'); + $action = ACT_VIEW; + break; + + case 'exec-vedit': + if ($_POST['action'] == 'subnetvlanadd') { + $action = ACT_VLAN_ADD; + } elseif ($_POST['action'] == 'subnetvlandel') { + $action = ACT_VLAN_DEL; + } else { + $g_warning->Add('Invalid action: '. $_POST['action']); + } + break; + + case 'exec-vadd': + $vlan_id = sanitize($_POST['vlan_id']); + $sql = "INSERT INTO subnetvlan (subnet_id, vlan_id) VALUES (?, ?)"; + $sth = $dbh->prepare($sql); + $sth->execute([$id, $vlan_id]); + $action = ACT_VIEW; + break; + + case 'exec-vdel': + $vlan_id = sanitize($_POST['vlan_id']); + $sth = $dbh->prepare("DELETE FROM subnetvlan WHERE subnet_id=? AND vlan_id=?"); + $sth->execute([$id, $vlan_id]); + $g_message->Add('Removed link to vlan'); + $action = ACT_VIEW; + break; + + case 'insert': + $address= sanitize($_POST['subnet_address']); + $mask = sanitize($_POST['subnet_mask']); + $info = sanitize($_POST['subnet_info']); + $dhcp_start = sanitize($_POST['dhcp_start']); + $dhcp_end = sanitize($_POST['dhcp_end']); + $sql = "INSERT INTO subnet ( + subnet_address, subnet_mask, subnet_info, + subnet_dhcp_start, subnet_dhcp_end + ) VALUES ( + :address, :mask, :info, + :dhcp_start, :dhcp_end + )"; + $sth = $dbh->prepare($sql); + $sth->bindValue(':address', $address, PDO::PARAM_STR); + $sth->bindValue(':mask', $mask, PDO::PARAM_INT); + $sth->bindValue(':info', $info, PDO::PARAM_STR); + $sth->bindValue(':dhcp_start', $dhcp_start, PDO::PARAM_STR); + $sth->bindValue(':dhcp_end', $dhcp_end, PDO::PARAM_STR); + $sth->execute(); + $id = $dbh->lastInsertId(); + // vlan if selected + $vlan_id = intval(sanitize($_POST['vlan_id'])); + if ($vlan_id > 0) { + $sql = "INSERT INTO subnetvlan (subnet_id, vlan_id) VALUES (?, ?)"; + $sth = $dbh->prepare($sql); + $sth->execute([$id, $vlan_id]); + } + $action = ACT_VIEW; + break; + + case 'update': + $subnet_address= sanitize($_POST['subnet_address']); + $subnet_proto_vers = sanitize($_POST['subnet_proto_vers']); + $subnet_mask = sanitize($_POST['subnet_mask']); + $subnet_dhcpstart = sanitize($_POST['subnet_dhcpstart']); + $subnet_dhcpend = sanitize($_POST['subnet_dhcpend']); + $subnet_ntp_server = sanitize($_POST['subnet_ntp_server']); + $subnet_info = sanitize($_POST['subnet_info']); + + $sql = "UPDATE subnet SET + subnet_address=?, subnet_mask=?, subnet_dhcp_start=?, + subnet_dhcp_end=?, subnet_info=?, protocol_version=?, + ntp_server=? + WHERE subnet_id=?"; + $sth = $dbh->prepare($sql); + $sth->execute([$subnet_address, $subnet_mask, $subnet_dhcpstart, + $subnet_dhcpend, $subnet_info, $subnet_proto_vers, + $subnet_ntp_server, $id]); + $action = ACT_VIEW; + break; + + case 'delete': + // TODO delete NAT + $sth = $dbh->prepare("DELETE FROM node WHERE subnet_id=?"); + $sth->execute([$id]); + $count = $sth->rowCount(); + $g_message->Add('Deleted $count nodes'); + + $sth = $dbh->prepare("DELETE FROM subnetlocation WHERE subnet_id=?"); + $sth->execute([$id]); + $count = $sth->rowCount(); + $g_message->Add('Deleted $count location links'); + + $sth = $dbh->prepare("DELETE FROM subnetvlan WHERE subnet_id=?"); + $sth->execute([$id]); + $count = $sth->rowCount(); + $g_message->Add('Deleted $count vlan links'); + + $sth = $dbh->prepare("DELETE FROM subnet WHERE subnet_id=?"); + $sth->execute([$id]); + $g_message->Add('Deleted subnet'); + + $action = ACT_DEFAULT; + break; + + default: + $g_error->Add(submit_error($submit)); + $valid = FALSE; +} + +// ========== ACTIONS END ===================================================== + +$smarty->assign("scripts",'changetext.js'); include("header.php"); +if ($action == ACT_DEFAULT): +// ========== VARIANT: default behavior ======================================= + $sql = "SELECT s.subnet_id, s.subnet_address, s.subnet_mask, s.ntp_server, CONCAT(LEFT(s.subnet_info, 50), IF(CHAR_LENGTH(s.subnet_info)>50,'...','')) AS subnet_info, @@ -23,5 +198,554 @@ $smarty->assign("subnets", $sth->fetchAll()); $smarty->display("subnet.tpl"); -include("footer.php"); +elseif ($action == ACT_ADD): +// ========== VARIANT: add record ============================================= + +if((isset($_GET['vlan_id'])) ? $vlan_id = sanitize($_GET['vlan_id']) : $vlan_id = ""); +$smarty->assign("vlan_id", $vlan_id); +$smarty->assign("vlan_options", db_get_options_vlan($lang['lang_option_none'])); + +$smarty->display("subnetadd.tpl"); + +elseif ($action == ACT_VIEW): +// ========== VARIANT: view single record ===================================== + +if(isset($_GET['page'])) { + $page = sanitize($_GET['page']); +} + +// subnet +$sql = "SELECT + s.subnet_id AS id, + s.subnet_address AS address, + s.subnet_mask AS mask, + s.subnet_dhcp_start AS dhcp_start, + s.subnet_dhcp_end AS dhcp_end, + s.subnet_info AS info, + s.protocol_version AS proto_vers, + s.ntp_server, + COUNT(node.subnet_id) AS node_counter + FROM + subnet AS s LEFT JOIN node USING (subnet_id) + WHERE + s.subnet_id=? + GROUP BY + s.subnet_id"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); + +$subnet = $sth->fetch(PDO::FETCH_OBJ); + +$smarty->assign("subnet", $subnet); + +// set counters +$host_counter = pow(2, (32-$subnet->mask)); +$node_counter = $subnet->node_counter; +$subnet_usedpercentage = round((($node_counter/($host_counter-2))*100), 1); + +$smarty->assign("node_counter", $node_counter); +$smarty->assign("subnet_usedpercentage", $subnet_usedpercentage); +$smarty->assign("config_color_unused", $config_color_unused); +$smarty->assign("host_counter", $host_counter-2); +$smarty->assign("free_counter", (($host_counter-2)-$node_counter)); + +// subnet + +// split up the range +$iprange = explode('.', $subnet->address); +$iprange1 = $iprange[0]; +$iprange2 = $iprange[1]; +$iprange3 = $iprange[2]; +$iprange4 = $iprange[3]; + +// create empty subnet-array +$subnetdata = array(); + +// determine range (Class A/B/C) +if ($subnet->mask >= 24) { + // Class C + // fill subnet-array with addresses we want to see + for($i=0; $i<$host_counter; $i++) { + // build ip + $ip = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$i); + + // fill subnet-array + $subnetdata[$ip] = array(); + } + + // calculate broadcast address + $broadcast_address = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$i-1); + + // to tpl + $smarty->assign("iprange1", $iprange1); + $smarty->assign("iprange2", $iprange2); + $smarty->assign("iprange3", $iprange3); + $smarty->assign("iprange4", $iprange4); + $smarty->assign("subnetmask1", 255); + $smarty->assign("subnetmask2", 255); + $smarty->assign("subnetmask3", 255); + $smarty->assign("subnetmask4", 256-$host_counter); + + // no pagination needed + $smarty->assign("noselect", TRUE); + $smarty->assign("one_select", FALSE); + $smarty->assign("two_select", FALSE); + + // set displayed nodes + $nodes_displayed = $host_counter; + +} else if ($subnet->mask >= 16) { + // Class B + // which part do we want to see? + if ((empty($page)) ? $page = $subnet->address : $page = $page); + $page = explode('.', $page); + $page2 = $page[2]; + + // fill subnet-array with addresses we want to see + for($i=0; $i<256; $i++) { + // build ip + $ip = $iprange1 . '.' . $iprange2 . '.' . $page2 . '.' . $i; + + // fill subnet-array + $subnetdata[$ip] = array(); + } + + // calculate broadcast address + $broadcast_address = $iprange1 . '.' . $iprange2 . '.' . ($iprange3+$i-1) . '.255'; + + // to tpl + $smarty->assign("iprange1", $iprange1); + $smarty->assign("iprange2", $iprange2); + + // loop addresses in range3 + for ($i=$iprange3; $i<(pow(2,(32-$subnet->mask))/256); $i++) { + // send to tpl + $smarty->assign("iprange3", $i); + $smarty->assign("iprange4", 0); + + // set select box + if ($i == $page2) { + $smarty->assign("row_selected", "selected"); + + } else { + $smarty->assign("row_selected", ""); + } + + } + + $smarty->assign("subnetmask1", 255); + $smarty->assign("subnetmask2", 255); + $smarty->assign("subnetmask3", 256-($host_counter/256)); + $smarty->assign("subnetmask4", 0); + + // one select box + $smarty->assign("noselect", FALSE); + $smarty->assign("one_select", TRUE); + $smarty->assign("two_select", FALSE); + + // set displayed nodes + $nodes_displayed = 256; +} else { + // Class A + // which part do we want to see? + if ((empty($page)) ? $page = $subnet->address : $page = $page); + $page = explode('.', $page); + $page2 = $page[1]; + $page3 = $page[2]; + + // fill subnet-array with addresses we want to see + for($i=0; $i<256; $i++) { + // build ip + $ip = $iprange1 . '.' . $page2 . '.' . $page3 . '.' . $i; + + // fill subnet-array + $subnetdata[$ip] = array(); + } + + // calculate broadcast address + $broadcast_address = $iprange1 . '.' . ($iprange2+$i-1) . '.255.255'; + + // to tpl + $smarty->assign("iprange1", $iprange1); + $smarty->assign("iprange2", $iprange2); + + // loop addresses in range 2 + for ($i=$iprange2; $i<(pow(2,(24-$subnet->mask))/256); $i++) { + // send to tpl + $smarty->assign("iprange1", $iprange1); + $smarty->assign("iprange2", $i); + $smarty->assign("iprange3", $page3); + $smarty->assign("iprange4", $iprange4); + + // set select box + if($i == $page2) { + $smarty->assign("row1_selected", "selected"); + + } else { + $smarty->assign("row1_selected", ""); + } + + } + + // loop addresses in range 3 + for ($i=0; $i<256; $i++) { + // send to tpl + $smarty->assign("iprange1", $iprange1); + $smarty->assign("iprange2", $page2); + $smarty->assign("iprange3", $i); + $smarty->assign("iprange4", $iprange4); + + // set select box + if($i==$page3) { + $smarty->assign("row2_selected", "selected"); + + } else { + $smarty->assign("row2_selected", ""); + } + + } + + $smarty->assign("subnetmask1", 255); + $smarty->assign("subnetmask2", 256-($host_counter/65536)); + $smarty->assign("subnetmask3", 0); + $smarty->assign("subnetmask4", 0); + + // one select box + $smarty->assign("noselect", FALSE); + $smarty->assign("one_select", FALSE); + $smarty->assign("two_select", TRUE); + + // set displayed nodes + $nodes_displayed = 256; +} + +// get nodes for this subnetview and implement the values into the array + +// TODO this is very bad SQL +/*$sql = "SELECT a.asset_name, g.assetclassgroup_color, n.node_id, n.node_ip + FROM + asset AS a, + assetclass AS c, + assetclassgroup AS g, + node AS n + WHERE + n.node_ip IN ('".implode("','",array_keys($subnetdata))."') + AND n.subnet_id=? + AND a.asset_id=n.asset_id + AND c.assetclass_id=a.assetclass_id + AND g.assetclassgroup_id=c.assetclassgroup_id"; */ +$sql = "SELECT + a.asset_name, g.assetclassgroup_color, n.node_id, n.node_ip + FROM node AS n + LEFT JOIN asset AS a USING (asset_id) + LEFT JOIN assetclass AS c USING (assetclass_id) + LEFT JOIN assetclassgroup AS g USING (assetclassgroup_id) + WHERE n.subnet_id=:subnet_id + AND INET_ATON(n.node_ip) BETWEEN :ipfrom AND :ipto"; +// Debug $smarty->assign("sql",array_key_first($subnetdata) . " - " . array_key_last($subnetdata) ); +$sth = $dbh->prepare($sql); +$sth->bindValue(':ipfrom', ip2long(array_key_first($subnetdata)), PDO::PARAM_INT); +$sth->bindValue(':ipto', ip2long(array_key_last($subnetdata)), PDO::PARAM_INT); +$sth->bindValue(':subnet_id', $id, PDO::PARAM_INT); +$sth->execute(); + +$nodes = $sth->fetchAll(); +$smarty->assign("nodes", $nodes); + +if (count($nodes) > 0) { + foreach ($nodes AS $node) { + $subnetdata[$node['node_ip']] = $node; + } +} + +// replace ip's in subnet-array (if necessary) +// check for subnet address +if (array_key_exists($subnet->address, $subnetdata)) { + // replace + $subnetdata[$subnet->address] = array("subnet_address"); +} + +// check for broadcast address +if (array_key_exists($broadcast_address, $subnetdata)) { + // replace + $subnetdata[$broadcast_address] = array("broadcast_address"); +} + +$dhcpstart = 0; +if ($subnet->dhcp_start && $subnet->dhcp_end) { + $dhcpstart = ip2long($subnet->dhcp_start); + $dhcpend = ip2long($subnet->dhcp_end); +} + + // loop subnet-array and send to template + // start counter +// $i=1; + // loop subnet-array +foreach ($subnetdata AS $node_ip => $node) { + +// make new line? +// if(($i%$_SESSION['suser_imagecount']==0 && $i!=$nodes_displayed) ? $tr="" : $tr=""); + + // check if node-ip in DHCP-area + $subnetdata[$node_ip]["dynamic"] = false; + if ($dhcpstart > 0) { + $ipval = ip2long($node_ip); + if (($ipval >= $dhcpstart) and ($ipval <= $dhcpend)) { + $subnetdata[$node_ip]["dynamic"] = true; + } + } + + // check node + if (empty($node)) { + // empty node to tpl + $subnetdata[$node_ip]["url"] = 'subnet.php?f=link&id=' . $id . '&node_ip='. $node_ip; + $subnetdata[$node_ip]["remotetext"] = $node_ip; + if ($subnetdata[$node_ip]["dynamic"]) { + $subnetdata[$node_ip]["assetclassgroup_color"] = $config_color_dynamic; + } else { + $subnetdata[$node_ip]["assetclassgroup_color"] = $config_color_unused; + } + } else if (array_key_exists(0, $node) && $node[0]=="subnet_address") { + // subnet address to tpl + $subnetdata[$node_ip]["url"] = ""; + $subnetdata[$node_ip]["remotetext"] = $node_ip . ' ' . $lang['lang_subnet_subnetaddress']; + $subnetdata[$node_ip]["assetclassgroup_color"] = $config_color_blocked; + } else if (array_key_exists(0, $node) && $node[0]=="broadcast_address") { + // broadcast address to tpl + $subnetdata[$node_ip]["url"] = ""; + $subnetdata[$node_ip]["remotetext"] = $node_ip . ' ' . $lang['lang_subnet_broadcastaddress']; + $subnetdata[$node_ip]["assetclassgroup_color"] = $config_color_blocked; + } else { + // node to tpl + $subnetdata[$node_ip]["url"] = 'node.php?f=view&id=' . $node['node_id']; + $subnetdata[$node_ip]["remotetext"] = $node_ip . ' ' . $node['asset_name']; + $subnetdata[$node_ip]["assetclassgroup_color"] = $node['assetclassgroup_color']; + } + + // update counter + // $i++; + +} // foreach + +$smarty->assign("subnetdata", $subnetdata); +$smarty->assign("imagewrap", $_SESSION['suser_imagecount']); + +// vlans +$sql = "SELECT v.vlan_id AS id, v.vlan_name AS name, + v.vlan_number AS number + FROM subnetvlan AS s JOIN vlan AS v USING (vlan_id) + WHERE s.subnet_id=? + ORDER BY v.vlan_name"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("vlans", $sth->fetchAll()); + +// locations +$sql = "SELECT l.location_id, l.location_name + FROM location AS l LEFT JOIN subnetlocation AS s USING (location_id) + WHERE s.subnet_id=? + ORDER BY l.location_name"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("locations", $sth->fetchAll()); + +// assetclasses with color from assetclassgroup +$sql = "SELECT assetclass_id AS id, assetclass_name AS name, + assetclassgroup_color AS color, COUNT(node_id) AS counter + FROM node LEFT JOIN asset USING (asset_id) + LEFT JOIN assetclass USING (assetclass_id) + LEFT JOIN assetclassgroup USING (assetclassgroup_id) + WHERE subnet_id=? + GROUP BY assetclass_id + ORDER BY assetclass_name"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("assetclasses", $sth->fetchAll()); + +$smarty->display("subnetview.tpl"); + +elseif ($action == ACT_EDIT): +// ========== VARIANT: edit single record ===================================== + +$sql = "SELECT subnet_id AS id, subnet_address AS address, subnet_mask AS mask, + protocol_version AS proto_vers, subnet_dhcp_start AS dhcp_start, + subnet_dhcp_end AS dhcp_end, ntp_server, subnet_info AS info + FROM subnet + WHERE subnet_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); + +$smarty->display("subnetedit.tpl"); + +elseif ($action == ACT_DELETE): +// ========== VARIANT: delete record ========================================== + +// subnet +$sql = "SELECT subnet_id AS id, subnet_address AS address, subnet_mask AS mask + FROM subnet + WHERE subnet_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); + +// node +$sql = "SELECT node_id AS id, node_ip AS ip + FROM node + WHERE subnet_id=? + ORDER BY INET_ATON(node_ip)"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("nodes", $sth->fetchAll()); + +$smarty->display("subnetdel.tpl"); + +elseif ($action == ACT_LINK): +// ========== VARIANT: link IP to node ======================================== + +// assigniptonode +$node_ip = sanitize($_GET['node_ip']); + +$sql = "SELECT subnet_id AS id, subnet_address AS address, subnet_mask AS mask + FROM subnet + WHERE subnet_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); + +$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); +$smarty->assign("node_ip", $node_ip); + +$smarty->display("assigniptonode.tpl"); + +elseif ($action == ACT_LOCATION_EDIT): +// ========== VARIANT: subnet to location ===================================== + +$sql = "SELECT subnet_id AS id, subnet_address AS address, subnet_mask AS mask + FROM subnet + WHERE subnet_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); + +$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); + +$smarty->display("subnetlocationedit.tpl"); + +elseif ($action == ACT_LOCATION_ADD): +// ========== VARIANT: subnet to location ===================================== + +$sql = "SELECT subnet_id AS id, subnet_address AS address, subnet_mask AS mask + FROM subnet + WHERE subnet_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); + +$smarty->assign("location_options", db_get_options_location()); + +$smarty->display("subnetlocationadd.tpl"); + +elseif ($action == ACT_LOCATION_DEL): +// ========== VARIANT: subnet to location ===================================== + +// subnet +$sql = "SELECT subnet_id AS id, subnet_address AS address, subnet_mask AS mask + FROM subnet + WHERE subnet_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); + +// locations for subnet +$sql = "SELECT l.location_id, l.location_name + FROM subnetlocation AS s LEFT JOIN location AS l USING (location_id) + WHERE s.subnet_id=? + ORDER BY l.location_name"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$records = $sth->fetchAll(); + +$locations = array(); +foreach ($records as $rec) { + $locations[$rec['location_id']] = $rec['location_name']; +} +$smarty->assign("location_options", $locations); + +$smarty->display("subnetlocationdel.tpl"); + +elseif ($action == ACT_VLAN_EDIT): +// ========== VARIANT: subnet to vlan ========================================= + +$sql = "SELECT subnet_id AS id, subnet_address AS address, subnet_mask AS mask + FROM subnet + WHERE subnet_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); + +$smarty->display("subnetvlanedit.tpl"); + +elseif ($action == ACT_VLAN_ADD): +// ========== VARIANT: subnet to vlan ========================================= + +$sql = "SELECT subnet_id AS id, subnet_address AS address, subnet_mask AS mask + FROM subnet + WHERE subnet_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); + +$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); + +// vlan +$sql = "SELECT vlan_id, vlan_number, vlan_name + FROM vlan + WHERE vlan_id NOT IN ( + SELECT vlan_id FROM subnetvlan WHERE subnet_id=? + ) + ORDER BY vlan_number"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); + +$vlans = $sth->fetchAll(); +foreach ($vlans as $vlan) { + $vlan_options[$vlan['vlan_id']] = $vlan['vlan_name'] . ' (' . $vlan['vlan_number']. ')'; +} +$smarty->assign("vlan_options", $vlan_options); + +$smarty->display("subnetvlanadd.tpl"); + +elseif ($action == ACT_VLAN_DEL): +// ========== VARIANT: subnet to vlan ========================================= + +// subnet +$sql = "SELECT subnet_id AS id, subnet_address AS address, subnet_mask AS mask + FROM subnet + WHERE subnet_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); + +// vlan +$sql = "SELECT v.vlan_id, v.vlan_number, v.vlan_name + FROM subnetvlan AS s LEFT JOIN vlan AS v USING (vlan_id) + WHERE s.subnet_id=? + ORDER BY v.vlan_number"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$vlans = $sth->fetchAll(); +foreach ($vlans as $vlan) { + $vlan_options[$vlan['vlan_id']] = $vlan['vlan_name'] . ' (' . $vlan['vlan_number']. ')'; +} +$smarty->assign("vlan_options", $vlan_options); + +$smarty->display("subnetvlandel.tpl"); + +else: +// ========== ERROR UNKNOWN VARIANT =========================================== + +echo "

Unknown function call: Please report to system development!

\n"; + +endif; // $action == ... +// ========== END OF VARIANTS ================================================= + +$smarty->display('footer.tpl'); ?> diff --git a/subnetadd.php b/subnetadd.php deleted file mode 100644 index 8f434fb..0000000 --- a/subnetadd.php +++ /dev/null @@ -1,21 +0,0 @@ -assign("vlan_options", db_get_options_vlan($lang['lang_option_none'])); - -$smarty->display("subnetadd.tpl"); - -include("footer.php"); -?> diff --git a/subnetdel.php b/subnetdel.php deleted file mode 100644 index 4e470f2..0000000 --- a/subnetdel.php +++ /dev/null @@ -1,36 +0,0 @@ -prepare($sql); -$sth->execute([$subnet_id]); -$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); - -// node -$sql = "SELECT node_id AS id, node_ip AS ip - FROM node - WHERE subnet_id=? - ORDER BY INET_ATON(node_ip)"; -$sth = $dbh->prepare($sql); -$sth->execute([$subnet_id]); -$smarty->assign("nodes", $sth->fetchAll()); - -$smarty->display("subnetdel.tpl"); - -include("footer.php"); -?> diff --git a/subnetedit.php b/subnetedit.php deleted file mode 100644 index ed1b51a..0000000 --- a/subnetedit.php +++ /dev/null @@ -1,29 +0,0 @@ -prepare($sql); -$sth->execute([$subnet_id]); - -$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->display("subnetedit.tpl"); - -include("footer.php"); -?> diff --git a/subnetlocationadd.php b/subnetlocationadd.php deleted file mode 100644 index 5bf181f..0000000 --- a/subnetlocationadd.php +++ /dev/null @@ -1,28 +0,0 @@ -prepare($sql); -$sth->execute([$subnet_id]); -$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->assign("location_options", db_get_options_location()); - -$smarty->display("subnetlocationadd.tpl"); - -include("footer.php"); -?> diff --git a/subnetlocationdel.php b/subnetlocationdel.php deleted file mode 100644 index 8761d9b..0000000 --- a/subnetlocationdel.php +++ /dev/null @@ -1,42 +0,0 @@ -prepare($sql); -$sth->execute([$subnet_id]); -$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); - -// locations for subnet -$sql = "SELECT l.location_id, l.location_name - FROM subnetlocation AS s LEFT JOIN location USING (location_id) - WHERE s.subnet_id=? - ORDER BY l.location_name"; -$sth = $dbh->prepare($sql); -$sth->execute([$subnet_id] -$records = $sth->fetchAll(); - -$locations = array(); -foreach ($records as $rec) { - $locations[$rec['location_id']] = $rec['location_name']; -} -$smarty->assign("location_options", $locations); - -$smarty->display("subnetlocationdel.tpl"); - -include("footer.php"); -?> diff --git a/subnetlocationedit.php b/subnetlocationedit.php deleted file mode 100644 index 80544df..0000000 --- a/subnetlocationedit.php +++ /dev/null @@ -1,27 +0,0 @@ -prepare($sql); -$sth->execute([$subnet_id]); - -$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->display("subnetlocationedit.tpl"); - -include("footer.php"); -?> diff --git a/subnetview.php b/subnetview.php deleted file mode 100644 index 1471b1b..0000000 --- a/subnetview.php +++ /dev/null @@ -1,364 +0,0 @@ -assign("scripts",'changetext.js'); -include("header.php"); - -// subnet -$sql = "SELECT - s.subnet_id AS id, - s.subnet_address AS address, - s.subnet_mask AS mask, - s.subnet_dhcp_start AS dhcp_start, - s.subnet_dhcp_end AS dhcp_end, - s.subnet_info AS info, - s.protocol_version AS proto_vers, - s.ntp_server, - COUNT(node.subnet_id) AS node_counter - FROM - subnet AS s LEFT JOIN node USING (subnet_id) - WHERE - s.subnet_id=? - GROUP BY - s.subnet_id"; -$sth = $dbh->prepare($sql); -$sth->execute([$subnet_id]); - -$subnet = $sth->fetch(PDO::FETCH_OBJ); - -$smarty->assign("subnet", $subnet); - -// set counters -$host_counter = pow(2, (32-$subnet->mask)); -$node_counter = $subnet->node_counter; -$subnet_usedpercentage = round((($node_counter/($host_counter-2))*100), 1); - -$smarty->assign("node_counter", $node_counter); -$smarty->assign("subnet_usedpercentage", $subnet_usedpercentage); -$smarty->assign("config_color_unused", $config_color_unused); -$smarty->assign("host_counter", $host_counter-2); -$smarty->assign("free_counter", (($host_counter-2)-$node_counter)); - -// subnet - -// split up the range -$iprange = explode('.', $subnet->address); -$iprange1 = $iprange[0]; -$iprange2 = $iprange[1]; -$iprange3 = $iprange[2]; -$iprange4 = $iprange[3]; - -// create empty subnet-array -$subnetdata = array(); - -// determine range (Class A/B/C) -if ($subnet->mask >= 24) { - // Class C - // fill subnet-array with addresses we want to see - for($i=0; $i<$host_counter; $i++) { - // build ip - $ip = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$i); - - // fill subnet-array - $subnetdata[$ip] = array(); - } - - // calculate broadcast address - $broadcast_address = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$i-1); - - // to tpl - $smarty->assign("iprange1", $iprange1); - $smarty->assign("iprange2", $iprange2); - $smarty->assign("iprange3", $iprange3); - $smarty->assign("iprange4", $iprange4); - $smarty->assign("subnetmask1", 255); - $smarty->assign("subnetmask2", 255); - $smarty->assign("subnetmask3", 255); - $smarty->assign("subnetmask4", 256-$host_counter); - - // no pagination needed - $smarty->assign("noselect", TRUE); - $smarty->assign("one_select", FALSE); - $smarty->assign("two_select", FALSE); - - // set displayed nodes - $nodes_displayed = $host_counter; - -} else if ($subnet->mask >= 16) { - // Class B - // which part do we want to see? - if ((empty($page)) ? $page = $subnet->address : $page = $page); - $page = explode('.', $page); - $page2 = $page[2]; - - // fill subnet-array with addresses we want to see - for($i=0; $i<256; $i++) { - // build ip - $ip = $iprange1 . '.' . $iprange2 . '.' . $page2 . '.' . $i; - - // fill subnet-array - $subnetdata[$ip] = array(); - } - - // calculate broadcast address - $broadcast_address = $iprange1 . '.' . $iprange2 . '.' . ($iprange3+$i-1) . '.255'; - - // to tpl - $smarty->assign("iprange1", $iprange1); - $smarty->assign("iprange2", $iprange2); - - // loop addresses in range3 - for ($i=$iprange3; $i<(pow(2,(32-$subnet->mask))/256); $i++) { - // send to tpl - $smarty->assign("iprange3", $i); - $smarty->assign("iprange4", 0); - - // set select box - if ($i == $page2) { - $smarty->assign("row_selected", "selected"); - - } else { - $smarty->assign("row_selected", ""); - } - - } - - $smarty->assign("subnetmask1", 255); - $smarty->assign("subnetmask2", 255); - $smarty->assign("subnetmask3", 256-($host_counter/256)); - $smarty->assign("subnetmask4", 0); - - // one select box - $smarty->assign("noselect", FALSE); - $smarty->assign("one_select", TRUE); - $smarty->assign("two_select", FALSE); - - // set displayed nodes - $nodes_displayed = 256; -} else { - // Class A - // which part do we want to see? - if ((empty($page)) ? $page = $subnet->address : $page = $page); - $page = explode('.', $page); - $page2 = $page[1]; - $page3 = $page[2]; - - // fill subnet-array with addresses we want to see - for($i=0; $i<256; $i++) { - // build ip - $ip = $iprange1 . '.' . $page2 . '.' . $page3 . '.' . $i; - - // fill subnet-array - $subnetdata[$ip] = array(); - } - - // calculate broadcast address - $broadcast_address = $iprange1 . '.' . ($iprange2+$i-1) . '.255.255'; - - // to tpl - $smarty->assign("iprange1", $iprange1); - $smarty->assign("iprange2", $iprange2); - - // loop addresses in range 2 - for ($i=$iprange2; $i<(pow(2,(24-$subnet->mask))/256); $i++) { - // send to tpl - $smarty->assign("iprange1", $iprange1); - $smarty->assign("iprange2", $i); - $smarty->assign("iprange3", $page3); - $smarty->assign("iprange4", $iprange4); - - // set select box - if($i == $page2) { - $smarty->assign("row1_selected", "selected"); - - } else { - $smarty->assign("row1_selected", ""); - } - - } - - // loop addresses in range 3 - for ($i=0; $i<256; $i++) { - // send to tpl - $smarty->assign("iprange1", $iprange1); - $smarty->assign("iprange2", $page2); - $smarty->assign("iprange3", $i); - $smarty->assign("iprange4", $iprange4); - - // set select box - if($i==$page3) { - $smarty->assign("row2_selected", "selected"); - - } else { - $smarty->assign("row2_selected", ""); - } - - } - - $smarty->assign("subnetmask1", 255); - $smarty->assign("subnetmask2", 256-($host_counter/65536)); - $smarty->assign("subnetmask3", 0); - $smarty->assign("subnetmask4", 0); - - // one select box - $smarty->assign("noselect", FALSE); - $smarty->assign("one_select", FALSE); - $smarty->assign("two_select", TRUE); - - // set displayed nodes - $nodes_displayed = 256; -} - -// get nodes for this subnetview and implement the values into the array -$sql = "SELECT a.asset_name, g.assetclassgroup_color, n.node_id, n.node_ip - FROM - asset AS a, - assetclass AS c, - assetclassgroup AS g, - node AS n - WHERE - n.node_ip IN ('".implode("','",array_keys($subnetdata))."') - AND n.subnet_id=? - AND a.asset_id=n.asset_id - AND c.assetclass_id=a.assetclass_id - AND g.assetclassgroup_id=c.assetclassgroup_id"; - -$sth = $dbh->prepare($sql); -$sth->execute([$subnet_id]); - -$nodes = $sth->fetchAll(); -$smarty->assign("nodes", $nodes); - -if (count($nodes) > 0) { - foreach ($nodes AS $node) { - $subnetdata[$node['node_ip']] = $node; - } -} - -// replace ip's in subnet-array (if necessary) -// check for subnet address -if (array_key_exists($subnet->address, $subnet)) { - // replace - $subnetdata[$subnet->address] = array("subnet_address"); -} - -// check for broadcast address -if (array_key_exists($broadcast_address, $subnet)) { - // replace - $subnetdata[$broadcast_address] = array("broadcast_address"); -} - -$dhcpstart = 0; -if ($subnet->dhcp_start && $subnet->dhcp_end) { - $dhcpstart = ip2long($subnet->dhcp_start); - $dhcpend = ip2long($subnet->dhcp_end); -} - - // loop subnet-array and send to template - // start counter -// $i=1; - // loop subnet-array -foreach ($subnetdata AS $node_ip => $node) { - -// make new line? -// if(($i%$_SESSION['suser_imagecount']==0 && $i!=$nodes_displayed) ? $tr="" : $tr=""); - - // check if node-ip in DHCP-area - $subnetdata[$node_ip]["dynamic"] = false; - if ($dhcpstart > 0) { - $ipval = ip2long($node_ip); - if (($ipval >= $dhcpstart) and ($ipval <= $dhcpend)) { - $subnetdata[$node_ip]["dynamic"] = true; - } - } - - // check node - if (empty($node)) { - // empty node to tpl - $subnetdata[$node_ip]["url"] = 'assigniptonode.php?subnet_id=' . $subnet_id . '&node_ip='. $node_ip; - $subnetdata[$node_ip]["remotetext"] = $node_ip; - if ($subnetdata[$node_ip]["dynamic"]) { - $subnetdata[$node_ip]["assetclassgroup_color"] = $config_color_dynamic; - } else { - $subnetdata[$node_ip]["assetclassgroup_color"] = $config_color_unused; - } - } else if (array_key_exists(0, $node) && $node[0]=="subnet_address") { - // subnet address to tpl - $subnetdata[$node_ip]["url"] = ""; - $subnetdata[$node_ip]["remotetext"] = $node_ip . ' ' . $lang['lang_subnet_subnetaddress']; - $subnetdata[$node_ip]["assetclassgroup_color"] = $config_color_blocked; - } else if (array_key_exists(0, $node) && $node[0]=="broadcast_address") { - // broadcast address to tpl - $subnetdata[$node_ip]["url"] = ""; - $subnetdata[$node_ip]["remotetext"] = $node_ip . ' ' . $lang['lang_subnet_broadcastaddress']; - $subnetdata[$node_ip]["assetclassgroup_color"] = $config_color_blocked; - } else { - // node to tpl - $subnetdata[$node_ip]["url"] = 'nodeview.php?node_id=' . $node['node_id']; - $subnetdata[$node_ip]["remotetext"] = $node_ip . ' ' . $node['asset_name']; - $subnetdata[$node_ip]["assetclassgroup_color"] = $node['assetclassgroup_color']; - } - - // update counter - // $i++; - -} // foreach - -$smarty->assign("subnetdata", $subnetdata); -$smarty->assign("imagewrap", $_SESSION['suser_imagecount']); - -// vlans -$sql = "SELECT v.vlan_id AS id, v.vlan_name AS name, - v.vlan_number AS number - FROM subnetvlan AS s JOIN vlan AS v USING (vlan_id) - WHERE s.subnet_id=? - ORDER BY v.vlan_name"; -$sth = $dbh->prepare($sql); -$sth->execute([$subnet_id]); -$smarty->assign("vlans", $sth->fetchAll()); - -// locations -$sql = "SELECT l.location_id, l.location_name - FROM location AS l LEFT JOIN subnetlocation AS s USING (location_id) - WHERE s.subnet_id=? - ORDER BY l.location_name"; -$sth = $dbh->prepare($sql); -$sth->execute([$subnet_id]); -$smarty->assign("locations", $sth->fetchAll()); - -// assetclassgroups -$sql = "SELECT - assetclassgroup_id AS id, - assetclassgroup_name AS name, - assetclassgroup_color AS color, - COUNT(assetclass_id) AS counter - FROM subnet - LEFT JOIN node USING (subnet_id) - LEFT JOIN asset USING (asset_id) - LEFT JOIN assetclass USING (assetclass_id) - LEFT JOIN assetclassgroup USING (assetclassgroup_id) - WHERE subnet_id=? - GROUP BY assetclass_id - ORDER BY counter DESC"; -$sth = $dbh->prepare($sql); -$sth->execute([$subnet_id]); -$smarty->assign("assetclassgroups", $sth->fetchAll()); - -$smarty->display("subnetview.tpl"); - -include("footer.php"); -?> diff --git a/subnetvlanadd.php b/subnetvlanadd.php deleted file mode 100644 index 181d49f..0000000 --- a/subnetvlanadd.php +++ /dev/null @@ -1,43 +0,0 @@ -prepare($sql); -$sth->execute([$subnet_id]); - -$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); - -// vlan -$sql = "SELECT vlan_id, vlan_number, vlan_name - FROM vlan - WHERE vlan_id NOT IN ( - SELECT vlan_id FROM subnetvlan WHERE subnet_id=? - ) - ORDER BY vlan_number"; -$sth = $dbh->prepare($sql); -$sth->execute([$subnet_id]); - -$vlans = $sth->fetchAll(); -foreach ($vlans as $vlan) { - $vlan_options[$vlan['vlan_id']] = $vlan['vlan_name'] . ' (' . $vlan['vlan_number']. ')'; -} -$smarty->assign("vlan_options", $vlan_options); - -$smarty->display("subnetvlanadd.tpl"); - -include("footer.php"); -?> diff --git a/subnetvlandel.php b/subnetvlandel.php deleted file mode 100644 index d544177..0000000 --- a/subnetvlandel.php +++ /dev/null @@ -1,36 +0,0 @@ -prepare($sql); -$sth->execute([$subnet_id]); -$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); - -// vlan -$sql = "SELECT v.vlan_id, v.vlan_number, v.vlan_name - FROM subnetvlan AS s LEFT JOIN vlan AS v USING (vlan_id) - WHERE s.subnet_id=? - ORDER BY v.vlan_number"; -$sth = $dbh->prepare($sql); -$sth->execute([$subnet_id]); -$smarty->assign("vlans", $sth->fetchAll()); - -$smarty->display("subnetvlandel.tpl"); - -include("footer.php"); -?> diff --git a/subnetvlanedit.php b/subnetvlanedit.php deleted file mode 100644 index 4bf5d0e..0000000 --- a/subnetvlanedit.php +++ /dev/null @@ -1,26 +0,0 @@ -prepare($sql); -$sth->execute([$subnet_id]); -$smarty->assign("subnet", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->display("subnetvlanedit.tpl"); - -include("footer.php"); -?> diff --git a/tpl/asset.tpl b/tpl/asset.tpl index 498289c..0722efe 100644 --- a/tpl/asset.tpl +++ b/tpl/asset.tpl @@ -6,7 +6,7 @@ {if $suser_add} - {$lang_asset_add} + {$lang_asset_add} {/if} @@ -37,7 +37,7 @@ {foreach item=asset from=$assets} - {$asset.asset_name} + {$asset.asset_name} {$asset.assetclass_name} diff --git a/tpl/assetclassview.tpl b/tpl/assetclassview.tpl index 778ddbf..e04a011 100644 --- a/tpl/assetclassview.tpl +++ b/tpl/assetclassview.tpl @@ -6,7 +6,7 @@ {if $suser_add} - {$lang_asset_add} + {$lang_asset_add} {/if} {if $suser_edit} {$lang_assetclass_edit} @@ -82,7 +82,7 @@ {foreach item=asset from=$assets} - {$asset.asset_name} + {$asset.asset_name} {$asset.asset_info}
{/foreach} diff --git a/tpl/assetedit.tpl b/tpl/assetedit.tpl index e2696ee..f85ec43 100644 --- a/tpl/assetedit.tpl +++ b/tpl/assetedit.tpl @@ -84,4 +84,24 @@ +{if $zabbix} + + + + + + + + + +
+ Zabbix + +   +
+ Host ID + + +
+{/if} diff --git a/tpl/assetview.tpl b/tpl/assetview.tpl index ccace93..a599e89 100644 --- a/tpl/assetview.tpl +++ b/tpl/assetview.tpl @@ -96,7 +96,7 @@ {if $suser_edit} - {$lang_assignnodetoasset} + {$lang_assignnodetoasset} {/if} @@ -106,7 +106,7 @@ {foreach item=node from=$nodes} - {if $node.node_ip}{$node.node_ip}{else}(leer){/if} + {if $node.node_ip}{$node.node_ip}{else}(leer){/if} {if $node.node_info}{$node.node_info}{/if}
{/foreach} diff --git a/tpl/assigniptonode.tpl b/tpl/assigniptonode.tpl index c36546c..9ba7580 100644 --- a/tpl/assigniptonode.tpl +++ b/tpl/assigniptonode.tpl @@ -1,5 +1,4 @@ -
- + @@ -10,7 +9,7 @@ {$lang_cancel} - + @@ -37,7 +36,7 @@ {$lang_subnet} - {$subnet->address}/{$subnet->mask} + {$subnet->address}/{$subnet->mask} @@ -50,12 +49,12 @@ -  {$lang_assignnodetoasset_existing} +   -  {$lang_assignnodetoasset_new} +   diff --git a/tpl/assignnodetoasset.tpl b/tpl/assignnodetoasset.tpl index 33e54e4..78223d9 100644 --- a/tpl/assignnodetoasset.tpl +++ b/tpl/assignnodetoasset.tpl @@ -1,5 +1,4 @@ - - + @@ -8,7 +7,7 @@
{$lang_cancel} - +
diff --git a/tpl/cableadd.tpl b/tpl/cableadd.tpl index ce636d8..68cff6c 100644 --- a/tpl/cableadd.tpl +++ b/tpl/cableadd.tpl @@ -47,7 +47,7 @@ {$lang_length} - m + m @@ -55,7 +55,7 @@ Type - {html_options name=cable_type options=$type_options selected=$cable->cable_type} + {html_options name=cable_type options=$type_options selected=$type} @@ -63,7 +63,7 @@ # Links - + @@ -71,7 +71,7 @@ {$lang_color} - # + # @@ -79,7 +79,7 @@ {$lang_info} - + diff --git a/tpl/comments.tpl b/tpl/comments.tpl deleted file mode 100644 index b5c7eca..0000000 --- a/tpl/comments.tpl +++ /dev/null @@ -1,23 +0,0 @@ - - - - - -
- {$lang_comments} - - {$lang_cancel} -
- - - - - - - - -
- {$lang_comments} -
- {$comments} -
diff --git a/tpl/header.tpl b/tpl/header.tpl index e35de4e..8255783 100644 --- a/tpl/header.tpl +++ b/tpl/header.tpl @@ -1,4 +1,4 @@ - + {$lang_ipreg} diff --git a/tpl/locationsubnetadd.tpl b/tpl/locationsubnetadd.tpl index 2510680..cde2824 100644 --- a/tpl/locationsubnetadd.tpl +++ b/tpl/locationsubnetadd.tpl @@ -1,15 +1,14 @@ - - - + +
- {$lang_locationsubnet} + {$lang_locationsubnet} ADD {$lang_cancel} - +
@@ -28,7 +27,7 @@ {$lang_location_name} - {$location->name} + {$location->name} diff --git a/tpl/locationsubnetdel.tpl b/tpl/locationsubnetdel.tpl index b1ff8e4..ffd8e37 100644 --- a/tpl/locationsubnetdel.tpl +++ b/tpl/locationsubnetdel.tpl @@ -1,15 +1,15 @@ - - - + +
- {lang_locationsubnet} + {$lang_locationsubnet} DEL {$lang_cancel} - +{* TODO link und unlink icons! *} +
@@ -28,7 +28,7 @@ {$lang_location_name} - {$location_name} + {$location->name} diff --git a/tpl/locationsubnetedit.tpl b/tpl/locationsubnetedit.tpl index a6d4079..93732e8 100644 --- a/tpl/locationsubnetedit.tpl +++ b/tpl/locationsubnetedit.tpl @@ -1,6 +1,6 @@ - + - + @@ -9,7 +9,7 @@
{$lang_cancel} - +
@@ -28,7 +28,7 @@ {$lang_location_name} - {$location->name} + {$location->name} diff --git a/tpl/locationview.tpl b/tpl/locationview.tpl index f4f3b17..da249a0 100644 --- a/tpl/locationview.tpl +++ b/tpl/locationview.tpl @@ -79,7 +79,7 @@ {if $suser_edit} - {$lang_locationsubnet_edit} + {$lang_locationsubnet_edit} {/if} @@ -89,7 +89,7 @@ {foreach item=subnet from=$subnets} - {$subnet.subnet_address}/{$subnet.subnet_mask}
+ {$subnet.subnet_address}/{$subnet.subnet_mask}
{/foreach} diff --git a/tpl/nat.tpl b/tpl/nat.tpl index 83c9773..e09a518 100644 --- a/tpl/nat.tpl +++ b/tpl/nat.tpl @@ -30,10 +30,10 @@ Rule #{$nat.id} {$nat.description} - {$nat.node_ip_ext} + {$nat.node_ip_ext} {if $nat.port_ext}:{$nat.port_ext}{/if} - {$nat.node_ip_int} + {$nat.node_ip_int} {if $nat.port_int}:{$nat.port_int}{/if} diff --git a/tpl/natadd.tpl b/tpl/natadd.tpl index 34345ee..082c2d3 100644 --- a/tpl/natadd.tpl +++ b/tpl/natadd.tpl @@ -1,5 +1,4 @@ - - + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -28,7 +27,7 @@ {$lang_ip} - {$node_ip_ext} + {$node_ip_ext} diff --git a/tpl/natdel.tpl b/tpl/natdel.tpl index 89384df..86629b2 100644 --- a/tpl/natdel.tpl +++ b/tpl/natdel.tpl @@ -1,5 +1,4 @@ - - + @@ -10,7 +9,7 @@ @@ -30,7 +29,7 @@ {$lang_ip}
{$lang_cancel} {if $nat_options} - + {/if}
- {$node->ip_ext} + {$node->ip_ext}
diff --git a/tpl/natedit.tpl b/tpl/natedit.tpl index 68a1d13..1f6da13 100644 --- a/tpl/natedit.tpl +++ b/tpl/natedit.tpl @@ -1,5 +1,4 @@ - - + @@ -28,7 +27,7 @@ {$lang_ip}
- {$node->ip} + {$node->ip}
@@ -41,12 +40,12 @@ -  {$lang_nat_add} +   -  {$lang_nat_del} +   diff --git a/tpl/node.tpl b/tpl/node.tpl index 6ca28fb..4612dca 100644 --- a/tpl/node.tpl +++ b/tpl/node.tpl @@ -6,7 +6,7 @@ {if $suser_add || $suser_admin} - {$lang_node_add} + {$lang_node_add} {/if} @@ -22,6 +22,9 @@ {$lang_asset_name} + + {$lang_assetclass} + {$lang_asset_info} @@ -29,13 +32,16 @@ {foreach item=node from=$nodes} - {if $node.node_ip}{$node.node_ip}{else}(leer){/if} + {if $node.node_ip}{$node.node_ip}{else}(leer){/if} {$node.node_info} - {$node.asset_name} + {$node.asset_name} + + + {$node.assetclass_name} {$node.asset_info} @@ -43,7 +49,7 @@ {foreachelse} - + {$lang_node_none} diff --git a/tpl/nodeadd.tpl b/tpl/nodeadd.tpl index 460464e..53ed570 100644 --- a/tpl/nodeadd.tpl +++ b/tpl/nodeadd.tpl @@ -1,5 +1,4 @@ - - + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -28,7 +27,7 @@ {$lang_ip} - + diff --git a/tpl/nodedel.tpl b/tpl/nodedel.tpl index 3bdc020..c65ceba 100644 --- a/tpl/nodedel.tpl +++ b/tpl/nodedel.tpl @@ -1,7 +1,5 @@ - - - - + + @@ -11,7 +9,7 @@
{$lang_cancel} - +
@@ -30,7 +28,7 @@ {$lang_ip} - {$node->ip} + {$node->ip} diff --git a/tpl/nodeedit.tpl b/tpl/nodeedit.tpl index d7afbda..d212c50 100644 --- a/tpl/nodeedit.tpl +++ b/tpl/nodeedit.tpl @@ -1,6 +1,5 @@ - - - + + @@ -10,7 +9,7 @@
{$lang_cancel} - +
diff --git a/tpl/nodeview.tpl b/tpl/nodeview.tpl index 8f67f27..c7aa8f8 100644 --- a/tpl/nodeview.tpl +++ b/tpl/nodeview.tpl @@ -6,10 +6,10 @@ {if $suser_edit} - {$lang_node_edit} + {$lang_node_edit} {/if} {if $suser_delete} - {$lang_node_del} + {$lang_node_del} {/if} @@ -29,7 +29,7 @@ {$lang_ip} - {$node->ip} + {$node->ip} @@ -96,7 +96,15 @@ {$lang_asset_name} - {$node->asset_name} + {$node->asset_name} + + + + + {$lang_assetclass} + + + {$node->assetclass_name} @@ -115,7 +123,7 @@ {$lang_subnet_subnetaddress}/{$lang_subnet_mask} - {$node->subnet_address}/{$node->subnet_mask} + {$node->subnet_address}/{$node->subnet_mask} @@ -126,7 +134,7 @@ {$lang_nat} - {$lang_nat_edit} + {$lang_nat_edit} @@ -137,10 +145,10 @@ {foreach item=rule from=$natrules} {if $rule.node_id_int eq $node->id} incoming - {$rule.node_ip_ext}/{$rule.asset_name_ext} ({$rule.nat_type})
+ {$rule.node_ip_ext}/{$rule.asset_name_ext} ({$rule.nat_type})
{else} outgoing - {$rule.node_ip_int}/{$rule.asset_name_int} ({$rule.nat_type})
+ {$rule.node_ip_int}/{$rule.asset_name_int} ({$rule.nat_type})
{/if} {/foreach} diff --git a/tpl/options.tpl b/tpl/options.tpl index e14f417..1baa709 100644 --- a/tpl/options.tpl +++ b/tpl/options.tpl @@ -18,12 +18,12 @@ - {$lang_options_password} + {$lang_options_password} - {$lang_options_display} + {$lang_options_display} {if $suser_admin || $suser_manage} diff --git a/tpl/optionseditdisplay.tpl b/tpl/optionseditdisplay.tpl index a5102f5..138dd8b 100644 --- a/tpl/optionseditdisplay.tpl +++ b/tpl/optionseditdisplay.tpl @@ -1,5 +1,4 @@ - - + @@ -9,7 +8,7 @@
{$lang_cancel} - +
diff --git a/tpl/optionseditpassword.tpl b/tpl/optionseditpassword.tpl index 04cdff8..f1b7a1d 100644 --- a/tpl/optionseditpassword.tpl +++ b/tpl/optionseditpassword.tpl @@ -1,5 +1,4 @@ - - + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -37,6 +36,7 @@ + (minimum length 5 chars) diff --git a/tpl/style.css b/tpl/style.css index 1a2ecf6..bd73ac7 100644 --- a/tpl/style.css +++ b/tpl/style.css @@ -207,7 +207,9 @@ table.subnetview td { div.error, div.warning, div.info, div.note { padding: 0 1em 0 36px; margin: 1em 0 0 0; - -moz-border-radius: 12px; + border-radius: 12px; + width: 750px; + animation: fadeout 5s 2s forwards; } div.error { border: 1px solid #8b0000; @@ -239,3 +241,7 @@ div.info p, div.note p { margin: 0.5em 0.5em 0.5em 0; } +@keyframes fadeout { + from { opacity: 1; } + to { opacity: 0; height: 0; } +} diff --git a/tpl/subnet.tpl b/tpl/subnet.tpl index ea1ac02..92da345 100644 --- a/tpl/subnet.tpl +++ b/tpl/subnet.tpl @@ -6,7 +6,7 @@ {if $suser_add || $suser_admin} - {$lang_subnet_add} + {$lang_subnet_add} {/if} @@ -27,7 +27,7 @@ {foreach item=subnet from=$subnets} - {$subnet.subnet_address}/{$subnet.subnet_mask} + {$subnet.subnet_address}/{$subnet.subnet_mask} {$subnet.node_counter} diff --git a/tpl/subnetadd.tpl b/tpl/subnetadd.tpl index 8e4fdd4..fd6d989 100644 --- a/tpl/subnetadd.tpl +++ b/tpl/subnetadd.tpl @@ -1,5 +1,4 @@ - - + @@ -8,7 +7,7 @@
{$lang_cancel} - +
diff --git a/tpl/subnetdel.tpl b/tpl/subnetdel.tpl index bd9a997..2d98146 100644 --- a/tpl/subnetdel.tpl +++ b/tpl/subnetdel.tpl @@ -1,6 +1,5 @@ - - - + + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -25,7 +24,7 @@ {$lang_subnet_subnetaddress}/{$lang_subnet_mask} - {$subnet->address}/{$subnet->mask} + {$subnet->address}/{$subnet->mask} @@ -43,7 +42,7 @@ {$lang_ip} - {$node.ip} + {$node.ip} {/foreach} diff --git a/tpl/subnetedit.tpl b/tpl/subnetedit.tpl index 6537b01..d168d10 100644 --- a/tpl/subnetedit.tpl +++ b/tpl/subnetedit.tpl @@ -1,6 +1,5 @@ - - - + + @@ -53,7 +52,7 @@ {$lang_subnet_dhcpstart} @@ -61,7 +60,7 @@ {$lang_subnet_dhcpend} @@ -69,7 +68,7 @@ NTP Server diff --git a/tpl/subnetlocationadd.tpl b/tpl/subnetlocationadd.tpl index 84760dd..3b59ceb 100644 --- a/tpl/subnetlocationadd.tpl +++ b/tpl/subnetlocationadd.tpl @@ -1,6 +1,5 @@ - - - + +
- +
- +
- +
@@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -30,7 +29,7 @@ {$lang_subnet_subnetaddress}/{$lang_subnet_mask} - {$subnet->address}/{$subnet->mask} + {$subnet->address}/{$subnet->mask} diff --git a/tpl/subnetlocationdel.tpl b/tpl/subnetlocationdel.tpl index 9c38246..738dd1c 100644 --- a/tpl/subnetlocationdel.tpl +++ b/tpl/subnetlocationdel.tpl @@ -1,6 +1,5 @@ - - - + + @@ -9,7 +8,7 @@
{$lang_cancel} - +
diff --git a/tpl/subnetlocationedit.tpl b/tpl/subnetlocationedit.tpl index 81ee80c..ee61eec 100644 --- a/tpl/subnetlocationedit.tpl +++ b/tpl/subnetlocationedit.tpl @@ -1,6 +1,5 @@ - - - + + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -28,7 +27,7 @@ {$lang_subnet_subnetaddress}/{$lang_subnet_mask} - {$subnet->address}/{$subnet->mask} + {$subnet->address}/{$subnet->mask} @@ -47,8 +46,8 @@ {$lang_options} -  {$lang_location_add}
-  {$lang_location_del} +  
+   diff --git a/tpl/subnetview.tpl b/tpl/subnetview.tpl index b62d3cc..58c8b22 100644 --- a/tpl/subnetview.tpl +++ b/tpl/subnetview.tpl @@ -6,10 +6,10 @@ {if $suser_edit} - {$lang_subnet_edit} + {$lang_subnet_edit} {/if} {if $suser_delete} - {$lang_subnet_del} + {$lang_subnet_del} {/if} @@ -53,7 +53,7 @@ {if $subnet->proto_vers eq 4} - {$subnet->address} + {$subnet->address} {else} {$subnet->address} / {$subnet->mask} {/if} @@ -138,13 +138,13 @@ {/if} -{foreach item=assetclassgroup from=$assetclassgroups} +{foreach item=assetclass from=$assetclasses} - {$assetclassgroup.name} {$assetclassgroup.name} + {$assetclass.name} {$assetclass.name} - {$assetclassgroup.counter} + {$assetclass.counter} {/foreach} @@ -157,7 +157,7 @@ {if $suser_edit} - {$lang_subnetvlan_edit} + {$lang_subnetvlan_edit} {/if} @@ -167,7 +167,7 @@ {foreach item=vlan from=$vlans} - {$vlan.name} ({$vlan.number})
+ {$vlan.name} ({$vlan.number})
{/foreach} @@ -180,7 +180,7 @@ {if $suser_edit} - {$lang_location_edit} + {$lang_location_edit} {/if} @@ -190,7 +190,7 @@ {foreach item=location from=$locations} - {$location.location_name}
+ {$location.location_name}
{/foreach} diff --git a/tpl/subnetvlanadd.tpl b/tpl/subnetvlanadd.tpl index 3543f2d..ee2b805 100644 --- a/tpl/subnetvlanadd.tpl +++ b/tpl/subnetvlanadd.tpl @@ -1,6 +1,5 @@ - - - + + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -28,7 +27,7 @@ {$lang_subnet_subnetaddress}/{$lang_subnet_mask} - {$subnet->address}/{$subnet->mask} + {$subnet->address}/{$subnet->mask} diff --git a/tpl/subnetvlandel.tpl b/tpl/subnetvlandel.tpl index 142e11b..c3d2f02 100644 --- a/tpl/subnetvlandel.tpl +++ b/tpl/subnetvlandel.tpl @@ -1,6 +1,5 @@ - - - + + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -28,7 +27,7 @@ {$lang_subnet_subnetaddress}/{$lang_subnet_mask} - {$subnet_address}/{$subnet_mask} + {$subnet->address}/{$subnet->mask} diff --git a/tpl/subnetvlanedit.tpl b/tpl/subnetvlanedit.tpl index f8af0da..fb89bbf 100644 --- a/tpl/subnetvlanedit.tpl +++ b/tpl/subnetvlanedit.tpl @@ -1,6 +1,5 @@ - - - + + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -28,7 +27,7 @@ {$lang_subnet_subnetaddress}/{$lang_subnet_mask} - {$subnet->address}/{$subnet->mask} + {$subnet->address}/{$subnet->mask} diff --git a/tpl/vlansubnetadd.tpl b/tpl/vlansubnetadd.tpl index 0dcd68c..5fc1bfc 100644 --- a/tpl/vlansubnetadd.tpl +++ b/tpl/vlansubnetadd.tpl @@ -1,6 +1,5 @@ - - - + + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -28,7 +27,7 @@ {$lang_vlan_name} ({$lang_vlan_number}) - {$vlan->name} ({$vlan->number}) + {$vlan->name} ({$vlan->number}) diff --git a/tpl/vlansubnetdel.tpl b/tpl/vlansubnetdel.tpl index ce36e57..1bb5b46 100644 --- a/tpl/vlansubnetdel.tpl +++ b/tpl/vlansubnetdel.tpl @@ -1,6 +1,5 @@ - - - + + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -28,7 +27,7 @@ {$lang_vlan_name} ({$lang_vlan_number}) - {$vlan_name} ({$vlan_number}) + {$vlan->name} ({$vlan->number}) diff --git a/tpl/vlansubnetedit.tpl b/tpl/vlansubnetedit.tpl index ff6af0d..c834537 100644 --- a/tpl/vlansubnetedit.tpl +++ b/tpl/vlansubnetedit.tpl @@ -1,6 +1,5 @@ - - - + + @@ -9,7 +8,7 @@
{$lang_cancel} - +
@@ -28,7 +27,7 @@ {$lang_vlan_name} ({$lang_vlan_number}) - {$vlan->name} ({$vlan->number}) + {$vlan->name} ({$vlan->number}) diff --git a/tpl/vlanview.tpl b/tpl/vlanview.tpl index 1e0a2e9..cd1faf3 100644 --- a/tpl/vlanview.tpl +++ b/tpl/vlanview.tpl @@ -69,7 +69,7 @@ {if $suser_edit} - {$lang_subnetvlan_edit} + {$lang_subnetvlan_edit} {/if} @@ -79,7 +79,7 @@ {foreach item=subnet from=$subnets} - {$subnet.subnet_address}/{$subnet.subnet_mask} + {$subnet.subnet_address}/{$subnet.subnet_mask} {$subnet.subnet_info}
{/foreach} diff --git a/tpl/zoneedit.tpl b/tpl/zoneedit.tpl index b3341c7..3930376 100644 --- a/tpl/zoneedit.tpl +++ b/tpl/zoneedit.tpl @@ -29,6 +29,7 @@ + (example.com.) @@ -37,6 +38,7 @@ + (3D) @@ -45,6 +47,7 @@ + (server.example.com.) @@ -53,6 +56,7 @@ + (hostmaster.example.com.) @@ -61,6 +65,7 @@ + (jjjjmmttnn) @@ -69,6 +74,7 @@ + (8H) @@ -77,6 +83,7 @@ + (2H) @@ -85,6 +92,7 @@ + (4W) @@ -93,6 +101,7 @@ + (1D) @@ -101,6 +110,7 @@ + (ns1.example.com.) @@ -125,6 +135,7 @@ + (50 mx.example.com.) diff --git a/user.php b/user.php index 03449d3..a4a3b0f 100644 --- a/user.php +++ b/user.php @@ -10,7 +10,8 @@ SPDX-License-Identifier: GPL-3.0-or-later include("includes.php"); if (($_SESSION['suser_role_admin'] == 0) and ($_SESSION['suser_role_manage'] == 0)) { - header_location('comments.php?comments=accessdenied'); + $g_error->add('Access denied!'); + $action = ACT_ERR_DENIED; } if (isset($_REQUEST['id'])) { @@ -170,6 +171,14 @@ $smarty->assign("user", $sth->fetch(PDO::FETCH_OBJ)); $smarty->display("userdel.tpl"); +elseif ($action == ACT_ERR_DENIED): +// ========== ERROR ACCESS TO PAGE DENIED ===================================== + +if (isset($_SERVER['HTTP_REFERER'])) { + echo '', "Back to last page

\n"; +} +echo "

"; + else: // ========== ERROR UNKNOWN VARIANT =========================================== diff --git a/vlan.php b/vlan.php index 75a8f94..0ef99b5 100644 --- a/vlan.php +++ b/vlan.php @@ -13,6 +13,12 @@ if (isset($_REQUEST['id'])) { $id = (int) $_REQUEST['id'] or $id = 0; } +// ========== ADDITIONAL ACTION DEFINITIONS =================================== + +define ('ACT_SUBNET_EDIT', 100); +define ('ACT_SUBNET_ADD', 101); +define ('ACT_SUBNET_DEL', 102); + // ========== ACTIONS START =================================================== switch ($submit = form_get_action()) { @@ -23,6 +29,37 @@ switch ($submit = form_get_action()) { case 'edit': $action = ACT_EDIT; break; case 'del': $action = ACT_DELETE; break; + // Subnet + case 'sedit': $action = ACT_SUBNET_EDIT; break; + case 'sadd': $action = ACT_SUBNET_ADD; break; + case 'sdel': $action = ACT_SUBNET_DEL; break; + + case 'exec-sedit': + if ($_POST['action'] == 'vlansubnetadd') { + $action = ACT_SUBNET_ADD; + } elseif ($_POST['action'] == 'vlansubnetdel') { + $action = ACT_SUBNET_DEL; + } else { + $g_warning->Add('Invalid action: '. $_POST['action']); + } + break; + + case 'exec-sadd': + $subnet_id = sanitize($_POST['subnet_id']); + $sql = "INSERT INTO subnetvlan (subnet_id, vlan_id) VALUES (?, ?)"; + $sth = $dbh->prepare($sql); + $sth->execute([$subnet_id, $id]); + $action = ACT_VIEW; + break; + + case 'exec-sdel': + $subnet_id = sanitize($_POST['subnet_id']); + $sth = $dbh->prepare("DELETE FROM subnetvlan WHERE subnet_id=? AND vlan_id=?"); + $sth->execute([$subnet_id, $id]); + $g_message->Add('Removed link to subnet'); + $action = ACT_VIEW; + break; + case 'insert': $vlan_name = sanitize($_POST['vlan_name']); $vlan_number = sanitize($_POST['vlan_number']); @@ -30,7 +67,7 @@ switch ($submit = form_get_action()) { $vlan_color = sanitize($_POST['vlan_color']); $sql = "INSERT INTO vlan (vlan_name, vlan_number, vlan_color, vlan_info) - VALUE (?, ?, ?, ?)"; + VALUES (?, ?, ?, ?)"; $sth = $dbh->prepare($sql); $sth->execute([$vlan_name, $vlan_number, $vlan_color, $vlan_info]); @@ -132,6 +169,60 @@ $smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); $smarty->display("vlandel.tpl"); +elseif ($action == ACT_SUBNET_EDIT): +// ========== VARIANT: subnet to vlan ========================================= + +$sql = "SELECT vlan_id AS id, vlan_name AS name, vlan_number AS number FROM vlan WHERE vlan_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); + +$smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); + +$smarty->display("vlansubnetedit.tpl"); + +elseif ($action == ACT_SUBNET_ADD): +// ========== VARIANT: subnet to vlan ========================================= + +$sql = "SELECT vlan_id AS id, vlan_name AS name, vlan_number AS number + FROM vlan + WHERE vlan_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); + +// possible subnets to add to vlan +// - exclude already assingned subnets from selection +$sql = "SELECT subnet_id, subnet_address, subnet_mask + FROM subnet + WHERE subnet_id NOT IN (SELECT subnet_id FROM subnetvlan WHERE vlan_id=?) + ORDER BY INET_ATON(subnet_address)"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); + +$subnets = $sth->fetchAll(); + +foreach ($subnets as $subnet) { + $subnet_options[$subnet['subnet_id']] = $subnet['subnet_address'].'/'.$subnet['subnet_mask']; +} +$smarty->assign("subnet_options", $subnet_options); + +$smarty->display("vlansubnetadd.tpl"); + +elseif ($action == ACT_SUBNET_DEL): +// ========== VARIANT: subnet to vlan ========================================= + +$sql = "SELECT vlan_id AS id, vlan_name AS name, vlan_number AS number + FROM vlan + WHERE vlan_id=?"; +$sth = $dbh->prepare($sql); +$sth->execute([$id]); +$smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); + +// TODO only linked subnets! +$smarty->assign("subnet_options", db_get_options_subnet()); + +$smarty->display("vlansubnetdel.tpl"); + else: // ========== ERROR UNKNOWN VARIANT =========================================== diff --git a/vlansubnetadd.php b/vlansubnetadd.php deleted file mode 100644 index bc47df3..0000000 --- a/vlansubnetadd.php +++ /dev/null @@ -1,43 +0,0 @@ -prepare($sql); -$sth->execute([$vlan_id]); -$smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); - - -// possible subnets to add to vlan -// - exclude already assingned subnets from selection -$sql = "SELECT subnet_id, subnet_address, subnet_mask - FROM subnet - WHERE subnet_id NOT IN (SELECT subnet_id FROM subnetvlan WHERE vlan_id=?) - ORDER BY INET_ATON(subnet_address)"; -$sth = $dbh->prepare($sql); -$sth->execute([$vlan_id]); - -$subnets = $sth->fetchAll(); - -foreach ($subnets as $subnet) { - $subnet_options[$subnet['subnet_id']] = $subnet['subnet_address'].'/'.$subnet['subnet_mask']; -} -$smarty->assign("subnet_options", $subnet_options); - -$smarty->display("vlansubnetadd.tpl"); - -include("footer.php"); -?> diff --git a/vlansubnetdel.php b/vlansubnetdel.php deleted file mode 100644 index 0434f75..0000000 --- a/vlansubnetdel.php +++ /dev/null @@ -1,27 +0,0 @@ -prepare($sql); -$sth->execute([$vlan_id]); -$smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->assign("subnet_options", db_get_options_subnet()); - -$smarty->display("vlansubnetdel.tpl"); - -include("footer.php"); -?> diff --git a/vlansubnetedit.php b/vlansubnetedit.php deleted file mode 100644 index 7feabd9..0000000 --- a/vlansubnetedit.php +++ /dev/null @@ -1,25 +0,0 @@ -prepare($sql); -$sth->execute([$vlan_id]); - -$smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); - -$smarty->display("vlansubnetedit.tpl"); - -include("footer.php"); -?>