Beispiel #1
0
        public MeshCentralTcpTunnel(MeshCentralAgent parent, Uri uri, string serverHash, Dictionary <string, object> creationArgs, string tcpaddr, int tcpport)
        {
            //Console.WriteLine("MeshCentralTcpTunnel(" + tcpaddr + ":" + tcpport + ")");
            this.parent               = parent;
            this.tcpaddr              = tcpaddr;
            this.tcpport              = tcpport;
            this.creationArgs         = creationArgs;
            WebSocket                 = new webSocketClient();
            WebSocket.pongTimeSeconds = 120; // Send a websocket pong every 2 minutes.
            WebSocket.onStateChanged += WebSocket_onStateChanged;
            WebSocket.onBinaryData   += WebSocket_onBinaryData;
            WebSocket.onStringData   += WebSocket_onStringData;
            WebSocket.onSendOk       += WebSocket_onSendOk;
            WebSocket.TLSCertCheck    = webSocketClient.TLSCertificateCheck.Fingerprint;
            WebSocket.Start(uri, serverHash, null);

            // Setup extra log values
            if (creationArgs != null)
            {
                if (creationArgs.ContainsKey("userid") && (creationArgs["userid"].GetType() == typeof(string)))
                {
                    extraLogStr += ",\"userid\":\"" + escapeJsonString((string)creationArgs["userid"]) + "\""; userid = (string)creationArgs["userid"];
                }
                if (creationArgs.ContainsKey("username") && (creationArgs["username"].GetType() == typeof(string)))
                {
                    extraLogStr += ",\"username\":\"" + escapeJsonString((string)creationArgs["username"]) + "\"";
                }
                if (creationArgs.ContainsKey("guestname") && (creationArgs["guestname"].GetType() == typeof(string)))
                {
                    extraLogStr += ",\"guestname\":\"" + escapeJsonString((string)creationArgs["guestname"]) + "\""; guestname = (string)creationArgs["guestname"];
                }
                if (creationArgs.ContainsKey("remoteaddr") && (creationArgs["remoteaddr"].GetType() == typeof(string)))
                {
                    extraLogStr += ",\"remoteaddr\":\"" + escapeJsonString((string)creationArgs["remoteaddr"]) + "\"";
                }
                if (creationArgs.ContainsKey("sessionid") && (creationArgs["sessionid"].GetType() == typeof(string)))
                {
                    extraLogStr += ",\"sessionid\":\"" + escapeJsonString((string)creationArgs["sessionid"]) + "\"";
                }
                if (creationArgs.ContainsKey("rights") && ((creationArgs["rights"].GetType() == typeof(System.Int32)) || (creationArgs["rights"].GetType() == typeof(System.Int64))))
                {
                    userRights = (long)creationArgs["rights"];
                }
            }
        }
Beispiel #2
0
        private void WebSocket_onStringData(webSocketClient sender, string data, int orglen)
        {
            if (state == 0) // Waitting for browser connection
            {
                if (data.Equals("c") || data.Equals("cr"))
                {
                    state = 1; connectedToServer();
                }

                // Add this session
                if (creationArgs != null)
                {
                    //if (creationArgs.ContainsKey("username") && (creationArgs["username"].GetType() == typeof(string))) { sessionUserName = (string)creationArgs["username"]; }
                    //if (creationArgs.ContainsKey("realname") && (creationArgs["realname"].GetType() == typeof(string))) { sessionUserName = (string)creationArgs["realname"]; }

                    if (creationArgs.ContainsKey("userid") && (creationArgs["userid"].GetType() == typeof(string)))
                    {
                        sessionLoggingUserName = sessionUserName = (string)creationArgs["userid"];
                        if (creationArgs.ContainsKey("guestname") && (creationArgs["guestname"].GetType() == typeof(string)))
                        {
                            sessionUserName        += "/guest:" + Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes((string)creationArgs["guestname"]));
                            sessionLoggingUserName += " - " + (string)creationArgs["guestname"];
                        }
                    }

                    if (sessionUserName != null)
                    {
                        if (parent.TcpSessions == null)
                        {
                            parent.TcpSessions = new Dictionary <string, object>();
                        }
                        if (parent.TcpSessions.ContainsKey(sessionUserName))
                        {
                            parent.TcpSessions[sessionUserName] = (int)parent.TcpSessions[sessionUserName] + 1;
                        }
                        else
                        {
                            parent.TcpSessions[sessionUserName] = 1;
                        }
                        parent.fireSessionChanged(9);
                    }
                }
            }
        }