Beispiel #1
0
        public RESTStatus ReportDevicesFilter(SQLLib sql, FilterDriverList devices, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (devices == null)
            {
                ni.Error   = "Invalid Items";
                ni.ErrorID = ErrorFlags.InvalidValue;
                return(RESTStatus.Fail);
            }

            devices.MachineID = ni.Username;

            lock (ni.sqllock)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                                      new SQLParam("@m", devices.MachineID))) == 0)
                {
                    ni.Error   = "Invalid MachineID";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.NotFound);
                }
            }

            lock (ni.sqllock)
            {
                sql.ExecSQL("DELETE FROM DevicesFilter WHERE MachineID=@id", new SQLParam("@id", devices.MachineID));
            }

            if (devices.List == null)
            {
                devices.List = new List <FilterDriver>();
            }

            int Counter = 0;

            foreach (FilterDriver flt in devices.List)
            {
                lock (ni.sqllock)
                {
                    sql.InsertMultiData("DevicesFilter",
                                        new SQLData("MachineID", devices.MachineID),
                                        new SQLData("Index", Counter),
                                        new SQLData("ClassGUID", flt.ClassGUID),
                                        new SQLData("ServiceName", flt.ServiceName),
                                        new SQLData("Type", flt.Type));
                }
                Counter++;
            }

            return(RESTStatus.Success);
        }
Beispiel #2
0
        public static void ReportEventLog(SQLLib sql, string MachineID, EventLogReportFull EV, ReportingFlags Flags)
        {
            Flags &= ~(ReportingFlags.AdminReported | ReportingFlags.ClientReported | ReportingFlags.UrgentAdminReported | ReportingFlags.UrgentClientReported);

            sql.InsertMultiData("Reporting",
                                new SQLData("MachineID", MachineID),
                                new SQLData("Type", ReportingPolicyType.EventLog),
                                new SQLData("Data", JsonConvert.SerializeObject(EV)),
                                new SQLData("Flags", Flags));
        }
Beispiel #3
0
        public RESTStatus ReportWindowsLic(SQLLib sql, WindowsLic WinLic, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            WinLic.MachineID = ni.Username;
            WinLic.Reported  = DateTime.Now;

            lock (ni.sqllock)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                                      new SQLParam("@m", WinLic.MachineID))) == 0)
                {
                    ni.Error   = "Invalid MachineID";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.Fail);
                }
            }

            lock (ni.sqllock)
            {
                sql.ExecSQL("DELETE FROM WindowsLic WHERE MachineID=@m",
                            new SQLParam("@m", WinLic.MachineID));
            }

            if (NullTest.Test(WinLic) == false)
            {
                ni.Error   = "Invalid Data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            lock (ni.sqllock)
            {
                sql.InsertMultiData("WindowsLic",
                                    new SQLData("MachineID", WinLic.MachineID),
                                    new SQLData("Name", WinLic.Name),
                                    new SQLData("Description", WinLic.Description),
                                    new SQLData("GracePeriodRemaining", WinLic.GracePeriodRemaining),
                                    new SQLData("PartialProductKey", WinLic.PartialProductKey),
                                    new SQLData("ProductKeyID", WinLic.ProductKeyID),
                                    new SQLData("ProductKeyID2", WinLic.ProductKeyID2),
                                    new SQLData("LicenseFamily", WinLic.LicenseFamily),
                                    new SQLData("ProductKeyChannel", WinLic.ProductKeyChannel),
                                    new SQLData("LicenseStatus", WinLic.LicenseStatus),
                                    new SQLData("LicenseStatusText", WinLic.LicenseStatusText));
            }

            return(RESTStatus.Success);
        }
Beispiel #4
0
        public static void ReportSMART(SQLLib sql, string MachineID, string Method, ReportingSMART AR, ReportingFlags Flags, bool Critical)
        {
            Flags &= ~(ReportingFlags.AdminReported | ReportingFlags.ClientReported | ReportingFlags.UrgentAdminReported | ReportingFlags.UrgentClientReported);

            AR.Action = Method;

            sql.InsertMultiData("Reporting",
                                new SQLData("MachineID", MachineID),
                                new SQLData("Type", Critical == false ? ReportingPolicyType.SMART : ReportingPolicyType.SMARTCritical),
                                new SQLData("Data", JsonConvert.SerializeObject(AR)),
                                new SQLData("Flags", Flags));
        }
Beispiel #5
0
        public static void ReportAddRemoveApps(SQLLib sql, string MachineID, string Method, AddRemoveApp AR, ReportingFlags Flags)
        {
            Flags &= ~(ReportingFlags.AdminReported | ReportingFlags.ClientReported | ReportingFlags.UrgentAdminReported | ReportingFlags.UrgentClientReported);

            ReportingAddRemovePrograms a = new ReportingAddRemovePrograms();

            a.Action = Method;
            a.App    = AR;

            sql.InsertMultiData("Reporting",
                                new SQLData("MachineID", MachineID),
                                new SQLData("Type", ReportingPolicyType.AddRemovePrograms),
                                new SQLData("Data", JsonConvert.SerializeObject(a)),
                                new SQLData("Flags", Flags));
        }
Beispiel #6
0
        public static void ReportSimpleTaskCompletion(SQLLib sql, string MachineID, string Method, SimpleTaskResult AR, ReportingFlags Flags)
        {
            Flags &= ~(ReportingFlags.AdminReported | ReportingFlags.ClientReported | ReportingFlags.UrgentAdminReported | ReportingFlags.UrgentClientReported);

            ReportingSimpleTaskCompletion a = new  ReportingSimpleTaskCompletion();

            a.Action = Method;
            a.App    = AR;

            sql.InsertMultiData("Reporting",
                                new SQLData("MachineID", MachineID),
                                new SQLData("Type", ReportingPolicyType.SimpleTaskCompleted),
                                new SQLData("Data", JsonConvert.SerializeObject(a)),
                                new SQLData("Flags", Flags));
        }
Beispiel #7
0
        public static void ReportDiskData(SQLLib sql, string MachineID, string Disk, Int64 NotifyValue, Int64 Is, Int64 TotalSZ, ReportingFlags Flags)
        {
            Flags &= ~(ReportingFlags.AdminReported | ReportingFlags.ClientReported | ReportingFlags.UrgentAdminReported | ReportingFlags.UrgentClientReported);

            ReportingDiskData rep = new ReportingDiskData();

            rep.Disk        = Disk;
            rep.Is          = Is;
            rep.NotifyValue = NotifyValue;
            rep.TotalSZ     = TotalSZ;

            sql.InsertMultiData("Reporting",
                                new SQLData("MachineID", MachineID),
                                new SQLData("Type", ReportingPolicyType.Disk),
                                new SQLData("Data", JsonConvert.SerializeObject(rep)),
                                new SQLData("Flags", Flags));
        }
Beispiel #8
0
        public RESTStatus ReportBitlockerRK(SQLLib sql, BitlockerRKList BitLockerRK, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            BitLockerRK.MachineID = ni.Username;

            lock (ni.sqllock)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                                      new SQLParam("@m", BitLockerRK.MachineID))) == 0)
                {
                    ni.Error   = "Invalid MachineID";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.Denied);
                }
            }

            if (BitLockerRK.List == null)
            {
                BitLockerRK.List = new List <BitlockerRK>();
            }

            if (BitLockerRK.List.Count == 0)
            {
                return(RESTStatus.Success);
            }

            List <string> DiskIDs = new List <string>();
            SqlDataReader dr      = sql.ExecSQLReader("SELECT DeviceID FROM BitlockerRK WHERE MachineID=@m",
                                                      new SQLParam("@m", BitLockerRK.MachineID));

            while (dr.Read())
            {
                DiskIDs.Add(Convert.ToString(dr["DeviceID"]).ToLower());
            }
            dr.Close();

            foreach (BitlockerRK disk in BitLockerRK.List)
            {
                if (disk.Keys == null)
                {
                    continue;
                }
                if (disk.Keys.Count == 0)
                {
                    continue;
                }
                disk.Reported = DateTime.UtcNow;
                if (disk.DeviceID == null)
                {
                    continue;
                }

                string RKs = JsonConvert.SerializeObject(disk.Keys);

                if (DiskIDs.Contains(disk.DeviceID.ToLower()) == true)
                {
                    lock (ni.sqllock)
                    {
                        sql.ExecSQL("DELETE FROM BitLockerRK WHERE MachineID=@m AND DeviceID=@d",
                                    new SQLParam("@m", BitLockerRK.MachineID),
                                    new SQLParam("@d", disk.DeviceID));
                    }
                }
                lock (ni.sqllock)
                {
                    sql.InsertMultiData("BitLockerRK",
                                        new SQLData("MachineID", BitLockerRK.MachineID),
                                        new SQLData("DeviceID", disk.DeviceID),
                                        new SQLData("DriveLetter", disk.DriveLetter == null ? "" : disk.DriveLetter),
                                        new SQLData("Keys", RKs),
                                        new SQLData("Reported", DateTime.UtcNow));
                }
            }

            return(RESTStatus.Success);
        }
Beispiel #9
0
        public RESTStatus ReportStatups(SQLLib sql, ListStartupItems StartupList, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            StartupList.MachineID = ni.Username;

            lock (ni.sqllock)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                                      new SQLParam("@m", StartupList.MachineID))) == 0)
                {
                    ni.Error   = "Invalid MachineID";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.Denied);
                }
            }

            if (StartupList.Items == null)
            {
                ni.Error   = "Invalid Items";
                ni.ErrorID = ErrorFlags.InvalidValue;
                return(RESTStatus.Fail);
            }
            if (StartupList.SIDUsers == null)
            {
                StartupList.SIDUsers = new List <string>();
            }

            foreach (StartupItem rep in StartupList.Items)
            {
                if (string.IsNullOrWhiteSpace(rep.Location) == true)
                {
                    ni.Error   = "Invalid Items";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.Fail);
                }
                if (string.IsNullOrWhiteSpace(rep.Key) == true)
                {
                    ni.Error   = "Invalid Items";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.Fail);
                }

                if (string.IsNullOrWhiteSpace(rep.HKCUUser) == true)
                {
                    rep.HKCUUser = "";
                }
                if (string.IsNullOrWhiteSpace(rep.Item) == true)
                {
                    rep.Item = "";
                }
            }

            List <StartupItem> Installed = new List <StartupItem>();
            List <StartupItem> Reported  = StartupList.Items;

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM Startups WHERE MachineID=@id", new SQLParam("@id", StartupList.MachineID));
                while (dr.Read())
                {
                    StartupItem ar = new StartupItem();
                    ar.Location = Convert.ToString(dr["Location"]);
                    ar.Key      = Convert.ToString(dr["Key"]);
                    ar.Item     = Convert.ToString(dr["Item"]);
                    ar.HKCUUser = Convert.ToString(dr["HKCUUser"]);
                    if (string.IsNullOrWhiteSpace(ar.HKCUUser) == true)
                    {
                        ar.HKCUUser = "";
                    }

                    Installed.Add(ar);
                }
                dr.Close();
            }

            List <StartupItem> Updated   = new List <StartupItem>();
            List <StartupItem> Unchanged = new List <StartupItem>();
            List <StartupItem> Removed   = new List <StartupItem>();
            List <StartupItem> Added     = new List <StartupItem>();

            foreach (StartupItem inst in Installed)
            {
                inst.Location = inst.Location.Trim();
                inst.Key      = inst.Key.Trim();
                inst.Item     = inst.Item.Trim();
                inst.HKCUUser = inst.HKCUUser.Trim();

                bool Found = false;
                foreach (StartupItem rep in Reported)
                {
                    rep.Location = rep.Location.Trim();
                    rep.Key      = rep.Key.Trim();
                    rep.Item     = rep.Item.Trim();
                    rep.HKCUUser = rep.HKCUUser.Trim();

                    if (rep.Location.ToLower() == inst.Location.ToLower() && rep.Key == inst.Key && rep.HKCUUser == inst.HKCUUser)
                    {
                        if (rep.Item.ToLower() == inst.Item.ToLower())
                        {
                            Unchanged.Add(rep);
                            Found = true;
                            break;
                        }
                        else
                        {
                            Updated.Add(rep);
                            Found = true;
                            break;
                        }
                    }
                }
                if (Found == false)
                {
                    if (inst.HKCUUser != "" && StartupList.SIDUsers.Contains(inst.HKCUUser, StringComparer.InvariantCultureIgnoreCase) == false)
                    {
                        //likely that this user is not logged on or such
                        Unchanged.Add(inst);
                    }
                    else
                    {
                        Removed.Add(inst);
                    }
                }
            }

            foreach (StartupItem inst in Reported)
            {
                bool Found = false;
                foreach (StartupItem rep in Installed)
                {
                    if (rep.Key.ToLower() == inst.Key.ToLower() && rep.Location == inst.Location && rep.HKCUUser == inst.HKCUUser)
                    {
                        Found = true;
                        break;
                    }
                }
                if (Found == false)
                {
                    Added.Add(inst);
                }
            }

            lock (ni.sqllock)
            {
                try
                {
                    sql.BeginTransaction();
                    sql.SEHError = true;
                    foreach (StartupItem ar in Removed)
                    {
                        sql.ExecSQL("DELETE FROM Startups WHERE MachineID=@id AND [Key]=@key AND Location=@location AND HKCUUser=@user",
                                    new SQLParam("@id", StartupList.MachineID),
                                    new SQLParam("@key", ar.Key),
                                    new SQLParam("@user", ar.HKCUUser),
                                    new SQLParam("@location", ar.Location));
                    }
                    foreach (StartupItem ar in Updated)
                    {
                        sql.ExecSQL(@"UPDATE Startups SET
                            Item=@item,
                            DT=@DT
                            WHERE MachineID=@id AND [Key]=@key AND Location=@location AND HKCUUser=@user",
                                    new SQLParam("@id", StartupList.MachineID),
                                    new SQLParam("@key", ar.Key),
                                    new SQLParam("@user", ar.HKCUUser),
                                    new SQLParam("@location", ar.Location),
                                    new SQLParam("@item", ar.Item),
                                    new SQLParam("@DT", DateTime.UtcNow));
                    }
                    foreach (StartupItem ar in Added)
                    {
                        sql.InsertMultiData("Startups",
                                            new SQLData("MachineID", StartupList.MachineID),
                                            new SQLData("Item", ar.Item),
                                            new SQLData("Location", ar.Location),
                                            new SQLData("Key", ar.Key),
                                            new SQLData("HKCUUser", ar.HKCUUser),
                                            new SQLData("DT", DateTime.UtcNow));
                    }
                    sql.CommitTransaction();
                }
                catch (Exception ee)
                {
                    sql.RollBackTransaction();
                    FoxEventLog.WriteEventLog("DB Error: Cannot update Startups: " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
                    return(RESTStatus.ServerError);
                }
                finally
                {
                    sql.SEHError = false;
                }
            }

            StartupLst l = new StartupLst();

            l.Added     = Added;
            l.Removed   = Removed;
            l.Unchanged = Unchanged;
            l.Updated   = Updated;
            l.MachineID = StartupList.MachineID;
            Thread t = new Thread(new ParameterizedThreadStart(new DReportingThread(ReportingThread)));

            t.Start(l);

            return(RESTStatus.Created);
        }
Beispiel #10
0
        public RESTStatus ReportAddRemovePrograms(SQLLib sql, ListAddRemoveApps AddRemoveList, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            AddRemoveList.MachineID = ni.Username;

            lock (ni.sqllock)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                                      new SQLParam("@m", AddRemoveList.MachineID))) == 0)
                {
                    ni.Error   = "Invalid MachineID";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.Denied);
                }
            }

            if (AddRemoveList.Items == null)
            {
                ni.Error   = "Invalid Items";
                ni.ErrorID = ErrorFlags.InvalidValue;
                return(RESTStatus.Fail);
            }
            if (AddRemoveList.SIDUsers == null)
            {
                AddRemoveList.SIDUsers = new List <string>();
            }

            foreach (AddRemoveApp rep in AddRemoveList.Items)
            {
                if (rep.ProductID == null)
                {
                    rep.ProductID = "";
                }
                if (rep.Name == null)
                {
                    rep.Name = "";
                }
                if (rep.DisplayVersion == null)
                {
                    rep.DisplayVersion = "";
                }
                if (rep.UninstallString == null)
                {
                    rep.UninstallString = "";
                }
                if (rep.Language == null)
                {
                    rep.Language = "";
                }
                if (rep.DisplayLanguage == null)
                {
                    rep.DisplayLanguage = "";
                }
                if (rep.HKCUUser == null)
                {
                    rep.HKCUUser = "";
                }

                rep.ProductID       = rep.ProductID.Trim();
                rep.Name            = rep.Name.Trim();
                rep.DisplayVersion  = rep.DisplayVersion.Trim();
                rep.UninstallString = rep.UninstallString.Trim();
                rep.Language        = rep.Language.Trim();
                rep.DisplayLanguage = rep.DisplayLanguage.Trim();
                rep.HKCUUser        = rep.HKCUUser.Trim();
            }

            List <AddRemoveApp> Installed = new List <AddRemoveApp>();
            List <AddRemoveApp> Reported  = AddRemoveList.Items;

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM AddRemovePrograms WHERE MachineID=@id", new SQLParam("@id", AddRemoveList.MachineID));
                while (dr.Read())
                {
                    AddRemoveApp ar = new AddRemoveApp();
                    ar.DisplayLanguage   = Convert.ToString(dr["DisplayLanguage"]);
                    ar.DisplayVersion    = Convert.ToString(dr["DisplayVersion"]);
                    ar.IsMSI             = Convert.ToBoolean(dr["IsMSI"]);
                    ar.IsWOWBranch       = Convert.ToBoolean(dr["IsWOWBranch"]);
                    ar.IsSystemComponent = Convert.ToBoolean(dr["IsSystemComponent"]);
                    ar.Language          = Convert.ToString(dr["Language"]);
                    ar.MachineID         = Convert.ToString(dr["MachineID"]);
                    ar.Name            = Convert.ToString(dr["Name"]);
                    ar.ProductID       = Convert.ToString(dr["ProductID"]);
                    ar.UninstallString = Convert.ToString(dr["UninstallString"]);
                    ar.VersionMajor    = Convert.ToInt32(dr["VersionMajor"]);
                    ar.VersionMinor    = Convert.ToInt32(dr["VersionMinor"]);
                    ar.HKCUUser        = Convert.ToString(dr["HKCUUser"]);
                    if (string.IsNullOrWhiteSpace(ar.HKCUUser) == true)
                    {
                        ar.HKCUUser = "";
                    }

                    Installed.Add(ar);
                }
                dr.Close();
            }

            List <AddRemoveApp> Updated   = new List <AddRemoveApp>();
            List <AddRemoveApp> Unchanged = new List <AddRemoveApp>();
            List <AddRemoveApp> Removed   = new List <AddRemoveApp>();
            List <AddRemoveApp> Added     = new List <AddRemoveApp>();

            foreach (AddRemoveApp inst in Installed)
            {
                if (inst.ProductID == null)
                {
                    inst.ProductID = "";
                }
                if (inst.Name == null)
                {
                    inst.Name = "";
                }
                if (inst.DisplayVersion == null)
                {
                    inst.DisplayVersion = "";
                }
                if (inst.UninstallString == null)
                {
                    inst.UninstallString = "";
                }
                if (inst.Language == null)
                {
                    inst.Language = "";
                }
                if (inst.DisplayLanguage == null)
                {
                    inst.DisplayLanguage = "";
                }

                inst.ProductID       = inst.ProductID.Trim();
                inst.Name            = inst.Name.Trim();
                inst.DisplayVersion  = inst.DisplayVersion.Trim();
                inst.UninstallString = inst.UninstallString.Trim();
                inst.Language        = inst.Language.Trim();
                inst.DisplayLanguage = inst.DisplayLanguage.Trim();
                inst.HKCUUser        = inst.HKCUUser.Trim();

                bool Found = false;
                foreach (AddRemoveApp rep in Reported)
                {
                    if (rep.ProductID.ToLower() == inst.ProductID.ToLower() && rep.IsWOWBranch == inst.IsWOWBranch && rep.HKCUUser == inst.HKCUUser)
                    {
                        if (rep.IsMSI == inst.IsMSI && rep.IsSystemComponent == inst.IsSystemComponent && rep.Name.ToLower() == inst.Name.ToLower() &&
                            rep.DisplayVersion.ToLower() == inst.DisplayVersion.ToLower() && inst.UninstallString.ToLower() == rep.UninstallString.ToLower() &&
                            rep.VersionMajor == inst.VersionMajor && rep.VersionMinor == inst.VersionMinor && rep.Language.ToLower() == inst.Language.ToLower() &&
                            rep.DisplayLanguage.ToLower() == inst.DisplayLanguage.ToLower())
                        {
                            Unchanged.Add(rep);
                            Found = true;
                            break;
                        }
                        else
                        {
                            Updated.Add(rep);
                            Found = true;
                            break;
                        }
                    }
                }
                if (Found == false)
                {
                    if (inst.HKCUUser != "" && AddRemoveList.SIDUsers.Contains(inst.HKCUUser, StringComparer.InvariantCultureIgnoreCase) == false)
                    {
                        //likely that this user is not logged on or such
                        Unchanged.Add(inst);
                    }
                    else
                    {
                        Removed.Add(inst);
                    }
                }
            }

            foreach (AddRemoveApp inst in Reported)
            {
                bool Found = false;
                foreach (AddRemoveApp rep in Installed)
                {
                    if (rep.ProductID.ToLower() == inst.ProductID.ToLower() && rep.IsWOWBranch == inst.IsWOWBranch && rep.HKCUUser == inst.HKCUUser)
                    {
                        Found = true;
                        break;
                    }
                }
                if (Found == false)
                {
                    Added.Add(inst);
                }
            }

            lock (ni.sqllock)
            {
                try
                {
                    sql.BeginTransaction();
                    sql.SEHError = true;
                    foreach (AddRemoveApp ar in Removed)
                    {
                        sql.ExecSQL("DELETE FROM AddRemovePrograms WHERE MachineID=@id AND IsWOWBranch=@wow AND ProductID=@prod AND HKCUUser=@user",
                                    new SQLParam("@id", AddRemoveList.MachineID),
                                    new SQLParam("@prod", ar.ProductID),
                                    new SQLParam("@user", ar.HKCUUser),
                                    new SQLParam("@wow", ar.IsWOWBranch));
                    }
                    foreach (AddRemoveApp ar in Updated)
                    {
                        sql.ExecSQL(@"UPDATE AddRemovePrograms SET
                            IsMSI=@IsMSI,
                            IsSystemComponent=@IsSystemComponent,
                            Name=@Name,
                            DisplayVersion=@DisplayVersion,
                            UninstallString=@UninstallString,
                            VersionMajor=@VersionMajor,
                            VersionMinor=@VersionMinor,
                            Language=@Language,
                            DisplayLanguage=@DisplayLanguage,
                            DT=@DT
                            WHERE MachineID=@id AND IsWOWBranch=@wow AND ProductID=@prod AND HKCUUser=@user",
                                    new SQLParam("@id", AddRemoveList.MachineID),
                                    new SQLParam("@prod", ar.ProductID),
                                    new SQLParam("@wow", ar.IsWOWBranch),
                                    new SQLParam("@IsMSI", ar.IsMSI),
                                    new SQLParam("@IsSystemComponent", ar.IsSystemComponent),
                                    new SQLParam("@Name", ar.Name.Trim()),
                                    new SQLParam("@DisplayVersion", ar.DisplayVersion),
                                    new SQLParam("@UninstallString", ar.UninstallString),
                                    new SQLParam("@VersionMajor", ar.VersionMajor),
                                    new SQLParam("@VersionMinor", ar.VersionMinor),
                                    new SQLParam("@Language", ar.Language),
                                    new SQLParam("@DisplayLanguage", ar.DisplayLanguage),
                                    new SQLParam("@user", ar.HKCUUser),
                                    new SQLParam("@DT", DateTime.UtcNow));
                    }
                    foreach (AddRemoveApp ar in Added)
                    {
                        sql.InsertMultiData("AddRemovePrograms",
                                            new SQLData("MachineID", AddRemoveList.MachineID),
                                            new SQLData("ProductID", ar.ProductID),
                                            new SQLData("IsWOWBranch", ar.IsWOWBranch),
                                            new SQLData("IsMSI", ar.IsMSI),
                                            new SQLData("IsSystemComponent", ar.IsSystemComponent),
                                            new SQLData("Name", ar.Name.Trim()),
                                            new SQLData("DisplayVersion", ar.DisplayVersion),
                                            new SQLData("UninstallString", ar.UninstallString),
                                            new SQLData("VersionMajor", ar.VersionMajor),
                                            new SQLData("VersionMinor", ar.VersionMinor),
                                            new SQLData("Language", ar.Language),
                                            new SQLData("DisplayLanguage", ar.DisplayLanguage),
                                            new SQLData("HKCUUser", ar.HKCUUser),
                                            new SQLData("DT", DateTime.UtcNow));
                    }
                    sql.CommitTransaction();
                }
                catch (Exception ee)
                {
                    sql.RollBackTransaction();
                    FoxEventLog.WriteEventLog("DB Error: Cannot update AddRemovePrograms: " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
                    return(RESTStatus.ServerError);
                }
                finally
                {
                    sql.SEHError = false;
                }
            }

            AddRemoveProgramsLst l = new AddRemoveProgramsLst();

            l.Added     = Added;
            l.Removed   = Removed;
            l.Unchanged = Unchanged;
            l.Updated   = Updated;
            l.MachineID = AddRemoveList.MachineID;
            Thread t = new Thread(new ParameterizedThreadStart(new DReportingThread(ReportingThread)));

            t.Start(l);

            return(RESTStatus.Created);
        }
Beispiel #11
0
        public RESTStatus ComputerLogin(SQLLib sql, ComputerLogon logon, NetworkConnectionInfo ni, string IPAddress)
        {
            Err = new ErrorInfo();

            if (logon == null)
            {
                Err.Error   = "Faulty data";
                Err.ErrorID = (int)ErrorFlags.FaultyData;
                return(RESTStatus.Fail);
            }

            if (NullTest.Test(logon) == false)
            {
                Err.Error   = "Invalid data";
                Err.ErrorID = (int)ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            if (logon.SysInfo != null)
            {
                if (logon.SysInfo.BIOSType == null)
                {
                    logon.SysInfo.BIOSType = "N/A";
                }
                if (logon.SysInfo.CPUName == null)
                {
                    logon.SysInfo.CPUName = "N/A";
                }
                if (logon.SysInfo.SecureBootState == null)
                {
                    logon.SysInfo.SecureBootState = "N/A";
                }
                if (logon.SysInfo.ComputerModel == null)
                {
                    logon.SysInfo.ComputerModel = "N/A";
                }
                if (logon.SysInfo.ComputerModel.Trim() == "")
                {
                    logon.SysInfo.ComputerModel = "N/A";
                }
                if (logon.SysInfo.SystemRoot == null)
                {
                    logon.SysInfo.SystemRoot = "C:\\Windows";
                }
                if (logon.SysInfo.SUSID == null)
                {
                    logon.SysInfo.SUSID = "";
                }
                if (logon.SysInfo.SUSID.Trim() == "")
                {
                    logon.SysInfo.SUSID = Consts.NullGUID;
                }
                if (logon.SysInfo.LegacyUCID == null)
                {
                    logon.SysInfo.LegacyUCID = Consts.NullUCID;
                }
            }

            if (NullTest.Test(logon.SysInfo, "IsMeteredConnection", "RunningInWindowsPE") == false)
            {
                Err.Error   = "Invalid data";
                Err.ErrorID = (int)ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            if (string.IsNullOrWhiteSpace(logon.Password) == true || string.IsNullOrWhiteSpace(logon.Username) == true)
            {
                Err.Error   = "Invalid data";
                Err.ErrorID = (int)ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            if (NullTest.TestBlankString(logon.SysInfo, "IsMeteredConnection", "RunningInWindowsPE") == false)
            {
                Err.Error   = "Invalid data";
                Err.ErrorID = (int)ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            Guid testguid;

            if (Guid.TryParse(logon.Username, out testguid) == false)
            {
                Err.Error   = "Invalid username";
                Err.ErrorID = (int)ErrorFlags.InvalidUsername;
                return(RESTStatus.Fail);
            }

            if (Guid.TryParse(logon.Password, out testguid) == false)
            {
                Err.Error   = "Invalid password";
                Err.ErrorID = (int)ErrorFlags.InvalidPassword;
                return(RESTStatus.Fail);
            }

            if (logon.SysInfo.UCID.Trim().Length != 32)
            {
                Err.Error   = "Invalid UCID";
                Err.ErrorID = (int)ErrorFlags.InvalidValue;
                return(RESTStatus.Fail);
            }

            if (logon.ContractID == null)
            {
                logon.ContractID = "";
            }
            if (logon.ContractPassword == null)
            {
                logon.ContractPassword = "";
            }

            if (Fox_LicenseGenerator.SDCLicensing.ValidLicense == false)
            {
                FoxEventLog.WriteEventLog("Licensing error: no valid license found. Client login are rejected.", EventLogEntryType.Warning);
                Err.Error   = "Licensing error";
                Err.ErrorID = (int)ErrorFlags.LicensingError;
                return(RESTStatus.Fail);
            }

            if (Fox_LicenseGenerator.SDCLicensing.TestExpiry() == false)
            {
                FoxEventLog.WriteEventLog("Licensing error: license expired. Client login are rejected.", EventLogEntryType.Warning);
                Err.Error   = "Licensing error";
                Err.ErrorID = (int)ErrorFlags.LicensingError;
                return(RESTStatus.Fail);
            }

            if (Settings.Default.UseContract == true)
            {
                if (logon.ContractID == "")
                {
                    Err.Error   = "Invalid Contract Data";
                    Err.ErrorID = (int)ErrorFlags.FaultyContractData;
                    return(RESTStatus.Fail);
                }
                if (logon.ContractPassword == "")
                {
                    Err.Error   = "Invalid Contract Data";
                    Err.ErrorID = (int)ErrorFlags.FaultyContractData;
                    return(RESTStatus.Fail);
                }
            }

            logon.Username          = logon.Username.Trim().ToUpper();
            logon.SysInfo.MachineID = logon.SysInfo.MachineID.Trim().ToUpper();

            if (logon.Username != logon.SysInfo.MachineID)
            {
                Err.Error   = "Invalid Username/MachineID";
                Err.ErrorID = (int)ErrorFlags.InvalidValue;
                return(RESTStatus.Fail);
            }

            string newID = NetworkConnection.NewSession();

            ni = NetworkConnection.GetSession(newID);
            if (NetworkConnectionProcessor.InitNi(ni) == false)
            {
                NetworkConnection.DeleteSession(newID);
                Err.Error   = "System Error";
                Err.ErrorID = (int)ErrorFlags.SystemError;
                return(RESTStatus.ServerError);
            }
            sql = ni.sql;

            ni.Permissions = 0;
            ni.Error       = "";
            ni.ErrorID     = ErrorFlags.NoError;

            if (Fox_LicenseGenerator.SDCLicensing.NumComputers != null)
            {
                Int64 Computers = Convert.ToInt64(sql.ExecSQLScalar("select count(*) from ComputerAccounts where Accepted=1"));
                if (Computers > Fox_LicenseGenerator.SDCLicensing.NumComputers.Value)
                {
                    NetworkConnection.DeleteSession(newID);
                    FoxEventLog.WriteEventLog("Licensing error: too many computers are accepted. Client login are rejected.\n" +
                                              "Lic=" + Fox_LicenseGenerator.SDCLicensing.NumComputers.Value.ToString() + " Listed=" + Computers.ToString(),
                                              EventLogEntryType.Warning);
                    Err.Error   = "Licensing error";
                    Err.ErrorID = (int)ErrorFlags.LicensingError;
                    return(RESTStatus.Fail);
                }
            }

            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);
                    Err.Error   = "Invalid/Disabled Contract Data";
                    Err.ErrorID = (int)ErrorFlags.FaultyContractData;
                    return(RESTStatus.Fail);
                }
            }

            if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                                  new SQLParam("@m", logon.Username))) == 0)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE UCID=@u",
                                                      new SQLParam("@u", logon.SysInfo.UCID.Trim()))) > 0)
                {
                    NetworkConnection.DeleteSession(newID);
                    Err.Error   = "UCID used for a different machine";
                    Err.ErrorID = (int)ErrorFlags.UCIDissues;
                    return(RESTStatus.Fail);
                }

                if (Settings.Default.UseContract == true)
                {
                    object o = sql.ExecSQLScalar("Select MaxComputers FROM Contracts WHERE ContractID=@cid", new SQLParam("@cid", logon.ContractID));
                    if (!(o is DBNull))
                    {
                        int i;
                        if (int.TryParse(o.ToString(), out i) == true)
                        {
                            int cnt = Convert.ToInt32(sql.ExecSQL("Select count(*) FROM ComputerAccounts WHERE ContractID=@cid", new SQLParam("@cid", logon.ContractID)));
                            if (cnt + 1 > i)
                            {
                                NetworkConnection.DeleteSession(newID);
                                Err.Error   = "Number of computers exhausted";
                                Err.ErrorID = (int)ErrorFlags.ContractNumComputersExhausted;
                                return(RESTStatus.Fail);
                            }
                        }
                    }
                }

                sql.InsertMultiData("ComputerAccounts",
                                    new SQLData("MachineID", logon.SysInfo.MachineID),
                                    new SQLData("UCID", logon.SysInfo.UCID),
                                    new SQLData("Password", logon.Password),
                                    new SQLData("Is64Bit", logon.SysInfo.Is64Bit),
                                    new SQLData("OSName", logon.SysInfo.OSName),
                                    new SQLData("OSVerMaj", logon.SysInfo.OSVerMaj),
                                    new SQLData("OSVerMin", logon.SysInfo.OSVerMin),
                                    new SQLData("OSVerBuild", logon.SysInfo.OSVerBuild),
                                    new SQLData("OSSuite", logon.SysInfo.OSSuite),
                                    new SQLData("IsTSE", logon.SysInfo.IsTSE),
                                    new SQLData("CPU", logon.SysInfo.CPU),
                                    new SQLData("ComputerModel", logon.SysInfo.ComputerModel),
                                    new SQLData("ComputerName", logon.SysInfo.ComputerName),
                                    new SQLData("Language", logon.SysInfo.Language),
                                    new SQLData("DisplayLanguage", logon.SysInfo.DisplayLanguage),
                                    new SQLData("AgentVersion", logon.SysInfo.AgentVersion),
                                    new SQLData("AgentVersionID", logon.SysInfo.AgentVersionID),
                                    new SQLData("OSVerType", logon.SysInfo.OSVerType),
                                    new SQLData("RunningInHypervisor", logon.SysInfo.RunningInHypervisor),
                                    new SQLData("BIOS", logon.SysInfo.BIOS),
                                    new SQLData("BIOSType", logon.SysInfo.BIOSType),
                                    new SQLData("NumberOfLogicalProcessors", logon.SysInfo.NumberOfLogicalProcessors),
                                    new SQLData("NumberOfProcessors", logon.SysInfo.NumberOfProcessors),
                                    new SQLData("TotalPhysicalMemory", logon.SysInfo.TotalPhysicalMemory),
                                    new SQLData("CPUName", logon.SysInfo.CPUName),
                                    new SQLData("SecureBootState", logon.SysInfo.SecureBootState),
                                    new SQLData("IPAddress", IPAddress),
                                    new SQLData("SystemRoot", logon.SysInfo.SystemRoot),
                                    new SQLData("SUSID", logon.SysInfo.SUSID),
                                    new SQLData("MeteredConnection", logon.SysInfo.IsMeteredConnection),
                                    new SQLData("RunningInWindowsPE", logon.SysInfo.RunningInWindowsPE),
                                    new SQLData("ContractID", Settings.Default.UseContract == true ? (object)logon.ContractID : DBNull.Value));

                Err.Error   = "Not accepted (computer registered)";
                Err.ErrorID = (int)ErrorFlags.NotAccepted;
                NetworkConnection.DeleteSession(newID);
                return(RESTStatus.Fail);
            }

            if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m AND UCID=@ucid",
                                                  new SQLParam("@m", logon.Username),
                                                  new SQLParam("@ucid", logon.SysInfo.UCID.Trim()))) == 0)
            {
                #region Remove in future
                if (logon.SysInfo.LegacyUCID != Consts.NullUCID && logon.SysInfo.LegacyUCID.Trim().Length == 32)
                {
                    if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE UCID=@u AND MachineID=@m AND Password=@p",
                                                          new SQLParam("@u", logon.SysInfo.LegacyUCID.Trim()),
                                                          new SQLParam("@p", logon.Password),
                                                          new SQLParam("@m", logon.Username))) > 0)
                    {
                        sql.ExecSQL("UPDATE ComputerAccounts SET UCID=@nu WHERE UCID=@u AND MachineID=@m",
                                    new SQLParam("@nu", logon.SysInfo.UCID.Trim()),
                                    new SQLParam("@u", logon.SysInfo.LegacyUCID.Trim()),
                                    new SQLParam("@m", logon.Username));

                        FoxEventLog.WriteEventLog("UCID changed:\nMachineID: " + logon.Username + "\nName: " + logon.SysInfo.ComputerName + "\nLUCID: " + logon.SysInfo.LegacyUCID + "\nUCID: " + logon.SysInfo.UCID, EventLogEntryType.Warning);

                        Err.Error   = "UCID changed!";
                        Err.ErrorID = (int)ErrorFlags.NotAccepted;
                        NetworkConnection.DeleteSession(newID);
                        return(RESTStatus.Fail);
                    }
                }
                #endregion

                Err.Error   = "MachineID & UCID do not match";
                Err.ErrorID = (int)ErrorFlags.MachineUCIDmissmatch;
                NetworkConnection.DeleteSession(newID);
                return(RESTStatus.Fail);
            }

            if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m AND Password=@p",
                                                  new SQLParam("@m", logon.Username),
                                                  new SQLParam("@p", logon.Password))) == 0)
            {
                Err.Error   = "Invalid password";
                Err.ErrorID = (int)ErrorFlags.InvalidPassword;
                NetworkConnection.DeleteSession(newID);
                return(RESTStatus.Fail);
            }

            if (Settings.Default.UseContract == true)
            {
                string CurrentContractID = Convert.ToString(sql.ExecSQLScalar("SELECT ContractID FROM ComputerAccounts WHERE MachineID=@m",
                                                                              new SQLParam("@m", logon.Username)));
                if (CurrentContractID == null)
                {
                    CurrentContractID = "";
                }
                if (CurrentContractID != "")
                {
                    if (CurrentContractID.Trim().ToLower() != logon.ContractID.Trim().ToLower())
                    {
                        Err.Error   = "Invalid Contract Data";
                        Err.ErrorID = (int)ErrorFlags.FaultyContractData;
                        NetworkConnection.DeleteSession(newID);
                        return(RESTStatus.Fail);
                    }
                }

                object   dt;
                DateTime dtt;

                dt = sql.ExecSQLScalar("Select ValidFrom FROM Contracts WHERE ContractID=@cid", new SQLParam("@cid", CurrentContractID));
                if (!(dt is DBNull))
                {
                    try
                    {
                        dtt = SQLLib.GetDTUTC(dt);
                        if (DateTime.UtcNow < dtt)
                        {
                            Err.Error   = "Contract not started / expired";
                            Err.ErrorID = (int)ErrorFlags.ContractNotStarted_Expired;
                            NetworkConnection.DeleteSession(newID);
                            return(RESTStatus.Fail);
                        }
                    }
                    catch
                    {
                        Err.Error   = "Invalid Contract Data";
                        Err.ErrorID = (int)ErrorFlags.FaultyContractData;
                        NetworkConnection.DeleteSession(newID);
                        return(RESTStatus.Fail);
                    }
                }

                dt = sql.ExecSQLScalar("Select ValidTo FROM Contracts WHERE ContractID=@cid", new SQLParam("@cid", CurrentContractID));
                if (!(dt is DBNull))
                {
                    try
                    {
                        dtt = SQLLib.GetDTUTC(dt);
                        if (dtt < DateTime.UtcNow)
                        {
                            Err.Error   = "Contract not started / expired";
                            Err.ErrorID = (int)ErrorFlags.ContractNotStarted_Expired;
                            NetworkConnection.DeleteSession(newID);
                            return(RESTStatus.Fail);
                        }
                    }
                    catch
                    {
                        Err.Error   = "Invalid Contract Data";
                        Err.ErrorID = (int)ErrorFlags.FaultyContractData;
                        NetworkConnection.DeleteSession(newID);
                        return(RESTStatus.Fail);
                    }
                }
            }
            else
            {
                logon.ContractID       = "";
                logon.ContractPassword = "";
            }

            sql.ExecSQL("UPDATE ComputerAccounts SET BIOS=@BIOS, OSVerType=@OSVerType, Is64Bit = @Is64Bit,OSName = @OSName,OSVerMaj = @OSVerMaj," +
                        "OSVerMin = @OSVerMin,OSVerBuild = @OSVerBuild,OSSuite = @OSSuite,IsTSE = @IsTSE,CPU = @CPU,ComputerModel = @ComputerModel,ComputerName = @ComputerName," +
                        "Language = @Language,DisplayLanguage = @DisplayLanguage,MachineID = @MachineID,LastUpdated = getutcdate(), AgentVersion=@AgentVersion, AgentVersionID=@AgentVersionID," +
                        "RunningInHypervisor=@RunningInHypervisor, ContractID=@ContractID, IPAddress=@IPAddress,BIOSType=@BIOSType, NumberOfLogicalProcessors=@NumberOfLogicalProcessors, " +
                        "NumberOfProcessors=@NumberOfProcessors, TotalPhysicalMemory=@TotalPhysicalMemory, CPUName=@CPUName, SecureBootState=@SecureBootState, " +
                        "SystemRoot=@SystemRoot,SUSID=@SUSID,MeteredConnection=@meteredconnection, " +
                        "RunningInWindowsPE=@RunningInWindowsPE " +
                        "    WHERE MachineID = @MachineID",
                        new SQLParam("@Is64Bit", logon.SysInfo.Is64Bit),
                        new SQLParam("@OSName", logon.SysInfo.OSName),
                        new SQLParam("@OSVerMaj", logon.SysInfo.OSVerMaj),
                        new SQLParam("@OSVerMin", logon.SysInfo.OSVerMin),
                        new SQLParam("@OSVerBuild", logon.SysInfo.OSVerBuild),
                        new SQLParam("@OSSuite", logon.SysInfo.OSSuite),
                        new SQLParam("@IsTSE", logon.SysInfo.IsTSE),
                        new SQLParam("@CPU", logon.SysInfo.CPU),
                        new SQLParam("@ComputerModel", logon.SysInfo.ComputerModel),
                        new SQLParam("@ComputerName", logon.SysInfo.ComputerName),
                        new SQLParam("@Language", logon.SysInfo.Language),
                        new SQLParam("@DisplayLanguage", logon.SysInfo.DisplayLanguage),
                        new SQLParam("@MachineID", logon.Username),
                        new SQLParam("@AgentVersionID", logon.SysInfo.AgentVersionID),
                        new SQLParam("@AgentVersion", logon.SysInfo.AgentVersion),
                        new SQLParam("@OSVerType", logon.SysInfo.OSVerType),
                        new SQLParam("@RunningInHypervisor", logon.SysInfo.RunningInHypervisor),
                        new SQLParam("@BIOS", logon.SysInfo.BIOS),
                        new SQLParam("@BIOSType", logon.SysInfo.BIOSType),
                        new SQLParam("@NumberOfLogicalProcessors", logon.SysInfo.NumberOfLogicalProcessors),
                        new SQLParam("@NumberOfProcessors", logon.SysInfo.NumberOfProcessors),
                        new SQLParam("@TotalPhysicalMemory", logon.SysInfo.TotalPhysicalMemory),
                        new SQLParam("@CPUName", logon.SysInfo.CPUName),
                        new SQLParam("@SecureBootState", logon.SysInfo.SecureBootState),
                        new SQLParam("@IPAddress", IPAddress),
                        new SQLParam("@SystemRoot", logon.SysInfo.SystemRoot),
                        new SQLParam("@SUSID", logon.SysInfo.SUSID),
                        new SQLParam("@meteredconnection", logon.SysInfo.IsMeteredConnection),
                        new SQLParam("@RunningInWindowsPE", logon.SysInfo.RunningInWindowsPE),
                        new SQLParam("@ContractID", Settings.Default.UseContract == true ? (object)logon.ContractID : DBNull.Value));

            sql.ExecSQL("UPDATE ComputerAccounts SET LastUpdated=getutcdate() WHERE MachineID=@m",
                        new SQLParam("@m", logon.Username));

            int Acceptance = Convert.ToInt32(sql.ExecSQLScalar("SELECT Accepted FROM ComputerAccounts WHERE MachineID=@m",
                                                               new SQLParam("@m", logon.Username)));

            switch (Acceptance)
            {
            case 1:     //OK
                break;

            default:
                Err.Error   = "Not accepted";
                Err.ErrorID = (int)ErrorFlags.NotAccepted;
                NetworkConnection.DeleteSession(newID);
                return(RESTStatus.Fail);
            }

            ni.Username           = logon.Username;
            ni.Name               = logon.SysInfo.ComputerName;
            ni.EMail              = "";
            ni.MustChangePassword = false;
            ni.LoggedIn           = false;
            ni.ComputerLoggedIn   = true;
            ni.Permissions        = (Int64)ACLFlags.ComputerLogin;
            Debug.WriteLine("Computer: " + ni.Name + " logged in");
            Err.Error   = "OK:" + newID;
            Err.ErrorID = (int)ErrorFlags.NoError;
            return(RESTStatus.Success);
        }
Beispiel #12
0
        public RESTStatus ReportDevicesConfig(SQLLib sql, PnPDeviceList devices, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (devices == null)
            {
                ni.Error   = "Invalid Items";
                ni.ErrorID = ErrorFlags.InvalidValue;
                return(RESTStatus.Fail);
            }

            devices.MachineID = ni.Username;

            lock (ni.sqllock)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                                      new SQLParam("@m", devices.MachineID))) == 0)
                {
                    ni.Error   = "Invalid MachineID";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.NotFound);
                }
            }

            lock (ni.sqllock)
            {
                sql.ExecSQL("DELETE FROM DevicesConfig WHERE MachineID=@id", new SQLParam("@id", devices.MachineID));
            }

            if (devices.List == null)
            {
                devices.List = new List <PnPDevice>();
            }

            int Counter = 0;

            foreach (PnPDevice dev in devices.List)
            {
                if (dev.CompatibleID == null)
                {
                    dev.CompatibleID = new List <string>();
                }
                if (dev.HardwareID == null)
                {
                    dev.HardwareID = new List <string>();
                }

                lock (ni.sqllock)
                {
                    sql.InsertMultiData("DevicesConfig",
                                        new SQLData("MachineID", devices.MachineID),
                                        new SQLData("Index", Counter),
                                        new SQLData("Availability", dev.Availability),
                                        new SQLData("Caption", dev.Caption == null ? "" : dev.Caption),
                                        new SQLData("ClassGuid", dev.ClassGuid == null ? "" : dev.ClassGuid),
                                        new SQLData("CompatibleID", JsonConvert.SerializeObject(dev.CompatibleID)),
                                        new SQLData("ConfigManagerErrorCode", dev.ConfigManagerErrorCode),
                                        new SQLData("ConfigManagerUserConfig", dev.ConfigManagerUserConfig),
                                        new SQLData("CreationClassName", dev.CreationClassName == null ? "" : dev.CreationClassName),
                                        new SQLData("Description", dev.Description == null ? "" : dev.Description),
                                        new SQLData("ErrorCleared", dev.ErrorCleared),
                                        new SQLData("ErrorDescription", dev.ErrorDescription == null ? "" : dev.ErrorDescription),
                                        new SQLData("HardwareID", JsonConvert.SerializeObject(dev.HardwareID)),
                                        new SQLData("InstallDate", dev.InstallDate),
                                        new SQLData("LastErrorCode", dev.LastErrorCode),
                                        new SQLData("Manufacturer", dev.Manufacturer == null ? "" : dev.Manufacturer),
                                        new SQLData("Name", dev.Name == null ? "" : dev.Name),
                                        new SQLData("PNPClass", dev.PNPClass == null ? "" : dev.PNPClass),
                                        new SQLData("PNPDeviceID", dev.PNPDeviceID == null ? "" : dev.PNPDeviceID),
                                        new SQLData("Present", dev.Present),
                                        new SQLData("Service", dev.Service == null ? "" : dev.Service),
                                        new SQLData("Status", dev.Status == null ? "" : dev.Status),
                                        new SQLData("StatusInfo", dev.StatusInfo));
                }
                Counter++;
            }

            return(RESTStatus.Success);
        }
Beispiel #13
0
        public RESTStatus ReportSmartInfos(SQLLib sql, VulpesSMARTInfoList SMART, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (SMART == null)
            {
                ni.Error   = "Invalid Items";
                ni.ErrorID = ErrorFlags.InvalidValue;
                return(RESTStatus.Fail);
            }

            SMART.MachineID = ni.Username;

            lock (ni.sqllock)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                                      new SQLParam("@m", SMART.MachineID))) == 0)
                {
                    ni.Error   = "Invalid MachineID";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.NotFound);
                }
            }

            if (SMART.List == null)
            {
                SMART.List = new List <VulpesSMARTInfo>();
            }

            if (TestAttributesKVP(SMART.List) == false)
            {
                ni.Error   = "Invalid Data (KVP)";
                ni.ErrorID = ErrorFlags.InvalidValue;
                return(RESTStatus.NotFound);
            }

            List <VulpesSMARTInfo> InDB = LoadData(SMART.MachineID, sql);

            List <VulpesSMARTInfo> Removed   = new List <VulpesSMARTInfo>();
            List <VulpesSMARTInfo> Updated   = new List <VulpesSMARTInfo>();
            List <VulpesSMARTInfo> Unchanged = new List <VulpesSMARTInfo>();
            List <VulpesSMARTInfo> Added     = new List <VulpesSMARTInfo>();


            foreach (VulpesSMARTInfo SMARTDevice in SMART.List)
            {
                bool Found = false;
                foreach (VulpesSMARTInfo idb in InDB)
                {
                    if (SMARTDescription.ComparePart(SMARTDevice, idb) == true)
                    {
                        if (SMARTDescription.CompareFull(SMARTDevice, idb, null) == true)
                        {
                            Unchanged.Add(SMARTDevice);
                            Found = true;
                            break;
                        }
                        else
                        {
                            Updated.Add(SMARTDevice);
                            Found = true;
                            break;
                        }
                    }
                }
                if (Found == false)
                {
                    Added.Add(SMARTDevice);
                }
            }

            foreach (VulpesSMARTInfo SMARTDevice in InDB)
            {
                bool Found = false;
                foreach (VulpesSMARTInfo i in SMART.List)
                {
                    if (SMARTDescription.ComparePart(SMARTDevice, i) == true)
                    {
                        Found = true;
                    }
                }
                if (Found == false)
                {
                    Removed.Add(SMARTDevice);
                }
            }

            foreach (VulpesSMARTInfo SMARTDevice in Added)
            {
                if (string.IsNullOrWhiteSpace(SMARTDevice.PNPDeviceID) == true)
                {
                    continue;
                }

                lock (ni.sqllock)
                {
                    sql.InsertMultiData("SMARTData",
                                        new SQLData("MachineID", SMART.MachineID),
                                        new SQLData("PNPDeviceID", SMARTDevice.PNPDeviceID == null ? "" : SMARTDevice.PNPDeviceID),
                                        new SQLData("Caption", SMARTDevice.Caption == null ? "" : SMARTDevice.Caption),
                                        new SQLData("FirmwareRevision", SMARTDevice.FirmwareRevision == null ? "" : SMARTDevice.FirmwareRevision),
                                        new SQLData("InterfaceType", SMARTDevice.InterfaceType == null ? "" : SMARTDevice.InterfaceType),
                                        new SQLData("Model", SMARTDevice.Model == null ? "" : SMARTDevice.Model),
                                        new SQLData("Name", SMARTDevice.Name == null ? "" : SMARTDevice.Name),
                                        new SQLData("PredictFailure", SMARTDevice.PredictFailure),
                                        new SQLData("SerialNumber", SMARTDevice.SerialNumber == null ? "" : SMARTDevice.SerialNumber),
                                        new SQLData("Size", SMARTDevice.Size),
                                        new SQLData("Status", SMARTDevice.Status == null ? "" : SMARTDevice.Status),
                                        new SQLData("DT", DateTime.UtcNow));

                    if (SMARTDevice.VendorSpecific != null)
                    {
                        sql.ExecSQL("UPDATE SMARTData SET VendorSpecific=@v WHERE MachineID=@id AND PNPDeviceID=@pnp",
                                    new SQLParam("@pnp", SMARTDevice.PNPDeviceID),
                                    new SQLParam("@id", SMART.MachineID),
                                    new SQLParam("@v", SMARTDevice.VendorSpecific));
                    }

                    if (SMARTDevice.VendorSpecificThreshold != null)
                    {
                        sql.ExecSQL("UPDATE SMARTData SET VendorSpecificThreshold=@v WHERE MachineID=@id AND PNPDeviceID=@pnp",
                                    new SQLParam("@pnp", SMARTDevice.PNPDeviceID),
                                    new SQLParam("@id", SMART.MachineID),
                                    new SQLParam("@v", SMARTDevice.VendorSpecificThreshold));
                    }
                }

                if (SMARTDevice.Attributes == null)
                {
                    SMARTDevice.Attributes = new Dictionary <int, VulpesSMARTAttribute>();
                }
                List <int> HasID = new List <int>();
                foreach (KeyValuePair <int, VulpesSMARTAttribute> kvp in SMARTDevice.Attributes)
                {
                    if (HasID.Contains(kvp.Value.ID) == true)
                    {
                        continue;
                    }
                    sql.InsertMultiData("SMARTDataAttributes",
                                        new SQLData("MachineID", SMART.MachineID),
                                        new SQLData("PNPDeviceID", SMARTDevice.PNPDeviceID),
                                        new SQLData("FailureImminent", kvp.Value.FailureImminent),
                                        new SQLData("Flags", kvp.Value.Flags),
                                        new SQLData("ID", kvp.Value.ID),
                                        new SQLData("Threshold", kvp.Value.Threshold),
                                        new SQLData("Value", kvp.Value.Value),
                                        new SQLData("Vendordata", kvp.Value.Vendordata),
                                        new SQLData("Worst", kvp.Value.Worst));
                    HasID.Add(kvp.Value.ID);
                }
            }

            foreach (VulpesSMARTInfo SMARTDevice in Removed)
            {
                if (string.IsNullOrWhiteSpace(SMARTDevice.PNPDeviceID) == true)
                {
                    continue;
                }

                lock (ni.sqllock)
                {
                    sql.ExecSQL("DELETE FROM SMARTDataAttributes WHERE MachineID=@id AND PNPDeviceID=@pnp",
                                new SQLParam("@id", SMART.MachineID),
                                new SQLParam("@pnp", SMARTDevice.PNPDeviceID));
                    sql.ExecSQL("DELETE FROM SMARTData WHERE MachineID=@id AND PNPDeviceID=@pnp",
                                new SQLParam("@id", SMART.MachineID),
                                new SQLParam("@pnp", SMARTDevice.PNPDeviceID));
                }
            }

            foreach (VulpesSMARTInfo SMARTDevice in Updated)
            {
                if (string.IsNullOrWhiteSpace(SMARTDevice.PNPDeviceID) == true)
                {
                    continue;
                }

                lock (ni.sqllock)
                {
                    sql.ExecSQL("DELETE FROM SMARTDataAttributes WHERE MachineID=@id AND PNPDeviceID=@pnp",
                                new SQLParam("@id", SMART.MachineID),
                                new SQLParam("@pnp", SMARTDevice.PNPDeviceID));
                    sql.ExecSQL("DELETE FROM SMARTData WHERE MachineID=@id AND PNPDeviceID=@pnp",
                                new SQLParam("@id", SMART.MachineID),
                                new SQLParam("@pnp", SMARTDevice.PNPDeviceID));
                }
                lock (ni.sqllock)
                {
                    sql.InsertMultiData("SMARTData",
                                        new SQLData("MachineID", SMART.MachineID),
                                        new SQLData("PNPDeviceID", SMARTDevice.PNPDeviceID),
                                        new SQLData("Caption", SMARTDevice.Caption == null ? "" : SMARTDevice.Caption),
                                        new SQLData("FirmwareRevision", SMARTDevice.FirmwareRevision == null ? "" : SMARTDevice.FirmwareRevision),
                                        new SQLData("InterfaceType", SMARTDevice.InterfaceType == null ? "" : SMARTDevice.InterfaceType),
                                        new SQLData("Model", SMARTDevice.Model == null ? "" : SMARTDevice.Model),
                                        new SQLData("Name", SMARTDevice.Name == null ? "" : SMARTDevice.Name),
                                        new SQLData("PredictFailure", SMARTDevice.PredictFailure),
                                        new SQLData("SerialNumber", SMARTDevice.SerialNumber == null ? "" : SMARTDevice.SerialNumber),
                                        new SQLData("Size", SMARTDevice.Size),
                                        new SQLData("Status", SMARTDevice.Status == null ? "" : SMARTDevice.Status),
                                        new SQLData("DT", DateTime.UtcNow));

                    if (SMARTDevice.VendorSpecific != null)
                    {
                        sql.ExecSQL("UPDATE SMARTData SET VendorSpecific=@v WHERE MachineID=@id AND PNPDeviceID=@pnp",
                                    new SQLParam("@pnp", SMARTDevice.PNPDeviceID),
                                    new SQLParam("@id", SMART.MachineID),
                                    new SQLParam("@v", SMARTDevice.VendorSpecific));
                    }

                    if (SMARTDevice.VendorSpecificThreshold != null)
                    {
                        sql.ExecSQL("UPDATE SMARTData SET VendorSpecificThreshold=@v WHERE MachineID=@id AND PNPDeviceID=@pnp",
                                    new SQLParam("@pnp", SMARTDevice.PNPDeviceID),
                                    new SQLParam("@id", SMART.MachineID),
                                    new SQLParam("@v", SMARTDevice.VendorSpecificThreshold));
                    }
                }
                if (SMARTDevice.Attributes == null)
                {
                    SMARTDevice.Attributes = new Dictionary <int, VulpesSMARTAttribute>();
                }
                List <int> HasID = new List <int>();
                foreach (KeyValuePair <int, VulpesSMARTAttribute> kvp in SMARTDevice.Attributes)
                {
                    if (HasID.Contains(kvp.Value.ID) == true)
                    {
                        continue;
                    }
                    sql.InsertMultiData("SMARTDataAttributes",
                                        new SQLData("MachineID", SMART.MachineID),
                                        new SQLData("PNPDeviceID", SMARTDevice.PNPDeviceID),
                                        new SQLData("FailureImminent", kvp.Value.FailureImminent),
                                        new SQLData("Flags", kvp.Value.Flags),
                                        new SQLData("ID", kvp.Value.ID),
                                        new SQLData("Threshold", kvp.Value.Threshold),
                                        new SQLData("Value", kvp.Value.Value),
                                        new SQLData("Vendordata", kvp.Value.Vendordata),
                                        new SQLData("Worst", kvp.Value.Worst));
                    HasID.Add(kvp.Value.ID);
                }
            }

            SmartDataLst l = new SmartDataLst();

            l.Added     = Added;
            l.Removed   = Removed;
            l.Unchanged = Unchanged;
            l.Updated   = Updated;
            l.InDB      = InDB;
            l.MachineID = SMART.MachineID;
            Thread t = new Thread(new ParameterizedThreadStart(new DReportingThread(ReportingThread)));

            t.Start(l);

            return(RESTStatus.Success);
        }
Beispiel #14
0
        public RESTStatus ReportDiskData(SQLLib sql, ListDiskDataReport DiskDataList, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            DiskDataList.MachineID = ni.Username;
            lock (ni.sqllock)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                                      new SQLParam("@m", DiskDataList.MachineID))) == 0)
                {
                    ni.Error   = "Invalid MachineID";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.NotFound);
                }
            }

            if (DiskDataList.Items == null)
            {
                ni.Error   = "Invalid Items";
                ni.ErrorID = ErrorFlags.InvalidValue;
                return(RESTStatus.Fail);
            }

            lock (ni.sqllock)
            {
                sql.ExecSQL("UPDATE DiskData SET DevicePresent=0 WHERE MachineID=@m",
                            new SQLParam("@m", DiskDataList.MachineID));
            }
            foreach (DiskDataReport dr in DiskDataList.Items)
            {
                lock (ni.sqllock)
                {
                    sql.ExecSQL("DELETE FROM DiskData WHERE MachineID=@m AND DeviceID=@d",
                                new SQLParam("@d", dr.DeviceID),
                                new SQLParam("@m", DiskDataList.MachineID));
                }
            }

            List <List <SQLData> > bulkdata = new List <List <SQLData> >();
            DateTime DT = DateTime.Now;

            DiskDataReport cdr = null;

            lock (ni.sqllock)
            {
                try
                {
                    sql.BeginTransaction();
                    sql.SEHError = true;

                    foreach (DiskDataReport dr in DiskDataList.Items)
                    {
                        sql.InsertMultiData("DiskData",
                                            new SQLData("MachineID", dr.MachineID),
                                            new SQLData("DevicePresent", true),
                                            new SQLData("LastUpdated", DT),
                                            new SQLData("DeviceID", dr.DeviceID),
                                            new SQLData("Access", dr.Access),
                                            new SQLData("Automount", dr.Automount),
                                            new SQLData("Availability", dr.Availability),
                                            new SQLData("Capacity", dr.Capacity),
                                            new SQLData("Caption", dr.Caption),
                                            new SQLData("Compressed", dr.Compressed),
                                            new SQLData("ConfigManagerErrorCode", dr.ConfigManagerErrorCode),
                                            new SQLData("Description", dr.Description),
                                            new SQLData("DirtyBitSet", dr.DirtyBitSet),
                                            new SQLData("DriveLetter", dr.DriveLetter),
                                            new SQLData("DriveType", dr.DriveType),
                                            new SQLData("ErrorDescription", dr.ErrorDescription),
                                            new SQLData("ErrorMethodology", dr.ErrorMethodology),
                                            new SQLData("FileSystem", dr.FileSystem),
                                            new SQLData("FreeSpace", dr.FreeSpace),
                                            new SQLData("Label", dr.Label),
                                            new SQLData("LastErrorCode", dr.LastErrorCode),
                                            new SQLData("MaximumFileNameLength", dr.MaximumFileNameLength),
                                            new SQLData("Name", dr.Name),
                                            new SQLData("PNPDeviceID", dr.PNPDeviceID),
                                            new SQLData("SerialNumber", dr.SerialNumber),
                                            new SQLData("Status", dr.Status));
                    }
                    sql.CommitTransaction();
                }
                catch (Exception ee)
                {
                    sql.RollBackTransaction();
                    FoxEventLog.WriteEventLog("DB Error: Cannot insert data to DiskData: " + ee.ToString() + "\r\n\r\nJSON: " +
                                              JsonConvert.SerializeObject(cdr, Formatting.Indented), System.Diagnostics.EventLogEntryType.Error);
                    return(RESTStatus.ServerError);
                }
                finally
                {
                    sql.SEHError = false;
                }
            }

            Thread t = new Thread(new ParameterizedThreadStart(new DReportingThread(ReportingThread)));

            t.Start(DiskDataList);

            return(RESTStatus.Success);
        }