Beispiel #1
0
 static void Main(string[] args)
 {
     var     test      = new NullTest();
     var     converter = new TestConvert();
     int?    t1        = test.Null("2", converter.ConvertToInt32Null);
     decimal?t2        = test.Null("", converter.ConvertToDecimalNull);
 }
Beispiel #2
0
        public RESTStatus ReportWindowsLic(SQLLib sql, WindowsLic WinLic, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

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

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

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

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

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

            return(RESTStatus.Success);
        }
Beispiel #3
0
        public void TestNullDefault()
        {
            var obj = new NullTest();

            var onlyNum = new Dictionary <string, Variant>();

            onlyNum["num"] = new Variant(10);
            ParameterParser.Parse(obj, onlyNum);

            Assert.Null(obj.str);
            Assert.AreEqual(10, obj.num);
            Assert.Null(obj.custom);

            var onlyStr = new Dictionary <string, Variant>();

            onlyNum["str"] = new Variant("hi");

            Assert.Throws <PeachException>(delegate() { ParameterParser.Parse(obj, onlyStr); });
        }
        public RESTStatus ReportEventLog(SQLLib sql, ListEventLogReport EventLogList, NetworkConnectionInfo ni)
        {
            if (ni.HasAcl(ACLFlags.ComputerLogin) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            EventLogList.MachineID = ni.Username;

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

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

            if (EventLogList.Items.Count == 0)
            {
                return(RESTStatus.Created);
            }

            DateTime DT = DateTime.Now;

            foreach (EventLogReport ar in EventLogList.Items)
            {
                if (NullTest.Test(ar) == false)
                {
                    ni.Error   = "Invalid Items";
                    ni.ErrorID = ErrorFlags.InvalidValue;
                    return(RESTStatus.Fail);
                }
                CommonUtilities.CalcEventLogID(ar);
            }

            List <SQLParam> sqlparams = new List <SQLParam>();

            sqlparams.Add(new SQLParam("@id", EventLogList.MachineID));
            int    count = 1;
            string vars  = "";

            foreach (EventLogReport ar in EventLogList.Items)
            {
                sqlparams.Add(new SQLParam("@p" + count.ToString(), ar.LogID));
                vars += "@p" + count.ToString() + ",";
                count++;
            }
            if (vars.EndsWith(",") == true)
            {
                vars = vars.Substring(0, vars.Length - 1);
            }

            List <string> LogIDinDB = new List <string>();

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT LogID FROM EventLog WHERE MachineID=@id and LogID in (" + vars + ")", sqlparams.ToArray());
                while (dr.Read())
                {
                    LogIDinDB.Add(Convert.ToString(dr["LogID"]));
                }
                dr.Close();
            }

            List <EventLogReport> RemoveEVL = new List <EventLogReport>();

            foreach (EventLogReport ar in EventLogList.Items)
            {
                if (LogIDinDB.Contains(ar.LogID) == true)
                {
                    RemoveEVL.Add(ar);
                    continue;
                }
                if (SettingsManager.Settings.KeepEventLogDays > 0)
                {
                    if (ar.TimeGenerated < DateTime.UtcNow.AddDays(0 - SettingsManager.Settings.KeepEventLogDays))
                    {
                        RemoveEVL.Add(ar);
                        continue;
                    }
                }
            }

            foreach (EventLogReport ar in RemoveEVL)
            {
                EventLogList.Items.Remove(ar);
            }

            List <EventLogReportFull> car = new List <EventLogReportFull>();

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

                    foreach (EventLogReport ar in EventLogList.Items)
                    {
                        EventLogReportFull arr = new EventLogReportFull();
                        ClassCopy.CopyClassData(ar, arr);
                        arr.Reported  = DateTime.UtcNow;
                        arr.MachineID = EventLogList.MachineID;
                        List <SQLData> d = sql.InsertFromClassPrep(arr);
                        foreach (SQLData dd in d)
                        {
                            if (dd.Column == "ID")
                            {
                                dd.Data = DBNull.Value;
                                break;
                            }
                        }
                        car.Add(arr);
                        sql.InsertFromClass("EventLog", arr);
                    }
                    sql.CommitTransaction();
                }
                catch (Exception ee)
                {
                    sql.RollBackTransaction();
                    FoxEventLog.WriteEventLog("DB Error: Cannot insert data to EventLog: " + ee.ToString() + "\r\n\r\nJSON: " +
                                              JsonConvert.SerializeObject(car, Formatting.Indented), System.Diagnostics.EventLogEntryType.Error);
                    return(RESTStatus.ServerError);
                }
                finally
                {
                    sql.SEHError = false;
                }
            }

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

            t.Start(car);

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

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

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

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

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

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

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

            Guid testguid;

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

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

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

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

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

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

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

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

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

            string newID = NetworkConnection.NewSession();

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

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

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

            if (Settings.Default.UseContract == true)
            {
                if (Convert.ToInt32(sql.ExecSQLScalar("SELECT Count(*) FROM Contracts WHERE ContractID=@id AND ContractPassword=@pw AND Disabled=0",
                                                      new SQLParam("@id", logon.ContractID),
                                                      new SQLParam("@pw", logon.ContractPassword))) == 0)
                {
                    NetworkConnection.DeleteSession(newID);
                    Err.Error   = "Invalid/Disabled Contract Data";
                    Err.ErrorID = (int)ErrorFlags.FaultyContractData;
                    return(RESTStatus.Fail);
                }
            }

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

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

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

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

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

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

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

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

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

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

                object   dt;
                DateTime dtt;

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

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

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

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

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

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

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

            ni.Username           = logon.Username;
            ni.Name               = logon.SysInfo.ComputerName;
            ni.EMail              = "";
            ni.MustChangePassword = false;
            ni.LoggedIn           = false;
            ni.ComputerLoggedIn   = true;
            ni.Permissions        = (Int64)ACLFlags.ComputerLogin;
            Debug.WriteLine("Computer: " + ni.Name + " logged in");
            Err.Error   = "OK:" + newID;
            Err.ErrorID = (int)ErrorFlags.NoError;
            return(RESTStatus.Success);
        }