From 42e327776c48e77f6414d9fba768795628599924 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Fri, 24 Feb 2023 14:46:24 +0100 Subject: [PATCH] Interface count for asset --- assetedit.php | 3 ++- assetview.php | 2 +- lang/de.php | 1 + lang/en.php | 1 + lib.php | 2 +- nat.php | 28 ++++++++++++++++++++++++++ submit.php | 14 ++++++++----- tpl/assetadd.tpl | 8 ++++++++ tpl/assetedit.tpl | 8 ++++++++ tpl/assetview.tpl | 8 ++++++++ tpl/nat.tpl | 50 +++++++++++++++++++++++++++++++++++++++++++++++ tpl/useradd.tpl | 8 ++++++++ tpl/userview.tpl | 10 +--------- useradd.php | 8 +++++++- 14 files changed, 133 insertions(+), 18 deletions(-) create mode 100644 nat.php create mode 100644 tpl/nat.tpl diff --git a/assetedit.php b/assetedit.php index 6119fbc..7f1e4fb 100644 --- a/assetedit.php +++ b/assetedit.php @@ -13,7 +13,8 @@ $asset_id = sanitize($_GET['asset_id']); include("header.php"); -$sql = "SELECT asset_id, asset_name, asset_hostname, asset_info, assetclass_id +$sql = "SELECT asset_id, asset_name, asset_hostname, asset_info, asset_intf, + assetclass_id FROM asset WHERE asset_id=?"; $sth = $dbh->prepare($sql); diff --git a/assetview.php b/assetview.php index 2c4a974..2580535 100644 --- a/assetview.php +++ b/assetview.php @@ -14,7 +14,7 @@ $asset_id = sanitize($_GET['asset_id']); include("header.php"); $sql = "SELECT a.asset_id, a.asset_name, a.asset_hostname, a.asset_info, - c.assetclass_id, c.assetclass_name + a.asset_intf, c.assetclass_id, c.assetclass_name FROM asset AS a LEFT OUTER JOIN assetclass AS c USING (assetclass_id) WHERE a.asset_id=?"; $sth = $dbh->prepare($sql); diff --git a/lang/de.php b/lang/de.php index 92c9dc2..fa7eac9 100644 --- a/lang/de.php +++ b/lang/de.php @@ -56,6 +56,7 @@ $lang = array( 'lang_asset_name' => 'Objektname', 'lang_asset_hostname' => 'Hostname', 'lang_asset_none' => 'Es sind keine Objekte vorhanden', + 'lang_asset_intf' => 'Anzahl Schnittstellen', 'lang_assetclass_add' => 'Objektklasse hinzufügen', 'lang_assetclass_del' => 'Objektklasse löschen', diff --git a/lang/en.php b/lang/en.php index 7281267..282ca1a 100644 --- a/lang/en.php +++ b/lang/en.php @@ -56,6 +56,7 @@ $lang = array( 'lang_asset_name' => 'Asset name', 'lang_asset_hostname' => 'Hostname', 'lang_asset_none' => 'There are no assets defined', + 'lang_asset_intf' => 'Number of interfaces', 'lang_assetclass_add' => 'Add assetclass', 'lang_assetclass_del' => 'Delete assetclass', diff --git a/lib.php b/lib.php index 86933f0..9fb723d 100644 --- a/lib.php +++ b/lib.php @@ -39,7 +39,7 @@ function db_load_enum($table, $column) { WHERE table_name=? AND column_name=?"; $sth = $dbh->prepare($sql); $sth->execute([$table, $column]); - return array_map(fn($x) => trim($x, "'"), explode(',', $sth->fetch(PDO::FETCH_NUM))); + return array_map(fn($x) => trim($x, "'"), explode(',', $sth->fetchColumn())); } function db_get_options_asset() { diff --git a/nat.php b/nat.php new file mode 100644 index 0000000..b9d8c26 --- /dev/null +++ b/nat.php @@ -0,0 +1,28 @@ +query($sql); +$smarty->assign("nats", $sth->fetchAll()); + +$smarty->display("nat.tpl"); + +include("footer.php"); +?> diff --git a/submit.php b/submit.php index 5400aa0..0d3d688 100644 --- a/submit.php +++ b/submit.php @@ -106,13 +106,14 @@ if (isset($_POST['add'])) { $hostname = sanitize($_POST['asset_hostname']); $assetclass_id = sanitize($_POST['assetclass_id']); $info = sanitize($_POST['asset_info']); + $intf = sanitize($_POST['asset_intf']); $sql = "INSERT INTO asset - (asset_name, asset_hostname, assetclass_id, asset_info) + (asset_name, asset_hostname, assetclass_id, asset_info, asset_intf) VALUE - (?, ?, ?, ?)"; + (?, ?, ?, ?, ?)"; $sth = $dbh->prepare($sql); - $sth->execute([$name, $hostname, $assetclass_id, $info]); + $sth->execute([$name, $hostname, $assetclass_id, $info, $intf]); header_location("assetview.php?asset_id=" . $dbh->lastInsertId()); break; @@ -528,15 +529,18 @@ if (isset($_POST['edit'])) { $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']); $sql = "UPDATE asset SET asset_name=?, asset_info=?, asset_hostname=?, - assetclass_id=? + assetclass_id=?, asset_intf=? WHERE asset_id=?"; $sth = $dbh->prepare($sql); - $sth->execute([$asset_name, $asset_info, $asset_hostname, $assetclass_id, $asset_id]); + $sth->execute([$asset_name, $asset_info, $asset_hostname, + $assetclass_id, $asset_intf, + $asset_id]); header_location("assetview.php?asset_id=" . $asset_id); diff --git a/tpl/assetadd.tpl b/tpl/assetadd.tpl index eeb0194..7ed81a4 100644 --- a/tpl/assetadd.tpl +++ b/tpl/assetadd.tpl @@ -46,6 +46,14 @@ + + + {$lang_asset_intf} + + + + + diff --git a/tpl/assetedit.tpl b/tpl/assetedit.tpl index 2abfb14..d674c0e 100644 --- a/tpl/assetedit.tpl +++ b/tpl/assetedit.tpl @@ -48,6 +48,14 @@ + + + +
+ {$lang_asset_intf} + + +
diff --git a/tpl/assetview.tpl b/tpl/assetview.tpl index a64d897..67bf67c 100644 --- a/tpl/assetview.tpl +++ b/tpl/assetview.tpl @@ -44,6 +44,14 @@ {$asset->asset_info} + + + +
+ {$lang_asset_intf} + + {$asset->asset_intf} +
diff --git a/tpl/nat.tpl b/tpl/nat.tpl new file mode 100644 index 0000000..2d9ab1e --- /dev/null +++ b/tpl/nat.tpl @@ -0,0 +1,50 @@ + + + + + +
+ {$lang_nat_rules} ({$nats|@count}) + +   +
+ + + + + + + + +{foreach item=nat from=$nats} + + + + + +{foreachelse} + + + +{/foreach} +
+ {$lang_nat} + + {$lang_source} (ext) + + {$lang_target} (int) + + {$lang_nat_type} +
+ Rule #{$nat.id} {$nat.description} + + {$nat.node_ip_ext} +{if $nat.port_ext}:{$nat.port_ext}{/if} + + {$nat.node_ip_int} +{if $nat.port_int}:{$nat.port_int}{/if} + + {$nat.nat_type} +
+ {$lang_nat_none} +
diff --git a/tpl/useradd.tpl b/tpl/useradd.tpl index 4a9d588..43f5026 100644 --- a/tpl/useradd.tpl +++ b/tpl/useradd.tpl @@ -47,5 +47,13 @@ + + + {$lang_user_realm} + + + {html_radios name=user_realm values=$realm_ids output=$realm_names selected=$realm_selected} + + diff --git a/tpl/userview.tpl b/tpl/userview.tpl index b774467..ff5a7bb 100644 --- a/tpl/userview.tpl +++ b/tpl/userview.tpl @@ -19,14 +19,6 @@   - - - {$lang_user_realm} - - - {$user_realm} - - @@ -49,7 +41,7 @@ {$lang_user_realm} - {$user_realm} + {$user->realm} diff --git a/useradd.php b/useradd.php index 043c8a2..fe1e136 100644 --- a/useradd.php +++ b/useradd.php @@ -9,7 +9,13 @@ SPDX-License-Identifier: GPL-3.0-or-later include("includes.php"); include("header.php"); - + +$realms = db_load_enum('user','user_realm'); + +$smarty->assign("realm_ids", $realms); +$smarty->assign("realm_names", $realms); +$smarty->assign("realm_selected", $realms[0]); + $smarty->display("useradd.tpl"); include("footer.php");