Skip to content

Commit

Permalink
Merge pull request #2173 from sspanel-uim/dev
Browse files Browse the repository at this point in the history
Dev 20230924
  • Loading branch information
M1Screw authored Sep 23, 2023
2 parents b192603 + 1e7eda7 commit 2176183
Show file tree
Hide file tree
Showing 28 changed files with 273 additions and 299 deletions.
6 changes: 3 additions & 3 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@
// 登录日志
$group->get('/login', App\Controllers\Admin\LoginLogController::class . ':index');
$group->post('/login/ajax', App\Controllers\Admin\LoginLogController::class . ':ajax');
// 在线IP
$group->get('/online', App\Controllers\Admin\OnlineIpController::class . ':index');
$group->post('/online/ajax', App\Controllers\Admin\OnlineIpController::class . ':ajax');
// 在线IP日志
$group->get('/online', App\Controllers\Admin\OnlineLogController::class . ':index');
$group->post('/online/ajax', App\Controllers\Admin\OnlineLogController::class . ':ajax');
// 订阅日志
$group->get('/subscribe', App\Controllers\Admin\SubscribeLogController::class . ':index');
$group->post('/subscribe/ajax', App\Controllers\Admin\SubscribeLogController::class . ':ajax');
Expand Down
153 changes: 76 additions & 77 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions config/appprofile.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@
],
'route' => [
'geoip' => [
'download_url' => 'https://cdn.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip-lite.db',
'download_url' => 'https://' . $_ENV['jsdelivr_url'] . '/gh/MetaCubeX/meta-rules-dat@release/geoip-lite.db',
'download_detour' => 'direct',
],
'geosite' => [
'download_url' => 'https://cdn.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite-lite.db',
'download_url' => 'https://' . $_ENV['jsdelivr_url'] . '/gh/MetaCubeX/meta-rules-dat@release/geosite-lite.db',
'download_detour' => 'direct',
],
'rules' => [
Expand Down
24 changes: 0 additions & 24 deletions config/clients.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,6 @@
}
]
},
{
"name": "v2rayN",
"tagMethod": "github_pre_release",
"gitRepo": "2dust/v2rayN",
"savePath": "public/clients/",
"downloads": [
{
"sourceName": "v2rayN-With-Core.zip",
"saveName": "v2rayN-Core.zip"
}
]
},
{
"name": "v2rayNG",
"tagMethod": "github_pre_release",
"gitRepo": "2dust/v2rayNG",
"savePath": "public/clients/",
"downloads": [
{
"sourceName": "v2rayNG_%tagName%.apk",
"saveName": "v2rayNG.apk"
}
]
},
{
"name": "sing-box",
"tagMethod": "github_release",
Expand Down
2 changes: 1 addition & 1 deletion resources/views/tabler/admin/log/online.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
ajax: {
url: '/admin/online/ajax',
type: 'POST',
dataSrc: 'onlines'
dataSrc: 'onlines.data'
},
"autoWidth":false,
'iDisplayLength': 10,
Expand Down
14 changes: 0 additions & 14 deletions resources/views/tabler/user/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,6 @@
复制传统订阅(Trojan)
</a>
{/if}
<a {if $config['enable_r2_client_download']}
href="/user/clients/v2rayN-Core.zip"
{else}
href="/clients/v2rayN-Core.zip"
{/if} class="btn btn-azure">
下载 v2rayN(Windows)
</a>
<a {if $config['enable_r2_client_download']}
href="/user/clients/v2rayNG.apk"
{else}
href="/clients/v2rayNG.apk"
{/if} class="btn btn-azure">
下载 v2rayNG(Android)
</a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ClientDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private function getSoft(array $task): void

echo '- 正在删除旧版本文件...' . PHP_EOL;

if (! unlink($filePath)) {
if (file_exists($filePath) && ! unlink($filePath)) {
echo '- 删除旧版本文件失败,此任务跳过,请检查权限' . PHP_EOL;
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Command/Tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ public function generateUUID(): void
$users = ModelsUser::all();

foreach ($users as $user) {
$user->generateUUID();
$user->uuid = Uuid::uuid4();
$user->save();
}

echo 'generate UUID successful';
Expand Down
106 changes: 0 additions & 106 deletions src/Controllers/Admin/OnlineIpController.php

This file was deleted.

78 changes: 78 additions & 0 deletions src/Controllers/Admin/OnlineLogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace App\Controllers\Admin;

use App\Controllers\BaseController;
use App\Models\OnlineLog;
use App\Utils\Tools;
use Exception;
use MaxMind\Db\Reader\InvalidDatabaseException;
use Psr\Http\Message\ResponseInterface;
use Slim\Http\Response;
use Slim\Http\ServerRequest;
use function time;

final class OnlineLogController extends BaseController
{
private static array $details =
[
'field' => [
'id' => '事件ID',
'user_id' => '用户ID',
'user_name' => '用户名',
'node_id' => '节点ID',
'node_name' => '节点名',
'ip' => 'IP',
'location' => 'IP归属地',
'first_time' => '首次连接',
'last_time' => '最后连接',
],
];

/**
* 后台在线 IP 页面
*
* @throws Exception
*/
public function index(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
{
return $response->write(
$this->view()
->assign('details', self::$details)
->fetch('admin/log/online.tpl')
);
}

/**
* 后台在线 IP 页面 AJAX
*
* @throws InvalidDatabaseException
*/
public function ajax(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
{
$length = $request->getParam('length');
$page = $request->getParam('start') / $length + 1;
$draw = $request->getParam('draw');

$onlines = OnlineLog::where('last_time', '>', time() - 90)->orderByDesc('last_time')->paginate($length, '*', '', $page);
$total = OnlineLog::where('last_time', '>', time() - 90)->count();

foreach ($onlines as $online) {
$online->user_name = $online->userName();
$online->node_name = $online->nodeName();
$online->ip = $online->ip();
$online->location = Tools::getIpLocation($online->ip);
$online->first_time = Tools::toDateTime($online->first_time);
$online->last_time = Tools::toDateTime($online->last_time);
}

return $response->withJson([
'draw' => $draw,
'recordsTotal' => $total,
'recordsFiltered' => $total,
'onlines' => $onlines,
]);
}
}
5 changes: 3 additions & 2 deletions src/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Controllers;

use App\Models\InviteCode;
use App\Models\LoginIp;
use App\Models\Setting;
use App\Models\User;
use App\Services\Auth;
Expand Down Expand Up @@ -69,16 +70,16 @@ public function loginHandle(ServerRequest $request, Response $response, array $a
}

$antiXss = new AntiXSS();

$code = $antiXss->xss_clean($request->getParam('code'));
$passwd = $request->getParam('passwd');
$rememberMe = $request->getParam('remember_me') === 'true' ? 1 : 0;
$email = strtolower(trim($antiXss->xss_clean($request->getParam('email'))));
$redir = Cookie::get('redir') === '' ? $antiXss->xss_clean(Cookie::get('redir')) : '/user';

$user = User::where('email', $email)->first();

if ($user === null) {
(new LoginIp())->collectInvalidUserLoginIP($_SERVER['REMOTE_ADDR'], 1);

return $response->withJson([
'ret' => 0,
'msg' => '邮箱或者密码错误',
Expand Down
1 change: 1 addition & 0 deletions src/Controllers/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function handleReset(ServerRequest $request, Response $response, array $a
{
if (Setting::obtain('enable_reset_password_captcha')) {
$ret = Captcha::verify($request->getParams());

if (! $ret) {
return ResponseHelper::error($response, '系统无法接受你的验证结果,请刷新页面后重试');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/SubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function getUniversalSubContent($request, $response, $args): Respo
. '; expire=' . strtotime($user->class_expire);

if ($_ENV['subscribeLog']) {
SubscribeLog::add($user, $subtype, $request->getHeaderLine('User-Agent'));
(new SubscribeLog())->add($user, $subtype, $request->getHeaderLine('User-Agent'));
}

return $response->withHeader('Subscription-Userinfo', $sub_details)
Expand Down Expand Up @@ -127,7 +127,7 @@ public static function getTraditionalSubContent($request, $response, $args): Res

// 记录订阅日志
if ($_ENV['subscribeLog']) {
SubscribeLog::add($user, $sub_type, $request->getHeaderLine('User-Agent'));
(new SubscribeLog())->add($user, $sub_type, $request->getHeaderLine('User-Agent'));
}

$sub_details = ' upload=' . $user->u
Expand Down
2 changes: 0 additions & 2 deletions src/Controllers/User/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public function getClients(ServerRequest $request, Response $response, array $ar
'Clash.Verge_aarch64.dmg',
'Clash.Verge.AppImage.tar.gz',
'Clash-Android.apk',
'v2rayN-Core.zip',
'v2rayNG.apk',
'SFA.apk',
'SFM.zip',
];
Expand Down
2 changes: 2 additions & 0 deletions src/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function invite(ServerRequest $request, Response $response, array $args):
public function logout(ServerRequest $request, Response $response, array $args): Response
{
Auth::logout();

return $response->withStatus(302)->withHeader('Location', '/');
}

Expand All @@ -152,6 +153,7 @@ public function doCheckIn(ServerRequest $request, Response $response, array $arg

if (Setting::obtain('enable_checkin_captcha')) {
$ret = Captcha::verify($request->getParams());

if (! $ret) {
return ResponseHelper::error($response, '系统无法接受你的验证结果,请刷新页面后重试');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/WebAPI/FuncController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getDetectRules(ServerRequest $request, Response $response, array
{
$rules = DetectRule::all();

return ResponseHelper::etagJson($request, $response, [
return ResponseHelper::successWithDataEtag($request, $response, [
'ret' => 1,
'data' => $rules,
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/WebAPI/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getInfo(ServerRequest $request, Response $response, array $args)
'version' => VERSION,
];

return ResponseHelper::etagJson($request, $response, [
return ResponseHelper::successWithDataEtag($request, $response, [
'ret' => 1,
'data' => $data,
]);
Expand Down
Loading

0 comments on commit 2176183

Please sign in to comment.