public static int ChangeUserPassword(string username, string oldPassword, string newPassword, string ip)
        {
            // place log record
            TaskManager.StartTask("USER", "CHANGE_PASSWORD_BY_USERNAME_PASSWORD", username);
            TaskManager.WriteParameter("IP", ip);

            try
            {
                UserInfo user = GetUserByUsernamePassword(username, oldPassword, ip);
                if (user == null)
                {
                    TaskManager.WriteWarning("Account not found");
                    return(BusinessErrorCodes.ERROR_USER_NOT_FOUND);
                }

                // change password
                DataProvider.ChangeUserPassword(-1, user.UserId,
                                                CryptoUtils.Encrypt(newPassword));

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #2
0
        private static void SetStorageSpaceFolderEncryptDataAccessStatusInternal(int storageSpaceFolderId, bool enabled)
        {
            TaskManager.StartTask("STORAGE_SPACES", "SET_ENCRYPT_DATA_ACCESS_STATUS");

            try
            {
                var folder = GetStorageSpaceFolderById(storageSpaceFolderId);

                if (folder == null)
                {
                    throw new Exception(string.Format("Storage space folder with id={0} not found", storageSpaceFolderId));
                }

                var storageSpace = StorageSpacesController.GetStorageSpaceById(folder.StorageSpaceId);

                if (storageSpace == null)
                {
                    throw new Exception(string.Format("Storage space with id={0} not found", folder.StorageSpaceId));
                }

                var ss = GetStorageSpaceService(storageSpace.ServiceId);

                ss.ShareSetEncyptDataAccess(folder.Path, enabled);
            }
            catch (Exception exception)
            {
                throw TaskManager.WriteError(exception);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static int CloseTerminalServicesSession(int serverId, int sessionId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsAdmin
                                                            | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load server info
            ServerInfo server = ServerController.GetServerById(serverId);

            // place log record
            TaskManager.StartTask("SERVER", "RESET_TERMINAL_SESSION", sessionId, serverId);

            try
            {
                GetServerService(serverId).CloseTerminalServicesSession(sessionId);
                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static UserInfo GetUserByUsernamePassword(string username, string password, string ip)
        {
            // place log record
            TaskManager.StartTask("USER", "GET_BY_USERNAME_PASSWORD", username);
            TaskManager.WriteParameter("IP", ip);

            try
            {
                // try to get user from database
                UserInfo user = GetUserInternally(username);

                // check if the user exists
                if (user == null)
                {
                    TaskManager.WriteWarning("Account not found");
                    return(null);
                }

                // compare user passwords
                if (user.Password == password)
                {
                    return(user);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #5
0
        public static int TerminateWindowsProcess(int serverId, int pid)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsAdmin
                                                            | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load server info
            ServerInfo server = ServerController.GetServerById(serverId);

            // place log record
            TaskManager.StartTask("SERVER", "TERMINATE_SYSTEM_PROCESS", pid);
            TaskManager.ItemId = serverId;

            try
            {
                GetServerService(serverId).TerminateWindowsProcess(pid);
                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static int ChangeUserPassword(int userId, string password)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // get user details
            UserInfo user = GetUserInternally(userId);

            // place log record
            TaskManager.StartTask("USER", "CHANGE_PASSWORD", user.Username);
            TaskManager.ItemId = user.UserId;

            try
            {
                DataProvider.ChangeUserPassword(SecurityContext.User.UserId, userId,
                                                CryptoUtils.Encrypt(password));

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #7
0
        public static int ChangeWindowsServiceStatus(int serverId, string id, WindowsServiceStatus status)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsAdmin
                                                            | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load server info
            ServerInfo server = ServerController.GetServerById(serverId);

            // place log record
            TaskManager.StartTask("SERVER", "CHANGE_WINDOWS_SERVICE_STATUS", id);
            TaskManager.ItemId = serverId;
            TaskManager.WriteParameter("New Status", status);

            try
            {
                GetServerService(serverId).ChangeWindowsServiceStatus(id, status);
                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #8
0
        public static int RebootSystem(int serverId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsAdmin
                                                            | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load server info
            ServerInfo server = ServerController.GetServerById(serverId);

            // place log record
            TaskManager.StartTask("SERVER", "REBOOT");
            TaskManager.ItemId = serverId;

            try
            {
                GetServerService(serverId).RebootSystem();
                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #9
0
        public static int ClearLog(int serverId, string logName)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsAdmin
                                                            | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            TaskManager.StartTask("SERVER", "CLEAR_EVENT_LOG", logName);
            TaskManager.ItemId = serverId;

            try
            {
                GetServerService(serverId).ClearLog(logName);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }

            return(0);
        }
Exemple #10
0
        private static bool CheckQuota(int packageId)
        {
            TaskManager.StartTask("CRM", "CHECK_QUOTA");
            bool res = false;

            try
            {
                // check account
                int errorCode = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
                if (errorCode < 0)
                {
                    return(false);
                }


                PackageContext cntx = PackageController.GetPackageContext(packageId);
                return(cntx.Quotas[Quotas.CRM_ORGANIZATION] != null && !cntx.Quotas[Quotas.CRM_ORGANIZATION].QuotaExhausted);
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);
                res = false;
            }
            finally
            {
                TaskManager.CompleteTask();
            }
            return(res);
        }
Exemple #11
0
        public static int CalculatePackageDiskspace(int packageId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // place log record
            TaskManager.StartTask("SPACE", "CALCULATE_DISKSPACE", packageId);

            try
            {
                // create thread parameters
                ThreadStartParameters prms = new ThreadStartParameters();
                prms.UserId     = SecurityContext.User.UserId;
                prms.Parameters = new object[] { packageId };

                Thread t = new Thread(new ParameterizedThreadStart(CalculatePackageDiskspaceAsync));
                t.Start(prms);
                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public void ChangePackagesServiceItemsState()
        {
            // impersonate thread
            if (userId != -1)
            {
                SecurityContext.SetThreadPrincipal(userId);
            }

            TaskManager.StartTask("SPACE", "CHANGE_ITEMS_STATUS");

            // collect required service items
            List <ServiceProviderItem> items = new List <ServiceProviderItem>();

            foreach (PackageInfo package in packages)
            {
                items.AddRange(PackageController.GetServiceItemsForStatistics(
                                   0, package.PackageId, false, false, true, false)); // suspendable items
            }

            // order items by service
            Dictionary <int, List <ServiceProviderItem> > orderedItems =
                PackageController.OrderServiceItemsByServices(items);

            // process items
            bool enabled = (ItemsStatus == PackageStatus.Active);

            foreach (int serviceId in orderedItems.Keys)
            {
                ProcessServiceItems(true, enabled, serviceId, orderedItems[serviceId]);
            }

            // add log record
            TaskManager.CompleteTask();
        }
Exemple #13
0
        public static int SetFilePermissions(int packageId, string path, UserPermission[] users, bool resetChildPermissions)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "SET_PERMISSIONS", path, packageId);

            try
            {
                OS.OperatingSystem os       = GetOS(packageId);
                string             fullPath = GetFullPackagePath(packageId, path);

                // get users OU defined on web server
                string usersOU = WebServerController.GetWebUsersOU(packageId);

                os.GrantGroupNtfsPermissions(fullPath, users, usersOU, resetChildPermissions);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static int UpdateSqlUser(SqlUser item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            SqlUser origItem = (SqlUser)PackageController.GetPackageItem(item.Id);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_MSSQL_USERS_PACKAGE_ITEM_NOT_FOUND);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("SQL_USER", "UPDATE", origItem.Name);
            TaskManager.ItemId = item.Id;

            try
            {
                // get service
                DatabaseServer sql = GetDatabaseServer(origItem.ServiceId);

                // update service item
                sql.UpdateUser(item, GetSqlDatabasesArray(origItem.PackageId, origItem.GroupName));

                // update meta item
                if (item.Password == "")
                {
                    item.Password = CryptoUtils.Decrypt(origItem.Password);
                }

                item.Password = CryptoUtils.Encrypt(item.Password);
                PackageController.UpdatePackageItem(item);
                return(0);
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);

                // Return a generic error instead of re-throwing an exception
                return(BusinessErrorCodes.FAILED_EXECUTE_SERVICE_OPERATION);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        internal static int SetupControlPanelAccounts(string passwordA, string passwordB, string ip)
        {
            try
            {
                TaskManager.StartTask("SYSTEM", "COMPLETE_SCPA");
                //
                TaskManager.WriteParameter("Password A", passwordA);
                TaskManager.WriteParameter("Password B", passwordB);
                TaskManager.WriteParameter("IP Address", ip);
                //
                var enabledScpaMode = GetSystemSetupMode();
                //
                if (enabledScpaMode == false)
                {
                    //
                    TaskManager.WriteWarning("Attempt to execute SCPA procedure for an uknown reason");
                    //
                    return(BusinessErrorCodes.FAILED_EXECUTE_SERVICE_OPERATION);
                }

                // Entering the security context into Supervisor mode
                SecurityContext.SetThreadSupervisorPrincipal();
                //
                var accountA = UserController.GetUserInternally("serveradmin");
                var accountB = UserController.GetUserInternally("admin");
                //
                var resultCodeA = UserController.ChangeUserPassword(accountA.UserId, passwordA);
                //
                if (resultCodeA < 0)
                {
                    TaskManager.WriteParameter("Result Code A", resultCodeA);
                    //
                    return(resultCodeA);
                }
                //
                var resultCodeB = UserController.ChangeUserPassword(accountB.UserId, passwordB);
                //
                if (resultCodeB < 0)
                {
                    TaskManager.WriteParameter("Result Code B", resultCodeB);
                    //
                    return(resultCodeB);
                }
                // Disable SCPA mode
                SetSystemSettings(SystemSettings.SETUP_SETTINGS, SystemSettings.Empty);
                // Operation has succeeded
                return(0);
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);
                //
                return(BusinessErrorCodes.FAILED_EXECUTE_SERVICE_OPERATION);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #16
0
        public static int ZipFiles(int packageId, string[] files, string archivePath)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "ZIP_FILES", archivePath, packageId);

            if (files != null)
            {
                foreach (string file in files)
                {
                    TaskManager.Write(file);
                }
            }

            try
            {
                OS.OperatingSystem os          = GetOS(packageId);
                string             zipFilePath = GetFullPackagePath(packageId, archivePath);

                List <string> archFiles  = new List <string>();
                string        rootFolder = "";
                foreach (string file in files)
                {
                    string archFile = GetFullPackagePath(packageId, file);
                    int    idx      = archFile.LastIndexOf("\\");
                    rootFolder = archFile.Substring(0, idx);
                    archFiles.Add(archFile.Substring(idx + 1));
                }

                os.ZipFiles(zipFilePath, rootFolder, archFiles.ToArray());

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static ResultObject DeleteOrganization(int itemId)
        {
            ResultObject result = new ResultObject();

            result.IsSuccess = true;

            try
            {
                // initialize task manager
                TaskManager.StartTask(TaskManagerSource, "DELETE_ORGANIZATION");
                TaskManager.WriteParameter("itemId", itemId);

                // load organization item
                ExchangeOrganization item = PackageController.GetPackageItem(itemId) as ExchangeOrganization;
                if (item == null)
                {
                    return(Error <ResultObject>(OrganizationNotFoundError));
                }

                #region Check Space and Account
                // Check account
                int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
                if (accountCheck < 0)
                {
                    return(Warning <ResultObject>((-accountCheck).ToString()));
                }

                // Check space
                int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);
                if (packageCheck < 0)
                {
                    return(Warning <ResultObject>((-packageCheck).ToString()));
                }
                #endregion

                // get Exchange service
                ExchangeServerHostedEdition exchange = GetExchangeService(item.ServiceId);

                // delete organization
                exchange.DeleteOrganization(item.Name);

                // delete meta-item
                PackageController.DeletePackageItem(itemId);

                return(result);
            }
            catch (Exception ex)
            {
                // log error
                TaskManager.WriteError(ex);

                // exit with error code
                return(Error <ResultObject>(DeleteOrganizationError, ex.Message));
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #18
0
        private static T StartTask <T>(string source, string taskName) where T : ResultObject, new()
        {
            TaskManager.StartTask(source, taskName);
            T res = new T();

            res.IsSuccess = true;
            return(res);
        }
Exemple #19
0
        public static int UpdateSite(StatsSite item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            StatsSite origItem = (StatsSite)PackageController.GetPackageItem(item.Id);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_STATS_PACKAGE_ITEM_NOT_FOUND);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // update statistics site
            item.Name   = origItem.Name;
            item.SiteId = origItem.SiteId;

            // place log record
            TaskManager.StartTask("STATS_SITE", "UPDATE", origItem.Name);
            TaskManager.ItemId = origItem.Id;

            try
            {
                StatisticsServer stats = new StatisticsServer();
                ServiceProviderProxy.Init(stats, origItem.ServiceId);
                stats.UpdateSite(item);

                // update service item
                PackageController.UpdatePackageItem(item);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #20
0
        public static string[] UnzipFiles(int packageId, string[] files)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(null);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(null);
            }

            // place log record
            TaskManager.StartTask("FILES", "UNZIP_FILES", packageId);

            if (files != null)
            {
                foreach (string file in files)
                {
                    TaskManager.Write(file);
                }
            }

            try
            {
                List <string> unzippedFiles = new List <string>();

                OS.OperatingSystem os = GetOS(packageId);

                for (int i = 0; i < files.Length; i++)
                {
                    string zipFilePath    = GetFullPackagePath(packageId, files[i]);
                    string destFolderPath = zipFilePath.Substring(0, zipFilePath.LastIndexOf("\\"));
                    unzippedFiles.AddRange(os.UnzipFiles(zipFilePath, destFolderPath));
                }

                return(unzippedFiles.ToArray());
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #21
0
        public static int DeleteWebPartsPackage(int itemId, string packageName)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            SharePointSite item = (SharePointSite)PackageController.GetPackageItem(itemId);

            if (item == null)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_NOT_FOUND);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("SHAREPOINT", "UNINSTALL_WEBPARTS", item.Name);
            TaskManager.ItemId = itemId;
            TaskManager.WriteParameter("Package name", packageName);

            try
            {
                SharePointServer sps = GetSharePoint(item.ServiceId);

                // uninstall webparts
                if (!String.IsNullOrEmpty(packageName))
                {
                    sps.DeleteWebPartsPackage(item.Name, packageName);
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #22
0
        // Implementation of ThreadStart delegate.
        // Used by Scheduler to kick off events on a seperate thread
        private void RunSchedule()
        {
            // impersonate thread
            UserInfo user = PackageController.GetPackageOwner(scheduleInfo.PackageId);

            SecurityContext.SetThreadPrincipal(user.UserId);

            List <BackgroundTaskParameter> parameters = new List <BackgroundTaskParameter>();

            foreach (ScheduleTaskParameterInfo prm in scheduleInfo.Parameters)
            {
                parameters.Add(new BackgroundTaskParameter(prm.ParameterId, prm.ParameterValue));
            }

            TaskManager.StartTask("SCHEDULER", "RUN_SCHEDULE", scheduleInfo.ScheduleName, scheduleInfo.ScheduleId,
                                  scheduleInfo.ScheduleId, scheduleInfo.PackageId, scheduleInfo.MaxExecutionTime,
                                  parameters);

            // run task
            try
            {
                // create scheduled task object
                SchedulerTask objTask = (SchedulerTask)Activator.CreateInstance(Type.GetType(task.TaskType));

                if (objTask != null)
                {
                    objTask.DoWork();
                }
                else
                {
                    throw new Exception(String.Format("Could not create scheduled task of '{0}' type",
                                                      task.TaskType));
                }
                // Thread.Sleep(40000);
            }
            catch (Exception ex)
            {
                // log error
                TaskManager.WriteError(ex, "Error executing scheduled task");
            }
            finally
            {
                // complete task
                try
                {
                    TaskManager.CompleteTask();
                }
                catch (Exception)
                {
                }
            }
        }
Exemple #23
0
        public static int UpdateSharePointGroup(SystemGroup item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            SystemGroup origItem = (SystemGroup)PackageController.GetPackageItem(item.Id);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_GROUPS_PACKAGE_ITEM_NOT_FOUND);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("SHAREPOINT", "UPDATE_GROUP", origItem.Name);
            TaskManager.ItemId = item.Id;

            try
            {
                // get service
                SharePointServer sps = GetSharePoint(origItem.ServiceId);

                item.Description = "WebsitePanel System Group";

                // update service item
                sps.UpdateGroup(item);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static int UpdateUserSettings(UserSettings settings)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // get user details
            UserInfo user = GetUserInternally(settings.UserId);

            // place log record
            TaskManager.StartTask("USER", "UPDATE_SETTINGS", user.Username);
            TaskManager.ItemId = user.UserId;

            try
            {
                // build xml
                XmlDocument doc       = new XmlDocument();
                XmlElement  nodeProps = doc.CreateElement("properties");
                if (settings.SettingsArray != null)
                {
                    foreach (string[] pair in settings.SettingsArray)
                    {
                        XmlElement nodeProp = doc.CreateElement("property");
                        nodeProp.SetAttribute("name", pair[0]);
                        nodeProp.SetAttribute("value", pair[1]);
                        nodeProps.AppendChild(nodeProp);
                    }
                }

                string xml = nodeProps.OuterXml;

                // update settings
                DataProvider.UpdateUserSettings(SecurityContext.User.UserId,
                                                settings.UserId, settings.SettingsName, xml);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static int AuthenticateUser(string username, string password, string ip)
        {
            // start task
            TaskManager.StartTask("USER", "AUTHENTICATE", username);
            TaskManager.WriteParameter("IP", ip);

            try
            {
                // try to get user from database
                UserInfo user = GetUserInternally(username);

                // check if the user exists
                if (user == null)
                {
                    TaskManager.WriteWarning("Wrong username");
                    return(BusinessErrorCodes.ERROR_USER_WRONG_USERNAME);
                }

                // compare user passwords
                if (user.Password != password)
                {
                    TaskManager.WriteWarning("Wrong password");
                    return(BusinessErrorCodes.ERROR_USER_WRONG_PASSWORD);
                }

                // check status
                if (user.Status == UserStatus.Cancelled)
                {
                    TaskManager.WriteWarning("Account cancelled");
                    return(BusinessErrorCodes.ERROR_USER_ACCOUNT_CANCELLED);
                }

                if (user.Status == UserStatus.Pending)
                {
                    TaskManager.WriteWarning("Account pending");
                    return(BusinessErrorCodes.ERROR_USER_ACCOUNT_PENDING);
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Exemple #26
0
        public static int CreateFile(int packageId, string path)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "CREATE_FILE", path);
            TaskManager.ItemId = packageId;

            try
            {
                OS.OperatingSystem os       = GetOS(packageId);
                string             fullPath = GetFullPackagePath(packageId, path);

                // cannot create a file with the same name as a directory
                if (os.DirectoryExists(fullPath))
                {
                    return(BusinessErrorCodes.ERROR_FILE_CREATE_FILE_WITH_DIR_NAME);
                }

                // create file
                os.CreateFile(fullPath);

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public static int DeleteSqlDatabase(int itemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original meta item
            SqlDatabase origItem = (SqlDatabase)PackageController.GetPackageItem(itemId);

            if (origItem == null)
            {
                return(BusinessErrorCodes.ERROR_MSSQL_DATABASES_PACKAGE_ITEM_NOT_FOUND);
            }

            // place log record
            TaskManager.StartTask("SQL_DATABASE", "DELETE", origItem.Name);
            TaskManager.ItemId = itemId;
            TaskManager.WriteParameter("Provider", origItem.GroupName);

            try
            {
                // get service
                DatabaseServer sql = GetDatabaseServer(origItem.ServiceId);

                // delete service item
                sql.DeleteDatabase(origItem.Name);

                // delete meta item
                PackageController.DeletePackageItem(origItem.Id);

                return(0);
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);
                // Return a generic error instead of re-throwing an exception
                return(BusinessErrorCodes.FAILED_EXECUTE_SERVICE_OPERATION);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        public void DeletePackagesServiceItems()
        {
            // impersonate thread
            if (userId != -1)
            {
                SecurityContext.SetThreadPrincipal(userId);
            }


            // delete package by package
            foreach (PackageInfo package in packages)
            {
                TaskManager.StartTask("SPACE", "DELETE_ITEMS", package.PackageName);
                TaskManager.WriteParameter("User", package.UserId);

                // get package service items
                List <ServiceProviderItem> items = PackageController.GetServiceItemsForStatistics(
                    0, package.PackageId, false, false, false, true); // disposable items

                // order items by service
                Dictionary <int, List <ServiceProviderItem> > orderedItems =
                    PackageController.OrderServiceItemsByServices(items);

                // delete service items by service sets
                foreach (int serviceId in orderedItems.Keys)
                {
                    ServiceInfo service = ServerController.GetServiceInfo(serviceId);
                    //Delete Exchange Organization
                    if (service.ProviderId == 103 /*Organizations*/)
                    {
                        OrganizationController.DeleteOrganization(orderedItems[serviceId][0].Id);
                        //int exchangeId = PackageController.GetPackageServiceId(package.PackageId, ResourceGroups.Exchange2007);
                        //ExchangeServerController.DeleteOrganization(orderedItems[serviceId][0].Id);
                    }
                    else
                    {
                        ProcessServiceItems(false, false, serviceId, orderedItems[serviceId]);
                    }
                }

                // delete package from database
                DataProvider.DeletePackage(SecurityContext.User.UserId, package.PackageId);
            }

            // add log record
            TaskManager.CompleteTask();
        }
Exemple #29
0
        // Implementation of ThreadStart delegate.
        // Used by Scheduler to kick off events on a seperate thread
        private void RunSchedule()
        {
            // impersonate thread
            UserInfo user = PackageController.GetPackageOwner(scheduleInfo.PackageId);

            SecurityContext.SetThreadPrincipal(user.UserId);

            TaskManager.StartTask("SCHEDULER", "RUN_SCHEDULE", scheduleInfo.ScheduleName);
            TaskManager.PackageId            = scheduleInfo.PackageId;
            TaskManager.ItemId               = scheduleInfo.ScheduleId;
            TaskManager.ScheduleId           = scheduleInfo.ScheduleId;
            TaskManager.MaximumExecutionTime = scheduleInfo.MaxExecutionTime;

            // set task parameters
            foreach (ScheduleTaskParameterInfo prm in scheduleInfo.Parameters)
            {
                TaskManager.TaskParameters[prm.ParameterId] = prm.ParameterValue;
            }

            // run task
            try
            {
                // create scheduled task object
                SchedulerTask objTask = (SchedulerTask)Activator.CreateInstance(Type.GetType(task.TaskType));

                if (objTask != null)
                {
                    objTask.DoWork();
                }
                else
                {
                    throw new Exception(String.Format("Could not create scheduled task of '{0}' type",
                                                      task.TaskType));
                }
            }
            catch (Exception ex)
            {
                // log error
                TaskManager.WriteError(ex, "Error executing scheduled task");
            }
            finally
            {
                // complete task
                TaskManager.CompleteTask();
            }
        }
Exemple #30
0
        public static GalleryApplicationsResult GetGalleryApplicationsByServiceId(int serviceId)
        {
            GalleryApplicationsResult result;

            //
            try
            {
                TaskManager.StartTask(TASK_MANAGER_SOURCE, GET_SRV_GALLERY_APPS_TASK);
                //
                if (SecurityContext.CheckAccount(DemandAccount.IsAdmin) != 0)
                {
                    return(WAG_MODULE_NOT_AVAILABLE <GalleryApplicationsResult>());
                }
                //
                WebServer webServer = WebServerController.GetWebServer(serviceId);
                // ERROR: WAG is unavailable
                if (!webServer.IsMsDeployInstalled())
                {
                    return(WAG_MODULE_NOT_AVAILABLE <GalleryApplicationsResult>());
                }
                //
                result = webServer.GetGalleryApplications(String.Empty);
                //
                if (!result.IsSuccess)
                {
                    foreach (string errorMessage in result.ErrorCodes)
                    {
                        TaskManager.WriteError(errorMessage);
                    }
                    //
                    return(WAG_GENERIC_MODULE_ERROR <GalleryApplicationsResult>());
                }
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);
                //
                return(WAG_GENERIC_MODULE_ERROR <GalleryApplicationsResult>());
            }
            finally
            {
                TaskManager.CompleteTask();
            }
            //
            return(result);
        }