Permalink
Browse files

add debug page

  • Loading branch information...
laurencei committed Feb 22, 2018
1 parent 0ca123f commit 953df48483ecffd8bcb8c8d85c6295412191b70d
@@ -0,0 +1,56 @@
<?php
namespace Eyewitness\Eye\Http\Controllers;
use Eyewitness\Eye\Eye;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Config;
class DebugController extends Controller
{
/**
* A method to help debug Eyewitness issues remotely.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
if (! config('eyewitness.debug')) {
return redirect(route('eyewitness.dashboard').'#overview')->withError('Sorry, but you need to enable eyewitness.debug mode to be able to view the debug page');
}
// Get all application config
$config = Config::all();
// Strip known sensitive config
$config['services'] = null;
$config['mail'] = null;
$config['filesystems']['disks'] = null;
// Now try to strip anything that might be senstive
$this->recursive_unset($config, 'key');
$this->recursive_unset($config, 'secret');
$this->recursive_unset($config, 'password');
return view('eyewitness::debug.index')->withEye(app(Eye::class))->withConfig($config);
}
/**
* A method to recursively remove a given key from the array.
* https://stackoverflow.com/a/1708914/1317935
*
* @param array &$array
* @param string $unwanted_key
* @return array
*/
protected function recursive_unset(&$array, $unwanted_key)
{
unset($array[$unwanted_key]);
foreach ($array as &$value) {
if (is_array($value)) {
$this->recursive_unset($value, $unwanted_key);
}
}
}
}
@@ -0,0 +1,16 @@
<h3>Hi there,</h3>
<p>This is a support page, where the below is all the configuration options for your application. We have attempted to automatically remove known senstive data from the config. This includes any "key", "password" or "secret" config item, as well as all "services".</p>
<p><strong>We highly recommend you check the config below for any other possible secret values before emailing us a copy.</strong></p>
<p>If there are more secrets, please remove them prior to emailing. Once you are happy - please "copy and paste" all the data below, and email it to <strong>support@eyewitness.io</strong> - and we'll look into the issue further.</p>
<hr/>
<pre>
{{ var_dump($eye->application()->settings()) }}
</pre>
<pre>
{{ var_dump($config) }}
</pre>
@@ -44,4 +44,6 @@
Route::delete('failedjob/{queue_id}/{job_id}', ['as' => 'eyewitness.failedjob.destroy', 'uses' => 'FailedJobController@destroy']);
Route::post('failedjob/{queue_id}', ['as' => 'eyewitness.failedjob.retry-all', 'uses' => 'FailedJobController@retryAll']);
Route::delete('failedjob/{queue_id}', ['as' => 'eyewitness.failedjob.destroy-all', 'uses' => 'FailedJobController@destroyAll']);
Route::get('debug', ['as' => 'eyewitness.debug.index', 'uses' => 'DebugController@index']);
});
@@ -0,0 +1,42 @@
<?php
namespace Eyewitness\Eye\Test\Controllers;
use Eyewitness\Eye\Test\TestCase;
class DebugControllerTest extends TestCase
{
public function setUp()
{
parent::setUp();
$this->artisan('migrate', ['--database' => 'testbench']);
}
public function test_debug_mode_must_be_enabled_to_view_page()
{
config(['eyewitness.debug' => false]);
$response = $this->withSession(['eyewitness:auth' => 1])
->get($this->home.'/debug');
$response->assertRedirect($this->home.'/dashboard#overview');
$response->assertSessionHas('error', 'Sorry, but you need to enable eyewitness.debug mode to be able to view the debug page');
}
public function test_removes_senstive_data()
{
config(['eyewitness.debug' => true]);
config(['app.secret' => 'example789']);
config(['app.password' => 'password789']);
config(['app.other' => 'other789']);
$response = $this->withSession(['eyewitness:auth' => 1])
->get($this->home.'/debug');
$response->assertStatus(200);
$response->assertSee('other789');
$response->assertDontSee('example789');
$response->assertDontSee('password789');
}
}

0 comments on commit 953df48

Please sign in to comment.