From db4982f8f7cb23025b68ca747b95a13d2bbd632e Mon Sep 17 00:00:00 2001 From: xiaomlove <1939737565@qq.com> Date: Sun, 29 Mar 2026 21:42:43 +0700 Subject: [PATCH] self enable --- app/Models/BonusLogs.php | 3 ++ app/Models/Setting.php | 5 +++ app/Models/UserBanLog.php | 2 + app/Repositories/UserRepository.php | 6 +-- include/functions.php | 11 +++-- include/globalfunctions.php | 15 ++++++- lang/chs/lang_settings.php | 2 + lang/cht/lang_settings.php | 2 + lang/en/lang_settings.php | 2 + nexus/Nexus.php | 18 ++++++++ public/self-enable.php | 62 ++++++++++++++++++++++++++++ public/settings.php | 3 +- public/takelogin.php | 4 +- resources/lang/en/bonus-log.php | 1 + resources/lang/en/self-enable.php | 13 ++++++ resources/lang/zh_CN/bonus-log.php | 1 + resources/lang/zh_CN/self-enable.php | 13 ++++++ resources/lang/zh_TW/bonus-log.php | 1 + resources/lang/zh_TW/self-enable.php | 13 ++++++ 19 files changed, 165 insertions(+), 12 deletions(-) create mode 100644 public/self-enable.php create mode 100644 resources/lang/en/self-enable.php create mode 100644 resources/lang/zh_CN/self-enable.php create mode 100644 resources/lang/zh_TW/self-enable.php diff --git a/app/Models/BonusLogs.php b/app/Models/BonusLogs.php index 17d55355..472a0b20 100644 --- a/app/Models/BonusLogs.php +++ b/app/Models/BonusLogs.php @@ -21,6 +21,7 @@ class BonusLogs extends NexusModel const DEFAULT_BONUS_BUY_TEMPORARY_INVITE = 500; const DEFAULT_BONUS_BUY_RAINBOW_ID = 5000; const DEFAULT_BONUS_BUY_CHANGE_USERNAME_CARD = 100000; + const DEFAULT_BONUS_SELF_ENABLE = 100000; //扣除类,1开始 const BUSINESS_TYPE_CANCEL_HIT_AND_RUN = 1; @@ -46,6 +47,7 @@ class BonusLogs extends NexusModel const BUSINESS_TYPE_TASK_PASS_REWARD = 21; const BUSINESS_TYPE_REWARD_TORRENT = 22; const BUSINESS_TYPE_CLAIMED_UNREACHED = 23; + const BUSINESS_TYPE_SELF_ENABLE = 24; //获得类,普通获得,1000 起步 const BUSINESS_TYPE_ROLE_WORK_SALARY = 1000; @@ -87,6 +89,7 @@ class BonusLogs extends NexusModel self::BUSINESS_TYPE_TASK_PASS_REWARD => ['text' => 'Task success reward'], self::BUSINESS_TYPE_REWARD_TORRENT => ['text' => 'Reward torrent'], self::BUSINESS_TYPE_CLAIMED_UNREACHED => ['text' => 'Claimed torrent unreached'], + self::BUSINESS_TYPE_SELF_ENABLE => ['text' => 'Self enable'], self::BUSINESS_TYPE_ROLE_WORK_SALARY => ['text' => 'Role work salary'], self::BUSINESS_TYPE_TORRENT_BE_DOWNLOADED => ['text' => 'Torrent be downloaded'], diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 1490cfdb..b6c40d8e 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -334,4 +334,9 @@ class Setting extends NexusModel { return self::get('main.showimdbinfo') == 'yes'; } + + public static function getSelfEnableBonus(): int + { + return (int)self::get("bonus.self_enable", BonusLogs::DEFAULT_BONUS_SELF_ENABLE); + } } diff --git a/app/Models/UserBanLog.php b/app/Models/UserBanLog.php index 081ed06b..6fa74a5b 100644 --- a/app/Models/UserBanLog.php +++ b/app/Models/UserBanLog.php @@ -8,6 +8,8 @@ class UserBanLog extends NexusModel protected $fillable = ['uid', 'username', 'operator', 'reason']; + public $timestamps = true; + public static function clearUserBanLogDuplicate() { $lists = UserBanLog::query() diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index a3b2dfb4..a04846aa 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -2,7 +2,6 @@ namespace App\Repositories; use App\Enums\ModelEventEnum; -use App\Enums\RedisKeysEnum; use App\Exceptions\InsufficientPermissionException; use App\Exceptions\NexusException; use App\Http\Resources\ExamUserResource; @@ -29,7 +28,6 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Str; use Nexus\Database\NexusDB; @@ -228,9 +226,9 @@ class UserRepository extends BaseRepository 'operator' => $operator->id, ]; $modCommentText = sprintf("%s - Disable by %s, reason: %s.", now()->format('Y-m-d'), $operator->username, $reason); - DB::transaction(function () use ($targetUser, $banLog, $modCommentText) { + NexusDB::transaction(function () use ($targetUser, $banLog, $modCommentText) { $targetUser->updateWithModComment(['enabled' => User::ENABLED_NO], $modCommentText); - UserBanLog::query()->insert($banLog); + UserBanLog::query()->create($banLog); }); do_log("user: $uid, $modCommentText"); $this->clearCache($targetUser); diff --git a/include/functions.php b/include/functions.php index cd362786..db018608 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2072,7 +2072,6 @@ function userlogin() { if (empty($row)) { return $loginResult = false; } - if (!$row["passkey"]){ $passkey = md5($row['username'].date("Y-m-d H:i:s").$row['passhash']); sql_query("UPDATE users SET passkey = ".sqlesc($passkey)." WHERE id=" . sqlesc($row["id"])); @@ -2093,6 +2092,9 @@ function userlogin() { // error_reporting(E_ALL & ~E_NOTICE); // error_reporting(-1); // } + if ($row['enabled'] !== 'yes') { + + } return $loginResult = true; } @@ -3168,8 +3170,9 @@ function base64 ($string, $encode=true) { function loggedinorreturn($mainpage = false) { global $CURUSER,$BASEURL; + $script = nexus()->getScript(); if (!$CURUSER) { - if (nexus()->getScript() == 'ajax') { + if ($script == 'ajax') { exit(fail('Not login!', $_POST)); } if ($mainpage) { @@ -3181,7 +3184,9 @@ function loggedinorreturn($mainpage = false) { } exit(); } -// do_log("[USER]: " . $CURUSER['id']); + if ($CURUSER['enabled'] != 'yes' && $script != 'self-enable') { + nexus_redirect('self-enable.php'); + } } function deletetorrent($id, $notify = false) { diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 6add1f01..d417edaf 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -1505,8 +1505,15 @@ function get_user_from_cookie(array $cookie, $isArray = true): array|\App\Models $tokenJson = $result['token_json']; $signature = $result['signature']; $log .= ", uid = $id"; + $isAjax = nexus()->isAjax(); + //only in nexus web can self-enable + $shouldIgnoreEnabled = IN_NEXUS && !$isAjax; if ($isArray) { - $res = sql_query("SELECT * FROM users WHERE users.id = ".sqlesc($id)." AND users.enabled='yes' AND users.status = 'confirmed' LIMIT 1"); + $whereStr = sprintf("id = %d and status = 'confirmed'", $id); + if (!$shouldIgnoreEnabled) { + $whereStr .= " and enabled = 'yes'"; + } + $res = sql_query("SELECT * FROM users WHERE $whereStr LIMIT 1"); $row = mysql_fetch_array($res); if (!$row) { do_log("$log, user not exists"); @@ -1520,7 +1527,11 @@ function get_user_from_cookie(array $cookie, $isArray = true): array|\App\Models do_log("$log, user not exists"); return null; } - $row->checkIsNormal(); + $checkFields = ['status']; + if (!$shouldIgnoreEnabled) { + $checkFields[] = 'enabled'; + } + $row->checkIsNormal($checkFields); $authKey = $row->auth_key; } $expectedSignature = hash_hmac('sha256', $tokenJson, $authKey); diff --git a/lang/chs/lang_settings.php b/lang/chs/lang_settings.php index 1ce174f7..186bcf2e 100644 --- a/lang/chs/lang_settings.php +++ b/lang/chs/lang_settings.php @@ -826,6 +826,8 @@ $lang_settings = array 'text_reward_bonus_options_note' => '种子详情页的魔力值奖励选项,多个用英文逗号分割', 'row_reward_times_limit' => '魔力奖励次数限制', 'text_reward_times_limit_note' => '种子详情页的魔力奖励每人每天次数限制,设置为 0 不限制。默认:0', + 'row_self_enable' => '自助解封', + 'text_self_enable_note' => '个魔力值,如果他选择在被封禁 1 天内解封。封禁时长为 N 天,失去的魔力值将会是此值的 N 倍。', ); ?> diff --git a/lang/cht/lang_settings.php b/lang/cht/lang_settings.php index 1def0ca8..ddb111fb 100644 --- a/lang/cht/lang_settings.php +++ b/lang/cht/lang_settings.php @@ -826,6 +826,8 @@ $lang_settings = array 'text_reward_bonus_options_note' => '種子詳情頁的魔力值獎勵選項,多個用英文逗號分割', 'row_reward_times_limit' => '魔力獎勵次數限制', 'text_reward_times_limit_note' => '種子詳情頁的魔力獎勵每人每天次數限制,設置爲 0 不限制。默認:0', + 'row_self_enable' => '自助解封', + 'text_self_enable_note' => '個魔力值,如果他選擇在被封禁 1 天內解封。封禁時長為 N 天,失去的魔力值將會是此值的 N 倍。', ); ?> diff --git a/lang/en/lang_settings.php b/lang/en/lang_settings.php index c6688550..e1c2b10c 100644 --- a/lang/en/lang_settings.php +++ b/lang/en/lang_settings.php @@ -826,6 +826,8 @@ $lang_settings = array 'text_reward_bonus_options_note' => 'Reward bonus options on the torrent details page, multiple options separated by commas', 'row_reward_times_limit' => 'Reward Frequency Limit', 'text_reward_times_limit_note' => 'Daily limit per user for bonus rewards on seed detail pages. Set to 0 for no limit. Default: 0', + 'row_self_enable' => 'Self-service unblocking', + 'text_self_enable_note' => 'points. If he chooses to unblock within 1 day of being banned. If the ban duration is N days, the lost mana points will be N times this value.', ); ?> diff --git a/nexus/Nexus.php b/nexus/Nexus.php index 281b5892..af6b944a 100644 --- a/nexus/Nexus.php +++ b/nexus/Nexus.php @@ -176,6 +176,22 @@ final class Nexus return false; } + public function isAjax(): bool + { + if ($this->getScript() == 'ajax') { + return true; + } + $ajax = $this->retrieveFromServer(['HTTP_X_REQUESTED_WITH'], true); + if (!empty($ajax) && strtolower($ajax) == 'xmlhttprequest') { + return true; + } + $json = $this->retrieveFromServer(['HTTP_ACCEPT'], true); + if (!empty($json) && strtolower($json) == 'application/json') { + return true; + } + return false; + } + private function generateRequestId(): string { $prefix = ($_SERVER['SCRIPT_FILENAME'] ?? '') . implode('', $_SERVER['argv'] ?? []); @@ -426,4 +442,6 @@ final class Nexus } + + } diff --git a/public/self-enable.php b/public/self-enable.php new file mode 100644 index 00000000..e632318a --- /dev/null +++ b/public/self-enable.php @@ -0,0 +1,62 @@ +%s', nexus_trans('self-enable.enable_status_normal')); +} else { + $latestBanLog = \App\Models\UserBanLog::query() + ->where('uid', $CURUSER['id']) + ->orderBy('id', 'desc') + ->first(); + if (!$latestBanLog) { + printf('

%s

', nexus_trans('self-enable.no_ban_info')); + } else { + $unit = \App\Models\Setting::getSelfEnableBonus(); + $elapsedDay = ceil((time() - $latestBanLog->created_at->getTimestamp()) / 86400); + $total = $unit * $elapsedDay; + $isUserBonusEnough = $CURUSER['seedbonus'] >= $total; + $userBonusNotEnoughTip = nexus_trans('self-enable.bonus_not_enough', ['bonus' => $CURUSER['seedbonus']]); + if (!empty($_POST['submit'])) { + if (!$isUserBonusEnough) { + stdmsg('Error', $userBonusNotEnoughTip); + } else { + $userRep = new \App\Repositories\UserRepository(); + $bonusRep = new \App\Repositories\BonusRepository(); + $operator = \App\Models\User::query()->find($CURUSER['id']); + $bonusRep->consumeUserBonus($CURUSER['id'], $total, \App\Models\BonusLogs::BUSINESS_TYPE_SELF_ENABLE, $title); + $userRep->enableUser($operator, $CURUSER['id'], $title); + nexus_redirect('index.php'); + } + } else { + printf('

%s

', nexus_trans('self-enable.latest_ban_info')); + printf(''); + printf('', $latestBanLog->uid); + printf('', $latestBanLog->username); + printf('', $latestBanLog->reason); + printf('', $latestBanLog->created_at); + printf('
UID:%s
Username:%s
Reason:%s
CreatedAt:%s
'); + printf('

%s

', nexus_trans('self-enable.deduct_bonus_per_day', ['unit' => number_format($unit)])); + printf('

%s

', nexus_trans('self-enable.deduct_bonus_total', ['days' => number_format($elapsedDay), 'total' => number_format($total)])); + if ($isUserBonusEnough) { + printf('

%s

', nexus_trans('self-enable.enable_desc')); + printf('
', nexus_trans('self-enable.enable_button')); + } else { + printf('

%s

', $userBonusNotEnoughTip); + } + } + } +} +end_frame(); +end_main_frame(); +stdfoot(); +?> diff --git a/public/settings.php b/public/settings.php index f77c0346..82b4ef99 100644 --- a/public/settings.php +++ b/public/settings.php @@ -99,7 +99,7 @@ elseif ($action == 'savesettings_bonus') // save bonus 'tengbupload', 'ratiolimit','dlamountlimit','oneinvite','customtitle','vipstatus','bonusgift', 'basictax', 'taxpercentage', 'prolinkpoint', 'prolinktime', 'attendance_initial', 'attendance_step', 'attendance_max', 'cancel_hr', 'attendance_card', 'harem_addition', 'hundredgbupload', 'tengbdownload', 'hundredgbdownload', 'official_addition', 'official_tag', 'zero_bonus_tag', 'zero_bonus_factor', - 'one_tmp_invite', 'rainbow_id', 'change_username_card', 'min_size' + 'one_tmp_invite', 'rainbow_id', 'change_username_card', 'min_size', 'self_enable' ); GetVar($validConfig); $BONUS = []; @@ -630,6 +630,7 @@ elseif ($action == 'bonussettings'){ tr($lang_settings['row_attendance_card'],$lang_settings['text_it_costs_user']."".$lang_settings['text_attendance_card_note'], 1); tr($lang_settings['row_buy_rainbow_id'],$lang_settings['text_it_costs_user']."".$lang_settings['text_buy_rainbow_id_note'], 1); tr($lang_settings['row_buy_change_username_card'],$lang_settings['text_it_costs_user']."".$lang_settings['text_buy_change_username_card_note'], 1); + tr($lang_settings['row_self_enable'],$lang_settings['text_it_costs_user']."".$lang_settings['text_self_enable_note'], 1); echo '' . $lang_settings['text_attendance_get_bonus'] . ''; diff --git a/public/takelogin.php b/public/takelogin.php index 23a44761..73f29f19 100644 --- a/public/takelogin.php +++ b/public/takelogin.php @@ -36,8 +36,8 @@ if (!$row) failedlogins(); if ($row['status'] == 'pending') failedlogins($lang_takelogin['std_user_account_unconfirmed']); -if ($row["enabled"] == "no") - bark($lang_takelogin['std_account_disabled']); +//if ($row["enabled"] == "no") +// bark($lang_takelogin['std_account_disabled']); if (!empty($row['two_step_secret'])) { if (empty($_POST['two_step_code'])) { diff --git a/resources/lang/en/bonus-log.php b/resources/lang/en/bonus-log.php index c7a2b738..46cb530a 100644 --- a/resources/lang/en/bonus-log.php +++ b/resources/lang/en/bonus-log.php @@ -25,6 +25,7 @@ return [ \App\Models\BonusLogs::BUSINESS_TYPE_TASK_NOT_PASS_DEDUCT => 'Task unfinished deduct', \App\Models\BonusLogs::BUSINESS_TYPE_REWARD_TORRENT => 'Reward torrent', \App\Models\BonusLogs::BUSINESS_TYPE_CLAIMED_UNREACHED => 'Claimed torrent unreached', + \App\Models\BonusLogs::BUSINESS_TYPE_SELF_ENABLE => 'Self enable', \App\Models\BonusLogs::BUSINESS_TYPE_ROLE_WORK_SALARY => 'Role work salary', \App\Models\BonusLogs::BUSINESS_TYPE_TORRENT_BE_DOWNLOADED => 'Torrent be downloaded', diff --git a/resources/lang/en/self-enable.php b/resources/lang/en/self-enable.php new file mode 100644 index 00000000..d6c11683 --- /dev/null +++ b/resources/lang/en/self-enable.php @@ -0,0 +1,13 @@ + 'Self-service unblocking', + 'enable_status_normal' => 'Your account status is normal, no self-service unblocking is required.', + 'no_ban_info' => 'Your ban information cannot be found, self-service unblocking is not possible, please contact the administrator.', + 'bonus_not_enough' => 'You currently only have :bonus bonus, self-service unblocking is not possible, please contact the administrator.', + 'latest_ban_info' => 'Your latest ban information is as follows:', + 'deduct_bonus_per_day' => 'Each ban day (less than 1 day is counted as 1 day) requires deducting :unit bonus.', + 'deduct_bonus_total' => 'Currently banned for :days days, total bonus to be deducted :total', + 'enable_desc' => 'If you need to unblock, click the button below, the corresponding bonus points will be deducted and the account will return to normal.', + 'enable_button' => 'Click to unblock', +]; diff --git a/resources/lang/zh_CN/bonus-log.php b/resources/lang/zh_CN/bonus-log.php index 783f51b5..362c4971 100644 --- a/resources/lang/zh_CN/bonus-log.php +++ b/resources/lang/zh_CN/bonus-log.php @@ -25,6 +25,7 @@ return [ \App\Models\BonusLogs::BUSINESS_TYPE_TASK_NOT_PASS_DEDUCT => '任务未完成扣除', \App\Models\BonusLogs::BUSINESS_TYPE_REWARD_TORRENT => '奖励种子', \App\Models\BonusLogs::BUSINESS_TYPE_CLAIMED_UNREACHED => '认领种子未达标扣除', + \App\Models\BonusLogs::BUSINESS_TYPE_SELF_ENABLE => '自助解封', \App\Models\BonusLogs::BUSINESS_TYPE_ROLE_WORK_SALARY => '工作组工资', \App\Models\BonusLogs::BUSINESS_TYPE_TORRENT_BE_DOWNLOADED => '种子被下载', diff --git a/resources/lang/zh_CN/self-enable.php b/resources/lang/zh_CN/self-enable.php new file mode 100644 index 00000000..6304b6ab --- /dev/null +++ b/resources/lang/zh_CN/self-enable.php @@ -0,0 +1,13 @@ + '自助解封', + 'enable_status_normal' => '你的账号状态是正常的,无需自助解封。', + 'no_ban_info' => '找不到你的封禁信息,无法自助解封,请联系管理员。', + 'bonus_not_enough' => '你目前仅有魔力 :bonus, 无法自助解封,请联系管理员。', + 'latest_ban_info' => '你的最新封禁信息如下:', + 'deduct_bonus_per_day' => '每封禁 1 天(不足 1 天按 1 天算)需扣除魔力 :unit', + 'deduct_bonus_total' => '当前已封禁 :days 天,共需扣除魔力 :total', + 'enable_desc' => '若需要解封,点击下面按钮,扣除相应魔力后账号即恢复正常。', + 'enable_button' => '点我解封', +]; diff --git a/resources/lang/zh_TW/bonus-log.php b/resources/lang/zh_TW/bonus-log.php index 13781e15..88470572 100644 --- a/resources/lang/zh_TW/bonus-log.php +++ b/resources/lang/zh_TW/bonus-log.php @@ -25,6 +25,7 @@ return [ \App\Models\BonusLogs::BUSINESS_TYPE_TASK_NOT_PASS_DEDUCT => '任務未完成扣除', \App\Models\BonusLogs::BUSINESS_TYPE_REWARD_TORRENT => '獎勵種子', \App\Models\BonusLogs::BUSINESS_TYPE_CLAIMED_UNREACHED => '認領種子未達標扣除', + \App\Models\BonusLogs::BUSINESS_TYPE_SELF_ENABLE => '自助解封', \App\Models\BonusLogs::BUSINESS_TYPE_ROLE_WORK_SALARY => '工作組工資', \App\Models\BonusLogs::BUSINESS_TYPE_TORRENT_BE_DOWNLOADED => '種子被下載', diff --git a/resources/lang/zh_TW/self-enable.php b/resources/lang/zh_TW/self-enable.php new file mode 100644 index 00000000..502a3491 --- /dev/null +++ b/resources/lang/zh_TW/self-enable.php @@ -0,0 +1,13 @@ + '自助解封', + 'enable_status_normal' => '妳的賬號狀態是正常的,無需自助解封。', + 'no_ban_info' => '找不到妳的封禁信息,無法自助解封,請聯系管理員。', + 'bonus_not_enough' => '妳目前僅有魔力 :bonus, 無法自助解封,請聯系管理員。', + 'latest_ban_info' => '妳的最新封禁信息如下:', + 'deduct_bonus_per_day' => '每封禁 1 天(不足 1 天按 1 天算)需扣除魔力 :unit', + 'deduct_bonus_total' => '當前已封禁 :days 天,共需扣除魔力 :total', + 'enable_desc' => '若需要解封,點擊下面按鈕,扣除相應魔力後賬號即恢復正常。', + 'enable_button' => '點我解封', +];