1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace RattfieldNz\Shodan; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use RattfieldNz\SafeUrls\SafeUrls; |
|
|
|
|
8
|
|
|
|
9
|
|
|
class ShodanServiceProvider extends ServiceProvider |
|
|
|
|
10
|
|
|
{ |
|
|
|
|
11
|
5 |
|
const CONFIG_PATH = __DIR__.'/../config/shodan.php'; |
|
|
|
|
12
|
|
|
|
13
|
5 |
|
public function boot() |
|
|
|
|
14
|
5 |
|
{ |
|
|
|
|
15
|
5 |
|
$this->publishes([ |
|
|
|
|
16
|
5 |
|
self::CONFIG_PATH => config_path('shodan.php'), |
|
|
|
|
17
|
|
|
], 'config'); |
18
|
5 |
|
} |
|
|
|
|
19
|
|
|
|
20
|
5 |
|
public function register() |
|
|
|
|
21
|
5 |
|
{ |
|
|
|
|
22
|
5 |
|
$this->mergeConfigFrom( |
|
|
|
|
23
|
|
|
self::CONFIG_PATH, |
24
|
|
|
'shodan' |
25
|
|
|
); |
26
|
|
|
|
27
|
5 |
|
$this->app->alias(Shodan::class, 'shodan'); |
|
|
|
|
28
|
5 |
|
|
29
|
|
|
$this->app->bind('shodan', function () { |
|
|
|
|
30
|
|
|
return new Shodan(); |
31
|
|
|
}); |
|
|
|
|
32
|
|
|
} |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
|
|
|
|
35
|
|
|
* Get the services provided by the provider. |
36
|
|
|
* |
37
|
|
|
* @return array |
|
|
|
|
38
|
|
|
*/ |
39
|
|
|
public function provides() |
|
|
|
|
40
|
|
|
{ |
|
|
|
|
41
|
|
|
return ['shodan']; |
|
|
|
|
42
|
|
|
} |
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
|
|
|
|
45
|
|
|
* Console-specific booting. |
46
|
|
|
* |
47
|
|
|
* @return void |
|
|
|
|
48
|
|
|
*/ |
49
|
|
|
public function bootForConsole() |
|
|
|
|
50
|
|
|
{ |
|
|
|
|
51
|
|
|
// Publishing the configuration file. |
|
|
|
|
52
|
|
|
$this->publishes([ |
|
|
|
|
53
|
|
|
__DIR__.'/../config/shodan.php' => config_path('shodan.php'), |
|
|
|
|
54
|
|
|
], 'shodan'); |
55
|
|
|
|
56
|
|
|
// Registering package commands. |
|
|
|
|
57
|
|
|
$this->commands(['shodan']); |
|
|
|
|
58
|
|
|
} |
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
|
|
|
|
61
|
|
|
* Merge the given configuration with the existing configuration. |
62
|
|
|
* |
63
|
|
|
* @param string $path |
|
|
|
|
64
|
|
|
* @param string $key |
|
|
|
|
65
|
|
|
* |
66
|
|
|
* @return void |
|
|
|
|
67
|
|
|
*/ |
68
|
|
|
protected function mergeConfigFrom($path, $key) |
|
|
|
|
69
|
|
|
{ |
|
|
|
|
70
|
|
|
$config = $this->app['config']->get($key, []); |
|
|
|
|
71
|
|
|
$this->app['config']->set($key, $this->mergeConfig($config, require $path)); |
|
|
|
|
72
|
|
|
} |
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
|
|
|
|
75
|
|
|
* Merges the configs together and takes multi-dimensional arrays into account. |
|
|
|
|
76
|
|
|
* |
77
|
|
|
* @param array $original |
|
|
|
|
78
|
|
|
* @param array $merging |
|
|
|
|
79
|
|
|
* |
80
|
|
|
* @return array |
|
|
|
|
81
|
|
|
*/ |
82
|
|
|
protected function mergeConfig(array $original, array $merging) |
|
|
|
|
83
|
|
|
{ |
|
|
|
|
84
|
|
|
$array = array_merge($original, $merging); |
|
|
|
|
85
|
|
|
foreach ($original as $key => $value) { |
|
|
|
|
86
|
|
|
if (!is_array($value)) { |
|
|
|
|
87
|
|
|
continue; |
|
|
|
|
88
|
|
|
} |
|
|
|
|
89
|
|
|
if (!Arr::exists($merging, $key)) { |
|
|
|
|
90
|
|
|
continue; |
|
|
|
|
91
|
|
|
} |
|
|
|
|
92
|
|
|
if (is_numeric($key)) { |
|
|
|
|
93
|
|
|
continue; |
|
|
|
|
94
|
|
|
} |
|
|
|
|
95
|
|
|
$array[$key] = $this->mergeConfig($value, $merging[$key]); |
|
|
|
|
96
|
|
|
} |
|
|
|
|
97
|
|
|
|
98
|
|
|
return $array; |
|
|
|
|
99
|
|
|
} |
|
|
|
|
100
|
|
|
} |
|
|
|
|
101
|
|
|
|