Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
debde29c
Commit
debde29c
authored
Aug 24, 2015
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crash reporter: refactor while at it; #241
parent
e7a233b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
68 deletions
+72
-68
crash_reporter.php
src/www/crash_reporter.php
+72
-68
No files found.
src/www/crash_reporter.php
View file @
debde29c
...
...
@@ -31,8 +31,6 @@
require_once
(
"guiconfig.inc"
);
require_once
(
"captiveportal.inc"
);
define
(
"FILE_SIZE"
,
450000
);
function
upload_crash_report
(
$files
,
$agent
)
{
global
$g
;
...
...
@@ -81,26 +79,11 @@ $crash_report_header = sprintf(
$pkgver
=
explode
(
'-'
,
trim
(
file_get_contents
(
'/usr/local/opnsense/version/opnsense'
)));
$user_agent
=
$g
[
'product_name'
]
.
'/'
.
$pkgver
[
0
];
$has_crashed
=
get_crash_report
(
true
)
!=
''
;
$crash_reports
=
array
();
?>
<body>
<?php
include
(
"fbegin.inc"
);
?>
<section
class=
"page-content-main"
>
<div
class=
"container-fluid"
>
<div
class=
"row"
>
<section
class=
"col-xs-12"
>
<div
class=
"content-box"
>
<form
action=
"crash_reporter.php"
method=
"post"
>
<div
class=
"col-xs-12"
>
<?php
if
(
isset
(
$_POST
[
'Submit'
])
&&
$_POST
[
'Submit'
]
==
'yes'
)
{
echo
'<br/><p>'
.
gettext
(
'Processing...'
);
flush
();
if
(
isset
(
$_POST
[
'Submit'
]))
{
if
(
$_POST
[
'Submit'
]
==
'yes'
)
{
if
(
!
is_dir
(
'/var/crash'
))
{
mkdir
(
'/var/crash'
,
0750
,
true
);
}
...
...
@@ -117,64 +100,85 @@ $user_agent = $g['product_name'] . '/' . $pkgver[0];
@
copy
(
'/var/run/dmesg.boot'
,
'/var/crash/dmesg.boot'
);
exec
(
'/usr/bin/gzip /var/crash/*'
);
$files_to_upload
=
glob
(
'/var/crash/*'
);
echo
gettext
(
'ok'
)
.
'<br/>'
.
gettext
(
'Uploading...'
);
flush
();
$resp
=
upload_crash_report
(
$files_to_upload
,
$user_agent
);
echo
(
$resp
?
gettext
(
'ok'
)
:
gettext
(
'failed'
))
.
'</p>'
;
array_map
(
'unlink'
,
$files_to_upload
);
}
elseif
(
isset
(
$_POST
[
'Submit'
])
&&
$_POST
[
'Submit'
]
==
'no'
)
{
}
elseif
(
$_POST
[
'Submit'
]
==
'no'
)
{
array_map
(
'unlink'
,
glob
(
'/var/crash/*'
));
@
unlink
(
'/tmp/PHP_errors.log'
);
}
elseif
(
$_POST
[
'Submit'
]
==
'new'
)
{
/* force a crash report generation */
$has_crashed
=
true
;
}
}
if
(
get_crash_report
(
true
)
!=
''
||
(
isset
(
$_POST
[
'Submit'
])
&&
$_POST
[
'Submit'
]
==
'new'
))
{
$crash_files
=
glob
(
"/var/crash/*"
);
$crash_reports
[
'System Information'
]
=
trim
(
$crash_report_header
);
$php_errors
=
@
file_get_contents
(
'/tmp/PHP_errors.log'
);
if
(
!
empty
(
$php_errors
))
{
$crash_reports
[
'PHP Errors'
]
=
trim
(
$php_errors
);
}
$dmesg_boot
=
@
file_get_contents
(
'/var/run/dmesg.boot'
);
if
(
!
empty
(
$dmesg_boot
))
{
$crash_reports
[
'dmesg.boot'
]
=
trim
(
$dmesg_boot
);
}
foreach
(
$crash_files
as
$cf
)
{
if
(
!
is_link
(
$cf
)
&&
$cf
!=
'/var/crash/minfree'
&&
$cf
!=
'/var/crash/bounds'
&&
filesize
(
$cf
)
<
FILE_SIZE
)
{
$crash_reports
[
$cf
]
=
trim
(
file_get_contents
(
$cf
));
}
}
echo
"<br/><p><strong>"
.
gettext
(
"Unfortunately we have detected at least one programming bug."
)
.
"</strong></p>"
;
echo
"<p>"
.
gettext
(
"Would you like to submit this crash report to the developers?"
)
.
"</p>"
;
echo
"<p><button name=
\"
Submit
\"
type=
\"
submit
\"
class=
\"
btn btn-primary
\"
value=
\"
yes
\"
>"
.
gettext
(
'Yes'
)
.
"</button> "
;
echo
"<button name=
\"
Submit
\"
type=
\"
submit
\"
class=
\"
btn btn-default
\"
value=
\"
no
\"
>"
.
gettext
(
'No'
)
.
"</button></p>"
;
echo
"<hr><p>"
.
gettext
(
"You can help us further by optionally adding your contact information and a problem description."
)
.
"</p>"
;
echo
"<p><input type=
\"
text
\"
placeholder=
\"
your@email.com
\"
name=
\"
Email
\"
></p>"
;
echo
"<p><textarea rows=
\"
5
\"
placeholder=
\"
A short problem description or steps to reproduce.
\"
name=
\"
Desc
\"
></textarea></p>"
;
echo
"<hr><p>"
.
gettext
(
"Please double-check the following contents to ensure you are comfortable submitting the following information."
)
.
"</p>"
;
foreach
(
$crash_reports
as
$report
=>
$content
)
{
echo
"<p>
{
$report
}
:<br/><pre>
{
$content
}
</pre></p>"
;
if
(
$has_crashed
)
{
$crash_files
=
glob
(
"/var/crash/*"
);
$crash_reports
[
'System Information'
]
=
trim
(
$crash_report_header
);
$php_errors
=
@
file_get_contents
(
'/tmp/PHP_errors.log'
);
if
(
!
empty
(
$php_errors
))
{
$crash_reports
[
'PHP Errors'
]
=
trim
(
$php_errors
);
}
$dmesg_boot
=
@
file_get_contents
(
'/var/run/dmesg.boot'
);
if
(
!
empty
(
$dmesg_boot
))
{
$crash_reports
[
'dmesg.boot'
]
=
trim
(
$dmesg_boot
);
}
foreach
(
$crash_files
as
$cf
)
{
if
(
!
is_link
(
$cf
)
&&
$cf
!=
'/var/crash/minfree'
&&
$cf
!=
'/var/crash/bounds'
&&
filesize
(
$cf
)
<
450000
)
{
$crash_reports
[
$cf
]
=
trim
(
file_get_contents
(
$cf
));
}
}
else
{
if
(
isset
(
$_POST
[
'Submit'
])
&&
$_POST
[
'Submit'
]
==
'yes'
)
{
echo
'<br/><p><strong>'
;
echo
gettext
(
'Thank you for submitting this crash report.'
);
echo
'</strong></p><br/>'
;
}
}
?>
<body>
<?php
include
(
"fbegin.inc"
);
?>
<section
class=
"page-content-main"
>
<div
class=
"container-fluid"
>
<div
class=
"row"
>
<section
class=
"col-xs-12"
>
<div
class=
"content-box"
>
<form
action=
"/crash_reporter.php"
method=
"post"
>
<div
class=
"col-xs-12"
>
<?php
if
(
$has_crashed
)
{
echo
"<br/><p><strong>"
.
gettext
(
"Unfortunately we have detected at least one programming bug."
)
.
"</strong></p>"
;
echo
"<p>"
.
gettext
(
"Would you like to submit this crash report to the developers?"
)
.
"</p>"
;
echo
"<p><button name=
\"
Submit
\"
type=
\"
submit
\"
class=
\"
btn btn-primary
\"
value=
\"
yes
\"
>"
.
gettext
(
'Yes'
)
.
"</button> "
;
echo
"<button name=
\"
Submit
\"
type=
\"
submit
\"
class=
\"
btn btn-default
\"
value=
\"
no
\"
>"
.
gettext
(
'No'
)
.
"</button></p>"
;
echo
"<hr><p>"
.
gettext
(
"You can help us further by optionally adding your contact information and a problem description."
)
.
"</p>"
;
echo
"<p><input type=
\"
text
\"
placeholder=
\"
your@email.com
\"
name=
\"
Email
\"
></p>"
;
echo
"<p><textarea rows=
\"
5
\"
placeholder=
\"
A short problem description or steps to reproduce.
\"
name=
\"
Desc
\"
></textarea></p>"
;
echo
"<hr><p>"
.
gettext
(
"Please double-check the following contents to ensure you are comfortable submitting the following information."
)
.
"</p>"
;
foreach
(
$crash_reports
as
$report
=>
$content
)
{
echo
"<p>
{
$report
}
:<br/><pre>
{
$content
}
</pre></p>"
;
}
}
else
{
$message
=
gettext
(
'Luckily we have not detected a programming bug.'
);
if
(
isset
(
$_POST
[
'Submit'
]))
{
if
(
$_POST
[
'Submit'
]
==
'yes'
)
{
$message
=
gettext
(
'Thank you for submitting this crash report.'
);
}
elseif
(
$_POST
[
'Submit'
]
==
'no'
)
{
echo
'<br/><p><strong>'
;
echo
gettext
(
'Please consider submitting a crash report if the error persists.'
);
echo
'</strong></p><br/>'
;
}
else
{
echo
'<br/><button name="Submit" type="submit" class="btn btn-primary pull-right" value="new">'
.
gettext
(
'Report an issue'
)
.
'</button>'
;
echo
'<p><strong>'
.
gettext
(
'Luckily we have not detected a programming bug.'
)
.
'</strong></p><br/>'
;
$message
=
gettext
(
'Please consider submitting a crash report if the error persists.'
);
}
}
echo
'<br/><button name="Submit" type="submit" class="btn btn-primary pull-right" value="new">'
.
gettext
(
'Report an issue'
)
.
'</button>'
;
echo
'<p><strong>'
.
$message
.
'</strong></p><br/>'
;
}
?>
</div>
</form>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
</div>
</div>
</section>
<?php
include
(
"foot.inc"
);
?>
<?php
include
(
"foot.inc"
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment