Skip to content

Commit

Permalink
Add device banning. Extract interfaces from DataService and Applicati…
Browse files Browse the repository at this point in the history
…onConfig. Create unit tests.
  • Loading branch information
bitbound committed Nov 25, 2020
1 parent e5d2322 commit 167a9fd
Show file tree
Hide file tree
Showing 50 changed files with 434 additions and 118 deletions.
2 changes: 1 addition & 1 deletion Agent/Services/AgentSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private void RegisterMessageHandlers()
await ScriptRunner.RunScript(mode, fileID, commandResultID, requesterID, HubConnection);
});

HubConnection.On("UninstallClient", () =>
HubConnection.On("UninstallAgent", () =>
{
Uninstaller.UninstallAgent();
});
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Whenever there's a reference to `appsettings.json` in this document, it refers t
For more information on configuring ASP.NET Core, see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1.

* AllowApiLogin: Whether to allow logging in via the API controller. API access tokens are recommended over this approach.
* BannedDevices: An array of device IDs, names, or IP addresses to ban. When they try to connect, an uninstall command will immediately be sent back.
* DataRetentionInDays: How long event logs and remote command logs will be kept.
* DBProvider: Determines which of the three connection strings (at the top) will be used. The appropriate DB provider for the database type is automatically loaded in code.
* DefaultPrompt: The default prompt string you'll see for each line on the console.
Expand Down
8 changes: 4 additions & 4 deletions Server/API/AgentUpdateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ public class AgentUpdateController : ControllerBase


public AgentUpdateController(IWebHostEnvironment hostingEnv,
DataService dataService,
ApplicationConfig appConfig)
IDataService dataService,
IApplicationConfig appConfig)
{
HostEnv = hostingEnv;
DataService = dataService;
AppConfig = appConfig;
}

private DataService DataService { get; }
public ApplicationConfig AppConfig { get; }
private IDataService DataService { get; }
public IApplicationConfig AppConfig { get; }
private IWebHostEnvironment HostEnv { get; }


Expand Down
4 changes: 2 additions & 2 deletions Server/API/AlertsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namespace Remotely.Server.API
[ServiceFilter(typeof(ApiAuthorizationFilter))]
public class AlertsController : ControllerBase
{
public AlertsController(DataService dataService, IEmailSenderEx emailSender)
public AlertsController(IDataService dataService, IEmailSenderEx emailSender)
{
DataService = dataService;
EmailSender = emailSender;
}

private DataService DataService { get; }
private IDataService DataService { get; }
private IEmailSenderEx EmailSender { get; }

[HttpPost("Create")]
Expand Down
4 changes: 2 additions & 2 deletions Server/API/ClientDownloadsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ namespace Remotely.Server.API
public class ClientDownloadsController : ControllerBase
{
public ClientDownloadsController(IWebHostEnvironment hostEnv,
ApplicationConfig appConfig)
IApplicationConfig appConfig)
{
HostEnv = hostEnv;
AppConfig = appConfig;
}

private ApplicationConfig AppConfig { get; }
private IApplicationConfig AppConfig { get; }
private SemaphoreSlim FileLock { get; } = new SemaphoreSlim(1);
private IWebHostEnvironment HostEnv { get; set; }

Expand Down
6 changes: 3 additions & 3 deletions Server/API/CommandsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ namespace Remotely.Server.API
[ApiController]
public class CommandsController : ControllerBase
{
public CommandsController(DataService dataService)
public CommandsController(IDataService dataService)
{
this.DataService = dataService;
DataService = dataService;
}

private DataService DataService { get; }
private IDataService DataService { get; }

// GET: api/<controller>
[HttpGet("{fileExt}")]
Expand Down
4 changes: 2 additions & 2 deletions Server/API/DevicesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace Remotely.Server.API
public class DevicesController : ControllerBase
{

public DevicesController(DataService dataService)
public DevicesController(IDataService dataService)
{
DataService = dataService;
}
private DataService DataService { get; set; }
private IDataService DataService { get; set; }


[HttpGet]
Expand Down
4 changes: 2 additions & 2 deletions Server/API/FileSharingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace Remotely.Server.API
[ApiController]
public class FileSharingController : ControllerBase
{
public FileSharingController(DataService dataService)
public FileSharingController(IDataService dataService)
{
DataService = dataService;
}
public DataService DataService { get; set; }
public IDataService DataService { get; set; }

[HttpGet("{id}")]
public ActionResult Get(string id)
Expand Down
8 changes: 4 additions & 4 deletions Server/API/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace Remotely.Server.API
public class LoginController : ControllerBase
{
public LoginController(SignInManager<RemotelyUser> signInManager,
DataService dataService,
ApplicationConfig appConfig,
IDataService dataService,
IApplicationConfig appConfig,
IHubContext<CasterHub> casterHubContext,
IHubContext<ViewerHub> viewerHubContext)
{
Expand All @@ -30,8 +30,8 @@ public LoginController(SignInManager<RemotelyUser> signInManager,
}

private SignInManager<RemotelyUser> SignInManager { get; }
private DataService DataService { get; }
public ApplicationConfig AppConfig { get; }
private IDataService DataService { get; }
public IApplicationConfig AppConfig { get; }
private IHubContext<CasterHub> CasterHubContext { get; }
private IHubContext<ViewerHub> ViewerHubContext { get; }

Expand Down
12 changes: 7 additions & 5 deletions Server/API/OrganizationManagementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ namespace Remotely.Server.API
[ApiController]
public class OrganizationManagementController : ControllerBase
{
public OrganizationManagementController(DataService dataService, UserManager<RemotelyUser> userManager, IEmailSenderEx emailSender)
public OrganizationManagementController(IDataService dataService,
UserManager<RemotelyUser> userManager,
IEmailSenderEx emailSender)
{
this.DataService = dataService;
this.UserManager = userManager;
this.EmailSender = emailSender;
DataService = dataService;
UserManager = userManager;
EmailSender = emailSender;
}

private DataService DataService { get; }
private IDataService DataService { get; }
private IEmailSenderEx EmailSender { get; }
private UserManager<RemotelyUser> UserManager { get; }

Expand Down
8 changes: 4 additions & 4 deletions Server/API/RemoteControlController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace Remotely.Server.API
[ApiController]
public class RemoteControlController : ControllerBase
{
public RemoteControlController(DataService dataService,
public RemoteControlController(IDataService dataService,
IHubContext<AgentHub> agentHub,
ApplicationConfig appConfig,
IApplicationConfig appConfig,
SignInManager<RemotelyUser> signInManager)
{
DataService = dataService;
Expand All @@ -30,9 +30,9 @@ public RemoteControlController(DataService dataService,
SignInManager = signInManager;
}

public DataService DataService { get; }
public IDataService DataService { get; }
public IHubContext<AgentHub> AgentHubContext { get; }
public ApplicationConfig AppConfig { get; }
public IApplicationConfig AppConfig { get; }
public SignInManager<RemotelyUser> SignInManager { get; }

[HttpGet("{deviceID}")]
Expand Down
4 changes: 2 additions & 2 deletions Server/API/ScriptingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Remotely.Server.API
[Route("api/[controller]")]
public class ScriptingController : ControllerBase
{
public ScriptingController(DataService dataService,
public ScriptingController(IDataService dataService,
UserManager<RemotelyUser> userManager,
IHubContext<AgentHub> agentHub)
{
Expand All @@ -27,7 +27,7 @@ public ScriptingController(DataService dataService,
AgentHubContext = agentHub;
}

private DataService DataService { get; }
private IDataService DataService { get; }
private IHubContext<AgentHub> AgentHubContext { get; }
private UserManager<RemotelyUser> UserManager { get; }

Expand Down
4 changes: 2 additions & 2 deletions Server/API/ServerLogsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace Remotely.Server.API
public class ServerLogsController : ControllerBase
{

public ServerLogsController(DataService dataService)
public ServerLogsController(IDataService dataService)
{
DataService = dataService;
}
public DataService DataService { get; set; }
public IDataService DataService { get; set; }

[ServiceFilter(typeof(ApiAuthorizationFilter))]
[HttpGet("Download")]
Expand Down
6 changes: 4 additions & 2 deletions Server/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public class ForgotPasswordModel : PageModel
private readonly UserManager<RemotelyUser> _userManager;
private readonly IEmailSenderEx _emailSender;

private DataService DataService { get; }
private IDataService DataService { get; }

public ForgotPasswordModel(UserManager<RemotelyUser> userManager, IEmailSenderEx emailSender, DataService dataService)
public ForgotPasswordModel(UserManager<RemotelyUser> userManager,
IEmailSenderEx emailSender,
IDataService dataService)
{
_userManager = userManager;
_emailSender = emailSender;
Expand Down
4 changes: 2 additions & 2 deletions Server/Areas/Identity/Pages/Account/Login.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ namespace Remotely.Server.Areas.Identity.Pages.Account
[AllowAnonymous]
public class LoginModel : PageModel
{
private readonly DataService _dataService;
private readonly IDataService _dataService;
private readonly SignInManager<RemotelyUser> _signInManager;
private readonly UserManager<RemotelyUser> _userManager;
private readonly ILogger<LoginModel> _logger;

public LoginModel(SignInManager<RemotelyUser> signInManager,
UserManager<RemotelyUser> userManager,
DataService dataService,
IDataService dataService,
ILogger<LoginModel> logger)
{
_dataService = dataService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage
[Authorize]
public class ApiTokensModel : PageModel
{
public ApiTokensModel(DataService dataService)
public ApiTokensModel(IDataService dataService)
{
DataService = dataService;
}
Expand All @@ -35,7 +35,7 @@ public ApiTokensModel(DataService dataService)
[TempData]
public string NewTokenSecret { get; set; }

private DataService DataService { get; }
private IDataService DataService { get; }

public void OnGet()
{
Expand Down
4 changes: 2 additions & 2 deletions Server/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public partial class IndexModel : PageModel
private readonly UserManager<RemotelyUser> _userManager;
private readonly SignInManager<RemotelyUser> _signInManager;
private readonly IEmailSenderEx _emailSender;
private readonly DataService _dataService;
private readonly IDataService _dataService;

public IndexModel(
UserManager<RemotelyUser> userManager,
SignInManager<RemotelyUser> signInManager,
DataService dataService,
IDataService dataService,
IEmailSenderEx emailSender)
{
_userManager = userManager;
Expand Down
6 changes: 3 additions & 3 deletions Server/Areas/Identity/Pages/Account/Manage/Options.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage
{
public class OptionsModel : PageModel
{
public OptionsModel(DataService dataService)
public OptionsModel(IDataService dataService)
{
this.DataService = dataService;
DataService = dataService;
}
private DataService DataService { get; set; }
private IDataService DataService { get; set; }

[TempData]
public string Message { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage
{
public class OrganizationModel : PageModel
{
public OrganizationModel(DataService dataService, UserManager<RemotelyUser> userManager, IEmailSenderEx emailSender)
public OrganizationModel(IDataService dataService,
UserManager<RemotelyUser> userManager,
IEmailSenderEx emailSender)
{
DataService = dataService;
UserManager = userManager;
Expand All @@ -40,7 +42,7 @@ public OrganizationModel(DataService dataService, UserManager<RemotelyUser> user
[Display(Name = "Users")]
public List<OrganizationUser> Users { get; set; }

private DataService DataService { get; }
private IDataService DataService { get; }

private IEmailSenderEx EmailSender { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ServerConfigModel : PageModel
public ServerConfigModel(IConfiguration configuration,
IWebHostEnvironment hostEnv,
UserManager<RemotelyUser> userManager,
DataService dataService)
IDataService dataService)
{
Configuration = configuration;
HostEnv = hostEnv;
Expand Down Expand Up @@ -52,7 +52,7 @@ public enum DBProviders
public string StatusMessage { get; set; }

private IConfiguration Configuration { get; }
private DataService DataService { get; }
private IDataService DataService { get; }
private IWebHostEnvironment HostEnv { get; }
private UserManager<RemotelyUser> UserManager { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Remotely.Server.Areas.Identity.Pages.Account.Manage
{
public class ServerLogsModel : PageModel
{
public ServerLogsModel(DataService dataService)
public ServerLogsModel(IDataService dataService)
{
DataService = dataService;
}
Expand All @@ -21,7 +21,7 @@ public ServerLogsModel(DataService dataService)
public InputModel Input { get; set; } = new InputModel();

public bool IsAdmin { get; private set; }
private DataService DataService { get; }
private IDataService DataService { get; }

public void OnGet()
{
Expand Down
4 changes: 2 additions & 2 deletions Server/Areas/Identity/Pages/Account/Register.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page
@inject Remotely.Server.Services.ApplicationConfig AppConfig
@inject Remotely.Server.Services.DataService DataService
@inject Remotely.Server.Services.IApplicationConfig AppConfig
@inject Remotely.Server.Services.IDataService DataService
@model RegisterModel
@{
ViewData["Title"] = "Register";
Expand Down
4 changes: 2 additions & 2 deletions Server/Areas/Identity/Pages/Account/Register.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public class RegisterModel : PageModel
private readonly ILogger<RegisterModel> _logger;
private readonly IEmailSenderEx _emailSender;
private readonly DataService _dataService;
private readonly ApplicationConfig _appConfig;
private readonly IApplicationConfig _appConfig;

public RegisterModel(
UserManager<RemotelyUser> userManager,
SignInManager<RemotelyUser> signInManager,
ILogger<RegisterModel> logger,
IEmailSenderEx emailSender,
DataService dataService,
ApplicationConfig appConfig)
IApplicationConfig appConfig)
{
_userManager = userManager;
_signInManager = signInManager;
Expand Down
4 changes: 2 additions & 2 deletions Server/Attributes/ApiAuthorizationFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace Remotely.Server.Attributes
{
public class ApiAuthorizationFilter : ActionFilterAttribute, IAuthorizationFilter
{
public ApiAuthorizationFilter(DataService dataService)
public ApiAuthorizationFilter(IDataService dataService)
{
DataService = dataService;
}

private DataService DataService { get; }
private IDataService DataService { get; }

public void OnAuthorization(AuthorizationFilterContext context)
{
Expand Down
Loading

0 comments on commit 167a9fd

Please sign in to comment.