popHandler(); // remove existing errorlog logger Log::useFiles(config('app.log') ?: Config::get('log_file', base_path('logs/librenms.log')), 'error'); // Blade directives (Yucky because of < L5.5) Blade::directive('config', function ($key) { return ""; }); Blade::directive('notconfig', function ($key) { return ""; }); Blade::directive('endconfig', function () { return ""; }); Blade::directive('admin', function () { return "check() && auth()->user()->isAdmin()): ?>"; }); Blade::directive('endadmin', function () { return ""; }); $this->bootCustomValidators(); $this->configureMorphAliases(); // Development service providers if ($this->app->environment() !== 'production') { if (class_exists(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class)) { $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } if (config('app.debug') && class_exists(\Barryvdh\Debugbar\ServiceProvider::class)) { // disable debugbar for api routes if (!Request::is('api/*')) { $this->app->register(\Barryvdh\Debugbar\ServiceProvider::class); } } } } /** * Register any application services. * * @return void */ public function register() { $this->registerGeocoder(); } private function configureMorphAliases() { Relation::morphMap([ 'interface' => \App\Models\Port::class, 'sensor' => \App\Models\Sensor::class, 'device' => \App\Models\Device::class, 'device_group' => \App\Models\DeviceGroup::class, ]); } private function registerGeocoder() { $this->app->alias(\LibreNMS\Interfaces\Geocoder::class, 'geocoder'); $this->app->bind(\LibreNMS\Interfaces\Geocoder::class, function ($app) { $engine = Config::get('geoloc.engine'); switch ($engine) { case 'mapquest': Log::debug('MapQuest geocode engine'); return $app->make(\App\ApiClients\MapquestApi::class); case 'bing': Log::debug('Bing geocode engine'); return $app->make(\App\ApiClients\BingApi::class); case 'openstreetmap': Log::debug('OpenStreetMap geocode engine'); return $app->make(\App\ApiClients\NominatimApi::class); default: case 'google': Log::debug('Google Maps geocode engine'); return $app->make(\App\ApiClients\GoogleMapsApi::class); } }); } private function bootCustomValidators() { Validator::extend('ip_or_hostname', function ($attribute, $value, $parameters, $validator) { $ip = substr($value, 0, strpos($value, '/') ?: strlen($value)); // allow prefixes too return IP::isValid($ip) || Validate::hostname($value); }, __('The :attribute must a valid IP address/network or hostname.')); } }