try cookie
[clinton/MarylandElectronicPetitionSignature.git] / admin / analytics.php
1 <?PHP
2 include_once('bots.php');
3 include_once('../slack.php');
4 include_once('security.php');
5 include_once('/var/www/secure.php'); //outside webserver
6 include_once('functions.php');
7
8
9 $sign_email = $_COOKIE['sign_email'];
10 if (isset($_GET['sign_email'])){
11 // here we use it, if it shows up next run, we block
12 $sign_email = $_GET['sign_email'];
13 $_COOKIE['sign_email'] = $sign_email;
14 slack_general('SETTING COOKIE ('.$_COOKIE['sign_email'].') FROM ('.$_GET['sign_email'].')','md-petition');
15 }
16
17 function js_redirect($page){
18 $base = 'https://www.md-petition.com/admin/';
19 $url = $base.$page;
20 $pos = strpos($page, $_SESSION['sign_email']);
21 if ($pos === false) {
22 // email not found - good to redirect
23 echo "<script>window.location.href = \"$url\";</script>";
24 slack_general('CHECK COOKIE ('.$_COOKIE['sign_email'].') PAGE ('.$page.')','md-petition');
25 die();
26 } else {
27 echo "<h1>Automated Loop Detected - Skip</h1>";
28 }
29
30 }
31
32 if ($_COOKIE['level'] == 'user'){
33 slack_general('ADMIN: Redirect User Home ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
34 header('Location: user_home.php');
35 }
36 if (isset($_GET['clear_php_session_id'])){
37 $id = $_GET['clear_php_session_id'];
38 $petition->query("update presign set presign_status = 'DONE' where php_session_id = '$id' ");
39 header('Location: analytics.php');
40 }
41 if (isset($_GET['clear_email'])){
42 $email = $_GET['clear_email'];
43 $petition->query("update presign set presign_status = 'DONE' where email_for_follow_up = '$email' ");
44 header('Location: analytics.php');
45 }
46 if (isset($_GET['sign_email'])){
47 $email = $_GET['sign_email'];
48 $petition->query("update presign set presign_status = 'SIGNED' where email_for_follow_up = '$email' ");
49 header('Location: analytics.php');
50 }
51 if (isset($_GET['sign_php_session_id'])){
52 $id = $_GET['sign_php_session_id'];
53 $petition->query("update presign set presign_status = 'SIGNED' where php_session_id = '$id' ");
54 header('Location: analytics.php');
55 }
56 if ($_COOKIE['level'] == 'manager'){
57 slack_general('ADMIN: Redirect Manager Home ('.$_COOKIE['name'].') ('.$_COOKIE['level'].')','md-petition');
58 header('Location: manager_home.php');
59 }
60 if (isset($_GET['flag_invalid_signature'])){
61 $id = $_GET['flag_invalid_signature'];
62 $petition->query("update signatures set signature_status = 'flag_invalid_signature' where id = '$id' ");
63 header('Location: analytics.php');
64 }
65 if (isset($_GET['flag_duplicate'])){
66 $id = $_GET['flag_duplicate'];
67 $petition->query("update signatures set signature_status = 'flag_duplicate' where id = '$id' ");
68 header('Location: analytics.php');
69 }
70 if (isset($_GET['flag_ip_address'])){
71 $ip = $_GET['flag_ip_address'];
72 $petition->query("update signatures set signature_status = 'flag_ip_address' where ip_address = '$ip' ");
73 header('Location: analytics.php');
74 }
75 if (isset($_GET['resign_requested'])){
76 $id = $_GET['resign_requested'];
77 $petition->query("update signatures set signature_status = 'resign_requested' where id = '$id' ");
78 header('Location: analytics.php');
79 }
80 if (isset($_GET['bot'])){
81 $id = $_GET['bot'];
82 $petition->query("update signatures set signature_status = 'bot' where id = '$id' ");
83 header('Location: analytics.php');
84 }
85 if (isset($_GET['flag_VTRID'])){
86 $VTRID = $_GET['flag_VTRID'];
87 $petition->query("update signatures set signature_status = 'flag_VTRID' where VTRID = '$VTRID' ");
88 header('Location: analytics.php');
89 }
90 if (isset($_GET['flag_phone'])){
91 $flag_phone = $_GET['flag_phone'];
92 $petition->query("update signatures set signature_status = 'flag_phone' where contact_phone = '$flag_phone' ");
93 header('Location: analytics.php');
94 }
95 include_once('header.php');
96 if (isset($_GET['ip_address'])){
97 $ip = $_GET['ip_address'];
98 $petition_id = $_GET['petition_id'];
99 echo "<h1>Review $ip</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";
100 $q = "SELECT * FROM signatures where ip_address = '$ip' and signature_status = 'verified' and petition_id = '$petition_id' order by signature_status desc ";
101 $r = $petition->query($q);
102 while($d = mysqli_fetch_array($r)){
103 $color = 'white';
104 $pos = strpos($d['date_time_signed'], date('Y-m-d'));
105 if ($pos !== false) {
106 $color= 'yellow';
107 }
108 echo "<tr style='background-color:$color;'>
109 <td><b>$d[date_time_signed]</b></td>
110 <td><a href='?VTRID=$d[VTRID]'>$d[VTRID]</a></td>
111 <td>".id2petition($d['petition_id'])."</td>
112 <td>$d[signed_name_as]</td>
113 <td>$d[signed_name_as_circulator]</td>
114 <td>$d[contact_phone]</td>
115 <td>$d[printed_status]</td>
116 <td><a href='?flag_invalid_signature=$d[id]'>flag invalid signature</a></td>
117 <td><a href='?flag_VTRID=$d[VTRID]'>flag VTRID</a></td>
118 <td><a href='?flag_ip_address=$d[ip_address]'>flag ip address</a></td>
119 <td><a href='?flag_duplicate=$d[id]'>flag duplicate</a></td>
120 <td><a href='?flag_phone=$d[contact_phone]'>contact phone</a></td>
121 <td><a href='?resign_requested=$d[id]'>resign requested</a></td>
122 <td><a href='?bot=$d[id]'>bot</a></td>
123 </tr>";
124 }
125 echo "</table>";
126 }elseif(isset($_GET['email'])){
127 $email = $_GET['email'];
128 echo "<h1>Review $email</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";
129 $q = "SELECT * FROM presign where email_for_follow_up = '$email' order by id desc ";
130 $r = $petition->query($q);
131 while($d = mysqli_fetch_array($r)){
132 $color = 'white';
133 $test = date('Y-m-d',strtotime($d['action_on']));
134 $pos = strpos($test, date('Y-m-d'));
135 if ($pos !== false) {
136 $color= 'yellow';
137 }
138 echo "<tr style='background-color:$color;'>
139 <td style='white-space:pre;'><b>$d[action_on]</b></td>
140 <td style='white-space:pre;'><a href='?php_session_id=$d[php_session_id]'>$d[php_session_id]</a></td>
141 <td style='white-space:pre;'>$d[php_page]</td>
142 <td style='white-space:pre;'>".id2petition($d['petition'])."</td>
143 <td style='white-space:pre;'>$d[invite]</td>
144 <td style='white-space:pre;'>$d[invite_error]</td>
145 <td style='white-space:pre;'>$d[name]</td>
146 <td style='white-space:pre;'>$d[email_for_follow_up]</td>
147 <td style='white-space:pre;'>$d[phone_for_validation]</td>
148 <td style='white-space:pre;'>$d[presign_status]</td>
149 <td style='white-space:pre;'>$d[ip_address]</td>
150 <td style='white-space:pre;'>$d[browser_string]</td>
151 </tr>";
152 }
153 echo "</table><a href='?clear_email=$email'>CLEAR EMAIL</a> - <a href='?sign_email=$email'>SIGNATURE FOUND</a>";
154 }elseif(isset($_GET['php_session_id']) && empty($_GET['follow_up'])){
155 $php_session_id = $_GET['php_session_id'];
156 echo "<h1>Review $php_session_id</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";
157 $q = "SELECT * FROM presign where php_session_id = '$php_session_id' order by id desc ";
158 $r = $petition->query($q);
159 while($d = mysqli_fetch_array($r)){
160 $color = 'white';
161 $test = date('Y-m-d',strtotime($d['action_on']));
162 $pos = strpos($test, date('Y-m-d'));
163 if ($pos !== false) {
164 $color= 'yellow';
165 }
166 echo "<tr style='background-color:$color;'>
167 <td style='white-space:pre;'><b>$d[action_on]</b></td>
168 <td style='white-space:pre;'>$d[php_page]</td>
169 <td style='white-space:pre;'>".id2petition($d['petition'])."</td>
170 <td style='white-space:pre;'>$d[invite]</td>
171 <td style='white-space:pre;'>$d[invite_error]</td>
172 <td style='white-space:pre;'>$d[name]</td>
173 <td style='white-space:pre;'><a href='?email=$d[email_for_follow_up]'>$d[email_for_follow_up]</a></td>
174 <td style='white-space:pre;'>$d[phone_for_validation]</td>
175 <td style='white-space:pre;'>$d[presign_status]</td>
176 <td style='white-space:pre;'>$d[ip_address]</td>
177 <td style='white-space:pre;'>$d[browser_string]</td>
178 </tr>";
179 }
180 echo "</table><a href='?clear_php_session_id=$php_session_id'>CLEAR SESSION</a> -
181 <a href='?sign_php_session_id=$php_session_id'>SIGNATURE FOUND</a><br>
182 - <a href='?php_session_id=$php_session_id&follow_up=X'>ADD TO FOLLOW UP LIST Maryland General</a><br>
183 - <a href='?php_session_id=$php_session_id&follow_up=1'>ADD TO FOLLOW UP LIST MGP</a><br>
184 - <a href='?php_session_id=$php_session_id&follow_up=2'>ADD TO FOLLOW UP LIST MLP</a><br>
185 - <a href='?php_session_id=$php_session_id&follow_up=3'>ADD TO FOLLOW UP LIST BTEC</a><br>
186 - <a href='?php_session_id=$php_session_id&follow_up=7'>ADD TO FOLLOW UP LIST PG</a><br>
187 - <a href='?php_session_id=$php_session_id&follow_up=8'>ADD TO FOLLOW UP LIST Ivey</a>
188 ";
189 }elseif(isset($_GET['php_session_id']) && isset($_GET['follow_up'])){
190 $php_session_id = $_GET['php_session_id'];
191 echo "<h1>Adding Follow up for $php_session_id to $_GET[follow_up]</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";
192 $q = "SELECT * FROM presign where php_session_id = '$php_session_id' order by id desc ";
193 $r = $petition->query($q);
194 while($d = mysqli_fetch_array($r)){
195
196 $color = 'white';
197 $test = date('Y-m-d',strtotime($d['action_on']));
198 $pos = strpos($test, date('Y-m-d'));
199 if ($pos !== false) {
200 $color= 'yellow';
201 }
202 if ($d[name] != ''){
203 $name = $d[name];
204 }
205 if ($d[email_for_follow_up] != ''){
206 $email = $d[email_for_follow_up];
207 }
208 echo "<tr style='background-color:$color;'>
209 <td style='white-space:pre;'><b>$d[action_on]</b></td>
210 <td style='white-space:pre;'>$d[php_page]</td>
211 <td style='white-space:pre;'>".id2petition($d['petition'])."</td>
212 <td style='white-space:pre;'>$d[invite]</td>
213 <td style='white-space:pre;'>$d[invite_error]</td>
214 <td style='white-space:pre;'>$d[name]</td>
215 <td style='white-space:pre;'>$d[email_for_follow_up]</td>
216 <td style='white-space:pre;'>$d[phone_for_validation]</td>
217 <td style='white-space:pre;'>$d[presign_status]</td>
218 <td style='white-space:pre;'>$d[ip_address]</td>
219 <td style='white-space:pre;'>$d[browser_string]</td>
220 </tr>";
221 }
222 $petition->query("insert into follow_up (name, email, php_session, petition_id, date_sent) values ('$name','$email','$php_session_id','$_GET[follow_up]','".date('Y-m-d')."') ");
223 $petition->query("update presign set presign_status = 'DONE' where php_session_id = '$php_session_id' ");
224 $petition->query("update presign set presign_status = 'DONE' where email_for_follow_up = '$email' ");
225 echo "</table>";
226 }elseif (isset($_GET['VTRID'])){
227 $VTRID = $_GET['VTRID'];
228 $petition_id = $_GET['petition_id'];
229 echo "<h1>Review $VTRID</h1><table width='100%' border='1' cellpadding='5' cellspacing='5'>";
230 $q = "SELECT * FROM signatures where VTRID = '$VTRID' and signature_status = 'verified' and petition_id = '$petition_id' order by petition_id, id DESC ";
231 $r = $petition->query($q);
232 $i=0;
233 while($d = mysqli_fetch_array($r)){
234 $color = 'white';
235 $pos = strpos($d['date_time_signed'], date('Y-m-d'));
236 if ($pos !== false) {
237 $color= 'yellow';
238 }
239 echo "<tr style='background-color:$color;'>
240 <td><b>$d[date_time_signed]</b></td>
241 <td><a href='?ip_address=$d[ip_address]'>$d[ip_address]</a></td>
242 <td>".id2petition($d['petition_id'])."</td>
243 <td>$d[signed_name_as]</td>
244 <td>$d[signed_name_as_circulator]</td>
245 <td>$d[contact_phone]</td>
246 <td>$d[printed_status]</td>
247 <td><a href='?flag_invalid_signature=$d[id]'>flag invalid signature</a></td>
248 <td><a href='?flag_VTRID=$d[VTRID]'>flag VTRID</a></td>
249 <td><a href='?flag_ip_address=$d[ip_address]'>flag ip address</a></td>
250 <td><a href='?flag_duplicate=$d[id]'>flag duplicate</a></td>
251 <td><a href='?flag_phone=$d[contact_phone]'>contact phone</a></td>
252 <td><a href='?resign_requested=$d[id]'>resign requested</a></td>
253 <td><a href='?bot=$d[id]'>bot</a></td>
254 </tr>";
255 if ($i == 0){
256 js_redirect("analytics.php?flag_duplicate=$d[id]");
257 }
258 $i++;
259 }
260 echo "</table>";
261 die();
262 }
263 ?>
264
265 <h1>Signature Analytics - Server Clock: <?PHP echo date('r');?></h1>
266 <h2>NEVER NEVER NEVER CALL OR TEXT ANYONE - ONLY EMAIL!!!</h2>
267 <h3>SysOp Says: Transparency = Trust</h3>
268 <table>
269
270 <tr>
271 <td valign="top" colspan='2'><?PHP /*
272 <h2>IP Address</h2>
273 <div>Watching for duplicates.</div><ol>
274 <?PHP
275 $q="SELECT ip_address, petition_id,VTRID, COUNT(*) as count FROM signatures where signature_status = 'verified' group by ip_address, petition_id, VTRID";
276 $r = $petition->query($q);
277 while($d = mysqli_fetch_array($r)){
278 if ($d['count'] > 1){
279 echo "<li><a href='?ip_address=$d[ip_address]&petition_id=$d[petition_id]'>$d[ip_address]</a> ".id2petition($d['petition_id'])." <b>$d[count]</b> $d[signed_name_as]</li>";
280 }
281 }
282 ?></ol>
283 </td><td valign="top"> */ ?>
284 <h2>VTRID</h2>
285 <div>Watching for duplicates.</div><ol>
286 <?PHP
287 $q="SELECT VTRID, petition_id, COUNT(*) as count FROM signatures where signature_status = 'verified' group by VTRID, petition_id";
288 $r = $petition->query($q);
289 $i=0;
290 while($d = mysqli_fetch_array($r)){
291 if ($d['count'] > 1){
292 echo "<li><a href='?VTRID=$d[VTRID]&petition_id=$d[petition_id]'>$d[VTRID]</a> ".id2petition($d['petition_id'])." <b>$d[count]</b> $d[signed_name_as]</li>";
293 if ($i == 0){
294 js_redirect("analytics.php?VTRID=$d[VTRID]&petition_id=$d[petition_id]");
295 }
296 $i++;
297 }
298
299 }
300 ?></ol>
301 </td></tr>
302
303
304 <tr>
305 <td valign="top" colspan='2'>
306 <h2>Pre-Sign</h2>
307 <div>Follow up requested - never signed.</div>
308 <form method='GET'><input name='email'><input type='submit' value='SEARCH E-MAIL'></form><table>
309 <?PHP
310 $q="SELECT distinct php_session_id FROM presign where presign_status = 'NEW' and email_for_follow_up <> '' order by id";
311 $r = $petition->query($q);
312 while($d = mysqli_fetch_array($r)){
313 $q2="SELECT * FROM presign where php_session_id = '$d[php_session_id]' order by id desc";
314 $r2 = $petition->query($q2);
315 $d2 = mysqli_fetch_array($r2);
316 $sig = '';
317 if ($d2['name'] != ''){
318 $q3 = "SELECT date_time_signed FROM signatures where signed_name_as = '$d2[name]'";
319 $r3 = $petition->query($q3);
320 $d3 = mysqli_fetch_array($r3);
321 if ($d3['date_time_signed'] != ''){
322 $sig = "<b><a href='?sign_email=$d2[email_for_follow_up]'>SIGNATURE $d3[date_time_signed]</a></b><br>";
323 js_redirect("analytics.php?sign_email=$d2[email_for_follow_up]");
324 }
325 }
326 $presig='';
327 $q4="SELECT * FROM presign where email_for_follow_up = '$d2[email_for_follow_up]' and php_page like '/sign.php%'";
328 $r4 = $petition->query($q4);
329 $d4 = mysqli_fetch_array($r4);
330 if ($d4['action_on']){
331 $presig = "<b><a href='?sign_email=$d2[email_for_follow_up]'>PRESIG $d4[action_on]</a></b><br>";
332 js_redirect("analytics.php?sign_email=$d2[email_for_follow_up]");
333 }
334 $invite_error='';
335 $q4="SELECT * FROM presign where email_for_follow_up = '$d2[email_for_follow_up]' and invite_error <> '' ";
336 $r4 = $petition->query($q4);
337 $d4 = mysqli_fetch_array($r4);
338 if ($d4['invite_error'] != ''){
339 $invite_error = "<b><a href='?clear_email=$d2[email_for_follow_up]'>$d4[invite_error]</a></b><br>";
340 js_redirect("analytics.php?clear_email=$d2[email_for_follow_up]");
341 }
342 $php_session_id = $d2['php_session_id'];
343 echo "<tr><td><a href='?php_session_id=$php_session_id'>$d2[action_on]</a></td><td>$presig $sig $invite_error</td>
344 <td>$d2[name]</td><td><a href='?email=$d2[email_for_follow_up]'>$d2[email_for_follow_up]</a></td>
345 <td>".id2petition($d2['petition'])."</td><td>$d2[invite]</td>
346 <td><a href='?php_session_id=$php_session_id&follow_up=X'>General</a>
347 - <a href='?php_session_id=$php_session_id&follow_up=1'>MGP</a>
348 - <a href='?php_session_id=$php_session_id&follow_up=2'>MLP</a>
349 - <a href='?php_session_id=$php_session_id&follow_up=3'>BTEC</a>
350 - <a href='?php_session_id=$php_session_id&follow_up=7'>PG</a>
351 - <a href='?php_session_id=$php_session_id&follow_up=8'>Ivey</a></td></tr>";
352 if( $presig == '' && $invite_error == '' && $sig == '' ){
353 if ($d2['invite'] == 'Ivey'){
354 js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=8");
355 }
356 if ($d2['invite'] == 'mlp'){
357 js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=2");
358 }
359 if ($d2['invite'] == 'BTEC'){
360 js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=3");
361 }
362 if ($d2['invite'] == 'RestorePGTermLimits'){
363 js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=7");
364 }
365 if ($d2['invite'] == 'mgp'){
366 js_redirect("analytics.php?php_session_id=$php_session_id&follow_up=1");
367 }
368 }
369 }
370 ?></table>
371 </td>
372 </tr>
373 <tr>
374 <td valign="top" colspan='2'>
375 <h2>Signatures</h2>
376 <div>Last 10</div><ol>
377 <?PHP
378 $q="SELECT * FROM signatures where signature_status = 'verified' order by id desc limit 0, 10";
379 $r = $petition->query($q);
380 while($d = mysqli_fetch_array($r)){
381 echo "<li>$d[date_time_signed] ".id2petition($d['petition_id'])." $d[signed_name_as]</li>";
382 }
383 ?></ol>
384
385 </td>
386
387 </tr>
388 <tr><td valign="top">
389 <h2>VTRID Bugs</h2>
390 <div>Watching for 0</div><ol>
391 <?PHP
392 $q="SELECT * FROM signatures where VTRID = '0' and signature_status <> 'bot' and signature_status <> 'flag_invalid_signature' and signature_status <> 'resign_requested'";
393 $r = $petition->query($q);
394 while($d = mysqli_fetch_array($r)){
395 echo "<li>$d[date_time_signed] <a href='?ip_address=$d[ip_address]'>$d[ip_address]</a> <a target='_Blank' href='https://ipinfo.io/$d[ip_address]'>IP INFO</a> $d[petition_id] $d[signed_name_as]</li>";
396 }
397 ?></ol>
398 </td><td valign="top">
399 <h2>Petition ID Bugs</h2>
400 <div>Watching for 0</div><ol>
401 <?PHP
402 $q="SELECT * FROM signatures where (petition_id = '0' or petition_id = '') and signature_status <> 'bot' and signature_status <> 'flag_invalid_signature' and signature_status <> 'resign_requested'";
403 $r = $petition->query($q);
404 while($d = mysqli_fetch_array($r)){
405 echo "<li>$d[date_time_signed] <a href='?ip_address=$d[ip_address]'>$d[ip_address]</a> <a target='_Blank' href='https://ipinfo.io/$d[ip_address]'>IP INFO</a> $d[petition_id] $d[signed_name_as]</li>";
406 }
407 ?></ol>
408 </td></tr><tr><td valign="top">
409 <?PHP ob_start(); ?>
410 <h2>resign_requested</h2>
411 <div>These are most likely from early bugs</div><ol>
412 <?PHP
413 $q="SELECT * FROM signatures where signature_status = 'resign_requested' order by ip_address";
414 $r = $petition->query($q);
415 $show = 0;
416 while($d = mysqli_fetch_array($r)){
417 $show = 1;
418 echo "<li>$d[date_time_signed] <a href='?ip_address=$d[ip_address]'>$d[ip_address]</a> <a target='_Blank' href='https://ipinfo.io/$d[ip_address]'>IP INFO</a> <a href='?VTRID=$d[VTRID]'>$d[VTRID]</a> $d[petition_id] $d[signed_name_as]</li>";
419 }
420 ?></ol>
421 <?PHP $html = ob_get_clean(); if ( $show == 1 ){ echo $html; } ?>
422 </td>
423
424 <td valign="top">
425 <?PHP ob_start(); ?>
426 <h2>bots</h2>
427 <div>These are bots on the site.</div><ol>
428 <?PHP
429 $q="SELECT * FROM signatures where signature_status = 'bot' order by ip_address";
430 $r = $petition->query($q);
431 $show = 0;
432 while($d = mysqli_fetch_array($r)){
433 $show = 1;
434 echo "<li>$d[date_time_signed] <a href='?ip_address=$d[ip_address]'>$d[ip_address]</a> <a target='_Blank' href='https://ipinfo.io/$d[ip_address]'>IP INFO</a> <a href='?VTRID=$d[VTRID]'>$d[VTRID]</a> $d[petition_id] $d[signed_name_as]</li>";
435 }
436 ?></ol>
437 <?PHP $html = ob_get_clean(); if ( $show == 1 ){ echo $html; } ?>
438
439 </td>
440
441
442 </tr>
443
444 </table>
445
446
447 <?PHP
448 include_once('footer.php');
449 ?>