mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
support plugin
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class Plugin extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'plugin {action} {name}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Plugin management, arguments: action plugin';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$plugin = new \Nexus\Plugin\Plugin();
|
||||
$action = $this->argument('action');
|
||||
$name = $this->argument('name');
|
||||
$mainClass = $plugin->getMainClass($name);
|
||||
if (!$mainClass) {
|
||||
$this->error("Can not find plugin: $name");
|
||||
return 1;
|
||||
}
|
||||
if ($action == 'install') {
|
||||
call_user_func([$mainClass, 'install']);
|
||||
} elseif ($action == 'uninstall') {
|
||||
call_user_func([$mainClass, 'uninstall']);
|
||||
} else {
|
||||
$this->error("Not support action: $action");
|
||||
return 1;
|
||||
}
|
||||
$log = sprintf("[%s], %s plugin: %s successfully !", nexus()->getRequestId(), $action, $name);
|
||||
$this->info($log);
|
||||
do_log($log);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ use JeroenG\Explorer\Infrastructure\Scout\ElasticEngine;
|
||||
use League\Flysystem\StorageAttributes;
|
||||
use Nexus\Database\NexusDB;
|
||||
use Nexus\Imdb\Imdb;
|
||||
use NexusPlugin\PostLike\PostLike;
|
||||
use Rhilip\Bencode\Bencode;
|
||||
|
||||
class Test extends Command
|
||||
@@ -74,62 +75,9 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// $searchRep = new SearchRepository();
|
||||
// $r = $searchRep->deleteIndex();
|
||||
// $r = $searchRep->createIndex();
|
||||
// $r = $searchRep->import();
|
||||
// dd($r);
|
||||
//
|
||||
// $arr = [
|
||||
// 'cat' => 'category',
|
||||
// 'source' => 'source',
|
||||
// 'medium' => 'medium',
|
||||
// 'codec' => 'codec',
|
||||
// 'audiocodec' => 'audiocodec',
|
||||
// 'standard' => 'standard',
|
||||
// 'processing' => 'processing',
|
||||
// 'team' => 'team',
|
||||
// ];
|
||||
$queryString = 'cat401=1&cat404=1&source2=1&medium2=1&medium3=1&codec3=1&audiocodec3=1&standard2=1&standard3=1&processing2=1&team3=1&team4=1&incldead=1&spstate=0&inclbookmarked=0&search=&search_area=0&search_mode=0';
|
||||
$userSetting = '[cat401][cat404][sou1][med1][cod1][sta2][sta3][pro2][tea2][aud2][incldead=0][spstate=3][inclbookmarked=2]';
|
||||
// foreach ($arr as $queryField => $value) {
|
||||
//// $pattern = sprintf("/\[%s([\d]+)\]/", substr($queryField, 0, 3));
|
||||
// $pattern = "/{$queryField}([\d]+)=/";
|
||||
// if (preg_match_all($pattern, $queryString, $matches)) {
|
||||
// dump($matches);
|
||||
// echo '----------------------' . PHP_EOL;
|
||||
// }
|
||||
// }
|
||||
// $r = preg_match("/\[incldead=([\d]+)\]/", $userSetting, $matches);
|
||||
// dump($matches);
|
||||
|
||||
$params = [
|
||||
'tag_id' => 1,
|
||||
// 'incldead' => 0,
|
||||
// 'spstate' => 0,
|
||||
// 'inclbookmarked' => 0,
|
||||
// 'search' => '5034',
|
||||
// 'search_area' => 4,
|
||||
// 'search_mode' => 0,
|
||||
];
|
||||
$queryString = "cat401=1&cat404=1&cat405=1&cat402=1&cat403=1&cat406=1&cat407=1&cat409=1&cat408=1&incldead=0&spstate=0&inclbookmarked=0&search=5034838&search_area=4&search_mode=0";
|
||||
// $r = $searchRep->listTorrentFromEs($params, 1, '');
|
||||
|
||||
// $r = $searchRep->updateTorrent(1);
|
||||
// $r = $searchRep->updateUser(1);
|
||||
// $r = $searchRep->addTorrent(1);
|
||||
// $r = $searchRep->deleteBookmark(1);
|
||||
// $r = $searchRep->addBookmark(1);
|
||||
|
||||
// $rep = new AttendanceRepository();
|
||||
// $uid = 1;
|
||||
// $attendance = $rep->getAttendance($uid);
|
||||
// $r = $rep->migrateAttendanceLogs($uid);
|
||||
// $r = $rep->getContinuousDays($attendance);
|
||||
// $r = $rep->getContinuousPoints(11);
|
||||
|
||||
$r = trim(exec('command -v 7z.exe'));
|
||||
dd($r);
|
||||
$postLike = new PostLike();
|
||||
$postLike->install();
|
||||
// $postLike->uninstall();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,6 +41,10 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
if (!request()->expectsJson()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
|
||||
@@ -57,6 +57,7 @@ class Kernel extends HttpKernel
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.nexus' => \App\Http\Middleware\NexusAuth::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class NexusAuth extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return getSchemeAndHttpHost() . '/login.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
@@ -25,6 +28,34 @@ class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
Auth::viaRequest('nexus-cookie', function (Request $request) {
|
||||
return $this->getUserByCookie($request->cookie());
|
||||
});
|
||||
}
|
||||
|
||||
private function getUserByCookie($cookie)
|
||||
{
|
||||
if (empty($cookie["c_secure_pass"]) || empty($cookie["c_secure_uid"]) || empty($cookie["c_secure_login"])) {
|
||||
return null;
|
||||
}
|
||||
$b_id = base64($cookie["c_secure_uid"],false);
|
||||
$id = intval($b_id ?? 0);
|
||||
if (!$id || !is_valid_id($id) || strlen($cookie["c_secure_pass"]) != 32) {
|
||||
return null;
|
||||
}
|
||||
$user = User::query()->find($id);
|
||||
if (!$user) {
|
||||
return null;
|
||||
}
|
||||
if ($cookie["c_secure_login"] == base64("yeah")) {
|
||||
if ($cookie["c_secure_pass"] != md5($user->passhash . $_SERVER["REMOTE_ADDR"])) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if ($cookie["c_secure_pass"] !== md5($user->passhash)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user