feat(browser): implement browser extension for sending files to DocuElevate
- Add complete browser extension with popup UI and background workers - Support Chrome, Firefox, Edge, and other Chromium-based browsers - Include context menu integration for quick file sending - Add comprehensive documentation for users and administrators - Update main README and API docs to include browser extension - Implement secure configuration storage in browser extension storage - Add SSRF-protected URL upload endpoint integration Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
color: #333;
|
||||
background-color: #f8f9fa;
|
||||
width: 400px;
|
||||
min-height: 300px;
|
||||
}
|
||||
|
||||
.container {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 2px solid #e9ecef;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.section.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-weight: 500;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
input[type="url"],
|
||||
input[type="text"] {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ced4da;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.15s ease-in-out;
|
||||
}
|
||||
|
||||
input[type="url"]:focus,
|
||||
input[type="text"]:focus {
|
||||
outline: none;
|
||||
border-color: #4CAF50;
|
||||
box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
|
||||
}
|
||||
|
||||
small {
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
color: #6c757d;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
width: 100%;
|
||||
padding: 10px 16px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease-in-out;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
|
||||
.btn-primary:active {
|
||||
background-color: #3d8b40;
|
||||
}
|
||||
|
||||
.btn-primary:disabled {
|
||||
background-color: #95c997;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: #6c757d;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background-color: #5a6268;
|
||||
}
|
||||
|
||||
.info-box {
|
||||
background-color: #e7f3ff;
|
||||
border: 1px solid #b3d9ff;
|
||||
border-radius: 4px;
|
||||
padding: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.info-box p {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.info-box strong {
|
||||
color: #0056b3;
|
||||
}
|
||||
|
||||
.url-display {
|
||||
word-break: break-all;
|
||||
font-family: 'Monaco', 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
#status-message {
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
margin-top: 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
#status-message.success {
|
||||
background-color: #d4edda;
|
||||
border: 1px solid #c3e6cb;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
#status-message.error {
|
||||
background-color: #f8d7da;
|
||||
border: 1px solid #f5c6cb;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
#status-message.info {
|
||||
background-color: #d1ecf1;
|
||||
border: 1px solid #bee5eb;
|
||||
color: #0c5460;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.loading::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin-top: -8px;
|
||||
margin-left: -8px;
|
||||
border: 2px solid #f3f3f3;
|
||||
border-top: 2px solid #4CAF50;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DocuElevate</title>
|
||||
<link rel="stylesheet" href="popup.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<img src="../icons/icon48.png" alt="DocuElevate" class="logo">
|
||||
<h1>DocuElevate</h1>
|
||||
</div>
|
||||
|
||||
<div id="config-section" class="section">
|
||||
<h2>Configuration</h2>
|
||||
<div class="form-group">
|
||||
<label for="server-url">DocuElevate Server URL:</label>
|
||||
<input type="url" id="server-url" placeholder="https://docuelevate.example.com" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="session-cookie">Session Cookie (optional):</label>
|
||||
<input type="text" id="session-cookie" placeholder="session=your_session_value">
|
||||
<small>Required if authentication is enabled</small>
|
||||
</div>
|
||||
<button id="save-config" class="btn btn-primary">Save Configuration</button>
|
||||
</div>
|
||||
|
||||
<div id="send-section" class="section hidden">
|
||||
<h2>Send File to DocuElevate</h2>
|
||||
<div class="info-box">
|
||||
<p><strong>Current URL:</strong></p>
|
||||
<p id="current-url" class="url-display"></p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="filename">Filename (optional):</label>
|
||||
<input type="text" id="filename" placeholder="Leave blank to use URL filename">
|
||||
</div>
|
||||
<button id="send-file" class="btn btn-primary">Send to DocuElevate</button>
|
||||
<button id="show-config" class="btn btn-secondary">Change Settings</button>
|
||||
</div>
|
||||
|
||||
<div id="status-section" class="section hidden">
|
||||
<div id="status-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,174 @@
|
||||
// Popup script for DocuElevate browser extension
|
||||
|
||||
// DOM elements
|
||||
const configSection = document.getElementById('config-section');
|
||||
const sendSection = document.getElementById('send-section');
|
||||
const statusSection = document.getElementById('status-section');
|
||||
const statusMessage = document.getElementById('status-message');
|
||||
|
||||
const serverUrlInput = document.getElementById('server-url');
|
||||
const sessionCookieInput = document.getElementById('session-cookie');
|
||||
const filenameInput = document.getElementById('filename');
|
||||
const currentUrlDisplay = document.getElementById('current-url');
|
||||
|
||||
const saveConfigBtn = document.getElementById('save-config');
|
||||
const sendFileBtn = document.getElementById('send-file');
|
||||
const showConfigBtn = document.getElementById('show-config');
|
||||
|
||||
// Load configuration and current tab URL on popup open
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
// Load saved configuration
|
||||
const config = await loadConfig();
|
||||
|
||||
if (config.serverUrl) {
|
||||
serverUrlInput.value = config.serverUrl;
|
||||
}
|
||||
|
||||
if (config.sessionCookie) {
|
||||
sessionCookieInput.value = config.sessionCookie;
|
||||
}
|
||||
|
||||
// Get current tab URL
|
||||
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
|
||||
const currentUrl = tabs[0]?.url || '';
|
||||
currentUrlDisplay.textContent = currentUrl;
|
||||
|
||||
// Show appropriate section
|
||||
if (config.serverUrl) {
|
||||
showSendSection();
|
||||
} else {
|
||||
showConfigSection();
|
||||
}
|
||||
});
|
||||
|
||||
// Save configuration
|
||||
saveConfigBtn.addEventListener('click', async () => {
|
||||
const serverUrl = serverUrlInput.value.trim();
|
||||
|
||||
if (!serverUrl) {
|
||||
showStatus('Please enter a server URL', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate URL format
|
||||
try {
|
||||
new URL(serverUrl);
|
||||
} catch (e) {
|
||||
showStatus('Invalid server URL format', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const config = {
|
||||
serverUrl: serverUrl,
|
||||
sessionCookie: sessionCookieInput.value.trim()
|
||||
};
|
||||
|
||||
await saveConfig(config);
|
||||
showStatus('Configuration saved successfully!', 'success');
|
||||
|
||||
setTimeout(() => {
|
||||
showSendSection();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// Send file to DocuElevate
|
||||
sendFileBtn.addEventListener('click', async () => {
|
||||
const config = await loadConfig();
|
||||
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
|
||||
const currentUrl = tabs[0]?.url || '';
|
||||
|
||||
if (!currentUrl) {
|
||||
showStatus('No URL found in current tab', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable button and show loading
|
||||
sendFileBtn.disabled = true;
|
||||
sendFileBtn.classList.add('loading');
|
||||
showStatus('Sending file to DocuElevate...', 'info');
|
||||
|
||||
try {
|
||||
const payload = {
|
||||
url: currentUrl,
|
||||
filename: filenameInput.value.trim() || null
|
||||
};
|
||||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
|
||||
// Add session cookie if provided
|
||||
if (config.sessionCookie) {
|
||||
headers['Cookie'] = config.sessionCookie;
|
||||
}
|
||||
|
||||
const response = await fetch(`${config.serverUrl}/api/process-url`, {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
body: JSON.stringify(payload),
|
||||
credentials: 'include'
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
showStatus(
|
||||
`✓ File sent successfully! Task ID: ${result.task_id}\nFilename: ${result.filename}`,
|
||||
'success'
|
||||
);
|
||||
} else {
|
||||
showStatus(
|
||||
`Error: ${result.detail || 'Failed to send file'}`,
|
||||
'error'
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
showStatus(
|
||||
`Error: ${error.message || 'Failed to connect to DocuElevate server'}`,
|
||||
'error'
|
||||
);
|
||||
} finally {
|
||||
sendFileBtn.disabled = false;
|
||||
sendFileBtn.classList.remove('loading');
|
||||
}
|
||||
});
|
||||
|
||||
// Show configuration section
|
||||
showConfigBtn.addEventListener('click', () => {
|
||||
showConfigSection();
|
||||
});
|
||||
|
||||
// Utility functions
|
||||
function showConfigSection() {
|
||||
configSection.classList.remove('hidden');
|
||||
sendSection.classList.add('hidden');
|
||||
statusSection.classList.add('hidden');
|
||||
}
|
||||
|
||||
function showSendSection() {
|
||||
configSection.classList.add('hidden');
|
||||
sendSection.classList.remove('hidden');
|
||||
statusSection.classList.add('hidden');
|
||||
}
|
||||
|
||||
function showStatus(message, type) {
|
||||
statusMessage.textContent = message;
|
||||
statusMessage.className = type;
|
||||
statusSection.classList.remove('hidden');
|
||||
}
|
||||
|
||||
async function loadConfig() {
|
||||
return new Promise((resolve) => {
|
||||
chrome.storage.sync.get(['serverUrl', 'sessionCookie'], (result) => {
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function saveConfig(config) {
|
||||
return new Promise((resolve) => {
|
||||
chrome.storage.sync.set(config, () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user