2020-06-29 11:40:42 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-25 16:05:14 +00:00
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
using ASC.Api.Core.Middleware;
|
|
|
|
|
using ASC.Common;
|
2020-09-17 12:04:28 +00:00
|
|
|
|
using ASC.Core;
|
2020-06-29 11:40:42 +00:00
|
|
|
|
using ASC.Data.Backup.Contracts;
|
|
|
|
|
using ASC.Data.Backup.Models;
|
|
|
|
|
using ASC.Web.Api.Routing;
|
2020-09-17 12:04:28 +00:00
|
|
|
|
using ASC.Web.Studio.Utility;
|
2020-06-25 16:05:14 +00:00
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace ASC.Data.Backup.Controllers
|
|
|
|
|
{
|
|
|
|
|
[DefaultRoute]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class BackupController
|
|
|
|
|
{
|
|
|
|
|
private BackupAjaxHandler BackupHandler { get; }
|
2020-09-17 12:04:28 +00:00
|
|
|
|
private CoreBaseSettings CoreBaseSettings { get; }
|
|
|
|
|
private TenantExtra TenantExtra { get; }
|
|
|
|
|
|
|
|
|
|
public BackupController(
|
|
|
|
|
BackupAjaxHandler backupAjaxHandler,
|
|
|
|
|
CoreBaseSettings coreBaseSettings,
|
|
|
|
|
TenantExtra tenantExtra)
|
2020-06-29 11:40:42 +00:00
|
|
|
|
{
|
|
|
|
|
BackupHandler = backupAjaxHandler;
|
2020-09-17 12:04:28 +00:00
|
|
|
|
CoreBaseSettings = coreBaseSettings;
|
|
|
|
|
TenantExtra = tenantExtra;
|
2020-06-29 11:40:42 +00:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the backup schedule of the current portal
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <category>Backup</category>
|
|
|
|
|
/// <returns>Backup Schedule</returns>
|
|
|
|
|
[Read("getbackupschedule")]
|
|
|
|
|
public BackupAjaxHandler.Schedule GetBackupSchedule()
|
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
return BackupHandler.GetSchedule();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create the backup schedule of the current portal
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="storageType">Storage type</param>
|
|
|
|
|
/// <param name="storageParams">Storage parameters</param>
|
|
|
|
|
/// <param name="backupsStored">Max of the backup's stored copies</param>
|
|
|
|
|
/// <param name="cronParams">Cron parameters</param>
|
|
|
|
|
/// <param name="backupMail">Include mail in the backup</param>
|
|
|
|
|
/// <category>Backup</category>
|
|
|
|
|
[Create("createbackupschedule")]
|
|
|
|
|
public void CreateBackupSchedule(BackupStorageType storageType, [FromQuery] Dictionary<string, string> storageParams, int backupsStored, [FromBody] BackupAjaxHandler.CronParams cronParams, bool backupMail)
|
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
BackupHandler.CreateSchedule(storageType, storageParams, backupsStored, cronParams, backupMail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete the backup schedule of the current portal
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <category>Backup</category>
|
|
|
|
|
[Delete("deletebackupschedule")]
|
|
|
|
|
public void DeleteBackupSchedule()
|
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
BackupHandler.DeleteSchedule();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Start a backup of the current portal
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="storageType">Storage Type</param>
|
|
|
|
|
/// <param name="storageParams">Storage Params</param>
|
|
|
|
|
/// <param name="backupMail">Include mail in the backup</param>
|
|
|
|
|
/// <category>Backup</category>
|
|
|
|
|
/// <returns>Backup Progress</returns>
|
|
|
|
|
[Create("startbackup")]
|
|
|
|
|
public BackupProgress StartBackup(Models.Backup backup)
|
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
BackupHandler.StartBackup(backup.StorageType, backup.StorageParams ?? new Dictionary<string, string>(), backup.BackupMail);
|
|
|
|
|
return BackupHandler.GetBackupProgress();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the progress of the started backup
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <category>Backup</category>
|
|
|
|
|
/// <returns>Backup Progress</returns>
|
|
|
|
|
[Read("getbackupprogress")]
|
|
|
|
|
public BackupProgress GetBackupProgress()
|
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
return BackupHandler.GetBackupProgress();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the backup history of the started backup
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <category>Backup</category>
|
|
|
|
|
/// <returns>Backup History</returns>
|
|
|
|
|
[Read("getbackuphistory")]
|
|
|
|
|
public List<BackupHistoryRecord> GetBackupHistory()
|
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
return BackupHandler.GetBackupHistory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete the backup with the specified id
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <category>Backup</category>
|
|
|
|
|
[Delete("deletebackup/{id}")]
|
|
|
|
|
public void DeleteBackup(Guid id)
|
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
BackupHandler.DeleteBackup(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete all backups of the current portal
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <category>Backup</category>
|
|
|
|
|
/// <returns>Backup History</returns>
|
|
|
|
|
[Delete("deletebackuphistory")]
|
|
|
|
|
public void DeleteBackupHistory()
|
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
BackupHandler.DeleteAllBackups();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Start a data restore of the current portal
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="backupId">Backup Id</param>
|
|
|
|
|
/// <param name="storageType">Storage Type</param>
|
|
|
|
|
/// <param name="storageParams">Storage Params</param>
|
|
|
|
|
/// <param name="notify">Notify about backup to users</param>
|
|
|
|
|
/// <category>Backup</category>
|
|
|
|
|
/// <returns>Restore Progress</returns>
|
|
|
|
|
[Create("startrestore")]
|
|
|
|
|
public BackupProgress StartBackupRestore(BackupRestore backupRestore)
|
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
BackupHandler.StartRestore(backupRestore.BackupId, backupRestore.StorageType, backupRestore.StorageParams, backupRestore.Notify);
|
|
|
|
|
return BackupHandler.GetBackupProgress();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the progress of the started restore
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <category>Backup</category>
|
|
|
|
|
/// <returns>Restore Progress</returns>
|
|
|
|
|
[Read("getrestoreprogress", true)] //NOTE: this method doesn't check payment!!!
|
|
|
|
|
public BackupProgress GetRestoreProgress()
|
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
return BackupHandler.GetRestoreProgress();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///<visible>false</visible>
|
|
|
|
|
[Read("backuptmp")]
|
2020-10-09 10:05:48 +00:00
|
|
|
|
public object GetTempPath()
|
2020-06-29 11:40:42 +00:00
|
|
|
|
{
|
2020-09-17 12:04:28 +00:00
|
|
|
|
if (CoreBaseSettings.Standalone)
|
|
|
|
|
{
|
|
|
|
|
TenantExtra.DemandControlPanelPermission();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 11:40:42 +00:00
|
|
|
|
return BackupHandler.GetTmpFolder();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static class BackupControllerExtension
|
|
|
|
|
{
|
|
|
|
|
public static DIHelper AddBackupController(this DIHelper services)
|
|
|
|
|
{
|
|
|
|
|
return services
|
|
|
|
|
.AddBackupAjaxHandler()
|
2020-09-17 12:04:28 +00:00
|
|
|
|
.AddIpSecurityFilter()
|
|
|
|
|
.AddCoreBaseSettingsService()
|
|
|
|
|
.AddTenantExtraService();
|
2020-06-29 11:40:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|