Esempio n. 1
0
        public static List <HTTPDataAnalyzer.Registration.RecentApp> GetRecentApp()
        {
            List <HTTPDataAnalyzer.Registration.RecentApp> oldApp = new List <Registration.RecentApp>();

            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(DBManager.ConnectionString))
                {
                    connection.Open();
                    using (SQLiteCommand selectCommand = new SQLiteCommand("select * from installedapp", connection))
                    {
                        using (SQLiteDataReader dataReader = selectCommand.ExecuteReader())
                        {
                            List <winaudits.InstalledApp> autoRun = new List <winaudits.InstalledApp>();
                            while (dataReader.Read())
                            {
                                HTTPDataAnalyzer.Registration.RecentApp app = new Registration.RecentApp();

                                app.CollectedDate          = dataReader["collecteddate"].ToString();
                                app.IsInstalled            = bool.Parse(dataReader["isinstalled"].ToString());
                                app.AppDetails             = new winaudits.InstalledApp();
                                app.AppDetails.DisplayName = dataReader["displayname"].ToString();
                                app.AppDetails.Version     = dataReader["version"].ToString();
                                app.AppDetails.InstallDate = dataReader["installdate"].ToString();
                                app.AppDetails.Key         = dataReader["key"].ToString();
                                app.AppDetails.Is64        = bool.Parse(dataReader["is64"].ToString());

                                oldApp.Add(app);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Registration.ClientRegistrar.Logger.Error(ex);
            }
            return(oldApp);
        }
Esempio n. 2
0
        //static Dictionary<string, RecentAutoRuns> PreviousAutorunpoints = new Dictionary<string, RecentAutoRuns>();

        public static byte[] GetConfig(bool isRegister)
        {
            string temp = string.Empty;
            Dictionary <string, RecentApp> currentAppList = new Dictionary <string, RecentApp>();
            SystemConfiguration            sysConfig      = null;

            if (isRegister)
            {
                sysConfig = HTTPDataAnalyzer.ReadQueries.GetSystemConfiguration();
            }

            // return serial;
            if (sysConfig == null)
            {
                sysConfig = new SystemConfiguration();
                sysConfig.NetworkTypes       = new List <NetworkType>();
                sysConfig.RecentApps         = new List <RecentApp>();
                sysConfig.Autorunpoints      = new List <RecentAutoRuns>();
                sysConfig.Browsers           = BrowsersDetector.GetBrowsers().Select(x => x.Value).ToList();
                sysConfig.OfficeApplications = MSOfficeDetector.GetOfficeApps();

                Dictionary <string, RecentAutoRuns> currentAutoruns = new Dictionary <string, RecentAutoRuns>();
                foreach (var item in winaudits.AutoRunManager.StartAudit())
                {
                    RecentAutoRuns recent = new RecentAutoRuns();
                    recent.AppDetails    = item;
                    recent.IsDeleted     = false;
                    recent.CollectedDate = DateTime.UtcNow;
                    sysConfig.Autorunpoints.Add(recent);
                }

                foreach (var item in winaudits.InstalledAppAuditor.StartAudit())
                {
                    RecentApp recent = new RecentApp();
                    recent.AppDetails    = item;
                    recent.IsInstalled   = true;
                    recent.CollectedDate = DateTime.UtcNow.ToString(HTTPDataAnalyzer.DBManager.DateTimeFormat);
                    sysConfig.RecentApps.Add(recent);
                    try
                    {
                        if (!currentAppList.ContainsKey(recent.AppDetails.Key))
                        {
                            currentAppList.Add(recent.AppDetails.Key, recent);
                        }
                        else
                        {
                            //Registration.ClientRegistrar.Logger.Error("=====================================================================");
                            //Registration.ClientRegistrar.Logger.Error("Config 1");
                            //Registration.ClientRegistrar.Logger.Error(recent.AppDetails.DisplayName);
                            //Registration.ClientRegistrar.Logger.Error(recent.AppDetails.Key);
                            //Registration.ClientRegistrar.Logger.Error(recent.AppDetails.InstallDate);
                            //Registration.ClientRegistrar.Logger.Error(recent.AppDetails.Version);
                            //Registration.ClientRegistrar.Logger.Error(recent.AppDetails.Is64);
                            //Registration.ClientRegistrar.Logger.Error(recent.IsInstalled);
                            //Registration.ClientRegistrar.Logger.Error(recent.CollectedDate);

                            recent = currentAppList[recent.AppDetails.Key];
                            //Registration.ClientRegistrar.Logger.Error("Config 2");
                            //Registration.ClientRegistrar.Logger.Error(recent.AppDetails.DisplayName);
                            //Registration.ClientRegistrar.Logger.Error(recent.AppDetails.Key);
                            //Registration.ClientRegistrar.Logger.Error(recent.AppDetails.InstallDate);
                            //Registration.ClientRegistrar.Logger.Error(recent.AppDetails.Version);
                            //Registration.ClientRegistrar.Logger.Error(recent.AppDetails.Is64);
                            //Registration.ClientRegistrar.Logger.Error(recent.IsInstalled);
                            //Registration.ClientRegistrar.Logger.Error(recent.CollectedDate);
                            //Registration.ClientRegistrar.Logger.Error("=====================================================================");
                        }
                    }
                    catch (Exception ex)
                    {
                        //Registration.ClientRegistrar.Logger.Error(ex);
                    }
                }

                sysConfig.ChasisType   = ChasisTypeFinder.GetChassisType().ToString();
                sysConfig.AgentVersion = "0";
                sysConfig.TimeZone     = GetSystemTimeZoneName();
                sysConfig.HostName     = Dns.GetHostName();
                sysConfig.DomainName   = Environment.UserDomainName;

                foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
                {
                    if (nic.OperationalStatus.ToString().ToLower() == "up" && nic.NetworkInterfaceType.ToString().ToLower() != "loopback")
                    {
                        NetworkType netTpe = new NetworkType();

                        foreach (UnicastIPAddressInformation ip in nic.GetIPProperties().UnicastAddresses)
                        {
                            if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                            {
                                netTpe.IPAdress = ip.Address.ToString();
                                break;
                            }
                        }
                        if (netTpe.IPAdress == null)
                        {
                            continue;
                        }
                        netTpe.MAC  = nic.GetPhysicalAddress().ToString();
                        netTpe.Type = nic.NetworkInterfaceType.ToString();
                        sysConfig.NetworkTypes.Add(netTpe);
                    }
                }

                sysConfig.Processor      = GetProcessor();
                sysConfig.BitLevel       = OSInfo.Bits;
                sysConfig.OSEdition      = OSInfo.Edition;
                sysConfig.OSServicePack  = OSInfo.ServicePack;
                sysConfig.OSName         = OSInfo.Name;
                sysConfig.ProductID      = ProductID();
                sysConfig.AgentID        = ConfigHandler.Config.AgentInstaller.AgentID;
                sysConfig.AgentVersion   = ConfigHandler.Config.AgentInstaller.AgentVersion;
                sysConfig.OSLastUpTime   = LastBootUpTime();
                sysConfig.Installdate    = DateTime.UtcNow;
                sysConfig.Acrobat        = GetAdobeVer();
                sysConfig.Java           = GetJavaVersion();
                sysConfig.Registereduser = Util.GetWindowsUserName();
                sysConfig.Flash          = GetFlashPlayerVersionString().Replace(",", ".");
            }
            if (isRegister)
            {
                HTTPDataAnalyzer.InsertQueries.InsertInHostInfo(sysConfig);
                sysConfig.RecentApps.Clear();
                sysConfig.Autorunpoints.Clear();
            }
            else
            {
                if (PreviousInstalledApp.Count == 0)
                {
                    PreviousInstalledApp = HTTPDataAnalyzer.ReadQueries.GetPreviousConfig();
                }

                if (PreviousInstalledApp.Count > 0)
                {
                    List <RecentApp> tempInstalledApp = new List <RecentApp>();
                    tempInstalledApp.AddRange(sysConfig.RecentApps);
                    sysConfig.RecentApps.Clear();
                    for (int i = 0; i < tempInstalledApp.Count; i++)
                    {
                        var appName = tempInstalledApp[i];
                        if (PreviousInstalledApp.ContainsKey(appName.AppDetails.Key))
                        {
                            continue;
                        }

                        sysConfig.RecentApps.Add(appName);
                        PreviousInstalledApp.Add(appName.AppDetails.Key, appName);
                    }

                    foreach (var item in PreviousInstalledApp)
                    {
                        if (!currentAppList.ContainsKey(item.Key))
                        {
                            RecentApp unInstall = PreviousInstalledApp[item.Key];
                            unInstall.IsInstalled   = false;
                            unInstall.CollectedDate = DateTime.UtcNow.ToString(HTTPDataAnalyzer.DBManager.DateTimeFormat);
                            sysConfig.RecentApps.Add(unInstall);
                        }
                    }

                    foreach (RecentApp item in sysConfig.RecentApps)
                    {
                        if (!item.IsInstalled)
                        {
                            if (PreviousInstalledApp.ContainsKey(item.AppDetails.Key))
                            {
                                PreviousInstalledApp.Remove(item.AppDetails.Key);
                            }
                        }
                    }
                }

                //if (PreviousAutorunpoints.Count == 0)
                //{
                //    PreviousAutorunpoints = HTTPDataAnalyzer.DBManager.ReadQueries.GetPreviousAutoRuns();
                //}

                //if (PreviousAutorunpoints.Count > 0)
                //{
                //    List<RecentAutoRuns> tempAutoRuns = new List<RecentAutoRuns>();
                //    tempAutoRuns.AddRange(sysConfig.Autorunpoints);
                //    sysConfig.Autorunpoints.Clear();
                //    for (int i = 0; i < tempAutoRuns.Count; i++)
                //    {
                //        var appName = tempAutoRuns[i];
                //        if (PreviousAutorunpoints.ContainsKey(appName.AppDetails.FilePath))
                //        {
                //            continue;
                //        }

                //        sysConfig.Autorunpoints.Add(appName);
                //        PreviousAutorunpoints.Add(appName.AppDetails.FilePath, appName);
                //    }

                //    foreach (var item in PreviousAutorunpoints)
                //    {
                //        if (!currentAutoruns.ContainsKey(item.Key))
                //        {
                //            RecentAutoRuns unInstall = PreviousAutorunpoints[item.Key];
                //            unInstall.IsDeleted = false;
                //            sysConfig.Autorunpoints.Add(unInstall);
                //        }
                //    }
                //}

                HTTPDataAnalyzer.UpdateQuery.UpdateInHostInfo(sysConfig);
            }

            byte[] configByte = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(sysConfig));

            return(configByte);
        }
Esempio n. 3
0
        public static Dictionary <string, HTTPDataAnalyzer.Registration.RecentApp> GetPreviousConfig()
        {
            //Registration.ClientRegistrar.Logger.Error("Start Reading previous configuration");
            Dictionary <string, HTTPDataAnalyzer.Registration.RecentApp> oldApps = new Dictionary <string, Registration.RecentApp>();

            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(DBManager.ConnectionString))
                {
                    connection.Open();
                    using (SQLiteCommand selectCommand = new SQLiteCommand("select * from installedapp", connection))
                    {
                        using (SQLiteDataReader dataReader = selectCommand.ExecuteReader())
                        {
                            while (dataReader.Read())
                            {
                                HTTPDataAnalyzer.Registration.RecentApp app = new Registration.RecentApp();
                                app.AppDetails             = new winaudits.InstalledApp();
                                app.AppDetails.DisplayName = dataReader["displayname"].ToString();
                                app.AppDetails.Key         = dataReader["key"].ToString();
                                app.AppDetails.InstallDate = dataReader["installdate"].ToString();
                                app.AppDetails.Version     = dataReader["version"].ToString();
                                app.AppDetails.Is64        = Convert.ToBoolean(dataReader["is64"].ToString());
                                app.IsInstalled            = Convert.ToBoolean(dataReader["isinstalled"].ToString());
                                app.CollectedDate          = DateTime.Parse(dataReader["collecteddate"].ToString()).ToString(DBManager.DateTimeFormat);
                                if (!oldApps.ContainsKey(app.AppDetails.Key))
                                {
                                    oldApps.Add(app.AppDetails.Key, app);
                                }
                                else
                                {
                                    //Registration.ClientRegistrar.Logger.Error("=====================================================================");
                                    //Registration.ClientRegistrar.Logger.Error("Config 1");
                                    //Registration.ClientRegistrar.Logger.Error(app.AppDetails.DisplayName);
                                    //Registration.ClientRegistrar.Logger.Error(app.AppDetails.Key);
                                    //Registration.ClientRegistrar.Logger.Error(app.AppDetails.InstallDate);
                                    //Registration.ClientRegistrar.Logger.Error(app.AppDetails.Version);
                                    //Registration.ClientRegistrar.Logger.Error(app.AppDetails.Is64);
                                    //Registration.ClientRegistrar.Logger.Error(app.IsInstalled);
                                    //Registration.ClientRegistrar.Logger.Error(app.CollectedDate);

                                    app = oldApps[app.AppDetails.Key];
                                    //Registration.ClientRegistrar.Logger.Error("Config 2");
                                    //Registration.ClientRegistrar.Logger.Error(app.AppDetails.DisplayName);
                                    //Registration.ClientRegistrar.Logger.Error(app.AppDetails.Key);
                                    //Registration.ClientRegistrar.Logger.Error(app.AppDetails.InstallDate);
                                    //Registration.ClientRegistrar.Logger.Error(app.AppDetails.Version);
                                    //Registration.ClientRegistrar.Logger.Error(app.AppDetails.Is64);
                                    //Registration.ClientRegistrar.Logger.Error(app.IsInstalled);
                                    //Registration.ClientRegistrar.Logger.Error(app.CollectedDate);
                                    //Registration.ClientRegistrar.Logger.Error("=====================================================================");
                                }
                            }
                        }
                    }
                }

                //Registration.ClientRegistrar.Logger.Error("End Reading previous configuration");
            }
            catch (Exception ex)
            {
                //Registration.ClientRegistrar.Logger.Error(ex);
            }
            return(oldApps);
        }