cscg24-photoeditor

CSCG 2024 Challenge 'PhotoEditor'
git clone https://git.sinitax.com/sinitax/cscg24-photoeditor
Log | Files | Refs | sfeed.txt

BaseAPIController.cs (1010B)


      1using System.Diagnostics;
      2using Microsoft.AspNetCore.Mvc;
      3using PhotoEditor.Models;
      4
      5namespace PhotoEditor.Controllers;
      6
      7public class BaseAPIController : ControllerBase
      8{
      9    public String GetUsername(Dictionary<String,String> env) {
     10        Process process = new Process();
     11        process.StartInfo.FileName = "bash";
     12        process.StartInfo.Arguments = "-c 'whoami'";
     13        
     14        foreach (var kv in env)
     15        {
     16            Console.WriteLine(kv.Key + ":" + kv.Value);
     17            process.StartInfo.EnvironmentVariables[kv.Key] = kv.Value;
     18        }
     19        
     20        process.StartInfo.UseShellExecute = false;
     21        process.StartInfo.RedirectStandardOutput = true;
     22        process.StartInfo.RedirectStandardError = true;
     23        process.Start();
     24        string output = process.StandardOutput.ReadToEnd();
     25        Console.WriteLine(output);
     26        string err = process.StandardError.ReadToEnd();
     27        Console.WriteLine(err);
     28        process.WaitForExit();
     29
     30        return output + err;
     31    }
     32}