mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
nastools approve
This commit is contained in:
@@ -80,3 +80,4 @@ SFTP_ROOT=/tmp
|
||||
UID_STARTS=10001
|
||||
|
||||
PHP_PATH=
|
||||
NAS_TOOLS_KEY=
|
||||
|
||||
@@ -95,8 +95,7 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$r = unserialize('{"command":"O:31:\"App\\Jobs\\CalculateUserSeedBonus\":3:{s:41:\"\u0000App\\Jobs\\CalculateUserSeedBonus\u0000beginUid\";i:32000;s:39:\"\u0000App\\Jobs\\CalculateUserSeedBonus\u0000endUid\";i:34000;s:42:\"\u0000App\\Jobs\\CalculateUserSeedBonus\u0000requestId\";s:32:\"2f6563f399f26f57b02882463199a49d\";}');
|
||||
dd($r);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -131,6 +131,15 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
->integer()
|
||||
->label(__('label.setting.system.maximum_number_of_medals_can_be_worn'))
|
||||
,
|
||||
Forms\Components\TextInput::make('system.cookie_valid_days')
|
||||
->integer()
|
||||
->label(__('label.setting.system.cookie_valid_days'))
|
||||
,
|
||||
Forms\Components\TextInput::make('system.maximum_upload_speed')
|
||||
->integer()
|
||||
->label(__('label.setting.system.maximum_upload_speed'))
|
||||
->helperText(__('label.setting.system.maximum_upload_speed_help'))
|
||||
,
|
||||
])->columns(2);
|
||||
|
||||
$tabs = apply_filter('nexus_setting_tabs', $tabs);
|
||||
|
||||
@@ -58,7 +58,7 @@ class AuthenticateController extends Controller
|
||||
// $passhash = md5($user->passhash . $ip);
|
||||
$passhash = md5($user->passhash);
|
||||
do_log(sprintf('passhash: %s, ip: %s, md5: %s', $user->passhash, $ip, $passhash));
|
||||
logincookie($user->id, $passhash,false, 0x7fffffff, true, true, true);
|
||||
logincookie($user->id, $passhash,false, get_setting('system.cookie_valid_days', 365) * 86400, true, true, true);
|
||||
$user->last_login = now();
|
||||
$user->save();
|
||||
}
|
||||
@@ -66,5 +66,15 @@ class AuthenticateController extends Controller
|
||||
return redirect('index.php');
|
||||
}
|
||||
|
||||
public function nasToolsApprove(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'data' => 'required|string'
|
||||
]);
|
||||
$user = $this->repository->nasToolsApprove($request->data);
|
||||
$resource = new UserResource($user);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class Kernel extends HttpKernel
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequestsWithRedis::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'permission' => \App\Http\Middleware\Permission::class,
|
||||
'admin' => \App\Http\Middleware\Admin::class,
|
||||
|
||||
@@ -16,7 +16,6 @@ class UserResource extends JsonResource
|
||||
{
|
||||
$out = [
|
||||
'id' => $this->id,
|
||||
'email' => $this->email,
|
||||
'username' => $this->username,
|
||||
'status' => $this->status,
|
||||
'enabled' => $this->enabled,
|
||||
@@ -32,7 +31,7 @@ class UserResource extends JsonResource
|
||||
'downloaded' => $this->downloaded,
|
||||
'downloaded_text' => mksize($this->downloaded),
|
||||
'bonus' => number_format($this->seedbonus, 1),
|
||||
'seed_points' => floatval($this->seed_points),
|
||||
'seed_points' => number_format($this->seed_points, 1),
|
||||
'seedtime' => $this->seedtime,
|
||||
'seedtime_text' => mkprettytime($this->seedtime),
|
||||
'leechtime' => $this->leechtime,
|
||||
@@ -41,6 +40,7 @@ class UserResource extends JsonResource
|
||||
'valid_medals' => MedalResource::collection($this->whenLoaded('valid_medals')),
|
||||
];
|
||||
if ($request->routeIs('user.me')) {
|
||||
$out['email'] = $this->email;
|
||||
$out['downloaded_human'] = mksize($this->downloaded);
|
||||
$out['uploaded_human'] = mksize($this->uploaded);
|
||||
$out['seed_time'] = mkprettytime($this->seedtime);
|
||||
|
||||
@@ -50,6 +50,11 @@ class RouteServiceProvider extends ServiceProvider
|
||||
Route::prefix('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/tracker.php'));
|
||||
|
||||
Route::prefix('api')
|
||||
->namespace($this->namespace)
|
||||
->middleware('throttle:third-party')
|
||||
->group(base_path('routes/third-party.php'));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,5 +68,9 @@ class RouteServiceProvider extends ServiceProvider
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
|
||||
});
|
||||
|
||||
RateLimiter::for('third-party', function (Request $request) {
|
||||
return Limit::perMinute(10)->by(getip());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Repositories;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\UnauthorizedException;
|
||||
|
||||
@@ -38,4 +39,25 @@ class AuthenticateRepository extends BaseRepository
|
||||
$result = $user->tokens()->delete();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function nasToolsApprove(string $json)
|
||||
{
|
||||
$key = env('NAS_TOOLS_KEY');
|
||||
$encrypter = new Encrypter($key);
|
||||
$decrypted = $encrypter->decryptString($json);
|
||||
$data = json_decode($decrypted, true);
|
||||
if (!is_array($data) || !isset($data['uid'], $data['passkey'])) {
|
||||
throw new \InvalidArgumentException("Invalid data format.");
|
||||
}
|
||||
$user = User::query()
|
||||
->where('id', $data['uid'])
|
||||
->where('passkey', $data['passkey'])
|
||||
->first()
|
||||
;
|
||||
if (!$user) {
|
||||
throw new \InvalidArgumentException("Invalid uid or passkey.");
|
||||
}
|
||||
$user->checkIsNormal();
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,8 +69,10 @@ function check_cheater($userid, $torrentid, $uploaded, $downloaded, $anctime, $s
|
||||
|
||||
$time = date("Y-m-d H:i:s");
|
||||
$upspeed = ($uploaded > 0 ? $uploaded / $anctime : 0);
|
||||
$mustBeCheaterSpeed = 1024 * 1024 * 1000; //1000 MB/s
|
||||
$mayBeCheaterSpeed = 1024 * 1024 * 100; //100 MB/s
|
||||
// $mustBeCheaterSpeed = 1024 * 1024 * 1000; //1000 MB/s
|
||||
$mustBeCheaterSpeed = get_setting('system.maximum_upload_speed', 8000) * 1024 * 1024 / 8;
|
||||
// $mayBeCheaterSpeed = 1024 * 1024 * 100; //100 MB/s
|
||||
$mayBeCheaterSpeed = $mustBeCheaterSpeed / 2;
|
||||
|
||||
if ($uploaded > 1073741824 && $upspeed > ($mustBeCheaterSpeed/$cheaterdet_security)) //Uploaded more than 1 GB with uploading rate higher than 100 MByte/S (For Consertive level). This is no doubt cheating.
|
||||
{
|
||||
|
||||
@@ -441,5 +441,7 @@ return array (
|
||||
'change_username_min_interval_in_days' => '365',
|
||||
'change_username_card_allow_characters_outside_the_alphabets' => 'no',
|
||||
'maximum_number_of_medals_can_be_worn' => 3,
|
||||
'cookie_valid_days' => 365,
|
||||
'maximum_upload_speed' => 8000,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -29,7 +29,7 @@ sql_query("UPDATE users SET status='confirmed', editsecret='' WHERE id=".sqlesc(
|
||||
if (!mysql_affected_rows())
|
||||
httperr();
|
||||
|
||||
|
||||
|
||||
if ($securelogin == "yes")
|
||||
{
|
||||
$securelogin_indentity_cookie = true;
|
||||
@@ -40,7 +40,7 @@ else // when it's op, default is not use secure login
|
||||
$securelogin_indentity_cookie = false;
|
||||
$passh = md5($row["passhash"]);
|
||||
}
|
||||
logincookie($id, $passh,1,0x7fffffff,$securelogin_indentity_cookie);
|
||||
logincookie($id, $passh,1,get_setting('system.cookie_valid_days', 365) * 86400,$securelogin_indentity_cookie);
|
||||
//sessioncookie($row["id"], $passh,false);
|
||||
|
||||
header("Refresh: 0; url=ok.php?type=confirm");
|
||||
|
||||
@@ -104,7 +104,7 @@ if (isset($_POST["logout"]) && $_POST["logout"] == "yes")
|
||||
}
|
||||
else
|
||||
{
|
||||
logincookie($row["id"], $passh,1,0x7fffffff,$securelogin_indentity_cookie, $ssl, $trackerssl);
|
||||
logincookie($row["id"], $passh,1,get_setting('system.cookie_valid_days', 365) * 86400,$securelogin_indentity_cookie, $ssl, $trackerssl);
|
||||
//sessioncookie($row["id"], $passh,false);
|
||||
}
|
||||
|
||||
|
||||
@@ -786,7 +786,7 @@ tr_small($lang_usercp['row_funbox'],"<input type=checkbox name=showfb".($CURUSER
|
||||
else
|
||||
$ssl = false;
|
||||
|
||||
logincookie($CURUSER["id"], $passh ,1,0x7fffffff,$securelogin_indentity_cookie,$ssl);
|
||||
logincookie($CURUSER["id"], $passh ,1,get_setting('system.cookie_valid_days', 365) * 86400,$securelogin_indentity_cookie,$ssl);
|
||||
//sessioncookie($CURUSER["id"], $passh);
|
||||
$passupdated = 1;
|
||||
}
|
||||
|
||||
@@ -89,6 +89,9 @@ return [
|
||||
'change_username_card_allow_characters_outside_the_alphabets' => 'Does the name change card allow characters other than English letters',
|
||||
'change_username_min_interval_in_days' => 'The minimum interval days of Change user name',
|
||||
'maximum_number_of_medals_can_be_worn' => 'Maximum number of medals that can be worn',
|
||||
'cookie_valid_days' => 'Cookie Valid days',
|
||||
'maximum_upload_speed' => 'Maximum upload speed',
|
||||
'maximum_upload_speed_help' => 'A single torrent upload speed exceeding this value is instantly disabled for the account, in Mbps. For example: 100 Mbps = 12.5 MB/s',
|
||||
],
|
||||
],
|
||||
'user' => [
|
||||
|
||||
@@ -89,6 +89,9 @@ return [
|
||||
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允许英文字母外的字符',
|
||||
'change_username_min_interval_in_days' => '修改用户名最小间隔天数',
|
||||
'maximum_number_of_medals_can_be_worn' => '勋章最大可佩戴数',
|
||||
'cookie_valid_days' => 'Cookie 有效天数',
|
||||
'maximum_upload_speed' => '最大上传速度',
|
||||
'maximum_upload_speed_help' => '单种上传速度超过此值账号即刻禁用,单位 Mbps。如:100 Mbps = 12.5 MB/s',
|
||||
],
|
||||
],
|
||||
'user' => [
|
||||
|
||||
@@ -89,6 +89,8 @@ return [
|
||||
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允許英文字母外的字符',
|
||||
'change_username_min_interval_in_days' => '修改用戶名最小間隔天數',
|
||||
'maximum_number_of_medals_can_be_worn' => '勛章最大可佩戴數',
|
||||
'cookie_valid_days' => 'Cookie 有效天數',
|
||||
'maximum_upload_speed_help' => '單種上傳速度超過此值賬號即刻禁用,單位 Mbps。如:100 Mbps = 12.5 MB/s',
|
||||
],
|
||||
],
|
||||
'user' => [
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
<?php
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::post('nastools/approve', [\App\Http\Controllers\AuthenticateController::class, 'nasToolsApprove']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user