Ocx File Download -
// Set headers for OCX download res.setHeader('Content-Type', 'application/octet-stream'); res.setHeader('Content-Disposition', attachment; filename="$safeName" ); res.setHeader('X-Content-Type-Options', 'nosniff');
Backend (Node.js/Express) // routes/ocxDownload.js const express = require('express'); const path = require('path'); const fs = require('fs'); const router = express.Router(); // Endpoint to download OCX file router.get('/download-ocx/:filename', (req, res) => const filename = req.params.filename; ocx file download
const filePath = path.join(__dirname, '../protected/ocx_files', safeName); // Set headers for OCX download res
fs.readdir(ocxDir, (err, files) => if (err) return res.status(500).json( error: 'Unable to list files' ); const path = require('path')
// Initialize downloader when page loads document.addEventListener('DOMContentLoaded', () => new OCXDownloader(); ); </script> </body> </html> // app.js const express = require('express'); const cors = require('cors'); const path = require('path'); const ocxRoutes = require('./routes/ocxDownload'); const app = express(); const PORT = process.env.PORT || 3000;
// Security: Validate filename to prevent path traversal const safeName = path.basename(filename); if (!safeName.endsWith('.ocx')) return res.status(400).json( error: 'Invalid file type' );
const ocxFiles = files .filter(file => file.endsWith('.ocx')) .map(file => ( name: file, size: fs.statSync(path.join(ocxDir, file)).size, lastModified: fs.statSync(path.join(ocxDir, file)).mtime ));