Exemplo n.º 1
0
        public RESTStatus GetWindowsLicData(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (string.IsNullOrWhiteSpace(id) == true)
            {
                ni.Error   = "Missing Data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            lock (ni.sqllock)
            {
                if (Computers.MachineExists(sql, id) == false)
                {
                    ni.Error   = "Invalid MachineID";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.Fail);
                }
            }

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM WindowsLic WHERE MachineID=@m",
                                                     new SQLParam("@m", id));
                if (dr.HasRows == false)
                {
                    dr.Close();
                    ni.Error   = "No Data";
                    ni.ErrorID = ErrorFlags.NoData;
                    return(RESTStatus.Fail);
                }

                WindowsLicData = new WindowsLic();
                dr.Read();

                WindowsLicData.Description          = Convert.ToString(dr["Description"]);
                WindowsLicData.GracePeriodRemaining = Convert.ToInt64(dr["GracePeriodRemaining"]);
                WindowsLicData.LicenseFamily        = Convert.ToString(dr["LicenseFamily"]);
                WindowsLicData.LicenseStatus        = Convert.ToInt64(dr["LicenseStatus"]);
                WindowsLicData.LicenseStatusText    = Convert.ToString(dr["LicenseStatusText"]);
                WindowsLicData.MachineID            = Convert.ToString(dr["MachineID"]);
                WindowsLicData.Name = Convert.ToString(dr["Name"]);
                WindowsLicData.PartialProductKey = Convert.ToString(dr["PartialProductKey"]);
                WindowsLicData.ProductKeyChannel = Convert.ToString(dr["ProductKeyChannel"]);
                WindowsLicData.ProductKeyID      = Convert.ToString(dr["ProductKeyID"]);
                WindowsLicData.ProductKeyID2     = Convert.ToString(dr["ProductKeyID2"]);
                WindowsLicData.Reported          = SQLLib.GetDTUTC(dr["Reported"]);

                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 2
0
        public RESTStatus GetStartupItems(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            StartupsRep       = new ListStartupItemReport();
            StartupsRep.Items = new List <StartupItemFull>();

            lock (ni.sqllock)
            {
                SqlDataReader dr;
                if (string.IsNullOrWhiteSpace(id) == true)
                {
                    dr = sql.ExecSQLReader("select * from Startups inner join ComputerAccounts on ComputerAccounts.MachineID=Startups.MachineID left outer join UsersList on UsersList.SID=HKCUUser AND UsersList.MachineID=Startups.MachineID order by Location,[Key]");
                }
                else
                {
                    if (Computers.MachineExists(sql, id) == false)
                    {
                        ni.Error   = "Invalid data";
                        ni.ErrorID = ErrorFlags.InvalidData;
                        return(RESTStatus.NotFound);
                    }

                    dr = sql.ExecSQLReader("select * from Startups inner join ComputerAccounts on ComputerAccounts.MachineID=Startups.MachineID left outer join UsersList on UsersList.SID=HKCUUser AND UsersList.MachineID=Startups.MachineID WHERE ComputerAccounts.MachineID=@m order by Location,[Key]",
                                           new SQLParam("@m", id));
                }

                while (dr.Read())
                {
                    StartupItemFull ar = new StartupItemFull();
                    ar.Computername = Convert.ToString(dr["Computername"]);
                    ar.DT           = SQLLib.GetDTUTC(dr["DT"]);
                    ar.HKCUUser     = Convert.ToString(dr["HKCUUser"]);
                    ar.MachineID    = Convert.ToString(dr["MachineID"]);
                    ar.Username     = Convert.ToString(dr["Username"]);
                    ar.Item         = Convert.ToString(dr["Item"]);
                    ar.Key          = Convert.ToString(dr["Key"]);
                    ar.Location     = Convert.ToString(dr["Location"]);

                    StartupsRep.Items.Add(ar);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 3
0
        public RESTStatus ListRKData(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (string.IsNullOrWhiteSpace(id) == true)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.NotFound);
            }

            lock (ni.sqllock)
            {
                if (Computers.MachineExists(sql, id) == false)
                {
                    ni.Error   = "Invalid data";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }
            }

            LstRKData           = new BitlockerRKList();
            LstRKData.List      = new List <BitlockerRK>();
            LstRKData.MachineID = id;

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM BitlockerRK WHERE MachineID=@m",
                                                     new SQLParam("@m", id));
                while (dr.Read())
                {
                    BitlockerRK rk = new BitlockerRK();
                    rk.DeviceID    = Convert.ToString(dr["DeviceID"]);
                    rk.DriveLetter = Convert.ToString(dr["DriveLetter"]);
                    rk.Reported    = SQLLib.GetDTUTC(dr["Reported"]);
                    rk.Keys        = JsonConvert.DeserializeObject <List <BitlockerRKKeyElement> >(Convert.ToString(dr["Keys"]));
                    LstRKData.List.Add(rk);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 4
0
        public RESTStatus ListDevicesFilters(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (string.IsNullOrWhiteSpace(id) == true)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.NotFound);
            }

            lock (ni.sqllock)
            {
                if (Computers.MachineExists(sql, id) == false)
                {
                    ni.Error   = "Invalid data";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }
            }

            LstFltData           = new FilterDriverList();
            LstFltData.List      = new List <FilterDriver>();
            LstFltData.MachineID = id;

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM DevicesFilter WHERE MachineID=@mid", new SQLParam("@mid", id));
                while (dr.Read())
                {
                    FilterDriver n = new FilterDriver();
                    n.ClassGUID   = Convert.ToString(dr["ClassGUID"]);
                    n.ServiceName = Convert.ToString(dr["ServiceName"]);
                    n.Type        = Convert.ToInt32(dr["Type"]);
                    LstFltData.List.Add(n);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 5
0
        public RESTStatus ListSTasks(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            lock (ni.sqllock)
            {
                SqlDataReader dr;
                if (string.IsNullOrWhiteSpace(id) == false)
                {
                    if (Computers.MachineExists(sql, id) == false)
                    {
                        ni.Error   = "Access denied";
                        ni.ErrorID = ErrorFlags.InvalidData;
                        return(RESTStatus.NotFound);
                    }

                    dr = sql.ExecSQLReader("select SimpleTasks.*,ComputerName from SimpleTasks inner join ComputerAccounts on ComputerAccounts.MachineID=SimpleTasks.MachineID where SimpleTasks.MachineID=@m order by MachineID,Name",
                                           new SQLParam("@m", id));
                }
                else
                {
                    dr = sql.ExecSQLReader("select SimpleTasks.*,ComputerName from SimpleTasks inner join ComputerAccounts on ComputerAccounts.MachineID=SimpleTasks.MachineID order by MachineID,Name");
                }

                SimpleList      = new SimpleTaskLiteList();
                SimpleList.List = new List <SimpleTaskLite>();

                while (dr.Read())
                {
                    SimpleTaskLite d = new SimpleTaskLite();
                    sql.LoadIntoClass(dr, d);
                    SimpleList.List.Add(d);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 6
0
        public RESTStatus ListDiskData(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            lock (ni.sqllock)
            {
                SqlDataReader dr;
                if (string.IsNullOrWhiteSpace(id) == false)
                {
                    if (Computers.MachineExists(sql, id) == false)
                    {
                        ni.Error   = "Access denied";
                        ni.ErrorID = ErrorFlags.InvalidData;
                        return(RESTStatus.NotFound);
                    }

                    dr = sql.ExecSQLReader("select DiskData.*,ComputerName from DiskData inner join ComputerAccounts on ComputerAccounts.MachineID=DiskData.MachineID where diskData.MachineID=@m order by MachineID,Caption",
                                           new SQLParam("@m", id));
                }
                else
                {
                    dr = sql.ExecSQLReader("select DiskData.*,ComputerName from DiskData inner join ComputerAccounts on ComputerAccounts.MachineID=DiskData.MachineID order by MachineID,Caption");
                }

                LstDiskData       = new ListDiskDataReport();
                LstDiskData.Items = new List <DiskDataReport>();

                while (dr.Read())
                {
                    DiskDataReport d = new DiskDataReport();
                    sql.LoadIntoClass(dr, d);
                    LstDiskData.Items.Add(d);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 7
0
        public RESTStatus GetEventLogs(SQLLib sql, EventLogSearch eventlogsearch, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            EventLogs      = new EventLogReportFullList();
            EventLogs.Data = new List <EventLogReportFull>();

            if (eventlogsearch == null)
            {
                return(RESTStatus.Success);
            }

            if (eventlogsearch.QTY < 1)
            {
                eventlogsearch.QTY = 500;
            }

            string          SQLQuery     = "SELECT TOP " + eventlogsearch.QTY + " * FROM EventLog WHERE ";
            List <SQLParam> SQLQueryArgs = new List <SQLParam>();

            if (eventlogsearch.MachineID != null)
            {
                if (Computers.MachineExists(sql, eventlogsearch.MachineID) == false)
                {
                    ni.Error   = "Invalid Data";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }

                SQLQuery += "MachineID=@m AND ";
                SQLQueryArgs.Add(new SQLParam("@m", eventlogsearch.MachineID));
            }

            if (eventlogsearch.Source != null)
            {
                SQLQuery += "Source=@s AND ";
                SQLQueryArgs.Add(new SQLParam("@s", eventlogsearch.Source));
            }

            if (eventlogsearch.EventLogType != null)
            {
                SQLQuery += "EventLogType=@t AND ";
                SQLQueryArgs.Add(new SQLParam("@t", eventlogsearch.EventLogType));
            }

            if (eventlogsearch.FromDate != null)
            {
                SQLQuery += "TimeGenerated>=@tgf AND ";
                SQLQueryArgs.Add(new SQLParam("@tgf", eventlogsearch.FromDate));
            }

            if (eventlogsearch.ToDate != null)
            {
                SQLQuery += "TimeGenerated<=@tgt AND ";
                SQLQueryArgs.Add(new SQLParam("@tgt", eventlogsearch.ToDate));
            }

            if (eventlogsearch.EventLogBook != null)
            {
                SQLQuery += "EventLog=@evtb AND ";
                SQLQueryArgs.Add(new SQLParam("@evtb", eventlogsearch.EventLogBook));
            }

            if (eventlogsearch.CategoryNumber != null)
            {
                SQLQuery += "CategoryNumber=@catnum AND ";
                SQLQueryArgs.Add(new SQLParam("@catnum", eventlogsearch.CategoryNumber));
            }

            SQLQuery = SQLQuery.Trim();

            SQLQuery += "   1=1  ";

            SQLQuery += " ORDER BY TimeGenerated DESC";

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader(SQLQuery, SQLQueryArgs.ToArray());
                while (dr.Read())
                {
                    EventLogReportFull ev = new EventLogReportFull();
                    ev.Category               = Convert.ToString(dr["Category"]);
                    ev.CategoryNumber         = Convert.ToInt32(dr["CategoryNumber"]);
                    ev.Data                   = (byte[])dr["Data"];
                    ev.EventLog               = Convert.ToString(dr["EventLog"]);
                    ev.EventLogType           = Convert.ToInt32(dr["EventLogType"]);
                    ev.InstanceID             = Convert.ToInt64(dr["InstanceID"]);
                    ev.JSONReplacementStrings = Convert.ToString(dr["JSONReplacementStrings"]);
                    ev.LogID                  = Convert.ToString(dr["LogID"]);
                    ev.MachineID              = Convert.ToString(dr["MachineID"]);
                    ev.Message                = Convert.ToString(dr["Message"]);
                    ev.Reported               = SQLLib.GetDTUTC(dr["Reported"]);
                    ev.Source                 = Convert.ToString(dr["Source"]);
                    ev.TimeGenerated          = SQLLib.GetDTUTC(dr["TimeGenerated"]);
                    ev.TimeWritten            = SQLLib.GetDTUTC(dr["TimeWritten"]);
                    EventLogs.Data.Add(ev);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 8
0
        void ReportingThread(object StartupListO)
        {
            try
            {
                using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for Startup Data"))
                {
                    if (sql == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot connect to SQL Server for Startup Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }
                    StartupLst   StartupList  = (StartupLst)StartupListO;
                    ComputerData computerdata = Computers.GetComputerDetail(sql, StartupList.MachineID);
                    if (computerdata == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot get any computer data for Startup Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }

                    List <PolicyObject>        Pol             = Policies.GetPolicyForComputerInternal(sql, StartupList.MachineID);
                    Dictionary <string, Int64> AlreadyReported = new Dictionary <string, long>();
                    foreach (PolicyObject PolO in Pol)
                    {
                        if (PolO.Type != PolicyIDs.ReportingPolicy)
                        {
                            continue;
                        }
                        ReportingPolicyElement RepElementRoot = JsonConvert.DeserializeObject <ReportingPolicyElement>(Policies.GetPolicy(sql, PolO.ID).Data);
                        if (RepElementRoot.Type != ReportingPolicyType.Startup)
                        {
                            continue;
                        }
                        if (RepElementRoot.ReportToAdmin == null)
                        {
                            RepElementRoot.ReportToAdmin = false;
                        }
                        if (RepElementRoot.ReportToClient == null)
                        {
                            RepElementRoot.ReportToClient = false;
                        }
                        if (RepElementRoot.UrgentForAdmin == null)
                        {
                            RepElementRoot.UrgentForAdmin = false;
                        }
                        if (RepElementRoot.UrgentForClient == null)
                        {
                            RepElementRoot.UrgentForClient = false;
                        }
                        if (RepElementRoot.ReportToAdmin == false && RepElementRoot.ReportToClient == false && RepElementRoot.UrgentForAdmin == false && RepElementRoot.UrgentForClient == false)
                        {
                            continue;
                        }

                        foreach (string Element in RepElementRoot.ReportingElements)
                        {
                            ReportingPolicyElementStartup arprep = JsonConvert.DeserializeObject <ReportingPolicyElementStartup>(Element);
                            if (arprep.NotifyOnAdd == false && arprep.NotifyOnRemove == false && arprep.NotifyOnUpdate == false)
                            {
                                continue;
                            }

                            if (arprep.NotifyOnAdd == true)
                            {
                                foreach (StartupItem ar in GetFilteredData(StartupList.Added, computerdata, arprep))
                                {
                                    ReportThings(sql, StartupList.MachineID, "Add", ar, ref AlreadyReported, RepElementRoot);
                                }
                            }

                            if (arprep.NotifyOnUpdate == true)
                            {
                                foreach (StartupItem ar in GetFilteredData(StartupList.Updated, computerdata, arprep))
                                {
                                    ReportThings(sql, StartupList.MachineID, "Update", ar, ref AlreadyReported, RepElementRoot);
                                }
                            }

                            if (arprep.NotifyOnRemove == true)
                            {
                                foreach (StartupItem ar in GetFilteredData(StartupList.Removed, computerdata, arprep))
                                {
                                    ReportThings(sql, StartupList.MachineID, "Remove", ar, ref AlreadyReported, RepElementRoot);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                FoxEventLog.WriteEventLog("SEH in Startup Reporting " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
            }
        }
Exemplo n.º 9
0
        public RESTStatus CreatePolicy(SQLLib sql, NewPolicyReq request, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (request.Name == null || request.Name.Trim() == "")
            {
                ni.Error   = "Invalid name";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            request.Name = request.Name.Trim();

            if (request.Grouping != null && request.MachineID != null)
            {
                ni.Error   = "Either Grouping OR MachineID should be set";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            if (request.Grouping != null)
            {
                lock (ni.sqllock)
                {
                    if (Groups.GroupExsits(sql, request.Grouping.Value) == false)
                    {
                        ni.Error   = "Group does not exists";
                        ni.ErrorID = ErrorFlags.InvalidData;
                        return(RESTStatus.Fail);
                    }
                }
            }

            if (request.MachineID != null)
            {
                lock (ni.sqllock)
                {
                    if (Computers.MachineExists(sql, request.MachineID) == false)
                    {
                        ni.Error   = "MachineID does not exists";
                        ni.ErrorID = ErrorFlags.InvalidData;
                        return(RESTStatus.Fail);
                    }
                }
            }

            try
            {
                JsonConvert.DeserializeObject(request.Data);
            }
            catch
            {
                ni.Error   = "JSON error";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            NewPolicyID = new NetInt64();
            Int64?res;

            lock (ni.sqllock)
            {
                res = sql.InsertMultiDataID("Policies",
                                            new SQLData("Type", request.Type),
                                            new SQLData("Name", request.Name),
                                            new SQLData("Grouping", request.Grouping),
                                            new SQLData("MachineID", request.MachineID),
                                            new SQLData("DataBlob", request.Data),
                                            new SQLData("DT", DateTime.Now),
                                            new SQLData("Version", 1),
                                            new SQLData("Enabled", 0));
            }
            if (res == null)
            {
                ni.Error   = "SQL Error";
                ni.ErrorID = ErrorFlags.SQLError;
                return(RESTStatus.ServerError);
            }
            NewPolicyID.Data = res.Value;

            return(RESTStatus.Created);
        }
Exemplo n.º 10
0
        public RESTStatus EditPolicy(SQLLib sql, EditPolicy request, NetworkConnectionInfo ni, Int64 id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            lock (ni.sqllock)
            {
                if (Policies.PolicyExsits(sql, id) == false)
                {
                    ni.Error   = "Invalid data";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.Fail);
                }
            }

            if (id != request.ID)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            if (request.DataOnly == false)
            {
                if (request.Name == null || request.Name.Trim() == "")
                {
                    ni.Error   = "Invalid name";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.Fail);
                }

                request.Name = request.Name.Trim();

                if (request.Grouping != null && request.MachineID != null)
                {
                    ni.Error   = "Either Grouping OR MachineID should be set";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.Fail);
                }

                if (request.Grouping != null)
                {
                    lock (ni.sqllock)
                    {
                        if (Groups.GroupExsits(sql, request.Grouping.Value) == false)
                        {
                            ni.Error   = "Group does not exists";
                            ni.ErrorID = ErrorFlags.InvalidData;
                            return(RESTStatus.Fail);
                        }
                    }
                }

                if (request.MachineID != null)
                {
                    lock (ni.sqllock)
                    {
                        if (Computers.MachineExists(sql, request.MachineID) == false)
                        {
                            ni.Error   = "MachineID does not exists";
                            ni.ErrorID = ErrorFlags.InvalidData;
                            return(RESTStatus.Fail);
                        }
                    }
                }
            }

            try
            {
                JsonConvert.DeserializeObject(request.Data);
            }
            catch
            {
                ni.Error   = "JSON error";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            try
            {
                if (request.DataOnly == false)
                {
                    lock (ni.sqllock)
                    {
                        sql.ExecSQL("Update Policies SET Name=@n, Grouping=@g, MachineID=@m, DataBlob=@blob, DT=Getutcdate(), Version=Version+1 WHERE ID=@id",
                                    new SQLParam("@id", request.ID),
                                    new SQLParam("@n", request.Name),
                                    new SQLParam("@g", request.Grouping),
                                    new SQLParam("@m", request.MachineID),
                                    new SQLParam("@blob", request.Data));
                    }
                }
                else
                {
                    lock (ni.sqllock)
                    {
                        sql.ExecSQL("Update Policies SET DataBlob=@blob, DT=Getutcdate(), Version=Version+1 WHERE ID=@id",
                                    new SQLParam("@id", request.ID),
                                    new SQLParam("@blob", request.Data));
                    }
                }
            }
            catch
            {
                ni.Error   = "SQL Error";
                ni.ErrorID = ErrorFlags.SQLError;
                return(RESTStatus.ServerError);
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 11
0
        public RESTStatus GetAddRemovePrograms(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            AddRemoveRep       = new ListAddRemoveAppsReport();
            AddRemoveRep.Items = new List <AddRemoveAppReport>();

            lock (ni.sqllock)
            {
                SqlDataReader dr;
                if (string.IsNullOrWhiteSpace(id) == true)
                {
                    dr = sql.ExecSQLReader("select * from AddRemovePrograms inner join ComputerAccounts on ComputerAccounts.MachineID=AddRemovePrograms.MachineID left outer join UsersList on UsersList.SID=HKCUUser AND UsersList.MachineID=AddRemovePrograms.MachineID order by Name,VersionMajor,VersionMinor");
                }
                else
                {
                    if (Computers.MachineExists(sql, id) == false)
                    {
                        ni.Error   = "Invalid data";
                        ni.ErrorID = ErrorFlags.InvalidData;
                        return(RESTStatus.NotFound);
                    }

                    dr = sql.ExecSQLReader("select * from AddRemovePrograms inner join ComputerAccounts on ComputerAccounts.MachineID=AddRemovePrograms.MachineID left outer join UsersList on UsersList.SID=HKCUUser AND UsersList.MachineID=AddRemovePrograms.MachineID WHERE ComputerAccounts.MachineID=@m order by Name,VersionMajor,VersionMinor",
                                           new SQLParam("@m", id));
                }

                while (dr.Read())
                {
                    AddRemoveAppReport ar = new AddRemoveAppReport();
                    ar.Computername      = Convert.ToString(dr["Computername"]);
                    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.DT       = SQLLib.GetDTUTC(dr["DT"]);
                    ar.HKCUUser = Convert.ToString(dr["HKCUUser"]);
                    ar.Username = Convert.ToString(dr["Username"]);
                    if (string.IsNullOrWhiteSpace(ar.HKCUUser) == true)
                    {
                        ar.HKCUUser = "";
                    }

                    AddRemoveRep.Items.Add(ar);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 12
0
        public RESTStatus SetSTasks(SQLLib sql, SimpleTask NewTask, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (NewTask == null)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.NotFound);
            }

            if (string.IsNullOrWhiteSpace(NewTask.Name) == true || string.IsNullOrWhiteSpace(NewTask.Data) == true || NewTask.Type < 1)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.NotFound);
            }

            if (NewTask.ExecAfter != null)
            {
                if (NewTask.ExecAfter.Value.Year < 2010)
                {
                    ni.Error   = "ExecAfter is invalid";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }
            }

            lock (ni.sqllock)
            {
                if (Computers.MachineExists(sql, NewTask.MachineID) == false)
                {
                    ni.Error   = "Invalid data";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }

                Int64?ID = sql.InsertMultiDataID("SimpleTasks",
                                                 new SQLData("MachineID", NewTask.MachineID),
                                                 new SQLData("Type", NewTask.Type),
                                                 new SQLData("Name", NewTask.Name),
                                                 new SQLData("ExecAfter", NewTask.ExecAfter),
                                                 new SQLData("Data", NewTask.Data));

                if (ID == null)
                {
                    ni.Error   = "Server error";
                    ni.ErrorID = ErrorFlags.SQLError;
                    return(RESTStatus.ServerError);
                }

                NewTaskID      = new NetInt64();
                NewTaskID.Data = ID.Value;
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 13
0
        public RESTStatus ListDevicesData(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (string.IsNullOrWhiteSpace(id) == true)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.NotFound);
            }

            lock (ni.sqllock)
            {
                if (Computers.MachineExists(sql, id) == false)
                {
                    ni.Error   = "Invalid data";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }
            }

            LstDevData           = new PnPDeviceList();
            LstDevData.List      = new List <PnPDevice>();
            LstDevData.MachineID = id;

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM DevicesConfig WHERE MachineID=@mid", new SQLParam("@mid", id));
                while (dr.Read())
                {
                    PnPDevice n = new PnPDevice();
                    n.Availability            = Convert.ToInt32(dr["Availability"]);
                    n.Caption                 = Convert.ToString(dr["Caption"]);
                    n.ClassGuid               = Convert.ToString(dr["ClassGuid"]);
                    n.ConfigManagerErrorCode  = Convert.ToInt32(dr["ConfigManagerErrorCode"]);
                    n.ConfigManagerUserConfig = Convert.ToBoolean(dr["ConfigManagerUserConfig"]);
                    n.CreationClassName       = Convert.ToString(dr["CreationClassName"]);
                    n.Description             = Convert.ToString(dr["Description"]);
                    n.ErrorCleared            = dr["ErrorCleared"] is DBNull ? (bool?)null : Convert.ToBoolean(dr["ErrorCleared"]);
                    n.ErrorDescription        = Convert.ToString(dr["ErrorDescription"]);
                    n.Index         = Convert.ToInt32(dr["Index"]);
                    n.InstallDate   = dr["InstallDate"] is DBNull ? (DateTime?)null : SQLLib.GetDTUTC(dr["InstallDate"]);
                    n.LastErrorCode = dr["LastErrorCode"] is DBNull ? (int?)null : Convert.ToInt32(dr["LastErrorCode"]);
                    n.Manufacturer  = Convert.ToString(dr["Manufacturer"]);
                    n.Name          = Convert.ToString(dr["Name"]);
                    n.PNPClass      = Convert.ToString(dr["PNPClass"]);
                    n.PNPDeviceID   = Convert.ToString(dr["PNPDeviceID"]);
                    n.Present       = Convert.ToBoolean(dr["Present"]);
                    n.Service       = Convert.ToString(dr["Service"]);
                    n.Status        = Convert.ToString(dr["Status"]);
                    n.StatusInfo    = dr["StatusInfo"] is DBNull ? (int?)null : Convert.ToInt32(dr["StatusInfo"]);
                    n.HardwareID    = JsonConvert.DeserializeObject <List <string> >(Convert.ToString(dr["HardwareID"]));
                    n.CompatibleID  = JsonConvert.DeserializeObject <List <string> >(Convert.ToString(dr["CompatibleID"]));
                    LstDevData.List.Add(n);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemplo n.º 14
0
        void ReportingThread(object SmartDataListO)
        {
            try
            {
                using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for SMART Device Data"))
                {
                    if (sql == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot connect to SQL Server for SMART Device Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }
                    SmartDataLst SmartDataList = (SmartDataLst)SmartDataListO;
                    ComputerData computerdata  = Computers.GetComputerDetail(sql, SmartDataList.MachineID);
                    if (computerdata == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot get any computer data for SMART Device Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }

                    List <PolicyObject>        Pol             = Policies.GetPolicyForComputerInternal(sql, SmartDataList.MachineID);
                    Dictionary <string, Int64> AlreadyReported = new Dictionary <string, long>();
                    foreach (PolicyObject PolO in Pol)
                    {
                        if (PolO.Type != PolicyIDs.ReportingPolicy)
                        {
                            continue;
                        }
                        ReportingPolicyElement RepElementRoot = JsonConvert.DeserializeObject <ReportingPolicyElement>(Policies.GetPolicy(sql, PolO.ID).Data);
                        if (RepElementRoot.Type != ReportingPolicyType.SMART)
                        {
                            continue;
                        }
                        if (RepElementRoot.ReportToAdmin == null)
                        {
                            RepElementRoot.ReportToAdmin = false;
                        }
                        if (RepElementRoot.ReportToClient == null)
                        {
                            RepElementRoot.ReportToClient = false;
                        }
                        if (RepElementRoot.UrgentForAdmin == null)
                        {
                            RepElementRoot.UrgentForAdmin = false;
                        }
                        if (RepElementRoot.UrgentForClient == null)
                        {
                            RepElementRoot.UrgentForClient = false;
                        }
                        if (RepElementRoot.ReportToAdmin == false && RepElementRoot.ReportToClient == false && RepElementRoot.UrgentForAdmin == false &&
                            RepElementRoot.UrgentForClient == false)
                        {
                            continue;
                        }

                        foreach (string Element in RepElementRoot.ReportingElements)
                        {
                            ReportingPolicyElementSMART arprep = JsonConvert.DeserializeObject <ReportingPolicyElementSMART>(Element);
                            if (arprep.NotifyOnAdd == false && arprep.NotifyOnRemove == false && arprep.NotifyOnUpdate == false &&
                                arprep.NotifyOnError == false)
                            {
                                continue;
                            }

                            if (arprep.NotifyOnAdd == true)
                            {
                                foreach (VulpesSMARTInfo ar in SmartDataList.Added)
                                {
                                    ReportThings(sql, SmartDataList.MachineID, "Add", ar, ref AlreadyReported, RepElementRoot);
                                }
                            }

                            if (arprep.NotifyOnUpdate == true)
                            {
                                foreach (VulpesSMARTInfo ar in SmartDataList.Updated)
                                {
                                    foreach (VulpesSMARTInfo indbvsm in SmartDataList.InDB)
                                    {
                                        if (indbvsm.PNPDeviceID == ar.PNPDeviceID)
                                        {
                                            if (SMARTDescription.CompareFull(ar, indbvsm, arprep.SkipAttribUpdateReport) == false)
                                            {
                                                if (indbvsm.Attributes != null)
                                                {
                                                    List <int> UpdatedAttribs = new List <int>();
                                                    if (ar.Attributes == null)
                                                    {
                                                        ar.Attributes = new Dictionary <int, VulpesSMARTAttribute>();
                                                    }
                                                    foreach (KeyValuePair <int, VulpesSMARTAttribute> indb in indbvsm.Attributes)
                                                    {
                                                        if (ar.Attributes.ContainsKey(indb.Key) == true)
                                                        {
                                                            if (ar.Attributes[indb.Key].FailureImminent != indb.Value.FailureImminent ||
                                                                ar.Attributes[indb.Key].Flags != indb.Value.Flags ||
                                                                ar.Attributes[indb.Key].ID != indb.Value.ID ||
                                                                ar.Attributes[indb.Key].Threshold != indb.Value.Threshold ||
                                                                ar.Attributes[indb.Key].Value != indb.Value.Value ||
                                                                ar.Attributes[indb.Key].Vendordata != indb.Value.Vendordata ||
                                                                ar.Attributes[indb.Key].Worst != indb.Value.Worst)
                                                            {
                                                                UpdatedAttribs.Add(indb.Key);
                                                            }
                                                        }
                                                    }
                                                    ReportThings(sql, SmartDataList.MachineID, "Update", ar, ref AlreadyReported, RepElementRoot, UpdatedAttribs);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (arprep.NotifyOnRemove == true)
                            {
                                foreach (VulpesSMARTInfo ar in SmartDataList.Removed)
                                {
                                    ReportThings(sql, SmartDataList.MachineID, "Remove", ar, ref AlreadyReported, RepElementRoot);
                                }
                            }

                            if (arprep.NotifyOnError == true)
                            {
                                foreach (VulpesSMARTInfo ar in SmartDataList.Added)
                                {
                                    if (SMARTDescription.IsInError(ar) == true)
                                    {
                                        ReportThings(sql, SmartDataList.MachineID, "Error", ar, ref AlreadyReported, RepElementRoot);
                                    }
                                }
                                foreach (VulpesSMARTInfo ar in SmartDataList.Updated)
                                {
                                    if (SMARTDescription.IsInError(ar) == true)
                                    {
                                        foreach (VulpesSMARTInfo indbvsm in SmartDataList.InDB)
                                        {
                                            if (indbvsm.PNPDeviceID == ar.PNPDeviceID)
                                            {
                                                if (SMARTDescription.CompareFullCriticalOnly(indbvsm, ar) == false)
                                                {
                                                    ReportThings(sql, SmartDataList.MachineID, "Error", ar, ref AlreadyReported, RepElementRoot);
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                FoxEventLog.WriteEventLog("SEH in SMART Data Reporting " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
            }
        }
Exemplo n.º 15
0
        void ReportingThread(object DiskDataListO)
        {
            try
            {
                using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for DiskData"))
                {
                    if (sql == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot connect to SQL Server for Disk Data Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }
                    ListDiskDataReport  DiskDataList = (ListDiskDataReport)DiskDataListO;
                    List <PolicyObject> Pol          = Policies.GetPolicyForComputerInternal(sql, DiskDataList.MachineID);

                    Dictionary <string, Int64> AlreadyReported = new Dictionary <string, long>();
                    foreach (PolicyObject PolO in Pol)
                    {
                        if (PolO.Type != PolicyIDs.ReportingPolicy)
                        {
                            continue;
                        }
                        ReportingPolicyElement RepElementRoot = JsonConvert.DeserializeObject <ReportingPolicyElement>(Policies.GetPolicy(sql, PolO.ID).Data);
                        if (RepElementRoot.Type != ReportingPolicyType.Disk)
                        {
                            continue;
                        }

                        foreach (string Element in RepElementRoot.ReportingElements)
                        {
                            ReportingPolicyElementDisk diskrep = JsonConvert.DeserializeObject <ReportingPolicyElementDisk>(Element);
                            if (diskrep.DriveLetter == null)
                            {
                                continue;
                            }
                            if (diskrep.DriveLetter.Length != 1)
                            {
                                continue;
                            }

                            foreach (DiskDataReport DD in DiskDataList.Items)
                            {
                                string Drive = diskrep.DriveLetter;

                                if (diskrep.DriveLetter == "$")
                                {
                                    ComputerData d = Computers.GetComputerDetail(sql, DiskDataList.MachineID);
                                    if (d != null)
                                    {
                                        if (string.IsNullOrWhiteSpace(d.SystemRoot) == false)
                                        {
                                            Drive = d.SystemRoot.Substring(0, 1);
                                        }
                                    }
                                }

                                if (string.IsNullOrWhiteSpace(DD.DriveLetter) == true)
                                {
                                    continue;
                                }
                                if (DD.DriveLetter.ToLower().Substring(0, 1) != Drive.ToLower())
                                {
                                    continue;
                                }

                                Int64 SZLimit;

                                if (diskrep.Method == 1)
                                {
                                    SZLimit = (Int64)((100m / (decimal)DD.Capacity) * (decimal)diskrep.MinimumSize);
                                }
                                else
                                {
                                    SZLimit = diskrep.MinimumSize;
                                }

                                if (DD.FreeSpace < SZLimit)
                                {
                                    bool ReportToAdmin   = RepElementRoot.ReportToAdmin.Value;
                                    bool ReportToClient  = RepElementRoot.ReportToClient.Value;
                                    bool UrgentForAdmin  = RepElementRoot.UrgentForAdmin.Value;
                                    bool UrgentForClient = RepElementRoot.UrgentForClient.Value;

                                    if (AlreadyReported.ContainsKey(DD.DriveLetter) == true)
                                    {
                                        if ((AlreadyReported[DD.DriveLetter] & (Int64)ReportingFlags.ReportToAdmin) != 0)
                                        {
                                            ReportToAdmin = false;
                                        }
                                        if ((AlreadyReported[DD.DriveLetter] & (Int64)ReportingFlags.ReportToClient) != 0)
                                        {
                                            ReportToClient = false;
                                        }
                                        if ((AlreadyReported[DD.DriveLetter] & (Int64)ReportingFlags.UrgentForAdmin) != 0)
                                        {
                                            UrgentForAdmin = false;
                                        }
                                        if ((AlreadyReported[DD.DriveLetter] & (Int64)ReportingFlags.UrgentForClient) != 0)
                                        {
                                            UrgentForClient = false;
                                        }
                                    }

                                    if (ReportToAdmin == false && ReportToClient == false && UrgentForAdmin == false && UrgentForClient == false)
                                    {
                                        continue;
                                    }
                                    ReportingFlags Flags = (ReportToAdmin == true ? ReportingFlags.ReportToAdmin : 0) |
                                                           (ReportToClient == true ? ReportingFlags.ReportToClient : 0) |
                                                           (UrgentForAdmin == true ? ReportingFlags.UrgentForAdmin : 0) |
                                                           (UrgentForClient == true ? ReportingFlags.UrgentForClient : 0);
                                    ReportingProcessor.ReportDiskData(sql, DiskDataList.MachineID, DD.DriveLetter, SZLimit, DD.FreeSpace, DD.Capacity, Flags);
                                    if (AlreadyReported.ContainsKey(DD.DriveLetter) == true)
                                    {
                                        AlreadyReported[DD.DriveLetter] |= (Int64)Flags;
                                    }
                                    else
                                    {
                                        AlreadyReported.Add(DD.DriveLetter, (Int64)Flags);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                FoxEventLog.WriteEventLog("SEH in Disk Data Reporting " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
            }
        }