예제 #1
0
        public static AuthResult Authorize(AuthData data)
        {
            Keys keys = GetKeys();
            if (keys != null && keys.Public.Equals(data.PublicKey))
            {
                var privateKey = keys.Private;
                var hashCheck = General.Sha1Hash(data.Data + privateKey + data.PublicKey);
                if (hashCheck.Equals(data.Hash))
                {
                    var newToken = General.Sha1Hash(privateKey + hashCheck + GetDateTimeFormatted());
                    var computersJsonFile = GetFile("~/App_Data/", "computers.json");
                    var computers = new List<ComputerData>();
                    try
                    {
                        computers = JsonConvert.DeserializeObject<List<ComputerData>>(GetFileContents(computersJsonFile));
                    }
                    catch { }

                    var computerData = new ComputerData()
                    {
                        Name = data.HostName,
                        IpExternal = data.IpExternal,
                        IpInternal = data.IpInternal,
                        LastActive = DateTime.Now,
                        FileUploaded = null,
                        BytesUploaded = 0,
                        Hash = null
                    };
                    computerData.Hash = Transmitter.GetComputerHash(computerData);
                    if (computers.Where(c => c.Hash == computerData.Hash).FirstOrDefault() == null)
                    {
                        computers.Add(computerData);
                    }

                    var computersJson = JsonConvert.SerializeObject(computers);
                    File.WriteAllText(computersJsonFile, computersJson);

                    return new AuthResult()
                    {
                        Token = newToken,
                        IpExternal = data.IpExternal
                    };
                }
            }
            return null;
        }
 public HttpResponseMessage GetDateTime(AuthData data)
 {
     return Request.GetResponse(RhsApi.GetDateTimeFormatted(), responseType);
 }
 public HttpResponseMessage UpdateLastActive(AuthData data)
 {
     return Request.GetResponse(RhsApi.UpdateLastActive(data), responseType);
 }
 public HttpResponseMessage DeAuthorize(AuthData data)
 {
     return Request.GetResponse(RhsApi.DeAuthorize(data), responseType);
 }
 public HttpResponseMessage Authorize(AuthData data)
 {
     return Request.GetResponse<AuthResult>(RhsApi.Authorize(data), responseType);
 }
예제 #6
0
 public static bool UpdateLastActive(AuthData data)
 {
     Keys keys = GetKeys();
     if (keys != null && keys.Public.Equals(data.PublicKey))
     {
         var privateKey = keys.Private;
         var hashCheck = General.Sha1Hash(data.Data + privateKey + data.PublicKey);
         if (hashCheck.Equals(data.Hash))
         {
             //var newToken = General.Sha1Hash(privateKey + hashCheck + GetDateTimeFormatted());
             var computersJsonFile = GetFile("~/App_Data/", "computers.json");
             var computers = new List<ComputerData>();
             try
             {
                 computers = JsonConvert.DeserializeObject<List<ComputerData>>(GetFileContents(computersJsonFile));
             }
             catch { }
             var computerData = new ComputerData()
             {
                 Name = data.HostName,
                 IpExternal = data.IpExternal,
                 IpInternal = data.IpInternal,
                 LastActive = DateTime.Now,
                 FileUploaded = null,
                 BytesUploaded = 0,
                 Hash = null
             };
             computerData.Hash = Transmitter.GetComputerHash(computerData);
             var computer = computers.Find(c => c.Hash == computerData.Hash);
             if(computer != null) 
             {
                 computer.LastActive = DateTime.Now;
             }
             var computersJson = JsonConvert.SerializeObject(computers);
             System.Threading.Thread.Sleep(250);
             File.WriteAllText(computersJsonFile, computersJson);
             return true;
         }
     }
     return false;
 }