Пример #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdatePlan_Click(object sender, EventArgs e)
        {
            BaseActivesyncPolicy policy = new BaseActivesyncPolicy();

            ExchCmds powershell = null;
            try
            {
                // Fill in custom object
                policy.CompanyCode = "";
                policy.DisplayName = txtDisplayName.Text;
                policy.Description = txtDescription.Text;
                policy.AllowNonProvisionableDevice = cbAllowNonProvisionableDevices.Checked;

                if (!string.IsNullOrEmpty(txtRefreshInterval.Text))
                    policy.DevicePolicyRefreshInterval = int.Parse(txtRefreshInterval.Text);
                else
                    policy.DevicePolicyRefreshInterval = 0;

                //
                // PASSWORD TAB
                //
                policy.DevicePasswordEnabled = cbRequirePassword.Checked;
                if (policy.DevicePasswordEnabled)
                {
                    policy.AlphanumericDevicePasswordRequired = cbRequireAlphaNumericPassword.Checked;

                    if (!string.IsNullOrEmpty(txtMinimumNumberOfCharacterSets.Text))
                        policy.MinDevicePasswordComplexCharacters = int.Parse(txtMinimumNumberOfCharacterSets.Text);
                    else
                        policy.MinDevicePasswordComplexCharacters = 0;

                    policy.PasswordRecoveryEnabled = cbEnablePasswordRecovery.Checked;
                    policy.RequireDeviceEncryption = cbRequireEncryption.Checked;
                    policy.RequireStorageCardEncryption = cbRequireEncryptionOnStorageCard.Checked;
                    policy.AllowSimpleDevicePassword = cbAllowSimplePassword.Checked;

                    if (!string.IsNullOrEmpty(txtNumberOfFailedAttemptsAllowed.Text))
                        policy.MaxDevicePasswordFailedAttempts = int.Parse(txtNumberOfFailedAttemptsAllowed.Text);
                    else
                        policy.MaxDevicePasswordFailedAttempts = 0;

                    if (!string.IsNullOrEmpty(txtMinimumPasswordLength.Text))
                        policy.MinDevicePasswordLength = int.Parse(txtMinimumPasswordLength.Text);
                    else
                        policy.MinDevicePasswordLength = 0;

                    if (!string.IsNullOrEmpty(txtInactivityTimeout.Text))
                        policy.MaxInactivityTimeDeviceLock = int.Parse(txtInactivityTimeout.Text);
                    else
                        policy.MaxInactivityTimeDeviceLock = 0;

                    if (!string.IsNullOrEmpty(txtPasswordExpiration.Text))
                        policy.DevicePasswordExpiration = int.Parse(txtPasswordExpiration.Text);
                    else
                        policy.DevicePasswordExpiration = 0;

                    if (!string.IsNullOrEmpty(txtEnforcePasswordHistory.Text))
                        policy.DevicePasswordHistory = int.Parse(txtEnforcePasswordHistory.Text);
                    else
                        policy.DevicePasswordHistory = 0;
                }


                //
                // SYNC SETTINGS
                //
                policy.MaxCalendarAgeFilter = ddlPastCalendarItems.SelectedValue;
                policy.MaxEmailAgeFilter = ddlPastEmailItems.SelectedValue;

                if (!string.IsNullOrEmpty(txtLimitEmailSize.Text))
                    policy.MaxEmailBodyTruncationSize = int.Parse(txtLimitEmailSize.Text);
                else
                    policy.MaxEmailBodyTruncationSize = 0;

                policy.RequireManualSyncWhenRoaming = cbAllowDirectPushWhenRoaming.Checked;
                policy.AllowHTMLEmail = cbAllowHTMLEmail.Checked;
                policy.AttachmentsEnabled = cbAllowAttachmentDownload.Checked;

                if (policy.AttachmentsEnabled)
                {
                    if (!string.IsNullOrEmpty(txtMaximumAttachmentSize.Text))
                        policy.MaxAttachmentSize = int.Parse(txtMaximumAttachmentSize.Text);
                    else
                        policy.MaxAttachmentSize = 0;
                }

                //
                // DEVICE
                //
                policy.AllowStorageCard = cbAllowRemovableStorage.Checked;
                policy.AllowCamera = cbAllowCamera.Checked;
                policy.AllowWiFi = cbAllowWiFi.Checked;
                policy.AllowIrDA = cbAllowInfrared.Checked;
                policy.AllowInternetSharing = cbAllowInternetSharing.Checked;
                policy.AllowRemoteDesktop = cbAllowRemoteDesktop.Checked;
                policy.AllowDesktopSync = cbAllowDesktopSync.Checked;
                policy.AllowBluetooth = ddlAllowBluetooth.SelectedValue;
                policy.AllowTextMessaging = cbAllowTextMessaging.Checked;

                //
                // DEVICE APPLICATIONS
                //
                policy.AllowBrowser = cbAllowBrowser.Checked;
                policy.AllowConsumerEmail = cbAllowConsumerMail.Checked;
                policy.AllowUnsignedApplications = cbAllowUnsignedApplications.Checked;
                policy.AllowUnsignedInstallationPackages = cbAllowUnsignedInstallPackages.Checked;
                


                // Initialize powershell
                powershell = new ExchCmds(Config.ExchangeURI, Config.Username, Config.Password, Config.ExchangeConnectionType, Config.PrimaryDC);

                // Check if we are creating a new policy or updating existing
                if (ddlActiveSyncPlan.SelectedIndex > 0)
                {
                    policy.ASID = int.Parse(ddlActiveSyncPlan.SelectedValue);

                    // Update Exchange
                    powershell.Update_ActiveSyncPolicy(policy, Config.ExchangeVersion);

                    // Update SQL database
                    SQLExchange.UpdateExchangeActiveSyncPolicy(policy);

                    // Update notification
                    notification1.SetMessage(controls.notification.MessageType.Success, Resources.LocalizedText.NotificationSuccessUpdateAS + policy.DisplayName);
                }
                else
                {
                    // Create new policy
                    powershell.New_ActiveSyncPolicy(policy, Config.ExchangeVersion);

                    // Add to SQL database
                    SQLExchange.AddExchangeActiveSyncPolicy(policy);

                    // Update notification
                    notification1.SetMessage(controls.notification.MessageType.Success, Resources.LocalizedText.NotificationSuccessCreatedAS + policy.DisplayName);
                }

            }
            catch (Exception ex)
            {
                notification1.SetMessage(controls.notification.MessageType.Error, ex.Message);
            }
            finally
            {
                if (powershell != null)
                    powershell.Dispose();

                // Refresh view
                GetPolicies();
            }
        }
Пример #2
0
        /// <summary>
        /// Updates an existing plan in the database
        /// </summary>
        /// <param name="policy"></param>
        public static void UpdateExchangeActiveSyncPolicy(BaseActivesyncPolicy policy)
        {
            // Initialize SQL
            SqlConnection sql = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
            SqlCommand cmd = new SqlCommand(@"UPDATE Plans_ExchangeActiveSync SET
                       CompanyCode=@CompanyCode, DisplayName=@DisplayName, Description=@Description, AllowNonProvisionableDevices=@AllowNonProvisionableDevices,
                       RefreshIntervalInHours=@RefreshIntervalInHours, RequirePassword=@RequirePassword, RequireAlphanumericPassword=@RequireAlphanumericPassword,
                       EnablePasswordRecovery=@EnablePasswordRecovery, RequireEncryptionOnDevice=@RequireEncryptionOnDevice, RequireEncryptionOnStorageCard=@RequireEncryptionOnStorageCard,
                       AllowSimplePassword=@AllowSimplePassword, NumberOfFailedAttempted=@NumberOfFailedAttempted, MinimumPasswordLength=@MinimumPasswordLength,
                       InactivityTimeoutInMinutes=@InactivityTimeoutInMinutes, PasswordExpirationInDays=@PasswordExpirationInDays, EnforcePasswordHistory=@EnforcePasswordHistory,
                       IncludePastCalendarItems=@IncludePastCalendarItems, IncludePastEmailItems=@IncludePastEmailItems, LimitEmailSizeInKB=@LimitEmailSizeInKB, AllowDirectPushWhenRoaming=@AllowDirectPushWhenRoaming,
                       AllowHTMLEmail=@AllowHTMLEmail, AllowAttachmentsDownload=@AllowAttachmentsDownload, MaximumAttachmentSizeInKB=@MaximumAttachmentSizeInKB,
                       AllowRemovableStorage=@AllowRemovableStorage, AllowCamera=@AllowCamera, AllowWiFi=@AllowWiFi, AllowInfrared=@AllowInfrared, AllowInternetSharing=@AllowInternetSharing,
                       AllowRemoteDesktop=@AllowRemoteDesktop, AllowDesktopSync=@AllowDesktopSync, AllowBluetooth=@AllowBluetooth, AllowBrowser=@AllowBrowser,
                       AllowConsumerMail=@AllowConsumerMail, AllowUnsignedApplications=@AllowUnsignedApplications, AllowUnsignedInstallationPackages=@AllowUnsignedInstallationPackages,
                       IsEnterpriseCAL=@IsEnterpriseCAL, AllowTextMessaging=@AllowTextMessaging WHERE ASID=@ASID", sql);

            try
            {
                // Add parameters
                cmd.Parameters.AddWithValue("ASID", policy.ASID);
                cmd.Parameters.AddWithValue("CompanyCode", policy.CompanyCode);
                cmd.Parameters.AddWithValue("DisplayName", policy.DisplayName);
                cmd.Parameters.AddWithValue("Description", policy.Description);
                cmd.Parameters.AddWithValue("AllowNonProvisionableDevices", policy.AllowNonProvisionableDevice);
                cmd.Parameters.AddWithValue("RefreshIntervalInHours", policy.DevicePolicyRefreshInterval);
                cmd.Parameters.AddWithValue("RequirePassword", policy.DevicePasswordEnabled);
                cmd.Parameters.AddWithValue("RequireAlphanumericPassword", policy.AlphanumericDevicePasswordRequired);
                cmd.Parameters.AddWithValue("EnablePasswordRecovery", policy.PasswordRecoveryEnabled);
                cmd.Parameters.AddWithValue("RequireEncryptionOnDevice", policy.RequireDeviceEncryption);
                cmd.Parameters.AddWithValue("RequireEncryptionOnStorageCard", policy.RequireStorageCardEncryption);
                cmd.Parameters.AddWithValue("AllowSimplePassword", policy.AllowSimpleDevicePassword);
                cmd.Parameters.AddWithValue("NumberOfFailedAttempted", policy.MaxDevicePasswordFailedAttempts);
                cmd.Parameters.AddWithValue("MinimumPasswordLength", policy.MinDevicePasswordLength);
                cmd.Parameters.AddWithValue("InactivityTimeoutInMinutes", policy.MaxInactivityTimeDeviceLock);
                cmd.Parameters.AddWithValue("PasswordExpirationInDays", policy.DevicePasswordExpiration);
                cmd.Parameters.AddWithValue("EnforcePasswordHistory", policy.DevicePasswordHistory);
                cmd.Parameters.AddWithValue("IncludePastCalendarItems", policy.MaxCalendarAgeFilter);
                cmd.Parameters.AddWithValue("IncludePastEmailItems", policy.MaxEmailAgeFilter);
                cmd.Parameters.AddWithValue("LimitEmailSizeInKB", policy.MaxEmailBodyTruncationSize);
                cmd.Parameters.AddWithValue("AllowDirectPushWhenRoaming", policy.RequireManualSyncWhenRoaming);
                cmd.Parameters.AddWithValue("AllowHTMLEmail", policy.AllowHTMLEmail);
                cmd.Parameters.AddWithValue("AllowAttachmentsDownload", policy.AttachmentsEnabled);
                cmd.Parameters.AddWithValue("MaximumAttachmentSizeInKB", policy.MaxAttachmentSize);
                cmd.Parameters.AddWithValue("AllowRemovableStorage", policy.AllowStorageCard);
                cmd.Parameters.AddWithValue("AllowCamera", policy.AllowCamera);
                cmd.Parameters.AddWithValue("AllowWiFi", policy.AllowWiFi);
                cmd.Parameters.AddWithValue("AllowInfrared", policy.AllowIrDA);
                cmd.Parameters.AddWithValue("AllowInternetSharing", policy.AllowInternetSharing);
                cmd.Parameters.AddWithValue("AllowRemoteDesktop", policy.AllowRemoteDesktop);
                cmd.Parameters.AddWithValue("AllowDesktopSync", policy.AllowDesktopSync);
                cmd.Parameters.AddWithValue("AllowBluetooth", policy.AllowBluetooth);
                cmd.Parameters.AddWithValue("AllowBrowser", policy.AllowBrowser);
                cmd.Parameters.AddWithValue("AllowConsumerMail", policy.AllowConsumerEmail);
                cmd.Parameters.AddWithValue("AllowUnsignedApplications", policy.AllowUnsignedApplications);
                cmd.Parameters.AddWithValue("AllowUnsignedInstallationPackages", policy.AllowUnsignedInstallationPackages);
                cmd.Parameters.AddWithValue("IsEnterpriseCAL", policy.IsEnterpriseCAL);
                cmd.Parameters.AddWithValue("AllowTextMessaging", policy.AllowTextMessaging);


                // Open Connection
                sql.Open();

                // Update
                cmd.ExecuteNonQuery();

                // Close
                sql.Close();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cmd.Dispose();
                sql.Dispose();
            }
        }
        /// <summary>
        /// Updates an existing activesync policy
        /// </summary>
        /// <param name="policy"></param>
        /// <param name="exchangeVersion"></param>
        public void Update_ActiveSyncPolicy(BaseActivesyncPolicy policy, string exchangeVersion)
        {
            try
            {
                // Start clock
                Stopwatch stopwatch = Stopwatch.StartNew();

                // DEBUG //
                logger.Debug("Updating Activesync mailbox policy " + policy.DisplayName);

                // Run commands
                powershell = PowerShell.Create();
                powershell.Runspace = runspace;

                // Update the distribution group
                PSCommand cmd = new PSCommand();
                cmd.AddCommand("Set-ActiveSyncMailboxPolicy");

                if (!string.IsNullOrEmpty(policy.OldDisplayName))
                    cmd.AddParameter("Identity", policy.OldDisplayName);
                else
                    cmd.AddParameter("Identity", policy.DisplayName);

                cmd.AddParameter("Name", policy.DisplayName);
                cmd.AddParameter("AllowBluetooth", policy.AllowBluetooth);
                cmd.AddParameter("AllowBrowser", policy.AllowBrowser);
                cmd.AddParameter("AllowCamera", policy.AllowCamera);
                cmd.AddParameter("AllowConsumerEmail", policy.AllowConsumerEmail);
                cmd.AddParameter("AllowDesktopSync", policy.AllowDesktopSync);
                cmd.AddParameter("AllowHTMLEmail", policy.AllowHTMLEmail);
                cmd.AddParameter("AllowInternetSharing", policy.AllowInternetSharing);
                cmd.AddParameter("AllowIrDA", policy.AllowIrDA);
                cmd.AddParameter("AllowNonProvisionableDevices", policy.AllowNonProvisionableDevice);
                cmd.AddParameter("AllowRemoteDesktop", policy.AllowRemoteDesktop);
                cmd.AddParameter("AllowSimpleDevicePassword", policy.AllowSimpleDevicePassword);
                cmd.AddParameter("AllowStorageCard", policy.AllowStorageCard);
                cmd.AddParameter("AllowTextMessaging", policy.AllowTextMessaging);
                cmd.AddParameter("AllowUnsignedApplications", policy.AllowUnsignedApplications);
                cmd.AddParameter("AllowUnsignedInstallationPackages", policy.AllowUnsignedInstallationPackages);
                cmd.AddParameter("AllowWiFi", policy.AllowWiFi);
                cmd.AddParameter("AlphanumericDevicePasswordRequired", policy.AlphanumericDevicePasswordRequired);
                cmd.AddParameter("AttachmentsEnabled", policy.AttachmentsEnabled);
                cmd.AddParameter("DeviceEncryptionEnabled", policy.DeviceEncryptionEnabled);
                cmd.AddParameter("DevicePasswordEnabled", policy.DevicePasswordEnabled);
                cmd.AddParameter("MaxCalendarAgeFilter", policy.MaxCalendarAgeFilter);
                cmd.AddParameter("MaxEmailAgeFilter", policy.MaxEmailAgeFilter);
                cmd.AddParameter("PasswordRecoveryEnabled", policy.PasswordRecoveryEnabled);
                cmd.AddParameter("RequireStorageCardEncryption", policy.RequireStorageCardEncryption);
                cmd.AddParameter("RequireManualSyncWhenRoaming", policy.RequireManualSyncWhenRoaming);

                if (policy.DevicePolicyRefreshInterval > 0)
                    cmd.AddParameter("DevicePolicyRefreshInterval", new TimeSpan(policy.DevicePolicyRefreshInterval, 0, 0).ToString());
                else
                    cmd.AddParameter("DevicePolicyRefreshInterval", "Unlimited");

                if (policy.MaxAttachmentSize > 0)
                    cmd.AddParameter("MaxAttachmentSize", policy.MaxAttachmentSize + "KB");
                else
                    cmd.AddParameter("MaxAttachmentSize", "Unlimited");

                if (policy.MaxDevicePasswordFailedAttempts > 0)
                    cmd.AddParameter("MaxDevicePasswordFailedAttempts", policy.MaxDevicePasswordFailedAttempts);
                else
                    cmd.AddParameter("MaxDevicePasswordFailedAttempts", "Unlimited");

                if (policy.MaxEmailBodyTruncationSize > 0)
                    cmd.AddParameter("MaxEmailBodyTruncationSize", policy.MaxEmailBodyTruncationSize);
                else
                    cmd.AddParameter("MaxEmailBodyTruncationSize", "Unlimited");

                if (policy.MaxInactivityTimeDeviceLock > 0)
                    cmd.AddParameter("MaxInactivityTimeDeviceLock", new TimeSpan(0, policy.MaxInactivityTimeDeviceLock, 0).ToString());
                else
                    cmd.AddParameter("MaxInactivityTimeDeviceLock", "Unlimited");

                if (policy.MinDevicePasswordComplexCharacters > 0)
                    cmd.AddParameter("MinDevicePasswordComplexCharacters", policy.MinDevicePasswordComplexCharacters);
                else
                    cmd.AddParameter("MinDevicePasswordComplexCharacters", 1);

                if (policy.MinDevicePasswordLength > 0)
                    cmd.AddParameter("MinDevicePasswordLength", policy.MinDevicePasswordLength);
                else
                    cmd.AddParameter("MinDevicePasswordLength", null);

                cmd.AddParameter("Confirm", false);
                cmd.AddParameter("DomainController", this.domainController);
                powershell.Commands = cmd;
                powershell.Invoke();

                // Stop the clock
                stopwatch.Stop();

                // Check for errors
                CheckErrors(ref powershell);

                // DEBUG //
                logger.Info("Updated Activesync mailbox policy " + policy.DisplayName + " in " + stopwatch.Elapsed.ToString() + " second(s)");
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (powershell != null)
                    powershell.Dispose();
            }
        }
Пример #4
0
        /// <summary>
        /// Gets a specific policy from SQL
        /// </summary>
        /// <param name="policyID"></param>
        /// <returns></returns>
        public static BaseActivesyncPolicy GetExchangeActiveSyncPolicy(int policyID)
        {
            // Initialize SQL
            SqlConnection sql = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
            SqlCommand cmd = new SqlCommand(@"SELECT * FROM Plans_ExchangeActiveSync WHERE ASID=@ASID", sql);

            // Initialize object
            BaseActivesyncPolicy tmp = new BaseActivesyncPolicy();

            try
            {
                // Add parameter
                cmd.Parameters.AddWithValue("ASID", policyID);

                // Open Connection
                sql.Open();

                // Read
                SqlDataReader r = cmd.ExecuteReader();
                while (r.Read())
                {
                    tmp.ASID = int.Parse(r["ASID"].ToString());
                    tmp.DisplayName = r["DisplayName"].ToString();

                    if (r["CompanyCode"] != DBNull.Value)
                        tmp.CompanyCode = r["CompanyCode"].ToString();
                    else
                        tmp.CompanyCode = string.Empty;

                    if (r["Description"] != DBNull.Value)
                        tmp.Description = r["Description"].ToString();
                    else
                        tmp.Description = string.Empty;

                    if (r["AllowNonProvisionableDevices"] != DBNull.Value)
                        tmp.AllowNonProvisionableDevice = bool.Parse(r["AllowNonProvisionableDevices"].ToString());
                    else
                        tmp.AllowNonProvisionableDevice = true;

                    if (r["RefreshIntervalInHours"] != DBNull.Value)
                        tmp.DevicePolicyRefreshInterval = int.Parse(r["RefreshIntervalInHours"].ToString());
                    else
                        tmp.DevicePolicyRefreshInterval = 0;

                    if (r["RequirePassword"] != DBNull.Value)
                        tmp.DevicePasswordEnabled = bool.Parse(r["RequirePassword"].ToString());
                    else
                        tmp.DevicePasswordEnabled = false;

                    if (r["RequireAlphaNumericPassword"] != DBNull.Value)
                        tmp.AlphanumericDevicePasswordRequired = bool.Parse(r["RequireAlphaNumericPassword"].ToString());
                    else
                        tmp.AlphanumericDevicePasswordRequired = false;

                    if (r["EnablePasswordRecovery"] != DBNull.Value)
                        tmp.PasswordRecoveryEnabled = bool.Parse(r["EnablePasswordRecovery"].ToString());
                    else
                        tmp.PasswordRecoveryEnabled = false;

                    if (r["RequireEncryptionOnDevice"] != DBNull.Value)
                        tmp.RequireDeviceEncryption = bool.Parse(r["RequireEncryptionOnDevice"].ToString());
                    else
                        tmp.RequireDeviceEncryption = false;

                    if (r["RequireEncryptionOnStorageCard"] != DBNull.Value)
                        tmp.DeviceEncryptionEnabled = bool.Parse(r["RequireEncryptionOnStorageCard"].ToString());
                    else
                        tmp.DeviceEncryptionEnabled = false;

                    if (r["AllowSimplePassword"] != DBNull.Value)
                        tmp.AllowSimpleDevicePassword = bool.Parse(r["AllowSimplePassword"].ToString());
                    else
                        tmp.AllowSimpleDevicePassword = true;

                    if (r["NumberOfFailedAttempted"] != DBNull.Value)
                        tmp.MaxDevicePasswordFailedAttempts = int.Parse(r["NumberOfFailedAttempted"].ToString());
                    else
                        tmp.MaxDevicePasswordFailedAttempts = 0;

                    if (r["MinimumPasswordLength"] != DBNull.Value)
                        tmp.MinDevicePasswordLength = int.Parse(r["MinimumPasswordLength"].ToString());
                    else
                        tmp.MinDevicePasswordLength = 0;

                    if (r["InactivityTimeoutInMinutes"] != DBNull.Value)
                        tmp.MaxInactivityTimeDeviceLock = int.Parse(r["InactivityTimeoutInMinutes"].ToString());
                    else
                        tmp.MaxInactivityTimeDeviceLock = 0;

                    if (r["PasswordExpirationInDays"] != DBNull.Value)
                        tmp.DevicePasswordExpiration = int.Parse(r["PasswordExpirationInDays"].ToString());
                    else
                        tmp.DevicePasswordExpiration = 0;

                    if (r["EnforcePasswordHistory"] != DBNull.Value)
                        tmp.DevicePasswordHistory = int.Parse(r["EnforcePasswordHistory"].ToString());
                    else
                        tmp.DevicePasswordHistory = 0;

                    if (r["IncludePastCalendarItems"] != DBNull.Value)
                        tmp.MaxCalendarAgeFilter = r["IncludePastCalendarItems"].ToString();
                    else
                        tmp.MaxCalendarAgeFilter = "All";

                    if (r["IncludePastEmailItems"] != DBNull.Value)
                        tmp.MaxEmailAgeFilter = r["IncludePastEmailItems"].ToString();
                    else
                        tmp.MaxEmailAgeFilter = "All";

                    if (r["LimitEmailSizeInKB"] != DBNull.Value)
                        tmp.MaxEmailBodyTruncationSize = int.Parse(r["LimitEmailSizeInKB"].ToString());
                    else
                        tmp.MaxEmailBodyTruncationSize = 0;

                    if (r["AllowDirectPushWhenRoaming"] != DBNull.Value)
                        tmp.RequireManualSyncWhenRoaming = bool.Parse(r["AllowDirectPushWhenRoaming"].ToString());
                    else
                        tmp.RequireManualSyncWhenRoaming = false;

                    if (r["AllowHTMLEmail"] != DBNull.Value)
                        tmp.AllowHTMLEmail = bool.Parse(r["AllowHTMLEmail"].ToString());
                    else
                        tmp.AllowHTMLEmail = true;

                    if (r["AllowAttachmentsDownload"] != DBNull.Value)
                        tmp.AttachmentsEnabled = bool.Parse(r["AllowAttachmentsDownload"].ToString());
                    else
                        tmp.AttachmentsEnabled = true;

                    if (r["MaximumAttachmentSizeInKB"] != DBNull.Value)
                        tmp.MaxAttachmentSize = int.Parse(r["MaximumAttachmentSizeInKB"].ToString());
                    else
                        tmp.MaxAttachmentSize = 0;

                    if (r["AllowRemovableStorage"] != DBNull.Value)
                        tmp.AllowStorageCard = bool.Parse(r["AllowRemovableStorage"].ToString());
                    else
                        tmp.AllowStorageCard = true;

                    if (r["AllowCamera"] != DBNull.Value)
                        tmp.AllowCamera = bool.Parse(r["AllowCamera"].ToString());
                    else
                        tmp.AllowCamera = true;

                    if (r["AllowWiFi"] != DBNull.Value)
                        tmp.AllowWiFi = bool.Parse(r["AllowWiFi"].ToString());
                    else
                        tmp.AllowWiFi = true;

                    if (r["AllowInfrared"] != DBNull.Value)
                        tmp.AllowIrDA = bool.Parse(r["AllowInfrared"].ToString());
                    else
                        tmp.AllowIrDA = true;

                    if (r["AllowInternetSharing"] != DBNull.Value)
                        tmp.AllowInternetSharing = bool.Parse(r["AllowInternetSharing"].ToString());
                    else
                        tmp.AllowInternetSharing = true;

                    if (r["AllowRemoteDesktop"] != DBNull.Value)
                        tmp.AllowRemoteDesktop = bool.Parse(r["AllowRemoteDesktop"].ToString());
                    else
                        tmp.AllowRemoteDesktop = true;

                    if (r["AllowDesktopSync"] != DBNull.Value)
                        tmp.AllowDesktopSync = bool.Parse(r["AllowDesktopSync"].ToString());
                    else
                        tmp.AllowDesktopSync = true;

                    if (r["AllowBluetooth"] != DBNull.Value)
                        tmp.AllowBluetooth = r["AllowBluetooth"].ToString();
                    else
                        tmp.AllowBluetooth = "Allow";

                    if (r["AllowBrowser"] != DBNull.Value)
                        tmp.AllowBrowser = bool.Parse(r["AllowBrowser"].ToString());
                    else
                        tmp.AllowBrowser = true;

                    if (r["AllowConsumerMail"] != DBNull.Value)
                        tmp.AllowConsumerEmail = bool.Parse(r["AllowConsumerMail"].ToString());
                    else
                        tmp.AllowConsumerEmail = true;

                    if (r["AllowUnsignedApplications"] != DBNull.Value)
                        tmp.AllowUnsignedApplications = bool.Parse(r["AllowUnsignedApplications"].ToString());
                    else
                        tmp.AllowUnsignedApplications = true;

                    if (r["AllowUnsignedInstallationPackages"] != DBNull.Value)
                        tmp.AllowUnsignedInstallationPackages = bool.Parse(r["AllowUnsignedInstallationPackages"].ToString());
                    else
                        tmp.AllowUnsignedInstallationPackages = true;

                    if (r["IsEnterpriseCAL"] != DBNull.Value)
                        tmp.IsEnterpriseCAL = bool.Parse(r["IsEnterpriseCAL"].ToString());
                    else
                        tmp.IsEnterpriseCAL = false;

                    if (r["AllowTextMessaging"] != DBNull.Value)
                        tmp.AllowTextMessaging = bool.Parse(r["AllowTextMessaging"].ToString());
                    else
                        tmp.AllowTextMessaging = true;
                }

                // Close
                r.Close();
                sql.Close();

                // Dispose
                r.Dispose();

                // Return
                return tmp;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cmd.Dispose();
                sql.Dispose();
            }
        }
Пример #5
0
        private void CreateNewPolicy()
        {
            ExchCmds powershell = null;

            try
            {
                BaseActivesyncPolicy policy = new BaseActivesyncPolicy();

                // Compile list of general settings
                policy.DisplayName = txtDisplayName.Text;
                policy.Description = txtDescription.Text;

                // Compile list of basic settings
                policy.AllowBluetooth = ddlAllowBluetooth.SelectedValue;
                policy.AllowBrowser = cbAllowBrowser.Checked;
                policy.AllowCamera = cbAllowCamera.Checked;
                policy.AllowConsumerEmail = cbAllowConsumerMail.Checked;
                policy.AllowDesktopSync = cbAllowDesktopSync.Checked;
                policy.AllowInternetSharing = cbAllowInternetSharing.Checked;
                policy.AllowSimpleDevicePassword = cbAllowSimplePassword.Checked;
                policy.AllowTextMessaging = cbAllowTextMessaging.Checked;
                policy.AllowWiFi = cbAllowWIFI.Checked;
                policy.DevicePasswordEnabled = cbPasswordEnabled.Checked;
                policy.AlphanumericDevicePasswordRequired = cbAlphanumericPwdRequired.Checked;
                policy.MaxDevicePasswordFailedAttempts = ddlMaxFailedPasswordAttempts.SelectedValue;
                policy.AllowHTMLEmail = cbAllowHTMLEmail.Checked;
                policy.AllowIrDA = cbAllowInfrared.Checked;
                policy.AllowNonProvisionableDevice = cbAllowNonProvisionable.Checked;
                policy.AllowPOPIMAPEmail = cbAllowPOPIMAP.Checked;
                policy.AllowRemoteDesktop = cbAllowRemoteDesktop.Checked;
                policy.AllowSMIMEEncryptionAlgorithmNegotiation = ddlAllowSMIMEEncryptionAlgorithmNeg.SelectedValue;
                policy.AllowSMIMESoftCerts = cbAllowSMIME.Checked;
                policy.AllowStorageCard = cbAllowStorageCard.Checked;
                policy.AllowUnsignedApplications = cbAllowUnsignedApps.Checked;
                policy.AllowUnsignedInstallationPackages = cbAllowUnsignedInstallPackages.Checked;
                policy.AttachmentsEnabled = cbAttachmentsEnabled.Checked;
                policy.DeviceEncryptionEnabled = cbDeviceEncryptionEnabled.Checked;
                policy.DevicePasswordExpiration = txtPasswordExpiration.Text;
                policy.DevicePolicyRefreshInterval = txtPolicyRefreshInterval.Text;
                policy.MaxAttachmentSize = txtMaxAttachmentSize.Text;
                policy.MaxCalendarAgeFilter = ddlMaxCalendarAgeFilter.SelectedValue;
                policy.MaxEmailAgeFilter = ddlMaxEmailAgeFilter.SelectedValue;
                policy.PasswordRecoveryEnabled = cbPasswordRecovery.Checked;
                policy.RequireDeviceEncryption = cbRequireDeviceEncryption.Checked;
                policy.RequireEncryptedSMIMEMessages = cbRequireEncryptedSMIMEMsg.Checked;
                policy.RequireEncryptionSMIMEAlgorithm = ddlRequireEncryptedSMIMEAlgorithm.SelectedValue;
                policy.RequireSignedSMIMEMessages = cbRequireSignedSMIMEMsg.Checked;
                policy.RequireSignedSMIMEAlgorithm = ddlRequireSignedSMIMEMsg.SelectedValue;
                policy.RequireManualSyncWhenRoaming = cbRequireManualSyncRoaming.Checked;
                policy.RequireStorageCardEncryption = cbRequireStorageCardEncryption.Checked;

                policy.MaxEmailHTMLBodyTruncationSize = txtMaxHTMLBodyTruncSize.Text;
                policy.MaxEmailBodyTruncationSize = txtMaxEmailBodyTruncSize.Text;

                int minComplexChar = 0;
                int.TryParse(txtMinPwdComplexChar.Text, out minComplexChar);
                policy.MinDevicePasswordComplexCharacters = minComplexChar;
                
                int inactivityLock = 0;
                int.TryParse(txtMaxInactivityLock.Text, out inactivityLock);
                policy.MaxInactivityTimeDeviceLock = inactivityLock;

                int passwordHistory = 0;
                int.TryParse(txtPasswordHistory.Text, out passwordHistory);
                policy.DevicePasswordHistory = passwordHistory;

                int minPwdLength = 0;
                int.TryParse(txtMinPwdLength.Text, out minPwdLength);
                policy.MinDevicePasswordLength = minPwdLength;

                // Exchange 2013
                policy.AllowApplePushNotifications = cbAllowApplePushNotifications.Checked;

                // Initilaze powershell
                powershell = new ExchCmds(Retrieve.ExchangeUri, Retrieve.Username, Retrieve.Password, Retrieve.ExchangeKerberos, Retrieve.PrimaryDC);

                // Insert into Exchange
                powershell.New_ActiveSyncPolicy(policy, CPContext.SelectedCompanyCode, Retrieve.ExchangeVersion);

                // Insert into SQL
                SQLExchange.AddExchangeActiveSyncPolicy(CPContext.SelectedCompanyCode, txtDisplayName.Text, txtDescription.Text);

                // Notify
                notification1.SetMessage(controls.notification.MessageType.Success, "Successfully added new activesync policy");
            }
            catch (Exception ex)
            {
                notification1.SetMessage(controls.notification.MessageType.Error, "Error creating activesync policy: " + ex.Message);
            }
            finally
            {
                if (powershell != null)
                    powershell.Dispose();

                // Refresh view
                GetPolicies();
            }
        }