diff --git a/config/df.php b/config/df.php index 646b92f0..3907567e 100644 --- a/config/df.php +++ b/config/df.php @@ -91,5 +91,6 @@ // list of allowed lookup modifying functions like urlencode, trim, etc. 'allowed_modifiers' => explode(',', env('DF_LOOKUP_MODIFIERS', 'strtoupper,strtolower,ucfirst,lcfirst,ucwords,urlencode,urldecode,rawurlencode,rawurldecode,base64_encode,base64_decode,trim')), - ] + ], + 'generate_report' => env('DF_GENERATE_REPORT', false), ]; diff --git a/routes/routes.php b/routes/routes.php index 1a212d60..70ca9a1e 100644 --- a/routes/routes.php +++ b/routes/routes.php @@ -12,6 +12,8 @@ Route::prefix(config('df.api_route_prefix', 'api')) ->middleware('df.api') ->group(function () { + Route::post('report', [\DreamFactory\Core\Http\Controllers\ReportController::class, 'generate'])->name('report:generate'); + $versionPattern = 'v[0-9.]+'; $servicePattern = '[_0-9a-zA-Z-.]+'; $resourcePathPattern = '[0-9a-zA-ZÀ-ÿ-_@&\#\!=,:;\/\^\$\.\|\{\}\[\]\(\)\*\+\?\' ]+'; @@ -29,7 +31,7 @@ ['service' => $servicePattern, 'resource' => $resourcePathPattern] ); } -); + ); /* |-------------------------------------------------------------------------- diff --git a/src/Events/GenerateReportEvent.php b/src/Events/GenerateReportEvent.php new file mode 100644 index 00000000..d250a9ac --- /dev/null +++ b/src/Events/GenerateReportEvent.php @@ -0,0 +1,12 @@ + \Config::get('app.version'), + 'bitnami_demo' => EnvUtilities::isDemoApplication(), + 'is_hosted' => to_bool(env('DF_MANAGED', false)), + 'is_trial' => to_bool(env('DF_IS_TRIAL', false)), + ]; + + // administrator-only information + $dbDriver = \Config::get('database.default'); + $result['platform']['db_driver'] = $dbDriver; + if ($dbDriver === 'sqlite') { + $result['platform']['sqlite_storage'] = \Config::get('df.db.sqlite_storage'); + } + $result['platform']['install_path'] = base_path() . DIRECTORY_SEPARATOR; + $result['platform']['log_path'] = env('DF_MANAGED_LOG_PATH', + storage_path('logs')) . DIRECTORY_SEPARATOR; + $result['platform']['app_debug'] = env('APP_DEBUG', false); + $result['platform']['log_mode'] = \Config::get('logging.log'); + $result['platform']['log_level'] = \Config::get('logging.log_level'); + $result['platform']['cache_driver'] = \Config::get('cache.default'); + + if ($result['platform']['cache_driver'] === 'file') { + $result['platform']['cache_path'] = \Config::get('cache.stores.file.path') . DIRECTORY_SEPARATOR; + } + + // including information that helps users use the API or debug + $result['server'] = php_uname(); + + /* + * Most API calls return a resource array or a single resource, + * If an array, shall we wrap it?, With what shall we wrap it? + */ + $result['config'] = [ + 'always_wrap_resources' => \Config::get('df.always_wrap_resources'), + 'resources_wrapper' => \Config::get('df.resources_wrapper'), + 'db' => [ + /** The default number of records to return at once for database queries */ + 'max_records_returned' => \Config::get('database.max_records_returned'), + 'time_format' => \Config::get('df.db.time_format'), + 'date_format' => \Config::get('df.db.date_format'), + 'datetime_format' => \Config::get('df.db.datetime_format'), + 'timestamp_format' => \Config::get('df.db.timestamp_format'), + ], + ]; + + $connectors = DB::table('service')->whereNotNull('created_by_id') + ->get(['name', 'type', 'created_date', 'last_modified_date']); + $result['connectors'] = $connectors->toArray(); +// $result['php'] = EnvUtilities::getPhpInfo(); +// // Remove environment variables being kicked back to the client +// unset($result['php']['environment']); +// unset($result['php']['php_variables']); + + + Log::channel('report')->debug('environment', $result); + } +} diff --git a/src/Handlers/Events/ServiceEventHandler.php b/src/Handlers/Events/ServiceEventHandler.php index 4bd0f96c..542fd56c 100644 --- a/src/Handlers/Events/ServiceEventHandler.php +++ b/src/Handlers/Events/ServiceEventHandler.php @@ -4,6 +4,7 @@ use DreamFactory\Core\Events\ApiEvent; use DreamFactory\Core\Events\BaseServiceEvent; +use DreamFactory\Core\Events\GenerateReportEvent; use DreamFactory\Core\Events\ServiceDeletedEvent; use DreamFactory\Core\Events\ServiceAssignedEvent; use DreamFactory\Core\Events\ServiceModifiedEvent; @@ -48,6 +49,12 @@ public function subscribe($events) static::class . '@handleQueryExecutedEvent' ); } + if (config('df.generate_report')) { + $events->listen( + [GenerateReportEvent::class], + GenerateReportHandler::class + ); + } } /** diff --git a/src/Http/Controllers/ReportController.php b/src/Http/Controllers/ReportController.php new file mode 100644 index 00000000..22405ff1 --- /dev/null +++ b/src/Http/Controllers/ReportController.php @@ -0,0 +1,25 @@ +