|
1 | 1 | // cmd/display_helpers.go - Shared display and formatting helpers |
| 2 | +// |
| 3 | +// This file re-exports display and helper functions from cmd/internal packages |
| 4 | +// for backward compatibility. All commands can use these functions without |
| 5 | +// importing the internal packages directly. |
2 | 6 | package cmd |
3 | 7 |
|
4 | 8 | import ( |
5 | | - "fmt" |
6 | | - |
| 9 | + "github.com/CodeMonkeyCybersecurity/shells/cmd/internal/display" |
| 10 | + "github.com/CodeMonkeyCybersecurity/shells/cmd/internal/helpers" |
| 11 | + "github.com/CodeMonkeyCybersecurity/shells/internal/discovery" |
| 12 | + "github.com/CodeMonkeyCybersecurity/shells/internal/logger" |
7 | 13 | "github.com/CodeMonkeyCybersecurity/shells/pkg/types" |
8 | | - "github.com/fatih/color" |
9 | 14 | ) |
10 | 15 |
|
11 | | -// Shared display helper functions for all commands |
12 | | - |
13 | | -func colorStatus(status string) string { |
14 | | - switch status { |
15 | | - case "completed": |
16 | | - return color.New(color.FgGreen).Sprint("✓ " + status) |
17 | | - case "running": |
18 | | - return color.New(color.FgYellow).Sprint("⟳ " + status) |
19 | | - case "failed": |
20 | | - return color.New(color.FgRed).Sprint("✗ " + status) |
21 | | - default: |
22 | | - return status |
23 | | - } |
24 | | -} |
25 | | - |
26 | | -func colorPhaseStatus(status string) string { |
27 | | - switch status { |
28 | | - case "completed": |
29 | | - return color.New(color.FgGreen).Sprint("✓") |
30 | | - case "running": |
31 | | - return color.New(color.FgYellow).Sprint("⟳") |
32 | | - case "failed": |
33 | | - return color.New(color.FgRed).Sprint("✗") |
34 | | - default: |
35 | | - return "○" |
36 | | - } |
37 | | -} |
38 | | - |
39 | | -func colorSeverity(severity types.Severity) string { |
40 | | - switch severity { |
41 | | - case types.SeverityCritical: |
42 | | - return color.New(color.FgRed, color.Bold).Sprint("CRITICAL") |
43 | | - case types.SeverityHigh: |
44 | | - return color.New(color.FgRed).Sprint("HIGH") |
45 | | - case types.SeverityMedium: |
46 | | - return color.New(color.FgYellow).Sprint("MEDIUM") |
47 | | - case types.SeverityLow: |
48 | | - return color.New(color.FgCyan).Sprint("LOW") |
49 | | - case types.SeverityInfo: |
50 | | - return color.New(color.FgWhite).Sprint("INFO") |
51 | | - default: |
52 | | - return string(severity) |
53 | | - } |
54 | | -} |
| 16 | +// Re-export display functions for backward compatibility |
| 17 | +var ( |
| 18 | + colorStatus = display.ColorStatus |
| 19 | + colorPhaseStatus = display.ColorPhaseStatus |
| 20 | + colorSeverity = display.ColorSeverity |
| 21 | + groupFindingsBySeverity = display.GroupFindingsBySeverity |
| 22 | + displayTopFindings = display.DisplayTopFindings |
| 23 | +) |
55 | 24 |
|
56 | | -func groupFindingsBySeverity(findings []types.Finding) map[types.Severity]int { |
57 | | - counts := make(map[types.Severity]int) |
58 | | - for _, finding := range findings { |
59 | | - counts[finding.Severity]++ |
60 | | - } |
61 | | - return counts |
| 25 | +// Re-export helper functions for backward compatibility |
| 26 | +func prioritizeAssetsForBugBounty(assets []*discovery.Asset, log *logger.Logger) []*helpers.BugBountyAssetPriority { |
| 27 | + return helpers.PrioritizeAssetsForBugBounty(assets, log) |
62 | 28 | } |
63 | 29 |
|
64 | | -func displayTopFindings(findings []types.Finding, limit int) { |
65 | | - // Sort by severity (critical first) |
66 | | - sortedFindings := make([]types.Finding, len(findings)) |
67 | | - copy(sortedFindings, findings) |
68 | | - |
69 | | - // Simple sort: critical, high, medium, low, info |
70 | | - severityOrder := map[types.Severity]int{ |
71 | | - types.SeverityCritical: 0, |
72 | | - types.SeverityHigh: 1, |
73 | | - types.SeverityMedium: 2, |
74 | | - types.SeverityLow: 3, |
75 | | - types.SeverityInfo: 4, |
76 | | - } |
77 | | - |
78 | | - // Bubble sort by severity |
79 | | - for i := 0; i < len(sortedFindings); i++ { |
80 | | - for j := i + 1; j < len(sortedFindings); j++ { |
81 | | - if severityOrder[sortedFindings[i].Severity] > severityOrder[sortedFindings[j].Severity] { |
82 | | - sortedFindings[i], sortedFindings[j] = sortedFindings[j], sortedFindings[i] |
83 | | - } |
84 | | - } |
85 | | - } |
86 | | - |
87 | | - count := 0 |
88 | | - for _, finding := range sortedFindings { |
89 | | - if count >= limit { |
90 | | - break |
91 | | - } |
92 | | - |
93 | | - fmt.Printf("\n%s - %s\n", colorSeverity(finding.Severity), finding.Title) |
94 | | - fmt.Printf(" Tool: %s | Type: %s\n", finding.Tool, finding.Type) |
95 | | - |
96 | | - if finding.Description != "" { |
97 | | - // Truncate description if too long |
98 | | - desc := finding.Description |
99 | | - if len(desc) > 150 { |
100 | | - desc = desc[:147] + "..." |
101 | | - } |
102 | | - fmt.Printf(" %s\n", desc) |
103 | | - } |
104 | | - |
105 | | - if finding.Evidence != "" { |
106 | | - // Show first line of evidence |
107 | | - evidence := finding.Evidence |
108 | | - if len(evidence) > 100 { |
109 | | - evidence = evidence[:97] + "..." |
110 | | - } |
111 | | - fmt.Printf(" Evidence: %s\n", evidence) |
112 | | - } |
113 | | - |
114 | | - count++ |
115 | | - } |
| 30 | +func displayTopBugBountyTargets(assets []*helpers.BugBountyAssetPriority) { |
| 31 | + helpers.DisplayTopBugBountyTargets(assets) |
116 | 32 | } |
117 | 33 |
|
118 | 34 | // noopTelemetry is a no-op implementation of core.Telemetry |
|
0 commit comments