Пример #1
0
        private void RollbackInstallation(InstallationInfo inst)
        {
            // remove virtual dir
            if (inst[PROPERTY_VDIR_CREATED] != null)
            {
                // delete virtual directory
                WebServerController.DeleteAppVirtualDirectory(inst.WebSiteId, inst.VirtualDir);

                // delete folder
                FilesController.DeleteFiles(inst.PackageId, new string[] { inst[PROPERTY_CONTENT_PATH] });
            }

            // remove database
            if (inst[PROPERTY_DATABASE_CREATED] != null)
            {
                DatabaseServerController.DeleteSqlDatabase(inst.DatabaseId);
            }

            // remove database user
            if (inst[PROPERTY_USER_CREATED] != null)
            {
                DatabaseServerController.DeleteSqlUser(inst.UserId);
            }
        }
Пример #2
0
 public int DeleteSqlDatabase(int itemId)
 {
     return(DatabaseServerController.DeleteSqlDatabase(itemId));
 }
Пример #3
0
 public int UpdateSqlDatabase(SqlDatabase item)
 {
     return(DatabaseServerController.UpdateSqlDatabase(item));
 }
Пример #4
0
 public int AddSqlDatabase(SqlDatabase item, string groupName)
 {
     return(DatabaseServerController.AddSqlDatabase(item, groupName));
 }
Пример #5
0
 public SqlDatabase GetSqlDatabase(int itemId)
 {
     return(DatabaseServerController.GetSqlDatabase(itemId));
 }
Пример #6
0
 public List <SqlDatabase> GetSqlDatabases(int packageId, string groupName, bool recursive)
 {
     return(DatabaseServerController.GetSqlDatabases(packageId, groupName, recursive));
 }
        public static int AddSite(SharePointSite item)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

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

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

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

            // check quota
            QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.SHAREPOINT_SITES);

            if (quota.QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_QUOTA_LIMIT);
            }

            // check if stats resource is available
            int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.SharePoint);

            if (serviceId == 0)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE);
            }

            // check package items
            if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SharePointSite)) != null)
            {
                return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_EXISTS);
            }

            // place log record
            TaskManager.StartTask("SHAREPOINT", "ADD_SITE", item.Name);
            TaskManager.WriteParameter("Database group", item.DatabaseGroupName);
            TaskManager.WriteParameter("Database name", item.DatabaseName);
            TaskManager.WriteParameter("Database user", item.DatabaseUser);

            int databaseItemId     = 0;
            int databaseUserItemId = 0;

            try
            {
                // load web site
                WebSite siteItem = (WebSite)PackageController.GetPackageItemByName(item.PackageId,
                                                                                   item.Name, typeof(WebSite));

                if (siteItem == null)
                {
                    return(BusinessErrorCodes.ERROR_WEB_SITE_SERVICE_UNAVAILABLE);
                }

                // get service web site
                WebServer web = new WebServer();
                ServiceProviderProxy.Init(web, siteItem.ServiceId);
                WebSite site = web.GetSite(siteItem.SiteId);

                /////////////////////////////////////////
                //
                //  PREPARE SHAREPOINT SITE INSTALLATION
                //

                ServiceInfo wssService = ServerController.GetServiceInfo(serviceId);
                bool        wss30      = (wssService.ProviderId == 23);     // WSS 3.0

                // remember original web site bindings
                ServerBinding[] bindings = site.Bindings;

                // set application pool and root folder
                item.ApplicationPool = site.ApplicationPool;
                item.RootFolder      = site.ContentPath;

                // change web site .NET framework if required
                bool siteUpdated = false;
                if (!wss30 && (site.AspNetInstalled != "1" ||
                               site.DedicatedApplicationPool))
                {
                    site.AspNetInstalled          = "1";
                    site.DedicatedApplicationPool = false;
                    web.UpdateSite(site);

                    siteUpdated = true;
                }

                if (wss30 && site.AspNetInstalled != "2")
                {
                    site.AspNetInstalled = "2";
                    web.UpdateSite(site);

                    siteUpdated = true;
                }

                if (siteUpdated)
                {
                    site = web.GetSite(siteItem.SiteId);
                    item.ApplicationPool = site.ApplicationPool;
                }

                if (site.FrontPageInstalled)
                {
                    // remove FrontPage
                    web.UninstallFrontPage(siteItem.SiteId, siteItem.FrontPageAccount);
                }

                // create SQL database
                SqlDatabase database = new SqlDatabase();
                database.PackageId = item.PackageId;
                database.Name      = item.DatabaseName;
                databaseItemId     = DatabaseServerController.AddSqlDatabase(database, item.DatabaseGroupName);
                if (databaseItemId < 0)
                {
                    return(databaseItemId);
                }

                // create SQL user
                SqlUser dbUser = new SqlUser();
                dbUser.PackageId   = item.PackageId;
                dbUser.Name        = item.DatabaseUser;
                dbUser.Password    = item.DatabasePassword;
                databaseUserItemId = DatabaseServerController.AddSqlUser(dbUser, item.DatabaseGroupName);
                if (databaseUserItemId < 0)
                {
                    return(databaseUserItemId);
                }

                // delete SQL database from service
                // and change database user role
                int sqlServiceId = PackageController.GetPackageServiceId(item.PackageId, item.DatabaseGroupName);
                if (sqlServiceId < 0)
                {
                    return(BusinessErrorCodes.ERROR_MSSQL_RESOURCE_UNAVAILABLE);
                }

                // load server settings
                StringDictionary sqlSettings = ServerController.GetServiceSettings(sqlServiceId);
                item.DatabaseServer = sqlSettings["ExternalAddress"];

                DatabaseServer dbServer = new DatabaseServer();
                ServiceProviderProxy.Init(dbServer, sqlServiceId);

                // delete database from service
                dbServer.DeleteDatabase(database.Name);

                // give SQL user "db_creator" role
                dbServer.ExecuteSqlNonQuery("master", String.Format(
                                                "sp_addsrvrolemember '{0}', 'dbcreator'\nGO", dbUser.Name));

                // install SharePoint site
                SharePointServer sps = GetSharePoint(serviceId);
                sps.ExtendVirtualServer(item);

                // remove SQL user from "db_creator" role
                dbServer.ExecuteSqlNonQuery("master", String.Format(
                                                "sp_dropsrvrolemember '{0}', 'dbcreator'\nGO", dbUser.Name));

                // restore original web site bindings
                web.UpdateSiteBindings(site.SiteId, bindings, false);

                // save statistics item
                item.ServiceId = serviceId;
                int itemId = PackageController.AddPackageItem(item);

                TaskManager.ItemId = itemId;

                return(itemId);
            }
            catch (Exception ex)
            {
                // delete database if required
                if (databaseItemId > 0)
                {
                    DatabaseServerController.DeleteSqlDatabase(databaseItemId);
                }

                // delete user if required
                if (databaseUserItemId > 0)
                {
                    DatabaseServerController.DeleteSqlUser(databaseUserItemId);
                }

                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Пример #8
0
 public DatabaseBrowserConfiguration GetDatabaseBrowserLogonScript(int packageId,
                                                                   string groupName, string username)
 {
     return(DatabaseServerController.GetDatabaseBrowserLogonScript(packageId, groupName, username));
 }
Пример #9
0
 public int TruncateSqlDatabase(int itemId)
 {
     return(DatabaseServerController.TruncateSqlDatabase(itemId));
 }
Пример #10
0
 public DatabaseBrowserConfiguration GetDatabaseBrowserConfiguration(int packageId, string groupName)
 {
     return(DatabaseServerController.GetDatabaseBrowserConfiguration(packageId, groupName));
 }
Пример #11
0
 public int RestoreSqlDatabase(int itemId, string[] uploadedFiles, string[] packageFiles)
 {
     return(DatabaseServerController.RestoreSqlDatabase(itemId, uploadedFiles, packageFiles));
 }
Пример #12
0
 public string AppendSqlBackupBinaryChunk(int itemId, string fileName, string path, byte[] chunk)
 {
     return(DatabaseServerController.AppendSqlBackupBinaryChunk(itemId, fileName, path, chunk));
 }
Пример #13
0
 public byte[] GetSqlBackupBinaryChunk(int itemId, string path, int offset, int length)
 {
     return(DatabaseServerController.GetSqlBackupBinaryChunk(itemId, path, offset, length));
 }
Пример #14
0
 public string BackupSqlDatabase(int itemId, string backupName,
                                 bool zipBackup, bool download, string folderName)
 {
     return(DatabaseServerController.BackupSqlDatabase(itemId, backupName, zipBackup,
                                                       download, folderName));
 }
Пример #15
0
 public int UpdateSqlUser(SqlUser item)
 {
     return(DatabaseServerController.UpdateSqlUser(item));
 }
Пример #16
0
        public int InstallWebApplication(InstallationInfo inst)
        {
            // place log record
            TaskManager.StartTask("APP_INSTALLER", "INSTALL_APPLICATION", inst.PackageId);

            TaskManager.WriteParameter("Virtual directory", inst.VirtualDir);
            TaskManager.WriteParameter("Database group", inst.DatabaseGroup);

            try
            {
                // get application info
                app = GetApplication(inst.PackageId, inst.ApplicationId);

                BackgroundTask topTask = TaskManager.TopTask;

                topTask.ItemName = app.Name;

                TaskController.UpdateTask(topTask);

                // check web site for existance
                WebSite webSite = WebServerController.GetWebSite(inst.WebSiteId);

                if (webSite == null)
                {
                    return(BusinessErrorCodes.ERROR_WEB_INSTALLER_WEBSITE_NOT_EXISTS);
                }

                TaskManager.WriteParameter("Web site", webSite.Name);

                webSiteName = webSite.Name;
                siteId      = webSite.SiteId;

                // change web site properties if required
                if (String.IsNullOrEmpty(inst.VirtualDir))
                {
                    ChangeAppVirtualDirectoryProperties(webSite, app.WebSettings);
                    WebServerController.UpdateWebSite(webSite);
                }

                // get OS service
                int osId = PackageController.GetPackageServiceId(inst.PackageId, "os");
                os = new OS.OperatingSystem();
                ServiceProviderProxy.Init(os, osId);

                // get remote content path
                contentPath = webSite.ContentPath;

                // create virtual dir if required
                if (!String.IsNullOrEmpty(inst.VirtualDir))
                {
                    // check if the required virtual dir already exists
                    contentPath = Path.Combine(contentPath, inst.VirtualDir);

                    WebAppVirtualDirectory vdir = null;
                    int result = WebServerController.AddAppVirtualDirectory(inst.WebSiteId, inst.VirtualDir, contentPath);
                    if (result == BusinessErrorCodes.ERROR_VDIR_ALREADY_EXISTS)
                    {
                        // the directory alredy exists
                        vdir = WebServerController.GetAppVirtualDirectory(
                            inst.WebSiteId, inst.VirtualDir);

                        contentPath = vdir.ContentPath;
                    }
                    else
                    {
                        vdir = WebServerController.GetAppVirtualDirectory(
                            inst.WebSiteId, inst.VirtualDir);

                        inst[PROPERTY_VDIR_CREATED] = "True";
                    }

                    // change virtual directory properties if required
                    ChangeAppVirtualDirectoryProperties(vdir, app.WebSettings);
                    WebServerController.UpdateAppVirtualDirectory(inst.WebSiteId, vdir);
                }

                // deploy application codebase ZIP and then unpack it
                string codebasePath       = app.Codebase;
                string remoteCodebasePath = Path.Combine(contentPath, Path.GetFileName(app.Codebase));

                // make content path absolute
                string absContentPath = FilesController.GetFullPackagePath(inst.PackageId, contentPath);

                // save content path
                inst[PROPERTY_CONTENT_PATH]          = contentPath;
                inst[PROPERTY_ABSOLUTE_CONTENT_PATH] = absContentPath;

                // copy ZIP to the target server
                FileStream stream        = File.OpenRead(codebasePath);
                int        BUFFER_LENGTH = 5000000;

                byte[] buffer    = new byte[BUFFER_LENGTH];
                int    readBytes = 0;
                while (true)
                {
                    readBytes = stream.Read(buffer, 0, BUFFER_LENGTH);

                    if (readBytes < BUFFER_LENGTH)
                    {
                        Array.Resize <byte>(ref buffer, readBytes);
                    }

                    FilesController.AppendFileBinaryChunk(inst.PackageId, remoteCodebasePath, buffer);

                    if (readBytes < BUFFER_LENGTH)
                    {
                        break;
                    }
                }



                // unpack codebase
                inst[PROPERTY_INSTALLED_FILES] = String.Join(";",
                                                             FilesController.UnzipFiles(inst.PackageId, new string[] { remoteCodebasePath }));

                // delete codebase zip
                FilesController.DeleteFiles(inst.PackageId, new string[] { remoteCodebasePath });

                // check/create databases
                if (!String.IsNullOrEmpty(inst.DatabaseGroup) &&
                    String.Compare(inst.DatabaseGroup, "None", true) != 0)
                {
                    // database
                    if (inst.DatabaseId == 0)
                    {
                        TaskManager.WriteParameter("Database name", inst.DatabaseName);

                        // we should create a new database
                        SqlDatabase db = new SqlDatabase();
                        db.PackageId    = inst.PackageId;
                        db.Name         = inst.DatabaseName;
                        inst.DatabaseId = DatabaseServerController.AddSqlDatabase(db, inst.DatabaseGroup);
                        if (inst.DatabaseId < 0)
                        {
                            // rollback installation
                            RollbackInstallation(inst);

                            // return error
                            return(inst.DatabaseId); // there was an error when creating database
                        }

                        inst[PROPERTY_DATABASE_CREATED] = "True";
                    }
                    else
                    {
                        // existing database
                        SqlDatabase db = DatabaseServerController.GetSqlDatabase(inst.DatabaseId);
                        inst.DatabaseName = db.Name;

                        TaskManager.WriteParameter("Database name", inst.DatabaseName);
                    }

                    SqlUser user = null;
                    // database user
                    if (inst.UserId == 0)
                    {
                        TaskManager.WriteParameter("Database user", inst.Username);

                        // NEW USER
                        user           = new SqlUser();
                        user.PackageId = inst.PackageId;
                        user.Name      = inst.Username;
                        user.Databases = new string[] { inst.DatabaseName };
                        user.Password  = inst.Password;
                        inst.UserId    = DatabaseServerController.AddSqlUser(user, inst.DatabaseGroup);
                        if (inst.UserId < 0)
                        {
                            // rollback installation
                            RollbackInstallation(inst);

                            // return error
                            return(inst.UserId); // error while adding user
                        }

                        inst[PROPERTY_USER_CREATED] = "True";
                    }
                    else
                    {
                        // EXISTING USER
                        user          = DatabaseServerController.GetSqlUser(inst.UserId);
                        inst.Username = user.Name;

                        TaskManager.WriteParameter("Database user", inst.Username);

                        List <string> databases = new List <string>();
                        databases.AddRange(user.Databases);

                        if (!databases.Contains(inst.DatabaseName))
                        {
                            databases.Add(inst.DatabaseName);

                            user.Databases = databases.ToArray();
                            DatabaseServerController.UpdateSqlUser(user);
                        }
                    }

                    // check connectivity with SQL Server and credentials provided
                    // load user item
                    int sqlServiceId = PackageController.GetPackageServiceId(inst.PackageId, inst.DatabaseGroup);
                    sql = new DatabaseServer();
                    ServiceProviderProxy.Init(sql, sqlServiceId);

                    if (!sql.CheckConnectivity(inst.DatabaseName, inst.Username,
                                               inst.Password))
                    {
                        // can't connect to the database
                        RollbackInstallation(inst);

                        return(BusinessErrorCodes.ERROR_WEB_INSTALLER_CANT_CONNECT_DATABASE);
                    }

                    // read SQL server settings
                    StringDictionary settings = ServerController.GetServiceSettings(sqlServiceId);
                    serverIpAddressExternal = settings["ExternalAddress"];
                    if (settings.ContainsKey("InternalAddress"))
                    {
                        serverIpAddressInternal = settings["InternalAddress"];
                    }
                }

                // ********* RUN INSTALL SCENARIO ***********
                int scriptResult = RunInstallScenario(inst);
                if (scriptResult < 0)
                {
                    // rollback installation
                    RollbackInstallation(inst);

                    // return error
                    return(scriptResult);
                }

                // add new installation to the database
                return(0);
            }
            catch (Exception ex)
            {
                // rollback installation
                RollbackInstallation(inst);

                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
Пример #17
0
 public DataSet GetRawSqlDatabasesPaged(int packageId, string groupName,
                                        string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
 {
     return(DatabaseServerController.GetRawSqlDatabasesPaged(packageId, groupName, filterColumn, filterValue,
                                                             sortColumn, startRow, maximumRows));
 }
Пример #18
0
        public override void DoWork()
        {
            // Input parameters:
            //  - DATABASE_GROUP
            //  - DATABASE_NAME
            //  - BACKUP_FOLDER
            //  - BACKUP_NAME
            //  - ZIP_BACKUP

            BackgroundTask topTask = TaskManager.TopTask;

            string databaseGroup = (string)topTask.GetParamValue("DATABASE_GROUP");
            string databaseName  = (string)topTask.GetParamValue("DATABASE_NAME");
            string backupFolder  = (string)topTask.GetParamValue("BACKUP_FOLDER");
            string backupName    = (string)topTask.GetParamValue("BACKUP_NAME");
            string strZipBackup  = (string)topTask.GetParamValue("ZIP_BACKUP");

            // check input parameters
            if (String.IsNullOrEmpty(databaseName))
            {
                TaskManager.WriteWarning("Specify 'Database Name' task parameter.");
                return;
            }

            bool zipBackup = (strZipBackup.ToLower() == "true");

            if (String.IsNullOrEmpty(backupName))
            {
                backupName = databaseName + (zipBackup ? ".zip" : ".bak");
            }
            else
            {
                // check extension
                string ext = Path.GetExtension(backupName);
                if (zipBackup && String.Compare(ext, ".zip", true) != 0)
                {
                    // change extension to .zip
                    backupName = Path.GetFileNameWithoutExtension(backupName) + ".zip";
                }
            }

            // try to find database
            SqlDatabase item = (SqlDatabase)PackageController.GetPackageItemByName(topTask.PackageId, databaseGroup,
                                                                                   databaseName, typeof(SqlDatabase));

            if (item == null)
            {
                TaskManager.WriteError("Database with the specified name was not found in the current hosting space.");
                return;
            }

            if (String.IsNullOrEmpty(backupFolder))
            {
                backupFolder = "\\";
            }

            // substitute parameters
            DateTime d    = DateTime.Now;
            string   date = d.ToString("yyyyMMdd");
            string   time = d.ToString("HHmm");

            backupFolder = Utils.ReplaceStringVariable(backupFolder, "date", date);
            backupFolder = Utils.ReplaceStringVariable(backupFolder, "time", time);
            backupName   = Utils.ReplaceStringVariable(backupName, "date", date);
            backupName   = Utils.ReplaceStringVariable(backupName, "time", time);

            // backup database
            DatabaseServerController.BackupSqlDatabase(item.Id, backupName, zipBackup, false, backupFolder);
        }
Пример #19
0
        public static int DeleteSite(int itemId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

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

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

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

            // place log record
            TaskManager.StartTask("SHAREPOINT", "DELETE_SITE", origItem.Name, itemId);

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

                // delete service item
                sps.UnextendVirtualServer(origItem.Name, true);

                try
                {
                    // delete database
                    ServiceProviderItem dbItem = PackageController.GetPackageItemByName(origItem.PackageId, origItem.DatabaseGroupName,
                                                                                        origItem.DatabaseName, typeof(SqlDatabase));
                    if (dbItem != null)
                    {
                        DatabaseServerController.DeleteSqlDatabase(dbItem.Id);
                    }

                    // delete database user
                    dbItem = PackageController.GetPackageItemByName(origItem.PackageId, origItem.DatabaseGroupName,
                                                                    origItem.DatabaseUser, typeof(SqlUser));
                    if (dbItem != null)
                    {
                        DatabaseServerController.DeleteSqlUser(dbItem.Id);
                    }
                }
                catch (Exception ex2)
                {
                    TaskManager.WriteError(ex2);
                }

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

                try
                {
                    // start web site
                    WebSite site = WebServerController.GetWebSite(origItem.PackageId, origItem.Name);
                    if (site != null)
                    {
                        WebServerController.ChangeSiteState(site.Id, ServerState.Started);
                    }
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex);
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }