Exemple #1
0
        public RESTStatus GetEarlyPackage(SQLLib sql, HttpListenerRequest request, HttpListenerResponse response, object dummy, NetworkConnectionInfo ni, Int64 id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false && ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;

                response.AddHeader("Content-Type", "text/plain; charset=UTF-8");
                response.StatusCode        = 403;
                response.StatusDescription = "Forbidden";
                byte[] data = Encoding.UTF8.GetBytes("403 - Forbidden.");
                response.ContentLength64 = data.LongLength;
                Stream output = response.OutputStream;
                output.Write(data, 0, data.Length);

                return(RESTStatus.Denied);
            }

            string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (AppPath.EndsWith("\\") == false)
            {
                AppPath += "\\";
            }
            AppPath += "Packages\\";

            return(ProvideUpdatePackage(AppPath + "SDCA-Early.foxpkg", request, response, ni));
        }
Exemple #2
0
        static public SQLLib ConnectSQL(string ApplicationName, int TimeOut = 600)
        {
            SQLLib sql = null;

            if (Settings.Default.DBType.ToLower() == "mssql")
            {
                sql = new SQLLib();
                sql.ApplicationName   = ApplicationName;
                sql.SqlCommandTimeout = TimeOut;
                if (sql.ConnectDatabase(Settings.Default.DBServer, Settings.Default.DBDB, true) == false)
                {
                    return(null);
                }
                sql.SEHError = true;
            }
            if (Settings.Default.DBType.ToLower() == "localdb")
            {
                sql = new SQLLib();
                sql.ApplicationName   = ApplicationName;
                sql.SqlCommandTimeout = TimeOut;
                if (sql.ConnectLocalDatabase(Settings.Default.DBLocalPath) == false)
                {
                    return(null);
                }
                sql.SEHError = true;
            }
            return(sql);
        }
Exemple #3
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 #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 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);
        }
Exemple #6
0
        List <VulpesSMARTInfo> LoadData(string MachineID, SQLLib sql)
        {
            List <VulpesSMARTInfo> lst = new List <VulpesSMARTInfo>();

            SqlDataReader dr = sql.ExecSQLReader("Select * from SMARTData WHERE MachineID=@id", new SQLParam("@id", MachineID));

            while (dr.Read())
            {
                VulpesSMARTInfo s = new VulpesSMARTInfo();
                sql.LoadIntoClass(dr, s);
                lst.Add(s);
            }
            dr.Close();

            foreach (VulpesSMARTInfo sm in lst)
            {
                sm.Attributes = new Dictionary <int, VulpesSMARTAttribute>();

                dr = sql.ExecSQLReader("Select * from SMARTDataAttributes WHERE MachineID=@id AND PnPDeviceID=@pnp",
                                       new SQLParam("@id", MachineID),
                                       new SQLParam("@pnp", sm.PNPDeviceID));
                while (dr.Read())
                {
                    VulpesSMARTAttribute attr = new VulpesSMARTAttribute();
                    sql.LoadIntoClass(dr, attr);
                    sm.Attributes.Add(attr.ID, attr);
                }
                dr.Close();
            }
            return(lst);
        }
Exemple #7
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 #8
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 #9
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 #10
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 #11
0
        public RESTStatus EnableDisablePolicy(SQLLib sql, PolicyEnableDisableRequest 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.NotFound);
                }
            }

            lock (ni.sqllock)
            {
                sql.ExecSQL("UPDATE Policies SET Enabled=@en WHERE ID=@id",
                            new SQLParam("@id", id),
                            new SQLParam("@en", request.Enable));
            }

            return(RESTStatus.Success);
        }
Exemple #12
0
        public static ComputerData GetComputerDetail(SQLLib sql, string MachineID)
        {
            if (MachineExists(sql, MachineID) == false)
            {
                return(null);
            }

            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", MachineID));
            ComputerData cd = null;

            while (dr.Read())
            {
                cd = new ComputerData();
                PutComputerData(dr, ref cd);
            }
            dr.Close();

            return(cd);
        }
Exemple #13
0
        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 #14
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);
        }
Exemple #15
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 #16
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 #17
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 #18
0
        public static void LoadSettings(SQLLib sql)
        {
            Settings.UseCertificate      = GetString(sql, "UseCertificate");
            Settings.KeepEventLogDays    = GetInt64(sql, "KeepEventLogDays");
            Settings.KeepBitlockerRK     = GetInt64(sql, "KeepBitlockerRK");
            Settings.KeepNonPresentDisks = GetInt64(sql, "KeepNonPresentDisks");
            Settings.KeepReports         = GetInt64(sql, "KeepReports");
            Settings.KeepChatLogs        = GetInt64(sql, "KeepChatLogs");

            Settings.EMailAdminTo          = GetString(sql, "EMailAdminTo");
            Settings.EMailFrom             = GetString(sql, "EMailFrom");
            Settings.EMailFromFriendly     = GetString(sql, "EMailFromFriendly");
            Settings.EMailPort             = GetInt(sql, "EMailPort");
            Settings.EMailServer           = GetString(sql, "EMailServer");
            Settings.EMailPassword         = GetString(sql, "EMailPassword");
            Settings.EMailUsername         = GetString(sql, "EMailUsername");
            Settings.EMailUseSSL           = GetBool(sql, "EMailUseSSL");
            Settings.LastScheduleRanAdmin  = GetDateTimex(sql, "LastScheduleRanAdmin");
            Settings.LastScheduleRanClient = GetDateTimex(sql, "LastScheduleRanClient");
            Settings.EMailAdminIsHTML      = GetBool(sql, "EMailAdminIsHTML", false);
            Settings.EMailClientIsHTML     = GetBool(sql, "EMailClientIsHTML", false);
            Settings.EMailAdminText        = GetString(sql, "EMailAdminText", "{URGENT}Report - {NMACHINES} machine{NMACHINESS} affected");
            Settings.EMailClientText       = GetString(sql, "EMailClientText", "{URGENT}Report for Client - {NMACHINES} machine{NMACHINESS} affected");
            Settings.EMailAdminSubject     = GetString(sql, "EMailAdminSubject", "Fox SDC - {URGENT}Report");
            Settings.EMailClientSubject    = GetString(sql, "EMailClientSubject", "Fox SDC - Client {URGENT}Report");
            Settings.AdminIPAddresses      = GetString(sql, "AdminIPAddresses");
            Settings.AdministratorName     = GetString(sql, "AdminstratorName", "Administrator");
            Settings.MessageDisclaimer     = GetString(sql, "MessageDisclaimer");

            try
            {
                Settings.EMailAdminScheduling = JsonConvert.DeserializeObject <SchedulerPlanning>(GetString(sql, "EMailAdminSched"));
                if (Settings.EMailAdminScheduling == null)
                {
                    Settings.EMailAdminScheduling = Scheduler.Nix;
                    PutString(sql, "EMailAdminSched", JsonConvert.SerializeObject(Settings.EMailAdminScheduling));
                }
            }
            catch
            {
                Settings.EMailAdminScheduling = Scheduler.Nix;
                PutString(sql, "EMailAdminSched", JsonConvert.SerializeObject(Settings.EMailAdminScheduling));
            }

            try
            {
                Settings.EMailClientScheduling = JsonConvert.DeserializeObject <SchedulerPlanning>(GetString(sql, "EMailClientSched"));
                if (Settings.EMailClientScheduling == null)
                {
                    Settings.EMailClientScheduling = Scheduler.Nix;
                    PutString(sql, "EMailClientSched", JsonConvert.SerializeObject(Settings.EMailClientScheduling));
                }
            }
            catch
            {
                Settings.EMailClientScheduling = Scheduler.Nix;
                PutString(sql, "EMailClientSched", JsonConvert.SerializeObject(Settings.EMailClientScheduling));
            }
        }
Exemple #19
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);
        }
Exemple #20
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 #21
0
 public static bool PolicyExsits(SQLLib sql, Int64 ID)
 {
     if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM Policies WHERE ID=@id",
                                           new SQLParam("@id", ID))) == 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #22
0
        static public bool SaveApplySettings2(SQLLib sql, ServerSettings newsettings)
        {
            Settings.LastScheduleRanAdmin  = newsettings.LastScheduleRanAdmin;
            Settings.LastScheduleRanClient = newsettings.LastScheduleRanClient;

            PutDateTimex(sql, "LastScheduleRanAdmin", Settings.LastScheduleRanAdmin);
            PutDateTimex(sql, "LastScheduleRanClient", Settings.LastScheduleRanClient);
            return(true);
        }
Exemple #23
0
 public static bool GroupExsits(SQLLib sql, Int64 GroupID)
 {
     if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM Grouping WHERE ID=@id",
                                           new SQLParam("@id", GroupID))) == 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #24
0
 public static bool MachineExists(SQLLib sql, string MachineID)
 {
     if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m",
                                           new SQLParam("@m", MachineID))) == 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #25
0
        public RESTStatus GetPackageMeta(SQLLib sql, HttpListenerRequest request, HttpListenerResponse response, object dummy, NetworkConnectionInfo ni, Int64 id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false && ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;

                response.AddHeader("Content-Type", "text/plain; charset=UTF-8");
                response.StatusCode        = 403;
                response.StatusDescription = "Forbidden";
                byte[] data = Encoding.UTF8.GetBytes("403 - Forbidden.");
                response.ContentLength64 = data.LongLength;
                Stream output = response.OutputStream;
                output.Write(data, 0, data.Length);

                return(RESTStatus.Denied);
            }

            if (PackageExists(sql, id) == false)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidID;

                response.AddHeader("Content-Type", "text/plain; charset=UTF-8");
                response.StatusCode        = 404;
                response.StatusDescription = "Not found";
                byte[] data = Encoding.UTF8.GetBytes("404 - Not found.");
                response.ContentLength64 = data.LongLength;
                Stream output = response.OutputStream;
                output.Write(data, 0, data.Length);

                return(RESTStatus.NotFound);
            }

            string MetaFilename = Convert.ToString(sql.ExecSQLScalar("SELECT MetaFilename FROM Packages WHERE ID=@id",
                                                                     new SQLParam("@id", id)));

            if (File.Exists(Settings.Default.DataPath + MetaFilename) == false)
            {
                ni.Error   = "Cannot find local file";
                ni.ErrorID = ErrorFlags.FileSystemError;

                response.AddHeader("Content-Type", "text/plain; charset=UTF-8");
                response.StatusCode        = 500;
                response.StatusDescription = "Server Error";
                byte[] data = Encoding.UTF8.GetBytes("500 - Server Error.");
                response.ContentLength64 = data.LongLength;
                Stream output = response.OutputStream;
                output.Write(data, 0, data.Length);

                return(RESTStatus.ServerError);
            }

            Downloader.ReadFileChunked(Settings.Default.DataPath + MetaFilename, request, response);

            return(RESTStatus.Success);
        }
Exemple #26
0
 public static bool PackageExists(SQLLib sql, Int64 id)
 {
     if (Convert.ToInt32(sql.ExecSQLScalar("Select count(*) FROM Packages WHERE ID=@id",
                                           new SQLParam("@id", id))) == 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #27
0
 public static bool STaskExsits(SQLLib sql, Int64 ID, string MID)
 {
     if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM SimpleTasks WHERE ID=@id AND MachineID=@mid",
                                           new SQLParam("@id", ID),
                                           new SQLParam("@mid", MID))) == 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #28
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 #29
0
 static bool PutBool(SQLLib sql, string SettingsName, bool Value)
 {
     if (sql.ExecSQL("if exists(select * from Config where [key]=@key) update Config set [Value]=@value where [key]=@key else insert into Config values(@key,@value)",
                     new SQLParam("@key", SettingsName),
                     new SQLParam("@value", Value == true ? "1" : "0")) == false)
     {
         return(false);
     }
     return(true);
 }
Exemple #30
0
 static bool PutDateTimex(SQLLib sql, string SettingsName, DateTime?Value)
 {
     if (sql.ExecSQL("if exists(select * from Config where [key]=@key) update Config set [Value]=@value where [key]=@key else insert into Config values(@key,@value)",
                     new SQLParam("@key", SettingsName),
                     new SQLParam("@value", Value == null ? "" : Value.Value.ToFileTime().ToString())) == false)
     {
         return(false);
     }
     return(true);
 }