Exemple #1
0
        private void CommandOpened(object sender, SessionRequestedArgs e)
        {
            var match   = RegexParseCommand.Match(e.CommandText);
            var command = match.Groups["cmd"].Value;
            var project = match.Groups["proj"].Value;

            if (string.IsNullOrWhiteSpace(command) || string.IsNullOrWhiteSpace(project))
            {
                throw new SshConnectionException("Unexpected command.", DisconnectReason.ByApplication);
            }

            var requireWrite = command == "git-receive-pack";
            var fingerprint  = e.AttachedUserauthArgs.Fingerprint;
            var key          = Convert.ToBase64String(e.AttachedUserauthArgs.Key);
            var allow        = requireWrite
                ? _repositoryService.CanWriteRepository(project, fingerprint, key)
                : _repositoryService.CanReadRepository(project, fingerprint, key);

            if (!allow)
            {
                throw new SshConnectionException("Access denied.", DisconnectReason.ByApplication);
            }

            e.Channel.DataReceived  += DataReceived;
            e.Channel.EofReceived   += EofReceived;
            e.Channel.CloseReceived += CloseReceived;
            _channel = e.Channel;

            StartProcess(command, project);
        }
Exemple #2
0
        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();
        }
Exemple #3
0
        void service_CommandOpened(object sender, SessionRequestedArgs e)
        {
            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(
                    this.projectRootPath
                    , this.gitCommandsPath);
            var gitPipe = git.Exec(command, project);
            var sshPipe = new SshSettionPipe(e.Channel);

            gitPipe.OnData   += (bytes) => sshPipe.PushData(bytes);
            sshPipe.OnData   += (bytes) => gitPipe.PushData(bytes);
            gitPipe.EndEvent += code => sshPipe.EndData(code);
            sshPipe.EndEvent += code => gitPipe.EndData(code);

            Task.Run((Action)gitPipe.Start);
        }
Exemple #4
0
        void OnSessionRequestOpened(object sender, SessionRequestedArgs e)
        {
            _logger.LogInformation("Channel {0} requested session: \"{1}\".", e.Channel.ServerChannelId, e.CommandText);

            if (e.SubSystemName == "sftp")
            {
                InitializeSftp(e.Channel, e.AttachedUserAuthArgs.Username);
            }
            else
            {
                e.Channel.SendData(Encoding.UTF8.GetBytes($"You ran {e.CommandText}\n"));
                e.Channel.SendClose();
            }
        }
Exemple #5
0
 static void OnServiceCommandOpened(object sender, SessionRequestedArgs e)
 {
     Console.WriteLine("Channel {0} runs command: \"{1}\".", e.Channel.ServerChannelId, e.CommandText);
     e.Channel.SendData(Encoding.UTF8.GetBytes($"You ran {e.CommandText}\n"));
     e.Channel.SendClose();
 }
 static void ServiceCommandOpened(object sender, SessionRequestedArgs e)
 {
     Console.WriteLine("Channel {0} runs command: \"{1}\".", e.Channel.ServerChannelId, e.CommandText);
     //e.Channel.SendData(Encoding.ASCII.GetBytes(".]0;root@server: ~.root@server:~# "));
     e.Channel.DataReceived += ServiceDataReceived;
 }