public RESTStatus GetContractInfos(SQLLib sql, object dummy, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } CI = new ContractInfosList(); CI.Items = new List <ContractInfos>(); if (Settings.Default.UseContract == false) { return(RESTStatus.Success); } lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("select * from contracts order by ContractID"); while (dr.Read()) { ContractInfos i = new ContractInfos(); i.IncludedComputers = new List <ComputerData>(); sql.LoadIntoClass(dr, i); CI.Items.Add(i); } dr.Close(); } foreach (ContractInfos i in CI.Items) { List <string> Machines = new List <string>(); lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("select MachineID from ComputerAccounts where ContractID=@c", new SQLParam("@c", i.ContractID)); while (dr.Read()) { Machines.Add(Convert.ToString(dr["MachineID"])); } dr.Close(); } foreach (string M in Machines) { ComputerData c = Computers.GetComputerDetail(sql, M); i.IncludedComputers.Add(c); } } return(RESTStatus.Success); }
public RESTStatus ListUsers(SQLLib sql, object Dummy, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Fail); } UserLists = new UserDetailsList(); UserLists.List = new List <UserDetails>(); SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM Users ORDER BY Username"); while (dr.Read()) { UserDetails d = new UserDetails(); d.EMail = Convert.ToString(dr["EMail"]); d.LDAPUsername = Convert.ToString(dr["LDAPUsername"]); d.MustChangePassword = Convert.ToBoolean(dr["MustChangePassword"]); d.Name = Convert.ToString(dr["Name"]); d.Permissions = Convert.ToInt64(dr["Permissions"]); d.UseLDAP = Convert.ToBoolean(dr["UseLDAP"]); d.Username = Convert.ToString(dr["Username"]); UserLists.List.Add(d); } dr.Close(); return(RESTStatus.Success); }
public RESTStatus GetPendingChatMessages(SQLLib sql, object dummy, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ComputerLogin) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } string MachineID = ni.Username; ChatList2 = new PushChatMessageList(); ChatList2.List = new List <PushChatMessage>(); lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("select * from Chats where [Read]=0 AND MachineID=@m AND ToClient=1 ORDER BY DT ASC", new SQLParam("@m", MachineID)); while (dr.Read()) { PushChatMessage pch = new PushChatMessage(); pch.ID = Convert.ToInt64(dr["ID"]); pch.DT = SQLLib.GetDTUTC(dr["DT"]); pch.Name = Convert.ToString(dr["Name"]); pch.Text = Convert.ToString(dr["Text"]); ChatList2.List.Add(pch); } dr.Close(); } return(RESTStatus.Success); }
public RESTStatus GetFileDataMgmt(SQLLib sql, object dummy, NetworkConnectionInfo ni, Int64 ID) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("SELECT COUNT(*) FROM FileTransfers WHERE ID=@id", new SQLParam("@id", ID)); if (dr.HasRows == false) { ni.Error = "Not found"; ni.ErrorID = ErrorFlags.InvalidID; dr.Close(); return(RESTStatus.NotFound); } dr.Read(); UploadedData2 = FillUploadData(dr); dr.Close(); } return(RESTStatus.Success); }
public RESTStatus GetFileList(SQLLib sql, object dummy, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ComputerLogin) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } Int64List = new NetInt64ListSigned(); Int64List.data = new NetInt64List2(); Int64List.data.data = new List <long>(); lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("SELECT ID FROM FileTransfers WHERE MachineID=@mid AND ((Size=ProgressSize AND Direction=0) OR (Direction=1)) ORDER BY RequestOnly ASC, ID ASC", new SQLParam("@mid", ni.Username)); while (dr.Read()) { Int64List.data.data.Add(Convert.ToInt64(dr["ID"])); } dr.Close(); } if (Certificates.Sign(Int64List, SettingsManager.Settings.UseCertificate) == false) { FoxEventLog.WriteEventLog("Cannot sign policy with Certificate " + SettingsManager.Settings.UseCertificate, System.Diagnostics.EventLogEntryType.Warning); ni.Error = "Cannot sign policy with Certificate " + SettingsManager.Settings.UseCertificate; ni.ErrorID = ErrorFlags.CannotSign; return(RESTStatus.ServerError); } return(RESTStatus.Success); }
public RESTStatus GetFullFileListMgmt(SQLLib sql, object dummy, NetworkConnectionInfo ni, string MachineID) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } FileUploadDataList = new FileUploadDataList(); FileUploadDataList.List = new List <FileUploadData>(); lock (ni.sqllock) { SqlDataReader dr; if (string.IsNullOrWhiteSpace(MachineID) == true) { if (Computers.MachineExists(sql, MachineID) == false) { ni.Error = "Invalid data"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Fail); } dr = sql.ExecSQLReader("SELECT * FROM FileTransfers WHERE MachineID=@mid ORDER BY ID", new SQLParam("@mid", MachineID)); } else { dr = sql.ExecSQLReader("SELECT * FROM FileTransfers ORDER BY ID"); } while (dr.Read()) { FileUploadDataList.List.Add(FillUploadData(dr)); } dr.Close(); } return(RESTStatus.Success); }
public RESTStatus GetPendingChatData(SQLLib sql, object dummy, NetworkConnectionInfo ni, string MachineID) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } ChatList = new PushChatMessageList(); ChatList.List = new List <PushChatMessage>(); List <Int64> IDs = new List <long>(); lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("select * from Chats where [Read]=0 AND MachineID=@m AND ToClient=0 ORDER BY DT ASC", new SQLParam("@m", MachineID)); while (dr.Read()) { IDs.Add(Convert.ToInt64(dr["ID"])); PushChatMessage pch = new PushChatMessage(); pch.ID = Convert.ToInt64(dr["ID"]); pch.DT = SQLLib.GetDTUTC(dr["DT"]); pch.Name = Convert.ToString(dr["Name"]); pch.Text = Convert.ToString(dr["Text"]); ChatList.List.Add(pch); } dr.Close(); } foreach (Int64 id in IDs) { lock (ni.sqllock) { sql.ExecSQL("UPDATE Chats SET [Read]=1 WHERE ID=@id", new SQLParam("@id", id)); } } return(RESTStatus.Success); }
public RESTStatus GetFileDataAny(SQLLib sql, object dummy, NetworkConnectionInfo ni, Int64 ID) { if (ni.HasAcl(ACLFlags.ComputerLogin) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM FileTransfers WHERE ID=@id AND MachineID=@mid AND Direction in (0,1)", new SQLParam("@mid", ni.Username), new SQLParam("@id", ID)); if (dr.HasRows == false) { ni.Error = "Not found"; ni.ErrorID = ErrorFlags.InvalidID; dr.Close(); return(RESTStatus.NotFound); } dr.Read(); UploadedData = new FileUploadDataSigned(); UploadedData.Data = FillUploadData(dr); dr.Close(); } if (Certificates.Sign(UploadedData, SettingsManager.Settings.UseCertificate) == false) { FoxEventLog.WriteEventLog("Cannot sign policy with Certificate " + SettingsManager.Settings.UseCertificate, System.Diagnostics.EventLogEntryType.Warning); ni.Error = "Cannot sign policy with Certificate " + SettingsManager.Settings.UseCertificate; ni.ErrorID = ErrorFlags.CannotSign; return(RESTStatus.ServerError); } return(RESTStatus.Success); }
public static void DeleteAllFiles(SQLLib sql, string MachineID) { SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM FileTransfers WHERE MachineID=@m", new SQLParam("@m", MachineID)); while (dr.Read()) { string Filename = Settings.Default.DataPath + Convert.ToString(dr["ServerFile"]); if (File.Exists(Filename) == true) { try { CommonUtilities.SpecialDeleteFile(Filename); } catch { } } } dr.Close(); sql.ExecSQL("DELETE FROM FileTransfers WHERE MachineID=@m", new SQLParam("@m", MachineID)); }
public RESTStatus GetPendingMachines(SQLLib sql, object dummy, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } GetPendingChats = new NetStringList(); GetPendingChats.Items = new List <string>(); lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("Select DISTINCT MachineID FROM Chats WHERE [Read]=0 AND ToClient=0"); while (dr.Read()) { GetPendingChats.Items.Add(Convert.ToString(dr["MachineID"])); } dr.Close(); } return(RESTStatus.Success); }
public RESTStatus ComputerLogin(SQLLib sql, RecoveryLogon logon, NetworkConnectionInfo ni, string IPAddress) { RD = new RecoveryData(); if (Fox_LicenseGenerator.SDCLicensing.ValidLicense == false) { RD.Worked = false; return(RESTStatus.Fail); } if (Fox_LicenseGenerator.SDCLicensing.TestExpiry() == false) { RD.Worked = false; return(RESTStatus.Fail); } if (string.IsNullOrWhiteSpace(logon.UCID) == true) { RD.Worked = false; return(RESTStatus.Fail); } if (Settings.Default.UseContract == true) { if (string.IsNullOrWhiteSpace(logon.ContractID) == true || string.IsNullOrWhiteSpace(logon.ContractPassword) == true) { RD.Worked = false; return(RESTStatus.Fail); } } string newID = NetworkConnection.NewSession(); ni = NetworkConnection.GetSession(newID); if (NetworkConnectionProcessor.InitNi(ni) == false) { NetworkConnection.DeleteSession(newID); RD.Worked = false; return(RESTStatus.ServerError); } sql = ni.sql; if (Settings.Default.UseContract == true) { if (Convert.ToInt32(sql.ExecSQLScalar("SELECT Count(*) FROM Contracts WHERE ContractID=@id AND ContractPassword=@pw AND Disabled=0", new SQLParam("@id", logon.ContractID), new SQLParam("@pw", logon.ContractPassword))) == 0) { NetworkConnection.DeleteSession(newID); RD.Worked = false; return(RESTStatus.Fail); } if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE ContractID=@id AND UCID=@u", new SQLParam("@id", logon.ContractID), new SQLParam("@u", logon.UCID))) == 0) { NetworkConnection.DeleteSession(newID); RD.Worked = false; return(RESTStatus.Fail); } } if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE UCID=@u", new SQLParam("@u", logon.UCID))) == 0) { NetworkConnection.DeleteSession(newID); RD.Worked = false; return(RESTStatus.Fail); } SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM ComputerAccounts WHERE UCID=@u", new SQLParam("@u", logon.UCID)); dr.Read(); string Check = Convert.ToString(dr["CPUName"]).Trim(); Check += Convert.ToString(dr["ComputerModel"]).Trim(); Check += Convert.ToString(dr["BIOS"]).Trim(); string MD5 = MD5Utilities.CalcMD5(Check); if (MD5.ToLower() != logon.MoreMachineHash.ToLower()) { dr.Close(); NetworkConnection.DeleteSession(newID); RD.Worked = false; return(RESTStatus.Fail); } RD.MachineID = Convert.ToString(dr["MachineID"]); RD.MachinePassword = Convert.ToString(dr["Password"]); RD.Worked = true; dr.Close(); NetworkConnection.DeleteSession(newID); return(RESTStatus.Success); }
public RESTStatus ListNetData(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } if (string.IsNullOrWhiteSpace(id) == true) { ni.Error = "Invalid data"; ni.ErrorID = ErrorFlags.InvalidData; return(RESTStatus.NotFound); } lock (ni.sqllock) { if (Computers.MachineExists(sql, id) == false) { ni.Error = "Invalid data"; ni.ErrorID = ErrorFlags.InvalidData; return(RESTStatus.NotFound); } } LstNetData = new ListNetworkAdapterConfiguration(); LstNetData.Items = new List <NetworkAdapterConfiguration>(); LstNetData.MachineID = id; lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM networkconfig WHERE MachineID=@mid", new SQLParam("@mid", id)); while (dr.Read()) { NetworkAdapterConfiguration n = new NetworkAdapterConfiguration(); sql.LoadIntoClass(dr, n); LstNetData.Items.Add(n); } dr.Close(); } foreach (NetworkAdapterConfiguration n in LstNetData.Items) { n.IPAddress = new List <string>(); n.IPSubnet = new List <string>(); n.DefaultIPGateway = new List <string>(); n.DNSDomainSuffixSearchOrder = new List <string>(); n.DNSServerSearchOrder = new List <string>(); lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("select * from NetworkConfigSuppl WHERE MachineID=@mid AND InterfaceIndex=@i order by Type,[Order]", new SQLParam("@mid", id), new SQLParam("@i", n.InterfaceIndex)); while (dr.Read()) { switch (Convert.ToInt32(dr["Type"])) { case 1: n.IPAddress.Add(Convert.ToString(dr["Data"])); break; case 2: n.IPSubnet.Add(Convert.ToString(dr["Data"])); break; case 3: n.DefaultIPGateway.Add(Convert.ToString(dr["Data"])); break; case 4: n.DNSDomainSuffixSearchOrder.Add(Convert.ToString(dr["Data"])); break; case 5: n.DNSServerSearchOrder.Add(Convert.ToString(dr["Data"])); break; } } dr.Close(); } } return(RESTStatus.Success); }