Sfoglia il codice sorgente

Add functionality to show exceptions

Closes #49
tags/ActivityRecorder/0.1.1
Chris Smith 14 anni fa
parent
commit
c9d1ec65ad
4 ha cambiato i file con 126 aggiunte e 35 eliminazioni
  1. 1
    35
      website/admin.php
  2. 39
    0
      website/auth.php
  3. 36
    0
      website/exceptions.php
  4. 50
    0
      website/process.php

+ 1
- 35
website/admin.php Vedi File

@@ -1,40 +1,6 @@
1 1
 <?PHP
2 2
 
3
- session_start();
4
-
5
- $allowedIDs = array(
6
-	'https://www.google.com/accounts/o8/id?id=AItOawk9b32oBoVvjzwEhvC2GOhsxj0MN2mWoc8', // Me
7
-	'https://www.google.com/accounts/o8/id?id=AItOawk8LzSeazeZxqMCTVKm-OkUu0mLDLOqBBs', // Simon
8
-	'https://www.google.com/accounts/o8/id?id=AItOawkM5hzpAq2WOz0DDy3N9PnEtqinHbgNrNI', // Shane
9
- );
10
-
11
- if (isset($_SESSION['openid']['error'])) {
12
-
13
-  // Failed OpenID login attempt
14
-  echo 'ERROR: ',  htmlentities($_SESSION['openid']['error']);
15
-  unset($_SESSION['openid']['error']);
16
-  exit;
17
-
18
- } else if (isset($_SESSION['openid']['validated']) && $_SESSION['openid']['validated']) {
19
-
20
-  if (!in_array($_SESSION['openid']['identity'], $allowedIDs)) {
21
-   echo 'ERROR: ', htmlentities($_SESSION['openid']['identity']), ' not permitted';
22
-   exit;
23
-  }
24
-
25
- } else {
26
-
27
-  if (!isset($_REQUEST['openid_mode'])) {
28
-   $_POST['openid_url'] = 'https://www.google.com/accounts/o8/id';
29
-  }
30
-
31
-  require('openid/processor.php');
32
-  exit;
33
-
34
- }
35
-
36
- # -------------- End of authentication code --------------------------
37
-
3
+ require('auth.php');
38 4
  require('common.php');
39 5
 
40 6
  # -------------- Form handling -----------------

+ 39
- 0
website/auth.php Vedi File

@@ -0,0 +1,39 @@
1
+<?PHP
2
+
3
+ session_start();
4
+
5
+ define('OPENID_TRUSTROOT', 'http://chris.smith.name/android/');
6
+
7
+ $allowedIDs = array(
8
+        'https://www.google.com/accounts/o8/id?id=AItOawlVzlhRypZuhvENeUFtVWY_flhmyihDje8', // Me
9
+        'https://www.google.com/accounts/o8/id?id=AItOawkmbwj0T1NMwv9GVrrY5g3VD5WsiVlWUhc', // Simon
10
+        'https://www.google.com/accounts/o8/id?id=AItOawkZ2rNlFp4lHowKWFYFiGRYLi51dlrhAzI', // Shane
11
+ );
12
+
13
+ if (isset($_SESSION['openid']['error'])) {
14
+
15
+  // Failed OpenID login attempt
16
+  echo 'ERROR: ',  htmlentities($_SESSION['openid']['error']);
17
+  unset($_SESSION['openid']['error']);
18
+  exit;
19
+
20
+ } else if (isset($_SESSION['openid']['validated']) && $_SESSION['openid']['validated']) {
21
+
22
+  if (!in_array($_SESSION['openid']['identity'], $allowedIDs)) {
23
+   echo 'ERROR: ', htmlentities($_SESSION['openid']['identity']), ' not permitted';
24
+   unset($_SESSION['openid']);
25
+   exit;
26
+  }
27
+
28
+ } else {
29
+
30
+  if (!isset($_REQUEST['openid_mode'])) {
31
+   $_POST['openid_url'] = 'https://www.google.com/accounts/o8/id';
32
+  }
33
+
34
+  require('openid/processor.php');
35
+  exit;
36
+
37
+ }
38
+
39
+?>

+ 36
- 0
website/exceptions.php Vedi File

@@ -0,0 +1,36 @@
1
+<?PHP
2
+
3
+ require('auth.php');
4
+ require('common.php');
5
+
6
+?>
7
+<h1>Exceptions</h1>
8
+
9
+<?PHP
10
+
11
+ $sql = 'SELECT ex_application, ex_ip, ex_imei, ex_version, ex_trace FROM exceptions ORDER BY ex_application, ex_version';
12
+ $res = mysql_query($sql);
13
+
14
+ function fix($x) { return str_replace('.', '/', $x[1]); }
15
+
16
+ echo '<table border="1">';
17
+
18
+ while ($row = mysql_fetch_assoc($res)) {
19
+
20
+  echo '<tr><td><table>';
21
+  foreach ($row as $k => $v) { echo '<tr><th>', $k, '</th><td>', $k == 'ex_trace' ? ($points = count(explode("\n", $v))) . ' line(s)' : nl2br(htmlentities($v)), '</td></tr>'; }
22
+
23
+  echo '</table>';
24
+
25
+  echo '</td><td><pre>';
26
+
27
+  parse_str($row['ex_trace'], $data);
28
+  echo preg_replace_callback('/__(.*?)__/', 'fix', preg_replace('(at (uk\.co\.md87.*?)(\.[^.]+)\((.*?):([0-9]+)\))', 'at \1\2(<a href="http://github.com/csmith/ContextApi/blob/' . $row['ex_application'] . '/' . $row['ex_version'] . '/code/' . $row['ex_application'] . '/src/__\1__.java#L\4">\3:\4</a>)', htmlentities($data['stacktrace'])));
29
+
30
+  echo '</pre></td>';
31
+  echo '</tr>';
32
+ }
33
+
34
+ echo '</table>';
35
+
36
+?>

+ 50
- 0
website/process.php Vedi File

@@ -4,6 +4,55 @@
4 4
 
5 5
  define('VERSION', 25);
6 6
 
7
+ function processExceptions($records = true) {
8
+  $sql = 'SELECT record_id, record_ip, record_headers, record_data FROM unprocessed';
9
+  $res = mysql_query($sql);
10
+  $count = 0;
11
+
12
+  while ($row = mysql_fetch_assoc($res)) {
13
+   $ip = $row['record_ip'];
14
+
15
+   $headers = array();
16
+
17
+   foreach (explode("\n", $row['record_headers']) as $line) {
18
+    if (preg_match('/(.*?): (.*)$/', $line, $m)) {
19
+     $headers[$m[1]] = $m[2];
20
+    }
21
+   }
22
+
23
+   if (!isset($headers['APPLICATION']) || substr($headers['APPLICATION'], -10) != '-exception') {
24
+    continue;
25
+   }
26
+
27
+   $application = substr($headers['APPLICATION'], 0, -10);
28
+   $imei = isset($headers['IMEI']) ? $headers['IMEI'] : '';
29
+
30
+   if (!ctype_digit($imei) && !empty($imei)) {
31
+    // It's probably an MEID not an IMEI number
32
+    $imei = bchexdec($headers['IMEI']);
33
+   }
34
+
35
+   $version = isset($headers['VERSION']) ? $headers['VERSION'] : '';
36
+   $headers = $row['record_headers'];
37
+   $data = $row['record_data'];
38
+
39
+   $sql  = 'INSERT INTO exceptions (ex_ip, ex_imei, ex_application, ex_version, ';
40
+   $sql .= 'ex_headers, ex_trace) VALUES (';
41
+   $sql .= '\'' . m($ip) . '\', \'' . m($imei) . '\', \'' . m($application) . '\', \'';
42
+   $sql .= m($version) . '\', \'' . m($headers) . '\', \'' . m($data) . '\')';
43
+   mysql_query($sql) or die(mysql_error());
44
+
45
+   $sql  = 'DELETE FROM unprocessed WHERE record_id = ' . $row['record_id'];
46
+   mysql_query($sql);
47
+
48
+   $count++;
49
+  }
50
+
51
+  if ($count > 1 || !$records && $count > 0) {
52
+   Oblong("\002[ANDROID]\002 Processed $count " . ($records ? "new" : "existing") . " exceptions");
53
+  }
54
+ }
55
+
7 56
  function processSensorLogger($records = true) {
8 57
   $sql = $records ? 'SELECT record_id, record_ip, record_headers, record_data FROM unprocessed'
9 58
                   : 'SELECT log_id, log_ip AS record_ip, log_headers AS record_headers, log_data '
@@ -133,5 +182,6 @@
133 182
  }
134 183
 
135 184
  processSensorLogger(!isset($argv[1]) || $argv[1] != '--update');
185
+ processExceptions(!isset($argv[1]) || $argv[1] != '--update');
136 186
 
137 187
 ?>

Loading…
Annulla
Salva