mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
Merge pull request #190 from kongrui05/security-patch
An IMPORTANT security patch 重要安全补丁
This commit is contained in:
@@ -1088,7 +1088,7 @@ function user_can($permission, $fail = false, $uid = 0): bool
|
|||||||
$uid = get_user_id();
|
$uid = get_user_id();
|
||||||
$log .= ", set current uid: $uid";
|
$log .= ", set current uid: $uid";
|
||||||
}
|
}
|
||||||
if ($uid <= 0) {
|
if (!$fail && $uid <= 0) {
|
||||||
do_log("$log, unauthenticated, false");
|
do_log("$log, unauthenticated, false");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+150
-145
@@ -6,158 +6,163 @@ loggedinorreturn();
|
|||||||
$action = $_POST['action'] ?? 'noAction';
|
$action = $_POST['action'] ?? 'noAction';
|
||||||
$params = $_POST['params'] ?? [];
|
$params = $_POST['params'] ?? [];
|
||||||
|
|
||||||
function noAction()
|
class AjaxInterface{
|
||||||
{
|
|
||||||
throw new \RuntimeException("no Action");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public static function toggleUserMedalStatus($params)
|
||||||
try {
|
{
|
||||||
$result = call_user_func($action, $params);
|
global $CURUSER;
|
||||||
exit(json_encode(success($result)));
|
$rep = new \App\Repositories\MedalRepository();
|
||||||
} catch (\Throwable $exception) {
|
return $rep->toggleUserMedalStatus($params['id'], $CURUSER['id']);
|
||||||
exit(json_encode(fail($exception->getMessage(), $_POST)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleUserMedalStatus($params)
|
|
||||||
{
|
|
||||||
global $CURUSER;
|
|
||||||
$rep = new \App\Repositories\MedalRepository();
|
|
||||||
return $rep->toggleUserMedalStatus($params['id'], $CURUSER['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function attendanceRetroactive($params)
|
|
||||||
{
|
|
||||||
global $CURUSER;
|
|
||||||
$rep = new \App\Repositories\AttendanceRepository();
|
|
||||||
return $rep->retroactive($CURUSER['id'], $params['timestamp']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPtGen($params)
|
|
||||||
{
|
|
||||||
$rep = new Nexus\PTGen\PTGen();
|
|
||||||
$result = $rep->generate($params['url']);
|
|
||||||
if ($rep->isRawPTGen($result)) {
|
|
||||||
return $result;
|
|
||||||
} elseif ($rep->isIyuu($result)) {
|
|
||||||
return $result['data'];
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function addClaim($params)
|
|
||||||
{
|
|
||||||
global $CURUSER;
|
|
||||||
$rep = new \App\Repositories\ClaimRepository();
|
|
||||||
return $rep->store($CURUSER['id'], $params['torrent_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeClaim($params)
|
public static function attendanceRetroactive($params)
|
||||||
{
|
{
|
||||||
global $CURUSER;
|
global $CURUSER;
|
||||||
$rep = new \App\Repositories\ClaimRepository();
|
$rep = new \App\Repositories\AttendanceRepository();
|
||||||
return $rep->delete($params['id'], $CURUSER['id']);
|
return $rep->retroactive($CURUSER['id'], $params['timestamp']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeUserLeechWarn($params)
|
public static function getPtGen($params)
|
||||||
{
|
{
|
||||||
global $CURUSER;
|
$rep = new Nexus\PTGen\PTGen();
|
||||||
$rep = new \App\Repositories\UserRepository();
|
$result = $rep->generate($params['url']);
|
||||||
return $rep->removeLeechWarn($CURUSER['id'], $params['uid']);
|
if ($rep->isRawPTGen($result)) {
|
||||||
}
|
return $result;
|
||||||
|
} elseif ($rep->isIyuu($result)) {
|
||||||
function getOffer($params)
|
return $result['data'];
|
||||||
{
|
} else {
|
||||||
$offer = \App\Models\Offer::query()->findOrFail($params['id']);
|
return '';
|
||||||
return $offer->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
function approvalModal($params)
|
|
||||||
{
|
|
||||||
global $CURUSER;
|
|
||||||
$rep = new \App\Repositories\TorrentRepository();
|
|
||||||
return $rep->buildApprovalModal($CURUSER['id'], $params['torrent_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function approval($params)
|
|
||||||
{
|
|
||||||
global $CURUSER;
|
|
||||||
foreach (['torrent_id', 'approval_status',] as $field) {
|
|
||||||
if (!isset($params[$field])) {
|
|
||||||
throw new \InvalidArgumentException("Require $field");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$rep = new \App\Repositories\TorrentRepository();
|
|
||||||
return $rep->approval($CURUSER['id'], $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addSeedBoxRecord($params)
|
public static function addClaim($params)
|
||||||
{
|
{
|
||||||
global $CURUSER;
|
global $CURUSER;
|
||||||
$rep = new \App\Repositories\SeedBoxRepository();
|
$rep = new \App\Repositories\ClaimRepository();
|
||||||
$params['uid'] = $CURUSER['id'];
|
return $rep->store($CURUSER['id'], $params['torrent_id']);
|
||||||
$params['type'] = \App\Models\SeedBoxRecord::TYPE_USER;
|
}
|
||||||
$params['status'] = \App\Models\SeedBoxRecord::STATUS_UNAUDITED;
|
|
||||||
return $rep->store($params);
|
public static function removeClaim($params)
|
||||||
}
|
{
|
||||||
|
global $CURUSER;
|
||||||
function removeSeedBoxRecord($params)
|
$rep = new \App\Repositories\ClaimRepository();
|
||||||
{
|
return $rep->delete($params['id'], $CURUSER['id']);
|
||||||
global $CURUSER;
|
}
|
||||||
$rep = new \App\Repositories\SeedBoxRepository();
|
|
||||||
return $rep->delete($params['id'], $CURUSER['id']);
|
public static function removeUserLeechWarn($params)
|
||||||
}
|
{
|
||||||
|
global $CURUSER;
|
||||||
function removeHitAndRun($params)
|
$rep = new \App\Repositories\UserRepository();
|
||||||
{
|
return $rep->removeLeechWarn($CURUSER['id'], $params['uid']);
|
||||||
global $CURUSER;
|
}
|
||||||
$rep = new \App\Repositories\BonusRepository();
|
|
||||||
return $rep->consumeToCancelHitAndRun($CURUSER['id'], $params['id']);
|
public static function getOffer($params)
|
||||||
}
|
{
|
||||||
|
$offer = \App\Models\Offer::query()->findOrFail($params['id']);
|
||||||
function consumeBenefit($params)
|
return $offer->toArray();
|
||||||
{
|
}
|
||||||
global $CURUSER;
|
|
||||||
$rep = new \App\Repositories\UserRepository();
|
public static function approvalModal($params)
|
||||||
return $rep->consumeBenefit($CURUSER['id'], $params);
|
{
|
||||||
}
|
global $CURUSER;
|
||||||
|
$rep = new \App\Repositories\TorrentRepository();
|
||||||
function clearShoutBox($params)
|
return $rep->buildApprovalModal($CURUSER['id'], $params['torrent_id']);
|
||||||
{
|
}
|
||||||
global $CURUSER;
|
|
||||||
user_can('sbmanage', true);
|
public static function approval($params)
|
||||||
\Nexus\Database\NexusDB::table('shoutbox')->delete();
|
{
|
||||||
return true;
|
global $CURUSER;
|
||||||
}
|
foreach (['torrent_id', 'approval_status',] as $field) {
|
||||||
|
if (!isset($params[$field])) {
|
||||||
function buyMedal($params)
|
throw new \InvalidArgumentException("Require $field");
|
||||||
{
|
}
|
||||||
global $CURUSER;
|
}
|
||||||
$rep = new \App\Repositories\BonusRepository();
|
$rep = new \App\Repositories\TorrentRepository();
|
||||||
return $rep->consumeToBuyMedal($CURUSER['id'], $params['medal_id']);
|
return $rep->approval($CURUSER['id'], $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function giftMedal($params)
|
public static function addSeedBoxRecord($params)
|
||||||
{
|
{
|
||||||
global $CURUSER;
|
global $CURUSER;
|
||||||
$rep = new \App\Repositories\BonusRepository();
|
$rep = new \App\Repositories\SeedBoxRepository();
|
||||||
return $rep->consumeToGiftMedal($CURUSER['id'], $params['medal_id'], $params['uid']);
|
$params['uid'] = $CURUSER['id'];
|
||||||
}
|
$params['type'] = \App\Models\SeedBoxRecord::TYPE_USER;
|
||||||
|
$params['status'] = \App\Models\SeedBoxRecord::STATUS_UNAUDITED;
|
||||||
function saveUserMedal($params)
|
return $rep->store($params);
|
||||||
{
|
}
|
||||||
global $CURUSER;
|
|
||||||
$data = [];
|
public static function removeSeedBoxRecord($params)
|
||||||
foreach ($params as $param) {
|
{
|
||||||
$fieldAndId = explode('_', $param['name']);
|
global $CURUSER;
|
||||||
$field = $fieldAndId[0];
|
$rep = new \App\Repositories\SeedBoxRepository();
|
||||||
$id = $fieldAndId[1];
|
return $rep->delete($params['id'], $CURUSER['id']);
|
||||||
$value = $param['value'];
|
}
|
||||||
$data[$id][$field] = $value;
|
|
||||||
|
public static function removeHitAndRun($params)
|
||||||
|
{
|
||||||
|
global $CURUSER;
|
||||||
|
$rep = new \App\Repositories\BonusRepository();
|
||||||
|
return $rep->consumeToCancelHitAndRun($CURUSER['id'], $params['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function consumeBenefit($params)
|
||||||
|
{
|
||||||
|
global $CURUSER;
|
||||||
|
$rep = new \App\Repositories\UserRepository();
|
||||||
|
return $rep->consumeBenefit($CURUSER['id'], $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function clearShoutBox($params)
|
||||||
|
{
|
||||||
|
global $CURUSER;
|
||||||
|
user_can('sbmanage', true);
|
||||||
|
\Nexus\Database\NexusDB::table('shoutbox')->delete();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function buyMedal($params)
|
||||||
|
{
|
||||||
|
global $CURUSER;
|
||||||
|
$rep = new \App\Repositories\BonusRepository();
|
||||||
|
return $rep->consumeToBuyMedal($CURUSER['id'], $params['medal_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function giftMedal($params)
|
||||||
|
{
|
||||||
|
global $CURUSER;
|
||||||
|
$rep = new \App\Repositories\BonusRepository();
|
||||||
|
return $rep->consumeToGiftMedal($CURUSER['id'], $params['medal_id'], $params['uid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function saveUserMedal($params)
|
||||||
|
{
|
||||||
|
global $CURUSER;
|
||||||
|
$data = [];
|
||||||
|
foreach ($params as $param) {
|
||||||
|
$fieldAndId = explode('_', $param['name']);
|
||||||
|
$field = $fieldAndId[0];
|
||||||
|
$id = $fieldAndId[1];
|
||||||
|
$value = $param['value'];
|
||||||
|
$data[$id][$field] = $value;
|
||||||
|
}
|
||||||
|
// dd($params, $data);
|
||||||
|
$rep = new \App\Repositories\MedalRepository();
|
||||||
|
return $rep->saveUserMedal($CURUSER['id'], $data);
|
||||||
}
|
}
|
||||||
// dd($params, $data);
|
}
|
||||||
$rep = new \App\Repositories\MedalRepository();
|
|
||||||
return $rep->saveUserMedal($CURUSER['id'], $data);
|
$class = 'AjaxInterface';
|
||||||
|
$reflection = new ReflectionClass($class);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if($reflection->hasMethod($action)&&$reflection->getMethod($action)->isStatic()) {
|
||||||
|
$result = $class::$action($params);
|
||||||
|
exit(json_encode(success($result)));
|
||||||
|
} else {
|
||||||
|
do_log("hacking attempt made by {$CURUSER['username']},uid {$CURUSER['id']}", 'error');
|
||||||
|
throw new \RuntimeException("no Action");
|
||||||
|
}
|
||||||
|
}catch(\Throwable $exception){
|
||||||
|
exit(json_encode(fail($exception->getMessage(), $_POST)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user