Esempio n. 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);
        }
Esempio n. 2
0
        public List <CollectionUser> GetUser(string subscriptionId, string deploymentName, string collectionName, string alias)
        {
            try
            {
                PowerShellExecutor <CollectionUser> executor;
                string key = deploymentName + ":" + collectionName + ":" + alias;
                if (!AppUserController.executors.TryGetValue(key, out executor))
                {
                    executor           = new PowerShellExecutor <CollectionUser>();
                    executor.CmdName   = "";
                    executor.NewFunc   = this.NewFunc;
                    executor.Configure = (engine) =>
                    {
                        engine.AddCommand("Get-RDRemoteApp");
                        engine.AddParameter("ConnectionBroker", deploymentName);
                        engine.AddParameter("CollectionName", collectionName);
                        engine.AddParameter("Alias", alias);
                    };
                    executor = AppUserController.executors.GetOrAdd(key, executor);
                }

                var list = executor.GetList();
                return(list);
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, " GetDeployment", deploymentName);
                throw ex;
            }
        }
Esempio n. 3
0
        public List <CollectionUser> GetADUser(string subscriptionId, string DeployName)
        {
            try
            {
                PowerShellExecutor <CollectionUser> executor;
                string domainName = DeployName.Split('.')[1] + "." + DeployName.Split('.')[2];//ConfigurationManager.AppSettings["DomainName"];
                string filename   = "'*@" + "" + domainName + "'";
                string key        = subscriptionId;
                if (!AppUserController.executors.TryGetValue(key, out executor))
                {
                    executor           = new PowerShellExecutor <CollectionUser>();
                    executor.CmdName   = "";
                    executor.NewFunc   = this.NewFunc;
                    executor.Configure = (engine) =>
                    {
                        //engine.AddScript("Get-ADUser -Filter {UserPrincipalName -Like " + filename + "} ");
                        engine.AddScript("Get-ADUser -Filter {UserPrincipalName -Like " + filename + "} | select userprincipalname");
                    };
                    executor = AppUserController.executors.GetOrAdd(key, executor);
                }

                var list = executor.GetList();
                return(list);
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, " GetADUser", subscriptionId);
                throw ex;
            }
        }
Esempio n. 4
0
        public List <UserGroup> GetUsersFromUserGroups(string subscriptionId, String UserGroupName)
        {
            try
            {
                PowerShellExecutor <UserGroup> executor;
                string key       = subscriptionId + UserGroupName;
                string usergroup = "\"" + UserGroupName + "\"";
                if (!UserGroupController.executors.TryGetValue(key, out executor))
                {
                    executor           = new PowerShellExecutor <UserGroup>();
                    executor.CmdName   = "";
                    executor.NewFunc   = this.NewUserFunc;
                    executor.Configure = (engine) =>
                    {
                        engine.AddScript("Get-ADGroupMember " + usergroup);
                    };
                    executor = UserGroupController.executors.GetOrAdd(key, executor);
                }

                var list = executor.GetList();
                return(list);
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, " GetUsersFromUserGroups", subscriptionId);
                throw ex;
            }
        }
Esempio n. 5
0
 private string GetGateWayURL(string ConnectionBroker)
 {
     try
     {
         // Get the description using powershell
         string Query = "Get-RDDeploymentGatewayConfiguration -ConnectionBroker " + ConnectionBroker;
         PowerShellExecutor <AzureRDSFarm> executor;
         string key = "12";
         if (!executors.TryGetValue(key, out executor))
         {
             executor           = new PowerShellExecutor <AzureRDSFarm>();
             executor.CmdName   = "";
             executor.NewFunc   = this.NewClientFunc;
             executor.Configure = (engine) =>
             {
                 engine.AddScript(Query);
             };
             executor = executors.GetOrAdd(key, executor);
         }
         List <AzureRDSFarm> list = executor.GetList();
         string clientURL         = "https://" + list[0].ClientURL + "/RDWeb";
         return(clientURL);
         //return list;
     }
     catch (Exception ex)
     {
         ErrorHelper.SendExcepToDB(ex, " GetGateWayURL", ConnectionBroker);
         throw ex;
     }
 }
Esempio n. 6
0
        public async Task <List <AppDetails> > AddApps(string subscriptionId)
        {
            try
            {
                PowerShellExecutor <Application> executor;
                List <AppDetails> list     = new List <AppDetails>();
                string            bodyText = await this.Request.Content.ReadAsStringAsync();

                var               data             = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.DeserializeObject(bodyText).ToString());
                var               commandData      = ((JObject)data["AppDetails"]).ToObject <Dictionary <string, object> >();
                string            ConnectionBroker = "\"" + commandData["ConnectionBroker"] as string + "\"";
                string            collectionName   = "\"" + commandData["CollectionName"] as string + "\"";
                string            DisplayNames     = commandData["DisplayNames"] as string;
                string[]          displayNames     = DisplayNames.Split(',');
                string            Path             = commandData["Path"] as string;
                string[]          paths            = Path.Split(',');
                List <AppDetails> appDetails       = new List <Controllers.AppDetails>();
                for (int i = 0; i < displayNames.Length; i++)
                {
                    AppDetails app = new Controllers.AppDetails();
                    app.DisplayName = displayNames[i];
                    app.Path        = paths[i];
                    appDetails.Add(app);
                }
                List <AppDetails> outApp = new List <Controllers.AppDetails>();
                foreach (var record in appDetails)
                {
                    string     appName     = (record.DisplayName).Replace(" ", "");
                    AppDetails app         = new Controllers.AppDetails();
                    string     dateKey     = DateTime.Now.ToString("yyyyMMddTHHmmss");
                    string     displayName = "\"" + record.DisplayName + "\"";
                    string     Alias       = "\"" + appName + dateKey + "\"";
                    string     path        = "\"" + record.Path + "\"";
                    if (!ApplicationController.executors.TryGetValue(dateKey, out executor))
                    {
                        executor           = new PowerShellExecutor <Application>();
                        executor.CmdName   = "";
                        executor.NewFunc   = this.NewFunc;
                        executor.Configure = (engine) =>
                        {
                            engine.AddScript("New-RDRemoteApp -ConnectionBroker " + ConnectionBroker + " -CollectionName " + collectionName + " -DisplayName " + displayName + " -Alias " + Alias + " -FilePath " + path + "");
                        };
                        executor = ApplicationController.executors.GetOrAdd(dateKey, executor);
                    }
                    executor.GetList();
                    app.Alias = Alias;
                    outApp.Add(app);
                }

                return(outApp);
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, " AddApps", subscriptionId);

                throw ex;
            }
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public async Task <List <Application> > GetApplication(string subscriptionId, string deploymentName, string collectionName, string collectionType, string type)
        {
            try
            {
                PowerShellExecutor <Application> executor;
                string key = deploymentName + ":" + collectionName + ":" + type;
                if (collectionType.Equals("RemoteDesktop"))
                {
                    return(GetDesktopIcon());
                }
                else
                {
                    if ("collAppType".Equals(type))
                    {
                        if (!ApplicationController.executors.TryGetValue(key, out executor))
                        {
                            executor           = new PowerShellExecutor <Application>();
                            executor.CmdName   = "";
                            executor.NewFunc   = this.NewFunc;
                            executor.Configure = (engine) =>
                            {
                                engine.AddCommand("Get-RDRemoteApp");
                                engine.AddParameter("ConnectionBroker", deploymentName);
                                engine.AddParameter("CollectionName", collectionName);
                            };
                            executor = ApplicationController.executors.GetOrAdd(key, executor);
                        }

                        return(executor.GetList());
                    }
                    else
                    {
                        if (!ApplicationController.executors.TryGetValue(key, out executor))
                        {
                            executor           = new PowerShellExecutor <Application>();
                            executor.CmdName   = "";
                            executor.NewFunc   = this.NewFunc;
                            executor.Configure = (engine) =>
                            {
                                engine.AddCommand("Get-RDAvailableApp");
                                engine.AddParameter("ConnectionBroker", deploymentName);
                                engine.AddParameter("CollectionName", collectionName);
                            };
                            executor = ApplicationController.executors.GetOrAdd(key, executor);
                        }

                        return(executor.GetList());
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, " GetApplication", deploymentName);
                throw ex;
            }
        }
        private List <AdminCollection> GetCollectionsByDeploymentName(string deploymentName)
        {
            try
            {
                PowerShellExecutor <AdminCollection> executor;

                if (!AdminCollectionsController.executors.TryGetValue(deploymentName, out executor))
                {
                    executor           = new PowerShellExecutor <AdminCollection>();
                    executor.CmdName   = "";
                    executor.NewFunc   = this.NewFunc;
                    executor.Configure = (engine) =>
                    {
                        engine.AddCommand("Get-RDSessionCollection");
                        engine.AddParameter("ConnectionBroker", deploymentName);
                    };
                    executor = AdminCollectionsController.executors.GetOrAdd(deploymentName, executor);
                }

                var list = executor.GetList();
                if (list == null || list.Count() == 0)
                {
                    return(list);
                }

                // Get the Collection Burst settings/ Collection Guids/ Audit files from the Database before returning the list
                var query = string.Format("SELECT CollectionName, IsActive FROM CollectionBurstSettings WHERE DeploymentFQDN ='{0}'", deploymentName);

                var queryResults = ServicesManager.Instance.ExecuteQuery <AdminCollection>(query, (rdr, results) =>
                {
                    var collection   = new AdminCollection();
                    collection.Name  = rdr["CollectionName"].ToString();
                    collection.Burst = (bool)rdr["IsActive"];
                    results.Add(collection);
                });

                if (queryResults != null)
                {
                    queryResults.ForEach(r =>
                    {
                        var collection = list.Where(i => i.Name == r.Name).FirstOrDefault();
                        if (collection != null) // populate the information before returning the list back
                        {
                            collection.Burst = r.Burst;
                        }
                    });
                }

                return(list);
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, "GetCollectionsByDeploymentName", deploymentName);
                throw ex;
            }
        }
Esempio n. 10
0
        public async Task <List <RDServer> > GetServer(string deploymentName, string role = "")
        {
            try
            {
                if (role == "FREE-RDS-RD-SERVER")
                {
                    return(GetFreeSessionHostServers(deploymentName));
                }
                if (role == "STATUS-RDS-RD-SERVER")
                {
                    return(GetStatusSessionHostServers(deploymentName));
                }

                PowerShellExecutor <RDServer> executor;
                string key = deploymentName + role;
                if (!RDServerController.executors.TryGetValue(key, out executor))
                {
                    executor           = new PowerShellExecutor <RDServer>();
                    executor.CmdName   = "";
                    executor.NewFunc   = this.NewFunc;
                    executor.Configure = (engine) =>
                    {
                        engine.AddCommand("Get-RDServer");
                        engine.AddParameter("ConnectionBroker", deploymentName);
                        if (!string.Equals(role, string.Empty))
                        {
                            engine.AddParameter("Role", role);
                        }
                    };
                    executor = RDServerController.executors.GetOrAdd(key, executor);
                }

                var list = executor.GetList();
                return(list);
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, "GetServer", deploymentName);
                throw ex;
            }
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        /// <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;
            }
        }
Esempio n. 13
0
        public async Task <List <Collection> > GetCollections(string subscriptionId, string deploymentName)
        {
            PowerShellExecutor <Collection> executor;

            this.SubscriptionID   = subscriptionId;
            this.ConnectionBroker = deploymentName;
            if (!CollectionsController.executors.TryGetValue(deploymentName, out executor))
            {
                executor           = new PowerShellExecutor <Collection>();
                executor.CmdName   = "";
                executor.NewFunc   = this.NewFunc;
                executor.Configure = (engine) =>
                {
                    engine.AddCommand("Get-RDSessionCollection");
                    engine.AddParameter("ConnectionBroker", deploymentName);
                };
                executor = CollectionsController.executors.GetOrAdd(deploymentName, executor);
            }

            var list = executor.GetList();

            return(list);
        }
Esempio n. 14
0
        public List <UserGroup> GetUserGroups(string subscriptionId)
        {
            try
            {
                PowerShellExecutor <UserGroup> executor;
                string key = subscriptionId + ":";
                string pslgetusergroups = ConfigurationManager.AppSettings["psl_layer"].ToString() + "/getusergroups.ps1";
                string psl_Script       = "";
                using (WebClient client = new WebClient())
                {
                    psl_Script = client.DownloadString(pslgetusergroups);
                }
                //string security = "\"" + "Security" + "\"";
                //string domainLocal = "\"" + "DomainLocal" + "\"";
                //string query = "Get-ADGroup -Filter 'GroupCategory -eq " + security + " -and GroupScope -ne " + domainLocal + "' | select  samaccountname,objectClass";
                if (!UserGroupController.executors.TryGetValue(key, out executor))
                {
                    executor           = new PowerShellExecutor <UserGroup>();
                    executor.CmdName   = "";
                    executor.NewFunc   = this.NewFunc;
                    executor.Configure = (engine) =>
                    {
                        //engine.AddScript(query);
                        engine.AddScript(psl_Script);
                    };
                    executor = UserGroupController.executors.GetOrAdd(key, executor);
                }

                var list = executor.GetList();
                return(list);
            }
            catch (Exception ex)
            {
                ErrorHelper.SendExcepToDB(ex, " GetUserGroups", subscriptionId);
                throw ex;
            }
        }
Esempio n. 15
0
        public List <CollectionUser> GetUser(string subscriptionId, string deploymentName, string collectionName)
        {
            PowerShellExecutor <CollectionUser> executor;
            string key = deploymentName + ":" + collectionName;

            if (!UserController.executors.TryGetValue(key, out executor))
            {
                executor           = new PowerShellExecutor <CollectionUser>();
                executor.CmdName   = "";
                executor.NewFunc   = this.NewFunc;
                executor.Configure = (engine) =>
                {
                    engine.AddCommand("RDSessionCollectionConfiguration");
                    engine.AddParameter("ConnectionBroker", deploymentName);
                    engine.AddParameter("CollectionName", collectionName);
                    engine.AddParameter("UserGroup");
                };
                executor = UserController.executors.GetOrAdd(key, executor);
            }

            var list = executor.GetList();

            return(list);
        }
Esempio n. 16
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);
        }