mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-14 07:55:01 +01:00
add back admin panel
This commit is contained in:
98
EpinelPS/Controllers/AdminApiController.cs
Normal file
98
EpinelPS/Controllers/AdminApiController.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using EpinelPS.Database;
|
||||
using EpinelPS.LobbyServer;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace EpinelPS.Controllers
|
||||
{
|
||||
[Route("adminapi")]
|
||||
[ApiController]
|
||||
public class AdminApiController : ControllerBase
|
||||
{
|
||||
public static Dictionary<string, User> AdminAuthTokens = new();
|
||||
private static MD5 md5 = MD5.Create();
|
||||
|
||||
[HttpPost]
|
||||
[Route("login")]
|
||||
public LoginApiResponse Login([FromBody] LoginApiBody b)
|
||||
{
|
||||
User? user = null;
|
||||
bool nullusernames = false;
|
||||
if (b.Username != null && b.Password != null)
|
||||
{
|
||||
var passwordHash = Convert.ToHexString(md5.ComputeHash(Encoding.ASCII.GetBytes(b.Password))).ToLower();
|
||||
foreach (var item in JsonDb.Instance.Users)
|
||||
{
|
||||
if (item.Username == b.Username)
|
||||
{
|
||||
if (item.Password.ToLower() == passwordHash)
|
||||
{
|
||||
user = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nullusernames = true;
|
||||
}
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
if (nullusernames)
|
||||
{
|
||||
return new LoginApiResponse() { Message = "Please enter a username and password" };
|
||||
}
|
||||
else
|
||||
{
|
||||
return new LoginApiResponse() { Message = "Username or password is incorrect" };
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (user.IsAdmin)
|
||||
{
|
||||
var tok = CreateAuthToken(user);
|
||||
HttpContext.Response.Cookies.Append("token", tok);
|
||||
return new LoginApiResponse() { OK = true, Token = tok };
|
||||
}
|
||||
else
|
||||
{
|
||||
return new LoginApiResponse() { Message = "User is not an administrator." };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static string CreateAuthToken(User user)
|
||||
{
|
||||
var tok = RandomString(128);
|
||||
AdminAuthTokens.Add(tok, user);
|
||||
return tok;
|
||||
}
|
||||
|
||||
public static string RandomString(int length)
|
||||
{
|
||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
return new string(Enumerable.Repeat(chars, length)
|
||||
.Select(s => s[new Random().Next(s.Length)]).ToArray());
|
||||
}
|
||||
|
||||
public class LoginApiBody
|
||||
{
|
||||
[Required]
|
||||
public string Username { get; set; } = "";
|
||||
[Required]
|
||||
public string Password { get; set; } = "";
|
||||
}
|
||||
public class LoginApiResponse
|
||||
{
|
||||
public string Message { get; set; } = "";
|
||||
public bool OK { get; set; }
|
||||
public string Token { get; set; } = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
58
EpinelPS/Controllers/AdminController.cs
Normal file
58
EpinelPS/Controllers/AdminController.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using EpinelPS.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace EpinelPS.Controllers
|
||||
{
|
||||
[Route("admin")]
|
||||
public class AdminController : Controller
|
||||
{
|
||||
private readonly ILogger<AdminController> _logger;
|
||||
|
||||
public AdminController(ILogger<AdminController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
[Route("index")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[Route("dashboard")]
|
||||
public IActionResult Dashboard()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[Route("Events")]
|
||||
public IActionResult Events()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[Route("Configuration")]
|
||||
public IActionResult Configuration()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[Route("Users")]
|
||||
public IActionResult Users()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[Route("Mail")]
|
||||
public IActionResult Mail()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[Route("Database")]
|
||||
public IActionResult Database()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,5 +108,22 @@ namespace EpinelPS.Controllers
|
||||
{
|
||||
return "{\"alpha2\":\"GR\",\"extra_json\":{\"certificate_type_map\":{}},\"msg\":\"success\",\"region\":\"300\",\"ret\":0,\"seq\":\"" + seq + "\",\"timestamp\":324234322}";
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("gnconfig/acquire_config")]
|
||||
public string AcquireConfig(string seq)
|
||||
{
|
||||
return "{\"ret\":23111202,\"msg\":\"no matched config error( [match logic]no match )\",\"rule_id\":\"\",\"resource_list\":\"\",\"sdk_enable\":0,\"sdk_debug_enable\":0,\"report_log_enable\":0,\"log_level\":0,\"inner_seq\":\"" + seq + "\",\"ab_test\":{\"id\":\"\",\"group\":\"\"},\"seq\":\"" + seq + "\"}";
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("profile/get_bind_info")]
|
||||
public string GetProfileBindInfo(string seq, [FromBody] AuthPkt req)
|
||||
{
|
||||
User? user;
|
||||
if ((user = NetUtils.GetUser(req.channel_info.token).Item1) == null) return BadAuthToken;
|
||||
|
||||
return "{\"bind_list\":[{\"bind_ts\":1717783095,\"channel_info\":{\"birthday\":\"1970-01\",\"email\":\"" + user.Username + "\",\"is_receive_email\":1,\"lang_type\":\"en\",\"last_login_time\":171000000,\"nick_name\":\"\",\"phone\":\"\",\"phone_area_code\":\"\",\"region\":\"724\",\"register_account\":\"" + user.Username + "\",\"register_account_type\":1,\"register_time\":" + user.RegisterTime + ",\"seq\":\"" + seq + "\",\"uid\":\"2752409592679849\",\"user_name\":\"" + user.PlayerName + "\",\"username_pass_verify\":0},\"channelid\":131,\"email\":\"" + user.Username + "\",\"history_scopes\":[],\"is_primary\":1,\"picture_url\":\"\",\"user_name\":\"" + user.PlayerName + "\"}],\"create_ts\":" + user.RegisterTime + ",\"last_login_ts\":171000000,\"msg\":\"success\",\"ret\":0,\"seq\":\"" + seq + "\"}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user