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