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 : research.js
const express = require('express'); const router = express.Router(); const authMiddleware = require('../middleware/auth'); const { validateId, validateResearch } = require('../middleware/validation'); const { readJSON, writeJSON, createBackup } = require('../utils/fileOperations'); const multer = require('multer'); const path = require('path'); const fs = require('fs'); const fsp = require('fs').promises; 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([ fsp.readFile(path1), fsp.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 research images const researchStorage = multer.diskStorage({ destination: (req, file, cb) => { const dest = path.join(__dirname, '../../public/images/research'); 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); } }); // File filter to accept only images 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: researchStorage, fileFilter: imageFilter, limits: { fileSize: 5 * 1024 * 1024, // 5MB limit files: 1 } }); const FILENAME = 'research.json'; // @route GET /api/research // @desc Get all research projects // @access Public router.get('/', async (req, res) => { try { const data = await readJSON(FILENAME); res.json(data); } catch (error) { res.status(500).json({ error: 'Error reading research data' }); } }); // @route GET /api/research/:id // @desc Get single research project // @access Public router.get('/:id', validateId(), async (req, res) => { try { const data = await readJSON(FILENAME); const item = data.find(r => r.id === req.params.id); if (!item) { return res.status(404).json({ error: 'Research project not found' }); } res.json(item); } catch (error) { res.status(500).json({ error: 'Error reading research data' }); } }); // @route POST /api/research // @desc Create new research project // @access Protected router.post('/', authMiddleware, upload.single('image'), validateResearch(), async (req, res) => { try { await createBackup(FILENAME); const data = await readJSON(FILENAME); const newProject = { id: req.body.id || `research-${Date.now()}`, ...req.body, createdAt: new Date().toISOString() }; // If an image was uploaded, store its public path if (req.file) { newProject.image = `/images/research/${req.file.filename}`; } data.push(newProject); await writeJSON(FILENAME, data); res.status(201).json({ success: true, data: newProject }); } catch (error) { res.status(500).json({ error: 'Error creating research project' }); } }); // @route PUT /api/research/:id // @desc Update research project // @access Protected router.put('/:id', authMiddleware, validateId(), upload.single('image'), validateResearch(), async (req, res) => { try { await createBackup(FILENAME); const data = await readJSON(FILENAME); const index = data.findIndex(r => r.id === req.params.id); if (index === -1) { return res.status(404).json({ error: 'Research project 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/research', req.file.filename); const oldImage = data[index].image; let shouldUseNewFile = true; // Check if old image exists and compare with new upload if (oldImage && typeof oldImage === 'string' && oldImage.startsWith('/images/research/')) { 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 fsp.unlink(newFilePath).catch(() => {}); shouldUseNewFile = false; console.log('ℹ️ Identical file detected, keeping existing image'); } else { // Files are different, remove old file await fsp.unlink(oldPath).catch(() => {}); } } if (shouldUseNewFile) { data[index] = { ...data[index], ...bodyWithoutImage, image: `/images/research/${req.file.filename}`, id: req.params.id, updatedAt: new Date().toISOString() }; } else { data[index] = { ...data[index], ...bodyWithoutImage, id: req.params.id, updatedAt: new Date().toISOString() }; } } else { data[index] = { ...data[index], ...bodyWithoutImage, id: req.params.id, updatedAt: new Date().toISOString() }; } await writeJSON(FILENAME, data); // Trigger rebuild in background res.json({ success: true, data: data[index] }); } catch (error) { res.status(500).json({ error: 'Error updating research project' }); } }); // @route DELETE /api/research/:id // @desc Delete research project // @access Protected router.delete('/:id', authMiddleware, validateId(), async (req, res) => { try { await createBackup(FILENAME); const data = await readJSON(FILENAME); const index = data.findIndex(r => r.id === req.params.id); if (index === -1) { return res.status(404).json({ error: 'Research project not found' }); } const deleted = data.splice(index, 1); // Remove associated image file if exists const oldImage = deleted[0].image; if (oldImage && typeof oldImage === 'string' && oldImage.startsWith('/images/research/')) { const oldPath = path.join(__dirname, '../../public', oldImage.replace(/^\//, '')); await fsp.unlink(oldPath).catch(() => {}); } await writeJSON(FILENAME, data); res.json({ success: true, data: deleted[0] }); } catch (error) { res.status(500).json({ error: 'Error deleting research project' }); } }); module.exports = router;
Close