@@ -275,35 +275,105 @@ switch ($Command.ToLower()) {
275275 $confirmation = Read-Host " Type 'yes' to proceed"
276276
277277 if ($confirmation.ToLower () -eq " yes" ) {
278+ Write-Host " "
279+ Write-Host " Starting cleanup process..." - ForegroundColor $WarningColor
280+
281+ $itemsToRemove = @ (
282+ " ./sentinel-kit_server_frontend/node_modules" ,
283+ " ./sentinel-kit_server_frontend/package-lock.json" ,
284+ " ./sentinel-kit_server_frontend/dist" ,
285+ " ./sentinel-kit_server_backend/.initial_setup_done" ,
286+ " ./sentinel-kit_server_backend/composer.lock" ,
287+ " ./sentinel-kit_server_backend/symfony.lock" ,
288+ " ./sentinel-kit_server_backend/var" ,
289+ " ./sentinel-kit_server_backend/vendor" ,
290+ " ./sentinel-kit_server_backend/migrations/*" ,
291+ " ./sentinel-kit_server_backend/config/jwt/*.pem" ,
292+ " ./config/elastalert_ruleset/*" ,
293+ " ./config/caddy_server/certificates/*" ,
294+ " ./data/caddy_logs/*" ,
295+ " ./data/ftp_data/*" ,
296+ " ./data/grafana/*" ,
297+ " ./data/kibana/*" ,
298+ " ./data/log_ingest_data/auditd/*" ,
299+ " ./data/log_ingest_data/evtx/*" ,
300+ " ./data/log_ingest_data/json/*" ,
301+ " ./data/fluentbit_db/*" ,
302+ " ./data/yara_triage_data/*"
303+ )
304+
305+ $successCount = 0
306+ $errorCount = 0
307+
308+ foreach ($item in $itemsToRemove ) {
309+ if ($item.Contains (" *" )) {
310+ # Handle wildcard paths
311+ $basePath = Split-Path $item - Parent
312+ $pattern = Split-Path $item - Leaf
313+
314+ if (Test-Path $basePath ) {
315+ try {
316+ $files = Get-ChildItem - Path $basePath - Filter $pattern - ErrorAction SilentlyContinue
317+ if ($files ) {
318+ Remove-Item - Path $files.FullName - Recurse - Force - ErrorAction Stop
319+ Write-Host " Removed: $item " - ForegroundColor $SuccessColor
320+ $successCount ++
321+ } else {
322+ Write-Host " Skipped: $item (not found)" - ForegroundColor $GrayColor
323+ }
324+ } catch {
325+ Write-Host " Failed to remove: $item " - ForegroundColor $ErrorColor
326+ $errorCount ++
327+ }
328+ } else {
329+ Write-Host " Skipped: $item (path not found)" - ForegroundColor $GrayColor
330+ }
331+ } else {
332+ # Handle regular paths
333+ if (Test-Path $item ) {
334+ try {
335+ Remove-Item - Path $item - Recurse - Force - ErrorAction Stop
336+ Write-Host " Removed: $item " - ForegroundColor $SuccessColor
337+ $successCount ++
338+ } catch {
339+ Write-Host " Failed to remove: $item " - ForegroundColor $ErrorColor
340+ $errorCount ++
341+ }
342+ } else {
343+ Write-Host " Skipped: $item (not found)" - ForegroundColor $GrayColor
344+ }
345+ }
346+ }
347+
348+ Write-Host " "
278349 Write-Host " Stopping Docker containers and removing volumes..." - ForegroundColor $WarningColor
279350
280351 if (Test-DockerCompose ) {
281352 Invoke-Expression " docker compose down -v"
282353
283354 if ($LASTEXITCODE -eq 0 ) {
284- Write-Host " Docker containers stopped and volumes removed." - ForegroundColor $SuccessColor
355+ Write-Host " Docker containers and volumes removed successfully." - ForegroundColor $SuccessColor
356+ $successCount ++
285357 } else {
286- Write-Host " Error stopping containers." - ForegroundColor $ErrorColor
358+ Write-Host " Error stopping Docker containers. Exit Code: $LASTEXITCODE " - ForegroundColor $ErrorColor
359+ $errorCount ++
287360 }
288361 }
289362
290- $dataDirs = @ (" data\mysql" , " data\elasticsearch" , " data\grafana" , " data\kibana" )
291-
292- Write-Host " Cleaning local data directories..." - ForegroundColor $WarningColor
293-
294- foreach ($dir in $dataDirs ) {
295- if (Test-Path $dir ) {
296- try {
297- Remove-Item - Path $dir - Recurse - Force
298- Write-Host " Cleaned: $dir " - ForegroundColor $SuccessColor
299- } catch {
300- Write-Host " Error cleaning: $dir " - ForegroundColor $ErrorColor
301- }
302- }
363+ Write-Host " "
364+ Write-Host " --------------------------------------------------------" - ForegroundColor $HeaderColor
365+ Write-Host " Cleanup Summary:" - ForegroundColor $HeaderColor
366+ Write-Host " Successful operations: $successCount " - ForegroundColor $SuccessColor
367+ if ($errorCount -gt 0 ) {
368+ Write-Host " Failed operations: $errorCount " - ForegroundColor $ErrorColor
303369 }
370+ Write-Host " --------------------------------------------------------" - ForegroundColor $HeaderColor
304371
305- Write-Host " "
306- Write-Host " Cleanup completed!" - ForegroundColor $SuccessColor
372+ if ($errorCount -eq 0 ) {
373+ Write-Host " All user data has been successfully cleaned!" - ForegroundColor $SuccessColor
374+ } else {
375+ Write-Host " Cleanup completed with some errors. Check the output above." - ForegroundColor $WarningColor
376+ }
307377 } else {
308378 Write-Host " Operation cancelled." - ForegroundColor $InfoColor
309379 }
0 commit comments