MailSharp / MailSharp.WebManager / Controllers / ConfigController.cs
Code · 104 lines · 4281 bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104using MailSharp.WebManager.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace MailSharp.WebManager.Controllers;

[Authorize(Roles = "Administrator")]
[Route("~/api/[controller]")]
[ApiController]
public class ConfigController(ConfigService configService) : ControllerBase
{
	[HttpGet]
	public IActionResult GetAll() => Ok(new
	{
		smtp     = configService.GetSmtp(),
		pop3     = configService.GetPop3(),
		imap     = configService.GetImap(),
		dmarc    = configService.GetDmarc(),
		mailbox  = configService.GetMailbox(),
		ipGroups = configService.GetIpGroups(),
		general  = configService.GetGeneral()
	});

	// ── SMTP ────────────────────────────────────────────────────
	[HttpPost("smtp/general")]
	public IActionResult SaveSmtpGeneral([FromBody] SmtpGeneralDto dto)
		{ configService.SaveSmtpGeneral(dto); return Ok(); }

	[HttpPost("smtp/connections")]
	public IActionResult SaveSmtpConnections([FromBody] SmtpConnectionsDto dto)
		{ configService.SaveSmtpConnections(dto); return Ok(); }

	[HttpPost("smtp/delivery")]
	public IActionResult SaveSmtpDelivery([FromBody] SmtpDeliveryDto dto)
		{ configService.SaveSmtpDelivery(dto); return Ok(); }

	[HttpPost("smtp/relay")]
	public IActionResult SaveSmtpRelay([FromBody] SmtpRelayDto dto)
		{ configService.SaveSmtpRelay(dto); return Ok(); }

	[HttpPost("smtp/security")]
	public IActionResult SaveSmtpSecurity([FromBody] SmtpSecurityDto dto)
		{ configService.SaveSmtpSecurity(dto); return Ok(); }

	[HttpPost("smtp/limits")]
	public IActionResult SaveSmtpLimits([FromBody] SmtpLimitsDto dto)
		{ configService.SaveSmtpLimits(dto); return Ok(); }

	// ── POP3 ────────────────────────────────────────────────────
	[HttpPost("pop3/general")]
	public IActionResult SavePop3General([FromBody] Pop3GeneralDto dto)
		{ configService.SavePop3General(dto); return Ok(); }

	[HttpPost("pop3/connections")]
	public IActionResult SavePop3Connections([FromBody] Pop3ConnectionsDto dto)
		{ configService.SavePop3Connections(dto); return Ok(); }

	// ── IMAP ────────────────────────────────────────────────────
	[HttpPost("imap/general")]
	public IActionResult SaveImapGeneral([FromBody] ImapGeneralDto dto)
		{ configService.SaveImapGeneral(dto); return Ok(); }

	[HttpPost("imap/connections")]
	public IActionResult SaveImapConnections([FromBody] ImapConnectionsDto dto)
		{ configService.SaveImapConnections(dto); return Ok(); }

	[HttpPost("imap/folders")]
	public IActionResult SaveImapFolders([FromBody] ImapFoldersDto dto)
		{ configService.SaveImapFolders(dto); return Ok(); }

	[HttpPost("imap/advanced")]
	public IActionResult SaveImapAdvanced([FromBody] ImapAdvancedDto dto)
		{ configService.SaveImapAdvanced(dto); return Ok(); }

	// ── Shared ──────────────────────────────────────────────────
	[HttpPost("dmarc")]
	public IActionResult SaveDmarc([FromBody] DmarcConfigDto dto)
		{ configService.SaveDmarc(dto); return Ok(); }

	[HttpPost("mailbox")]
	public IActionResult SaveMailbox([FromBody] MailboxConfigDto dto)
		{ configService.SaveMailbox(dto); return Ok(); }

	[HttpGet("general")]
	public IActionResult GetGeneral() => Ok(configService.GetGeneral());

	[HttpPost("general")]
	public IActionResult SaveGeneral([FromBody] GeneralSettingsDto dto)
		{ configService.SaveGeneral(dto); return Ok(); }

	[HttpGet("maintenance-users")]
	public IActionResult GetMaintenanceUsers() => Ok(configService.GetMaintenanceUsers());

	[HttpPost("maintenance-users")]
	public IActionResult SaveMaintenanceUsers([FromBody] List<MaintenanceUserDto> dto)
		{ configService.SaveMaintenanceUsers(dto); return Ok(); }

	[HttpGet("ipgroups")]
	public IActionResult GetIpGroups() => Ok(configService.GetIpGroups());

	[HttpPost("ipgroups")]
	public IActionResult SaveIpGroups([FromBody] List<IpGroupDto> dto)
		{ configService.SaveIpGroups(dto); return Ok(); }
}