Add VA token copy button to extension
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
"name": "Alta Proxy Tool Bridge",
|
"name": "Alta Proxy Tool Bridge",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Send Alta session cookies to the Alta Proxy Tool desktop app.",
|
"description": "Send Alta session cookies to the Alta Proxy Tool desktop app.",
|
||||||
"permissions": ["cookies", "activeTab"],
|
"permissions": ["cookies", "activeTab", "clipboardWrite"],
|
||||||
"host_permissions": [
|
"host_permissions": [
|
||||||
"https://*.avasecurity.com/*",
|
"https://*.avasecurity.com/*",
|
||||||
"https://*.avigilon.com/*",
|
"https://*.avigilon.com/*",
|
||||||
|
|||||||
@@ -44,7 +44,13 @@ h1 {
|
|||||||
border-color: #F44336;
|
border-color: #F44336;
|
||||||
}
|
}
|
||||||
|
|
||||||
.send-btn {
|
.action-buttons {
|
||||||
|
display: grid;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary-btn,
|
||||||
|
.secondary-btn {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 10px 16px;
|
padding: 10px 16px;
|
||||||
@@ -59,11 +65,26 @@ h1 {
|
|||||||
transition: background 0.2s ease;
|
transition: background 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.send-btn:hover:not(:disabled) {
|
.primary-btn {
|
||||||
|
background: #0E7AFE;
|
||||||
|
}
|
||||||
|
|
||||||
|
.secondary-btn {
|
||||||
|
background: #2D2D30;
|
||||||
|
border: 1px solid #0E7AFE;
|
||||||
|
color: #E0E0E0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary-btn:hover:not(:disabled) {
|
||||||
background: #0A5FD9;
|
background: #0A5FD9;
|
||||||
}
|
}
|
||||||
|
|
||||||
.send-btn:disabled {
|
.secondary-btn:hover:not(:disabled) {
|
||||||
|
background: #0E7AFE;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary-btn:disabled,
|
||||||
|
.secondary-btn:disabled {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,10 @@
|
|||||||
<div class="popup-container">
|
<div class="popup-container">
|
||||||
<h1>Alta Proxy Tool</h1>
|
<h1>Alta Proxy Tool</h1>
|
||||||
<div id="tabInfo" class="tab-info">Checking tab...</div>
|
<div id="tabInfo" class="tab-info">Checking tab...</div>
|
||||||
<button id="sendBtn" class="send-btn" disabled>Send Cookie to APT</button>
|
<div class="action-buttons">
|
||||||
|
<button id="sendBtn" class="primary-btn" disabled>Send to APT</button>
|
||||||
|
<button id="copyBtn" class="secondary-btn" disabled>Copy VA Token</button>
|
||||||
|
</div>
|
||||||
<div id="statusMsg" class="status-msg"></div>
|
<div id="statusMsg" class="status-msg"></div>
|
||||||
</div>
|
</div>
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
|
|||||||
+50
-20
@@ -3,6 +3,7 @@ const APT_TOKEN = 'apt-local-bridge-token';
|
|||||||
|
|
||||||
const tabInfo = document.getElementById('tabInfo');
|
const tabInfo = document.getElementById('tabInfo');
|
||||||
const sendBtn = document.getElementById('sendBtn');
|
const sendBtn = document.getElementById('sendBtn');
|
||||||
|
const copyBtn = document.getElementById('copyBtn');
|
||||||
const statusMsg = document.getElementById('statusMsg');
|
const statusMsg = document.getElementById('statusMsg');
|
||||||
|
|
||||||
let detectedOrigin = null;
|
let detectedOrigin = null;
|
||||||
@@ -12,6 +13,29 @@ function showStatus(message, type) {
|
|||||||
statusMsg.className = 'status-msg ' + type;
|
statusMsg.className = 'status-msg ' + type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setActionButtonsDisabled(disabled) {
|
||||||
|
sendBtn.disabled = disabled;
|
||||||
|
copyBtn.disabled = disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getVaCookieValue() {
|
||||||
|
if (!detectedOrigin) {
|
||||||
|
throw new Error('No Alta deployment detected.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const cookie = await chrome.cookies.get({ url: detectedOrigin, name: 'va' });
|
||||||
|
|
||||||
|
if (!cookie || !cookie.value) {
|
||||||
|
throw new Error('No "va" session cookie found. Are you logged in?');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cookie.expirationDate && cookie.expirationDate < Date.now() / 1000) {
|
||||||
|
throw new Error('Session cookie has expired. Please log in again.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return cookie.value;
|
||||||
|
}
|
||||||
|
|
||||||
// Check the active tab on popup open
|
// Check the active tab on popup open
|
||||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||||
if (!tabs || tabs.length === 0) {
|
if (!tabs || tabs.length === 0) {
|
||||||
@@ -42,30 +66,18 @@ chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
|||||||
detectedOrigin = url.origin;
|
detectedOrigin = url.origin;
|
||||||
tabInfo.textContent = 'Detected: ' + hostname;
|
tabInfo.textContent = 'Detected: ' + hostname;
|
||||||
tabInfo.className = 'tab-info detected';
|
tabInfo.className = 'tab-info detected';
|
||||||
sendBtn.disabled = false;
|
setActionButtonsDisabled(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send cookie on button click
|
// Send cookie on button click
|
||||||
sendBtn.addEventListener('click', async () => {
|
sendBtn.addEventListener('click', async () => {
|
||||||
if (!detectedOrigin) return;
|
if (!detectedOrigin) return;
|
||||||
|
|
||||||
sendBtn.disabled = true;
|
setActionButtonsDisabled(true);
|
||||||
showStatus('Retrieving cookie...', 'info');
|
showStatus('Retrieving VA token...', 'info');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cookie = await chrome.cookies.get({ url: detectedOrigin, name: 'va' });
|
const cookieValue = await getVaCookieValue();
|
||||||
|
|
||||||
if (!cookie || !cookie.value) {
|
|
||||||
showStatus('No "va" session cookie found. Are you logged in?', 'error');
|
|
||||||
sendBtn.disabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cookie.expirationDate && cookie.expirationDate < Date.now() / 1000) {
|
|
||||||
showStatus('Session cookie has expired. Please log in again.', 'error');
|
|
||||||
sendBtn.disabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
showStatus('Sending to Alta Proxy Tool...', 'info');
|
showStatus('Sending to Alta Proxy Tool...', 'info');
|
||||||
|
|
||||||
@@ -77,17 +89,16 @@ sendBtn.addEventListener('click', async () => {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
deploymentUrl: detectedOrigin,
|
deploymentUrl: detectedOrigin,
|
||||||
cookieValue: cookie.value
|
cookieValue
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
showStatus('Cookie sent successfully!', 'success');
|
showStatus('VA token sent successfully!', 'success');
|
||||||
} else {
|
} else {
|
||||||
showStatus('Error: ' + (data.message || 'Unknown error'), 'error');
|
showStatus('Error: ' + (data.message || 'Unknown error'), 'error');
|
||||||
sendBtn.disabled = false;
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.message && err.message.includes('Failed to fetch')) {
|
if (err.message && err.message.includes('Failed to fetch')) {
|
||||||
@@ -95,6 +106,25 @@ sendBtn.addEventListener('click', async () => {
|
|||||||
} else {
|
} else {
|
||||||
showStatus('Error: ' + err.message, 'error');
|
showStatus('Error: ' + err.message, 'error');
|
||||||
}
|
}
|
||||||
sendBtn.disabled = false;
|
} finally {
|
||||||
|
setActionButtonsDisabled(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Copy VA token on button click
|
||||||
|
copyBtn.addEventListener('click', async () => {
|
||||||
|
if (!detectedOrigin) return;
|
||||||
|
|
||||||
|
setActionButtonsDisabled(true);
|
||||||
|
showStatus('Retrieving VA token...', 'info');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const cookieValue = await getVaCookieValue();
|
||||||
|
await navigator.clipboard.writeText(cookieValue);
|
||||||
|
showStatus('VA token copied to clipboard!', 'success');
|
||||||
|
} catch (err) {
|
||||||
|
showStatus('Error: ' + err.message, 'error');
|
||||||
|
} finally {
|
||||||
|
setActionButtonsDisabled(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user