private void HandleLog(int mode) { SQLiteClass sql = new SQLiteClass(ProgramFilesx86() + "\\DuckServer\\Information.dat"); MSSQL msl; if (!Service.shouldIBeRunning) { Console.WriteLine("This server instance should not be handling requests now."); } switch (mode) { case IM_Event: if (Service.shouldIBeRunning) { String eventString = br.ReadString(); Events ev = DeserializeXMLFileToObject <Events>(eventString); sql.CloseCon(); msl = new MSSQL(); msl.AddEvent(ev); bw.Write(IM_OK); } else { bw.Write(IM_Bad_Credentials); } break; case IM_NewVersions: if (Service.shouldIBeRunning) { IMClient imc = new IMClient(); imc.setConnParams(GetOriginIP(), 25567); imc.SetupConn(); imc.SendSignal(IM_NewVersions, Service.DoSerialize(new DateTimeVersions { ServiceVersion = sql.GetServices(), WhitelistVersion = sql.GetWhitelists(), ServiceDateTime = sql.GetLastUpdated(SQLiteClass.GET_SERVICE_LIST), WhitelistDateTime = sql.GetLastUpdated(SQLiteClass.GET_WHITELIST_LIST) })); bw.Write(IM_OK); } else { bw.Write(IM_Bad_Credentials); } break; case IM_AddDatabases: sql.AddDatabase(new DatabaseObject(br.ReadString(), br.ReadInt32())); bw.Write(IM_OK); break; case IM_GetDatabases: List <DatabaseObject> dbos = sql.GetConnections(); foreach (DatabaseObject dbo in dbos) { bw.Write(dbo.ConnectionString); bw.Write(dbo.Preference); } bw.Write(IM_OK); sql.CloseCon(); break; case IM_NewDatabases: List <DatabaseObject> dbs = DeserializeXMLFileToObject <List <DatabaseObject> >(br.ReadString()); sql.NewConnections(dbs); sql.CloseCon(); break; case IM_NewServiceList: List <ServicesObject> sros = DeserializeXMLFileToObject <List <ServicesObject> >(br.ReadString()); sql.NewServices(sros); sql.CloseCon(); //Port scan //Broadcast break; case IM_NewWhitelists: List <Whitelists> wls = DeserializeXMLFileToObject <List <Whitelists> >(br.ReadString()); sql.NewWhitelists(wls); sql.CloseCon(); break; case IM_AddWhiteList: break; case IM_RemoveWhitelist: break; case IM_Debug: Console.WriteLine(br.ReadString()); break; case IM_Diagnostic: if (!Service.shouldIBeRunning) { bw.Write(IM_Bad_Credentials); } else { bw.Write(IM_OK); } break; default: break; } bw.Write(IM_OK); }
private static void RoutineCheck() { if (!MSSQL.ConnectionsExist()) { Console.WriteLine("No database connections configured"); return; } if (shouldIBeRunning && !runningScan) { runningScan = true; Console.WriteLine("Getting active hosts"); List <GUIDMACVersionIP> gmvis = GetActiveHosts(); Console.WriteLine(gmvis.Count + " running clients"); MSSQL ms = new MSSQL(); List <KnownHost> khs = ms.GetKnownHosts(); foreach (GUIDMACVersionIP gmvi in gmvis) { bool found = false; foreach (KnownHost kh in khs) { bool change = false; if (kh.GUID.Trim().ToUpper().Equals(gmvi.GUID.Trim().ToUpper())) { found = true; if (!kh.hostMAC.Trim().ToUpper().Equals(gmvi.MAC.Trim().ToUpper())) { ms.AddEvent(new Events("HOST010", "MAC Address changed to " + gmvi.MAC, 2, gmvi.IP, gmvi.GUID, DateTime.Now)); kh.hostMAC = gmvi.MAC; change = true; } if (!kh.version.Trim().ToUpper().Equals(gmvi.Version.Trim().ToUpper())) { ms.AddEvent(new Events("HOST020", "Version changed to " + gmvi.Version, 1, gmvi.IP, gmvi.GUID, DateTime.Now)); kh.version = gmvi.Version; change = true; } if (!kh.hostIP.Trim().ToUpper().Equals(gmvi.IP.Trim().ToUpper())) { Console.WriteLine(kh.hostIP.Trim().ToUpper() + " " + gmvi.IP.Trim().ToUpper()); ms.AddEvent(new Events("HOST030", "IP Changed to " + gmvi.IP, 1, gmvi.IP, gmvi.GUID, DateTime.Now)); kh.hostIP = gmvi.IP; change = true; } if (change) { ms.UpdateHost(kh); } break; } } if (!found) { try { Console.WriteLine("New host " + gmvi.GUID); IMClient imc = new IMClient(); imc.setConnParams(gmvi.IP, 25567); imc.SetupConn(); imc.SendSignal(ServiceConn.IM_RegistrationDone, gmvi.GUID); imc.Disconnect(); ms.AddEvent(new Events("HOST100", "New host added", 2, gmvi.IP, gmvi.GUID, DateTime.Now)); ms.AddKnownHost(new KnownHost(gmvi.MAC, gmvi.IP, gmvi.Version, DateTime.Now, gmvi.GUID, gmvi.Hostname)); } catch { } } } runningScan = false; //Version broadcast ms.GetWhitelists(); SQLiteClass sql = new SQLiteClass(SQLiteClass.ProgramFilesx86() + "\\DuckServer\\Information.dat"); sql.NewServices(ms.GetServices()); sql.SetLastUpdated(SQLiteClass.GET_SERVICE_LIST, ms.GetLastUpdated(SQLiteClass.GET_SERVICE_LIST)); sql.NewWhitelists(ms.GetWhitelists()); sql.SetLastUpdated(SQLiteClass.GET_WHITELIST_LIST, ms.GetLastUpdated(SQLiteClass.GET_WHITELIST_LIST)); DateTime serviceTime = sql.GetLastUpdated(SQLiteClass.GET_SERVICE_LIST); DateTime whitelistTime = sql.GetLastUpdated(SQLiteClass.GET_WHITELIST_LIST); foreach (GUIDMACVersionIP gmvi in gmvis) { IMClient imclient = new IMClient(); imclient.setConnParams(gmvi.IP, 25567); Thread th = new Thread(() => SendNewDataVersion(imclient, serviceTime, whitelistTime)); th.Start(); } } shouldIBeRunning = ServiceConcurrencyCheck(); Console.WriteLine("The service concurrency check returns that I should be running: " + shouldIBeRunning); }
private void HandleLog(int mode) { SQLiteClass sql = new SQLiteClass(ProgramFilesx86() + "\\DuckClient\\Information.dat"); switch (mode) { case IM_GetIdentity: bw.Write(sql.GetGUID()); break; case IM_GetVersion: bw.Write(sql.GetVersion()); break; case IM_GetMAC: var s = MACFinder.getMacByIp(GetIPAddress()); bw.Write(s); break; case IM_GetHostname: bw.Write(Dns.GetHostName()); break; case IM_RegistrationDone: if (br.ReadString().Equals(sql.GetGUID())) { sql.SetRegistered(true); } break; case IM_NewVersionsCheck: DateTimeVersions dtv = DeserializeXMLFileToObject <DateTimeVersions>(br.ReadString()); if (DateTime.Compare(dtv.ServiceDateTime, sql.GetLastUpdated(SQLiteClass.GET_SERVICE_LIST)) > 0 || DateTime.Compare(dtv.WhitelistDateTime, sql.GetLastUpdated(SQLiteClass.GET_WHITELIST_LIST)) > 0) { IMClient imc = new IMClient(); imc.setConnParams(GetOriginIP(), 25568); imc.SetupConn(); imc.SendSignal(IM_NewVersions, "2"); imc.Disconnect(); } break; case IM_NewVersions: DateTimeVersions dtv1 = DeserializeXMLFileToObject <DateTimeVersions>(br.ReadString()); UpdateStuff(dtv1); break; case IM_NewServiceList: List <ServicesObject> sros = DeserializeXMLFileToObject <List <ServicesObject> >(br.ReadString()); sql.NewServices(sros); break; case IM_NewWhitelists: List <Whitelists> wls = DeserializeXMLFileToObject <List <Whitelists> >(br.ReadString()); sql.NewWhitelists(wls); break; case IM_AddWhiteList: break; case IM_RemoveWhitelist: break; case IM_Debug: Console.WriteLine(br.ReadString()); bw.Write(IM_OK); break; default: break; } bw.Write(IM_OK); }