Exemple #1
0
        public List <Server> GetServer(string subscriptionId, string deploymentName, string collectionName)
        {
            PowerShellExecutor <Server> executor;
            string key = deploymentName + ":" + collectionName;
            string pslgetsessionhost = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getsessionhost.ps1";
            string psl_Script        = "";

            using (WebClient client = new WebClient())
            {
                psl_Script = client.DownloadString(pslgetsessionhost);
            }
            if (!ServerController.executors.TryGetValue(key, out executor))
            {
                executor           = new PowerShellExecutor <Server>();
                executor.CmdName   = "";
                executor.NewFunc   = this.NewFunc;
                executor.Configure = (engine) =>
                {
                    PowerShellJob.AddVariable(engine, "ConnectionBroker", deploymentName);
                    PowerShellJob.AddVariable(engine, "CollectionAlias", collectionName);
                    engine.AddScript(psl_Script);
                };
                executor = ServerController.executors.GetOrAdd(key, executor);
            }

            var list = executor.GetList();

            return(list);
        }
Exemple #2
0
        public string Execute()
        {
            string error  = "unknown";
            var    pShell = ServicesManager.Instance.MakePowerShellJob((engine) =>
            {
                foreach (var paramName in paramNames)
                {
                    PowerShellJob.AddVariable(engine, paramName, data);
                }
                engine.AddScript(this.script);
            }, (data) =>
            {
                if (this.process != null)
                {
                    this.process(data, this);
                }
                this.Result = data; //added to store the resultant data to Result previous was not storing
            }, (ex) =>
            {
                error = ex.Message;
            });

            JobManager.Instance.Execute(pShell);
            if (!pShell.Success)
            {
                throw new Exception("Error executing command:" + error);
            }

            return(string.Empty);
        }
Exemple #3
0
        public IEnumerable <SQLServerState> GetServerStatus(string AccountType, string AccountID)
        {
            string filePath = "";

            if (AccountType == "Azure")
            {
                filePath = HttpContext.Current.Server.MapPath("~/DB_Csv_files/AzureAccountCreds.csv");
            }
            else if (AccountType == "AWS")
            {
                filePath = HttpContext.Current.Server.MapPath("~/DB_Csv_files/AWSAccountCreds.csv");
            }
            PowerShellExecutor <SQLServerState> executor;
            string key = "";

            if (!SQLServerStateController.executors.TryGetValue(key, out executor))
            {
                executor           = new PowerShellExecutor <SQLServerState>();
                executor.CmdName   = "";
                executor.NewFunc   = this.NewFunc;
                executor.Configure = (engine) =>
                {
                    PowerShellJob.AddVariable(engine, "CredFile", filePath);
                    PowerShellJob.AddVariable(engine, "AccountID", AccountID);
                    engine.AddScript(AzureCommandResource.Azure_SQLServerState_PS);
                };
                executor = SQLServerStateController.executors.GetOrAdd(key, executor);
            }


            var list = executor.GetList();

            return(list);
        }
Exemple #4
0
        public List <Session> GetSession(string subscriptionId, string usrlData)
        {
            var bytes  = System.Convert.FromBase64String(usrlData);
            var data   = System.Text.Encoding.ASCII.GetString(bytes);
            var inData = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, object> >(data);

            top        = (long)inData["top"];
            skip       = (long)inData["localSkip"];
            searchText = inData["searchText"] as string;
            columnMap  = inData["columnMap"] as string;
            var            checkQuery = (bool)inData["checkQuery"];
            List <Session> list;

            if (testMode)
            {
                list = testList;
            }
            else
            {
                PowerShellExecutor <Session> executor;
                string key = inData["deploymentInfo"] + ":" + inData["collectionName"];
                if (!SessionController.executors.TryGetValue(key, out executor))
                {
                    executor           = new PowerShellExecutor <Session>();
                    executor.CmdName   = "";
                    executor.NewFunc   = this.NewFunc;
                    executor.Configure = (engine) =>
                    {
                        PowerShellJob.AddVariable(engine, "ConnectionBroker", inData["deploymentInfo"] as string);
                        PowerShellJob.AddVariable(engine, "CollectionName", inData["collectionName"] as string);
                        engine.AddScript("Get-RDUserSession -ConnectionBroker $ConnectionBroker -CollectionName $CollectionName");
                    };
                    executor = SessionController.executors.GetOrAdd(key, executor);
                }

                list = executor.GetList();
            }
            if (list != null && top > 0 && skip >= 0)
            {
                if (!string.IsNullOrWhiteSpace(searchText))
                {
                    try
                    {
                        var colsMap = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, object> >(columnMap.ToLower());
                        list = SessionController.DoQuery <Session>(searchText, list, colsMap, checkQuery);
                    }
                    catch (Exception ex)
                    {
                        ErrorHelper.SendExcepToDB(ex, " GetSession", subscriptionId);
                        throw ex;
                    }
                }
            }

            return(list);
        }
Exemple #5
0
        public List <CollectionUser> GetUsersAndGroups(string deploymentName, string collectionName, string type)
        {
            PowerShellExecutor <CollectionUser> executor;
            string key = deploymentName + ":" + collectionName;
            string pslgetusersandgroups = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getusersandgroups.ps1";
            string psl_Script           = "";

            using (WebClient client = new WebClient())
            {
                psl_Script = client.DownloadString(pslgetusersandgroups);
            }
            if (!UserController.executors.TryGetValue(key, out executor))
            {
                executor           = new PowerShellExecutor <CollectionUser>();
                executor.CmdName   = "";
                executor.NewFunc   = this.NewFunc;
                executor.Configure = (engine) =>
                {
                    PowerShellJob.AddVariable(engine, "ConnectionBroker", deploymentName);
                    PowerShellJob.AddVariable(engine, "CollectionName", collectionName);
                    engine.AddScript(psl_Script);
                };
                executor = UserController.executors.GetOrAdd(key, executor);
            }

            var userlist = new List <CollectionUser>();
            var list     = executor.GetList();

            if (list != null)
            {
                foreach (var value in list)
                {
                    if ((value.UserType).Equals(type))
                    {
                        userlist.Add(value);
                    }
                }
            }
            return(userlist);
        }
Exemple #6
0
        public IEnumerable <Processes> GetLocalProcess(int Id)
        {
            PowerShellExecutor <Processes> executor;
            string key = Id.ToString();

            if (!GetLocalProcessesController.executors.TryGetValue(key, out executor))
            {
                executor           = new PowerShellExecutor <Processes>();
                executor.CmdName   = "";
                executor.NewFunc   = this.NewFunc;
                executor.Configure = (engine) =>
                {
                    PowerShellJob.AddVariable(engine, "Id", Id.ToString());
                    engine.AddScript(AWSCommandResource.getSpecificProcess);
                };
                executor = GetLocalProcessesController.executors.GetOrAdd(key, executor);
            }

            var list = executor.GetList();

            return(list);
        }
Exemple #7
0
        public IEnumerable <VMDetails> GetAzureVMDetails()
        {
            //Connect to DB and get the Creds
            string    stm            = @"Select SubscriptionId, Username, Password from kloudLoginDetails";
            DataTable dt             = DBHelper.ExecuteAndGetDataTable(stm);
            string    SubscriptionId = "";
            string    Username       = "";
            string    Password       = "";

            if (dt.Rows.Count == 1)
            {
                SubscriptionId = dt.Rows[0]["SubscriptionId"] as string;
                Username       = dt.Rows[0]["Username"] as string;
                Password       = dt.Rows[0]["Password"] as string;
            }
            PowerShellExecutor <VMDetails> executor;
            string key = "";

            if (!VMDetailsController.executors.TryGetValue(key, out executor))
            {
                executor           = new PowerShellExecutor <VMDetails>();
                executor.CmdName   = "";
                executor.NewFunc   = this.NewFunc;
                executor.Configure = (engine) =>
                {
                    PowerShellJob.AddVariable(engine, "SubscriptionId", SubscriptionId);
                    PowerShellJob.AddVariable(engine, "Username", Username);
                    PowerShellJob.AddVariable(engine, "Password", Password);
                    engine.AddScript(AzureCommandResource.getAzureVMDetails);
                };
                executor = VMDetailsController.executors.GetOrAdd(key, executor);
            }


            var list = executor.GetList();

            return(list);
        }
        /// <summary>
        /// Get Session Host Servers with their status with a given Deployment FQDN name
        /// </summary>
        /// <param name="deploymentName">Deployment FQDN name</param>
        /// <returns>List of Session Host Servers with their status under the given deployment name</returns>
        private List <RDServer> GetStatusSessionHostServers(string deploymentName)
        {
            try
            {
                string pslgetSessionHostServerStatus = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getSessionHostServerStatus.ps1";
                string psl_Script = "";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslgetSessionHostServerStatus);
                }
                // Get the available Session Host Servers via ScriptCommand/Powershell
                string role = "STATUS-RDS-RD-SERVER";
                PowerShellExecutor <RDServer> executor;
                string key = deploymentName + ":" + role;

                if (!RDServerController.executors.TryGetValue(key, out executor))
                {
                    executor           = new PowerShellExecutor <RDServer>();
                    executor.CmdName   = "";
                    executor.NewFunc   = this.NewRDFunc;
                    executor.Configure = (engine) =>
                    {
                        PowerShellJob.AddVariable(engine, "ConnectionBroker", deploymentName);
                        engine.AddScript(psl_Script);
                    };
                    executor = RDServerController.executors.GetOrAdd(key, executor);
                }

                var list = executor.GetList();

                return(list);
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, " GetStatusSessionHostServers", deploymentName);
                throw ex;
            }
        }
Exemple #9
0
        public async Task <List <CollectionUser> > AuthoriseUser(string subscriptionId)
        {
            string bodyText = await this.Request.Content.ReadAsStringAsync();

            var    data        = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.DeserializeObject(bodyText).ToString());
            var    commandData = ((JObject)data["credentials"]).ToObject <Dictionary <string, object> >();
            string fullName    = commandData["username"] as string;

            string[] dfName     = fullName.Split('\\');
            string   domainName = dfName[0];
            string   Username   = dfName[1];
            string   Password   = commandData["password"] as string;

            string psl_path   = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/userlogin.ps1";
            string psl_Script = "";

            using (WebClient client = new WebClient())
            {
                psl_Script = client.DownloadString(psl_path);
            }

            PowerShellExecutor <CollectionUser> executor;

            executor           = new PowerShellExecutor <CollectionUser>();
            executor.CmdName   = "";
            executor.NewFunc   = this.NewFunclogin;
            executor.Configure = (engine) =>
            {
                PowerShellJob.AddVariable(engine, "caUserName", fullName);
                PowerShellJob.AddVariable(engine, "caPassword", Password);
                engine.AddScript(psl_Script);
            };

            List <CollectionUser> response = new List <CollectionUser>();
            CollectionUser        obj      = new CollectionUser();
            var    list = executor.GetList();
            string res  = list[0].UserType.ToString();

            obj.Name     = Username.ToUpper().ToString();
            obj.UserType = res;
            if (res == "CollectionAdmin")
            {
                obj.UserType = "TenantAdmin";
                // List<CollectionUser> list = new List<CollectionUser>();


                obj.ConnectionBroker = list[0].ConnectionBroker.ToString();
            }
            string isAllowed = "Valid";//IsAllowed();

            if (isAllowed.Contains("Valid"))
            {
                obj.IsValid = true;
                obj.Message = "";
                if (isAllowed.Contains("|"))
                {
                    obj.Message = isAllowed.Split('|')[1].ToString();
                }
            }
            else
            {
                obj.IsValid = false;
                obj.Message = "";
            }

            response.Add(obj);

            return(response);
        }
Exemple #10
0
 public PowerShellJob MakePowerShellJob <T>(Action <PowerShell> Configure,
                                            Action <dynamic, List <T> > NewFunc, Func <List <T>, bool> SetList)
 {
     return(PowerShellJob.MakePowerShellJob <T>(Configure, NewFunc, SetList));
 }
Exemple #11
0
 public PowerShellJob MakePowerShellJob(Action <PowerShell> configure,
                                        Action <dynamic> process, Action <Exception> errors = null)
 {
     return(PowerShellJob.MakePowerShellJob(configure, process, errors));
 }