Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions resources/lang/en/exment.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
'outside_api' => 'Perform server external communication',
'permission_available' => 'Use Role Management',
'organization_available' => 'Use Organization Management',
'logging_toggle_available' => 'Enable Operation Log',
'system_admin_users' => 'System Administrator',
'system_mail' => 'System Mail Settings',
'system_mail_host' => 'Host Name',
Expand Down Expand Up @@ -447,6 +448,7 @@
'datalist_pager_count' => 'It is the default number of display of data that is displayed in keyword search and data list of dashboard. It is reflected in the whole system.',
'permission_available' => 'If Select YES, management role using user or organozation.',
'organization_available' => 'If Select YES, create organizations to which the user belongs.',
'logging_toggle_available' => 'If set to YES, the operation log feature will be enabled and all user actions will be recorded.',
'system_admin_users' => 'Set the user who will be the system administrator.',
'system_mail' => 'Configure settings when sending mail from the system.',
'system_mail_from' => 'the mail address from this system. Using this mail address as "from", this system sends users.',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/ja/exment.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
'outside_api' => 'サーバー外部通信を行う',
'permission_available' => '権限管理を使用する',
'organization_available' => '組織管理を使用する',
'logging_toggle_available' => '操作ログを有効にする',
'system_admin_users' => 'システム管理者',
'system_mail' => 'システムメール設定',
'system_mail_host' => 'ホスト名',
Expand Down Expand Up @@ -447,6 +448,7 @@
'datalist_pager_count' => 'キーワード検索や、ダッシュボードのデータ一覧で表示されるデータの、既定の表示件数です。システム全体に反映されます。',
'permission_available' => 'YESにした場合、ユーザーや役割によって、アクセスできる項目を管理します。',
'organization_available' => 'YESにした場合、ユーザーが所属する組織や部署を作成します。',
'logging_toggle_available' => 'YESに設定すると、操作ログ機能が有効になり、すべてのユーザーの操作が記録されます。',
'system_admin_users' => 'システム管理者となるユーザーを設定してください。',
'system_mail' => 'システムからメールを送付する時の設定を行います。',
'system_mail_from' => '送信元のメールアドレスです。このメールアドレスをFromとして、メールが送付されます。',
Expand Down
8 changes: 8 additions & 0 deletions src/Console/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Exceedone\Exment\Console;

use Exceedone\Exment\Enums\SystemTableName;
use Exceedone\Exment\Model\CustomTable;
use Illuminate\Console\Command;
use Exceedone\Exment\Services\TemplateImportExport\TemplateImporter;

Expand Down Expand Up @@ -78,5 +80,11 @@ public function initDatabase()
// Remove template import if update
// $importer = new TemplateImporter;
// $importer->importSystemTemplate(true);
$customTable = CustomTable::where('table_name', SystemTableName::SYSTEM_LOGS)->first();
if (!$customTable) {
$importer = new TemplateImporter();
$importer->importSystemLogsTemplate();
}

}
}
1 change: 1 addition & 0 deletions src/Enums/SystemTableName.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class SystemTableName extends EnumBase
{
public const SYSTEM = 'systems';
public const SYSTEM_LOGS = 'system_logs';
public const LOGIN_USER = 'login_users';
public const PLUGIN = 'plugins';
public const USER = 'user';
Expand Down
5 changes: 5 additions & 0 deletions src/ExmentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class ExmentServiceProvider extends ServiceProvider
*/
protected $middleware = [
\Exceedone\Exment\Middleware\TrustProxies::class,
// \Exceedone\Exment\Middleware\LogRouteExecutionTime::class,
\Exceedone\Exment\Middleware\ExmentDebug::class,
];

Expand All @@ -114,6 +115,8 @@ class ExmentServiceProvider extends ServiceProvider
*/
protected $routeMiddleware = [
'admin.auth' => \Exceedone\Exment\Middleware\Authenticate::class,
'log.exec.time' => \Exceedone\Exment\Middleware\LogRouteExecutionTime::class,
'check.logging.enabled' => \Exceedone\Exment\Middleware\CheckLoggingEnabled::class,
'admin.auth-2factor' => \Exceedone\Exment\Middleware\Authenticate2factor::class,
'admin.password-limit' => \Exceedone\Exment\Middleware\AuthenticatePasswordLimit::class,
'admin.bootstrap2' => \Exceedone\Exment\Middleware\Bootstrap::class,
Expand Down Expand Up @@ -154,6 +157,8 @@ class ExmentServiceProvider extends ServiceProvider
'admin.web-ipfilter',
'admin.initialize',
'admin.auth',
'log.exec.time',
'check.logging.enabled',
'admin.auth-2factor',
'admin.password-limit',
'admin.morph',
Expand Down
49 changes: 49 additions & 0 deletions src/Middleware/CheckLoggingEnabled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Exceedone\Exment\Middleware;

use Exceedone\Exment\Model\CustomTable;
use Carbon\Carbon;
use Exceedone\Exment\Model\System;



use Closure;
use Exceedone\Exment\Services\QueryLogger;

class CheckLoggingEnabled
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
if (System::logging_toggle_available()) {
$table = CustomTable::getEloquent('system_logs');

if ($table) {
$user = \Exment::user()->base_user;
$email = $user->getValue('email');
$url = $request->fullUrl();
$date_time = Carbon::now()->toDateTimeString();
$system_logs = $table->getValueModel();
$system_logs->parent_id = null;
$system_logs->parent_type = null;
$system_logs->setValue('email', $email);
$system_logs->setValue('create_at', $date_time);
$system_logs->setValue('url', $url);
$allSql = implode("\n", QueryLogger::all());
$system_logs->setValue('sql', $allSql);
$system_logs->save();
QueryLogger::clear();
}
}

return $response;
}
}
9 changes: 7 additions & 2 deletions src/Middleware/ExmentDebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Http\Request;
use Exceedone\Exment\Enums\EnumBase;
use Illuminate\Console\Scheduling\Schedule;
use Exceedone\Exment\Model\CustomTable;
use Exceedone\Exment\Model\System;
use Exceedone\Exment\Services\QueryLogger;

class ExmentDebug
{
Expand All @@ -18,7 +21,7 @@ public function handle(Request $request, \Closure $next)

public static function handleLog(?Request $request = null)
{
if (boolval(config('exment.debugmode', false)) || boolval(config('exment.debugmode_sql', false))) {
if (boolval(config('exment.debugmode', false)) || boolval(config('exment.debugmode_sql', false)) || System::logging_toggle_available()) {
static::logDatabase();
}

Expand All @@ -27,6 +30,7 @@ public static function handleLog(?Request $request = null)
}
}

protected static $queryLogs = [];

/**
* Output log database
Expand All @@ -46,7 +50,8 @@ protected static function logDatabase()
$sql = preg_replace("/\?/", "'{$binding}'", $sql, 1);
}

$log_string = "TIME:{$query->time}ms; SQL: $sql";
$log_string = "TIME:{$query->time}ms SQL: $sql";
QueryLogger::add($log_string);
if (boolval(config('exment.debugmode_sqlfunction', false))) {
$function = static::getFunctionName();
$log_string .= "; function: $function";
Expand Down
49 changes: 49 additions & 0 deletions src/Middleware/LogRouteExecutionTime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Exceedone\Exment\Middleware;

use Exceedone\Exment\Model\CustomTable;
use Carbon\Carbon;


use Closure;
use Exceedone\Exment\Services\QueryLogger;
use Illuminate\Http\Request;

class LogRouteExecutionTime
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$log_enabled = boolval(config('exment.debugmode', false)) || boolval(config('exment.debugmode_sql', false));
if ($log_enabled) {
\Log::info("画面名: " . $request->fullUrl());
$start = microtime(true);
}
$response = $next($request);
if ($log_enabled) {
$user = \Exment::user()->base_user;
$email = $user->getValue('email');
$url = $request->fullUrl();
$date_time = Carbon::now()->toDateTimeString();
$execution_logs = CustomTable::getEloquent('execution_logs')->getValueModel();
$execution_logs->parent_id = null;
$execution_logs->parent_type = null;
$execution_logs->setValue('email', $email);
$execution_logs->setValue('create_at', $date_time);
$execution_logs->setValue('url', $url);
$allSql = implode("\n", QueryLogger::all());
$execution_logs->setValue('sql', $allSql);
$execution_logs->save();
QueryLogger::clear();
}

return $response;
}
}
1 change: 1 addition & 0 deletions src/Model/Define.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Define
'outside_api' => ['type' => 'boolean', 'group' => 'initialize', 'default' => true],
'permission_available' => ['type' => 'boolean', 'default' => '1', 'group' => 'initialize'],
'organization_available' => ['type' => 'boolean', 'default' => '1', 'group' => 'initialize'],
'logging_toggle_available' => ['type' => 'boolean', 'default' => '0', 'group' => 'initialize'],

// Advanced ----------------------------------
'filter_search_type' => ['default' => 'forward', 'group' => 'advanced'],
Expand Down
1 change: 1 addition & 0 deletions src/Model/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @method static boolean|void outside_api($arg = null)
* @method static boolean|void permission_available($arg = null)
* @method static boolean|void organization_available($arg = null)
* @method static boolean|void logging_toggle_available($arg = null)
* @method static string|void filter_search_type($arg = null)
* @method static string|void system_mail_host($arg = null)
* @method static string|void system_mail_port($arg = null)
Expand Down
3 changes: 3 additions & 0 deletions src/Services/Installer/InitializeFormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ protected function getInitializeForm($routeName, $isInitialize = false): WidgetF
$form->switchbool('organization_available', exmtrans("system.organization_available"))
->help(exmtrans("system.help.organization_available"));

$form->switchbool('logging_toggle_available', exmtrans("system.logging_toggle_available"))
->help(exmtrans("system.help.logging_toggle_available"));

// template list
if ($isInitialize) {
$this->addTemplateTile($form);
Expand Down
24 changes: 24 additions & 0 deletions src/Services/QueryLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Exceedone\Exment\Services;

class QueryLogger
{
protected static $queries = [];

public static function add($query)
{
$index = count(self::$queries) + 1;
self::$queries[] = "{$index}. {$query}";
}

public static function all()
{
return static::$queries;
}

public static function clear()
{
static::$queries = [];
}
}
18 changes: 18 additions & 0 deletions src/Services/TemplateImportExport/TemplateImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ public function importSystemTemplate($is_update = false)
]);
}

public function importSystemLogsTemplate($is_update = false)
{
// get vendor folder
$templates_base_path = exment_package_path('templates/system_logs');
$path = "$templates_base_path/config.json";

// If file not exists
if (!File::exists($path)) {
// TODO:Error
}

$this->importFromFile(File::get($path), [
'system_flg' => true,
'is_update' => $is_update,
'basePath' => $templates_base_path,
]);
}

/**
* Upload template and import (from display)
*/
Expand Down
Loading
Loading