first commit: Complete phishing test management panel with Node.js backend and React frontend

This commit is contained in:
salvacybersec
2025-11-10 17:00:40 +03:00
commit 19e551f33b
77 changed files with 6677 additions and 0 deletions

View File

@@ -0,0 +1,160 @@
import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import {
Box,
Button,
Card,
CardContent,
Grid,
Typography,
Chip,
CircularProgress,
Dialog,
DialogTitle,
DialogContent,
DialogActions,
TextField,
} from '@mui/material';
import { Add, TrendingUp } from '@mui/icons-material';
import { companyService } from '../services/companyService';
function Companies() {
const [companies, setCompanies] = useState([]);
const [loading, setLoading] = useState(true);
const [openDialog, setOpenDialog] = useState(false);
const [formData, setFormData] = useState({
name: '',
description: '',
industry: '',
});
const navigate = useNavigate();
useEffect(() => {
loadCompanies();
}, []);
const loadCompanies = async () => {
try {
const response = await companyService.getAll();
setCompanies(response.data);
} catch (error) {
console.error('Failed to load companies:', error);
} finally {
setLoading(false);
}
};
const handleCreate = async () => {
try {
await companyService.create(formData);
setOpenDialog(false);
setFormData({ name: '', description: '', industry: '' });
loadCompanies();
} catch (error) {
console.error('Failed to create company:', error);
alert('Şirket oluşturulamadı');
}
};
if (loading) {
return (
<Box display="flex" justifyContent="center" alignItems="center" minHeight="400px">
<CircularProgress />
</Box>
);
}
return (
<Box>
<Box display="flex" justifyContent="space-between" alignItems="center" mb={3}>
<Typography variant="h4">Şirketler</Typography>
<Button
variant="contained"
startIcon={<Add />}
onClick={() => setOpenDialog(true)}
>
Yeni Şirket
</Button>
</Box>
<Grid container spacing={3}>
{companies.map((company) => (
<Grid item xs={12} sm={6} md={4} key={company.id}>
<Card
sx={{ cursor: 'pointer', '&:hover': { boxShadow: 6 } }}
onClick={() => navigate(`/companies/${company.id}`)}
>
<CardContent>
<Typography variant="h6" gutterBottom>
{company.name}
</Typography>
<Typography variant="body2" color="text.secondary" gutterBottom>
{company.industry || 'Sektör belirtilmemiş'}
</Typography>
<Box mt={2} display="flex" gap={1} flexWrap="wrap">
<Chip
label={`${company.total_tokens} Token`}
size="small"
color="primary"
/>
<Chip
label={`${company.total_clicks} Tıklama`}
size="small"
color="success"
/>
<Chip
icon={<TrendingUp />}
label={`${company.click_rate}%`}
size="small"
color={company.click_rate > 30 ? 'error' : 'default'}
/>
</Box>
</CardContent>
</Card>
</Grid>
))}
</Grid>
<Dialog open={openDialog} onClose={() => setOpenDialog(false)} maxWidth="sm" fullWidth>
<DialogTitle>Yeni Şirket Ekle</DialogTitle>
<DialogContent>
<TextField
autoFocus
margin="dense"
label="Şirket Adı"
fullWidth
required
value={formData.name}
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
/>
<TextField
margin="dense"
label="Açıklama"
fullWidth
multiline
rows={2}
value={formData.description}
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
/>
<TextField
margin="dense"
label="Sektör"
fullWidth
value={formData.industry}
onChange={(e) => setFormData({ ...formData, industry: e.target.value })}
placeholder="Örn: Banking, Telecom, Government"
/>
</DialogContent>
<DialogActions>
<Button onClick={() => setOpenDialog(false)}>İptal</Button>
<Button onClick={handleCreate} variant="contained" disabled={!formData.name}>
Oluştur
</Button>
</DialogActions>
</Dialog>
</Box>
);
}
export default Companies;

View File

@@ -0,0 +1,202 @@
import { useState, useEffect } from 'react';
import {
Grid,
Paper,
Typography,
Box,
Card,
CardContent,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Chip,
CircularProgress,
} from '@mui/material';
import {
Business,
Token as TokenIcon,
CheckCircle,
TrendingUp,
} from '@mui/icons-material';
import { statsService } from '../services/statsService';
import { format } from 'date-fns';
import { tr } from 'date-fns/locale';
function Dashboard() {
const [stats, setStats] = useState(null);
const [recentClicks, setRecentClicks] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
loadData();
}, []);
const loadData = async () => {
try {
const [statsData, clicksData] = await Promise.all([
statsService.getDashboard(),
statsService.getRecentClicks(10),
]);
setStats(statsData.data);
setRecentClicks(clicksData.data);
} catch (error) {
console.error('Failed to load dashboard:', error);
} finally {
setLoading(false);
}
};
if (loading) {
return (
<Box display="flex" justifyContent="center" alignItems="center" minHeight="400px">
<CircularProgress />
</Box>
);
}
const StatCard = ({ title, value, icon, color }) => (
<Card>
<CardContent>
<Box display="flex" justifyContent="space-between" alignItems="center">
<Box>
<Typography color="textSecondary" gutterBottom variant="body2">
{title}
</Typography>
<Typography variant="h4">{value}</Typography>
</Box>
<Box
sx={{
bgcolor: `${color}.light`,
borderRadius: 2,
p: 1.5,
display: 'flex',
}}
>
{icon}
</Box>
</Box>
</CardContent>
</Card>
);
return (
<Box>
<Typography variant="h4" gutterBottom>
Dashboard
</Typography>
<Grid container spacing={3} sx={{ mb: 3 }}>
<Grid item xs={12} sm={6} md={3}>
<StatCard
title="Şirketler"
value={stats?.overview?.total_companies || 0}
icon={<Business sx={{ color: 'primary.main' }} />}
color="primary"
/>
</Grid>
<Grid item xs={12} sm={6} md={3}>
<StatCard
title="Toplam Token"
value={stats?.overview?.total_tokens || 0}
icon={<TokenIcon sx={{ color: 'info.main' }} />}
color="info"
/>
</Grid>
<Grid item xs={12} sm={6} md={3}>
<StatCard
title="Tıklanan"
value={stats?.overview?.clicked_tokens || 0}
icon={<CheckCircle sx={{ color: 'success.main' }} />}
color="success"
/>
</Grid>
<Grid item xs={12} sm={6} md={3}>
<StatCard
title="Başarı Oranı"
value={`${stats?.overview?.click_rate || 0}%`}
icon={<TrendingUp sx={{ color: 'warning.main' }} />}
color="warning"
/>
</Grid>
</Grid>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<Paper sx={{ p: 2 }}>
<Typography variant="h6" gutterBottom>
Şirket Performansı
</Typography>
<TableContainer>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Şirket</TableCell>
<TableCell align="right">Tokenlar</TableCell>
<TableCell align="right">Tıklama</TableCell>
<TableCell align="right">Oran</TableCell>
</TableRow>
</TableHead>
<TableBody>
{stats?.top_companies?.map((company) => (
<TableRow key={company.id}>
<TableCell>{company.name}</TableCell>
<TableCell align="right">{company.total_tokens}</TableCell>
<TableCell align="right">{company.total_clicks}</TableCell>
<TableCell align="right">
<Chip
label={`${company.click_rate}%`}
size="small"
color={company.click_rate > 30 ? 'error' : 'success'}
/>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</Paper>
</Grid>
<Grid item xs={12} md={6}>
<Paper sx={{ p: 2 }}>
<Typography variant="h6" gutterBottom>
Son Tıklamalar
</Typography>
<TableContainer>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Email</TableCell>
<TableCell>Şirket</TableCell>
<TableCell>Konum</TableCell>
<TableCell>Zaman</TableCell>
</TableRow>
</TableHead>
<TableBody>
{recentClicks.map((click) => (
<TableRow key={click.id}>
<TableCell sx={{ fontSize: '0.875rem' }}>
{click.token?.target_email}
</TableCell>
<TableCell>{click.token?.company?.name}</TableCell>
<TableCell>{click.city}, {click.country}</TableCell>
<TableCell>
{format(new Date(click.clicked_at), 'HH:mm', { locale: tr })}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</Paper>
</Grid>
</Grid>
</Box>
);
}
export default Dashboard;

View File

@@ -0,0 +1,111 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import {
Container,
Paper,
TextField,
Button,
Typography,
Box,
Alert,
} from '@mui/material';
import { LockOutlined } from '@mui/icons-material';
import { useAuth } from '../context/AuthContext';
function Login() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const { login } = useAuth();
const navigate = useNavigate();
const handleSubmit = async (e) => {
e.preventDefault();
setError('');
setLoading(true);
try {
await login(username, password);
navigate('/');
} catch (err) {
setError(err.response?.data?.error || 'Login failed');
} finally {
setLoading(false);
}
};
return (
<Container component="main" maxWidth="xs">
<Box
sx={{
marginTop: 8,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}}
>
<Paper elevation={3} sx={{ p: 4, width: '100%' }}>
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center', mb: 3 }}>
<LockOutlined sx={{ fontSize: 40, mb: 1, color: 'primary.main' }} />
<Typography component="h1" variant="h5">
Oltalama Test Paneli
</Typography>
<Typography variant="body2" color="text.secondary" sx={{ mt: 1 }}>
Güvenlik Farkındalık Yönetimi
</Typography>
</Box>
{error && (
<Alert severity="error" sx={{ mb: 2 }}>
{error}
</Alert>
)}
<Box component="form" onSubmit={handleSubmit}>
<TextField
margin="normal"
required
fullWidth
label="Kullanıcı Adı"
autoFocus
value={username}
onChange={(e) => setUsername(e.target.value)}
disabled={loading}
/>
<TextField
margin="normal"
required
fullWidth
label="Şifre"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
disabled={loading}
/>
<Button
type="submit"
fullWidth
variant="contained"
sx={{ mt: 3, mb: 2 }}
disabled={loading}
>
{loading ? 'Giriş yapılıyor...' : 'Giriş Yap'}
</Button>
<Box sx={{ mt: 2, p: 2, bgcolor: 'grey.100', borderRadius: 1 }}>
<Typography variant="caption" color="text.secondary">
<strong>Default Giriş:</strong><br />
Kullanıcı Adı: admin<br />
Şifre: admin123
</Typography>
</Box>
</Box>
</Paper>
</Box>
</Container>
);
}
export default Login;

View File

@@ -0,0 +1,243 @@
import { useState, useEffect } from 'react';
import {
Box,
Paper,
Typography,
TextField,
Button,
Grid,
Alert,
CircularProgress,
Divider,
} from '@mui/material';
import { Save, Send } from '@mui/icons-material';
import axios from 'axios';
const API_URL = import.meta.env.VITE_API_URL;
function Settings() {
const [settings, setSettings] = useState({
gmail_user: '',
gmail_app_password: '',
telegram_bot_token: '',
telegram_chat_id: '',
});
const [loading, setLoading] = useState(true);
const [testLoading, setTestLoading] = useState({ mail: false, telegram: false });
const [alerts, setAlerts] = useState({ mail: null, telegram: null });
useEffect(() => {
loadSettings();
}, []);
const loadSettings = async () => {
try {
const response = await axios.get(`${API_URL}/api/settings`, {
withCredentials: true,
});
setSettings(response.data.data);
} catch (error) {
console.error('Failed to load settings:', error);
} finally {
setLoading(false);
}
};
const handleSave = async () => {
try {
await axios.put(`${API_URL}/api/settings`, settings, {
withCredentials: true,
});
alert('Ayarlar kaydedildi!');
} catch (error) {
console.error('Failed to save settings:', error);
alert('Ayarlar kaydedilemedi');
}
};
const handleTestMail = async () => {
setTestLoading({ ...testLoading, mail: true });
try {
const response = await axios.post(
`${API_URL}/api/settings/test-mail`,
{},
{ withCredentials: true }
);
setAlerts({ ...alerts, mail: { severity: 'success', message: response.data.message } });
} catch (error) {
setAlerts({
...alerts,
mail: { severity: 'error', message: error.response?.data?.error || 'Test başarısız' },
});
} finally {
setTestLoading({ ...testLoading, mail: false });
}
};
const handleTestTelegram = async () => {
setTestLoading({ ...testLoading, telegram: true });
try {
const response = await axios.post(
`${API_URL}/api/settings/test-telegram`,
{},
{ withCredentials: true }
);
setAlerts({ ...alerts, telegram: { severity: 'success', message: response.data.message } });
} catch (error) {
setAlerts({
...alerts,
telegram: {
severity: 'error',
message: error.response?.data?.error || 'Test başarısız',
},
});
} finally {
setTestLoading({ ...testLoading, telegram: false });
}
};
if (loading) {
return (
<Box display="flex" justifyContent="center" alignItems="center" minHeight="400px">
<CircularProgress />
</Box>
);
}
return (
<Box>
<Typography variant="h4" gutterBottom>
Sistem Ayarları
</Typography>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<Paper sx={{ p: 3 }}>
<Typography variant="h6" gutterBottom>
Gmail Ayarları
</Typography>
<Typography variant="body2" color="text.secondary" gutterBottom>
Gmail App Password kullanın (2FA aktif olmalı)
</Typography>
<TextField
fullWidth
margin="normal"
label="Gmail Adresi"
type="email"
value={settings.gmail_user}
onChange={(e) =>
setSettings({ ...settings, gmail_user: e.target.value })
}
/>
<TextField
fullWidth
margin="normal"
label="App Password"
type="password"
value={settings.gmail_app_password}
onChange={(e) =>
setSettings({ ...settings, gmail_app_password: e.target.value })
}
/>
{alerts.mail && (
<Alert severity={alerts.mail.severity} sx={{ mt: 2 }}>
{alerts.mail.message}
</Alert>
)}
<Box mt={2} display="flex" gap={2}>
<Button
variant="contained"
startIcon={<Save />}
onClick={handleSave}
>
Kaydet
</Button>
<Button
variant="outlined"
startIcon={<Send />}
onClick={handleTestMail}
disabled={testLoading.mail}
>
Test Mail Gönder
</Button>
</Box>
</Paper>
</Grid>
<Grid item xs={12} md={6}>
<Paper sx={{ p: 3 }}>
<Typography variant="h6" gutterBottom>
Telegram Ayarları
</Typography>
<Typography variant="body2" color="text.secondary" gutterBottom>
@BotFather'dan bot token alın, @userinfobot'dan chat ID öğrenin
</Typography>
<TextField
fullWidth
margin="normal"
label="Bot Token"
type="password"
value={settings.telegram_bot_token}
onChange={(e) =>
setSettings({ ...settings, telegram_bot_token: e.target.value })
}
/>
<TextField
fullWidth
margin="normal"
label="Chat ID"
value={settings.telegram_chat_id}
onChange={(e) =>
setSettings({ ...settings, telegram_chat_id: e.target.value })
}
/>
{alerts.telegram && (
<Alert severity={alerts.telegram.severity} sx={{ mt: 2 }}>
{alerts.telegram.message}
</Alert>
)}
<Box mt={2} display="flex" gap={2}>
<Button
variant="contained"
startIcon={<Save />}
onClick={handleSave}
>
Kaydet
</Button>
<Button
variant="outlined"
startIcon={<Send />}
onClick={handleTestTelegram}
disabled={testLoading.telegram}
>
Test Bildirimi
</Button>
</Box>
</Paper>
</Grid>
</Grid>
<Paper sx={{ p: 3, mt: 3 }}>
<Typography variant="h6" gutterBottom>
Tracking URL Bilgisi
</Typography>
<Divider sx={{ my: 2 }} />
<Typography variant="body2" color="text.secondary">
Tracking URL formatı: <strong>http://your-domain.com/t/TOKEN</strong>
</Typography>
<Typography variant="body2" color="text.secondary" mt={1}>
Bu URL'ler mail şablonlarında otomatik olarak oluşturulur ve gönderilir.
</Typography>
</Paper>
</Box>
);
}
export default Settings;

View File

@@ -0,0 +1,198 @@
import { useState, useEffect } from 'react';
import {
Box,
Button,
Paper,
Typography,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Chip,
CircularProgress,
Dialog,
DialogTitle,
DialogContent,
DialogActions,
TextField,
MenuItem,
} from '@mui/material';
import { Add, Check, Close } from '@mui/icons-material';
import { tokenService } from '../services/tokenService';
import { companyService } from '../services/companyService';
import { templateService } from '../services/templateService';
import { format } from 'date-fns';
function Tokens() {
const [tokens, setTokens] = useState([]);
const [companies, setCompanies] = useState([]);
const [templates, setTemplates] = useState([]);
const [loading, setLoading] = useState(true);
const [openDialog, setOpenDialog] = useState(false);
const [formData, setFormData] = useState({
company_id: '',
target_email: '',
employee_name: '',
template_type: 'bank',
});
useEffect(() => {
loadData();
}, []);
const loadData = async () => {
try {
const [tokensData, companiesData, templatesData] = await Promise.all([
tokenService.getAll(),
companyService.getAll(),
templateService.getAll(),
]);
setTokens(tokensData.data);
setCompanies(companiesData.data);
setTemplates(templatesData.data);
} catch (error) {
console.error('Failed to load data:', error);
} finally {
setLoading(false);
}
};
const handleCreateAndSend = async () => {
try {
await tokenService.createAndSend(formData);
setOpenDialog(false);
setFormData({ company_id: '', target_email: '', employee_name: '', template_type: 'bank' });
loadData();
alert('Token oluşturuldu ve mail gönderildi!');
} catch (error) {
console.error('Failed to create token:', error);
alert('Token oluşturulamadı: ' + (error.response?.data?.error || error.message));
}
};
if (loading) {
return (
<Box display="flex" justifyContent="center" alignItems="center" minHeight="400px">
<CircularProgress />
</Box>
);
}
return (
<Box>
<Box display="flex" justifyContent="space-between" alignItems="center" mb={3}>
<Typography variant="h4">Tracking Tokenlar</Typography>
<Button
variant="contained"
startIcon={<Add />}
onClick={() => setOpenDialog(true)}
>
Yeni Mail Oluştur
</Button>
</Box>
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow>
<TableCell>Email</TableCell>
<TableCell>Şirket</TableCell>
<TableCell>Çalışan</TableCell>
<TableCell>Durum</TableCell>
<TableCell align="right">Tıklama</TableCell>
<TableCell>Tarih</TableCell>
</TableRow>
</TableHead>
<TableBody>
{tokens.map((token) => (
<TableRow key={token.id} hover sx={{ cursor: 'pointer' }}>
<TableCell>{token.target_email}</TableCell>
<TableCell>{token.company?.name}</TableCell>
<TableCell>{token.employee_name || '-'}</TableCell>
<TableCell>
<Chip
icon={token.clicked ? <Check /> : <Close />}
label={token.clicked ? 'Tıklandı' : 'Bekliyor'}
color={token.clicked ? 'success' : 'default'}
size="small"
/>
</TableCell>
<TableCell align="right">{token.click_count}×</TableCell>
<TableCell>
{format(new Date(token.created_at), 'dd/MM/yyyy HH:mm')}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
<Dialog open={openDialog} onClose={() => setOpenDialog(false)} maxWidth="sm" fullWidth>
<DialogTitle>Yeni Token Oluştur ve Mail Gönder</DialogTitle>
<DialogContent>
<TextField
select
margin="dense"
label="Şirket Seç"
fullWidth
required
value={formData.company_id}
onChange={(e) => setFormData({ ...formData, company_id: e.target.value })}
>
{companies.map((company) => (
<MenuItem key={company.id} value={company.id}>
{company.name}
</MenuItem>
))}
</TextField>
<TextField
margin="dense"
label="Hedef Email"
type="email"
fullWidth
required
value={formData.target_email}
onChange={(e) => setFormData({ ...formData, target_email: e.target.value })}
/>
<TextField
margin="dense"
label="Çalışan Adı (Opsiyonel)"
fullWidth
value={formData.employee_name}
onChange={(e) => setFormData({ ...formData, employee_name: e.target.value })}
/>
<TextField
select
margin="dense"
label="Mail Şablonu"
fullWidth
required
value={formData.template_type}
onChange={(e) => setFormData({ ...formData, template_type: e.target.value })}
>
{templates.map((template) => (
<MenuItem key={template.id} value={template.template_type}>
{template.name}
</MenuItem>
))}
</TextField>
</DialogContent>
<DialogActions>
<Button onClick={() => setOpenDialog(false)}>İptal</Button>
<Button
onClick={handleCreateAndSend}
variant="contained"
disabled={!formData.company_id || !formData.target_email}
>
Oluştur ve Gönder
</Button>
</DialogActions>
</Dialog>
</Box>
);
}
export default Tokens;