2018-03-27 00:54:20 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-02-16 16:04:40 -05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
using WebfrontCore.ViewModels;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using static SharedLibraryCore.Database.Models.EFClient;
|
2018-03-27 00:54:20 -04:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class ActionController : BaseController
|
|
|
|
|
{
|
|
|
|
|
public IActionResult BanForm()
|
|
|
|
|
{
|
|
|
|
|
var info = new ActionInfo()
|
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_BAN_NAME"],
|
2018-03-27 00:54:20 -04:00
|
|
|
|
Name = "Ban",
|
|
|
|
|
Inputs = new List<InputInfo>()
|
|
|
|
|
{
|
|
|
|
|
new InputInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = "Reason",
|
2018-05-05 16:36:26 -04:00
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
|
2018-09-02 17:59:27 -04:00
|
|
|
|
},
|
|
|
|
|
new InputInfo()
|
|
|
|
|
{
|
|
|
|
|
Name ="Duration",
|
|
|
|
|
Label=Localization["WEBFRONT_ACTION_LABEL_DURATION"],
|
|
|
|
|
Type="select",
|
|
|
|
|
Values = new Dictionary<string, string>()
|
|
|
|
|
{
|
|
|
|
|
{"1", $"1 {Localization["GLOBAL_TIME_HOUR"]}" },
|
|
|
|
|
{"2", $"6 {Localization["GLOBAL_TIME_HOURS"]}" },
|
|
|
|
|
{"3", $"1 {Localization["GLOBAL_TIME_DAY"]}" },
|
2018-09-13 21:00:41 -04:00
|
|
|
|
{"4", $"2 {Localization["GLOBAL_TIME_DAYS"]}" },
|
|
|
|
|
{"5", $"1 {Localization["GLOBAL_TIME_WEEK"]}" },
|
|
|
|
|
{"6", $"{Localization["WEBFRONT_ACTION_SELECTION_PERMANENT"]}" },
|
2018-09-02 17:59:27 -04:00
|
|
|
|
}
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Action = "BanAsync"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-02 17:59:27 -04:00
|
|
|
|
public async Task<IActionResult> BanAsync(int targetId, string Reason, int Duration)
|
2018-03-27 00:54:20 -04:00
|
|
|
|
{
|
2018-09-02 17:59:27 -04:00
|
|
|
|
string duration = string.Empty;
|
|
|
|
|
|
2018-10-02 13:39:08 -04:00
|
|
|
|
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
|
|
|
|
|
2018-09-02 17:59:27 -04:00
|
|
|
|
switch (Duration)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
2018-10-02 13:39:08 -04:00
|
|
|
|
duration = $"1{loc["GLOBAL_TIME_HOURS"][0]}";
|
2018-09-02 17:59:27 -04:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2018-10-02 13:39:08 -04:00
|
|
|
|
duration = $"6{loc["GLOBAL_TIME_HOURS"][0]}";
|
2018-09-02 17:59:27 -04:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2018-10-02 13:39:08 -04:00
|
|
|
|
duration = $"1{loc["GLOBAL_TIME_DAYS"][0]}";
|
2018-09-02 17:59:27 -04:00
|
|
|
|
break;
|
|
|
|
|
case 4:
|
2018-10-02 13:39:08 -04:00
|
|
|
|
duration = $"2{loc["GLOBAL_TIME_DAYS"][0]}";
|
2018-09-13 21:00:41 -04:00
|
|
|
|
break;
|
|
|
|
|
case 5:
|
2018-10-02 13:39:08 -04:00
|
|
|
|
duration = $"1{loc["GLOBAL_TIME_WEEKS"][0]}";
|
2018-09-02 17:59:27 -04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 21:00:41 -04:00
|
|
|
|
string command = Duration == 6 ?
|
2018-09-02 17:59:27 -04:00
|
|
|
|
$"!ban @{targetId} {Reason}" :
|
|
|
|
|
$"!tempban @{targetId} {duration} {Reason}";
|
|
|
|
|
|
2018-03-27 00:54:20 -04:00
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
|
|
|
|
|
{
|
2018-11-27 19:31:48 -05:00
|
|
|
|
serverId = server.EndPoint,
|
2018-09-02 17:59:27 -04:00
|
|
|
|
command
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult UnbanForm()
|
|
|
|
|
{
|
|
|
|
|
var info = new ActionInfo()
|
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_UNBAN_NAME"],
|
2018-03-27 00:54:20 -04:00
|
|
|
|
Name = "Unban",
|
|
|
|
|
Inputs = new List<InputInfo>()
|
|
|
|
|
{
|
|
|
|
|
new InputInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = "Reason",
|
2018-05-05 16:36:26 -04:00
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Action = "UnbanAsync"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> UnbanAsync(int targetId, string Reason)
|
|
|
|
|
{
|
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
|
|
|
|
|
{
|
2018-11-27 19:31:48 -05:00
|
|
|
|
serverId = server.EndPoint,
|
2018-03-27 00:54:20 -04:00
|
|
|
|
command = $"!unban @{targetId} {Reason}"
|
|
|
|
|
}));
|
|
|
|
|
}
|
2018-04-04 15:38:34 -04:00
|
|
|
|
|
|
|
|
|
public IActionResult LoginForm()
|
|
|
|
|
{
|
|
|
|
|
var login = new ActionInfo()
|
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_LOGIN_NAME"],
|
2018-04-04 15:38:34 -04:00
|
|
|
|
Name = "Login",
|
|
|
|
|
Inputs = new List<InputInfo>()
|
|
|
|
|
{
|
|
|
|
|
new InputInfo()
|
|
|
|
|
{
|
2018-04-05 18:50:04 -04:00
|
|
|
|
Name = "clientId",
|
2018-05-05 18:52:04 -04:00
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_ID"]
|
2018-04-04 15:38:34 -04:00
|
|
|
|
},
|
|
|
|
|
new InputInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = "Password",
|
2018-05-05 18:52:04 -04:00
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_PASSWORD"],
|
2018-04-04 15:38:34 -04:00
|
|
|
|
Type = "password",
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-04-05 18:50:04 -04:00
|
|
|
|
Action = "LoginAsync"
|
2018-04-04 15:38:34 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", login);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-05 18:50:04 -04:00
|
|
|
|
public async Task<IActionResult> LoginAsync(int clientId, string password)
|
2018-04-04 15:38:34 -04:00
|
|
|
|
{
|
2018-04-05 18:50:04 -04:00
|
|
|
|
return await Task.FromResult(RedirectToAction("LoginAsync", "Account", new { clientId, password }));
|
2018-04-04 15:38:34 -04:00
|
|
|
|
}
|
2018-09-02 17:59:27 -04:00
|
|
|
|
|
|
|
|
|
public IActionResult EditForm()
|
|
|
|
|
{
|
|
|
|
|
var info = new ActionInfo()
|
|
|
|
|
{
|
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_LABEL_EDIT"],
|
|
|
|
|
Name = "Edit",
|
|
|
|
|
Inputs = new List<InputInfo>()
|
|
|
|
|
{
|
|
|
|
|
new InputInfo()
|
|
|
|
|
{
|
|
|
|
|
Name ="level",
|
|
|
|
|
Label=Localization["WEBFRONT_PROFILE_LEVEL"],
|
|
|
|
|
Type="select",
|
|
|
|
|
Values = Enum.GetValues(typeof(Permission)).OfType<Permission>()
|
|
|
|
|
.Where(p => p <= Client.Level)
|
|
|
|
|
.Where(p => p != Permission.Banned)
|
2018-11-27 19:31:48 -05:00
|
|
|
|
.Where(p => p != Permission.Flagged)
|
2018-09-02 17:59:27 -04:00
|
|
|
|
.ToDictionary(p => p.ToString(), p=> p.ToLocalizedLevelName())
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Action = "EditAsync"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> EditAsync(int targetId, string level)
|
|
|
|
|
{
|
|
|
|
|
var server = Manager.GetServers().First();
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
|
|
|
|
|
{
|
2018-11-27 19:31:48 -05:00
|
|
|
|
serverId = server.EndPoint,
|
2018-09-02 17:59:27 -04:00
|
|
|
|
command = $"!setlevel @{targetId} {level}"
|
|
|
|
|
}));
|
|
|
|
|
}
|
2019-02-16 16:04:40 -05:00
|
|
|
|
|
2019-02-26 22:25:27 -05:00
|
|
|
|
public IActionResult GenerateLoginTokenForm()
|
2019-02-16 16:04:40 -05:00
|
|
|
|
{
|
|
|
|
|
var info = new ActionInfo()
|
|
|
|
|
{
|
|
|
|
|
ActionButtonLabel = "Generate",
|
|
|
|
|
Name = "GenerateLoginToken",
|
|
|
|
|
Action = "GenerateLoginTokenAsync",
|
|
|
|
|
Inputs = new List<InputInfo>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
public string GenerateLoginTokenAsync()
|
|
|
|
|
{
|
|
|
|
|
var state = Manager.TokenAuthenticator.GenerateNextToken(Client.NetworkId);
|
|
|
|
|
return string.Format(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_GENERATETOKEN_SUCCESS"], state.Token, $"{state.RemainingTime} {Utilities.CurrentLocalization.LocalizationIndex["GLOBAL_MINUTES"]}", Client.ClientId);
|
|
|
|
|
}
|
2019-07-13 21:45:25 -04:00
|
|
|
|
|
|
|
|
|
public IActionResult ChatForm(long id)
|
|
|
|
|
{
|
|
|
|
|
var info = new ActionInfo()
|
|
|
|
|
{
|
|
|
|
|
ActionButtonLabel = Localization["WEBFRONT_ACTION_LABEL_SUBMIT_MESSAGE"],
|
|
|
|
|
Name = "Chat",
|
|
|
|
|
Inputs = new List<InputInfo>
|
|
|
|
|
{
|
|
|
|
|
new InputInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = "message",
|
|
|
|
|
Type = "text",
|
|
|
|
|
Label = Localization["WEBFRONT_ACTION_LABEL_MESSAGE"]
|
|
|
|
|
},
|
|
|
|
|
new InputInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = "id",
|
|
|
|
|
Value = id.ToString(),
|
|
|
|
|
Type = "hidden"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Action = "ChatAsync"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View("_ActionForm", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> ChatAsync(long id, string message)
|
|
|
|
|
{
|
|
|
|
|
var server = Manager.GetServers().First(_server => _server.EndPoint == id);
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
|
|
|
|
|
{
|
|
|
|
|
serverId = server.EndPoint,
|
|
|
|
|
command = $"!say {message}"
|
|
|
|
|
}));
|
|
|
|
|
}
|
2019-07-16 16:27:19 -04:00
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> RecentClientsForm()
|
|
|
|
|
{
|
|
|
|
|
var clients = await Manager.GetClientService().GetRecentClients();
|
|
|
|
|
return View("~/Views/Shared/Components/Client/_RecentClients.cshtml", clients);
|
|
|
|
|
}
|
2018-03-27 00:54:20 -04:00
|
|
|
|
}
|
|
|
|
|
}
|