Пример #1
0
        /// <summary> Adds domain to AD.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="domainName"> The domain name.</param>
        private void AddAdDomainName(string organizationId, string domainName)
        {
            string         path = AddADPrefix(GetOrganizationPath(organizationId));
            DirectoryEntry ou   = ActiveDirectoryUtils.GetADObject(path);

            ActiveDirectoryUtils.SetADObjectPropertyValue(ou, "Url", new[] { domainName });
            ou.CommitChanges();
        }
Пример #2
0
        /// <summary> Sets users general settings.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="userUpn"> The user UPN.</param>
        /// <param name="sfbUser"> The sfb user settings.</param>
        /// <returns> The result.</returns>
        internal override bool SetSfBUserGeneralSettingsInternal(string organizationId, string userUpn, SfBUser sfbUser)
        {
            HostedSolutionLog.LogStart("SetSfBUserGeneralSettingsInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);

            bool           ret         = true;
            Runspace       runspace    = null;
            SfBTransaction transaction = StartTransaction();

            try
            {
                runspace = OpenRunspace();
                Guid     tenantId = GetObjectGuid(organizationId, runspace);
                string[] tmp      = userUpn.Split('@');

                if (tmp.Length < 2)
                {
                    return(false);
                }

                var command = new Command("Get-CsSipDomain");
                Collection <PSObject> sipDomains = ExecuteShellCommand(runspace, command, false);
                bool bSipDomainExists            = sipDomains.Select(domain => (string)GetPSObjectProperty(domain, "Name")).Any(d => d.ToLower() == tmp[1].ToLower());

                if (!bSipDomainExists)
                {
                    command = new Command("New-CsSipDomain");
                    command.Parameters.Add("Identity", tmp[1].ToLower());
                    ExecuteShellCommand(runspace, command, false);

                    transaction.RegisterNewSipDomain(tmp[1].ToLower());

                    string         path      = AddADPrefix(GetOrganizationPath(organizationId));
                    DirectoryEntry ou        = ActiveDirectoryUtils.GetADObject(path);
                    string[]       sipDs     = ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "Url");
                    var            listSipDs = new List <string>();
                    listSipDs.AddRange(sipDs);
                    listSipDs.Add(tmp[1]);

                    ActiveDirectoryUtils.SetADObjectPropertyValue(ou, "Url", listSipDs.ToArray());
                    ou.CommitChanges();

                    CreateSimpleUrl(runspace, tenantId);
                    transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), tenantId.ToString());

                    path = AddADPrefix(GetResultObjectDN(organizationId, runspace));
                    DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path);

                    if (tmp.Length > 0)
                    {
                        string Url = SimpleUrlRoot + tmp[1];
                        ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-BaseSimpleUrl", Url.ToLower());
                    }

                    user.CommitChanges();
                }

                command = new Command("Set-CsUser");
                command.Parameters.Add("Identity", userUpn);

                if (!string.IsNullOrEmpty(sfbUser.SipAddress))
                {
                    command.Parameters.Add("SipAddress", "SIP:" + sfbUser.SipAddress);
                }

                if (!string.IsNullOrEmpty(sfbUser.LineUri))
                {
                    command.Parameters.Add("LineUri", "TEL:+" + sfbUser.LineUri);
                }
                else
                {
                    command.Parameters.Add("LineUri", null);
                }

                ExecuteShellCommand(runspace, command, false);

                if (!String.IsNullOrEmpty(sfbUser.PIN))
                {
                    command = new Command("Set-CsClientPin");
                    command.Parameters.Add("Identity", userUpn);
                    command.Parameters.Add("Pin", sfbUser.PIN);
                    ExecuteShellCommand(runspace, command, false);
                }

                command = new Command("Update-CsAddressBook");
                ExecuteShellCommand(runspace, command, false);

                command = new Command("Update-CsUserDatabase");
                ExecuteShellCommand(runspace, command, false);
            }
            catch (Exception ex)
            {
                ret = false;
                HostedSolutionLog.LogError("SetSfBUserGeneralSettingsInternal", ex);
                RollbackTransaction(transaction);
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("SetSfBUserGeneralSettingsInternal");

            return(ret);
        }
Пример #3
0
        /// <summary> Deletes organization.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="sipDomain"> The sip domain.</param>
        /// <returns> The result.</returns>
        internal override bool DeleteOrganizationInternal(string organizationId, string sipDomain)
        {
            HostedSolutionLog.LogStart("DeleteOrganizationInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("sipDomain: {0}", sipDomain);
            Runspace runspace = null;

            try
            {
                runspace = OpenRunspace();
                string         path  = AddADPrefix(GetOrganizationPath(organizationId));
                DirectoryEntry ou    = ActiveDirectoryUtils.GetADObject(path);
                string[]       sipDs = ActiveDirectoryUtils.GetADObjectPropertyMultiValue(ou, "Url");

                foreach (string sipD in sipDs)
                {
                    DeleteSipDomain(runspace, sipD);
                }

                try
                {
                    DeleteConferencingPolicy(runspace, organizationId);
                }
                catch (Exception)
                {
                }

                try
                {
                    DeleteExternalAccessPolicy(runspace, organizationId);
                }
                catch (Exception)
                {
                }

                try
                {
                    DeleteMobilityPolicy(runspace, organizationId + " EnableOutSideVoice");
                }
                catch (Exception)
                {
                }

                try
                {
                    DeleteMobilityPolicy(runspace, organizationId + " DisableOutSideVoice");
                }
                catch (Exception)
                {
                }

                var command = new Command("Invoke-CsManagementStoreReplication");
                ExecuteShellCommand(runspace, command, false);
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("DeleteOrganizationInternal", ex);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("DeleteOrganizationInternal");

            return(true);
        }
Пример #4
0
        /// <summary> Creates the user.</summary>
        /// <param name="organizationId"> The organization identifier.</param>
        /// <param name="userUpn"> The user UPN.</param>
        /// <param name="plan"> The SfB user plan.</param>
        /// <returns> The result.</returns>
        internal override bool CreateUserInternal(string organizationId, string userUpn, SfBUserPlan plan)
        {
            HostedSolutionLog.LogStart("CreateUserInternal");
            HostedSolutionLog.DebugInfo("organizationId: {0}", organizationId);
            HostedSolutionLog.DebugInfo("userUpn: {0}", userUpn);
            SfBTransaction transaction = StartTransaction();
            Runspace       runspace    = null;

            try
            {
                runspace = OpenRunspace();
                Guid     guid = GetObjectGuid(organizationId, runspace);
                string[] tmp  = userUpn.Split('@');

                if (tmp.Length < 2)
                {
                    return(false);
                }

                var command = new Command("Get-CsSipDomain");
                Collection <PSObject> sipDomains = ExecuteShellCommand(runspace, command, false);
                bool bSipDomainExists            = sipDomains.Select(domain => (string)GetPSObjectProperty(domain, "Name")).Any(d => d.ToLower() == tmp[1].ToLower());

                string path = string.Empty;
                if (!bSipDomainExists)
                {
                    command = new Command("New-CsSipDomain");
                    command.Parameters.Add("Identity", tmp[1].ToLower());
                    ExecuteShellCommand(runspace, command, false);
                    transaction.RegisterNewSipDomain(tmp[1].ToLower());
                    AddAdDomainName(organizationId, tmp[1].ToLower());
                    CreateSimpleUrl(runspace, guid);
                    transaction.RegisterNewSimpleUrl(tmp[1].ToLower(), guid.ToString());
                }

                command = new Command("Enable-CsUser");
                command.Parameters.Add("Identity", userUpn);
                command.Parameters.Add("RegistrarPool", PoolFQDN);
                command.Parameters.Add("SipAddressType", "UserPrincipalName");
                ExecuteShellCommand(runspace, command, false);
                transaction.RegisterNewCsUser(userUpn);

                command = new Command("Get-CsAdUser");
                command.Parameters.Add("Identity", userUpn);
                Collection <PSObject> result = ExecuteShellCommand(runspace, command, false);

                //set groupingID
                path = AddADPrefix(GetResultObjectDN(result));
                DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path);
                ActiveDirectoryUtils.SetADObjectPropertyValue(user, "msRTCSIP-GroupingID", guid);
                user.CommitChanges();

                command = new Command("Update-CsAddressBook");
                ExecuteShellCommand(runspace, command, false);
                command = new Command("Update-CsUserDatabase");
                ExecuteShellCommand(runspace, command, false);

                int trySleep = 2000; int tryMaxCount = 10; bool PlanSet = false;
                for (int tryCount = 0; (tryCount < tryMaxCount) && (!PlanSet); tryCount++)
                {
                    try
                    {
                        PlanSet = SetSfBUserPlanInternal(organizationId, userUpn, plan, runspace);
                    }
                    catch { }
                    if (!PlanSet)
                    {
                        System.Threading.Thread.Sleep(trySleep);
                    }
                }
            }
            catch (Exception ex)
            {
                HostedSolutionLog.LogError("CreateUserInternal", ex);
                RollbackTransaction(transaction);
                throw;
            }
            finally
            {
                CloseRunspace(runspace);
            }

            HostedSolutionLog.LogEnd("CreateUserInternal");

            return(true);
        }
Пример #5
0
        public static void SetOUAclPermissions(OrganizationProvider orgProvider, string organizationId, string rootDomain, string rootDomainPath)
        {
            string OUPath = orgProvider.GetOrganizationPath(organizationId);

            string dSHeuristicsOU = orgProvider.GetdSHeuristicsOU(rootDomain);

            Log.WriteInfo("dSHeuristicsOU: {0}", dSHeuristicsOU);

            DirectoryEntry GetdSHeuristicspath = new DirectoryEntry(dSHeuristicsOU);
            object         DSObject            = ActiveDirectoryUtils.GetADObjectProperty(GetdSHeuristicspath, "dSHeuristics") ?? "notset";
            string         dSHeuristics        = DSObject.ToString();

            Log.WriteInfo("dSHeuristics is : {0}", dSHeuristics);

            if (dSHeuristics is "001")
            {
                ActiveDirectoryUtils.DisableInheritance(OUPath);

                Log.WriteInfo("Removing PreWindows2000Identity from OU");
                ActiveDirectoryUtils.RemoveIdentityAllows(OUPath, PreWindows2000Identity);



                Log.WriteInfo("RemoveIdentityAllows for Everyone\n SID: {0}", EveryoneIdentity.ToString());
                ActiveDirectoryUtils.RemoveIdentityAllows(OUPath, EveryoneIdentity);
                Log.WriteInfo("RemoveIdentityAllows for AuthenticatedUsers\n SID: {0}", AuthenticatedUsersIdentity.ToString());
                ActiveDirectoryUtils.RemoveIdentityAllows(OUPath, AuthenticatedUsersIdentity);

                Log.WriteInfo("Changes for Exchange Servers: Recipient Management");
                var exchServers = ActiveDirectoryUtils.GetObjectTargetAccountName("Recipient Management", rootDomain);
                Log.WriteInfo("Recipient Management Exchange Servers: {0} ", exchServers);
                if (ActiveDirectoryUtils.AccountExists(exchServers))
                {
                    ActiveDirectoryUtils.AddPermission(OUPath, new NTAccount(exchServers), ActiveDirectoryRights.GenericAll);
                }

                Log.WriteInfo("Changes for Exchange Servers: Public Folder Management");
                exchServers = ActiveDirectoryUtils.GetObjectTargetAccountName("Public Folder Management", rootDomain);
                Log.WriteInfo("Public Folder Management Exchange Servers: {0} ", exchServers);
                if (ActiveDirectoryUtils.AccountExists(exchServers))
                {
                    ActiveDirectoryUtils.AddPermission(OUPath, new NTAccount(exchServers), ActiveDirectoryRights.GenericAll);
                }

                Log.WriteInfo("Completed Changes for Exchange Servers");

                var groupAccount = ActiveDirectoryUtils.GetObjectTargetAccountName(organizationId, orgProvider.RootDomain);
                Log.WriteInfo("Changes for GroupAccount: {0}", groupAccount.ToString());
                for (int i = 0; i <= 25; i++)
                {
                    if (ActiveDirectoryUtils.AccountExists(groupAccount))
                    {
                        ActiveDirectoryUtils.AddOrgPermisionsToIdentity(OUPath, new NTAccount(groupAccount));
                        break;
                    }

                    if (i == 25)
                    {
                        throw new Exception($"Can not find {groupAccount} group to set ACL permissions after {i * 2} seconds. Set Acl permissions manually");
                    }

                    Thread.Sleep(2000);
                }

                var privilegedGroup = ActiveDirectoryUtils.GetObjectTargetAccountName("Privileged Services", rootDomain);
                if (!ActiveDirectoryUtils.AccountExists(privilegedGroup))
                {
                    ActiveDirectoryUtils.CreateGroup(rootDomainPath, "Privileged Services");
                }

                ActiveDirectoryUtils.AddPermission(OUPath, new NTAccount(privilegedGroup), ActiveDirectoryRights.GenericRead);
            }
        }