Page MenuHomeGitPull.it

Simplify extraction of JSON debug data received via mail
Closed, ResolvedPublic1 Points

Description

Simplify extraction of JSON debug data received via mail.

Event Timeline

valerio.bozzolan triaged this task as Normal priority.

Done!

https://lab.reyboz.it/libre-busto/crash-report/

1<?php
2# Android Crash Dump exporter for Phabricator
3# Copyright (C) 2021-2025 Valerio Bozzolan, crash report contributors
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Affero General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>
17
18/**
19 * Quick and dirty Android Crash Dump analyzer
20 *
21 * https://gitpull.it/P15
22 */
23
24// This should be less than 50 to avoid "Request-URI Too Long" when creating the task using
25// a super-long GET URL...
26//$logcat_max_lines = 20;
27$logcat_max_lines = 30;
28
29// base of your Phabricator
30define( 'BASE_URI', 'https://gitpull.it/maniphest/task/edit/form/3/?' );
31
32// received data from textarea
33$data_raw = $_POST['data'] ?? null;
34
35// or, receive data from file
36if (!$data_raw && isset($_FILES['data_file']['tmp_name'])) {
37 $data_raw = file_get_contents($_FILES['data_file']['tmp_name']);
38}
39
40$data_clean_text = null;
41$task_args = null;
42if( $data_raw ) {
43
44 $data = @json_decode( $data_raw );
45
46 if( $data ) {
47
48 $data_raw = json_encode( $data, JSON_PRETTY_PRINT );
49
50 $app_version_name = $data->APP_VERSION_NAME ?? null;
51
52 // Take only some lines of logcat.
53 $logcat_reduced = null;
54 $logcat = $data->LOGCAT ?? null;
55 if ($logcat) {
56 $lines = explode("\n", $logcat);
57
58 // Pop last lines, until limit is reached.
59 $last_lines = [];
60 do {
61 $last_line = null;
62 if ($lines) {
63 $last_line = array_pop($lines);
64 }
65 if ($last_line !== null) {
66 // Check if the line is in scope. The 'ACRA' is shit.
67 if (mb_strpos($last_line, ' E/ACRA ') === false) {
68 $last_lines[] = $last_line;
69 }
70 }
71 } while($last_line !== null && count($last_lines) < $logcat_max_lines);
72
73 $last_lines = array_reverse($last_lines);
74 $logcat_reduced = implode("\n", $last_lines);
75 }
76
77 // some useful informations
78 $data_clean = [
79 'Version code' => $data->APP_VERSION_CODE ?? null,
80 'Version name' => $app_version_name,
81 'Android version' => $data->ANDROID_VERSION ?? null,
82 'Phone' => $data->PHONE_MODEL ?? null,
83 'Brand' => $data->BRAND ?? null,
84 'Stack' => $data->STACK_TRACE ?? null,
85 "logcat (last $logcat_max_lines lines)" => $logcat_reduced,
86 ];
87
88 // build an human phrase
89 $data_clean_parts = [];
90 foreach( $data_clean as $k => $v ) {
91 $data_clean_parts[] = "$k:\n$v";
92 }
93 $data_clean_text = implode( "\n\n", $data_clean_parts );
94 $data_clean_text = trim($data_clean_text);
95
96 // build query string
97 $task_args = [
98 'title' => "Fix crash caused by ... on version $app_version_name",
99 'description' => implode( "\n", [
100 "Dear Developers of the amazing Free/Libre and Open Source app #libre_busto,",
101 "Please triage my crash:",
102 '',
103 '```',
104 $data_clean_text,
105 '```',
106 '',
107 '',
108 "Thank you! :)",
109 '',
110 '',
111 "> Generated with https://lab.reyboz.it/libre-busto/crash-report/ (P15)",
112 ] ),
113 ];
114
115 } else {
116 $data_raw = 'invalid';
117 }
118
119}
120
121?>
122<html>
123<head>
124 <title>Libre BusTO - crash report dump</title>
125</head>
126<body>
127
128 <h1>Libre BusTO - crash report dump</h1>
129
130 <form method="post" enctype="multipart/form-data">
131 <?php if( $data_clean_text ): ?>
132 <h2>Generated Crash report</h2>
133 <?php if( $task_args ): ?>
134 <p>
135 <a href="<?= htmlspecialchars( BASE_URI . http_build_query( $task_args ) )?>" target="_blank">Create New Task in Phorge</a>
136 </p>
137 <?php endif ?>
138 <p>Preview of Task Content:<br />
139 <textarea readonly><?= htmlentities( $data_clean_text ) ?></textarea>
140 </p>
141
142 <hr />
143 <?php endif ?>
144
145 <h2>Generate New Crash Report</h2>
146
147 <p>Upload here our JSON crash report:</p>
148 <p><input type="file" name="data_file" accept="application/json" /></p>
149
150 <p>or, paste here our JSON crash report:</p>
151 <p><textarea name="data"><?= htmlentities( $data_raw ) ?></textarea></p>
152
153 <p><button type="submit">OK</button></p>
154 </form>
155
156 <hr />
157
158 <p><a href="https://gitpull.it/tag/libre_busto/">Workboard</a></p>
159
160 <hr />
161
162 <p><a href="https://gitpull.it/P15" target="_blank">Source code and license</a></p>
163
164</body>
165</html>
166