Linux websever 5.15.0-153-generic #163-Ubuntu SMP Thu Aug 7 16:37:18 UTC 2025 x86_64
Apache/2.4.52 (Ubuntu)
: 192.168.3.70 | : 192.168.1.99
Cant Read [ /etc/named.conf ]
8.1.2-1ubuntu2.23
urlab
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
var /
www /
html /
cqt /
server /
routes /
[ HOME SHELL ]
Name
Size
Permission
Action
auth.js
2.8
KB
-rw-r--r--
courses.js
5.97
KB
-rw-r--r--
labs.js
9.38
KB
-rw-r--r--
news.js
6.1
KB
-rw-r--r--
publications.js
8.21
KB
-rw-r--r--
rebuild.js
1.09
KB
-rw-r--r--
research.js
6.83
KB
-rw-r--r--
team.js
6.52
KB
-rw-r--r--
workshops.js
6.01
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : labs.js
const express = require('express'); const router = express.Router(); const fs = require('fs').promises; const path = require('path'); const authenticateToken = require('../middleware/auth'); const { validateId, validateLab } = require('../middleware/validation'); const multer = require('multer'); const crypto = require('crypto'); // Helper function to check if two files are identical async function filesAreIdentical(path1, path2) { try { const [file1, file2] = await Promise.all([ fs.readFile(path1), fs.readFile(path2) ]); const hash1 = crypto.createHash('md5').update(file1).digest('hex'); const hash2 = crypto.createHash('md5').update(file2).digest('hex'); return hash1 === hash2; } catch (error) { return false; } } // Multer storage for labs images const labsStorage = multer.diskStorage({ destination: (req, file, cb) => { const dest = path.join(__dirname, '../../public/images/labs'); require('fs').mkdirSync(dest, { recursive: true }); cb(null, dest); }, filename: (req, file, cb) => { const ext = path.extname(file.originalname) || ''; const name = `${Date.now()}-${Math.random().toString(36).slice(2,8)}${ext}`; cb(null, name); } }); const imageFilter = (req, file, cb) => { const allowedMimes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp']; if (allowedMimes.includes(file.mimetype)) { cb(null, true); } else { cb(new Error('Invalid file type. Only JPEG, PNG, GIF, and WebP images are allowed.'), false); } }; const upload = multer({ storage: labsStorage, fileFilter: imageFilter, limits: { fileSize: 5 * 1024 * 1024, files: 1 } }); const DATA_DIR = path.join(__dirname, '../../public/data'); const FILENAME = 'labs.json'; const FILEPATH = path.join(DATA_DIR, FILENAME); // Backup function async function createBackup() { try { const data = await fs.readFile(FILEPATH, 'utf8'); const timestamp = new Date().toISOString().replace(/:/g, '-'); const backupPath = path.join(DATA_DIR, `backups/${FILENAME.replace('.json', '')}_${timestamp}.json`); // Ensure backups directory exists await fs.mkdir(path.join(DATA_DIR, 'backups'), { recursive: true }); await fs.writeFile(backupPath, data); console.log(`Backup created: ${backupPath}`); } catch (error) { console.error('Error creating backup:', error); } } // Read data async function readData() { try { const data = await fs.readFile(FILEPATH, 'utf8'); return JSON.parse(data); } catch (error) { console.error('Error reading labs:', error); return []; } } // Write data async function writeData(data) { await createBackup(); await fs.writeFile(FILEPATH, JSON.stringify(data, null, 2)); } // GET all labs router.get('/', async (req, res) => { try { const labs = await readData(); res.json(labs); } catch (error) { res.status(500).json({ error: 'Failed to fetch labs' }); } }); // GET single lab by ID router.get('/:id', validateId(), async (req, res) => { try { const labs = await readData(); const lab = labs.find(l => l.id === req.params.id); if (!lab) { return res.status(404).json({ error: 'Lab not found' }); } res.json(lab); } catch (error) { res.status(500).json({ error: 'Failed to fetch lab' }); } }); // POST new lab (protected) router.post('/', authenticateToken, upload.single('image'), validateLab(), async (req, res) => { try { const labs = await readData(); const newLab = { id: req.body.id || `lab${Date.now()}`, ...req.body, equipment: Array.isArray(req.body.equipment) ? req.body.equipment : typeof req.body.equipment === 'string' ? req.body.equipment.split('\n').filter(e => e.trim()) : [], capabilities: Array.isArray(req.body.capabilities) ? req.body.capabilities : typeof req.body.capabilities === 'string' ? req.body.capabilities.split('\n').filter(c => c.trim()) : [], features: Array.isArray(req.body.features) ? req.body.features : [] }; // If an image was uploaded, store its public path if (req.file) { newLab.image = `/images/labs/${req.file.filename}`; } labs.push(newLab); await writeData(labs); res.status(201).json(newLab); } catch (error) { console.error('Error creating lab:', error); res.status(500).json({ error: 'Failed to create lab' }); } }); // PUT update lab (protected) router.put('/:id', authenticateToken, validateId(), upload.single('image'), validateLab(), async (req, res) => { try { const labs = await readData(); const index = labs.findIndex(l => l.id === req.params.id); if (index === -1) { return res.status(404).json({ error: 'Lab not found' }); } // Remove image from body to prevent overwriting uploaded file const { image: _, ...bodyWithoutImage } = req.body; // If a new image was uploaded, check if it's identical to existing one if (req.file) { const newFilePath = path.join(__dirname, '../../public/images/labs', req.file.filename); const oldImage = labs[index].image; let shouldUseNewFile = true; // Check if old image exists and compare with new upload if (oldImage && typeof oldImage === 'string' && oldImage.startsWith('/images/labs/')) { const oldPath = path.join(__dirname, '../../public', oldImage.replace(/^\//, '')); const areIdentical = await filesAreIdentical(oldPath, newFilePath); if (areIdentical) { // Files are identical, remove the newly uploaded file and keep the old one await fs.unlink(newFilePath).catch(() => {}); shouldUseNewFile = false; console.log('ℹ️ Identical file detected, keeping existing image'); } else { // Files are different, remove old file await fs.unlink(oldPath).catch(() => {}); } } if (shouldUseNewFile) { labs[index] = { ...labs[index], ...bodyWithoutImage, image: `/images/labs/${req.file.filename}`, id: req.params.id, equipment: Array.isArray(bodyWithoutImage.equipment) ? bodyWithoutImage.equipment : typeof bodyWithoutImage.equipment === 'string' ? bodyWithoutImage.equipment.split('\n').filter(e => e.trim()) : labs[index].equipment, capabilities: Array.isArray(bodyWithoutImage.capabilities) ? bodyWithoutImage.capabilities : typeof bodyWithoutImage.capabilities === 'string' ? bodyWithoutImage.capabilities.split('\n').filter(c => c.trim()) : labs[index].capabilities, features: Array.isArray(bodyWithoutImage.features) ? bodyWithoutImage.features : labs[index].features }; } else { labs[index] = { ...labs[index], ...bodyWithoutImage, id: req.params.id, equipment: Array.isArray(bodyWithoutImage.equipment) ? bodyWithoutImage.equipment : typeof bodyWithoutImage.equipment === 'string' ? bodyWithoutImage.equipment.split('\n').filter(e => e.trim()) : labs[index].equipment, capabilities: Array.isArray(bodyWithoutImage.capabilities) ? bodyWithoutImage.capabilities : typeof bodyWithoutImage.capabilities === 'string' ? bodyWithoutImage.capabilities.split('\n').filter(c => c.trim()) : labs[index].capabilities, features: Array.isArray(bodyWithoutImage.features) ? bodyWithoutImage.features : labs[index].features }; } } else { labs[index] = { ...labs[index], ...bodyWithoutImage, id: req.params.id, equipment: Array.isArray(bodyWithoutImage.equipment) ? bodyWithoutImage.equipment : typeof bodyWithoutImage.equipment === 'string' ? bodyWithoutImage.equipment.split('\n').filter(e => e.trim()) : labs[index].equipment, capabilities: Array.isArray(bodyWithoutImage.capabilities) ? bodyWithoutImage.capabilities : typeof bodyWithoutImage.capabilities === 'string' ? bodyWithoutImage.capabilities.split('\n').filter(c => c.trim()) : labs[index].capabilities, features: Array.isArray(bodyWithoutImage.features) ? bodyWithoutImage.features : labs[index].features }; } await writeData(labs); res.json(labs[index]); } catch (error) { console.error('Error updating lab:', error); res.status(500).json({ error: 'Failed to update lab' }); } }); // DELETE lab (protected) router.delete('/:id', authenticateToken, validateId(), async (req, res) => { try { const labs = await readData(); const lab = labs.find(l => l.id === req.params.id); if (!lab) { return res.status(404).json({ error: 'Lab not found' }); } // Remove associated image file if exists const oldImage = lab.image; if (oldImage && typeof oldImage === 'string' && oldImage.startsWith('/images/labs/')) { const oldPath = path.join(__dirname, '../../public', oldImage.replace(/^\//, '')); await fs.unlink(oldPath).catch(() => {}); } const filteredLabs = labs.filter(l => l.id !== req.params.id); await writeData(filteredLabs); res.json({ message: 'Lab deleted successfully' }); } catch (error) { console.error('Error deleting lab:', error); res.status(500).json({ error: 'Failed to delete lab' }); } }); module.exports = router;
Close