Vosa.Cc
€200,00 EUR
Prix promotionnel
€200,00 EUR
Prix régulier
```csharp// ============================================================// SAVA COMMAND v1 — FULL WORKING CODE// Platform: Windows 11 | .NET 8 | WPF// Copy entire block. Create project with:// dotnet new wpf -n SavaCommand// Replace all generated files with these.// ============================================================// ============================================================// FILE: SavaCommand.csproj// ============================================================/*<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>WinExe</OutputType><TargetFramework>net8.0-windows</TargetFramework><Nullable>enable</Nullable><UseWPF>true</UseWPF><AssemblyName>SavaCommand</AssemblyName></PropertyGroup></Project>*/// ============================================================// FILE: App.xaml// ============================================================/*<Application x:Class="SavaCommand.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"StartupUri="MainWindow.xaml"></Application>*/// ============================================================// FILE: App.xaml.cs// ============================================================using System.IO;using System.Windows;namespace SavaCommand{public partial class App : Application{protected override void OnStartup(StartupEventArgs e){base.OnStartup(e);FolderManager.EnsureStructure();}}}// ============================================================// FILE: MainWindow.xaml// ============================================================/*<Window x:Class="SavaCommand.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="SAVA COMMAND v1" Height="700" Width="900"Background="#1e1e2e" Foreground="#cdd6f4"WindowStartupLocation="CenterScreen"><Grid Margin="16"><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="*"/><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="160"/></Grid.RowDefinitions><!-- Header --><TextBlock Grid.Row="0" Text="SAVA COMMAND" FontSize="24" FontWeight="Bold"Foreground="#89b4fa" Margin="0,0,0,8"/><!-- Status --><Border Grid.Row="1" Background="#313244" CornerRadius="6" Padding="12" Margin="0,0,0,12"><StackPanel><TextBlock Text="STATUS" FontWeight="Bold" Foreground="#a6adc8"/><TextBlock x:Name="StatusText" Text="Ready. No pending actions." Margin="0,4,0,0"/></StackPanel></Border><!-- Action Queue --><Border Grid.Row="2" Background="#313244" CornerRadius="6" Padding="12" Margin="0,0,0,12"><DockPanel><TextBlock DockPanel.Dock="Top" Text="PENDING ACTIONS" FontWeight="Bold"Foreground="#a6adc8" Margin="0,0,0,8"/><ListBox x:Name="QueueList" Background="Transparent" Foreground="#cdd6f4"BorderThickness="0" SelectionChanged="QueueList_SelectionChanged"/></DockPanel></Border><!-- Action Detail --><Border Grid.Row="3" Background="#45475a" CornerRadius="6" Padding="12" Margin="0,0,0,12"><StackPanel><TextBlock Text="SELECTED ACTION DETAIL" FontWeight="Bold"Foreground="#a6adc8" Margin="0,0,0,8"/><TextBlock x:Name="DetailType" Text="Type: —"/><TextBlock x:Name="DetailTarget" Text="Target: —"/><TextBlock x:Name="DetailRisk" Text="Risk: —"/><TextBlock x:Name="DetailAdmin" Text="Requires Admin: —"/><TextBlock x:Name="DetailNetwork" Text="Requires Network: —"/><TextBlock x:Name="DetailDescription" Text="Description: —" TextWrapping="Wrap"/></StackPanel></Border><!-- Buttons --><StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,12"><Button x:Name="BtnApprove" Content="✓ APPROVE" Width="140" Height="40"Margin="0,0,12,0" Click="BtnApprove_Click"Background="#a6e3a1" Foreground="#1e1e2e" FontWeight="Bold"/><Button x:Name="BtnReject" Content="✗ REJECT" Width="140" Height="40"Margin="0,0,12,0" Click="BtnReject_Click"Background="#f38ba8" Foreground="#1e1e2e" FontWeight="Bold"/><Button x:Name="BtnAdd" Content="+ TEST ACTION" Width="140" Height="40"Click="BtnAdd_Click"Background="#89b4fa" Foreground="#1e1e2e" FontWeight="Bold"/></StackPanel><!-- Logs --><Border Grid.Row="5" Background="#181825" CornerRadius="6" Padding="8"><DockPanel><TextBlock DockPanel.Dock="Top" Text="LOG" FontWeight="Bold"Foreground="#a6adc8" Margin="0,0,0,4"/><ScrollViewer VerticalScrollBarVisibility="Auto"><TextBlock x:Name="LogText" TextWrapping="Wrap" FontFamily="Consolas" FontSize="11"/></ScrollViewer></DockPanel></Border></Grid></Window>*/// ============================================================// FILE: MainWindow.xaml.cs// ============================================================using System;using System.Collections.ObjectModel;using System.Windows;using System.Windows.Controls;namespace SavaCommand{public partial class MainWindow : Window{private readonly ObservableCollection<ActionItem> _queue = new();private readonly PolicyEngine _policy = new();private readonly Logger _logger = new();public MainWindow(){InitializeComponent();QueueList.ItemsSource = _queue;_logger.OnLog += msg => Dispatcher.Invoke(() =>{LogText.Text += msg + "\n";});_logger.Log("SAVA COMMAND v1 started.");_logger.Log("Policy: DENY ALL by default. Manual approval required.");}private void BtnAdd_Click(object sender, RoutedEventArgs e){// Simulate a proposed action for testingvar action = new ActionItem{Id = Guid.NewGuid().ToString("N")[..8],Type = ActionType.WriteFile,Target = FolderManager.GetPath("Outputs", "test_output.txt"),Description = "Write test result to Outputs folder",RiskLevel = RiskLevel.Low,RequiresAdmin = false,RequiresNetwork = false,Status = ActionStatus.Pending};var validation = _policy.Validate(action);if (!validation.Allowed){_logger.Log($"[BLOCKED] {action.Id} — {validation.Reason}");action.Status = ActionStatus.Blocked;QueueManager.SaveToQuarantine(action);StatusText.Text = $"Action {action.Id} BLOCKED by policy.";return;}_queue.Add(action);QueueManager.SaveToQueue(action);_logger.Log($"[QUEUED] {action.Id} | {action.Type} | {action.Target}");StatusText.Text = $"{_queue.Count} pending action(s).";}private void QueueList_SelectionChanged(object sender, SelectionChangedEventArgs e){if (QueueList.SelectedItem is ActionItem item){DetailType.Text = $"Type: {item.Type}";DetailTarget.Text = $"Target: {item.Target}";DetailRisk.Text = $"Risk: {item.RiskLevel}";DetailAdmin.Text = $"Requires Admin: {item.RequiresAdmin}";DetailNetwork.Text = $"Requires Network: {item.RequiresNetwork}";DetailDescription.Text = $"Description: {item.Description}";}}private void BtnApprove_Click(object sender, RoutedEventArgs e){if (QueueList.SelectedItem is not ActionItem item) return;if (item.Status != ActionStatus.Pending) return;// Confirmvar result = MessageBox.Show($"APPROVE this action?\n\nType: {item.Type}\nTarget: {item.Target}\nRisk: {item.RiskLevel}","SAVA COMMAND — Confirm Approval",MessageBoxButton.YesNo,MessageBoxImage.Warning);if (result != MessageBoxResult.Yes) return;item.Status = ActionStatus.Approved;_logger.Log($"[APPROVED] {item.Id} | {item.Type} | {item.Target}");// Executevar executor = new Executor(_logger);var success = executor.Execute(item);if (success){item.Status = ActionStatus.Completed;_logger.Log($"[COMPLETED] {item.Id}");}else{item.Status = ActionStatus.Failed;_logger.Log($"[FAILED] {item.Id}");}_queue.Remove(item);QueueManager.RemoveFromQueue(item);QueueManager.SaveToApproved(item);StatusText.Text = $"{item.Id} → {item.Status}. {_queue.Count} remaining.";ClearDetail();}private void BtnReject_Click(object sender, RoutedEventArgs e){if (QueueList.SelectedItem is not ActionItem item) return;if (item.Status != ActionStatus.Pending) return;item.Status = ActionStatus.Rejected;_logger.Log($"[REJECTED] {item.Id} | {item.Type} | {item.Target}");_queue.Remove(item);QueueManager.RemoveFromQueue(item);QueueManager.SaveToQuarantine(item);StatusText.Text = $"{item.Id} rejected. {_queue.Count} remaining.";ClearDetail();}private void ClearDetail(){DetailType.Text = "Type: —";DetailTarget.Text = "Target: —";DetailRisk.Text = "Risk: —";DetailAdmin.Text = "Requires Admin: —";DetailNetwork.Text = "Requires Network: —";DetailDescription.Text = "Description: —";}}}// ============================================================// FILE: Models/ActionItem.cs// ============================================================namespace SavaCommand{public enum ActionType{ReadFile,WriteFile,CreateFolder,ListFolder,DeleteFile, // blocked by policy in v1Execute, // blocked by policy in v1Network // blocked by policy in v1}public enum RiskLevel { Low, Medium, High, Critical }public enum ActionStatus { Pending, Approved, Rejected, Blocked, Completed, Failed }public class ActionItem{public string Id { get; set; } = "";public ActionType Type { get; set; }public string Target { get; set; } = "";public string Description { get; set; } = "";public RiskLevel RiskLevel { get; set; }public bool RequiresAdmin { get; set; }public bool RequiresNetwork { get; set; }public ActionStatus Status { get; set; }public string Timestamp { get; set; } = DateTime.UtcNow.ToString("o");public override string ToString() => $"[{Status}] {Id} | {Type} → {System.IO.Path.GetFileName(Target)}";}}// ============================================================// FILE: Core/FolderManager.cs// ============================================================using System.IO;namespace SavaCommand{public static class FolderManager{private static readonly string Root = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),"SavaCommand");private static readonly string[] Folders ={ "Config", "Queue", "Approved", "Outputs", "Logs", "Quarantine", "Policy" };public static void EnsureStructure(){foreach (var folder in Folders)Directory.CreateDirectory(Path.Combine(Root, folder));}public static string GetPath(string folder, string file = "")=> string.IsNullOrEmpty(file)? Path.Combine(Root, folder): Path.Combine(Root, folder, file);public static bool IsInsideWorkingFolder(string path){var full = Path.GetFullPath(path);var rootFull = Path.GetFullPath(Root);return full.StartsWith(rootFull, StringComparison.OrdinalIgnoreCase);}}}// ============================================================// FILE: Core/PolicyEngine.cs// ============================================================using System.IO;namespace SavaCommand{public class ValidationResult{public bool Allowed { get; set; }public string Reason { get; set; } = "";}public class PolicyEngine{private static readonly ActionType[] BlockedActions ={ ActionType.DeleteFile, ActionType.Execute, ActionType.Network };private static readonly string[] BlockedExtensions ={ ".exe", ".ps1", ".bat", ".cmd", ".vbs", ".reg", ".msi", ".dll", ".com", ".scr" };public ValidationResult Validate(ActionItem action){// Rule 1: blocked action typesif (Array.Exists(BlockedActions, a => a == action.Type))return new() { Allowed = false, Reason = $"Action type '{action.Type}' is blocked in v1." };// Rule 2: must be inside working folderif (!FolderManager.IsInsideWorkingFolder(action.Target))return new() { Allowed = false, Reason = "Target is outside SAVA COMMAND working folder." };// Rule 3: blocked file extensionsvar ext = Path.GetExtension(action.Target).ToLowerInvariant();if (Array.Exists(BlockedExtensions, e => e == ext))return new() { Allowed = false, Reason = $"File extension '{ext}' is blocked." };// Rule 4: no adminif (action.RequiresAdmin)return new() { Allowed = false, Reason = "Admin elevation is blocked in v1." };// Rule 5: no networkif (action.RequiresNetwork)return new() { Allowed = false, Reason = "Network access is blocked in v1." };return new() { Allowed = true, Reason = "Passed all policy checks." };}}}// ============================================================// FILE: Core/Executor.cs// ============================================================using System.IO;namespace SavaCommand{public class Executor{private readonly Logger _logger;public Executor(Logger logger) => _logger = logger;public bool Execute(ActionItem action){try{switch (action.Type){case ActionType.WriteFile:File.WriteAllText(action.Target,$"# SAVA COMMAND Output\n# Action: {action.Id}\n# Time: {DateTime.UtcNow:o}\n\nAction completed successfully.");return true;case ActionType.CreateFolder:Directory.CreateDirectory(action.Target);return true;case ActionType.ReadFile:if (!File.Exists(action.Target)) return false;var content = File.ReadAllText(action.Target);_logger.Log($"[READ] {action.Id} | Length: {content.Length} chars");return true;case ActionType.ListFolder:if (!Directory.Exists(action.Target)) return false;var entries = Directory.GetFileSystemEntries(action.Target);_logger.Log($"[LIST] {action.Id} | {entries.Length} entries");return true;default:_logger.Log($"[BLOCKED] {action.Id} | Executor refused type: {action.Type}");return false;}}catch (Exception ex){_logger.Log($"[ERROR] {action.Id} | {ex.Message}");return false;}}}}// ============================================================// FILE: Core/Logger.cs// ============================================================using System.IO;namespace SavaCommand{public class Logger{private readonly string _logFile;public event Action<string>? OnLog;public Logger(){_logFile = FolderManager.GetPath("Logs", "operational.log");}public void Log(string message){var entry = $"{DateTime.UtcNow:o} | {message}";try{File.AppendAllText(_logFile, entry + Environment.NewLine);}catch { /* fail silent for log, don't crash app */ }OnLog?.Invoke(entry);}}}// ============================================================// FILE: Core/QueueManager.cs// ============================================================using System.IO;using System.Text.Json;namespace SavaCommand{public static class QueueManager{public static void SaveToQueue(ActionItem item)=> Save("Queue", item);public static void SaveToApproved(ActionItem item)=> Save("Approved", item);public static void SaveToQuarantine(ActionItem item)=> Save("Quarantine", item);public static void RemoveFromQueue(ActionItem item){var path = FolderManager.GetPath("Queue", $"{item.Id}.json");if (File.Exists(path)) File.Delete(path);}private static void Save(string folder, ActionItem item){var path = FolderManager.GetPath(folder, $"{item.Id}.json");var json = JsonSerializer.Serialize(item, new JsonSerializerOptions { WriteIndented = true });File.WriteAllText(path, json);}}}// ============================================================// SETUP INSTRUCTIONS// ============================================================// 1. Install .NET 8 SDK: https://dotnet.microsoft.com/download/dotnet/8.0// 2. Open terminal (cmd or PowerShell):// dotnet new wpf -n SavaCommand// cd SavaCommand// 3. Replace generated files with the code above:// - SavaCommand.csproj// - App.xaml + App.xaml.cs// - MainWindow.xaml + MainWindow.xaml.cs// - Create folder: Models/ → ActionItem.cs// - Create folder: Core/ → FolderManager.cs, PolicyEngine.cs,// Executor.cs, Logger.cs, QueueManager.cs// 4. Build:// dotnet build// 5. Run:// dotnet run//// WHAT HAPPENS:// - Creates C:\Users\<You>\SavaCommand\ with subfolders// - Shows approval UI// - Click "+ TEST ACTION" to simulate a proposed action// - Review details, click APPROVE or REJECT// - All actions logged to Logs\operational.log// - Blocked actions go to Quarantine\// - Nothing executes without your click// - Nothing touches anything outside SavaCommand folder// - No network, no admin, no scripts, no hidden tasks// ============================================================```
Made with care
Heirloom quality