Exemple #1
0
        public RESTStatus GetPackages(SQLLib sql, object dummy, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            PackageDataList       = new PackageDataList();
            PackageDataList.Items = new List <FoxSDC_Common.PackageData>();

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("Select * FROM Packages");

                while (dr.Read())
                {
                    PackageData pd = new PackageData();
                    sql.LoadIntoClass(dr, pd);
                    PackageDataList.Items.Add(pd);
                }

                dr.Close();
            }
            return(RESTStatus.Success);
        }
Exemple #2
0
        public RESTStatus GetSTask(SQLLib sql, object dummy, NetworkConnectionInfo ni, Int64 id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("select * from SimpleTasks WHERE ID=@id", new SQLParam("@id", id));
                if (dr.HasRows == false)
                {
                    dr.Close();
                    return(RESTStatus.NotFound);
                }

                SimpleTask = new SimpleTask();

                while (dr.Read())
                {
                    sql.LoadIntoClass(dr, SimpleTask);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemple #3
0
        public RESTStatus ChangeCommentsComputer(SQLLib sql, NetString comments, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

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

            if (comments.Data == null)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            lock (ni.sqllock)
            {
                sql.ExecSQL("UPDATE ComputerAccounts SET Comments=@c WHERE MachineID=@m",
                            new SQLParam("@m", id),
                            new SQLParam("@c", comments.Data));
            }

            return(RESTStatus.NoContent);
        }
Exemple #4
0
        public RESTStatus GetPackage(SQLLib sql, object dummy, 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 (PackageExists(sql, id) == false)
                {
                    ni.Error   = "Invalid data";
                    ni.ErrorID = ErrorFlags.InvalidID;
                    return(RESTStatus.NotFound);
                }
            }

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("Select * FROM Packages WHERE ID=@id",
                                                     new SQLParam("@id", id));
                dr.Read();

                PackageData = new PackageData();
                sql.LoadIntoClass(dr, PackageData);
                dr.Close();
            }
            return(RESTStatus.Success);
        }
Exemple #5
0
        public RESTStatus GetGroupDetails(SQLLib sql, object dummy, 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 (GroupExsits(sql, id) == false)
                {
                    ni.Error   = "Invalid data";
                    ni.ErrorID = ErrorFlags.InvalidID;
                    return(RESTStatus.NotFound);
                }
            }

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM Grouping WHERE ID=@id", new SQLParam("@id", id));
                while (dr.Read())
                {
                    GroupElement          = new GroupElement();
                    GroupElement.ID       = Convert.ToInt64(dr["ID"]);
                    GroupElement.Name     = Convert.ToString(dr["Name"]);
                    GroupElement.ParentID = dr["ParentID"] is DBNull ? (Int64?)null : Convert.ToInt64(dr["ParentID"]);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemple #6
0
        public RESTStatus GetSMARTInfos(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)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                                      new SQLParam("@m", id))) == 0)
                {
                    ni.Error   = "Invalid MachineID";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.NotFound);
                }
            }

            SMARTRet           = new VulpesSMARTInfoList();
            SMARTRet.MachineID = id;
            SMARTRet.List      = LoadData(id, sql);

            return(RESTStatus.Success);
        }
        public static bool SaveApplySettings(SQLLib sql, ServerSettings newsettings, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(false);
            }

            if (SaveApplySettings(sql, newsettings) == false)
            {
                ni.Error   = "Invalid settings";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(false);
            }

            string ErrorReason;

            if (Utilities.TestSign(out ErrorReason) == false)
            {
                FoxEventLog.WriteEventLog("Cannot test-sign with the certificate " + SettingsManager.Settings.UseCertificate + ": " + ErrorReason, EventLogEntryType.Warning);
            }

            return(true);
        }
Exemple #8
0
        public RESTStatus DeletePolicy(SQLLib sql, object dummy, 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 ID";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }
            }

            try
            {
                lock (ni.sqllock)
                {
                    sql.ExecSQL("DELETE FROM Policies WHERE ID=@id", new SQLParam("@id", id));
                }
            }
            catch
            {
                ni.Error   = "SQL Error";
                ni.ErrorID = ErrorFlags.SQLError;
                return(RESTStatus.ServerError);
            }

            return(RESTStatus.Success);
        }
Exemple #9
0
        public RESTStatus GetPolicyObject(SQLLib sql, object dummy, 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.NotFound);
                }
            }

            lock (ni.sqllock)
            {
                PolicyObj = GetPolicy(sql, id);
            }

            return(RESTStatus.Success);
        }
        bool CookieValidator(CookieCollection req, CookieCollection res)
        {
            string InternalRunningSessionID = req["MGMT-SessionID"].Value;

            if (string.IsNullOrWhiteSpace(InternalRunningSessionID) == true)
            {
                return(false);
            }
            NetworkConnectionInfo ni = NetworkConnection.GetSession(InternalRunningSessionID);

            if (ni == null)
            {
                return(false);
            }
            if (ni.ComputerLoggedIn == true)
            {
                return(false);
            }
            lock (RemoteNetworkConnectionWSCrosser.DictLock)
            {
                if (RemoteNetworkConnectionWSCrosser.Sessions.ContainsKey(SessionID) == false)
                {
                    return(false);
                }
                if (RemoteNetworkConnectionWSCrosser.Sessions[SessionID].MGMTUser != ni.Username)
                {
                    return(false);
                }
            }

            Debug.WriteLine("Cookie (MG) validated");
            return(true);
        }
Exemple #11
0
        public RESTStatus GetGroups(SQLLib sql, object dummy, NetworkConnectionInfo ni, Int64 id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            GroupList      = new GroupElementList();
            GroupList.List = new List <GroupElement>();

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("select * from Grouping WHERE ParentID=@p order by Name",
                                                     new SQLParam("@p", id));
                while (dr.Read())
                {
                    GroupElement ge = new GroupElement();
                    ge.ID       = Convert.ToInt64(dr["ID"]);
                    ge.Name     = Convert.ToString(dr["Name"]);
                    ge.ParentID = dr["ParentID"] is DBNull ? (Int64?)null : Convert.ToInt64(dr["ParentID"]);
                    GroupList.List.Add(ge);
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemple #12
0
        public RESTStatus DeleteGroup(SQLLib sql, object dummy, 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 (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM Grouping WHERE ID=@id",
                                                      new SQLParam("@id", id))) == 0)
                {
                    ni.Error   = "Group does not exist";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }
            }

            try
            {
                lock (ni.sqllock)
                {
                    sql.ExecSQL("DELETE FROM Grouping WHERE ID=@id", new SQLParam("@id", id));
                }
            }
            catch
            {
                ni.Error   = "SQL Error";
                ni.ErrorID = ErrorFlags.SQLError;
                return(RESTStatus.ServerError);
            }
            return(RESTStatus.Success);
        }
Exemple #13
0
        public RESTStatus CloneSession(SQLLib sql, object dummy, NetworkConnectionInfo ni)
        {
            string newID = NetworkConnection.NewSession();
            NetworkConnectionInfo cloneni = NetworkConnection.GetSession(newID);

            cloneni.Permissions = ni.Permissions;
            cloneni.LoggedIn    = true;
            cloneni.Username    = ni.Username;
            cloneni.Name        = ni.Name;
            cloneni.EMail       = ni.EMail;
            cloneni.FromClone   = true;
            cloneni.IPAddress   = ni.IPAddress;
            cloneni.IsLDAP      = ni.IsLDAP;

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

            Err         = new ErrorInfo();
            Err.Error   = "OK:" + newID;
            Err.ErrorID = (int)ErrorFlags.NoError;
            return(RESTStatus.Success);
        }
Exemple #14
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);
        }
        public static string NewSession()
        {
            NetworkConnectionInfo nc = new NetworkConnectionInfo();

            lock (Connections)
                Connections.Add(nc.ID, nc);
            return(nc.ID);
        }
Exemple #16
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);
        }
Exemple #17
0
 public RESTStatus Logoff(SQLLib sql, object dummy, NetworkConnectionInfo ni)
 {
     ni.RWLock.EnterWriteLock();
     NetworkConnection.DeleteSession(ni.ID);
     ni.RWLock.ExitWriteLock();
     Err         = new ErrorInfo();
     Err.Error   = "OK";
     Err.ErrorID = (int)ErrorFlags.NoError;
     return(RESTStatus.Success);
 }
Exemple #18
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);
        }
Exemple #19
0
        public RESTStatus GetEarlyUpdateVersion(SQLLib sql, object dummy, NetworkConnectionInfo ni)
        {
            if (CurrentEarlyVersion == null)
            {
                return(RESTStatus.NotFound);
            }

            EarlyVersion      = new NetInt64();
            EarlyVersion.Data = CurrentEarlyVersion.Value;

            return(RESTStatus.Success);
        }
Exemple #20
0
        public RESTStatus ListPolicies(SQLLib sql, object dummy, NetworkConnectionInfo ni, NameValueCollection QueryString)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (QueryString["MachineID"] != null && QueryString["Grouping"] != null)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            PolicyList       = new PolicyObjectList();
            PolicyList.Items = new List <PolicyObject>();

            bool AllPolicies = true;
            bool WithData    = false;
            int  tmp;

            int.TryParse(QueryString["AllPolicies"] == null ? "1" : QueryString["AllPolicies"], out tmp);
            AllPolicies = tmp == 1 ? true : false;
            int.TryParse(QueryString["WithData"] == null ? "0" : QueryString["WithData"], out tmp);
            WithData = tmp == 1 ? true : false;

            lock (ni.sqllock)
            {
                SqlDataReader dr = null;
                if (AllPolicies == true)
                {
                    dr = sql.ExecSQLReader("select * from Policies order by Name");
                }
                else
                {
                    dr = sql.ExecSQLReader("select * from Policies where " + (QueryString["Grouping"] == null ? " Grouping is null AND " : " Grouping=@grouping AND ") +
                                           (QueryString["MachineID"] == null ? " MachineID is null " : " MachineID=@machineid ") + " order by Name",
                                           new SQLParam("@machineid", QueryString["MachineID"]),
                                           new SQLParam("@grouping", QueryString["Grouping"]));
                }

                while (dr.Read())
                {
                    PolicyList.Items.Add(LoadPolicyDB(dr, WithData, false));
                }
                dr.Close();
            }

            return(RESTStatus.Success);
        }
Exemple #21
0
        public RESTStatus ReportRSOP(SQLLib sql, object RSOPData, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            //Keep older clients happy

            return(RESTStatus.Success);
        }
Exemple #22
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);
        }
Exemple #23
0
        public RESTStatus GetComputerDetail(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)
            {
                if (MachineExists(sql, id) == false)
                {
                    ni.Error   = "Invalid data";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }
            }

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader(@"
                WITH GroupingRecursive(ID, Name, ParentID, LEVEL, Path) AS
                (SELECT ID, name, ParentID, 0 AS LEVEL,
                CAST(name AS nvarchar(max)) AS treepath
                FROM Grouping
                WHERE ParentID IS NULL
                UNION ALL
                SELECT d.ID, d.Name, d.ParentID,
                GroupingRecursive.LEVEL + 1 AS LEVEL,
                CAST(GroupingRecursive.Path + '\' +
                CAST(d.Name AS nvarchar(max)) AS NVARCHAR(max)) AS treepath
                FROM Grouping as d
                INNER JOIN GroupingRecursive
                ON GroupingRecursive.ID = d.ParentID)
                select *,(SELECT Path FROM GroupingRecursive WHERE ID=ComputerAccounts.Grouping) as Path from ComputerAccounts WHERE MachineID=@id order by ComputerName",
                                                     new SQLParam("@id", id));
                ComputerData cd = null;
                while (dr.Read())
                {
                    cd = new ComputerData();
                    PutComputerData(dr, ref cd);
                }
                dr.Close();
                ComputerDataInfo = cd;
            }

            return(RESTStatus.Success);
        }
Exemple #24
0
        public RESTStatus RunAdminNowREST(SQLLib sql, object dummy, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            RunAdminNow = true;
            Dummy       = new NetString();
            Dummy.Data  = "OK";

            return(RESTStatus.Success);
        }
Exemple #25
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);
        }
Exemple #26
0
        static public bool DeInitNi(NetworkConnectionInfo ni, bool KickPushService)
        {
            if (ni == null)
            {
                return(true);
            }
            if (ni.PushChannel != null)
            {
                if (KickPushService == true)
                {
                    PushServiceHelper.DeletePushService(ni.Username, ni.PushChannel.Value);
                }
            }

            Debug.WriteLine("DeInitNI " + ni.ID);
            try
            {
                if (ni.sql != null)
                {
                    ni.sql.Dispose();
                }
            }
            catch
            {
            }
            try
            {
                if (ni.Upload != null)
                {
                    ni.Upload.Data.Close();
                }
            }
            catch
            {
            }

            /*try
             * {
             *  if (ni.Download != null)
             *      ni.Download.Data.Close();
             * }
             * catch
             * {
             *
             * }*/
            return(true);
        }
Exemple #27
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);
        }
Exemple #28
0
        public RESTStatus CompleteSTask(SQLLib sql, SimpleTaskResult STaskResult, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

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

            lock (ni.sqllock)
            {
                STaskResult.MachineID = ni.Username;
                if (STaskExsits(sql, STaskResult.ID, STaskResult.MachineID) == false)
                {
                    ni.Error   = "Invalid ID";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.NotFound);
                }
            }

            lock (ni.sqllock)
            {
                STaskResult.Name = Convert.ToString(sql.ExecSQLScalar("SELECT Name FROM SimpleTasks WHERE ID=@id",
                                                                      new SQLParam("@id", STaskResult.ID)));
            }

            lock (ni.sqllock)
            {
                sql.ExecSQL("DELETE FROM SimpleTasks WHERE ID=@id",
                            new SQLParam("@id", STaskResult.ID));
            }

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

            t.Start(STaskResult);

            return(RESTStatus.Success);
        }
Exemple #29
0
        public RESTStatus GetPackageSigned(SQLLib sql, object dummy, NetworkConnectionInfo ni, Int64 id)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

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

            PackageData pp = null;

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("Select * FROM Packages WHERE ID=@id",
                                                     new SQLParam("@id", id));
                dr.Read();

                pp = new PackageData();
                sql.LoadIntoClass(dr, pp);
                dr.Close();
            }

            PackageDataSigned         = new PackageDataSigned();
            PackageDataSigned.Package = pp;
            if (Certificates.Sign(PackageDataSigned, SettingsManager.Settings.UseCertificate) == false)
            {
                FoxEventLog.WriteEventLog("Cannot sign package element with Certificate " + SettingsManager.Settings.UseCertificate, System.Diagnostics.EventLogEntryType.Warning);
                ni.Error   = "Cannot sign package element with Certificate " + SettingsManager.Settings.UseCertificate;
                ni.ErrorID = ErrorFlags.CannotSign;
                return(RESTStatus.ServerError);
            }

            return(RESTStatus.Success);
        }
Exemple #30
0
        public RESTStatus GetPolicyObjectSigned(SQLLib sql, object dummy, NetworkConnectionInfo ni, Int64 id)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == 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.NotFound);
                }
            }

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("select * from Policies where ID=@id", new SQLParam("@id", id));
                while (dr.Read())
                {
                    PolicyObj = LoadPolicyDB(dr, true, true);
                }
                dr.Close();
            }

            PolicyObjectSigned objs = new PolicyObjectSigned();

            objs.Policy = PolicyObj;
            if (Certificates.Sign(objs, SettingsManager.Settings.UseCertificate) == false)
            {
                FoxEventLog.WriteEventLog("Cannot sign policy with Certificate " + SettingsManager.Settings.UseCertificate, System.Diagnostics.EventLogEntryType.Warning);
                ni.Error   = "Cannot sign policy with Certificate " + SettingsManager.Settings.UseCertificate;
                ni.ErrorID = ErrorFlags.CannotSign;
                return(RESTStatus.ServerError);
            }

            PolicyObjSigned = objs;

            return(RESTStatus.Success);
        }