public static int ReinstallService(Service service) { var reinstallInfo = new GameHostingReinstallInfo { ServiceId = service.ServiceId, Variables = service.Variables.ToString() }; var taskInfo = new TaskInfo { CreatedBy = 3, RunNow = true, UserId = service.UserId, DisplayName = "Reinstall Service " + service.IpAddress, Source = service.GetType().ToString(), SourceId = service.ServiceId.ToString() }; var stepInfo = new StepInfo(string.Empty, "d3b2aa93-7e2b-4e0d-8080-67d14b2fa8a9", 5, service.ServerId, ObjectXml.ObjectToXml(reinstallInfo)); taskInfo.AddStep(stepInfo); var taskData = new TaskData { Service = service, StepInfo = stepInfo, TaskInfo = taskInfo }; var action = new ActionsTab(taskData, new Server(service.ServerId)); return(action.TaskId); }
public async Task <ActionResult> Restore(int id, int backupId = 0) { this.EnforceFeaturePermission("FileManager"); if (backupId == 0) { return(this.SendError("No backup selected to restore.")); } var service = Service.GetSelectedService(); var server = TCAdmin.SDK.Objects.Server.GetSelectedServer(); var directorySecurity = service.GetDirectorySecurityForCurrentUser(); var fileSystem = TCAdmin.SDK.Objects.Server.GetSelectedServer().FileSystemService; var backup = new Backup(backupId); var backupSolution = backup.Provider.Create <BackupSolution>(); try { var randomFileName = TCAdmin.SDK.Misc.Random.RandomString(8, true, true) + ".zip"; var saveTo = FileSystem.CombinePath(server.OperatingSystem, service.RootDirectory, backup.Path, randomFileName); if (backupSolution.AllowsDirectDownload) { var downloadUrl = await backupSolution.DirectDownloadLink(backup); fileSystem.DownloadFile(saveTo, downloadUrl); } else { var bytes = await backupSolution.DownloadBytes(backup); var memoryStream = new MemoryStream(bytes); var byteBuffer = new byte[1024 * 1024 * 2]; int bytesRead; memoryStream.Position = 0; if (fileSystem.FileExists(saveTo)) { fileSystem.DeleteFile(saveTo); } while ((bytesRead = memoryStream.Read(byteBuffer, 0, byteBuffer.Length)) > 0) { fileSystem.AppendFile(saveTo, byteBuffer.Take(bytesRead).ToArray()); } fileSystem.SetOwnerAutomatically(saveTo); } fileSystem.Extract(saveTo, FileSystem.CombinePath(server.OperatingSystem, service.RootDirectory, backup.Path), ObjectXml.ObjectToXml(directorySecurity)); fileSystem.DeleteFile(saveTo); return(this.SendSuccess($"Restored <strong>{backup.Name}</strong>")); } catch (Exception e) { return(this.SendException(e, "Unable to restore backup - " + e.Message)); } }
public virtual string Compress(Backup backup, BackupRequest request) { var service = new Service(backup.ServiceId); var server = new Server(service.ServerId); var fileSystemService = server.FileSystemService; var baseDir = FileSystem.CombinePath(server.OperatingSystem, service.RootDirectory, request.Path); var toCompress = request.Directories.Select(x => x.Name).ToList(); toCompress.AddRange(request.Files.Select(x => x.Name + x.Extension)); return(fileSystemService.CompressFiles(baseDir, toCompress.ToArray(), ObjectXml.ObjectToXml(GenerateVirtualDirectorySecurity(service)), 5000000000)); }
public VirtualDirectorySecurity(string currentDirectory) { UserType = UserType.Admin; var ds = new TCAdmin.SDK.VirtualFileSystem.VirtualDirectorySecurity { PermissionMode = PermissionMode.Basic, Permissions = Permission.Read | Permission.Write | Permission.Delete, PermissionType = PermissionType.Root, RootPhysicalPath = currentDirectory + "\\", DisableOwnerCheck = true, DisableSymlinkCheck = true }; VirtualDirectorySecurityObject = ds; VirtualDirectorySecurityString = ObjectXml.ObjectToXml(ds); }
public VirtualDirectorySecurity(TCAdmin.SDK.Web.References.FileSystem.FileSystem fileSystem, string currentDirectory, UserType type, int gameId) { UserType = type; if (!fileSystem.DirectoryExists(currentDirectory)) { throw new CustomMessageException(EmbedTemplates.CreateErrorEmbed("Could not find directory.")); } var game = new TCAdmin.GameHosting.SDK.Objects.Game(gameId); var ds = new TCAdmin.SDK.VirtualFileSystem.VirtualDirectorySecurity { PermissionMode = PermissionMode.Basic, Permissions = Permission.Read | Permission.Write | Permission.Delete, PermissionType = PermissionType.Root, RootPhysicalPath = currentDirectory + "\\", RealPhysicalPath = TCAdmin.SDK.Misc.FileSystem.FixAbsoluteFilePath(currentDirectory, OperatingSystem.Windows), DisableOwnerCheck = true, DisableSymlinkCheck = true, VirtualDirectoryName = currentDirectory }; if (type == UserType.SubAdmin) { var f = game.FileSystemPermissions.FirstOrDefault(x => x.RootPhysicalPath == "$[SubAdminFiles]"); ds.AdditionalPermissions = f.AdditionalPermissions; ds.Filters = f.Filters; } if (type == UserType.User) { var f = game.FileSystemPermissions.FirstOrDefault(x => x.RootPhysicalPath == "$[UserFiles]"); ds.AdditionalPermissions = f.AdditionalPermissions; ds.Filters = f.Filters; } VirtualDirectorySecurityObject = ds; VirtualDirectorySecurityString = ObjectXml.ObjectToXml(ds); }
public static int RunServiceCreation(GameHostingCreateInfo createInfo, string name) { var taskInfo = new TaskInfo { CreatedBy = 3, RunNow = true, UserId = 1, DisplayName = name }; var stepInfo = new StepInfo(string.Empty, "d3b2aa93-7e2b-4e0d-8080-67d14b2fa8a9", 1, createInfo.ServerId, ObjectXml.ObjectToXml(createInfo)); taskInfo.AddStep(stepInfo); var taskData = new TaskData { StepInfo = stepInfo, TaskInfo = taskInfo }; var action = new ActionsTab(taskData, new Server(createInfo.ServerId)); return(action.TaskId); }