Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public RESTStatus ListNetData(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

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

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

            LstNetData           = new ListNetworkAdapterConfiguration();
            LstNetData.Items     = new List <NetworkAdapterConfiguration>();
            LstNetData.MachineID = id;

            lock (ni.sqllock)
            {
                SqlDataReader dr = sql.ExecSQLReader("SELECT * FROM networkconfig WHERE MachineID=@mid", new SQLParam("@mid", id));
                while (dr.Read())
                {
                    NetworkAdapterConfiguration n = new NetworkAdapterConfiguration();
                    sql.LoadIntoClass(dr, n);
                    LstNetData.Items.Add(n);
                }
                dr.Close();
            }

            foreach (NetworkAdapterConfiguration n in LstNetData.Items)
            {
                n.IPAddress                  = new List <string>();
                n.IPSubnet                   = new List <string>();
                n.DefaultIPGateway           = new List <string>();
                n.DNSDomainSuffixSearchOrder = new List <string>();
                n.DNSServerSearchOrder       = new List <string>();

                lock (ni.sqllock)
                {
                    SqlDataReader dr = sql.ExecSQLReader("select * from NetworkConfigSuppl WHERE MachineID=@mid AND InterfaceIndex=@i order by Type,[Order]",
                                                         new SQLParam("@mid", id),
                                                         new SQLParam("@i", n.InterfaceIndex));
                    while (dr.Read())
                    {
                        switch (Convert.ToInt32(dr["Type"]))
                        {
                        case 1:
                            n.IPAddress.Add(Convert.ToString(dr["Data"])); break;

                        case 2:
                            n.IPSubnet.Add(Convert.ToString(dr["Data"])); break;

                        case 3:
                            n.DefaultIPGateway.Add(Convert.ToString(dr["Data"])); break;

                        case 4:
                            n.DNSDomainSuffixSearchOrder.Add(Convert.ToString(dr["Data"])); break;

                        case 5:
                            n.DNSServerSearchOrder.Add(Convert.ToString(dr["Data"])); break;
                        }
                    }
                    dr.Close();
                }
            }
            return(RESTStatus.Success);
        }