add bconsole on backup management dashboard with limited commands
This commit is contained in:
@@ -451,6 +451,42 @@ func (s *Service) getClientNameFromJob(ctx context.Context, jobID int) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// ExecuteBconsoleCommand executes a bconsole command and returns the output
|
||||
func (s *Service) ExecuteBconsoleCommand(ctx context.Context, command string) (string, error) {
|
||||
// Sanitize command
|
||||
command = strings.TrimSpace(command)
|
||||
if command == "" {
|
||||
return "", fmt.Errorf("command cannot be empty")
|
||||
}
|
||||
|
||||
// Remove any existing quit commands from user input
|
||||
command = strings.TrimSuffix(strings.ToLower(command), "quit")
|
||||
command = strings.TrimSpace(command)
|
||||
|
||||
// Ensure command ends with quit
|
||||
commandWithQuit := command + "\nquit"
|
||||
|
||||
// Use printf instead of echo -e for better compatibility
|
||||
// Escape single quotes in command
|
||||
escapedCommand := strings.ReplaceAll(commandWithQuit, "'", "'\"'\"'")
|
||||
|
||||
// Execute bconsole command using printf to avoid echo -e issues
|
||||
cmd := exec.CommandContext(ctx, "sh", "-c", fmt.Sprintf("printf '%%s\\n' '%s' | bconsole", escapedCommand))
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
// bconsole may return non-zero exit code even on success, so check output
|
||||
outputStr := string(output)
|
||||
if len(outputStr) > 0 {
|
||||
// If there's output, return it even if there's an error
|
||||
return outputStr, nil
|
||||
}
|
||||
return outputStr, fmt.Errorf("bconsole error: %w", err)
|
||||
}
|
||||
|
||||
return string(output), nil
|
||||
}
|
||||
|
||||
// upsertJob inserts or updates a job in the database
|
||||
func (s *Service) upsertJob(ctx context.Context, job Job) error {
|
||||
query := `
|
||||
|
||||
Reference in New Issue
Block a user