Skip to content

Commit

Permalink
Fix asset discovery.
Browse files Browse the repository at this point in the history
  • Loading branch information
csavelief committed Sep 8, 2024
1 parent 744e509 commit 66b98e1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Modules\AdversaryMeter\Http\Controllers;

use App\Modules\AdversaryMeter\Events\BeginPortsScan;
use App\Modules\AdversaryMeter\Helpers\ApiUtils;
use App\Modules\AdversaryMeter\Helpers\ApiUtilsFacade as ApiUtils;
use App\Modules\AdversaryMeter\Listeners\CreateAssetListener;
use App\Modules\AdversaryMeter\Listeners\DeleteAssetListener;
use App\Modules\AdversaryMeter\Models\Alert;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function discover(Request $request): array
if (!IsValidDomain::test($domain)) {
return [];
}
if (!in_array($domain, self::BLACKLIST)) {
if (in_array($domain, self::BLACKLIST)) {
abort(500, "The domain is blacklisted : {$domain}");
}
return ApiUtils::discover_public($domain);
Expand Down Expand Up @@ -361,7 +361,7 @@ public function deleteAsset(Asset $asset): void

/** @var User $user */
$user = Auth::user();
DeleteAssetListener::execute($user, $asset);
DeleteAssetListener::execute($user, $asset->asset);
}

public function restartScan(Asset $asset): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function handle()
Asset::where('tld', $tld)
->get()
->each(function (Asset $asset) use ($domain) {
event(new CreateAsset($domain));
event(new CreateAsset($asset->createdBy(), $domain));
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/Modules/AdversaryMeter/Listeners/CreateAssetListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use App\Modules\AdversaryMeter\Rules\IsValidDomain;
use App\Modules\AdversaryMeter\Rules\IsValidIpAddress;
use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

class CreateAssetListener extends AbstractListener
Expand All @@ -28,14 +27,15 @@ public static function execute(User $user, string $asset): ?Asset
} else {
$assetType = AssetTypesEnum::RANGE;
}
Auth::login($user); // otherwise the tenant will not be properly set
return Asset::updateOrCreate(
[
'asset' => $asset,
'created_by' => $user->id,
],
[
'asset' => $asset,
'type' => $assetType,
'created_by' => $user->id,
]
);
}
Expand Down
8 changes: 5 additions & 3 deletions app/Modules/AdversaryMeter/Listeners/DeleteAssetListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use App\Modules\AdversaryMeter\Rules\IsValidDomain;
use App\Modules\AdversaryMeter\Rules\IsValidIpAddress;
use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

class DeleteAssetListener extends AbstractListener
Expand All @@ -29,8 +28,11 @@ public static function execute(User $user, string $asset): bool
$assetType = AssetTypesEnum::RANGE;
}

Auth::login($user); // otherwise the tenant will not be properly set
Asset::where('asset', $asset)->where('type', $assetType)->delete();
Asset::where('asset', $asset)
->where('type', $assetType)
->where('created_by', $user->id)
->delete();

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function handle2($event)
Asset::where('tld', $tld)
->get()
->each(function (Asset $asset) use ($domain) {
event(new CreateAsset($domain));
event($asset->createdBy(), new CreateAsset($domain));
});
});

Expand Down
4 changes: 2 additions & 2 deletions public/adversary_meter/src/js/_assets/tab-assets-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class TabAssetsImporter extends com.computablefacts.widgets.Widget {
const tags = data.tags.map(tag => `<span class="badge me-2 mb-1">${tag}</span>`).join('');
return createNode('div', tags)
},
(data) => document.createTextNode(data.inDatabase ? i18next.t('Déjà importé') : '-'),
(data) => document.createTextNode(data.inDatabase ? i18next.t('importé') : ''),
(data) => {
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
Expand All @@ -222,7 +222,7 @@ export class TabAssetsImporter extends com.computablefacts.widgets.Widget {
}
] : [
(data) => document.createTextNode(data.asset ? data.asset : '-'),
(data) => document.createTextNode(data.inDatabase ? i18next.t('Déjà importé') : '-'),
(data) => document.createTextNode(data.inDatabase ? i18next.t('importé') : ''),
(data) => {
const checkbox = document.createElement('input');
checkbox.classList.add('me-2')
Expand Down
2 changes: 1 addition & 1 deletion public/adversary_meter/src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"Ce n'est pas un nom de domaine ou une adresse ip valide.": "This is not a valid domain name or IP address.",
"Étiquettes": "Tags",
"Status": "Status",
"Déjà importé": "Already imported",
"importé": "imported",
"Une erreur s'est produite, veuillez réessayer plus tard.": "An error occurred, please try again later.",
"Aucun fichier sélectionné.": "No file selected.",
"Erreur lors de la lecture du fichier CSV.": "Error reading the CSV file.",
Expand Down

0 comments on commit 66b98e1

Please sign in to comment.