diff --git a/app/Http/Controllers/Admin/AdminUserController.php b/app/Http/Controllers/Admin/AdminUserController.php index 3aa7bd840..b5dcb5e86 100644 --- a/app/Http/Controllers/Admin/AdminUserController.php +++ b/app/Http/Controllers/Admin/AdminUserController.php @@ -10,6 +10,7 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Jrean\UserVerification\Facades\UserVerification; use Spatie\Permission\Models\Role; +use Stevebauman\Location\Facades\Location; class AdminUserController extends BasePageController { @@ -53,6 +54,16 @@ class AdminUserController extends BasePageController $results = $this->paginate($result ?? [], User::getCount($variables['role'], $variables['username'], $variables['host'], $variables['email']) ?? 0, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); + // Add country data to each user based on their host IP + foreach ($results as $user) { + $position = null; + if (!empty($user->host) && filter_var($user->host, FILTER_VALIDATE_IP)) { + $position = Location::get($user->host); + } + $user->country_name = $position ? $position->countryName : null; + $user->country_code = $position ? $position->countryCode : null; + } + $this->smarty->assign( [ 'username' => $variables['username'], diff --git a/composer.json b/composer.json index ebda53420..b436f2599 100644 --- a/composer.json +++ b/composer.json @@ -104,6 +104,7 @@ "spatie/laravel-permission": "^6.16", "sspat/es-query-sanitizer": "^1.0", "stechstudio/laravel-zipstream": "^5.4", + "stevebauman/location": "^7.5", "symfony/http-client": "^7.0", "symfony/postmark-mailer": "^7.0", "symfony/process": "^7.0", diff --git a/composer.lock b/composer.lock index d73ff7e94..53af131ef 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "03f39cab20bcd22f2daaa24ab30d2b51", + "content-hash": "2b382facdfd79c66e30785ffd5f8fc49", "packages": [ { "name": "aharen/omdbapi", @@ -10433,6 +10433,75 @@ }, "time": "2025-05-14T19:04:31+00:00" }, + { + "name": "stevebauman/location", + "version": "v7.5.0", + "source": { + "type": "git", + "url": "https://github.com/stevebauman/location.git", + "reference": "4091806f36da22f903e3013b42629b3b9f0ef014" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stevebauman/location/zipball/4091806f36da22f903e3013b42629b3b9f0ef014", + "reference": "4091806f36da22f903e3013b42629b3b9f0ef014", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "geoip2/geoip2": "^2.0|^3.0", + "guzzlehttp/guzzle": "^7.0", + "illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0", + "php": ">=8.1" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0|^10.0", + "pestphp/pest": "^1.0|^2.0|^3.7" + }, + "type": "library", + "extra": { + "laravel": { + "aliases": { + "Location": "Stevebauman\\Location\\Facades\\Location" + }, + "providers": [ + "Stevebauman\\Location\\LocationServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Stevebauman\\Location\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Steve Bauman", + "email": "steven_bauman@outlook.com" + } + ], + "description": "Retrieve a user's location by their IP Address", + "keywords": [ + "IP", + "geo", + "geo-location", + "geoip", + "laravel", + "location", + "php" + ], + "support": { + "issues": "https://github.com/stevebauman/location/issues", + "source": "https://github.com/stevebauman/location/tree/v7.5.0" + }, + "time": "2025-02-19T04:59:26+00:00" + }, { "name": "symfony/cache", "version": "v7.2.6", diff --git a/resources/views/themes/admin/user-list.tpl b/resources/views/themes/admin/user-list.tpl index 69a163c4b..c02b91381 100644 --- a/resources/views/themes/admin/user-list.tpl +++ b/resources/views/themes/admin/user-list.tpl @@ -144,6 +144,12 @@ {$user->host} + {if $user->country_code} + + {$user->country_name} + {$user->country_name} + + {/if}