public static string CompareSections(TcpClient clientSocket, string data) { Token AuthToken; string Token; string ServerResponse; if (Request.Contains("Token", data)) { Token = Request.Get("Token", data); //Get Token by Token -> Get Token by IP Address -> Compare Returned Tokens if (Tokens.GetTokenByToken(Token) != null && Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString()) != null && Tokens.GetTokenByToken(Token) == Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString())) { AuthToken = Tokens.GetTokenByToken(Token); ServerResponse = "Not Implemented"; } else { ServerResponse = "Authentication Token not found"; } } else { ServerResponse = "Token Parameter was not provided"; } return(ServerResponse); }
/// <summary> /// Calls UploadFile ( Upload to Client ) /// </summary> /// <param name="clientSocket"></param> /// <param name="data"></param> /// <returns></returns> public static string Files(TcpClient clientSocket, string data) { Token AuthToken; string Token; string ServerResponse = null; if (Request.Contains("Token", data)) { Token = Request.Get("Token", data); //Get Token by Token -> Get Token by IP Address -> Compare Returned Tokens if (Tokens.GetTokenByToken(Token) != null && Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString()) != null && Tokens.GetTokenByToken(Token) == Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString())) { AuthToken = Tokens.GetTokenByToken(Token); //Root of the Sync Path foreach (string file in GetFiles(ClensePath.CleanPath(AuthToken))) { //SyncPath = Folder Name of the Sync Folder //C:\\Server\\CrispyCheats\\MaverickCloud1\\File.txt -> Replace("C:\\Server\\CrispyCheats") = \\MaverickCloud1\\File.txt string SyncPath = file.Replace(ClensePath.CleanPath(AuthToken), "").Replace(new FileInfo(file).Name, "").Replace(@"\", ""); Console.WriteLine("Clean Path: " + ClensePath.CleanPath(AuthToken, SyncPath) + " File Path: " + file); string RelevantPath = file.Replace(ClensePath.CleanPath(AuthToken, SyncPath), "").Replace(new FileInfo(file).Name, ""); string FileName = new FileInfo(file).Name; Console.WriteLine("File Info: SyncPath={0}, RelevantPath={1}, FileName={2}", SyncPath, RelevantPath, FileName); } ServerResponse = "Files Retrieved"; } else { ServerResponse = "Authentication Token not found"; } } else { ServerResponse = "Token Parameter was not provided"; } return(ServerResponse); }
public static string Delete(TcpClient clientSocket, string data) { Token AuthToken; string Token; string SyncPath; string RelevantPath; string FileName; bool Folder; string ServerResponse; if (Request.Contains("Token", data)) { Token = Request.Get("Token", data); //Get Token by Token -> Get Token by IP Address -> Compare Returned Tokens if (Tokens.GetTokenByToken(Token) != null && Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString()) != null && Tokens.GetTokenByToken(Token) == Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString())) { AuthToken = Tokens.GetTokenByToken(Token); if (Request.Contains("SyncPath", data)) { SyncPath = Request.Get("SyncPath", data); if (Request.Contains("RelevantPath", data)) { RelevantPath = Request.Get("RelevantPath", data); if (Request.Contains("FileName", data)) { FileName = Request.Get("FileName", data); if (Request.Contains("Folder", data)) { Folder = Request.Get("Folder", data) == "true" ? true : false; } else { Folder = false; } string CleanPath = ClensePath.CleanPath(AuthToken, SyncPath, RelevantPath); //Return True ( File Renamed ) or False ( File Failed to Rename ) ServerResponse = CloudFunctions.DeleteFile(CleanPath, FileName, Folder) ? "File Deleted" : "File Failed to be Deleted"; } else { ServerResponse = "FileName Parameter was not provided"; } } else { ServerResponse = "RelevantPath Parameter was not provided"; } } else { ServerResponse = "SyncPath Parameter was not provided"; } } else { ServerResponse = "Authentication Token not found"; } } else { ServerResponse = "Token parameter was not provided"; } return(ServerResponse); }
//Database -> Grab Properties -> Compare Cached Properties //Return True == (Client has a good file) || False == (Server has the better file) public static string CompareProperties(TcpClient clientSocket, string data) { Token AuthToken; string Token; //File Properties string Size; //Size Hash string Created; //Created Hash string LastModified; //Last Modified //File Path string SyncPath; string RelevantPath; string FileName; string ServerResponse; if (Request.Contains("Token", data)) { Token = Request.Get("Token", data); //Get Token by Token -> Get Token by IP Address -> Compare Returned Tokens if (Tokens.GetTokenByToken(Token) != null && Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString()) != null && Tokens.GetTokenByToken(Token) == Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString())) { AuthToken = Tokens.GetTokenByToken(Token); if (Request.Contains("Size", data)) { Size = Request.Get("Size", data); if (Request.Contains("Created", data)) { Created = Request.Get("Created", data); if (Request.Contains("SyncPath", data)) { SyncPath = Request.Get("SyncPath", data); if (Request.Contains("LastModified", data)) { LastModified = Request.Get("LastModified", data); if (Request.Contains("RelevantPath", data)) { RelevantPath = Request.Get("RelevantPath", data); if (Request.Contains("FileName", data)) { FileName = Request.Get("FileName", data); string FullPath = ClensePath.CleanPath(AuthToken, SyncPath, RelevantPath) + FileName; if (Convert.ToInt64(Size) != new FileInfo(FullPath).Length) { ServerResponse = "Size Different"; } else if (Convert.ToInt64(Created) != File.GetCreationTimeUtc(FullPath).ToBinary()) { ServerResponse = "Created Different"; } else if (Convert.ToInt64(LastModified) != File.GetLastWriteTimeUtc(FullPath).ToBinary()) { ServerResponse = "LastModified Different"; } else { ServerResponse = "Same"; } } else { ServerResponse = "FileName Parameter was not provided"; } } else { ServerResponse = "RelevantPath Parameter was not provided"; } } else { ServerResponse = "LastModified Parameter was not provided"; } } else { ServerResponse = "SyncPath Parameter was not provided"; } } else { ServerResponse = "Created Parameter was not provided"; } } else { ServerResponse = "Size Parameter was not provided"; } } else { ServerResponse = "Authentication Token not found"; } } else { ServerResponse = "Token Parameter was not provided"; } return(ServerResponse); }
public static string Create(TcpClient clientSocket, string data) { Token AuthToken; string Token, SyncPath, RelevantPath, FileName; string ServerResponse = null; if (Request.Contains("Token", data)) { Token = Request.Get("Token", data); //Get Token by Token -> Get Token by IP Address -> Compare Returned Tokens if (Tokens.GetTokenByToken(Token) != null && Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString()) != null && Tokens.GetTokenByToken(Token) == Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString())) { AuthToken = Tokens.GetTokenByToken(Token); if (Request.Contains("SyncPath", data)) { SyncPath = Request.Get("SyncPath", data); if (Request.Contains("RelevantPath", data)) { RelevantPath = Request.Get("RelevantPath", data); if (Request.Contains("FileName", data)) { FileName = Request.Get("FileName", data); string FullPath = ClensePath.CleanPath(AuthToken, SyncPath, RelevantPath) + FileName; Console.WriteLine("Creating Folder: " + FullPath); if (!Directory.Exists(FullPath)) { Directory.CreateDirectory(FullPath); ServerResponse = "Folder Created"; } else { ServerResponse = "Folder Exists"; } } else { ServerResponse = "FileName Parameter was not provided"; } } else { ServerResponse = "RelevantPath Parameter was not provided"; } } else { ServerResponse = "SyncPath Parameter was not provided"; } } else { ServerResponse = "Authentication Token not found"; } } else { ServerResponse = "Token Parameter was not provided"; } return(ServerResponse); }
/// <summary> /// Calls UploadFile ( Upload to Client ) /// </summary> /// <param name="clientSocket"></param> /// <param name="data"></param> /// <returns></returns> public static string UploadFile(TcpClient clientSocket, string data) { Token AuthToken; string Token; string SyncPath; string RelevantPath; string FileName; string ServerResponse = null; if (Request.Contains("Token", data)) { Token = Request.Get("Token", data); //Get Token by Token -> Get Token by IP Address -> Compare Returned Tokens if (Tokens.GetTokenByToken(Token) != null && Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString()) != null && Tokens.GetTokenByToken(Token) == Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString())) { AuthToken = Tokens.GetTokenByToken(Token); if (Request.Contains("SyncPath", data)) { SyncPath = Request.Get("SyncPath", data); if (Request.Contains("RelevantPath", data)) { RelevantPath = Request.Get("RelevantPath", data); if (Request.Contains("FileName", data)) { FileName = Request.Get("FileName", data); string FullPath = ClensePath.CleanPath(AuthToken, SyncPath, RelevantPath); if (UploadFile(clientSocket.GetStream(), FullPath, FileName, new FileInfo(FullPath + FileName).Length)) { ServerResponse = "Created=" + File.GetCreationTimeUtc(FullPath + FileName).ToBinary() + "&LastModified=" + File.GetLastWriteTimeUtc(FullPath + FileName).ToBinary() + "&Status=File Upload Completed"; } else { ServerResponse = "File Upload Failed"; } } else { ServerResponse = "FileName Parameter was not provided"; } } else { ServerResponse = "RelevantPath Parameter was not provided"; } } else { ServerResponse = "SyncPath Parameter was not provided"; } } else { ServerResponse = "Authentication Token not found"; } } else { ServerResponse = "Token Parameter was not provided"; } return(ServerResponse); }
/// <summary> /// Calls DownloadFile ( Download from Client ) /// </summary> /// <param name="clientSocket"></param> /// <param name="data"></param> /// <returns></returns> public static string DownloadFile(TcpClient clientSocket, string data) { Token AuthToken; string Token, SyncPath, RelevantPath, FileName, Created, LastModified, Size; string ServerResponse = null; if (Request.Contains("Token", data)) { Token = Request.Get("Token", data); //Get Token by Token -> Get Token by IP Address -> Compare Returned Tokens if (Tokens.GetTokenByToken(Token) != null && Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString()) != null && Tokens.GetTokenByToken(Token) == Tokens.GetToken(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString())) { AuthToken = Tokens.GetTokenByToken(Token); if (Request.Contains("SyncPath", data)) { SyncPath = Request.Get("SyncPath", data); if (Request.Contains("RelevantPath", data)) { RelevantPath = Request.Get("RelevantPath", data); if (Request.Contains("FileName", data)) { FileName = Request.Get("FileName", data); if (Request.Contains("Created", data)) { Created = Request.Get("Created", data); if (Request.Contains("LastModified", data)) { LastModified = Request.Get("LastModified", data); if (Request.Contains("Size", data)) { Size = Request.Get("Size", data); //Server Files -> User Folder -> SyncPath Folder -> Files if (!Directory.Exists(ClensePath.CleanPath(AuthToken, SyncPath, ""))) { Directory.CreateDirectory(ClensePath.CleanPath(AuthToken, SyncPath, "")); } string FullPath = ClensePath.CleanPath(AuthToken, SyncPath, RelevantPath); if (File.Exists(FullPath + FileName)) { try { File.Delete(FullPath + FileName); } catch { Console.WriteLine("File Deletion Failed!"); } } if (DownloadFile(clientSocket.GetStream(), FullPath, FileName, Convert.ToInt64(Size))) { File.SetCreationTimeUtc(FullPath + FileName, DateTime.FromBinary(Convert.ToInt64(Created))); File.SetLastWriteTimeUtc(FullPath + FileName, DateTime.FromBinary(Convert.ToInt64(LastModified))); ServerResponse = "File Download Completed"; } else { ServerResponse = "File Download Failed"; } } else { ServerResponse = "Size Parameter not found"; } } else { ServerResponse = "LastModified Parameter not found"; } } else { ServerResponse = "Created Parameter not found"; } } else { ServerResponse = "FileName Parameter was not provided"; } } else { ServerResponse = "RelevantPath Parameter was not provided"; } } else { ServerResponse = "SyncPath Parameter was not provided"; } } else { ServerResponse = "Authentication Token not found"; } } else { ServerResponse = "Token Parameter was not provided"; } return(ServerResponse); }