Пример #1
0
        public void UpdateStuff(DateTimeVersions dtv1)
        {
            SQLiteClass sql = new SQLiteClass(ProgramFilesx86() + "\\DuckClient\\Information.dat");

            sql.NewServices(dtv1.ServiceVersion);
            sql.NewWhitelists(dtv1.WhitelistVersion);
            sql.SetLastUpdated(SQLiteClass.GET_SERVICE_LIST, dtv1.ServiceDateTime);
            sql.SetLastUpdated(SQLiteClass.GET_WHITELIST_LIST, dtv1.WhitelistDateTime);
        }
Пример #2
0
        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);
        }