static void service_CommandOpened(object sender, SessionRequestedArgs e) { Console.WriteLine("Channel {0} runs command: \"{1}\".", e.Channel.ServerChannelId, e.CommandText); var allow = true; // func(e.CommandText, e.AttachedUserauthArgs); if (!allow) { return; } var parser = new Regex(@"(?<cmd>git-receive-pack|git-upload-pack|git-upload-archive) \'/?(?<proj>.+)\.git\'"); var match = parser.Match(e.CommandText); var command = match.Groups["cmd"].Value; var project = match.Groups["proj"].Value; var git = new GitService(command, project); e.Channel.DataReceived += (ss, ee) => git.OnData(ee); e.Channel.CloseReceived += (ss, ee) => git.OnClose(); git.DataReceived += (ss, ee) => e.Channel.SendData(ee); git.CloseReceived += (ss, ee) => e.Channel.SendClose(ee); git.Start(); }
static void service_CommandOpened(object sender, CommandRequestedArgs e) { Console.WriteLine($"Channel {e.Channel.ServerChannelId} runs {e.ShellType}: \"{e.CommandText}\"."); var allow = true; // func(e.ShellType, e.CommandText, e.AttachedUserauthArgs); if (!allow) { return; } if (e.ShellType == "shell") { // requirements: Windows 10 RedStone 5, 1809 // also, you can call powershell.exe var terminal = new Terminal("cmd.exe", windowWidth, windowHeight); e.Channel.DataReceived += (ss, ee) => terminal.OnInput(ee); e.Channel.CloseReceived += (ss, ee) => terminal.OnClose(); terminal.DataReceived += (ss, ee) => e.Channel.SendData(ee); terminal.CloseReceived += (ss, ee) => e.Channel.SendClose(ee); terminal.Run(); } else if (e.ShellType == "exec") { var parser = new Regex(@"(?<cmd>git-receive-pack|git-upload-pack|git-upload-archive) \'/?(?<proj>.+)\.git\'"); var match = parser.Match(e.CommandText); var command = match.Groups["cmd"].Value; var project = match.Groups["proj"].Value; var git = new GitService(command, project); e.Channel.DataReceived += (ss, ee) => git.OnData(ee); e.Channel.CloseReceived += (ss, ee) => git.OnClose(); git.DataReceived += (ss, ee) => e.Channel.SendData(ee); git.CloseReceived += (ss, ee) => e.Channel.SendClose(ee); git.Start(); } else if (e.ShellType == "subsystem") { // do something more } }
static void service_CommandOpened(object sender, SessionRequestedArgs e) { Console.WriteLine("Channel {0} runs command: \"{1}\".", e.Channel.ServerChannelId, e.CommandText); var allow = true; // func(e.CommandText, e.AttachedUserauthArgs); if (!allow) return; var parser = new Regex(@"(?<cmd>git-receive-pack|git-upload-pack|git-upload-archive) \'/?(?<proj>.+)\.git\'"); var match = parser.Match(e.CommandText); var command = match.Groups["cmd"].Value; var project = match.Groups["proj"].Value; var git = new GitService(command, project); e.Channel.DataReceived += (ss, ee) => git.OnData(ee); e.Channel.CloseReceived += (ss, ee) => git.OnClose(); git.DataReceived += (ss, ee) => e.Channel.SendData(ee); git.CloseReceived += (ss, ee) => e.Channel.SendClose(ee); git.Start(); }