private void HandleMessage(ShellRequestMessage message) { var channel = FindChannelByServerId <SessionChannel>(message.RecipientChannel); _session.SendMessage(new ChannelSuccessMessage { RecipientChannel = channel.ClientChannelId }); if (CommandOpened != null) { var args = new SessionRequestedArgs(channel, message.RequestType, _auth); CommandOpened(this, args); } }
//private void HandleMessage(ShellRequestMessage message) //{ // var channel = FindChannelByServerId<SessionChannel>(message.RecipientChannel); // if (message.WantReply) // _session.SendMessage(new ChannelSuccessMessage { RecipientChannel = channel.ClientChannelId }); // CommandOpened?.Invoke(this, new CommandRequestedArgs(channel, "shell", null, _auth)); //} private void HandleMessage(SubsystemRequestMessage message) { var channel = FindChannelByServerId <SessionChannel>(message.RecipientChannel); if (message.WantReply) { _session.SendMessage(new ChannelSuccessMessage { RecipientChannel = channel.ClientChannelId }); } if (SessionRequest != null) { var args = new SessionRequestedArgs(channel, message.SubsystemName, "open", _auth); SessionRequest(this, args); } }
private void HandleMessage(ShellRequestMessage message) { var channel = this.FindChannelByServerId <SessionChannel>(message.RecipientChannel); if (message.WantReply) { this.Session.SendMessage(new ChannelSuccessMessage { RecipientChannel = channel.ClientChannelId }); } if (this.CommandOpened == null) { return; } var args = new SessionRequestedArgs(channel, "shell", this.auth); this.CommandOpened(this, args); }
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(); }