Esempio n. 1
0
 internal string GetSessionName()
 {
     return((IsAuthorized ? User.Name : "__not_auth") + "[" + SessionID.Substring(0, 5) + "]");
 }
Esempio n. 2
0
 public void HandleConnectionType(dynamic JsonData)
 {
     try
     {
         ConnectionType = Enum.Parse(typeof(ConnectionTypes), JsonData.ConnectionType.ToString());
         if (ConnectionType == ConnectionTypes.ClientApp || ConnectionType == ConnectionTypes.ViewerApp)
         {
             if (!String.IsNullOrWhiteSpace(JsonData.ComputerName))
             {
                 ComputerName = JsonData.ComputerName.ToString().Trim().ToLower();
             }
             var sessionID = SessionID.Substring(0, 3) + " " + SessionID.Substring(3, 3);
             var request   = new
             {
                 Type      = "SessionID",
                 SessionID = sessionID
             };
             Send(Json.Encode(request));
         }
         else if (ConnectionType == ConnectionTypes.ClientConsole)
         {
             ComputerName = JsonData.ComputerName.ToString().Trim().ToLower();
         }
         else if (ConnectionType == ConnectionTypes.ClientService)
         {
             var client = SocketCollection.Find(sock => (sock as Remote_Control).ComputerName == JsonData.ComputerName);
             if (client != null)
             {
                 JsonData.Status = "ServiceDuplicate";
                 Send(Json.Encode(JsonData));
                 SocketCollection.Remove(this);
                 var filePath = Path.Combine(Utilities.App_Data, "Logs", "Alerts", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString().PadLeft(2, '0'), DateTime.Now.Day.ToString().PadLeft(2, '0') + ".txt");
                 if (!Directory.Exists(Path.GetDirectoryName(filePath)))
                 {
                     Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                 }
                 var entry = new
                 {
                     Timestamp    = DateTime.Now.ToString(),
                     Message      = "The service may be running on two computers that have the same name.",
                     ComputerName = JsonData.ComputerName.ToString().Trim(),
                     IPAddress    = WebSocketContext.UserHostAddress
                 };
                 File.AppendAllText(filePath, Json.Encode(entry) + Environment.NewLine);
             }
             ComputerName = JsonData.ComputerName.ToString().Trim().ToLower();
             CurrentUser  = JsonData?.CurrentUser?.ToString()?.Trim()?.ToLower() ?? "";
             if (JsonData.LastReboot != null)
             {
                 LastReboot = JsonData.LastReboot;
             }
             Load();
             Save();
         }
         else if (ConnectionType == ConnectionTypes.ClientServiceOnce)
         {
             ComputerName = JsonData.ComputerName.ToString().Trim().ToLower();
         }
         else if (ConnectionType == ConnectionTypes.ClientConsoleOnce)
         {
             ComputerName = JsonData.ComputerName.ToString().Trim().ToLower();
         }
         LogConnection();
     }
     catch (Exception ex)
     {
         Utilities.WriteToLog(ex);
     }
 }