emailPoubelleAdmin.php 6.82 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

//-----------------------------------------------------------
// Title : Email Poubelle
// Licence : GNU GPL v3 : http://www.gnu.org/licenses/gpl.html
// Author : David Mercereau - david [aro] mercereau [.] info
// Home : http://poubelle.zici.fr
// Date : 08/2013
// Version : 1.0
// Depend : Postifx (postmap command) php-pdo
//----------------------------------------------------------- 

session_start();

$auth=false;
if (isset($_POST['adminPassword'])) {
	$_SESSION['adminPasswordHash'] = password_hash($_POST['adminPassword'], PASSWORD_DEFAULT);
}
if (isset($_SESSION['adminPasswordHash'])) {
David's avatar
David committed
20
	if (password_verify(ADMIN_PASSWORD, $_SESSION['adminPasswordHash'])) {
21
22
23
24
25
26
		$auth=true;
	} else {
		$auth=false;
	}
}
if (isset($_POST['adminPassword']) && $auth==false) {
David's avatar
David committed
27
	echo '<div class="highlight-1">'._('Error: Incorrect password').'</div>';
28
29
30
}
if (empty($_SESSION['adminPasswordHash']) || $auth == false) {
	echo '<form action="#" method="post">
David's avatar
David committed
31
	<label>'.('The admin password').' : </label>
32
33
34
35
36
37
38
	<input type="password" name="adminPassword" />
	<input type="submit" />
	</form>';
}

// Test connexion, si c'est ok : 
if ($auth==true) {
David's avatar
David committed
39
	languesSwitch();
40
41
42
43
44
45
46
47
48
	// Connect DB
	try {
		if (preg_match('/^sqlite/', DB)) {
			$dbco = new PDO(DB);
		} else {
			$dbco = new PDO(DB, DBUSER, DBPASS);
		}
		$dbco->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	} catch ( PDOException $e ) {
David's avatar
David committed
49
		die('DB connect error :  '.$e->getMessage());
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
	}
	if (isset($_POST['action'])) {
		if ($_POST['action'] == 'DeleteEmail' && isset($_POST['email'])) {
			DeleteEmail($_POST['email']);
		}
		if ($_POST['action'] == 'AddBlacklistEmail' && isset($_POST['email'])) {
			AddBlacklistEmail($_POST['email']);
		}
		if ($_POST['action'] == 'DeleteAlias' && isset($_POST['id']) && isset($_POST['alias'])) {
			 DeleteAlias($_POST['id'], $_POST['alias']);
		}
		if ($_POST['action'] == 'DisableAlias' && isset($_POST['id']) && isset($_POST['alias'])) {
			 DisableAlias($_POST['id'], $_POST['alias'], $_POST['email']);
		}
	}
	?>
	<script>
	function confirmation(idForm, idAction, action) {
		if (confirm(action + " : êtes-vous sûr ?")) {
			document.getElementById(idAction).value = action;
			document.getElementById(idForm).submit();
		} 
	}
    </script>
	<?php
David's avatar
David committed
75
	echo '<p>'._('Statistics').' : </p>';
76
	echo '<ul>';
David's avatar
David committed
77
78
79
80
	echo '<li>'._('Total alias').' : '.$dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias")->fetchColumn().'</li>';
	echo '<li>'._('Active alias').' : '.$dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE status = 5")->fetchColumn().'</li>';
	echo '<li>'._('Alias suspended').' : '.$dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE status = 3")->fetchColumn().'</li>';
	echo '<li>'._('Alias not verified').' : '.$dbco->query("SELECT COUNT(*) FROM ".DBTABLEPREFIX."alias WHERE status = 0")->fetchColumn().'</li>';
81
82
83
84
85
	//echo '<li>Email différent : '.$dbco->query("SELECT DISTINCT count(email) FROM ".DBTABLEPREFIX."alias WHERE status = 5")->fetchColumn().'</li>';
	echo '</ul>';
	
	echo '<h3 id="user">User info</h3>';
	echo '<form action="#" method="post">
David's avatar
David committed
86
	<label>'._('User email').' : </label>
87
88
89
90
91
	<input type="text" value="'.$_POST['email'].'" name="email" />
	<input type="submit" />
	</form>';
	if (isset($_POST['email'])) {
		$requestUtilisateur = $dbco->query("SELECT * FROM ".DBTABLEPREFIX."alias WHERE email='".$_POST['email']."' ORDER BY dateCreat DESC")->fetchAll() ;
David's avatar
David committed
92
		echo '<p>User '.$_POST['email'].' : ';
93
94
95
96
97
98
		if (count($requestUtilisateur) != 0) {
			echo '<img onclick="confirmation(\'uniqemail_'.$_POST['email'].'\', \'uniqaction_'.$_POST['email'].'\', \'DeleteEmail\')" src="'.URLINC.'/sup.png" alt="sup" />';
			if (!BlacklistEmail($_POST['email'])) {
				echo '<img onclick="confirmation(\'uniqemail_'.$_POST['email'].'\', \'uniqaction_'.$_POST['email'].'\', \'AddBlacklistEmail\')" src="'.URLINC.'/blk.png" alt="blk" />';
			}
		} else {
David's avatar
David committed
99
			echo 'Not found !';
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
		}
		echo '<form style="display: none" method="post" action="#" id="uniqemail_'.$_POST['email'].'">
		<input type="hidden" name="email" value="'.$_POST['email'].'" />
		<input type="hidden" id="uniqaction_'.$_POST['email'].'" name="action" value="" />
		</form>';
		echo '</p>';
		if (count($requestUtilisateur) != 0) {
			echo '<table>';
			echo '<tr>
					<th>Status</th>
					<th>Alias</th>
					<th>DateCreat</th>
					<th>DateExpir</th>
					<th>Comment</th>
			</tr>';
			foreach ($requestUtilisateur as $utilisateur) {
				echo '<tr>
					<td><img src="'.URLINC.'/status'.$utilisateur['status'].'.png" alt="'.$utilisateur['status'].'" /></td>
					<td>'.$utilisateur['alias'].'
					<br /><form style="display: none" method="post" action="#" id="alias'.$utilisateur['id'].'">
					<input type="hidden" name="id" value="'.$utilisateur['id'].'" />
					<input type="hidden" name="alias" value="'.$utilisateur['alias'].'" />
					<input type="hidden" name="email" value="'.$_POST['email'].'" />
					<input type="hidden" id="action'.$utilisateur['id'].'" name="action" value="" />
					</form>
					<img onclick="confirmation(\'alias'.$utilisateur['id'].'\', \'action'.$utilisateur['id'].'\', \'DeleteAlias\')" src="'.URLINC.'/sup.png" alt="sup" />';
					if ($utilisateur['status'] == 5) {
						echo '<img onclick="confirmation(\'alias'.$utilisateur['id'].'\', \'action'.$utilisateur['id'].'\', \'DisableAlias\')" src="'.URLINC.'/status3.png" alt="Suspendre" />';
					}
					echo '</td>
					<td>'.$utilisateur['dateCreat'].'</td>
					<td>'.$utilisateur['dateExpir'].'</td>
					<td>'.$utilisateur['comment'].'</td>
				</tr>';
			}
			echo '</table>';
		}
	}
	
	echo '<h3 id="top">Top user </h3>';
	$recordActifs = $dbco->query("SELECT email, count(alias) calias FROM ".DBTABLEPREFIX."alias WHERE status=5 GROUP BY email ORDER BY calias DESC LIMIT 40")->fetchAll();
	echo '<table>';
	echo '<tr>
			<th>Email</th>
David's avatar
David committed
144
			<th style="text-align: center">Number of alias</th>
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
			<th style="text-align: center">Action</th>
	</tr>';
	foreach ($recordActifs as $recordActif) {
		echo '<tr>
			<td>';
			if (BlacklistEmail($recordActif['email'])) {
				echo '<img src="'.URLINC.'/blk.png" alt="blk" /> ';
			}
			echo $recordActif['email'].'</td>
			<td style="text-align: center">'.$recordActif['calias'].'</td>
			<td style="text-align: center">
				<form style="display: none" method="post" action="#" id="email_'.$recordActif['email'].'">
				<input type="hidden" name="email" value="'.$recordActif['email'].'" />
				<input type="hidden" id="action_'.$recordActif['email'].'" name="action" value="" />
				</form>
				<img onclick="confirmation(\'email_'.$recordActif['email'].'\', \'action_'.$recordActif['email'].'\', \'DeleteEmail\')" src="'.URLINC.'/sup.png" alt="sup" />';
				if (!BlacklistEmail($recordActif['email'])) {
					echo '<img onclick="confirmation(\'email_'.$recordActif['email'].'\', \'action_'.$recordActif['email'].'\', \'AddBlacklistEmail\')" src="'.URLINC.'/blk.png" alt="blk" />';
				}
				echo '
			</td>
		</tr>';
	}
	echo '</table>';
	
}



?>