From a79953c589c9bc9b70562d6360fe8ee5ec389278 Mon Sep 17 00:00:00 2001
From: Alexandre <146840804+alex001x@users.noreply.github.com>
Date: Tue, 6 May 2025 00:59:03 +0200
Subject: [PATCH 01/25] feature_managementhdd
---
classes/DeviceTemplate.class.php | 67 +++++++++++
classes/People.class.php | 52 +++++----
classes/hdd.class.php | 192 +++++++++++++++++++++++++++++++
configuration.php | 10 ++
db-23.04-to-24.01.sql | 24 ++++
device_templates.php | 26 +++++
devices.php | 17 ++-
managementhdd.php | 103 +++++++++++++++++
usermgr.php | 3 +
9 files changed, 470 insertions(+), 24 deletions(-)
create mode 100644 classes/hdd.class.php
create mode 100644 managementhdd.php
diff --git a/classes/DeviceTemplate.class.php b/classes/DeviceTemplate.class.php
index d4b62b29d..ef7a67a8e 100644
--- a/classes/DeviceTemplate.class.php
+++ b/classes/DeviceTemplate.class.php
@@ -40,6 +40,9 @@ class DeviceTemplate {
var $SNMPVersion;
var $CustomValues;
var $GlobalID;
+ //for feature management hdd at the bottom of the page
+ public $EnableHDDFeature = 0;
+ public $HDDCount = 0;
public function __construct($dtid=false){
if($dtid){
@@ -748,6 +751,70 @@ static function getAvailableImages(){
}
return $array;
}
+
+ // method for feature management hdd
+ //HDD data is a logical complement to the equipment model. It depends directly on the TemplateID.
+ public function UpdateTemplateHDD() {
+ global $dbh;
+
+ $EnableHDDFeature = isset($_POST['EnableHDDFeature']) ? intval($_POST['EnableHDDFeature']) : 0;
+ $HDDCount = isset($_POST['HDDCount']) ? intval($_POST['HDDCount']) : 0;
+
+ $check = $dbh->prepare("SELECT COUNT(*) FROM fac_DeviceTemplateHdd WHERE TemplateID = ?");
+ $check->execute([$this->TemplateID]);
+
+ if ($check->fetchColumn() > 0) {
+ $sql = "UPDATE fac_DeviceTemplateHdd SET EnableHDDFeature = ?, HDDCount = ? WHERE TemplateID = ?";
+ $dbh->prepare($sql)->execute([$EnableHDDFeature, $HDDCount, $this->TemplateID]);
+ } else {
+ $sql = "INSERT INTO fac_DeviceTemplateHdd (TemplateID, EnableHDDFeature, HDDCount) VALUES (?, ?, ?)";
+ $dbh->prepare($sql)->execute([$this->TemplateID, $EnableHDDFeature, $HDDCount]);
+ }
+ }
+
+ public function LoadHDDConfig() {
+ global $dbh;
+
+ $this->EnableHDDFeature = 0;
+ $this->HDDCount = 0;
+
+ if ($this->TemplateID > 0) {
+ $sql = "SELECT EnableHDDFeature, HDDCount FROM fac_DeviceTemplateHdd WHERE TemplateID = ?";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$this->TemplateID]);
+ if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $this->EnableHDDFeature = $row['EnableHDDFeature'];
+ $this->HDDCount = $row['HDDCount'];
+ }
+ }
+ }
+
+ public function DeleteTemplateHDD() {
+ global $dbh;
+
+ if ($this->TemplateID > 0) {
+ $sql = "DELETE FROM fac_DeviceTemplateHdd WHERE TemplateID = ?";
+ $stmt = $dbh->prepare($sql);
+ return $stmt->execute([$this->TemplateID]);
+ }
+ return false;
+ }
+
+ public function ExportTemplateHDD($asJSON = false) {
+ global $dbh;
+
+ $sql = "SELECT EnableHDDFeature, HDDCount FROM fac_DeviceTemplateHdd WHERE TemplateID = ?";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$this->TemplateID]);
+
+ if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ return $asJSON ? json_encode($row) : $row;
+ } else {
+ $data = ['EnableHDDFeature' => 0, 'HDDCount' => 0];
+ return $asJSON ? json_encode($data) : $data;
+ }
+ }
+
}
?>
diff --git a/classes/People.class.php b/classes/People.class.php
index b53378def..522bdf86c 100644
--- a/classes/People.class.php
+++ b/classes/People.class.php
@@ -31,27 +31,28 @@ class People {
things greatly.
*/
- var $PersonID;
- var $UserID;
- var $LastName;
- var $FirstName;
- var $Phone1;
- var $Phone2;
- var $countryCode;
- var $Email;
- var $AdminOwnDevices;
- var $ReadAccess;
- var $WriteAccess;
- var $DeleteAccess;
- var $ContactAdmin;
- var $RackRequest;
- var $RackAdmin;
- var $BulkOperations;
- var $SiteAdmin;
- var $APIKey;
- var $Disabled;
- var $LastActivity;
- var $ExpirationDate;
+ public $PersonID;
+ public $UserID;
+ public $LastName;
+ public $FirstName;
+ public $Phone1;
+ public $Phone2;
+ public $countryCode;
+ public $Email;
+ public $AdminOwnDevices;
+ public $ReadAccess;
+ public $WriteAccess;
+ public $DeleteAccess;
+ public $ContactAdmin;
+ public $RackRequest;
+ public $RackAdmin;
+ public $BulkOperations;
+ public $SiteAdmin;
+ public $APIKey;
+ public $Disabled;
+ public $LastActivity;
+ public $ExpirationDate;
+ public $ManageHDD;
function MakeSafe(){
$this->PersonID=intval($this->PersonID);
@@ -71,6 +72,7 @@ function MakeSafe(){
$this->RackAdmin=intval($this->RackAdmin);
$this->BulkOperations=intval($this->BulkOperations);
$this->SiteAdmin=intval($this->SiteAdmin);
+ $this->ManageHDD=intval($this->ManageHDD);
$this->Disabled=intval($this->Disabled);
$this->ExpirationDate=sanitize($this->ExpirationDate);
}
@@ -95,6 +97,7 @@ function MakeDisplay(){
$this->RackAdmin=intval($this->RackAdmin);
$this->BulkOperations=intval($this->BulkOperations);
$this->SiteAdmin=intval($this->SiteAdmin);
+ $this->ManageHDD=intval($this->ManageHDD);
$this->Disabled=intval($this->Disabled);
}
@@ -117,6 +120,7 @@ static function RowToObject($row){
$person->RackAdmin=$row["RackAdmin"];
$person->BulkOperations=$row["BulkOperations"];
$person->SiteAdmin=$row["SiteAdmin"];
+ $person->ManageHDD=$row["ManageHDD"];
$person->APIKey=$row["APIKey"];
$person->Disabled=$row["Disabled"];
$person->LastActivity=$row["LastActivity"];
@@ -164,6 +168,7 @@ function revokeAll() {
$this->ContactAdmin = false;
$this->BulkOperations = false;
$this->SiteAdmin = false;
+ $this->ManageHDD = false;
}
function canRead( $Owner ) {
@@ -208,7 +213,7 @@ function CreatePerson() {
AdminOwnDevices=$this->AdminOwnDevices, ReadAccess=$this->ReadAccess,
WriteAccess=$this->WriteAccess, DeleteAccess=$this->DeleteAccess,
ContactAdmin=$this->ContactAdmin, RackRequest=$this->RackRequest,
- RackAdmin=$this->RackAdmin, BulkOperations=$this->BulkOperations, SiteAdmin=$this->SiteAdmin,
+ RackAdmin=$this->RackAdmin, BulkOperations=$this->BulkOperations, SiteAdmin=$this->SiteAdmin,ManageHDD=$this->ManageHDD,
APIKey=\"$this->APIKey\", Disabled=$this->Disabled, ExpirationDate=\"$this->ExpirationDate\";";
if(!$this->query($sql)){
@@ -233,6 +238,7 @@ static function Current(){
$cperson->ReadAccess=true;
$cperson->WriteAccess=true;
$cperson->SiteAdmin=true;
+ $cperson->ManageHDD=true;
$cperson->Disabled=false;
}elseif(AUTHENTICATION=="Apache"){
if(!isset($_SERVER["REMOTE_USER"])){
@@ -451,7 +457,7 @@ function UpdatePerson() {
AdminOwnDevices=$this->AdminOwnDevices, ReadAccess=$this->ReadAccess,
WriteAccess=$this->WriteAccess, DeleteAccess=$this->DeleteAccess,
ContactAdmin=$this->ContactAdmin, RackRequest=$this->RackRequest,
- RackAdmin=$this->RackAdmin, BulkOperations=$this->BulkOperations, SiteAdmin=$this->SiteAdmin,
+ RackAdmin=$this->RackAdmin, BulkOperations=$this->BulkOperations, SiteAdmin=$this->SiteAdmin,ManageHDD=$this->ManageHDD,
APIKey=\"$this->APIKey\", ExpirationDate=\"$formattedDate\", Disabled=$this->Disabled
WHERE PersonID=$this->PersonID;";
diff --git a/classes/hdd.class.php b/classes/hdd.class.php
new file mode 100644
index 000000000..4d1d148b7
--- /dev/null
+++ b/classes/hdd.class.php
@@ -0,0 +1,192 @@
+HDDID = intval($this->HDDID);
+ $this->DeviceID = intval($this->DeviceID);
+ $this->Label = sanitize($this->Label);
+ $this->SerialNo = sanitize($this->SerialNo);
+ $this->Status = sanitize($this->Status);
+ $this->Size = intval($this->Size);
+ $this->TypeMedia = sanitize($this->TypeMedia);
+ $this->Note = sanitize($this->Note);
+ }
+
+ function MakeDisplay() {
+ // Si besoin d'afficher des données formatées
+ }
+
+ static function RowToObject($row){
+ $hdd = new HDD();
+ foreach($row as $prop => $val){
+ $hdd->$prop = $val;
+ }
+ $hdd->MakeDisplay();
+ return $hdd;
+ }
+
+ function CreateHDD() {
+ global $dbh;
+
+ $this->MakeSafe();
+
+ $sql = "INSERT INTO fac_HDD (DeviceID, Label, SerialNo, Status, Size, TypeMedia, DateAdd, StatusDestruction, Note)
+ VALUES (:DeviceID, :Label, :SerialNo, :Status, :Size, :TypeMedia, NOW(), 'none', :Note)";
+
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([
+ ":DeviceID" => $this->DeviceID,
+ ":Label" => $this->Label,
+ ":SerialNo" => $this->SerialNo,
+ ":Status" => $this->Status,
+ ":Size" => $this->Size,
+ ":TypeMedia" => $this->TypeMedia,
+ ":Note" => $this->Note
+ ]);
+
+ $this->HDDID = $dbh->lastInsertId();
+ }
+
+ function UpdateHDD() {
+ global $dbh;
+
+ $this->MakeSafe();
+
+ $sql = "UPDATE fac_HDD SET
+ DeviceID = :DeviceID,
+ Label = :Label,
+ SerialNo = :SerialNo,
+ Status = :Status,
+ Size = :Size,
+ TypeMedia = :TypeMedia,
+ Note = :Note
+ WHERE HDDID = :HDDID";
+
+ $stmt = $dbh->prepare($sql);
+ return $stmt->execute([
+ ":DeviceID" => $this->DeviceID,
+ ":Label" => $this->Label,
+ ":SerialNo" => $this->SerialNo,
+ ":Status" => $this->Status,
+ ":Size" => $this->Size,
+ ":TypeMedia" => $this->TypeMedia,
+ ":Note" => $this->Note,
+ ":HDDID" => $this->HDDID
+ ]);
+ }
+
+ function DeleteHDD() {
+ global $dbh;
+
+ $this->MakeSafe();
+
+ $sql = "DELETE FROM fac_HDD WHERE HDDID = :HDDID";
+
+ $stmt = $dbh->prepare($sql);
+ return $stmt->execute([":HDDID" => $this->HDDID]);
+ }
+
+ function SendForDestruction($note = '') {
+ global $dbh;
+
+ $this->MakeSafe();
+ $note = sanitize($note);
+
+ $sql = "UPDATE fac_HDD SET
+ Status = 'pending_destruction',
+ StatusDestruction = 'pending',
+ DateWithdrawn = NOW(),
+ Note = CONCAT(Note, ' ', :Note)
+ WHERE HDDID = :HDDID";
+
+ $stmt = $dbh->prepare($sql);
+ return $stmt->execute([
+ ":HDDID" => $this->HDDID,
+ ":Note" => $note
+ ]);
+ }
+
+ function MarkAsDestroyed($note = '') {
+ global $dbh;
+
+ $this->MakeSafe();
+ $note = sanitize($note);
+
+ $sql = "UPDATE fac_HDD SET
+ Status = 'destroyed_h2',
+ StatusDestruction = 'destroyed',
+ DateDestruction = NOW(),
+ Note = CONCAT(Note, ' ', :Note)
+ WHERE HDDID = :HDDID";
+
+ $stmt = $dbh->prepare($sql);
+ return $stmt->execute([
+ ":HDDID" => $this->HDDID,
+ ":Note" => $note
+ ]);
+ }
+
+ static function GetHDDByDevice($DeviceID) {
+ global $dbh;
+
+ $DeviceID = intval($DeviceID);
+
+ $sql = "SELECT * FROM fac_HDD WHERE DeviceID = :DeviceID ORDER BY Label ASC";
+
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([":DeviceID" => $DeviceID]);
+
+ $hddList = array();
+ while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
+ $hddList[] = self::RowToObject($row);
+ }
+
+ return $hddList;
+ }
+
+ static function SearchBySerial($SerialNo) {
+ global $dbh;
+
+ $SerialNo = "%".sanitize($SerialNo)."%";
+
+ $sql = "SELECT * FROM fac_HDD WHERE SerialNo LIKE :SerialNo";
+
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([":SerialNo" => $SerialNo]);
+
+ $hddList = array();
+ while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
+ $hddList[] = self::RowToObject($row);
+ }
+
+ return $hddList;
+ }
+
+ static function GetPendingDestruction() {
+ global $dbh;
+
+ $sql = "SELECT * FROM fac_HDD WHERE StatusDestruction = 'pending'";
+
+ $stmt = $dbh->query($sql);
+
+ $hddList = array();
+ while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
+ $hddList[] = self::RowToObject($row);
+ }
+
+ return $hddList;
+ }
+}
+?>
diff --git a/configuration.php b/configuration.php
index 029605263..e96fb2d80 100644
--- a/configuration.php
+++ b/configuration.php
@@ -1928,6 +1928,16 @@ function uploadifive() {
+
+
+
+
+
+
+
diff --git a/db-23.04-to-24.01.sql b/db-23.04-to-24.01.sql
index 22c9ac1e1..9c8f6bac0 100755
--- a/db-23.04-to-24.01.sql
+++ b/db-23.04-to-24.01.sql
@@ -3,3 +3,27 @@
---
UPDATE fac_Config set Value="24.01" WHERE Parameter="Version";
+INSERT INTO fac_Config (Parameter, Value) VALUES ('feature_hdd', 'disabled')
+ON DUPLICATE KEY UPDATE Value = Value;
+ALTER TABLE fac_People ADD COLUMN ManageHDD TINYINT(1) DEFAULT 0;
+CREATE TABLE fac_DeviceTemplateHdd (
+ TemplateID INT NOT NULL,
+ EnableHDDFeature TINYINT(1) DEFAULT 0,
+ HDDCount INT DEFAULT 0,
+ PRIMARY KEY (TemplateID)
+);
+CREATE TABLE fac_HDD (
+ HDDID INT NOT NULL AUTO_INCREMENT,
+ DeviceID INT NOT NULL,
+ Label VARCHAR(100),
+ SerialNo VARCHAR(100) UNIQUE,
+ Status ENUM('on','off','replace','pending_destruction','destroyed_h2') DEFAULT 'on',
+ Size INT, -- en Go
+ TypeMedia ENUM('SATA', 'SCSI', 'SD'),
+ DateAdd DATETIME DEFAULT CURRENT_TIMESTAMP,
+ DateWithdrawn DATETIME,
+ DateDestruction DATETIME,
+ StatusDestruction ENUM('none', 'pending', 'destroyed'),
+ Note TEXT,
+ PRIMARY KEY (HDDID)
+);
\ No newline at end of file
diff --git a/device_templates.php b/device_templates.php
index a09fcc480..f42cea5ee 100644
--- a/device_templates.php
+++ b/device_templates.php
@@ -65,6 +65,7 @@
}
// Transfers are done, delete this shit
$template->DeleteTemplate();
+ $tempplate->DeleteTemplateHDD(); // feature management hdd: delete
}
echo '1';
exit;
@@ -82,6 +83,7 @@
$template->TemplateID=$_REQUEST['TemplateID'];
$template->GetTemplateByID();
$deviceList = Device::GetDevicesByTemplate( $template->TemplateID );
+ $Template->LoadHDDConfig(); // feature management hdd: Load
}
if(isset($_POST['action'])){
@@ -240,6 +242,7 @@ function updatecdu($template,$status){
if($template->CreateTemplate()){
$oldstatus=$status;
$status=UpdateSlotsPorts($template,$status);
+ $template->UpdateTemplateHDD(); // feature management hdd
if($oldstatus==$status){
$status=UpdateCustomValues($template,$status);
}
@@ -255,6 +258,7 @@ function updatecdu($template,$status){
$status=($template->UpdateTemplate())?__("Updated"):__("Error updating template");
if($status==__("Updated")){
$status=UpdateSlotsPorts($template,$status);
+ $template->UpdateTemplateHDD();// feature management hdd
}
if($status==__("Updated")){
$status=UpdateCustomValues($template,$status);
@@ -271,6 +275,7 @@ function updatecdu($template,$status){
$status=($template->UpdateTemplate())?__("Updated"):__("Error updating template");
if ($status==__("Updated")){
$status=UpdateSlotsPorts($template,$status);
+ $template->UpdateTemplateHDD();// feature management hdd
}
if ($status==__("Updated")){
$status=UpdateCustomValues($template,$status);
@@ -288,6 +293,7 @@ function updatecdu($template,$status){
$status=($template->UpdateTemplate())?__("Updated"):__("Error");
if ($status==__("Updated")){
$status=UpdateSlotsPorts($template,$status);
+ $template->UpdateTemplateHDD();// feature management hdd
}
if ($status==__("Updated")){
$status=UpdateCustomValues($template,$status);
@@ -826,6 +832,26 @@ function applynames(inputs,portnames,e){
';
+// feature management hdd
+if($config->ParameterArray['feature_hdd'] == 'enabled'){
+ echo '
+
+
+
+
+
+
+
+
+
+
+
+
';
+}
+
foreach($dcaList as $dca) {
$templatedcaChecked = "";
$templatedcaDisabled = "";
diff --git a/devices.php b/devices.php
index 26d2e822d..992f6d5d4 100644
--- a/devices.php
+++ b/devices.php
@@ -2065,7 +2065,22 @@ function setPreferredLayout() {
';
}
-
+ //feature management hdd
+ if(
+ $config->ParameterArray['feature_hdd'] == 'enabled' &&
+ $template->EnableHDDFeature == 1 &&
+ $dev->DeviceID > 0 &&
+ $person->ManageHDD == 1
+ ){
+ echo '
';
+ }
+ //device images
echo '
From 78e0f06bd6dd4682f536b0f4f79038df34ded8c2 Mon Sep 17 00:00:00 2001
From: Alexandre <146840804+alex001x@users.noreply.github.com>
Date: Wed, 7 May 2025 19:27:00 +0200
Subject: [PATCH 02/25] feature_managementhdd
---
classes/hdd.class.php | 127 ++++++++++++++++++++++++++++++++++++++----
hdd_log_view.php | 71 +++++++++++++++++++++++
managementhdd.php | 80 ++++++++++++++++++++++----
savehdd.php | 91 ++++++++++++++++++++++++++++++
4 files changed, 347 insertions(+), 22 deletions(-)
create mode 100644 hdd_log_view.php
create mode 100644 savehdd.php
diff --git a/classes/hdd.class.php b/classes/hdd.class.php
index 4d1d148b7..7eff65684 100644
--- a/classes/hdd.class.php
+++ b/classes/hdd.class.php
@@ -1,17 +1,17 @@
HDDID = intval($this->HDDID);
@@ -189,4 +189,107 @@ static function GetPendingDestruction() {
return $hddList;
}
}
+
+ private static function logAction($action, $HDDID) {
+ global $person, $dbh;
+ $sql = "INSERT INTO fac_GenericLog (UserID, Time, ItemType, ItemID, LogText) VALUES (?, NOW(), 'HDD', ?, ?)";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$person->UserID, $HDDID, $action]);
+ }
+
+ public static function WithdrawByID($id) {
+ global $dbh;
+ $sql = "UPDATE fac_HDD SET Status='pending_destruction', dateWithdrawn=NOW() WHERE HDDID=?";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$id]);
+ self::logAction("Withdrawn (pending destruction)", $id);
+ }
+
+ public static function DeleteByID($id) {
+ global $dbh;
+ $sql = "DELETE FROM fac_HDD WHERE HDDID=?";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$id]);
+ self::logAction("Deleted", $id);
+ }
+
+ public static function MarkDestroyed($id) {
+ global $dbh;
+ $sql = "UPDATE fac_HDD SET StatusDestruction='destroyed', dateDestruction=NOW() WHERE HDDID=?";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$id]);
+ self::logAction("Marked as destroyed", $id);
+ }
+
+ public static function ReassignToDevice($id, $deviceID) {
+ global $dbh;
+ $sql = "UPDATE fac_HDD SET Status='on', DeviceID=?, dateWithdrawn=NULL, dateDestruction=NULL, StatusDestruction=NULL WHERE HDDID=?";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$deviceID, $id]);
+ self::logAction("Reassigned to DeviceID $deviceID", $id);
+ }
+
+ public static function MarkAsSpare($id) {
+ global $dbh;
+ $sql = "UPDATE fac_HDD SET Status='spare' WHERE HDDID=?";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$id]);
+ self::logAction("Marked as spare", $id);
+ }
+
+ public static function CreateEmpty($deviceID) {
+ global $dbh;
+ $sql = "INSERT INTO fac_HDD (DeviceID, Label, SerialNo, Status, TypeMedia, Size, dateAdd) VALUES (?, '', '', 'on', 'SATA', 0, NOW())";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$deviceID]);
+ $id = $dbh->lastInsertId();
+ self::logAction("Created new empty HDD", $id);
+ }
+
+ public static function DuplicateToEmptySlots($sourceHDDID) {
+ global $dbh;
+ $sql = "SELECT * FROM fac_HDD WHERE HDDID=?";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$sourceHDDID]);
+ if (!$hdd = $stmt->fetch(PDO::FETCH_ASSOC)) return;
+
+ $sql = "SELECT DeviceID FROM fac_HDD WHERE HDDID=?";
+ $devID = $dbh->prepare($sql);
+ $devID->execute([$sourceHDDID]);
+ $DeviceID = $devID->fetchColumn();
+
+ $sql = "SELECT HDDCount FROM fac_DeviceTemplateHdd dt INNER JOIN fac_Device d ON d.TemplateID=dt.TemplateID WHERE d.DeviceID=?";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$DeviceID]);
+ $max = $stmt->fetchColumn();
+
+ $sql = "SELECT COUNT(*) FROM fac_HDD WHERE DeviceID=?";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$DeviceID]);
+ $current = $stmt->fetchColumn();
+
+ $remaining = $max - $current;
+ if ($remaining <= 0) return;
+
+ $sql = "INSERT INTO fac_HDD (DeviceID, Label, SerialNo, Status, TypeMedia, Size, dateAdd) VALUES (?, ?, '', ?, ?, ?, NOW())";
+ $stmt = $dbh->prepare($sql);
+ for ($i = 0; $i < $remaining; $i++) {
+ $stmt->execute([$DeviceID, $hdd['Label'], $hdd['Status'], $hdd['TypeMedia'], $hdd['Size']]);
+ $id = $dbh->lastInsertId();
+ self::logAction("Duplicated from HDDID $sourceHDDID", $id);
+ }
+ }
+
+ public static function ExportPendingDestruction($deviceID) {
+ global $dbh;
+ $sql = "SELECT Label, SerialNo, dateWithdrawn FROM fac_HDD WHERE DeviceID=? AND Status='pending_destruction'";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute([$deviceID]);
+
+ echo "Label\tSerial Number\tDate Withdrawn\n";
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ echo "{$row['Label']}\t{$row['SerialNo']}\t{$row['dateWithdrawn']}\n";
+ }
+ }
+}
?>
diff --git a/hdd_log_view.php b/hdd_log_view.php
new file mode 100644
index 000000000..80e60a318
--- /dev/null
+++ b/hdd_log_view.php
@@ -0,0 +1,71 @@
+ManageHDD) {
+ header("Location: index.php");
+ exit;
+}
+
+$deviceID = isset($_GET['DeviceID']) ? intval($_GET['DeviceID']) : 0;
+
+if (!$deviceID) {
+ echo __("DeviceID is required");
+ exit;
+}
+
+$sql = "
+ SELECT g.Time, g.UserID, g.LogText, h.Label, h.SerialNo
+ FROM fac_GenericLog g
+ JOIN fac_HDD h ON g.ItemID = h.hddID
+ WHERE g.ItemType = 'HDD' AND h.DeviceID = ?
+ ORDER BY g.Time DESC
+";
+
+$stmt = $dbh->prepare($sql);
+$stmt->execute([$deviceID]);
+$logEntries = $stmt->fetchAll(PDO::FETCH_ASSOC);
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+ |
+ |
+ |
+ |
+
+
+
+
+
+ |
+ |
+ |
+ |
+ |
+
+
+
+
+
+
+
+
+
diff --git a/managementhdd.php b/managementhdd.php
index 0acaeba93..16f09550a 100644
--- a/managementhdd.php
+++ b/managementhdd.php
@@ -28,7 +28,13 @@
$template->GetTemplateByID();
$template->LoadHDDConfig();
+if (!$template->EnableHDDFeature) {
+ echo '
'.__("This equipment does not support HDD management.").'
';
+ exit;
+}
+
$hddList = HDD::GetHDDByDevice($device->DeviceID);
+$hddWaitList = HDD::GetRetiredHDDByDevice($device->DeviceID);
?>
@@ -38,11 +44,13 @@
openDCIM Data Center Inventory
-
+
@@ -54,9 +62,11 @@
+
+
diff --git a/savehdd.php b/savehdd.php
new file mode 100644
index 000000000..a85b3f7ee
--- /dev/null
+++ b/savehdd.php
@@ -0,0 +1,91 @@
+ManageHDD) {
+ header("Location: index.php");
+ exit;
+}
+
+$deviceID = isset($_POST['DeviceID']) ? intval($_POST['DeviceID']) : 0;
+
+if (!$deviceID) {
+ header("Location: index.php");
+ exit;
+}
+
+$action = isset($_POST['action']) ? $_POST['action'] : '';
+
+switch (true) {
+ case preg_match('/^update_(\d+)$/', $action, $m):
+ $hdd = new HDD();
+ $hdd->HDDID = $m[1];
+ $hdd->Label = $_POST['Label'][$hdd->HDDID];
+ $hdd->SerialNo = $_POST['SerialNo'][$hdd->HDDID];
+ $hdd->Status = $_POST['Status'][$hdd->HDDID];
+ $hdd->TypeMedia = $_POST['TypeMedia'][$hdd->HDDID];
+ $hdd->Size = $_POST['Size'][$hdd->HDDID];
+ $hdd->Update();
+ break;
+
+ case preg_match('/^remove_(\d+)$/', $action, $m):
+ $hdd = new HDD();
+ $hdd->HDDID = $m[1];
+ $hdd->Withdraw();
+ break;
+
+ case preg_match('/^delete_(\d+)$/', $action, $m):
+ $hdd = new HDD();
+ $hdd->HDDID = $m[1];
+ $hdd->Delete();
+ break;
+
+ case preg_match('/^duplicate_(\d+)$/', $action, $m):
+ HDD::DuplicateToEmptySlots($m[1]);
+ break;
+
+ case preg_match('/^destroy_(\d+)$/', $action, $m):
+ HDD::MarkDestroyed($m[1]);
+ break;
+
+ case preg_match('/^reassign_(\d+)$/', $action, $m):
+ HDD::ReassignToDevice($m[1], $deviceID);
+ break;
+
+ case preg_match('/^spare_(\d+)$/', $action, $m):
+ HDD::MarkAsSpare($m[1]);
+ break;
+
+ case $action === "add_hdd":
+ HDD::CreateEmpty($deviceID);
+ break;
+
+ case $action === "bulk_remove":
+ foreach ($_POST['select_active'] ?? [] as $id) {
+ HDD::WithdrawByID($id);
+ }
+ break;
+
+ case $action === "bulk_delete":
+ foreach ($_POST['select_active'] ?? [] as $id) {
+ HDD::DeleteByID($id);
+ }
+ break;
+
+ case $action === "bulk_destroy":
+ foreach ($_POST['select_pending'] ?? [] as $id) {
+ HDD::MarkDestroyed($id);
+ }
+ break;
+
+ case $action === "print_list":
+ header('Content-Type: application/vnd.ms-excel');
+ header('Content-Disposition: attachment; filename="HDD_List_Device_' . $deviceID . '.xls"');
+ HDD::ExportPendingDestruction($deviceID);
+ exit;
+ break;
+}
+
+header("Location: managementhdd.php?DeviceID=$deviceID");
+exit;
From 0b5beac3de93b47b2c6cd3b8dc24eccf88a8da96 Mon Sep 17 00:00:00 2001
From: Alexandre <146840804+alex001x@users.noreply.github.com>
Date: Wed, 7 May 2025 19:31:51 +0200
Subject: [PATCH 03/25] feature_managementhdd
---
devices.php | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/devices.php b/devices.php
index 992f6d5d4..5107ae19b 100644
--- a/devices.php
+++ b/devices.php
@@ -2052,19 +2052,9 @@ function setPreferredLayout() {DeviceType){$selected=" selected";}else{$selected="";}
print "\t\t\t\n";
}
-echo '
+ echo '
-
-
-';
-
- if ($dev->DeviceType=='Sensor'){
-echo '';
- }
+ ';
//feature management hdd
if(
$config->ParameterArray['feature_hdd'] == 'enabled' &&
@@ -2072,14 +2062,24 @@ function setPreferredLayout() {DeviceID > 0 &&
$person->ManageHDD == 1
){
- echo '';
+
+ if ($dev->DeviceType=='Sensor'){
+echo '';
+ ';
}
+
//device images
echo '';
diff --git a/managementhdd.php b/managementhdd.php
index 16f09550a..e6f38f551 100644
--- a/managementhdd.php
+++ b/managementhdd.php
@@ -1,4 +1,7 @@
- |
+ |
$i |
- |
- |
- |