Пример #1
0
        internal RConSession(RConCredentials creds, TimeSpan timeout)
        {
            Credentials = creds;
            StartedTime = LastMessageTime = DateTime.UtcNow;
            Timeout = timeout;

            var bytes = new byte[32];
            _sRng.GetBytes(bytes);

            Secret = Convert.ToBase64String(bytes);
        }
Пример #2
0
        protected override void OnMessage(String action, JToken data)
        {
            switch (action) {
                case "auth": {
                    var name = (String) data["name"];
                    var password = (String) data["password"];

                    var creds = new RConCredentials(Context.UserEndPoint.Address, name, password);
                    var session = Server.TryCreateSession(creds);

                    Send("auth_response", session.ToJObject());
                    return;
                }
                case "exec": {
                    var session = Server.TryGetSession(Context.UserEndPoint.Address, data["session"] as JObject);
                    if (session == null) throw new AuthenticationException("Invalid session");

                    var response = Server.ExecuteCommandInternal(session.Credentials, (String) data["command"]);

                    Send("exec_response", response);
                    return;
                }
            }
        }
Пример #3
0
        internal RConSession TryCreateSession(RConCredentials creds)
        {
            if (VerifyCredentials == null || !VerifyCredentials(creds)) {
                throw new AuthenticationException("Invalid credentials");
            }

            var session = new RConSession(creds, SessionTimeout);

            if (_sessions.ContainsKey(creds.Name)) {
                _sessions[creds.Name] = session;
            } else {
                _sessions.Add(creds.Name, session);
            }

            return session;
        }
Пример #4
0
 internal String ExecuteCommandInternal(RConCredentials creds, String command)
 {
     return ExecuteCommand != null ? ExecuteCommand(creds, command) : "";
 }