mirror of
https://gitlab.com/ArkHost/WHMCS-Password-Toggle-Plus.git
synced 2026-07-24 07:45:52 +02:00
Update hooks.php
This commit is contained in:
@@ -19,22 +19,18 @@ function passwordtoggleplus_show_passwords($vars) {
|
|||||||
->value('packageid');
|
->value('packageid');
|
||||||
|
|
||||||
if ($pid) {
|
if ($pid) {
|
||||||
// Get product-specific custom fields
|
|
||||||
$productFields = Capsule::table('tblcustomfields')
|
$productFields = Capsule::table('tblcustomfields')
|
||||||
->where('type', 'product')
|
->where('type', 'product')
|
||||||
->where('relid', $pid)
|
->where('relid', $pid)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
// Get global custom fields
|
|
||||||
$globalFields = Capsule::table('tblcustomfields')
|
$globalFields = Capsule::table('tblcustomfields')
|
||||||
->where('type', 'client')
|
->where('type', 'client')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
// Combine both sets of fields
|
|
||||||
$fields = collect($productFields)->merge($globalFields);
|
$fields = collect($productFields)->merge($globalFields);
|
||||||
|
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
// Check for various password-related field names
|
|
||||||
$fieldNameLower = strtolower($field->fieldname);
|
$fieldNameLower = strtolower($field->fieldname);
|
||||||
if (strpos($fieldNameLower, 'password') !== false ||
|
if (strpos($fieldNameLower, 'password') !== false ||
|
||||||
strpos($fieldNameLower, 'pass') !== false ||
|
strpos($fieldNameLower, 'pass') !== false ||
|
||||||
@@ -46,9 +42,11 @@ function passwordtoggleplus_show_passwords($vars) {
|
|||||||
->value('value');
|
->value('value');
|
||||||
|
|
||||||
if ($value) {
|
if ($value) {
|
||||||
// Decrypt the password value
|
|
||||||
$decryptedValue = decrypt($value);
|
$decryptedValue = decrypt($value);
|
||||||
die($decryptedValue ?? 'No password value');
|
// Convert HTML entities to their actual characters before output
|
||||||
|
$cleanValue = html_entity_decode($decryptedValue, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||||
|
header('Content-Type: text/plain');
|
||||||
|
die($cleanValue ?? 'No password value');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,6 +74,7 @@ function passwordtoggleplus_show_passwords($vars) {
|
|||||||
}
|
}
|
||||||
.password-field {
|
.password-field {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
|
white-space: pre;
|
||||||
}
|
}
|
||||||
.copy-tooltip {
|
.copy-tooltip {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -94,25 +93,24 @@ function passwordtoggleplus_show_passwords($vars) {
|
|||||||
function modifyPasswordFields() {
|
function modifyPasswordFields() {
|
||||||
console.log("Starting password field modification...");
|
console.log("Starting password field modification...");
|
||||||
|
|
||||||
// Find password fields in both additional info and custom fields sections
|
|
||||||
const rows = document.querySelectorAll("#additionalinfo .row, .custom-field-row");
|
const rows = document.querySelectorAll("#additionalinfo .row, .custom-field-row");
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
const label = row.querySelector("strong, .field-label");
|
const label = row.querySelector("strong, .field-label");
|
||||||
if (label && /password|pass|pwd/i.test(label.textContent.trim())) {
|
if (label && /password|pass|pwd/i.test(label.textContent.trim())) {
|
||||||
console.log("Found password row:", label.textContent.trim());
|
console.log("Found password row:", label.textContent.trim());
|
||||||
|
|
||||||
// Get the value cell
|
|
||||||
const valueCell = row.querySelector(".col-sm-7, .field-value");
|
const valueCell = row.querySelector(".col-sm-7, .field-value");
|
||||||
if (valueCell) {
|
if (valueCell) {
|
||||||
console.log("Found value cell");
|
console.log("Found value cell");
|
||||||
|
|
||||||
// Create new elements
|
|
||||||
const container = document.createElement("div");
|
const container = document.createElement("div");
|
||||||
container.className = "password-container";
|
container.className = "password-container";
|
||||||
container.style.position = "relative";
|
container.style.position = "relative";
|
||||||
|
|
||||||
const passwordSpan = document.createElement("span");
|
const passwordSpan = document.createElement("pre");
|
||||||
passwordSpan.className = "password-field";
|
passwordSpan.className = "password-field";
|
||||||
|
passwordSpan.style.margin = "0";
|
||||||
|
passwordSpan.style.display = "inline";
|
||||||
passwordSpan.textContent = "******";
|
passwordSpan.textContent = "******";
|
||||||
|
|
||||||
const toggleBtn = document.createElement("button");
|
const toggleBtn = document.createElement("button");
|
||||||
@@ -124,21 +122,19 @@ function passwordtoggleplus_show_passwords($vars) {
|
|||||||
copyBtn.type = "button";
|
copyBtn.type = "button";
|
||||||
copyBtn.className = "password-copy";
|
copyBtn.className = "password-copy";
|
||||||
copyBtn.textContent = "Copy";
|
copyBtn.textContent = "Copy";
|
||||||
copyBtn.style.display = "none"; // Hide initially
|
copyBtn.style.display = "none";
|
||||||
|
|
||||||
const tooltip = document.createElement("span");
|
const tooltip = document.createElement("span");
|
||||||
tooltip.className = "copy-tooltip";
|
tooltip.className = "copy-tooltip";
|
||||||
tooltip.textContent = "Copied!";
|
tooltip.textContent = "Copied!";
|
||||||
tooltip.style.opacity = "0";
|
tooltip.style.opacity = "0";
|
||||||
|
|
||||||
// Add copy functionality
|
|
||||||
copyBtn.addEventListener("click", async function(e) {
|
copyBtn.addEventListener("click", async function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
const textToCopy = passwordSpan.textContent;
|
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(textToCopy);
|
await navigator.clipboard.writeText(passwordSpan.getAttribute("data-raw-password") || passwordSpan.textContent);
|
||||||
tooltip.style.opacity = "1";
|
tooltip.style.opacity = "1";
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
tooltip.style.opacity = "0";
|
tooltip.style.opacity = "0";
|
||||||
@@ -148,7 +144,6 @@ function passwordtoggleplus_show_passwords($vars) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add toggle handler
|
|
||||||
toggleBtn.addEventListener("click", function(e) {
|
toggleBtn.addEventListener("click", function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -164,6 +159,7 @@ function passwordtoggleplus_show_passwords($vars) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
passwordSpan.textContent = password;
|
passwordSpan.textContent = password;
|
||||||
|
passwordSpan.setAttribute("data-raw-password", password);
|
||||||
toggleBtn.textContent = "Hide";
|
toggleBtn.textContent = "Hide";
|
||||||
copyBtn.style.display = "inline-block";
|
copyBtn.style.display = "inline-block";
|
||||||
})
|
})
|
||||||
@@ -180,13 +176,11 @@ function passwordtoggleplus_show_passwords($vars) {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assemble and insert
|
|
||||||
container.appendChild(passwordSpan);
|
container.appendChild(passwordSpan);
|
||||||
container.appendChild(toggleBtn);
|
container.appendChild(toggleBtn);
|
||||||
container.appendChild(copyBtn);
|
container.appendChild(copyBtn);
|
||||||
container.appendChild(tooltip);
|
container.appendChild(tooltip);
|
||||||
|
|
||||||
// Clear and update the value cell
|
|
||||||
valueCell.innerHTML = "";
|
valueCell.innerHTML = "";
|
||||||
valueCell.appendChild(container);
|
valueCell.appendChild(container);
|
||||||
|
|
||||||
@@ -196,17 +190,14 @@ function passwordtoggleplus_show_passwords($vars) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the function when DOM is ready
|
|
||||||
if (document.readyState === "loading") {
|
if (document.readyState === "loading") {
|
||||||
document.addEventListener("DOMContentLoaded", modifyPasswordFields);
|
document.addEventListener("DOMContentLoaded", modifyPasswordFields);
|
||||||
} else {
|
} else {
|
||||||
modifyPasswordFields();
|
modifyPasswordFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run again after a delay to catch dynamic content
|
|
||||||
setTimeout(modifyPasswordFields, 1000);
|
setTimeout(modifyPasswordFields, 1000);
|
||||||
</script>';
|
</script>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the hook
|
|
||||||
add_hook('ClientAreaFooterOutput', 1, 'passwordtoggleplus_show_passwords');
|
add_hook('ClientAreaFooterOutput', 1, 'passwordtoggleplus_show_passwords');
|
||||||
|
|||||||
Reference in New Issue
Block a user