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

            PushData data = PushServiceHelper.WaitForPush(ni, 10);

            if (data == null)
            {
                ni.Error   = "Push Service Error";
                ni.ErrorID = ErrorFlags.SystemError;
                return(RESTStatus.ServerError);
            }

            ReturnData      = new PushDataRoot();
            ReturnData.Data = data;

            if (Certificates.Sign(ReturnData, SettingsManager.Settings.UseCertificate) == false)
            {
                ni.Error   = "Push Service Signing Error";
                ni.ErrorID = ErrorFlags.SystemError;
                return(RESTStatus.ServerError);
            }

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

            string MachineID = ni.Username;

            ChatList2      = new PushChatMessageList();
            ChatList2.List = new List <PushChatMessage>();

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("select * from Chats where [Read]=0 AND MachineID=@m AND ToClient=1 ORDER BY DT ASC",
                                                     new SQLParam("@m", MachineID));
                while (dr.Read())
                {
                    PushChatMessage pch = new PushChatMessage();
                    pch.ID   = Convert.ToInt64(dr["ID"]);
                    pch.DT   = SQLLib.GetDTUTC(dr["DT"]);
                    pch.Name = Convert.ToString(dr["Name"]);
                    pch.Text = Convert.ToString(dr["Text"]);
                    ChatList2.List.Add(pch);
                }
                dr.Close();
            }

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

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

            if (ni.PushChannel == null)
            {
                ni.Error   = "Too early";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            if (PushServiceHelper.PushResponse(ni.Username, pdr, ni.PushChannel.Value, true) == false)
            {
                ni.Error   = "Cannot push";
                ni.ErrorID = ErrorFlags.SystemError;
                return(RESTStatus.ServerError);
            }

            return(RESTStatus.Success);
        }
Exemple #4
0
        public RESTStatus GetFileDataMgmt(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 COUNT(*) FROM FileTransfers WHERE ID=@id",
                                                     new SQLParam("@id", ID));
                if (dr.HasRows == false)
                {
                    ni.Error   = "Not found";
                    ni.ErrorID = ErrorFlags.InvalidID;
                    dr.Close();
                    return(RESTStatus.NotFound);
                }

                dr.Read();

                UploadedData2 = FillUploadData(dr);

                dr.Close();
            }

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

            UserLists      = new UserDetailsList();
            UserLists.List = new List <UserDetails>();

            SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM Users ORDER BY Username");

            while (dr.Read())
            {
                UserDetails d = new UserDetails();
                d.EMail              = Convert.ToString(dr["EMail"]);
                d.LDAPUsername       = Convert.ToString(dr["LDAPUsername"]);
                d.MustChangePassword = Convert.ToBoolean(dr["MustChangePassword"]);
                d.Name        = Convert.ToString(dr["Name"]);
                d.Permissions = Convert.ToInt64(dr["Permissions"]);
                d.UseLDAP     = Convert.ToBoolean(dr["UseLDAP"]);
                d.Username    = Convert.ToString(dr["Username"]);
                UserLists.List.Add(d);
            }
            dr.Close();
            return(RESTStatus.Success);
        }
Exemple #6
0
        public RESTStatus GetFileList(SQLLib sql, object dummy, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            Int64List           = new NetInt64ListSigned();
            Int64List.data      = new NetInt64List2();
            Int64List.data.data = new List <long>();

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT ID FROM FileTransfers WHERE MachineID=@mid AND ((Size=ProgressSize AND Direction=0) OR (Direction=1)) ORDER BY RequestOnly ASC, ID ASC",
                                                     new SQLParam("@mid", ni.Username));
                while (dr.Read())
                {
                    Int64List.data.data.Add(Convert.ToInt64(dr["ID"]));
                }
                dr.Close();
            }

            if (Certificates.Sign(Int64List, 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);
            }

            return(RESTStatus.Success);
        }
Exemple #7
0
        public RESTStatus DeleteUser(SQLLib sql, NetString User, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Fail);
            }

            if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM Users WHERE Username=@u",
                                                  new SQLParam("@u", User.Data))) == 0)
            {
                ni.Error   = "Invalid User";
                ni.ErrorID = ErrorFlags.InvalidID;
                return(RESTStatus.Fail);
            }

            if (User.Data.ToLower().Trim() == "root")
            {
                ni.Error   = "Invalid User";
                ni.ErrorID = ErrorFlags.InvalidID;
                return(RESTStatus.Fail);
            }

            sql.ExecSQL("DELETE FROM Users WHERE Username=@u",
                        new SQLParam("@u", User.Data));

            return(RESTStatus.Success);
        }
Exemple #8
0
        public RESTStatus AddUser(SQLLib sql, NetString User, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Fail);
            }

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

            if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM Users WHERE Username=@u",
                                                  new SQLParam("@u", User.Data.Trim()))) != 0)
            {
                ni.Error   = "User already exists";
                ni.ErrorID = ErrorFlags.InvalidID;
                return(RESTStatus.Fail);
            }

            sql.InsertMultiData("Users",
                                new SQLData("Username", User.Data.Trim()),
                                new SQLData("Name", "new user"),
                                new SQLData("Permissions", 0),
                                new SQLData("Password", ""));

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

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

            users.MachineID = ni.Username;

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

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

            if (users.Users == null)
            {
                users.Users = new Dictionary <string, string>();
            }

            foreach (KeyValuePair <string, string> kvp in users.Users)
            {
                if (string.IsNullOrWhiteSpace(kvp.Key) == true || string.IsNullOrWhiteSpace(kvp.Value) == true)
                {
                    continue;
                }

                lock (ni.sqllock)
                {
                    sql.InsertMultiData("UsersList",
                                        new SQLData("MachineID", users.MachineID),
                                        new SQLData("SID", kvp.Key),
                                        new SQLData("Username", kvp.Value));
                }
            }

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

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

            CI       = new ContractInfosList();
            CI.Items = new List <ContractInfos>();

            if (Settings.Default.UseContract == false)
            {
                return(RESTStatus.Success);
            }
            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("select * from contracts order by ContractID");
                while (dr.Read())
                {
                    ContractInfos i = new ContractInfos();
                    i.IncludedComputers = new List <ComputerData>();
                    sql.LoadIntoClass(dr, i);
                    CI.Items.Add(i);
                }
                dr.Close();
            }

            foreach (ContractInfos i in CI.Items)
            {
                List <string> Machines = new List <string>();
                lock (ni.sqllock)
                {
                    SqlDataReader dr = sql.ExecSQLReader("select MachineID from ComputerAccounts where ContractID=@c",
                                                         new SQLParam("@c", i.ContractID));
                    while (dr.Read())
                    {
                        Machines.Add(Convert.ToString(dr["MachineID"]));
                    }
                    dr.Close();
                }

                foreach (string M in Machines)
                {
                    ComputerData c = Computers.GetComputerDetail(sql, M);
                    i.IncludedComputers.Add(c);
                }
            }

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

            ClientSettings = new ClientSettings();
            ClientSettings.AdministratorName = SettingsManager.Settings.AdministratorName;
            ClientSettings.MessageDisclaimer = SettingsManager.Settings.MessageDisclaimer;
            return(RESTStatus.Success);
        }
Exemple #13
0
        public RESTStatus GetPaperList(SQLLib sql, object dummy, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            RetListPaper       = new NetStringList();
            RetListPaper.Items = SupportedNames;

            return(RESTStatus.Success);
        }
Exemple #14
0
        public RESTStatus CancelUploadAgentToServer(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 (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM FileTransfers WHERE ID=@id AND MachineID=@mid AND Direction in (0,1)",
                                                      new SQLParam("@mid", ni.Username),
                                                      new SQLParam("@id", ID))) == 0)
                {
                    ni.Error   = "Invalid ID";
                    ni.ErrorID = ErrorFlags.InvalidData;
                    return(RESTStatus.Fail);
                }
            }

            string Filename = null;

            lock (ni.sqllock)
            {
                Filename = Settings.Default.DataPath + Convert.ToString(sql.ExecSQLScalar("SELECT ServerFile FROM FileTransfers WHERE ID=@id AND MachineID=@mid",
                                                                                          new SQLParam("@mid", ni.Username),
                                                                                          new SQLParam("@id", ID)));
            }

            if (File.Exists(Filename) == true)
            {
                try
                {
                    CommonUtilities.SpecialDeleteFile(Filename);
                }
                catch
                { }
            }

            lock (ni.sqllock)
            {
                sql.ExecSQLScalar("DELETE FROM FileTransfers WHERE ID=@id AND MachineID=@mid",
                                  new SQLParam("@mid", ni.Username),
                                  new SQLParam("@id", ID));
            }

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

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

            Paper = Paper.ToUpper().Trim();

            if (SupportedNames.Contains(Paper) == false)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            RetPaper      = new NetByte();
            RetPaper.Data = null;

            lock (ni.sqllock)
            {
                object o = sql.ExecSQLScalar("SELECT [data] from ReportPapers WHERE ID=@id",
                                             new SQLParam("@id", Paper));
                if (o is DBNull || o is null)
                {
                    switch (Paper)
                    {
                    case "COMPUTERREPORT":
                        RetPaper.Data = Resources.Computer_Report;
                        break;
                    }
                }
                else
                {
                    RetPaper.Data = (byte[])o;
                }
            }

            return(RESTStatus.Success);
        }
        public RESTStatus CloseWSServerMappingPort(SQLLib sql, NetString GUID, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            RemoteNetworkConnectionWSCrosser.CloseSession(ni.Username, GUID.Data);

            Res        = new PushConnectNetworkResult();
            Res.Result = 0;
            return(RESTStatus.Success);
        }
Exemple #17
0
        public RESTStatus PopSTDIOData(SQLLib sql, NetString StdIOSession, NetworkConnectionInfo ni, string MachineID)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            if (StdIOSession == null)
            {
                ni.Error   = "Missing Session Data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

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

            string           sess = "stdio-" + StdIOSession.Data;
            PushDataResponse resp = PushServiceHelper.PopResponse(MachineID, 0, sess, true);

            if (resp == null)
            {
                res           = new Push_Stdio_StdOut();
                res.SessionID = StdIOSession.Data;
                res.State     = PushStdoutState.Timeout;
                return(RESTStatus.NoContent);
            }

            try
            {
                res = JsonConvert.DeserializeObject <Push_Stdio_StdOut>(resp.Data.ToString());
            }
            catch
            {
                res           = new Push_Stdio_StdOut();
                res.SessionID = StdIOSession.Data;
                res.State     = PushStdoutState.InternalError;
                return(RESTStatus.NoContent);
            }

            return(RESTStatus.Success);
        }
Exemple #18
0
        public RESTStatus ChangeUser(SQLLib sql, UserDetailsPassword User, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Fail);
            }

            if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM Users WHERE Username=@u",
                                                  new SQLParam("@u", User.Username))) == 0)
            {
                ni.Error   = "Invalid User";
                ni.ErrorID = ErrorFlags.InvalidID;
                return(RESTStatus.Fail);
            }

            if (string.IsNullOrWhiteSpace(User.NewPassword) == false)
            {
                if (MeetPasswordPolicy(User.NewPassword) == false)
                {
                    ni.Error   = "Password policy not met";
                    ni.ErrorID = ErrorFlags.PWPolicyNotMet;
                    return(RESTStatus.Fail);
                }
                string PWMD5REQ = Convert.ToBase64String(Encoding.Unicode.GetBytes(User.NewPassword));
                sql.ExecSQL("UPDATE Users SET Password=@p WHERE Username=@u",
                            new SQLParam("@u", User.Username),
                            new SQLParam("@p", PWMD5REQ));
            }

            if (User.Username.ToLower().Trim() == "root")
            {
                User.Permissions = SQLTest.AllPermissions;
            }

            sql.ExecSQL("UPDATE Users SET Name=@n, Permissions=@p, MustChangePassword=@mchg,EMail=@email,UseLDAP=@UseLDAP,LDAPUsername=@LDAPUsername WHERE Username=@u",
                        new SQLParam("@u", User.Username),
                        new SQLParam("@n", User.Name),
                        new SQLParam("@p", User.Permissions),
                        new SQLParam("@mchg", User.MustChangePassword),
                        new SQLParam("@email", User.EMail),
                        new SQLParam("@useldap", User.UseLDAP),
                        new SQLParam("@LDAPUsername", User.LDAPUsername));

            return(RESTStatus.Success);
        }
Exemple #19
0
        public RESTStatus PushNetworkDataCreateConnection(SQLLib sql, PushConnectNetwork data, NetworkConnectionInfo ni, string MachineID)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            string SessionConnectionGUID = RemoteNetworkConnectionWSCrosser.CreateSession(ni.Username, MachineID);

            data.SessionID = SessionConnectionGUID;

            string sess = Guid.NewGuid().ToString();

            PushData p = new PushData();

            p.Action          = "netcreatedata2";
            p.ReplyID         = sess;
            p.AdditionalData1 = JsonConvert.SerializeObject(data);

            PushServiceHelper.SendPushService(MachineID, p, 1);
            PushDataResponse resp = PushServiceHelper.PopResponse(MachineID, 1, sess);

            if (resp == null)
            {
                ni.Error   = "No response";
                ni.ErrorID = ErrorFlags.NoData;
                RemoteNetworkConnectionWSCrosser.CloseSession(SessionConnectionGUID);
                return(RESTStatus.NoContent);
            }

            try
            {
                res1 = JsonConvert.DeserializeObject <PushConnectNetworkResult>(resp.Data.ToString());
            }
            catch
            {
                ni.Error   = "Faulty data";
                ni.ErrorID = ErrorFlags.NoData;
                RemoteNetworkConnectionWSCrosser.CloseSession(SessionConnectionGUID);
                return(RESTStatus.NoContent);
            }

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

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

            Paper = Paper.ToUpper().Trim();

            if (SupportedNames.Contains(Paper) == false)
            {
                ni.Error   = "Invalid data";
                ni.ErrorID = ErrorFlags.InvalidData;
                return(RESTStatus.Fail);
            }

            RetPaper      = new NetByte();
            RetPaper.Data = null;

            lock (ni.sqllock)
            {
                switch (Paper)
                {
                case "COMPUTERREPORT":
                    RetPaper.Data = RenderReport.RenderReportData(RenderReport.GetReportPaperData(sql, Paper, Resources.Computer_Report), new Dictionary <string, object>(), "PDF");
                    break;
                }
            }

            return(RESTStatus.Success);
#else
            ni.Error   = "Unsupported functionality";
            ni.ErrorID = ErrorFlags.SystemError;
            return(RESTStatus.Fail);
#endif
        }
Exemple #21
0
        public RESTStatus CheckFile(SQLLib sql, NetString Req, NetworkConnectionInfo ni, string MachineID)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            string guid = Guid.NewGuid().ToString();

            PushData p = new PushData();

            p.Action          = "checkfile";
            p.ReplyID         = guid;
            p.AdditionalData1 = Req.Data;

            PushServiceHelper.SendPushService(MachineID, p, 0);
            PushDataResponse resp = PushServiceHelper.PopResponse(MachineID, 0, guid);

            if (resp == null)
            {
                ni.Error   = "No response";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.NoContent);
            }

            try
            {
                FileRes = new NetInt32();
                if (Int32.TryParse(resp.Data.ToString(), out FileRes.Data) == false)
                {
                    ni.Error   = "Faulty data";
                    ni.ErrorID = ErrorFlags.NoData;
                    return(RESTStatus.NoContent);
                }
            }
            catch
            {
                ni.Error   = "Faulty data";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.NoContent);
            }
            return(RESTStatus.Success);
        }
Exemple #22
0
        public RESTStatus ChangeMyPassword(SQLLib sql, ChangePassword chgpw, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == true)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            ni.Error = "";

            if (ni.IsLDAP == true)
            {
                ni.Error   = "Password is LDAP";
                ni.ErrorID = ErrorFlags.IsLDAP;
                return(RESTStatus.Fail);
            }

            string PWMD5REQ = Convert.ToBase64String(Encoding.Unicode.GetBytes(chgpw.OldPassword));

            if (MeetPasswordPolicy(chgpw.NewPassword) == false)
            {
                ni.Error   = "Password policy not met";
                ni.ErrorID = ErrorFlags.PWPolicyNotMet;
                return(RESTStatus.Fail);
            }
            int Count = Convert.ToInt32(sql.ExecSQLScalar("SELECT Count(*) FROM Users WHERE Username=@u AND Password=@p",
                                                          new SQLParam("@u", ni.Username),
                                                          new SQLParam("@p", PWMD5REQ)));

            if (Count < 1)
            {
                ni.Error   = "Invalid old password";
                ni.ErrorID = ErrorFlags.InvalidPassword;
                return(RESTStatus.Fail);
            }
            string PWMD5New = Convert.ToBase64String(Encoding.Unicode.GetBytes(chgpw.NewPassword));

            sql.ExecSQLNQ("UPDATE Users SET Password=@pw, MustChangePassword=0 WHERE Username=@u",
                          new SQLParam("@u", ni.Username),
                          new SQLParam("@pw", PWMD5New));
            ni.MustChangePassword = false;

            return(RESTStatus.NoContent);
        }
Exemple #23
0
        public RESTStatus GetSettings(SQLLib sql, ServerSettings settings, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            lock (ni.sqllock)
            {
                if (SettingsManager.SaveApplySettings(sql, settings, ni) == false)
                {
                    return(RESTStatus.Fail);
                }
            }
            return(RESTStatus.NoContent);
        }
Exemple #24
0
        public RESTStatus ConfirmChat(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);
            }
            string MachineID = ni.Username;

            lock (ni.sqllock)
            {
                sql.ExecSQL("UPDATE Chats SET [Read]=1 WHERE MachineID=@m AND ID=@id",
                            new SQLParam("@m", MachineID),
                            new SQLParam("@id", ID));
            }
            return(RESTStatus.Success);
        }
Exemple #25
0
        public RESTStatus PushNetworkDataPull(SQLLib sql, PushConnectNetworkData data, NetworkConnectionInfo ni, string MachineID)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            string sess = Guid.NewGuid().ToString();

            data.data = null;

            PushData p = new PushData();

            p.Action          = "netdatapull";
            p.ReplyID         = sess;
            p.AdditionalData1 = JsonConvert.SerializeObject(data);

            PushServiceHelper.SendPushService(MachineID, p, 1);
            PushDataResponse resp = PushServiceHelper.PopResponse(MachineID, 1, sess);

            if (resp == null)
            {
                ni.Error   = "No response";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.NoContent);
            }

            try
            {
                resd = JsonConvert.DeserializeObject <PushConnectNetworkData>(resp.Data.ToString());
            }
            catch
            {
                ni.Error   = "Faulty data";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.NoContent);
            }

            return(RESTStatus.Success);
        }
Exemple #26
0
        public RESTStatus GetFileDataAny(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)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM FileTransfers WHERE ID=@id AND MachineID=@mid AND Direction in (0,1)",
                                                     new SQLParam("@mid", ni.Username),
                                                     new SQLParam("@id", ID));

                if (dr.HasRows == false)
                {
                    ni.Error   = "Not found";
                    ni.ErrorID = ErrorFlags.InvalidID;
                    dr.Close();
                    return(RESTStatus.NotFound);
                }

                dr.Read();

                UploadedData      = new FileUploadDataSigned();
                UploadedData.Data = FillUploadData(dr);
                dr.Close();
            }

            if (Certificates.Sign(UploadedData, 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);
            }


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

            FileUploadDataList      = new FileUploadDataList();
            FileUploadDataList.List = new List <FileUploadData>();

            lock (ni.sqllock)
            {
                SqlDataReader dr;
                if (string.IsNullOrWhiteSpace(MachineID) == true)
                {
                    if (Computers.MachineExists(sql, MachineID) == false)
                    {
                        ni.Error   = "Invalid data";
                        ni.ErrorID = ErrorFlags.InvalidValue;
                        return(RESTStatus.Fail);
                    }

                    dr = sql.ExecSQLReader("SELECT * FROM FileTransfers WHERE MachineID=@mid ORDER BY ID",
                                           new SQLParam("@mid", MachineID));
                }
                else
                {
                    dr = sql.ExecSQLReader("SELECT * FROM FileTransfers ORDER BY ID");
                }

                while (dr.Read())
                {
                    FileUploadDataList.List.Add(FillUploadData(dr));
                }
                dr.Close();
            }

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

            ChatList      = new PushChatMessageList();
            ChatList.List = new List <PushChatMessage>();
            List <Int64> IDs = new List <long>();

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("select * from Chats where [Read]=0 AND MachineID=@m AND ToClient=0 ORDER BY DT ASC",
                                                     new SQLParam("@m", MachineID));
                while (dr.Read())
                {
                    IDs.Add(Convert.ToInt64(dr["ID"]));
                    PushChatMessage pch = new PushChatMessage();
                    pch.ID   = Convert.ToInt64(dr["ID"]);
                    pch.DT   = SQLLib.GetDTUTC(dr["DT"]);
                    pch.Name = Convert.ToString(dr["Name"]);
                    pch.Text = Convert.ToString(dr["Text"]);
                    ChatList.List.Add(pch);
                }
                dr.Close();
            }

            foreach (Int64 id in IDs)
            {
                lock (ni.sqllock)
                {
                    sql.ExecSQL("UPDATE Chats SET [Read]=1 WHERE ID=@id",
                                new SQLParam("@id", id));
                }
            }

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

            string SessionConnectionGUID = RemoteNetworkConnectionWSCrosser.CreateSession(ni.Username, MachineID);
            string guid = Guid.NewGuid().ToString();

            PushData p = new PushData();

            p.Action          = "startwsscreen";
            p.ReplyID         = guid;
            p.AdditionalData1 = SessionConnectionGUID;

            PushServiceHelper.SendPushService(MachineID, p, 2);
            PushDataResponse resp = PushServiceHelper.PopResponse(MachineID, 2, guid, Timeout: 240);

            if (resp == null)
            {
                ni.Error   = "No response";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.NoContent);
            }

            try
            {
                res1 = JsonConvert.DeserializeObject <PushConnectNetworkResult>(resp.Data.ToString());
            }
            catch
            {
                ni.Error   = "Faulty data";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.NoContent);
            }
            return(RESTStatus.Success);
        }
Exemple #30
0
        public RESTStatus ListFiles(SQLLib sql, PushDirListReq Req, NetworkConnectionInfo ni, string MachineID)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            string guid = Guid.NewGuid().ToString();

            PushData p = new PushData();

            p.Action          = "listfiles";
            p.ReplyID         = guid;
            p.AdditionalData1 = JsonConvert.SerializeObject(Req);

            PushServiceHelper.SendPushService(MachineID, p, 0);
            PushDataResponse resp = PushServiceHelper.PopResponse(MachineID, 0, guid);

            if (resp == null)
            {
                ni.Error   = "No response";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.NoContent);
            }

            try
            {
                Lists = JsonConvert.DeserializeObject <NetStringList>(resp.Data.ToString());
            }
            catch
            {
                ni.Error   = "Faulty data";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.NoContent);
            }
            return(RESTStatus.Success);
        }