Luski.Shared HTTP
This commit is contained in:
parent
e4bb89c957
commit
298fdd2ef7
@ -4,6 +4,9 @@ namespace LuskiServer.Classes;
|
||||
|
||||
public class AppConfig
|
||||
{
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("addresses")]
|
||||
public string[] Addresses { get; set; } = new string[]{"http://localhost"};
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("address")]
|
||||
public string Address { get; set; } = "127.0.0.1";
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System.Text;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using Luski.Shared.PublicServers.V1.Shared;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Enums;
|
||||
using LuskiServer.Interfaces;
|
||||
@ -8,11 +11,21 @@ namespace LuskiServer.Classes;
|
||||
|
||||
public static class EXT
|
||||
{
|
||||
public static string GetNumberString(this ServerPermissions enu)
|
||||
public static string GetNumberString(this ServerPermission enu)
|
||||
{
|
||||
return ((long)(enu)).ToString();
|
||||
}
|
||||
|
||||
public static ServerPermission GetPermission(this string enu)
|
||||
{
|
||||
return (ServerPermission)long.Parse(enu);
|
||||
}
|
||||
public static bool GetBool(this string enu)
|
||||
{
|
||||
if (enu == "0") return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CanTokenRequest(this ControllerBase Base, out long id, out long sid, out IActionResult? result)
|
||||
{
|
||||
if (Base.Request.Headers.ContainsKey("token"))
|
||||
@ -30,9 +43,9 @@ public static class EXT
|
||||
if (LogInDB)
|
||||
{
|
||||
Tables.Logs.Insert(
|
||||
Logs.ID.CreateParameter(Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch).ID),
|
||||
Logs.ID.CreateParameter(LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch).ID),
|
||||
Logs.Type.CreateParameter(LogType.Error),
|
||||
Logs.Message.CreateParameter(Error.ToString()));
|
||||
Logs.Message.CreateParameter(Error.ToString() + " in " + Base.Url.ToString()));
|
||||
}
|
||||
|
||||
return Base.ShowError(ErrorCode.ServerError, Error.Message);
|
||||
@ -41,14 +54,14 @@ public static class EXT
|
||||
public static IActionResult ResponseCodeToResult(this ControllerBase Base, ErrorCode Result, string msg = "")
|
||||
{
|
||||
return Base.ResponseToResult(
|
||||
new HTTPResponse()
|
||||
new STC()
|
||||
{
|
||||
error = Result,
|
||||
error_message = msg
|
||||
Error = Result,
|
||||
ErrorMessage = msg
|
||||
});
|
||||
}
|
||||
|
||||
public static IActionResult ResponseToResult<TResult>(this ControllerBase Base, TResult Result) where TResult : IWebResponse
|
||||
public static IActionResult ResponseToResult<TResult>(this ControllerBase Base, TResult Result) where TResult : STC
|
||||
{
|
||||
return Base.StatusCode(StatusCodes.Status200OK, Result);
|
||||
}
|
||||
@ -57,10 +70,10 @@ public static class EXT
|
||||
{
|
||||
int cod = 403;
|
||||
if (code == ErrorCode.ServerError) cod = StatusCodes.Status500InternalServerError;
|
||||
return Base.StatusCode(cod, new HTTPResponse()
|
||||
return Base.StatusCode(cod, new STC()
|
||||
{
|
||||
error = code,
|
||||
error_message = Error
|
||||
Error = code,
|
||||
ErrorMessage = Error
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using LuskiServer.Enums;
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes;
|
||||
|
||||
public class HTTPResponse : IWebResponse
|
||||
{
|
||||
public ErrorCode? error { get; set; } = default!;
|
||||
public string? error_message { get; set; } = default!;
|
||||
}
|
||||
|
||||
|
||||
[JsonSerializable(typeof(HTTPResponse))]
|
||||
internal partial class HTTPResponseContext : JsonSerializerContext
|
||||
{
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace LuskiServer.Classes;
|
||||
|
||||
public class Login
|
||||
{
|
||||
public string login_token { get; set; } = default!;
|
||||
}
|
@ -3,14 +3,15 @@ using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization.Metadata;
|
||||
using JacobTechEncryption.Enums;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.Shared;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Enums;
|
||||
using Npgsql;
|
||||
using ServerDatabase;
|
||||
|
||||
namespace LuskiServer.Classes;
|
||||
|
||||
public static class Luski
|
||||
public static class LuskiFunctions
|
||||
{
|
||||
public static Database Database = null!;
|
||||
|
||||
@ -93,22 +94,22 @@ public static class Luski
|
||||
public static long[] GetChannelBroadcastMembers(long Channel)
|
||||
{
|
||||
List<long> Members = new();
|
||||
long[] ChanUserOverides = Tables.Channels.Read(Channels.UserOverides, Channels.ID.CreateParameter(Channel));
|
||||
long[] ChanRoleOverides = Tables.Channels.Read(Channels.RoleOverides, Channels.ID.CreateParameter(Channel));
|
||||
long[] ChanUserOverides = Tables.Channels.Read(Channels.UserOverrides, Channels.ID.CreateParameter(Channel));
|
||||
long[] ChanRoleOverides = Tables.Channels.Read(Channels.RoleOverrides, Channels.ID.CreateParameter(Channel));
|
||||
Dictionary<long, long> ChanRoleIDOverides = new();
|
||||
foreach (long cro in ChanRoleOverides)
|
||||
{
|
||||
ChanRoleIDOverides.Add(Tables.ServerRoleOverides.Read(ServerRoleOverides.RoleID, ServerRoleOverides.ID.CreateParameter(cro)), cro);
|
||||
ChanRoleIDOverides.Add(Tables.ServerRoleOverrides.Read(ServerRoleOverrides.RoleID, ServerRoleOverrides.ID.CreateParameter(cro)), cro);
|
||||
}
|
||||
Dictionary<long, long> ChanUserIDOverides = new();
|
||||
foreach (long cro in ChanUserOverides)
|
||||
{
|
||||
ChanUserIDOverides.Add(Tables.UserRoleOverides.Read(UserRoleOverides.UserID, UserRoleOverides.ID.CreateParameter(cro)), cro);
|
||||
ChanUserIDOverides.Add(Tables.UserRoleOverrides.Read(UserRoleOverrides.UserID, UserRoleOverrides.ID.CreateParameter(cro)), cro);
|
||||
}
|
||||
|
||||
ServerPermissions[] pp = new[]
|
||||
{ ServerPermissions.ViewThis, ServerPermissions.ReadMessageHistory };
|
||||
using NpgsqlConnection dbConnection = Luski.Database.CreateConnection();
|
||||
ServerPermission req = ServerPermission.ViewThis | ServerPermission.ReadMessageHistory;
|
||||
|
||||
using NpgsqlConnection dbConnection = LuskiFunctions.Database.CreateConnection();
|
||||
dbConnection.Open();
|
||||
using NpgsqlCommand cmd = new();
|
||||
cmd.Connection = dbConnection;
|
||||
@ -117,24 +118,14 @@ public static class Luski
|
||||
while (reader.Read())
|
||||
{
|
||||
long rol = reader.GetInt64(0);
|
||||
List<ServerPermissions> GoodPerms = new();
|
||||
ServerPermission GoodPerms = ServerPermission.None;
|
||||
if (ChanRoleIDOverides.ContainsKey(rol))
|
||||
{
|
||||
string[] overides = Tables.ServerRoleOverides.Read(ServerRoleOverides.Overides,
|
||||
ServerRoleOverides.ID.CreateParameter(ChanRoleIDOverides[rol]));
|
||||
foreach (string o in overides)
|
||||
{
|
||||
foreach (ServerPermissions p in pp)
|
||||
{
|
||||
if (GoodPerms.Contains(p)) continue;
|
||||
if (o.StartsWith($"{p.GetNumberString()}:"))
|
||||
{
|
||||
if (o.EndsWith("1")) GoodPerms.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
GoodPerms |= Tables.ServerRoleOverrides.Read(ServerRoleOverrides.GoodPermissions,
|
||||
ServerRoleOverrides.ID.CreateParameter(ChanRoleIDOverides[rol]));
|
||||
|
||||
if (GoodPerms.Count == pp.Length)
|
||||
|
||||
if (GoodPerms.HasPermission(req))
|
||||
{
|
||||
foreach (long m in Tables.Roles.Read(Roles.MembersList, Roles.ID.CreateParameter(rol)))
|
||||
{
|
||||
@ -144,13 +135,9 @@ public static class Luski
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerPermissions[] pppp = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(rol));
|
||||
foreach (ServerPermissions p in pp)
|
||||
{
|
||||
if (GoodPerms.Contains(p)) continue;
|
||||
if (pppp.Contains(p)) GoodPerms.Add(p);
|
||||
}
|
||||
if (GoodPerms.Count == pp.Length)
|
||||
ServerPermission pppp = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(rol));
|
||||
GoodPerms |= pppp;
|
||||
if (GoodPerms.HasPermission(req))
|
||||
{
|
||||
foreach (long m in Tables.Roles.Read(Roles.MembersList, Roles.ID.CreateParameter(rol)))
|
||||
{
|
||||
@ -162,21 +149,11 @@ public static class Luski
|
||||
|
||||
foreach (long o in ChanUserOverides)
|
||||
{
|
||||
List<ServerPermissions> GoodPerms = new();
|
||||
long u = Tables.UserRoleOverides.Read(UserRoleOverides.UserID, UserRoleOverides.ID.CreateParameter(o));
|
||||
string[] x = Tables.UserRoleOverides.Read(UserRoleOverides.Overides, UserRoleOverides.ID.CreateParameter(o));
|
||||
foreach (string oo in x)
|
||||
{
|
||||
foreach (ServerPermissions p in pp)
|
||||
{
|
||||
if (GoodPerms.Contains(p)) continue;
|
||||
if (oo.StartsWith($"{p.GetNumberString()}:"))
|
||||
{
|
||||
if (oo.EndsWith("1")) GoodPerms.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (GoodPerms.Count == pp.Length)
|
||||
ServerPermission GoodPerms = ServerPermission.None;
|
||||
long u = Tables.UserRoleOverrides.Read(UserRoleOverrides.UserID, UserRoleOverrides.ID.CreateParameter(o));
|
||||
GoodPerms |= Tables.UserRoleOverrides.Read(UserRoleOverrides.GoodPermissions, UserRoleOverrides.ID.CreateParameter(o));
|
||||
|
||||
if (GoodPerms.HasPermission(req))
|
||||
{
|
||||
if (!Members.Contains(u)) Members.Add(u);
|
||||
}
|
||||
@ -189,206 +166,144 @@ public static class Luski
|
||||
return Members.ToArray();
|
||||
}
|
||||
|
||||
public static bool HasPermissions(long User, params ServerPermissions[] RequiredPerms)
|
||||
public static bool HasPermissions(long User, ServerPermission RequiredPerms)
|
||||
{
|
||||
if (User == Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0))) return true;
|
||||
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
|
||||
List<ServerPermissions> GoodPerms = new();
|
||||
ServerPermission op = ServerPermission.None;
|
||||
foreach (long RoleID in UserRoleIDList)
|
||||
{
|
||||
List<ServerPermissions> pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID)).ToList();
|
||||
foreach (ServerPermissions rp in RequiredPerms)
|
||||
{
|
||||
if (!GoodPerms.Contains(rp) && pers.Contains(rp)) GoodPerms.Add(rp);
|
||||
}
|
||||
op |= Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID));;
|
||||
}
|
||||
|
||||
return (GoodPerms.Count == RequiredPerms.Length);
|
||||
return op.HasPermission(RequiredPerms);
|
||||
}
|
||||
|
||||
public static bool HasAccessToCategory(long User, long Category, out IReadOnlyList<ServerPermissions> missing, params ServerPermissions[] OptionalPerms)
|
||||
public static bool HasAccessToCategory(long User, long Category, out ServerPermission missing, ServerPermission OptionalPerms)
|
||||
{
|
||||
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
|
||||
List<ServerPermissions> pp = OptionalPerms.ToList();
|
||||
if (!pp.Contains(ServerPermissions.ViewThis)) pp.Add(ServerPermissions.ViewThis);
|
||||
List<ServerPermissions> GoodPerms = new();
|
||||
long[] CatUserOverides = Tables.Categories.Read(Categories.UserOverides, Categories.ID.CreateParameter(Category));
|
||||
foreach (long CatUserOveride in CatUserOverides)
|
||||
if (User == Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0)))
|
||||
{
|
||||
if (Tables.UserRoleOverides.Read(UserRoleOverides.UserID, UserRoleOverides.ID.CreateParameter(CatUserOveride)) != User) continue;
|
||||
string[] overrids = Tables.UserRoleOverides.Read(UserRoleOverides.Overides,
|
||||
UserRoleOverides.ID.CreateParameter(CatUserOveride));
|
||||
foreach (string o in overrids)
|
||||
{
|
||||
foreach (ServerPermissions p in pp)
|
||||
{
|
||||
if (o.StartsWith($"{p.GetNumberString()}:"))
|
||||
{
|
||||
missing = pp.AsReadOnly();
|
||||
if (o.EndsWith("0")) return false;
|
||||
else GoodPerms.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
long[] CatRoleOverides = Tables.Categories.Read(Categories.RoleOverides, Categories.ID.CreateParameter(Category));
|
||||
foreach (long CatRoleOveride in CatRoleOverides)
|
||||
{
|
||||
if (!UserRoleIDList.Contains(Tables.ServerRoleOverides.Read(ServerRoleOverides.RoleID, ServerRoleOverides.ID.CreateParameter(CatRoleOveride)))) continue;
|
||||
string[] overrids = Tables.ServerRoleOverides.Read(ServerRoleOverides.Overides,
|
||||
ServerRoleOverides.ID.CreateParameter(CatRoleOveride));
|
||||
foreach (string o in overrids)
|
||||
{
|
||||
foreach (ServerPermissions p in pp)
|
||||
{
|
||||
if (o.StartsWith($"{p.GetNumberString()}:"))
|
||||
{
|
||||
missing = pp.AsReadOnly();
|
||||
if (o.EndsWith("0")) return false;
|
||||
else GoodPerms.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (long RoleID in UserRoleIDList)
|
||||
{
|
||||
List<ServerPermissions> pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID)).ToList();
|
||||
foreach (ServerPermissions rp in pp)
|
||||
{
|
||||
if (!GoodPerms.Contains(rp) && pers.Contains(rp)) GoodPerms.Add(rp);
|
||||
}
|
||||
}
|
||||
if (GoodPerms.Count == pp.Count)
|
||||
{
|
||||
foreach (ServerPermissions p in GoodPerms)
|
||||
{
|
||||
pp.Remove(p);
|
||||
}
|
||||
|
||||
missing = pp.AsReadOnly();
|
||||
missing = ServerPermission.None;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (ServerPermissions p in GoodPerms)
|
||||
{
|
||||
pp.Remove(p);
|
||||
}
|
||||
|
||||
missing = pp.AsReadOnly();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasAccessToCategory(long User, long Category, params ServerPermissions[] RequiredPerms)
|
||||
{
|
||||
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
|
||||
List<ServerPermissions> pp = RequiredPerms.ToList();
|
||||
if (!pp.Contains(ServerPermissions.ViewThis)) pp.Add(ServerPermissions.ViewThis);
|
||||
List<ServerPermissions> GoodPerms = new();
|
||||
long[] CatUserOverides = Tables.Categories.Read(Categories.UserOverides, Categories.ID.CreateParameter(Category));
|
||||
ServerPermission BadPermissions = ServerPermission.None;
|
||||
ServerPermission GoodPerms = ServerPermission.None;
|
||||
|
||||
long[] CatUserOverides = Tables.Categories.Read(Categories.UserOverrides, Categories.ID.CreateParameter(Category));
|
||||
foreach (long CatUserOveride in CatUserOverides)
|
||||
{
|
||||
if (Tables.UserRoleOverides.Read(UserRoleOverides.UserID, UserRoleOverides.ID.CreateParameter(CatUserOveride)) != User) continue;
|
||||
string[] overrids = Tables.UserRoleOverides.Read(UserRoleOverides.Overides,
|
||||
UserRoleOverides.ID.CreateParameter(CatUserOveride));
|
||||
foreach (string o in overrids)
|
||||
if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(CatUserOveride), UserRoleOverrides.UserID.CreateParameter(User))) continue;
|
||||
if (!row.BadPermissions.HasPermission(ServerPermission.ViewThis))
|
||||
{
|
||||
foreach (ServerPermissions p in pp)
|
||||
{
|
||||
if (o.StartsWith($"{p.GetNumberString()}:"))
|
||||
{
|
||||
if (o.EndsWith("0")) return false;
|
||||
else GoodPerms.Add(p);
|
||||
}
|
||||
}
|
||||
missing = ServerPermission.ViewThis;
|
||||
return false;
|
||||
}
|
||||
|
||||
BadPermissions |= row.BadPermissions;
|
||||
GoodPerms |= row.GoodPermissions;
|
||||
}
|
||||
long[] CatRoleOverides = Tables.Categories.Read(Categories.RoleOverides, Categories.ID.CreateParameter(Category));
|
||||
long[] CatRoleOverides = Tables.Categories.Read(Categories.RoleOverrides, Categories.ID.CreateParameter(Category));
|
||||
foreach (long CatRoleOveride in CatRoleOverides)
|
||||
{
|
||||
if (!UserRoleIDList.Contains(Tables.ServerRoleOverides.Read(ServerRoleOverides.RoleID, ServerRoleOverides.ID.CreateParameter(CatRoleOveride)))) continue;
|
||||
string[] overrids = Tables.ServerRoleOverides.Read(ServerRoleOverides.Overides,
|
||||
ServerRoleOverides.ID.CreateParameter(CatRoleOveride));
|
||||
foreach (string o in overrids)
|
||||
if (!UserRoleIDList.Contains(CatRoleOveride)) continue;
|
||||
ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride));
|
||||
if (!row.BadPermissions.HasPermission(ServerPermission.ViewThis) && !GoodPerms.HasPermission(ServerPermission.ViewThis))
|
||||
{
|
||||
foreach (ServerPermissions p in pp)
|
||||
{
|
||||
if (o.StartsWith($"{p.GetNumberString()}:"))
|
||||
{
|
||||
if (o.EndsWith("0")) return false;
|
||||
else GoodPerms.Add(p);
|
||||
}
|
||||
}
|
||||
missing = ServerPermission.ViewThis;
|
||||
return false;
|
||||
}
|
||||
|
||||
BadPermissions |= (GoodPerms ^ row.BadPermissions);
|
||||
GoodPerms |= row.GoodPermissions;
|
||||
}
|
||||
|
||||
foreach (long RoleID in UserRoleIDList)
|
||||
{
|
||||
List<ServerPermissions> pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID)).ToList();
|
||||
foreach (ServerPermissions rp in pp)
|
||||
ServerPermission pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID));
|
||||
if (!pers.HasPermission(ServerPermission.ViewThis) && !GoodPerms.HasPermission(ServerPermission.ViewThis))
|
||||
{
|
||||
if (!GoodPerms.Contains(rp) && pers.Contains(rp)) GoodPerms.Add(rp);
|
||||
missing = ServerPermission.ViewThis;
|
||||
return false;
|
||||
}
|
||||
|
||||
GoodPerms |= pers;
|
||||
}
|
||||
|
||||
if (GoodPerms.Count == pp.Count) return true;
|
||||
return false;
|
||||
ServerPermission combine = GoodPerms ^ BadPermissions;
|
||||
missing = (combine ^ OptionalPerms) & OptionalPerms;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool HasAccessToChannel(long User, long Channel, params ServerPermissions[] RequiredPerms)
|
||||
public static bool HasAccessToCategory(long User, long Category, ServerPermission RequiredPerms)
|
||||
{
|
||||
if (User == Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0))) return true;
|
||||
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
|
||||
List<ServerPermissions> pp = RequiredPerms.ToList();
|
||||
if (!pp.Contains(ServerPermissions.ViewThis)) pp.Add(ServerPermissions.ViewThis);
|
||||
List<ServerPermissions> GoodPerms = new();
|
||||
long[] ChanUserOverides = Tables.Channels.Read(Channels.UserOverides, Channels.ID.CreateParameter(Channel));
|
||||
foreach (long ChanUserOveride in ChanUserOverides)
|
||||
|
||||
RequiredPerms |= ServerPermission.ViewThis;
|
||||
|
||||
ServerPermission GoodPerms = ServerPermission.None;
|
||||
|
||||
long[] CatUserOverides = Tables.Categories.Read(Categories.UserOverrides, Categories.ID.CreateParameter(Category));
|
||||
foreach (long CatUserOveride in CatUserOverides)
|
||||
{
|
||||
if (Tables.UserRoleOverides.Read(UserRoleOverides.UserID, UserRoleOverides.ID.CreateParameter(ChanUserOveride)) != User) continue;
|
||||
string[] overrids = Tables.UserRoleOverides.Read(UserRoleOverides.Overides,
|
||||
UserRoleOverides.ID.CreateParameter(ChanUserOveride));
|
||||
foreach (string o in overrids)
|
||||
{
|
||||
foreach (ServerPermissions p in pp)
|
||||
{
|
||||
if (o.StartsWith($"{p.GetNumberString()}:"))
|
||||
{
|
||||
if (o.EndsWith("0")) return false;
|
||||
else GoodPerms.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(CatUserOveride), UserRoleOverrides.UserID.CreateParameter(User))) continue;
|
||||
if ((row.BadPermissions & RequiredPerms) > ServerPermission.None) return false;
|
||||
|
||||
GoodPerms |= row.GoodPermissions;
|
||||
}
|
||||
long[] ChanRoleOverides = Tables.Channels.Read(Channels.RoleOverides, Channels.ID.CreateParameter(Channel));
|
||||
foreach (long ChanRoleOveride in ChanRoleOverides)
|
||||
long[] CatRoleOverides = Tables.Categories.Read(Categories.RoleOverrides, Categories.ID.CreateParameter(Category));
|
||||
foreach (long CatRoleOveride in CatRoleOverides)
|
||||
{
|
||||
if (!UserRoleIDList.Contains(Tables.ServerRoleOverides.Read(ServerRoleOverides.RoleID, ServerRoleOverides.ID.CreateParameter(ChanRoleOveride)))) continue;
|
||||
string[] overrids = Tables.ServerRoleOverides.Read(ServerRoleOverides.Overides,
|
||||
ServerRoleOverides.ID.CreateParameter(ChanRoleOveride));
|
||||
foreach (string o in overrids)
|
||||
{
|
||||
foreach (ServerPermissions p in pp)
|
||||
{
|
||||
if (o.StartsWith($"{p.GetNumberString()}:"))
|
||||
{
|
||||
if (o.EndsWith("0")) return false;
|
||||
else GoodPerms.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!UserRoleIDList.Contains(CatRoleOveride)) continue;
|
||||
ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride));
|
||||
if (((row.BadPermissions & RequiredPerms) ^ GoodPerms) > ServerPermission.None) return false;
|
||||
|
||||
GoodPerms |= row.GoodPermissions;
|
||||
}
|
||||
|
||||
foreach (long RoleID in UserRoleIDList)
|
||||
{
|
||||
List<ServerPermissions> pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID)).ToList();
|
||||
foreach (ServerPermissions rp in pp)
|
||||
{
|
||||
if (!GoodPerms.Contains(rp) && pers.Contains(rp)) GoodPerms.Add(rp);
|
||||
}
|
||||
ServerPermission pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID));
|
||||
if (((pers & RequiredPerms) ^ GoodPerms) > ServerPermission.None) return false;
|
||||
GoodPerms |= pers;
|
||||
}
|
||||
|
||||
return GoodPerms.Count == pp.Count;
|
||||
return GoodPerms.HasPermission(RequiredPerms);
|
||||
}
|
||||
|
||||
public static bool HasAccessToChannel(long User, long Channel, ServerPermission RequiredPerms)
|
||||
{
|
||||
long[] UserRoleIDList = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(User));
|
||||
RequiredPerms |= ServerPermission.ViewThis;
|
||||
ServerPermission GoodPerms = ServerPermission.None;
|
||||
|
||||
long[] ChanUserOverides = Tables.Channels.Read(Channels.UserOverrides, Channels.ID.CreateParameter(Channel));
|
||||
long[] ChanRoleOverides = Tables.Channels.Read(Channels.RoleOverrides, Channels.ID.CreateParameter(Channel));
|
||||
|
||||
foreach (long CatUserOveride in ChanUserOverides)
|
||||
{
|
||||
if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(CatUserOveride), UserRoleOverrides.UserID.CreateParameter(User))) continue;
|
||||
if ((row.BadPermissions & RequiredPerms) > ServerPermission.None) return false;
|
||||
|
||||
GoodPerms |= row.GoodPermissions;
|
||||
}
|
||||
foreach (long CatRoleOveride in ChanRoleOverides)
|
||||
{
|
||||
if (!UserRoleIDList.Contains(CatRoleOveride)) continue;
|
||||
ServerRoleOverrideRow row = Tables.ServerRoleOverrides.ReadRow(ServerRoleOverrides.ID.CreateParameter(CatRoleOveride));
|
||||
if (((row.BadPermissions & RequiredPerms) ^ GoodPerms) > ServerPermission.None) return false;
|
||||
|
||||
GoodPerms |= row.GoodPermissions;
|
||||
}
|
||||
foreach (long RoleID in UserRoleIDList)
|
||||
{
|
||||
ServerPermission pers = Tables.Roles.Read(Roles.ServerPermissions, Roles.ID.CreateParameter(RoleID));
|
||||
if (((pers & RequiredPerms) ^ GoodPerms) > ServerPermission.None) return false;
|
||||
GoodPerms |= pers;
|
||||
}
|
||||
|
||||
return GoodPerms.HasPermission(RequiredPerms);
|
||||
}
|
||||
|
||||
public static class Info
|
||||
@ -434,13 +349,19 @@ public static class Luski
|
||||
return new Snowflake((((Info.GetTimestampFromEpoch(Epoch) << 8) | Config.DataId) << 12) | i);
|
||||
}
|
||||
|
||||
public static Snowflake GenerateSnowflake()
|
||||
{
|
||||
i++;
|
||||
if (i > 0b_1111_1111_1111) i = 0;
|
||||
return new Snowflake((((Info.GetTimestampFromEpoch(LuskiFunctions.Config.ServerEpoch) << 8) | Config.DataId) << 12) | i);
|
||||
}
|
||||
|
||||
public static Snowflake GenerateSnowflake(DateTime Epoch, DateTime Current)
|
||||
{
|
||||
i++;
|
||||
if (i > 0b_1111_1111_1111) i = 0;
|
||||
return new Snowflake((((Info.GetTimestampFromEpoch(Epoch, Current) << 8) | Config.DataId) << 12) | i);
|
||||
}
|
||||
|
||||
public long ID { get; }
|
||||
public long Timestamp { get; }
|
||||
public byte Data_ID { get; }
|
@ -1,4 +1,6 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using JacobTechEncryption.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Interfaces.ServerComs;
|
||||
|
||||
namespace LuskiServer.Classes.ServerComs;
|
||||
@ -6,7 +8,7 @@ namespace LuskiServer.Classes.ServerComs;
|
||||
public class MessageEvent : IServerEvent
|
||||
{
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("user_id")]
|
||||
[JsonPropertyName("author_id")]
|
||||
public long UserID { get; set; }
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("channel_id")]
|
||||
@ -19,7 +21,17 @@ public class MessageEvent : IServerEvent
|
||||
public long ID { get; set; }
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("files")]
|
||||
public long[] Files { get; set; }
|
||||
public ServerFileInfoSTC[] Files { get; set; }
|
||||
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("encryption_key")]
|
||||
public long EncryptionKey { get; set; } = default!;
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("encoder_type")]
|
||||
public EncoderType EncoderType { get; set; } = default!;
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("is_channel_profile")]
|
||||
public bool IsProfile { get; set; }
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(MessageEvent))]
|
||||
|
@ -5,6 +5,7 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Enums.ServerComs;
|
||||
using LuskiServer.Interfaces.ServerComs;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
|
||||
@ -19,8 +20,12 @@ public static class WSS
|
||||
{
|
||||
try
|
||||
{
|
||||
long id = Tables.Sessions.Read(TableDef.Sessions.ID, TableDef.Sessions.WSSTCP.CreateParameter(ID));
|
||||
Tables.Sessions.DeleteRow(TableDef.Sessions.ID.CreateParameter(id));
|
||||
SessionsRow id = Tables.Sessions.ReadRow(TableDef.Sessions.WSSTCP.CreateParameter(ID));
|
||||
Tables.Sessions.DeleteRow(TableDef.Sessions.ID.CreateParameter(id.ID));
|
||||
if (id.SessionKey != 0)
|
||||
{
|
||||
Tables.Keys.DeleteRow(Keys.ID.CreateParameter(id.SessionKey));
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@ -82,7 +87,7 @@ public static class WSS
|
||||
SessionTokens.AccountID.CreateParameter(row.User),
|
||||
SessionTokens.TimeFilter.CreateParameter(DateTime.UtcNow.AddDays(5)),
|
||||
SessionTokens.AddressFilter.CreateParameter(Array.Empty<byte>()),
|
||||
SessionTokens.ID.CreateParameter(Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch).ID));
|
||||
SessionTokens.ID.CreateParameter(LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch).ID));
|
||||
string raw = JsonSerializer.Serialize(te, TokenEventContext.Default.TokenEvent);
|
||||
Send(raw);
|
||||
}
|
||||
@ -97,10 +102,13 @@ public static class WSS
|
||||
}
|
||||
}
|
||||
|
||||
private static string path = "";
|
||||
|
||||
public static void Init(string IPv4, int IPv4_Port, string IPv4_URL, bool IPv4_Secure = true, string? IPv6 = null, string? IPv6_URL = null, int IPv6_Port = 0, bool IPv6_Secure = true)
|
||||
{
|
||||
ServerIPv4 = new WebSocketServer(IPAddress.Parse(IPv4), IPv4_Port, IPv4_Secure);
|
||||
ServerIPv4.AddWebSocketService<CoreV1>($"{IPv4_URL}v1");
|
||||
path = $"{IPv4_URL}v1";
|
||||
ServerIPv4.Start();
|
||||
if (IPv6 is not null)
|
||||
{
|
||||
@ -119,6 +127,26 @@ public static class WSS
|
||||
};
|
||||
if (SendType == SendType.ID_Group) SSSE.IDS = IDS;
|
||||
else if (SendType == SendType.ID) SSSE.ID = IDS[0];
|
||||
|
||||
if (SendType == SendType.ID_Group)
|
||||
{
|
||||
foreach (long id in IDS)
|
||||
{
|
||||
Console.WriteLine("Trying To Find: " + id);
|
||||
bool sec = Tables.Sessions.TryReadRows(out SessionsRow[] srs, Sessions.User.CreateParameter(id));
|
||||
if (sec)
|
||||
{
|
||||
foreach (SessionsRow sr in srs)
|
||||
{
|
||||
Console.WriteLine("Trying To Send Data To: " + id + " as " + sr.WSSTCP);
|
||||
string d = JsonSerializer.Serialize(Event);
|
||||
Console.WriteLine("Sending Data: \n" + d);
|
||||
ServerIPv4.WebSocketServices[path].Sessions.SendTo(d, sr.WSSTCP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Start work on server send code
|
||||
}
|
||||
}
|
@ -9,13 +9,13 @@ public static class Categories
|
||||
{
|
||||
public static TableColumn<long> ID { get; } = new("id", true);
|
||||
public static TableColumn<byte[]> Name { get; } = new("name") { DefaultValue = Encoding.UTF8.GetBytes("New Category") };
|
||||
public static TableColumn<string> Color { get; } = new("color") {DefaultValue = "ÿÿÿÿ" };
|
||||
public static TableColumn<byte[]> Color { get; } = new("color") { DefaultValue = new byte[]{255,255,255,255} };
|
||||
public static TableColumn<byte[]> Description { get; } = new("description") { DefaultValue = Encoding.UTF8.GetBytes("Description") };
|
||||
public static TableColumn<long> Parent { get; } = new("parent") { DefaultValue = -1 };
|
||||
public static TableColumn<long[]> InnerCategories { get; } = new("inner_categories") { DefaultValue = Array.Empty<long>() };
|
||||
public static TableColumn<long[]> Channels { get; } = new("channels") { DefaultValue = Array.Empty<long>() };
|
||||
public static TableColumn<long[]> RoleOverides { get; } = new("role_overides") { DefaultValue = Array.Empty<long>() };
|
||||
public static TableColumn<long[]> UserOverides { get; } = new("member_overides") { DefaultValue = Array.Empty<long>() };
|
||||
public static TableColumn<long[]> RoleOverrides { get; } = new("role_overrides") { DefaultValue = Array.Empty<long>() };
|
||||
public static TableColumn<long[]> UserOverrides { get; } = new("member_overrides") { DefaultValue = Array.Empty<long>() };
|
||||
public static TableColumn<long> TitleEncryptionKey { get; } = new("title_encryption_key") { DefaultValue = 0 };
|
||||
public static TableColumn<long> DescriptionEncryptionKey { get; } = new("description_encryption_key") { DefaultValue = 0 };
|
||||
public static TableColumn<EncoderType> TitleEncoderType { get; } = new("title_encoder_type") { DefaultValue = EncoderType.UTF8 };
|
||||
|
20
LuskiServer/Classes/TableDef/ChannelProfiles.cs
Normal file
20
LuskiServer/Classes/TableDef/ChannelProfiles.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using ServerDatabase;
|
||||
using ServerDatabase.SourceGenerator;
|
||||
using bob = Luski.Shared.PublicServers.V1.Enums.PictureType;
|
||||
|
||||
namespace LuskiServer.Classes.TableDef;
|
||||
|
||||
public class ChannelProfiles
|
||||
{
|
||||
public static TableColumn<long> ID { get; } = new("id", true);
|
||||
public static TableColumn<string> DisplayName { get; } = new("displayname");
|
||||
public static TableColumn<long[]> Controllers { get; } = new("controllers") {DefaultValue = Array.Empty<long>()};
|
||||
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
|
||||
public static TableColumn<byte[]> Picture { get; } = new("picture");
|
||||
public static TableColumn<byte[]> Color { get; } = new("color") { DefaultValue = new byte[]{255,255,255,255}};
|
||||
}
|
||||
|
||||
[TableRow(typeof(ChannelProfiles))]
|
||||
public partial class ChannelProfileRow
|
||||
{}
|
@ -1,8 +1,10 @@
|
||||
using System.Text;
|
||||
using JacobTechEncryption.Enums;
|
||||
using LuskiServer.Enums;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using ServerDatabase;
|
||||
using ServerDatabase.SourceGenerator;
|
||||
using bob = Luski.Shared.PublicServers.V1.Enums.PictureType;
|
||||
|
||||
|
||||
namespace LuskiServer.Classes.TableDef;
|
||||
|
||||
@ -10,19 +12,19 @@ public static class Channels
|
||||
{
|
||||
public static TableColumn<long> ID { get; } = new("id", true);
|
||||
public static TableColumn<long> Parent { get; } = new("parent") { DefaultValue = -1 };
|
||||
public static TableColumn<string> Color { get; } = new("color") {DefaultValue = "ÿÿÿÿ" };
|
||||
public static TableColumn<byte[]> Color { get; } = new("color") {DefaultValue = new byte[]{255,255,255,255} };
|
||||
public static TableColumn<ChannelType> Type { get; } = new("type");
|
||||
public static TableColumn<DateTime> Epoch { get; } = new("epoch");
|
||||
public static TableColumn<byte[]> Name { get; } = new("name") { DefaultValue = Encoding.UTF8.GetBytes("New Channel") };
|
||||
public static TableColumn<byte[]> Description { get; } = new("description") { DefaultValue = Encoding.UTF8.GetBytes("New Channel") };
|
||||
public static TableColumn<long[]> RoleOverides { get; } = new("role_overides") { DefaultValue = Array.Empty<long>() };
|
||||
public static TableColumn<long[]> UserOverides { get; } = new("member_overides") { DefaultValue = Array.Empty<long>() };
|
||||
public static TableColumn<long[]> RoleOverrides { get; } = new("role_overrides") { DefaultValue = Array.Empty<long>() };
|
||||
public static TableColumn<long[]> UserOverrides { get; } = new("member_overrides") { DefaultValue = Array.Empty<long>() };
|
||||
public static TableColumn<long> TitleEncryptionKey { get; } = new("title_encryption_key") { DefaultValue = 0 };
|
||||
public static TableColumn<long> DescriptionEncryptionKey { get; } = new("description_encryption_key") { DefaultValue = 0 };
|
||||
public static TableColumn<long[]> EncryptionKeys { get; } = new("encryption_keys") { DefaultValue = new long[]{0} };
|
||||
public static TableColumn<EncoderType> TitleEncoderType { get; } = new("title_encoder_type") { DefaultValue = EncoderType.UTF8 };
|
||||
public static TableColumn<EncoderType> DescriptionEncoderType { get; } = new("description_encoder_type") { DefaultValue = EncoderType.UTF8 };
|
||||
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = Enums.PictureType.png };
|
||||
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
|
||||
public static TableColumn<byte[]> Picture { get; } = new("picture");
|
||||
public static TableColumn<EncoderType[]> EncoderTypes { get; } = new("encoder_types") { DefaultValue = new []
|
||||
{
|
||||
@ -30,6 +32,8 @@ public static class Channels
|
||||
EncoderType.UTF32, EncoderType.ASCII,
|
||||
EncoderType.Latin1, EncoderType.BigEndianUnicode
|
||||
} };
|
||||
|
||||
public static TableColumn<long[]> Profiles { get; } = new("profiles") { DefaultValue = Array.Empty<long>() };
|
||||
}
|
||||
|
||||
[TableRow(typeof(Channels))]
|
||||
|
@ -8,7 +8,6 @@ public static class Files
|
||||
{
|
||||
public static TableColumn<long> ID { get; } = new("id", true);
|
||||
public static TableColumn<long> Owner { get; } = new("owner");
|
||||
public static TableColumn<long> Channel { get; } = new("channel");
|
||||
public static TableColumn<bool> Public { get; } = new("public_download");
|
||||
public static TableColumn<long[]> AllowedChannels { get; } = new("channels");
|
||||
public static TableColumn<long> Size { get; } = new("size");
|
||||
|
@ -7,13 +7,14 @@ namespace LuskiServer.Classes.TableDef;
|
||||
public static class Messages
|
||||
{
|
||||
public static TableColumn<long> ID { get; } = new("id", true);
|
||||
public static TableColumn<long> ChannelID { get; } = new("channel_id");
|
||||
public static TableColumn<long> ChannelID { get; } = new("channel_id", true);
|
||||
public static TableColumn<long> AuthorID { get; } = new("author_id");
|
||||
public static TableColumn<long> TimeStamp { get; } = new("ts");
|
||||
public static TableColumn<byte[]> Context { get; } = new("context");
|
||||
public static TableColumn<long> EncryptionKey { get; } = new("encryption_key");
|
||||
public static TableColumn<EncoderType> EncoderType { get; } = new("encoder_type");
|
||||
public static TableColumn<long[]> Files { get; } = new("files");
|
||||
public static TableColumn<bool> IsChannelProfile { get; } = new("is_channel_profile") { DefaultValue = false };
|
||||
public static TableColumn<long> ReplyTo { get; } = new("reply_to");
|
||||
}
|
||||
|
||||
[TableRow(typeof(Messages))]
|
||||
|
@ -1,3 +1,4 @@
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using LuskiServer.Enums;
|
||||
using ServerDatabase;
|
||||
using ServerDatabase.SourceGenerator;
|
||||
@ -10,9 +11,9 @@ public static class Roles
|
||||
public static TableColumn<string> Name { get; } = new("name");
|
||||
public static TableColumn<string> DisplayName { get; } = new("display_name") {DefaultValue = string.Empty};
|
||||
public static TableColumn<int> Index { get; } = new("index") {DefaultValue = 0 };
|
||||
public static TableColumn<string> Color { get; } = new("color");
|
||||
public static TableColumn<byte[]> Color { get; } = new("color") {DefaultValue = new byte[]{255,255,255,255}};
|
||||
public static TableColumn<string> Description { get; } = new("description");
|
||||
public static TableColumn<ServerPermissions[]> ServerPermissions { get; } = new("server_perms");
|
||||
public static TableColumn<ServerPermission> ServerPermissions { get; } = new("server_perms");
|
||||
public static TableColumn<long[]> MembersList { get; } = new("members_list") {DefaultValue = Array.Empty<long>()};
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,16 @@
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using LuskiServer.Enums;
|
||||
using ServerDatabase;
|
||||
using ServerDatabase.SourceGenerator;
|
||||
using bob = Luski.Shared.PublicServers.V1.Enums.PictureType;
|
||||
|
||||
|
||||
namespace LuskiServer.Classes.TableDef;
|
||||
|
||||
public static class Server
|
||||
{
|
||||
public static TableColumn<long> ID { get; } = new("id", true) { DefaultValue = 0 };
|
||||
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = Enums.PictureType.png };
|
||||
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
|
||||
public static TableColumn<byte[]> Picture { get; } = new("picture") { DefaultValue = Array.Empty<byte>() };
|
||||
public static TableColumn<string> Name { get; } = new("name") { DefaultValue = "Luski Server" };
|
||||
public static TableColumn<string> Description { get; } = new("description") { DefaultValue = "description" };
|
||||
|
@ -1,15 +1,16 @@
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using ServerDatabase;
|
||||
using ServerDatabase.SourceGenerator;
|
||||
|
||||
namespace LuskiServer.Classes.TableDef;
|
||||
|
||||
public static class ServerRoleOverides
|
||||
public static class ServerRoleOverrides
|
||||
{
|
||||
public static TableColumn<long> ID { get; } = new("id", true);
|
||||
public static TableColumn<long> RoleID { get; } = new("role_id");
|
||||
public static TableColumn<string[]> Overides { get; } = new("overides");
|
||||
public static TableColumn<ServerPermission> BadPermissions { get; } = new("bad_permissions");
|
||||
public static TableColumn<ServerPermission> GoodPermissions { get; } = new("good_permissions");
|
||||
}
|
||||
|
||||
[TableRow(typeof(ServerRoleOverides))]
|
||||
public partial class ServerRoleOverideRow
|
||||
{}
|
||||
[TableRow(typeof(ServerRoleOverrides))]
|
||||
public partial class ServerRoleOverrideRow;
|
@ -1,18 +1,24 @@
|
||||
using ServerDatabase;
|
||||
using ServerDatabase.SourceGenerator;
|
||||
using ServerDatabase.Utils;
|
||||
using ServerDatabase.Utils.Enums;
|
||||
|
||||
namespace LuskiServer.Classes.TableDef;
|
||||
|
||||
public static class Sessions
|
||||
{
|
||||
public static TableColumn<long> ID { get; } = new("id", true);
|
||||
public static TableColumn<long> User { get; } = new("userid");
|
||||
public static TableColumn<long> User { get; } = new("userid")
|
||||
{ForeignKeys = new IForeignKey[]{ new ForeignKey(){Table = Tables.Users, Column = Users.ID}}};
|
||||
public static TableColumn<string> WSSTCP { get; } = new("wsstcp");
|
||||
public static TableColumn<string> Token { get; } = new("token");
|
||||
public static TableColumn<string> LoginToken { get; } = new("login_token");
|
||||
public static TableColumn<long> SessionKey { get; } = new("session_key");
|
||||
public static TableColumn<long> SessionKey { get; } = new("session_key")
|
||||
{ForeignKeys = new IForeignKey[]{ new ForeignKey(){Table = Tables.Keys, Column = Keys.ID, OnDelete = ConstraintAction.Cascade}}};
|
||||
|
||||
public static TableColumn<long> StorageID { get; } = new("storage_id");
|
||||
}
|
||||
|
||||
[TableRow(typeof(Sessions))]
|
||||
public partial class SessionsRow
|
||||
{}
|
||||
|
@ -1,16 +1,17 @@
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using LuskiServer.Enums;
|
||||
using ServerDatabase;
|
||||
using ServerDatabase.SourceGenerator;
|
||||
|
||||
namespace LuskiServer.Classes.TableDef;
|
||||
|
||||
public static class UserRoleOverides
|
||||
public static class UserRoleOverrides
|
||||
{
|
||||
public static TableColumn<long> ID { get; } = new("id", true);
|
||||
public static TableColumn<long> UserID { get; } = new("user_id");
|
||||
public static TableColumn<string[]> Overides { get; } = new("overides");
|
||||
public static TableColumn<ServerPermission> BadPermissions { get; } = new("bad_permissions");
|
||||
public static TableColumn<ServerPermission> GoodPermissions { get; } = new("good_permissions");
|
||||
}
|
||||
|
||||
[TableRow(typeof(UserRoleOverides))]
|
||||
public partial class UserRoleOverideRow
|
||||
{}
|
||||
[TableRow(typeof(UserRoleOverrides))]
|
||||
public partial class UserRoleOverrideRow;
|
@ -1,6 +1,9 @@
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using LuskiServer.Enums;
|
||||
using ServerDatabase;
|
||||
using ServerDatabase.SourceGenerator;
|
||||
using bob = Luski.Shared.PublicServers.V1.Enums.PictureType;
|
||||
|
||||
|
||||
namespace LuskiServer.Classes.TableDef;
|
||||
|
||||
@ -9,8 +12,8 @@ public class Users
|
||||
public static TableColumn<long> ID { get; } = new("id", true);
|
||||
public static TableColumn<string> DisplayName { get; } = new("displayname");
|
||||
public static TableColumn<long> SelectedChannel { get; } = new("selected_channel");
|
||||
public static TableColumn<Status> Status { get; } = new("status") { DefaultValue = Enums.Status.Offline };
|
||||
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = Enums.PictureType.png };
|
||||
public static TableColumn<UserStatus> Status { get; } = new("status") { DefaultValue = UserStatus.Offline };
|
||||
public static TableColumn<PictureType> PictureType { get; } = new("picture_type") {DefaultValue = bob.png };
|
||||
public static TableColumn<byte[]> Picture { get; } = new("picture");
|
||||
public static TableColumn<long[]> Roles { get; } = new("roles");
|
||||
public static TableColumn<byte[]> Username { get; } = new("username");
|
||||
|
@ -14,10 +14,11 @@ public static class Tables
|
||||
public static Table<CategoryRow> Categories { get; } = new("categories", null!);
|
||||
public static Table<ChannelRow> Channels { get; } = new("channels", null!);
|
||||
public static Table<MessageRow> Messages { get; } = new("messages", null!);
|
||||
public static Table<ServerRoleOverideRow> ServerRoleOverides { get; } = new("role_overides", null!);
|
||||
public static Table<ServerRoleOverrideRow> ServerRoleOverrides { get; } = new("role_overrides", null!);
|
||||
public static Table<StorageRow> Storage { get; } = new("storage", null!);
|
||||
public static Table<UserRoleOverideRow> UserRoleOverides { get; } = new("user_overides", null!);
|
||||
public static Table<UserRoleOverrideRow> UserRoleOverrides { get; } = new("user_overrides", null!);
|
||||
public static Table<SessionsRow> Sessions { get; } = new("sessions", null!);
|
||||
public static Table<SessionTokenRow> SessionTokens { get; } = new("session_tokens", null!);
|
||||
public static Table<KeyRow> Keys { get; } = new("keys", null!);
|
||||
public static Table<ChannelProfileRow> ChannelProfiles { get; } = new("channel_profiles", null!);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class BasePermOverideRequest
|
||||
{
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
using JacobTechEncryption.Enums;
|
||||
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class ClientKeyPostReqest
|
||||
{
|
||||
public EncryptionType encryption_type { get; set; }
|
||||
public string key_data { get; set; }
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
using System.Security.Cryptography;
|
||||
using JacobTechEncryption;
|
||||
using JacobTechEncryption.Enums;
|
||||
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class File
|
||||
{
|
||||
public string name { get; set; } = default!;
|
||||
public EncoderType encoder_type { get; set; } = default!;
|
||||
public EncoderType name_encoder_type { get; set; } = default!;
|
||||
public long encryption_key { get; set; } = default!;
|
||||
public long channel { get; set; } = default!;
|
||||
public long name_encryption_key { get; set; } = default!;
|
||||
public ulong? size { get; set; } = default!;
|
||||
public long? id { get; set; } = default!;
|
||||
|
||||
internal void decrypt(RSAParameters key, string outkey)
|
||||
{
|
||||
if (name != null) name = Convert.ToBase64String(Encryption.RSA.Encrypt(Encryption.RSA.Decrypt(Convert.FromBase64String(name), key), outkey));
|
||||
//for (int i = 0; i < data.Count(); i++)
|
||||
// {
|
||||
// data[i] = Convert.ToBase64String(Encryption.Encrypt(Encryption.Decrypt(Convert.FromBase64String(data[i]), key), outkey));
|
||||
//}
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class Role : IWebResponse
|
||||
{
|
||||
public long id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string display_name { get; set; }
|
||||
public int index { get; set; }
|
||||
public string color { get; set; }
|
||||
public string description { get; set; }
|
||||
public Enums.ServerPermissions[] server_permissions { get; set; }
|
||||
public long[] members_list { get; set; }
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class SocketBulkMessage : IWebResponse
|
||||
{
|
||||
public SocketMessage[] messages { get; set; } = default!;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using JacobTechEncryption.Enums;
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class SocketMessage : IWebResponse
|
||||
{
|
||||
public long channel_id { get; set; } = default!;
|
||||
public long user_id { get; set; } = default!;
|
||||
public long id { get; set; } = default!;
|
||||
public string context { get; set; } = default!;
|
||||
public long encryption_key { get; set; } = default!;
|
||||
public EncoderType encoder_type { get; set; } = default!;
|
||||
public File[] files { get; set; } = default!;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
using JacobTechEncryption.Enums;
|
||||
using LuskiServer.Enums;
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class UserCategoryRequest : IWebResponse
|
||||
{
|
||||
public long id { get; set; }
|
||||
public long parent { get; set; }
|
||||
public string name { get; set; }
|
||||
public string description { get; set; }
|
||||
public UserRoleOverideRequest[] role_overides { get; set; }
|
||||
public UserPermOverideRequest[] user_overides { get; set; }
|
||||
public long title_encryption_key { get; set; }
|
||||
public long[] channels { get; set; }
|
||||
public long[] inner_categories { get; set; }
|
||||
public long description_encryption_key { get; set; }
|
||||
public EncoderType title_encoder_type { get; set; }
|
||||
public EncoderType description_encoder_type { get; set; }
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using JacobTechEncryption.Enums;
|
||||
using LuskiServer.Enums;
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class UserChannelRequest : IWebResponse
|
||||
{
|
||||
public long id { get; set; }
|
||||
public long parent { get; set; }
|
||||
public ChannelType type { get; set; }
|
||||
public string name { get; set; }
|
||||
public string description { get; set; }
|
||||
public UserRoleOverideRequest[] role_overides { get; set; }
|
||||
public UserPermOverideRequest[] user_overides { get; set; }
|
||||
public long title_encryption_key { get; set; }
|
||||
public long description_encryption_key { get; set; }
|
||||
public long[] encryption_keys { get; set; }
|
||||
public EncoderType title_encoder_type { get; set; }
|
||||
public EncoderType description_encoder_type { get; set; }
|
||||
public EncoderType[] encoder_types { get; set; }
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using JacobTechEncryption.Enums;
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class UserKeyGetRequest : IWebResponse
|
||||
{
|
||||
public long id { get; set; }
|
||||
public long owner { get; set; }
|
||||
public EncryptionType encryption_type { get; set; }
|
||||
public string key_data { get; set; }
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class UserPermOverideRequest : HTTPResponse
|
||||
{
|
||||
public long id { get; set; }
|
||||
public long user_id { get; set; }
|
||||
public string[] overides { get; set; }
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
namespace LuskiServer.Classes.WebTypes;
|
||||
|
||||
public class UserRoleOverideRequest : HTTPResponse
|
||||
{
|
||||
public long id { get; set; }
|
||||
public long role_id { get; set; }
|
||||
public string[] overides { get; set; }
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using JacobTechEncryption.Enums;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
namespace LuskiServer.Classes.v1.Incoming;
|
||||
|
||||
public class ClientSendMessage
|
||||
{
|
||||
[JsonInclude]
|
||||
[BindRequired]
|
||||
[JsonRequired]
|
||||
[JsonPropertyName("channel_id")]
|
||||
public long ChannelID { get; set; }
|
||||
[JsonInclude]
|
||||
[BindRequired]
|
||||
[JsonRequired]
|
||||
[JsonPropertyName("context")]
|
||||
public string Base64Context { get; set; }
|
||||
|
||||
[JsonInclude]
|
||||
[BindRequired]
|
||||
[JsonRequired]
|
||||
[JsonPropertyName("files")]
|
||||
public long[] Files { get; set; }
|
||||
[JsonInclude]
|
||||
[BindRequired]
|
||||
[JsonRequired]
|
||||
[JsonPropertyName("encryption_key")]
|
||||
public long EncryptionKey { get; set; }
|
||||
[JsonInclude]
|
||||
[BindRequired]
|
||||
[JsonRequired]
|
||||
[JsonPropertyName("encoding")]
|
||||
public EncoderType Encoding { get; set; }
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
using JacobTechEncryption.Enums;
|
||||
using LuskiServer.Enums;
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.v1.OutGoing;
|
||||
|
||||
public class ChannelResponse : IWebResponse
|
||||
{
|
||||
public string name { get; set; } = default!;
|
||||
public string color { get; set; } = default!;
|
||||
public string description { get; set; } = default!;
|
||||
public PictureType picture_type { get; set; } = default!;
|
||||
public long id { get; set; } = default!;
|
||||
public ChannelType type { get; set; } = default!;
|
||||
public long parent { get; set; } = default!;
|
||||
public DateTime epoch { get; set; } = default!;
|
||||
public long title_encryption_key { get; set; } = default!;
|
||||
public long description_encryption_key { get; set; } = default!;
|
||||
public bool encoder_blacklist { get; set; } = default!;
|
||||
public bool encryption_blacklist { get; set; } = default!;
|
||||
public long[] encryption_keys { get; set; } = default!;
|
||||
public long[] role_overides { get; set; } = default!;
|
||||
public long[] member_overides { get; set; } = default!;
|
||||
public EncoderType title_encoder_type { get; set; } = default!;
|
||||
public EncoderType description_encoder_type { get; set; } = default!;
|
||||
public EncoderType[] encoder_types { get; set; } = default!;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.v1.OutGoing;
|
||||
|
||||
public class OfflineDataBlob : IWebResponse
|
||||
{
|
||||
public string[] data { get; set; }
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.v1.OutGoing;
|
||||
|
||||
public class ServerFile : IWebResponse
|
||||
{
|
||||
public long id { get; set; }
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.v1.OutGoing;
|
||||
|
||||
public class ServerInfoJson : IWebResponse
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string wssv4 { get; set; }
|
||||
public string description { get; set; }
|
||||
public long owner { get; set; }
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.v1.OutGoing;
|
||||
|
||||
public class StorageInfo : IWebResponse
|
||||
{
|
||||
public long id { get; set; }
|
||||
public string password { get; set; }
|
||||
public bool update { get; set; }
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using JacobTechEncryption.Enums;
|
||||
using LuskiServer.Enums;
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.v1.OutGoing;
|
||||
|
||||
public class UserCategoryResponse : IWebResponse
|
||||
{
|
||||
public long id { get; set; }
|
||||
public long parent { get; set; }
|
||||
public string name { get; set; }
|
||||
public string color { get; set; } = default!;
|
||||
public string description { get; set; }
|
||||
public long[] role_overides { get; set; }
|
||||
public long[] member_overides { get; set; }
|
||||
public long title_encryption_key { get; set; }
|
||||
public long[] channels { get; set; }
|
||||
public long[] inner_categories { get; set; }
|
||||
public long description_encryption_key { get; set; }
|
||||
public EncoderType title_encoder_type { get; set; }
|
||||
public EncoderType description_encoder_type { get; set; }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
using LuskiServer.Classes.WebTypes;
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.v1.OutGoing;
|
||||
|
||||
public class UserKeysGetRequest : IWebResponse
|
||||
{
|
||||
public UserKeyGetRequest[] keys { get; set; }
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
using LuskiServer.Enums;
|
||||
using LuskiServer.Interfaces;
|
||||
|
||||
namespace LuskiServer.Classes.v1.OutGoing;
|
||||
|
||||
public class UserResponse : IWebResponse
|
||||
{
|
||||
public Status status { get; set; } = default!;
|
||||
public long[] roles { get; set; } = default!;
|
||||
public long id { get; set; } = default!;
|
||||
public string displayname { get; set; } = default!;
|
||||
public PictureType picture_type { get; set; } = default!;
|
||||
public long selected_channel { get; set; } = default!;
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using Asp.Versioning;
|
||||
using JacobTechEncryption;
|
||||
using JacobTechEncryption.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Classes.v1.OutGoing;
|
||||
using LuskiServer.Classes.WebTypes;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
@ -26,10 +24,10 @@ public class KeysController : ControllerBase
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[Produces(MediaTypeNames.Application.Xml)]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/PublicKey")]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/PublicKey")]
|
||||
public IActionResult PublicKey()
|
||||
{
|
||||
return File(Encoding.UTF8.GetBytes(Luski.Encryption.Keys.PublicKey), "application/xml");
|
||||
return File(Encoding.UTF8.GetBytes(LuskiFunctions.Encryption.Keys.PublicKey), "application/xml");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -41,14 +39,14 @@ public class KeysController : ControllerBase
|
||||
[HttpDelete]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
||||
[ProducesResponseType(typeof(HTTPResponse), StatusCodes.Status403Forbidden)]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Delete([FromHeader(Name = "id")]long keyid, [FromHeader(Name = "token")]string? token)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Tables.Keys.TryRead(Keys.Owner, out long Owner, Keys.ID.CreateParameter(keyid)) || (Owner != ID || !Luski.HasPermissions(ID, ServerPermissions.DeleteKeys)))
|
||||
if (!Tables.Keys.TryRead(Keys.Owner, out long Owner, Keys.ID.CreateParameter(keyid)) || (Owner != ID || !LuskiFunctions.HasPermissions(ID, ServerPermission.DeleteKeys)))
|
||||
return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
|
||||
Tables.Keys.DeleteRow(Keys.ID.CreateParameter(keyid));
|
||||
@ -67,23 +65,24 @@ public class KeysController : ControllerBase
|
||||
/// <param name="keyreq">The public key info you want to store on the server</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Consumes(typeof(ClientKeyPostReqest), MediaTypeNames.Application.Json)]
|
||||
[Consumes(typeof(KeyPostCTS), MediaTypeNames.Application.Json)]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
||||
[ProducesResponseType(typeof(HTTPResponse), StatusCodes.Status403Forbidden)]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
public IActionResult Post([FromBody]ClientKeyPostReqest keyreq, [FromHeader(Name = "token")]string? token)
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Post([FromBody]KeyPostCTS keyreq, [FromHeader(Name = "token")]string? token)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
|
||||
Luski.Snowflake sf = Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch);
|
||||
LuskiFunctions.Snowflake sf = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
||||
Console.WriteLine("P");
|
||||
Tables.Keys.Insert(
|
||||
Keys.ID.CreateParameter(sf.ID),
|
||||
Keys.Owner.CreateParameter(ID),
|
||||
Keys.EncryptionType.CreateParameter(keyreq.encryption_type),
|
||||
Keys.KeyData.CreateParameter(Convert.FromBase64String(keyreq.key_data)));
|
||||
Keys.EncryptionType.CreateParameter(keyreq.EncryptionType),
|
||||
Keys.KeyData.CreateParameter(Convert.FromBase64String(keyreq.Data)));
|
||||
return StatusCode(202);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -98,26 +97,26 @@ public class KeysController : ControllerBase
|
||||
/// <param name="userid">The user id you want to get a key from.</param>
|
||||
[HttpGet]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(typeof(HTTPResponse), StatusCodes.Status403Forbidden)]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/UserKeys")]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/UserKeys")]
|
||||
public IActionResult GetUserKeys([FromRoute(Name = "id")]long userid)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Tables.Users.TryRead(Users.ID, out _, Users.ID.CreateParameter(userid))) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
bool UserOnline = Tables.Sessions.TryReadRows(out SessionsRow[] usersessions, Sessions.User.CreateParameter(userid));
|
||||
List<UserKeyGetRequest> req = new();
|
||||
List<KeyGetSTC> req = new();
|
||||
if (!UserOnline)
|
||||
{
|
||||
foreach (StorageRow StorageRow in Tables.Storage.ReadRows(uint.MaxValue, Storage.AccountID.CreateParameter(userid)))
|
||||
{
|
||||
KeyRow Row = Tables.Keys.ReadRow(Keys.ID.CreateParameter(StorageRow.OffileKey));
|
||||
req.Add(new UserKeyGetRequest()
|
||||
req.Add(new KeyGetSTC()
|
||||
{
|
||||
id = Row.ID,
|
||||
owner = Row.Owner,
|
||||
encryption_type = Row.EncryptionType,
|
||||
key_data = Convert.ToBase64String(Row.KeyData)
|
||||
ID = Row.ID,
|
||||
Owner = Row.Owner,
|
||||
EncryptionType = Row.EncryptionType,
|
||||
Data = Convert.ToBase64String(Row.KeyData)
|
||||
});
|
||||
}
|
||||
|
||||
@ -129,12 +128,12 @@ public class KeysController : ControllerBase
|
||||
{
|
||||
if (!b.Contains(sess.StorageID)) b.Add(sess.StorageID);
|
||||
KeyRow Row = Tables.Keys.ReadRow(Keys.ID.CreateParameter(sess.SessionKey));
|
||||
req.Add(new UserKeyGetRequest()
|
||||
req.Add(new KeyGetSTC()
|
||||
{
|
||||
id = Row.ID,
|
||||
owner = Row.Owner,
|
||||
encryption_type = Row.EncryptionType,
|
||||
key_data = Convert.ToBase64String(Row.KeyData)
|
||||
ID = Row.ID,
|
||||
Owner = Row.Owner,
|
||||
EncryptionType = Row.EncryptionType,
|
||||
Data = Convert.ToBase64String(Row.KeyData)
|
||||
});
|
||||
}
|
||||
|
||||
@ -142,18 +141,18 @@ public class KeysController : ControllerBase
|
||||
{
|
||||
if (b.Contains(StorageRow.ID)) continue;
|
||||
KeyRow Row = Tables.Keys.ReadRow(Keys.ID.CreateParameter(StorageRow.OffileKey));
|
||||
req.Add(new UserKeyGetRequest()
|
||||
req.Add(new KeyGetSTC()
|
||||
{
|
||||
id = Row.ID,
|
||||
owner = Row.Owner,
|
||||
encryption_type = Row.EncryptionType,
|
||||
key_data = Convert.ToBase64String(Row.KeyData)
|
||||
ID = Row.ID,
|
||||
Owner = Row.Owner,
|
||||
EncryptionType = Row.EncryptionType,
|
||||
Data = Convert.ToBase64String(Row.KeyData)
|
||||
});
|
||||
}
|
||||
}
|
||||
return this.ResponseToResult(new UserKeysGetRequest()
|
||||
return this.ResponseToResult(new KeysGetSTC()
|
||||
{
|
||||
keys = req.ToArray()
|
||||
Keys = req.ToArray()
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -168,19 +167,19 @@ public class KeysController : ControllerBase
|
||||
/// <param name="keyid">The public key id you want to get from the server.</param>
|
||||
[HttpGet]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(typeof(HTTPResponse), StatusCodes.Status403Forbidden)]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromHeader(Name = "id")]long keyid)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Tables.Keys.TryReadRow(out KeyRow Row, Keys.ID.CreateParameter(keyid))) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
return this.ResponseToResult(new UserKeyGetRequest()
|
||||
return this.ResponseToResult(new KeyGetSTC()
|
||||
{
|
||||
id = Row.ID,
|
||||
owner = Row.Owner,
|
||||
encryption_type = Row.EncryptionType,
|
||||
key_data = Convert.ToBase64String(Row.KeyData)
|
||||
ID = Row.ID,
|
||||
Owner = Row.Owner,
|
||||
EncryptionType = Row.EncryptionType,
|
||||
Data = Convert.ToBase64String(Row.KeyData)
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -196,32 +195,32 @@ public class KeysController : ControllerBase
|
||||
/// <param name="keyreq">The key you want to set for when you go offline.</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Consumes(typeof(ClientKeyPostReqest), MediaTypeNames.Application.Json)]
|
||||
[Consumes(typeof(KeyPostCTS), MediaTypeNames.Application.Json)]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
||||
[ProducesResponseType(typeof(HTTPResponse), StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(typeof(HTTPResponse), 500)]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/SetOfflineKey")]
|
||||
public IActionResult SetOfflineKey([FromBody]ClientKeyPostReqest keyreq, [FromHeader(Name = "token")]string? token, [FromHeader(Name = "storage_id")]long StorageID)
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(typeof(STC), 500)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/SetOfflineKey")]
|
||||
public IActionResult SetOfflineKey([FromBody]KeyPostCTS keyreq, [FromHeader(Name = "token")]string? token, [FromHeader(Name = "storage_id")]long StorageID)
|
||||
{
|
||||
try
|
||||
{
|
||||
string key = "";
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
byte[][]? data = Tables.Storage.Read(Storage.Data, Storage.ID.CreateParameter(ID));
|
||||
if (data is not null && data.Any()) return this.ShowError(ErrorCode.Forbidden, "you cant change your key until you download your data");
|
||||
bool f = Tables.Storage.TryRead(Storage.Data, out byte[][]? data, Storage.ID.CreateParameter(StorageID));
|
||||
if (f && data!.Any()) return this.ShowError(ErrorCode.Forbidden, "you cant change your key until you download your data");
|
||||
long k = 0;
|
||||
if ((k = Tables.Storage.Read(Storage.OffileKey, Storage.ID.CreateParameter(ID))) != 0)
|
||||
if (Tables.Storage.TryRead(Storage.OffileKey, out k, Storage.ID.CreateParameter(StorageID)) && k !=0)
|
||||
{
|
||||
Tables.Keys.DeleteRow(Keys.ID.CreateParameter(k));
|
||||
}
|
||||
Luski.Snowflake sf = Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch);
|
||||
LuskiFunctions.Snowflake sf = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
||||
Console.WriteLine("OO");
|
||||
Tables.Keys.Insert(
|
||||
Keys.ID.CreateParameter(sf.ID),
|
||||
Keys.Owner.CreateParameter(ID),
|
||||
Keys.EncryptionType.CreateParameter(keyreq.encryption_type),
|
||||
Keys.KeyData.CreateParameter(Convert.FromBase64String(keyreq.key_data)));
|
||||
Tables.Storage.Update(Storage.ID, ID,
|
||||
Keys.EncryptionType.CreateParameter(keyreq.EncryptionType),
|
||||
Keys.KeyData.CreateParameter(Convert.FromBase64String(keyreq.Data)));
|
||||
Tables.Storage.Update(Storage.ID, StorageID,
|
||||
Storage.OffileKey.CreateParameter(sf.ID));
|
||||
return StatusCode(202);
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
using Asp.Versioning;
|
||||
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Classes.v1.OutGoing;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
@ -12,12 +13,14 @@ namespace LuskiServer.Controllers.v1;
|
||||
public class OfflineDataController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromHeader(Name = "token")]string? token, [FromHeader(Name = "storage_id")]long SID)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Storage GET 1: " +SID.ToString());
|
||||
if (!this.CanTokenRequest(out long UID, out long SSID, out IActionResult? toc) && toc != null) return toc;
|
||||
Console.WriteLine("Storage GET 1: " +SID.ToString());
|
||||
if (!Tables.Storage.TryReadRow(out StorageRow row, Storage.ID.CreateParameter(SID)))
|
||||
return this.ResponseCodeToResult(ErrorCode.InvalidHeader);
|
||||
if (row.AccountID != UID) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
@ -27,9 +30,9 @@ public class OfflineDataController : ControllerBase
|
||||
bbb.Add(Convert.ToBase64String(blob));
|
||||
}
|
||||
Tables.Storage.Update(Storage.ID, SID, Storage.Data.CreateParameter(Array.Empty<byte[]>()));
|
||||
return this.ResponseToResult(new OfflineDataBlob()
|
||||
return this.ResponseToResult(new OfflineDataBlobSTC()
|
||||
{
|
||||
data = bbb.ToArray()
|
||||
Data = bbb.ToArray()
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -39,12 +42,21 @@ public class OfflineDataController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/Info")]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Info")]
|
||||
public IActionResult GetInfo([FromHeader(Name = "token")]string? token, [FromHeader(Name = "storage_id")]long SID)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var h in HttpContext.Request.Headers)
|
||||
{
|
||||
foreach (var v in h.Value)
|
||||
{
|
||||
Console.WriteLine(h.Key + ": " + v);
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Storage GET: " +SID.ToString());
|
||||
if (!this.CanTokenRequest(out long UID, out long SSID, out IActionResult? toc) && toc != null) return toc;
|
||||
Console.WriteLine("Storage GET: " +SID.ToString());
|
||||
if (!Tables.Storage.TryReadRow(out StorageRow row, Storage.ID.CreateParameter(SID)))
|
||||
return this.ResponseCodeToResult(ErrorCode.InvalidHeader);
|
||||
if (row.AccountID != UID) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
@ -56,13 +68,13 @@ public class OfflineDataController : ControllerBase
|
||||
{
|
||||
update = true;
|
||||
}
|
||||
Tables.Sessions.Update(Sessions.StorageID, SID, Sessions.ID.CreateParameter(SSID));
|
||||
Tables.Sessions.Update(Sessions.ID, SSID, Sessions.StorageID.CreateParameter(SID));
|
||||
}
|
||||
return this.ResponseToResult(new StorageInfo()
|
||||
return this.ResponseToResult(new StorageInfoSTC()
|
||||
{
|
||||
password = Convert.ToBase64String(row.Password),
|
||||
id = row.ID,
|
||||
update = update
|
||||
Password = Convert.ToBase64String(row.Password),
|
||||
ID = row.ID,
|
||||
Update = update
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -72,22 +84,31 @@ public class OfflineDataController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/Info")]
|
||||
public IActionResult SetInfo([FromBody]StorageInfo si, [FromHeader(Name = "token")]string? token, [FromHeader(Name = "storage_id")]long SID)
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Info")]
|
||||
public IActionResult SetInfo([FromBody]StorageInfoCTS si, [FromHeader(Name = "token")]string? token, [FromHeader(Name = "storage_id")]long SID)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var h in HttpContext.Request.Headers)
|
||||
{
|
||||
foreach (var v in h.Value)
|
||||
{
|
||||
Console.WriteLine(h.Key + ": " + v);
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Storage Patch: " +SID.ToString());
|
||||
if (!this.CanTokenRequest(out long UID, out long SSID, out IActionResult? toc) && toc != null) return toc;
|
||||
Console.WriteLine("Storage Patch: " +SID.ToString());
|
||||
if (!Tables.Storage.TryReadRow(out StorageRow row, Storage.ID.CreateParameter(SID)))
|
||||
return this.ResponseCodeToResult(ErrorCode.InvalidHeader);
|
||||
if (row.AccountID != UID) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
Tables.Storage.Update(Storage.ID, SID, Storage.Password.CreateParameter(Convert.FromBase64String(si.password)));
|
||||
Tables.Storage.Update(Storage.ID, SID, Storage.Password.CreateParameter(Convert.FromBase64String(si.Password)));
|
||||
|
||||
return this.ResponseToResult(new StorageInfo()
|
||||
return this.ResponseToResult(new StorageInfoSTC()
|
||||
{
|
||||
password = si.password,
|
||||
id = row.ID,
|
||||
update = false
|
||||
Password = si.Password,
|
||||
ID = row.ID,
|
||||
Update = false
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -97,27 +118,27 @@ public class OfflineDataController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/Info")]
|
||||
public IActionResult PostInfo([FromBody]StorageInfo si, [FromHeader(Name = "token")]string? token)
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Info")]
|
||||
public IActionResult PostInfo([FromBody]StorageInfoCTS si, [FromHeader(Name = "token")]string? token)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("POST");
|
||||
if (!this.CanTokenRequest(out long UID, out long SSID, out IActionResult? toc) && toc != null) return toc;
|
||||
Luski.Snowflake sf = Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch);
|
||||
LuskiFunctions.Snowflake sf = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
||||
Tables.Storage.Insert(
|
||||
Storage.ID.CreateParameter(sf.ID),
|
||||
Storage.Password.CreateParameter(Convert.FromBase64String(si.password)),
|
||||
Storage.Password.CreateParameter(Convert.FromBase64String(si.Password)),
|
||||
Storage.AccountID.CreateParameter(UID),
|
||||
Storage.Data.CreateParameter(Array.Empty<byte[]>()),
|
||||
Storage.OffileKey.CreateParameter(0));
|
||||
Tables.Sessions.Update(Sessions.StorageID, sf.ID, Sessions.ID.CreateParameter(SSID));
|
||||
|
||||
return this.ResponseToResult(new StorageInfo()
|
||||
return this.ResponseToResult(new StorageInfoSTC()
|
||||
{
|
||||
password = si.password,
|
||||
id = sf.ID,
|
||||
update = false
|
||||
Password = si.Password,
|
||||
ID = sf.ID,
|
||||
Update = false
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -4,11 +4,11 @@ using System.Text;
|
||||
using Asp.Versioning;
|
||||
using JacobTechEncryption;
|
||||
using JacobTechEncryption.Enums;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
|
||||
@ -25,9 +25,9 @@ public class SocketAccountController : Controller
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(typeof(Login), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(Login), StatusCodes.Status403Forbidden)]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[ProducesResponseType(typeof(LoginSTC), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromHeader(Name = "username")]string UsernameRaw, [FromHeader(Name = "password")]string PasRaw, [FromHeader(Name = "key")]string KeyRaw)
|
||||
{
|
||||
try
|
||||
@ -38,10 +38,10 @@ public class SocketAccountController : Controller
|
||||
try
|
||||
{
|
||||
|
||||
Username = Encryption.RSA.Decrypt(Convert.FromBase64String(UsernameRaw), Luski.Encryption.Keys.PrivateKey);
|
||||
Username = Encryption.RSA.Decrypt(Convert.FromBase64String(UsernameRaw), LuskiFunctions.Encryption.Keys.PrivateKey);
|
||||
if (!Tables.Users.TryRead(Users.Salt, out byte[]? salt, Users.Username.CreateParameter(Username)))
|
||||
return this.ShowError(ErrorCode.Forbidden, "Make sure our login info is correct");
|
||||
PasBytes = Luski.Encryption.RemotePasswordEncrypt(PasRaw, salt);
|
||||
PasBytes = LuskiFunctions.Encryption.RemotePasswordEncrypt(PasRaw, salt);
|
||||
|
||||
try
|
||||
{
|
||||
@ -73,9 +73,9 @@ public class SocketAccountController : Controller
|
||||
byte[] Number2 = Encoding.UTF8.GetBytes(num2.ToString());
|
||||
string Token = $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(ID.ToString()))}.{Convert.ToBase64String(Timestamp)}.{Convert.ToBase64String(Number)}.{Convert.ToBase64String(Number2)}";
|
||||
|
||||
Luski.Snowflake id = Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch);
|
||||
LuskiFunctions.Snowflake id = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
||||
long kid = id.ID;
|
||||
Tables.Users.Update(Users.ID, ID, Users.Status.CreateParameter(Status.Invisible));
|
||||
Tables.Users.Update(Users.ID, ID, Users.Status.CreateParameter(UserStatus.Invisible));
|
||||
Tables.Keys.Insert(
|
||||
Keys.ID.CreateParameter(kid),
|
||||
Keys.EncryptionType.CreateParameter(EncryptionType.RSA),
|
||||
@ -83,9 +83,9 @@ public class SocketAccountController : Controller
|
||||
Keys.KeyData.CreateParameter(Encoding.UTF8.GetBytes(KeyRaw)));
|
||||
Thread t = new(o => RegToken((string?)o, kid));
|
||||
t.Start(Token);
|
||||
return StatusCode(StatusCodes.Status202Accepted, new Login()
|
||||
return StatusCode(StatusCodes.Status202Accepted, new LoginSTC()
|
||||
{
|
||||
login_token = Token
|
||||
Token = Token
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -103,9 +103,9 @@ public class SocketAccountController : Controller
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(typeof(Login), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(Login), StatusCodes.Status403Forbidden)]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/AccessToken")]
|
||||
[ProducesResponseType(typeof(LoginSTC), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/AccessToken")]
|
||||
public IActionResult GetT([FromHeader(Name = "token")]string TokenRaw, [FromHeader(Name = "key")]string KeyRaw)
|
||||
{
|
||||
try
|
||||
@ -115,7 +115,7 @@ public class SocketAccountController : Controller
|
||||
{
|
||||
|
||||
tok = Encryption.RSA.Decrypt(Convert.FromBase64String(TokenRaw),
|
||||
Luski.Encryption.Keys.PrivateKey, EncoderType.UTF16);
|
||||
LuskiFunctions.Encryption.Keys.PrivateKey, EncoderType.UTF16);
|
||||
|
||||
try
|
||||
{
|
||||
@ -140,9 +140,10 @@ public class SocketAccountController : Controller
|
||||
byte[] Number2 = Encoding.UTF8.GetBytes(num2.ToString());
|
||||
string Token = $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(ID.ToString()))}.{Convert.ToBase64String(Timestamp)}.{Convert.ToBase64String(Number)}.{Convert.ToBase64String(Number2)}";
|
||||
Tables.SessionTokens.DeleteRow(SessionTokens.Token.CreateParameter(tok));
|
||||
Luski.Snowflake id = Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch);
|
||||
LuskiFunctions.Snowflake id = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
||||
long kid = id.ID;
|
||||
Tables.Users.Update(Users.ID, ID, Users.Status.CreateParameter(Status.Invisible));
|
||||
Tables.Users.Update(Users.ID, ID, Users.Status.CreateParameter(UserStatus.Invisible));
|
||||
Console.WriteLine("C");
|
||||
Tables.Keys.Insert(
|
||||
Keys.ID.CreateParameter(kid),
|
||||
Keys.EncryptionType.CreateParameter(EncryptionType.RSA),
|
||||
@ -150,9 +151,9 @@ public class SocketAccountController : Controller
|
||||
Keys.KeyData.CreateParameter(Encoding.UTF8.GetBytes(KeyRaw)));
|
||||
Thread t = new(o => RegToken((string?)o, kid));
|
||||
t.Start(Token);
|
||||
return StatusCode(StatusCodes.Status202Accepted, new Login()
|
||||
return StatusCode(StatusCodes.Status202Accepted, new LoginSTC()
|
||||
{
|
||||
login_token = Token
|
||||
Token = Token
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -175,9 +176,9 @@ public class SocketAccountController : Controller
|
||||
//[Consumes(MediaTypeNames.Image.Jpeg, MediaTypeNames.Image.Gif, MediaTypeNames.Image.Tiff, "image/png")]
|
||||
//[Consumes(MediaTypeNames.Application.Octet)]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(typeof(Login), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(Login), StatusCodes.Status403Forbidden)]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[ProducesResponseType(typeof(LoginSTC), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public async Task<IActionResult> Post([FromHeader(Name = "username")]string? UsernameRaw, [FromHeader(Name = "password")]string PasRaw, [FromHeader(Name = "displayname")]string? DisplayName, [FromHeader(Name = "key")]string? KeyRaw)
|
||||
{
|
||||
try
|
||||
@ -198,8 +199,8 @@ public class SocketAccountController : Controller
|
||||
}
|
||||
try
|
||||
{
|
||||
PasBytes = Luski.Encryption.RemotePasswordEncrypt(PasRaw, salt);
|
||||
Username = Encryption.RSA.Decrypt(Convert.FromBase64String(UsernameRaw), Luski.Encryption.Keys.PrivateKey);
|
||||
PasBytes = LuskiFunctions.Encryption.RemotePasswordEncrypt(PasRaw, salt);
|
||||
Username = Encryption.RSA.Decrypt(Convert.FromBase64String(UsernameRaw), LuskiFunctions.Encryption.Keys.PrivateKey);
|
||||
|
||||
try
|
||||
{
|
||||
@ -225,7 +226,7 @@ public class SocketAccountController : Controller
|
||||
{
|
||||
int num = new Random().Next(1000, 1000000000);
|
||||
int num2 = new Random().Next(1000, 1000000000);
|
||||
Luski.Snowflake id = Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch);
|
||||
LuskiFunctions.Snowflake id = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch);
|
||||
if (Tables.Server.Read(Server.Owner, Server.ID.CreateParameter(0)) == -1)
|
||||
{
|
||||
id = new(0);
|
||||
@ -239,18 +240,22 @@ public class SocketAccountController : Controller
|
||||
|
||||
pfp = GetProfilePictureType(Encoding.UTF8.GetString(Body).ToUpper());
|
||||
long uid = id.ID;
|
||||
long kid = Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch).ID;
|
||||
long kid = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch).ID;
|
||||
Tables.Users.Insert(
|
||||
Users.ID.CreateParameter(uid),
|
||||
Users.DisplayName.CreateParameter(DisplayName!.Replace("'", "\'")),
|
||||
Users.SelectedChannel.CreateParameter(0), //TODO set to default channel
|
||||
Users.Status.CreateParameter(Status.Online),
|
||||
Users.Status.CreateParameter(UserStatus.Online),
|
||||
Users.PictureType.CreateParameter(pfp),
|
||||
Users.Picture.CreateParameter(Body),
|
||||
Users.Roles.CreateParameter(new long[] {0}),
|
||||
Users.Username.CreateParameter(Username),
|
||||
Users.Password.CreateParameter(PasBytes),
|
||||
Users.Salt.CreateParameter(salt));
|
||||
List<long> old = Tables.Roles.Read(Roles.MembersList, Roles.ID.CreateParameter(0)).ToList();
|
||||
old.Add(uid);
|
||||
Tables.Roles.Update(Roles.ID, 0, Roles.MembersList.CreateParameter(old.ToArray()));
|
||||
Console.WriteLine("A");
|
||||
Tables.Keys.Insert(
|
||||
Keys.ID.CreateParameter(kid),
|
||||
Keys.EncryptionType.CreateParameter(EncryptionType.RSA),
|
||||
@ -258,9 +263,9 @@ public class SocketAccountController : Controller
|
||||
Keys.KeyData.CreateParameter(Encoding.UTF8.GetBytes(KeyRaw)));
|
||||
Thread t = new(o => RegToken((string?)o, kid));
|
||||
t.Start(Token);
|
||||
return StatusCode(201, new Login()
|
||||
return StatusCode(201, new LoginSTC()
|
||||
{
|
||||
login_token = Token
|
||||
Token = Token
|
||||
});
|
||||
}
|
||||
return this.ShowError(ErrorCode.Forbidden, "That email is already being used");
|
||||
@ -319,7 +324,7 @@ public class SocketAccountController : Controller
|
||||
{
|
||||
if (token == null) return;
|
||||
long id = long.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(token.Split('.')[0])));
|
||||
long l = Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch).ID;
|
||||
long l = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch).ID;
|
||||
Tables.Sessions.Insert(
|
||||
Sessions.ID.CreateParameter(l),
|
||||
Sessions.User.CreateParameter(id),
|
||||
|
@ -1,8 +1,8 @@
|
||||
using Asp.Versioning;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Classes.WebTypes;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
@ -12,7 +12,7 @@ namespace LuskiServer.Controllers.v1;
|
||||
public class SocketBulkMessageController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get()
|
||||
{
|
||||
try
|
||||
@ -23,7 +23,7 @@ public class SocketBulkMessageController : ControllerBase
|
||||
long MessagesToDownload = 50;
|
||||
long Max = 200;
|
||||
if (long.TryParse(channel_id, out long Channel_Id) && !Tables.Channels.TryRead(Channels.ID, out _, Channels.ID.CreateParameter(Channel_Id))) return this.ShowError(ErrorCode.InvalidHeader, "The the channel id you have given the server is not a valed id");
|
||||
if (!Luski.HasAccessToChannel(ID, Channel_Id, ServerPermissions.ReadMessageHistory))
|
||||
if (!LuskiFunctions.HasAccessToChannel(ID, Channel_Id, ServerPermission.ReadMessageHistory))
|
||||
return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
if (Request.Headers.ContainsKey("messages")) _ = long.TryParse(Request.Headers["messages"].First(), out MessagesToDownload);
|
||||
if (MessagesToDownload > Max) MessagesToDownload = Max;
|
||||
@ -33,8 +33,7 @@ public class SocketBulkMessageController : ControllerBase
|
||||
{
|
||||
try
|
||||
{
|
||||
bool HasMRID = Tables.Messages.TryRead(Messages.ID, Messages.TimeStamp.GetDecendingOrder(), out long MRID, Messages.ChannelID.CreateParameter(Channel_Id));
|
||||
Console.WriteLine(MRID);
|
||||
bool HasMRID = Tables.Messages.TryRead(Messages.ID, Messages.ID.GetDecendingOrder(), out long MRID, Messages.ChannelID.CreateParameter(Channel_Id));
|
||||
if (HasMRID)
|
||||
{
|
||||
MostRecentID = MRID.ToString();
|
||||
@ -44,63 +43,61 @@ public class SocketBulkMessageController : ControllerBase
|
||||
catch
|
||||
{
|
||||
return this.ResponseToResult(
|
||||
new SocketBulkMessage()
|
||||
new SocketBulkMessageSTC()
|
||||
{
|
||||
messages = Array.Empty<SocketMessage>()
|
||||
Messages = Array.Empty<MessageSTC>()
|
||||
});
|
||||
}
|
||||
}
|
||||
SocketBulkMessage all = new();
|
||||
List<SocketMessage> mmmm = new List<SocketMessage>();
|
||||
SocketBulkMessageSTC all = new();
|
||||
List<MessageSTC> mmmm = new List<MessageSTC>();
|
||||
if (MostRecentID != null)
|
||||
{
|
||||
MessageRow[] rawmsgs = Tables.Messages.ReadRows((uint)MessagesToDownload,
|
||||
Messages.TimeStamp.GetDecendingOrder(),
|
||||
Messages.TimeStamp.CreateParameter(new Luski.Snowflake(long.Parse(MostRecentID)).Timestamp, sign),
|
||||
Messages.ID.GetDecendingOrder(),
|
||||
Messages.ID.CreateParameter(long.Parse(MostRecentID), sign),
|
||||
Messages.ChannelID.CreateParameter(Channel_Id));
|
||||
|
||||
|
||||
|
||||
foreach (MessageRow Row in rawmsgs)
|
||||
{
|
||||
SocketMessage temp = new()
|
||||
MessageSTC temp = new()
|
||||
{
|
||||
context = Convert.ToBase64String(Row.Context),
|
||||
encoder_type = Row.EncoderType,
|
||||
encryption_key = Row.EncryptionKey,
|
||||
channel_id = Row.ChannelID,
|
||||
user_id = Row.AuthorID,
|
||||
id = Row.ID,
|
||||
files = Array.Empty<Classes.WebTypes.File>()
|
||||
Context = Convert.ToBase64String(Row.Context),
|
||||
EncoderType = Row.EncoderType,
|
||||
EncryptionKey = Row.EncryptionKey,
|
||||
ChannelID = Row.ChannelID,
|
||||
AuthorID = Row.AuthorID,
|
||||
ID = Row.ID,
|
||||
Files = Array.Empty<ServerFileInfoSTC>(),
|
||||
IsProfile = Row.IsChannelProfile,
|
||||
};
|
||||
if (Row.Files.Any())
|
||||
{
|
||||
List<Classes.WebTypes.File> list = new();
|
||||
List<ServerFileInfoSTC> list = new();
|
||||
foreach (long b in Row.Files)
|
||||
{
|
||||
FileRow fileraw = Tables.Files.ReadRow(Files.ID.CreateParameter(b));
|
||||
Classes.WebTypes.File file = new()
|
||||
ServerFileInfoSTC file = new()
|
||||
{
|
||||
id = b,
|
||||
name = Convert.ToBase64String(fileraw.Name),
|
||||
size = ulong.Parse(fileraw.Size.ToString()),
|
||||
name_encoder_type = fileraw.NameEncoderType,
|
||||
name_encryption_key = fileraw.NameEncryptionKey,
|
||||
encoder_type = fileraw.EncoderType,
|
||||
encryption_key = fileraw.EncryptionKey,
|
||||
channel = fileraw.Channel
|
||||
ID = b,
|
||||
Name = Convert.ToBase64String(fileraw.Name),
|
||||
Size = fileraw.Size,
|
||||
NameEncoder = fileraw.NameEncoderType,
|
||||
NameKey = fileraw.NameEncryptionKey,
|
||||
Encoder = fileraw.EncoderType,
|
||||
Key = fileraw.EncryptionKey,
|
||||
};
|
||||
list.Add(file);
|
||||
}
|
||||
|
||||
temp.files = list.ToArray();
|
||||
temp.Files = list.ToArray();
|
||||
}
|
||||
mmmm.Add(temp);
|
||||
}
|
||||
}
|
||||
|
||||
if (mmmm is not null) all.messages = mmmm.ToArray();
|
||||
else all.messages = Array.Empty<SocketMessage>();
|
||||
if (mmmm is not null) all.Messages = mmmm.ToArray();
|
||||
else all.Messages = Array.Empty<MessageSTC>();
|
||||
return this.ResponseToResult(all);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -1,11 +1,11 @@
|
||||
using Asp.Versioning;
|
||||
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using Luski.Shared.PublicServers.V1.Shared;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Classes.v1.OutGoing;
|
||||
using LuskiServer.Classes.WebTypes;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
|
||||
@ -14,58 +14,80 @@ namespace LuskiServer.Controllers.v1;
|
||||
public class SocketCategoryController : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
public IActionResult Post([FromBody]UserChannelRequest ChanReq)
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Post([FromBody]CategoryPostCTS ChanReq)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Luski.HasAccessToCategory(ID, ChanReq.parent, ServerPermissions.CreateChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
DateTime epoch = Luski.Config.ServerEpoch;
|
||||
if (!LuskiFunctions.HasAccessToCategory(ID, ChanReq.Parent, out ServerPermission opt, ServerPermission.CreateCategories)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
DateTime epoch = LuskiFunctions.Config.ServerEpoch;
|
||||
List<long> RoleOverides = new(), UserOverides = new();
|
||||
if (ChanReq.role_overides is not null && ChanReq.role_overides.Any())
|
||||
if (ChanReq.RoleOverrides.Length > 0)
|
||||
{
|
||||
foreach (UserRoleOverideRequest over in ChanReq.role_overides)
|
||||
foreach (UserRoleOverrideCTS over in ChanReq.RoleOverrides)
|
||||
{
|
||||
Luski.Snowflake overSnowflake = Luski.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.ServerRoleOverides.Insert(
|
||||
ServerRoleOverides.ID.CreateParameter(overSnowflake.ID),
|
||||
ServerRoleOverides.RoleID.CreateParameter(over.role_id),
|
||||
ServerRoleOverides.Overides.CreateParameter(over.overides));
|
||||
LuskiFunctions.Snowflake overSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.ServerRoleOverrides.Insert(
|
||||
ServerRoleOverrides.ID.CreateParameter(overSnowflake.ID),
|
||||
ServerRoleOverrides.RoleID.CreateParameter(over.RoleID),
|
||||
ServerRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
||||
ServerRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
||||
RoleOverides.Add(overSnowflake.ID);
|
||||
}
|
||||
}
|
||||
if (ChanReq.user_overides is not null && ChanReq.user_overides.Any())
|
||||
if (ChanReq.UserOverrides.Length > 0)
|
||||
{
|
||||
foreach (UserPermOverideRequest over in ChanReq.user_overides)
|
||||
foreach (UserOverrideCTS over in ChanReq.UserOverrides)
|
||||
{
|
||||
Luski.Snowflake overSnowflake = Luski.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.UserRoleOverides.Insert(
|
||||
UserRoleOverides.ID.CreateParameter(overSnowflake.ID),
|
||||
UserRoleOverides.UserID.CreateParameter(over.user_id),
|
||||
UserRoleOverides.Overides.CreateParameter(over.overides));
|
||||
LuskiFunctions.Snowflake overSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.UserRoleOverrides.Insert(
|
||||
UserRoleOverrides.ID.CreateParameter(overSnowflake.ID),
|
||||
UserRoleOverrides.UserID.CreateParameter(over.UserID),
|
||||
UserRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
||||
UserRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
||||
UserOverides.Add(overSnowflake.ID);
|
||||
}
|
||||
}
|
||||
|
||||
epoch = DateTime.UtcNow.Date;
|
||||
Luski.Snowflake chanSnowflake = Luski.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.Channels.Insert(
|
||||
Channels.ID.CreateParameter(chanSnowflake.ID),
|
||||
Channels.Parent.CreateParameter(ChanReq.parent),
|
||||
Channels.Type.CreateParameter(ChanReq.type),
|
||||
Channels.Epoch.CreateParameter(epoch.Date),
|
||||
Channels.Name.CreateParameter(Convert.FromBase64String(ChanReq.name)),
|
||||
Channels.Description.CreateParameter(Convert.FromBase64String(ChanReq.description)),
|
||||
Channels.RoleOverides.CreateParameter(RoleOverides.ToArray()),
|
||||
Channels.UserOverides.CreateParameter(UserOverides.ToArray()),
|
||||
Channels.TitleEncryptionKey.CreateParameter(ChanReq.title_encryption_key),
|
||||
Channels.DescriptionEncryptionKey.CreateParameter(ChanReq.description_encryption_key),
|
||||
Channels.EncryptionKeys.CreateParameter(ChanReq.encryption_keys),
|
||||
Channels.TitleEncoderType.CreateParameter(ChanReq.title_encoder_type),
|
||||
Channels.DescriptionEncoderType.CreateParameter(ChanReq.description_encoder_type),
|
||||
Channels.EncoderTypes.CreateParameter(ChanReq.encoder_types));
|
||||
return this.ResponseToResult(new UserChannelRequest(){ id = ID});
|
||||
LuskiFunctions.Snowflake chanSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.Categories.Insert(
|
||||
Categories.ID.CreateParameter(chanSnowflake.ID),
|
||||
Categories.Parent.CreateParameter(ChanReq.Parent),
|
||||
Categories.Name.CreateParameter(Convert.FromBase64String(ChanReq.Name)),
|
||||
Categories.Description.CreateParameter(Convert.FromBase64String(ChanReq.Description)),
|
||||
Categories.RoleOverrides.CreateParameter(RoleOverides.ToArray()),
|
||||
Categories.UserOverrides.CreateParameter(UserOverides.ToArray()),
|
||||
Categories.TitleEncryptionKey.CreateParameter(ChanReq.TitleEncryptionKey),
|
||||
Categories.DescriptionEncryptionKey.CreateParameter(ChanReq.DescriptionEncryptionKey),
|
||||
Categories.TitleEncoderType.CreateParameter(ChanReq.TitleEncoderType),
|
||||
Categories.DescriptionEncoderType.CreateParameter(ChanReq.DescriptionEncoderType));
|
||||
CategoryRow chan = Tables.Categories.ReadRow(Categories.ID.CreateParameter(chanSnowflake.ID));
|
||||
if (opt.HasPermission(ServerPermission.ViewCategories))
|
||||
{
|
||||
chan.InnerCategories = Array.Empty<long>();
|
||||
}
|
||||
if (opt.HasPermission(ServerPermission.ViewChannels))
|
||||
{
|
||||
chan.Channels = Array.Empty<long>();
|
||||
}
|
||||
return this.ResponseToResult(new CategorySTC()
|
||||
{
|
||||
Name = Convert.ToBase64String(chan.Name),
|
||||
Description = Convert.ToBase64String(chan.Description),
|
||||
ID = chanSnowflake.ID,
|
||||
Channels = chan.Channels,
|
||||
InnerCategories = chan.InnerCategories,
|
||||
Parent = chan.Parent,
|
||||
TitleEncryptionKey = chan.TitleEncryptionKey,
|
||||
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
||||
TitleEncoderType = chan.TitleEncoderType,
|
||||
DescriptionEncoderType = chan.DescriptionEncoderType,
|
||||
UserOverrides = chan.UserOverrides,
|
||||
RoleOverrides = chan.RoleOverrides,
|
||||
Color = Convert.ToHexString(chan.Color)
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -74,13 +96,13 @@ public class SocketCategoryController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Delete([FromHeader(Name = "id")]long Channel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Luski.HasAccessToCategory(ID, Channel, ServerPermissions.DeleteChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
if (!LuskiFunctions.HasAccessToCategory(ID, Channel, ServerPermission.DeleteChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
Tables.Channels.DeleteRow(Channels.ID.CreateParameter(Channel));
|
||||
Tables.Messages.DeleteRow(Messages.ChannelID.CreateParameter(Channel));
|
||||
return StatusCode(StatusCodes.Status202Accepted);
|
||||
@ -92,44 +114,44 @@ public class SocketCategoryController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Patch([FromHeader(Name = "id")]long Channel) //TODO Add Channel edit latter
|
||||
{
|
||||
return null!;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromHeader(Name = "id")]long Channel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Luski.HasAccessToCategory(ID, Channel, out IReadOnlyList<ServerPermissions> opt, ServerPermissions.ViewCategories, ServerPermissions.ViewChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
var chan = Tables.Categories.ReadRow(Categories.ID.CreateParameter(Channel));
|
||||
if (opt.Contains(ServerPermissions.ViewCategories))
|
||||
if (!LuskiFunctions.HasAccessToCategory(ID, Channel, out ServerPermission opt, ServerPermission.ViewCategories | ServerPermission.ViewChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
CategoryRow chan = Tables.Categories.ReadRow(Categories.ID.CreateParameter(Channel));
|
||||
if (opt.HasPermission(ServerPermission.ViewCategories))
|
||||
{
|
||||
chan.InnerCategories = Array.Empty<long>();
|
||||
}
|
||||
if (opt.Contains(ServerPermissions.ViewChannels))
|
||||
if (opt.HasPermission(ServerPermission.ViewChannels))
|
||||
{
|
||||
chan.Channels = Array.Empty<long>();
|
||||
}
|
||||
return this.ResponseToResult(new UserCategoryResponse()
|
||||
return this.ResponseToResult(new CategorySTC()
|
||||
{
|
||||
name = Convert.ToBase64String(chan.Name),
|
||||
description = Convert.ToBase64String(chan.Description),
|
||||
id = Channel,
|
||||
channels = chan.Channels,
|
||||
inner_categories = chan.InnerCategories,
|
||||
parent = chan.Parent,
|
||||
title_encryption_key = chan.TitleEncryptionKey,
|
||||
description_encryption_key = chan.DescriptionEncryptionKey,
|
||||
title_encoder_type = chan.TitleEncoderType,
|
||||
description_encoder_type = chan.DescriptionEncoderType,
|
||||
member_overides = chan.UserOverides,
|
||||
role_overides = chan.RoleOverides,
|
||||
color = chan.Color
|
||||
Name = Convert.ToBase64String(chan.Name),
|
||||
Description = Convert.ToBase64String(chan.Description),
|
||||
ID = Channel,
|
||||
Channels = chan.Channels,
|
||||
InnerCategories = chan.InnerCategories,
|
||||
Parent = chan.Parent,
|
||||
TitleEncryptionKey = chan.TitleEncryptionKey,
|
||||
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
||||
TitleEncoderType = chan.TitleEncoderType,
|
||||
DescriptionEncoderType = chan.DescriptionEncoderType,
|
||||
UserOverrides = chan.UserOverrides,
|
||||
RoleOverrides = chan.RoleOverrides,
|
||||
Color = Convert.ToHexString(chan.Color)
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -1,10 +1,9 @@
|
||||
using System.Text;
|
||||
using Asp.Versioning;
|
||||
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Classes.v1.OutGoing;
|
||||
using LuskiServer.Classes.WebTypes;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
@ -14,58 +13,88 @@ namespace LuskiServer.Controllers.v1;
|
||||
public class SocketChannelController : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
public IActionResult Post([FromBody]UserChannelRequest ChanReq)
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Post([FromBody]ChannelPostCTS ChanReq)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Luski.HasAccessToCategory(ID, ChanReq.parent, ServerPermissions.CreateChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
DateTime epoch = Luski.Config.ServerEpoch;
|
||||
if (!LuskiFunctions.HasAccessToCategory(ID, ChanReq.Parent, ServerPermission.CreateChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
DateTime epoch = LuskiFunctions.Config.ServerEpoch;
|
||||
List<long> RoleOverides = new(), UserOverides = new();
|
||||
if (ChanReq.role_overides is not null && ChanReq.role_overides.Any())
|
||||
if (ChanReq.RoleOverrides.Length > 0)
|
||||
{
|
||||
foreach (UserRoleOverideRequest over in ChanReq.role_overides)
|
||||
foreach (UserRoleOverrideCTS over in ChanReq.RoleOverrides)
|
||||
{
|
||||
Luski.Snowflake overSnowflake = Luski.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.ServerRoleOverides.Insert(
|
||||
ServerRoleOverides.ID.CreateParameter(overSnowflake.ID),
|
||||
ServerRoleOverides.RoleID.CreateParameter(over.role_id),
|
||||
ServerRoleOverides.Overides.CreateParameter(over.overides));
|
||||
LuskiFunctions.Snowflake overSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.ServerRoleOverrides.Insert(
|
||||
ServerRoleOverrides.ID.CreateParameter(overSnowflake.ID),
|
||||
ServerRoleOverrides.RoleID.CreateParameter(over.RoleID),
|
||||
ServerRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
||||
ServerRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
||||
RoleOverides.Add(overSnowflake.ID);
|
||||
}
|
||||
}
|
||||
if (ChanReq.user_overides is not null && ChanReq.user_overides.Any())
|
||||
if (ChanReq.UserOverrides.Length > 0)
|
||||
{
|
||||
foreach (UserPermOverideRequest over in ChanReq.user_overides)
|
||||
foreach (UserOverrideCTS over in ChanReq.UserOverrides)
|
||||
{
|
||||
Luski.Snowflake overSnowflake = Luski.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.UserRoleOverides.Insert(
|
||||
UserRoleOverides.ID.CreateParameter(overSnowflake.ID),
|
||||
UserRoleOverides.UserID.CreateParameter(over.user_id),
|
||||
UserRoleOverides.Overides.CreateParameter(over.overides));
|
||||
LuskiFunctions.Snowflake overSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.UserRoleOverrides.Insert(
|
||||
UserRoleOverrides.ID.CreateParameter(overSnowflake.ID),
|
||||
UserRoleOverrides.UserID.CreateParameter(over.UserID),
|
||||
UserRoleOverrides.GoodPermissions.CreateParameter(over.GoodPermissions),
|
||||
UserRoleOverrides.BadPermissions.CreateParameter(over.BadPermissions));
|
||||
UserOverides.Add(overSnowflake.ID);
|
||||
}
|
||||
}
|
||||
|
||||
epoch = DateTime.UtcNow.Date;
|
||||
Luski.Snowflake chanSnowflake = Luski.Snowflake.GenerateSnowflake(epoch);
|
||||
LuskiFunctions.Snowflake chanSnowflake = LuskiFunctions.Snowflake.GenerateSnowflake(epoch);
|
||||
Tables.Channels.Insert(
|
||||
Channels.ID.CreateParameter(chanSnowflake.ID),
|
||||
Channels.Parent.CreateParameter(ChanReq.parent),
|
||||
Channels.Type.CreateParameter(ChanReq.type),
|
||||
Channels.Parent.CreateParameter(ChanReq.Parent),
|
||||
Channels.Color.CreateParameter(Convert.FromHexString(ChanReq.Color)),
|
||||
Channels.Type.CreateParameter(ChanReq.Type),
|
||||
Channels.Epoch.CreateParameter(epoch.Date),
|
||||
Channels.Name.CreateParameter(Convert.FromBase64String(ChanReq.name)),
|
||||
Channels.Description.CreateParameter(Convert.FromBase64String(ChanReq.description)),
|
||||
Channels.RoleOverides.CreateParameter(RoleOverides.ToArray()),
|
||||
Channels.UserOverides.CreateParameter(UserOverides.ToArray()),
|
||||
Channels.TitleEncryptionKey.CreateParameter(ChanReq.title_encryption_key),
|
||||
Channels.DescriptionEncryptionKey.CreateParameter(ChanReq.description_encryption_key),
|
||||
Channels.EncryptionKeys.CreateParameter(ChanReq.encryption_keys),
|
||||
Channels.TitleEncoderType.CreateParameter(ChanReq.title_encoder_type),
|
||||
Channels.DescriptionEncoderType.CreateParameter(ChanReq.description_encoder_type),
|
||||
Channels.EncoderTypes.CreateParameter(ChanReq.encoder_types));
|
||||
return this.ResponseToResult(new UserChannelRequest(){ id = ID});
|
||||
Channels.Name.CreateParameter(Convert.FromBase64String(ChanReq.Name)),
|
||||
Channels.Description.CreateParameter(Convert.FromBase64String(ChanReq.Description)),
|
||||
Channels.RoleOverrides.CreateParameter(RoleOverides.ToArray()),
|
||||
Channels.UserOverrides.CreateParameter(UserOverides.ToArray()),
|
||||
Channels.TitleEncryptionKey.CreateParameter(ChanReq.TitleEncryptionKey),
|
||||
Channels.DescriptionEncryptionKey.CreateParameter(ChanReq.DescriptionEncryptionKey),
|
||||
Channels.EncryptionKeys.CreateParameter(ChanReq.EncryptionKeys),
|
||||
Channels.TitleEncoderType.CreateParameter(ChanReq.TitleEncoderType),
|
||||
Channels.DescriptionEncoderType.CreateParameter(ChanReq.DescriptionEncoderType),
|
||||
Channels.PictureType.CreateParameter(PictureType.none),
|
||||
Channels.Picture.CreateParameter(Array.Empty<byte>()),
|
||||
Channels.EncoderTypes.CreateParameter(ChanReq.EncoderTypes),
|
||||
Channels.Profiles.CreateParameter(Array.Empty<long>()));
|
||||
List<long> lll = Tables.Categories.Read(Categories.Channels, Categories.ID.CreateParameter(ChanReq.Parent))
|
||||
.ToList();
|
||||
lll.Add(chanSnowflake.ID);
|
||||
Tables.Categories.Update(Categories.ID, ChanReq.Parent, Categories.Channels.CreateParameter(lll.ToArray()));
|
||||
|
||||
ChannelRow chan = Tables.Channels.ReadRow(Channels.ID.CreateParameter(chanSnowflake.ID));
|
||||
return this.ResponseToResult(new ChannelSTC()
|
||||
{
|
||||
Name = Convert.ToBase64String(chan.Name),
|
||||
Description = Convert.ToBase64String(chan.Description),
|
||||
ID = chanSnowflake.ID,
|
||||
Type = chan.Type,
|
||||
Parent = chan.Parent,
|
||||
Epoch = chan.Epoch,
|
||||
TitleEncryptionKey = chan.TitleEncryptionKey,
|
||||
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
||||
EncryptionKeys = chan.EncryptionKeys,
|
||||
TitleEncoderType = chan.TitleEncoderType,
|
||||
DescriptionEncoderType = chan.DescriptionEncoderType,
|
||||
EncoderTypes = chan.EncoderTypes,
|
||||
UserOverrides = chan.UserOverrides,
|
||||
RoleOverrides = chan.RoleOverrides,
|
||||
PictureType = chan.PictureType,
|
||||
Color = Convert.ToHexString(chan.Color)
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -74,13 +103,13 @@ public class SocketChannelController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Delete([FromHeader(Name = "id")]long Channel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Luski.HasAccessToCategory(ID, Channel, ServerPermissions.DeleteChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
if (!LuskiFunctions.HasAccessToCategory(ID, Channel, ServerPermission.DeleteChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
Tables.Channels.DeleteRow(Channels.ID.CreateParameter(Channel));
|
||||
Tables.Messages.DeleteRow(Messages.ChannelID.CreateParameter(Channel));
|
||||
return StatusCode(StatusCodes.Status202Accepted);
|
||||
@ -92,20 +121,20 @@ public class SocketChannelController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Patch([FromHeader(Name = "id")]long Channel) //TODO Add Channel edit latter
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/GetPicture")]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/GetPicture")]
|
||||
public IActionResult GetPicture([FromHeader(Name = "id")]long chan)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Luski.HasAccessToChannel(ID, chan)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
if (!LuskiFunctions.HasAccessToChannel(ID, chan, ServerPermission.ViewThis)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
if (!Tables.Channels.TryRead(Channels.Picture, out byte[] image, Channels.ID.CreateParameter(chan))) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
return Tables.Channels.Read(Channels.PictureType, Channels.ID.CreateParameter(chan)) switch
|
||||
{
|
||||
@ -127,32 +156,32 @@ public class SocketChannelController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromHeader(Name = "id")]long Channel)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Luski.HasAccessToChannel(ID, Channel, ServerPermissions.ViewChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
if (!LuskiFunctions.HasAccessToChannel(ID, Channel, ServerPermission.ViewChannels)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
ChannelRow chan = Tables.Channels.ReadRow(Channels.ID.CreateParameter(Channel));
|
||||
return this.ResponseToResult(new ChannelResponse()
|
||||
return this.ResponseToResult(new ChannelSTC()
|
||||
{
|
||||
name = Convert.ToBase64String(chan.Name),
|
||||
description = Convert.ToBase64String(chan.Description),
|
||||
id = Channel,
|
||||
type = chan.Type,
|
||||
parent = chan.Parent,
|
||||
epoch = chan.Epoch,
|
||||
title_encryption_key = chan.TitleEncryptionKey,
|
||||
description_encryption_key = chan.DescriptionEncryptionKey,
|
||||
encryption_keys = chan.EncryptionKeys,
|
||||
title_encoder_type = chan.TitleEncoderType,
|
||||
description_encoder_type = chan.DescriptionEncoderType,
|
||||
encoder_types = chan.EncoderTypes,
|
||||
member_overides = chan.UserOverides,
|
||||
role_overides = chan.RoleOverides,
|
||||
picture_type = chan.PictureType,
|
||||
color = chan.Color
|
||||
Name = Convert.ToBase64String(chan.Name),
|
||||
Description = Convert.ToBase64String(chan.Description),
|
||||
ID = Channel,
|
||||
Type = chan.Type,
|
||||
Parent = chan.Parent,
|
||||
Epoch = chan.Epoch,
|
||||
TitleEncryptionKey = chan.TitleEncryptionKey,
|
||||
DescriptionEncryptionKey = chan.DescriptionEncryptionKey,
|
||||
EncryptionKeys = chan.EncryptionKeys,
|
||||
TitleEncoderType = chan.TitleEncoderType,
|
||||
DescriptionEncoderType = chan.DescriptionEncoderType,
|
||||
EncoderTypes = chan.EncoderTypes,
|
||||
UserOverrides = chan.UserOverrides,
|
||||
RoleOverrides = chan.RoleOverrides,
|
||||
PictureType = chan.PictureType,
|
||||
Color = Convert.ToHexString(chan.Color)
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
75
LuskiServer/Controllers/v1/SocketChannelProfileController.cs
Normal file
75
LuskiServer/Controllers/v1/SocketChannelProfileController.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System.Net.Mime;
|
||||
using Asp.Versioning;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
|
||||
[ApiVersion(1)]
|
||||
[ApiController]
|
||||
public class SocketChannelProfileController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the Avatar for the channel profile.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the requested profile</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Produces(MediaTypeNames.Image.Jpeg, MediaTypeNames.Image.Gif, MediaTypeNames.Image.Tiff, "image/png", MediaTypeNames.Application.Json)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Avatar/{id:long}")]
|
||||
public IActionResult? Avatar(long id)
|
||||
{
|
||||
if (Tables.ChannelProfiles.TryRead(ChannelProfiles.Picture, out byte[]? image, ChannelProfiles.ID.CreateParameter(id)))
|
||||
{
|
||||
return Tables.ChannelProfiles.Read(ChannelProfiles.PictureType, ChannelProfiles.ID.CreateParameter(id)) switch
|
||||
{
|
||||
PictureType.png => File(image, "image/png"),
|
||||
PictureType.jpeg => File(image, "image/jpeg"),
|
||||
PictureType.bmp => File(image, "image/bmp"),
|
||||
PictureType.gif => File(image, "image/gif"),
|
||||
PictureType.ico => File(image, "image/vnd.microsoft.icon"),
|
||||
PictureType.svg => File(image, "image/svg+xml"),
|
||||
PictureType.tif => File(image, "image/tiff"),
|
||||
PictureType.webp => File(image, "image/webp"),
|
||||
//should never happen
|
||||
_ => File(image, "image/png"),
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return StatusCode(403, new STC()
|
||||
{
|
||||
Error = ErrorCode.Forbidden,
|
||||
ErrorMessage = "the user you have given does not exist"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromHeader(Name = "id")]long Person)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (Person != ID && !Tables.ChannelProfiles.TryRead(ChannelProfiles.ID, out _, ChannelProfiles.ID.CreateParameter(Person))) return this.ShowError(ErrorCode.Forbidden, "Profile does not exist");
|
||||
return this.ResponseToResult(new ChannelProfileSTC()
|
||||
{
|
||||
ID = Person,
|
||||
DisplayName = Tables.ChannelProfiles.Read(ChannelProfiles.DisplayName, ChannelProfiles.ID.CreateParameter(Person)),
|
||||
PictureType = Tables.ChannelProfiles.Read(ChannelProfiles.PictureType, ChannelProfiles.ID.CreateParameter(Person)),
|
||||
Controllers = Tables.ChannelProfiles.Read(ChannelProfiles.Controllers, ChannelProfiles.ID.CreateParameter(Person)),
|
||||
Color = Convert.ToHexString(Tables.ChannelProfiles.Read(ChannelProfiles.Color, ChannelProfiles.ID.CreateParameter(Person))),
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return this.ShowError(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
using System.Diagnostics.SymbolStore;
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using Asp.Versioning;
|
||||
using JacobTechEncryption;
|
||||
using JacobTechEncryption.Enums;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Classes.v1.OutGoing;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
@ -17,8 +16,8 @@ namespace LuskiServer.Controllers.v1;
|
||||
public class SocketFileController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromQuery(Name = "id")]long id, [FromQuery(Name = "channel")]long? Channel_id)
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromQuery(Name = "id")]long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -35,8 +34,6 @@ public class SocketFileController : ControllerBase
|
||||
else
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Channel_id.HasValue) return this.ResponseCodeToResult(ErrorCode.InvalidURL);
|
||||
if (!Luski.HasAccessToChannel(ID, Channel_id.Value, ServerPermissions.ReadMessageHistory)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
return File(raw, MediaTypeNames.Application.Octet);
|
||||
}
|
||||
}
|
||||
@ -47,7 +44,7 @@ public class SocketFileController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Delete([FromHeader(Name = "id")] long File_id)
|
||||
{
|
||||
try
|
||||
@ -70,7 +67,7 @@ public class SocketFileController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Post([FromBody] byte[] data, [FromHeader(Name = "name_encoder")] EncoderType nameEncoderNum, [FromHeader(Name = "name_encryption")]long nameEncryptionRaw, [FromHeader(Name = "encoder")] EncoderType EncoderNum, [FromHeader(Name = "encryption")]long EncryptionRaw, [FromHeader(Name = "name")]string name)
|
||||
{
|
||||
try
|
||||
@ -78,13 +75,22 @@ public class SocketFileController : ControllerBase
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
|
||||
byte[] hash = Encryption.Hashing.SHA256(data);
|
||||
if (Tables.Files.TryRead(Files.ID, out long ido, Files.Hash.CreateParameter(hash)))
|
||||
return this.ResponseToResult(new ServerFile() { id = ido });
|
||||
if (Tables.Files.TryReadRow(out FileRow ido, Files.Hash.CreateParameter(hash)))
|
||||
return this.ResponseToResult(new ServerFileInfoSTC()
|
||||
{
|
||||
ID = ido.ID,
|
||||
Name = Convert.ToBase64String(ido.Name),
|
||||
Encoder = ido.EncoderType,
|
||||
NameEncoder = ido.NameEncoderType,
|
||||
Key = ido.EncryptionKey,
|
||||
NameKey = ido.NameEncryptionKey,
|
||||
Size = ido.Size
|
||||
});
|
||||
|
||||
ido = Luski.Snowflake.GenerateSnowflake(Luski.Config.ServerEpoch).ID;
|
||||
long ido2 = LuskiFunctions.Snowflake.GenerateSnowflake(LuskiFunctions.Config.ServerEpoch).ID;
|
||||
|
||||
Tables.Files.Insert(
|
||||
Files.ID.CreateParameter(ido),
|
||||
Files.ID.CreateParameter(ido2),
|
||||
Files.Size.CreateParameter(data.Length),
|
||||
Files.Name.CreateParameter(Convert.FromBase64String(name)),
|
||||
Files.NameEncoderType.CreateParameter(nameEncoderNum),
|
||||
@ -96,7 +102,16 @@ public class SocketFileController : ControllerBase
|
||||
Files.Owner.CreateParameter(ID),
|
||||
Files.Public.CreateParameter(false),
|
||||
Files.AllowedChannels.CreateParameter(Array.Empty<long>()));
|
||||
return this.ResponseToResult(new ServerFile() { id = ido });
|
||||
return this.ResponseToResult(new ServerFileInfoSTC()
|
||||
{
|
||||
ID = ido2,
|
||||
Name = name,
|
||||
Encoder = ido.EncoderType,
|
||||
NameEncoder = ido.NameEncoderType,
|
||||
Key = ido.EncryptionKey,
|
||||
NameKey = ido.NameEncryptionKey,
|
||||
Size = ido.Size
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -1,15 +1,14 @@
|
||||
using System.Net.Mime;
|
||||
using Asp.Versioning;
|
||||
using JacobTechEncryption.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.ServerComs;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Classes.v1.Incoming;
|
||||
using LuskiServer.Classes.WebTypes;
|
||||
using LuskiServer.Enums;
|
||||
using LuskiServer.Enums.ServerComs;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServerDatabase;
|
||||
using DataType = LuskiServer.Enums.ServerComs.DataType;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
|
||||
@ -17,43 +16,80 @@ namespace LuskiServer.Controllers.v1;
|
||||
[ApiController]
|
||||
public class SocketMessageController : ControllerBase
|
||||
{
|
||||
private IActionResult GetMSG(long MSG_id)
|
||||
{
|
||||
MessageRow msgraw = Tables.Messages.ReadRow(Messages.ID.CreateParameter(MSG_id));
|
||||
MessageSTC msg = new()
|
||||
{
|
||||
AuthorID = msgraw.AuthorID,
|
||||
Context = Convert.ToBase64String(msgraw.Context),
|
||||
ID = MSG_id,
|
||||
ChannelID = msgraw.ChannelID
|
||||
};
|
||||
List<ServerFileInfoSTC> list = new();
|
||||
if (msgraw.Files.Any())
|
||||
{
|
||||
|
||||
foreach (long b in msgraw.Files)
|
||||
{
|
||||
FileRow fileraw = Tables.Files.ReadRow(Files.ID.CreateParameter(b));
|
||||
ServerFileInfoSTC file = new()
|
||||
{
|
||||
ID = b,
|
||||
Name = Convert.ToBase64String(fileraw.Name),
|
||||
Size = fileraw.Size,
|
||||
NameEncoder = fileraw.NameEncoderType,
|
||||
NameKey = fileraw.NameEncryptionKey,
|
||||
Encoder = fileraw.EncoderType,
|
||||
Key = fileraw.EncryptionKey
|
||||
};
|
||||
list.Add(file);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
msg.Files = list.ToArray();
|
||||
|
||||
return this.ResponseToResult(msg);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromHeader(Name = "msg_id")]long MSG_id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Tables.Messages.TryRead(Messages.ChannelID, out long Channel_Id, Messages.ID.CreateParameter(MSG_id)) ||
|
||||
!Luski.HasAccessToChannel(ID, Channel_Id, ServerPermissions.ReadMessageHistory)) this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
!LuskiFunctions.HasAccessToChannel(ID, Channel_Id, ServerPermission.ReadMessageHistory)) this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
MessageRow msgraw = Tables.Messages.ReadRow(Messages.ID.CreateParameter(MSG_id));
|
||||
SocketMessage msg = new()
|
||||
MessageSTC msg = new()
|
||||
{
|
||||
user_id = msgraw.AuthorID,
|
||||
context = Convert.ToBase64String(msgraw.Context),
|
||||
id = MSG_id,
|
||||
channel_id = Channel_Id
|
||||
AuthorID = msgraw.AuthorID,
|
||||
Context = Convert.ToBase64String(msgraw.Context),
|
||||
ID = MSG_id,
|
||||
ChannelID = Channel_Id
|
||||
};
|
||||
if (msgraw.Files.Any())
|
||||
{
|
||||
List<Classes.WebTypes.File> list = new();
|
||||
List<ServerFileInfoSTC> list = new();
|
||||
foreach (long b in msgraw.Files)
|
||||
{
|
||||
FileRow fileraw = Tables.Files.ReadRow(Files.ID.CreateParameter(b));
|
||||
Classes.WebTypes.File file = new()
|
||||
ServerFileInfoSTC file = new()
|
||||
{
|
||||
id = b,
|
||||
name = Convert.ToBase64String(fileraw.Name),
|
||||
size = ulong.Parse(fileraw.Size.ToString()),
|
||||
name_encoder_type = fileraw.NameEncoderType,
|
||||
name_encryption_key = fileraw.NameEncryptionKey,
|
||||
encoder_type = fileraw.EncoderType,
|
||||
encryption_key = fileraw.EncryptionKey
|
||||
ID = b,
|
||||
Name = Convert.ToBase64String(fileraw.Name),
|
||||
Size = fileraw.Size,
|
||||
NameEncoder = fileraw.NameEncoderType,
|
||||
NameKey = fileraw.NameEncryptionKey,
|
||||
Encoder = fileraw.EncoderType,
|
||||
Key = fileraw.EncryptionKey
|
||||
};
|
||||
list.Add(file);
|
||||
}
|
||||
|
||||
msg.files = list.ToArray();
|
||||
msg.Files = list.ToArray();
|
||||
}
|
||||
|
||||
return this.ResponseToResult(msg);
|
||||
@ -66,39 +102,49 @@ public class SocketMessageController : ControllerBase
|
||||
|
||||
[HttpPost]
|
||||
[DisableRequestSizeLimit]
|
||||
[Consumes(typeof(ClientSendMessage), MediaTypeNames.Application.Json)]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
public IActionResult Post([FromBody]ClientSendMessage data)
|
||||
[Consumes(typeof(MessageCTS), MediaTypeNames.Application.Json)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Post([FromBody]MessageCTS data)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Luski.HasAccessToChannel(ID, data.ChannelID, ServerPermissions.SendMessages)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
Luski.Snowflake Id = Luski.Snowflake.GenerateSnowflake(Tables.Channels.Read(Channels.Epoch, Channels.ID.CreateParameter(data.ChannelID)));
|
||||
if (!LuskiFunctions.HasAccessToChannel(ID, data.ChannelID, ServerPermission.SendMessages)) return this.ResponseCodeToResult(ErrorCode.Forbidden);
|
||||
LuskiFunctions.Snowflake Id = LuskiFunctions.Snowflake.GenerateSnowflake(Tables.Channels.Read(Channels.Epoch, Channels.ID.CreateParameter(data.ChannelID)));
|
||||
ChannelType type = Tables.Channels.Read(Channels.Type, Channels.ID.CreateParameter(data.ChannelID));
|
||||
bool Fake = data.Profile.HasValue;
|
||||
if (Fake)
|
||||
{
|
||||
ID = data.Profile!.Value;
|
||||
}
|
||||
MessageEvent MessageEvent = new()
|
||||
{
|
||||
UserID = ID,
|
||||
ChannelID = data.ChannelID,
|
||||
Base64Context = data.Base64Context,
|
||||
ID = Id.ID
|
||||
ID = Id.ID,
|
||||
EncoderType = data.Encoding,
|
||||
EncryptionKey = data.EncryptionKey,
|
||||
Files = Array.Empty<ServerFileInfoSTC>(),
|
||||
IsProfile = Fake,
|
||||
};
|
||||
Tables.Messages.Insert(
|
||||
Messages.ChannelID.CreateParameter(data.ChannelID),
|
||||
Messages.ID.CreateParameter(Id.ID),
|
||||
Messages.AuthorID.CreateParameter(ID),
|
||||
Messages.Context.CreateParameter(Convert.FromBase64String(data.Base64Context)),
|
||||
Messages.TimeStamp.CreateParameter(Id.Timestamp),
|
||||
Messages.Files.CreateParameter(data.Files),
|
||||
Messages.EncoderType.CreateParameter(data.Encoding),
|
||||
Messages.EncryptionKey.CreateParameter(data.EncryptionKey));
|
||||
Messages.EncryptionKey.CreateParameter(data.EncryptionKey),
|
||||
Messages.ReplyTo.CreateParameter(Id.ID),
|
||||
Messages.IsChannelProfile.CreateParameter(Fake));
|
||||
WSS.SendData(SendType.ID_Group, new ServerEvent()
|
||||
{
|
||||
Type = DataType.MessageCreate,
|
||||
Data = MessageEvent
|
||||
}, Luski.GetChannelBroadcastMembers(data.ChannelID));
|
||||
}, LuskiFunctions.GetChannelBroadcastMembers(data.ChannelID));
|
||||
Response.StatusCode = 201;
|
||||
return null!;
|
||||
return GetMSG(Id.ID);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
44
LuskiServer/Controllers/v1/SocketOverridesController.cs
Normal file
44
LuskiServer/Controllers/v1/SocketOverridesController.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Asp.Versioning;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using Luski.Shared.PublicServers.V1.Shared;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
|
||||
[ApiVersion(1)]
|
||||
[ApiController]
|
||||
public class SocketOverridesController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/UserOverride/{id:long}")]
|
||||
public IActionResult GetUserOverride([FromQuery(Name = "id")]long id)
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Tables.UserRoleOverrides.TryReadRow(out UserRoleOverrideRow row, UserRoleOverrides.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "Override does not exist");
|
||||
return this.ResponseToResult(new UserOverrideSTC()
|
||||
{
|
||||
Id = row.ID,
|
||||
UserID = row.UserID,
|
||||
GoodPermissions = row.GoodPermissions,
|
||||
BadPermissions = row.BadPermissions
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/RoleOverride/{id:long}")]
|
||||
public IActionResult GetRoleOverride([FromQuery(Name = "id")]long id)
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Tables.ServerRoleOverrides.TryReadRow(out ServerRoleOverrideRow? row, ServerRoleOverrides.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "Override does not exist");
|
||||
return this.ResponseToResult(new UserRoleOverrideSTC()
|
||||
{
|
||||
Id = row.ID,
|
||||
RoleID = row.RoleID,
|
||||
GoodPermissions = row.GoodPermissions,
|
||||
BadPermissions = row.BadPermissions
|
||||
});
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using Asp.Versioning;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Classes.WebTypes;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
@ -12,21 +12,21 @@ namespace LuskiServer.Controllers.v1;
|
||||
public class SocketRoleController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromQuery(Name = "id")]long id)
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (!Tables.Roles.TryReadRow(out RoleRow row, Roles.ID.CreateParameter(id))) return this.ShowError(ErrorCode.Forbidden, "User does not exist");
|
||||
return this.ResponseToResult(new Role()
|
||||
return this.ResponseToResult(new RoleSTC()
|
||||
{
|
||||
id = row.ID,
|
||||
server_permissions = row.ServerPermissions,
|
||||
description = row.Description,
|
||||
display_name = row.DisplayName,
|
||||
index = row.Index,
|
||||
name = row.Name,
|
||||
members_list = row.MembersList,
|
||||
color = row.Color
|
||||
ID = row.ID,
|
||||
ServerPermissions = row.ServerPermissions,
|
||||
Description = row.Description,
|
||||
DisplayName = row.DisplayName,
|
||||
Index = row.Index,
|
||||
Name = row.Name,
|
||||
Members = row.MembersList,
|
||||
Color = Convert.ToHexString(row.Color)
|
||||
});
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
using System.Net.Mime;
|
||||
using Asp.Versioning;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Classes.v1.OutGoing;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
@ -17,27 +17,27 @@ public class SocketServerController : ControllerBase
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(ServerInfoJson), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ServerInfoSTC), StatusCodes.Status200OK)]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get()
|
||||
{
|
||||
ServerRow sr = Tables.Server.ReadRow(Server.ID.CreateParameter(0));
|
||||
ServerInfoJson si = new ServerInfoJson()
|
||||
ServerInfoSTC si = new()
|
||||
{
|
||||
wssv4 = (Luski.Config.IPv4_Overode_WSS is null
|
||||
? $"{(Luski.Config.IPv4SecureWSS ? "wss" : "ws")}://{Luski.Config.IPv4WSS}:{Luski.Config.IPv4PortWSS}{Luski.Config.IPv4_URL_WSS}v1"
|
||||
: Luski.Config.IPv4_Overode_WSS + "v1"),
|
||||
name = sr.Name,
|
||||
description = sr.Description,
|
||||
owner = sr.Owner
|
||||
WSSv4Address = (LuskiFunctions.Config.IPv4_Overode_WSS is null
|
||||
? $"{(LuskiFunctions.Config.IPv4SecureWSS ? "wss" : "ws")}://{LuskiFunctions.Config.IPv4WSS}:{LuskiFunctions.Config.IPv4PortWSS}{LuskiFunctions.Config.IPv4_URL_WSS}v1"
|
||||
: LuskiFunctions.Config.IPv4_Overode_WSS + "v1"),
|
||||
Name = sr.Name,
|
||||
Description = sr.Description,
|
||||
Owner = sr.Owner
|
||||
};
|
||||
return this.ResponseToResult(si);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/servercom")]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/servercom")]
|
||||
public IActionResult ServerConnect([FromHeader(Name = "key")]string Key)
|
||||
{
|
||||
byte[] data = Convert.FromBase64String(Key);
|
||||
@ -52,9 +52,9 @@ public class SocketServerController : ControllerBase
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(HTTPResponse), StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Produces(MediaTypeNames.Image.Jpeg, MediaTypeNames.Image.Gif, MediaTypeNames.Image.Tiff, "image/png")]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/Icon")]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Icon")]
|
||||
public IActionResult Icon()
|
||||
{
|
||||
if (Tables.Server.TryRead(Server.Picture, out byte[]? image, Server.ID.CreateParameter(0)))
|
||||
@ -75,10 +75,10 @@ public class SocketServerController : ControllerBase
|
||||
}
|
||||
else
|
||||
{
|
||||
return StatusCode(403, new HTTPResponse()
|
||||
return StatusCode(403, new STC()
|
||||
{
|
||||
error = ErrorCode.Forbidden,
|
||||
error_message = "the user you have given does not exist"
|
||||
Error = ErrorCode.Forbidden,
|
||||
ErrorMessage = "the user you have given does not exist"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
using Asp.Versioning;
|
||||
using JacobTechEncryption;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Classes.v1.OutGoing;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LuskiServer.Controllers.v1;
|
||||
@ -13,20 +12,30 @@ namespace LuskiServer.Controllers.v1;
|
||||
public class SocketUserController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
[Route(Luski.Info.Routes.Default.Base)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base)]
|
||||
public IActionResult Get([FromHeader(Name = "id")]long Person)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
if (Person != ID && !Tables.Users.TryRead(Users.ID, out _, Users.ID.CreateParameter(Person))) return this.ShowError(ErrorCode.Forbidden, "User does not exist");
|
||||
return this.ResponseToResult(new UserResponse()
|
||||
UserRow UR = Tables.Users.ReadRow(Users.ID.CreateParameter(Person));
|
||||
if (Person == ID) return this.ResponseToResult(new SocketUserSTC()
|
||||
{
|
||||
id = Person,
|
||||
displayname = Tables.Users.Read(Users.DisplayName, Users.ID.CreateParameter(Person)),
|
||||
picture_type = Tables.Users.Read(Users.PictureType, Users.ID.CreateParameter(Person)),
|
||||
roles = Tables.Users.Read(Users.Roles, Users.ID.CreateParameter(Person)),
|
||||
status = Tables.Users.Read(Users.Status, Users.ID.CreateParameter(Person))
|
||||
ID = Person,
|
||||
DisplayName = UR.DisplayName,
|
||||
PictureType = UR.PictureType,
|
||||
RoleIds = UR.Roles,
|
||||
Status = UR.Status,
|
||||
SelectedChannel = UR.SelectedChannel
|
||||
});
|
||||
return this.ResponseToResult(new SocketUserSTC()
|
||||
{
|
||||
ID = Person,
|
||||
DisplayName = UR.DisplayName,
|
||||
PictureType = UR.PictureType,
|
||||
RoleIds = UR.Roles,
|
||||
Status = UR.Status
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -1,10 +1,11 @@
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using Asp.Versioning;
|
||||
using Luski.Shared.PublicServers.V1.ClientToServer.HTTP;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.ActionFilters;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
@ -21,12 +22,12 @@ public class SocketUserProfileController : ControllerBase
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(HTTPResponse), StatusCodes.Status403Forbidden, MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden, MediaTypeNames.Application.Json)]
|
||||
[Produces(MediaTypeNames.Text.Plain, MediaTypeNames.Application.Json)]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/Status/{id:long}")]
|
||||
public Status Status(long id)
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Status/{id:long}")]
|
||||
public UserStatus Status(long id)
|
||||
{
|
||||
Status status = Tables.Users.Read(Users.Status, Users.ID.CreateParameter(id));
|
||||
UserStatus status = Tables.Users.Read(Users.Status, Users.ID.CreateParameter(id));
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -37,9 +38,9 @@ public class SocketUserProfileController : ControllerBase
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(HTTPResponse), StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Produces(MediaTypeNames.Image.Jpeg, MediaTypeNames.Image.Gif, MediaTypeNames.Image.Tiff, "image/png", MediaTypeNames.Application.Json)]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/Avatar/{id:long}")]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Avatar/{id:long}")]
|
||||
public IActionResult? Avatar(long id)
|
||||
{
|
||||
if (Tables.Users.TryRead(Users.Picture, out byte[]? image, Users.ID.CreateParameter(id)))
|
||||
@ -60,21 +61,15 @@ public class SocketUserProfileController : ControllerBase
|
||||
}
|
||||
else
|
||||
{
|
||||
return StatusCode(403, new HTTPResponse()
|
||||
return StatusCode(403, new STC()
|
||||
{
|
||||
error = ErrorCode.Forbidden,
|
||||
error_message = "the user you have givven does not exist"
|
||||
Error = ErrorCode.Forbidden,
|
||||
ErrorMessage = "the user you have givven does not exist"
|
||||
});
|
||||
//return File(Encoding.UTF8.GetBytes(obj.ToString()), "application/json");
|
||||
}
|
||||
}
|
||||
|
||||
public class StatusUpdate
|
||||
{
|
||||
[BindRequired]
|
||||
public Status status { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a post to this endpoint to change the status of you account.
|
||||
/// </summary>
|
||||
@ -83,21 +78,21 @@ public class SocketUserProfileController : ControllerBase
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
||||
[ProducesResponseType(typeof(HTTPResponse), StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(typeof(STC), StatusCodes.Status403Forbidden)]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
[Consumes(typeof(StatusUpdate), MediaTypeNames.Application.Json)]
|
||||
[Route(Luski.Info.Routes.Default.Base + "/Status")]
|
||||
[Consumes(typeof(StatusUpdateCTS), MediaTypeNames.Application.Json)]
|
||||
[Route(LuskiFunctions.Info.Routes.Default.Base + "/Status")]
|
||||
[TokenFilter]
|
||||
public IActionResult Status([FromBody]StatusUpdate SentData)
|
||||
public IActionResult Status([FromBody]StatusUpdateCTS SentData)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!this.CanTokenRequest(out long ID, out long SID, out IActionResult? toc) && toc != null) return toc;
|
||||
|
||||
//dynamic? SentData = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(content);
|
||||
Status NewStatus = SentData.status;
|
||||
Status OldStatus = Tables.Users.Read(Users.Status, Users.ID.CreateParameter(ID));
|
||||
if (OldStatus != NewStatus && (int)NewStatus < (int)Enums.Status.MAX && (int)NewStatus >= 0)
|
||||
UserStatus NewStatus = SentData.Status;
|
||||
UserStatus OldStatus = Tables.Users.Read(Users.Status, Users.ID.CreateParameter(ID));
|
||||
if (OldStatus != NewStatus && (int)NewStatus < (int)UserStatus.MAX && (int)NewStatus >= 0)
|
||||
{
|
||||
// JObject @out = new()
|
||||
// {
|
||||
@ -107,7 +102,7 @@ public class SocketUserProfileController : ControllerBase
|
||||
// { "type", (int)DataType.Status_Update }
|
||||
// };
|
||||
Tables.Users.Update(Users.ID, ID, Users.Status.CreateParameter(NewStatus));
|
||||
if (NewStatus == Enums.Status.Invisible) NewStatus = Enums.Status.Offline;
|
||||
if (NewStatus == UserStatus.Invisible) NewStatus = UserStatus.Offline;
|
||||
// WSS.SendData(SendType.All, @out);
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,25 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using JacobTechEncryption.Enums;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Converters.Matrix.Types;
|
||||
using LuskiServer.Enums;
|
||||
|
||||
namespace LuskiServer.Converters.Matrix;
|
||||
|
||||
public static class Matrix
|
||||
{
|
||||
public static void ZipJsonChatExpot(Stream Zip, long Channel, Dictionary<string, long> UserMap,
|
||||
public static void ZipJsonChatExport(Stream Zip, long Channel, Dictionary<string, long> UserMap,
|
||||
Dictionary<string, int> ChannelProfilesIdList,
|
||||
List<Tuple<string, byte[], PictureType, byte[]>> Profiles,
|
||||
List<string> IgnoredUsers, EncoderType Encoder, long Encryption, bool remove = true)
|
||||
{
|
||||
Dictionary<int, long> IdConverter = new();
|
||||
Dictionary<string, long> cps = new();
|
||||
if (Tables.Channels.TryRead(Channels.ID, out _, Channels.ID.CreateParameter(Channel)))
|
||||
{
|
||||
Tables.Messages.DeleteRow(Messages.ChannelID.CreateParameter(Channel));
|
||||
Tables.Files.DeleteRow(Files.Channel.CreateParameter(Channel));
|
||||
//throw new Exception("Channel Exist");
|
||||
}
|
||||
|
||||
@ -27,10 +28,37 @@ public static class Matrix
|
||||
ZipArchiveEntry json = archive.GetEntry(internalfolder + "export.json")!;
|
||||
MessageExport export = JsonSerializer.Deserialize(json.Open(), MessageExportContext.Default.MessageExport)!;
|
||||
|
||||
void checkFakeUser(string id)
|
||||
{
|
||||
if (!IdConverter.ContainsKey(ChannelProfilesIdList[id]))
|
||||
{
|
||||
long id2 = LuskiFunctions.Snowflake.GenerateSnowflake().ID;
|
||||
|
||||
Tables.ChannelProfiles.Insert(
|
||||
ChannelProfiles.ID.CreateParameter(id2),
|
||||
ChannelProfiles.Controllers.CreateDefaultParameter(),
|
||||
ChannelProfiles.PictureType.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item3),
|
||||
ChannelProfiles.Picture.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item2),
|
||||
ChannelProfiles.DisplayName.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item1),
|
||||
ChannelProfiles.Color.CreateParameter(Profiles[ChannelProfilesIdList[id]].Item4));
|
||||
IdConverter.Add(ChannelProfilesIdList[id], id2);
|
||||
foreach (KeyValuePair<string, int> v in ChannelProfilesIdList.Where(s => s.Value == ChannelProfilesIdList[id]))
|
||||
{
|
||||
cps.Add(v.Key, id2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DateTime epoch = DateTime.UnixEpoch.AddMilliseconds(export.Messages[0].Origin).Date;
|
||||
|
||||
try
|
||||
{
|
||||
//TODO REMOVE FOR LAST VERSION
|
||||
foreach (long i in Tables.Channels.Read(Channels.Profiles, Channels.ID.CreateParameter(Channel)))
|
||||
{
|
||||
Tables.ChannelProfiles.DeleteRow(ChannelProfiles.ID.CreateParameter(i));
|
||||
}
|
||||
|
||||
Tables.Channels.Update(Channels.ID, Channel,
|
||||
//Tables.Channels.Insert(
|
||||
Channels.ID.CreateParameter(Channel),
|
||||
@ -38,8 +66,8 @@ public static class Matrix
|
||||
Channels.Type.CreateParameter(ChannelType.TextAndVoice),
|
||||
Channels.Description.CreateParameter(export.RoomTopic.ToDB(Encoder, Encryption)),
|
||||
Channels.Name.CreateParameter(export.RoomName.ToDB(Encoder, Encryption)),
|
||||
Channels.RoleOverides.CreateParameter(Array.Empty<long>()),
|
||||
Channels.UserOverides.CreateParameter(Array.Empty<long>()),
|
||||
Channels.RoleOverrides.CreateParameter(Array.Empty<long>()),
|
||||
Channels.UserOverrides.CreateParameter(Array.Empty<long>()),
|
||||
Channels.Epoch.CreateParameter(epoch),
|
||||
Channels.TitleEncryptionKey.CreateParameter(Encryption),
|
||||
Channels.DescriptionEncryptionKey.CreateParameter(Encryption),
|
||||
@ -50,42 +78,142 @@ public static class Matrix
|
||||
//Channels.Picture.CreateParameter(Array.Empty<byte>()),
|
||||
Channels.EncoderTypes.CreateParameter(new[] { Encoder }));
|
||||
|
||||
|
||||
Dictionary<string, long> Events = new();
|
||||
foreach (Message msg in export.Messages)
|
||||
{
|
||||
if (msg.Type != "m.room.message")
|
||||
continue;
|
||||
if (!UserMap.ContainsKey(msg.Sender))
|
||||
if (!UserMap.ContainsKey(msg.Sender) && !ChannelProfilesIdList.ContainsKey(msg.Sender))
|
||||
{
|
||||
if (IgnoredUsers.Contains(msg.Sender))
|
||||
continue;
|
||||
if (remove)
|
||||
{
|
||||
Tables.Messages.DeleteRow(Messages.ChannelID.CreateParameter(Channel));
|
||||
Tables.Files.DeleteRow(Files.Channel.CreateParameter(Channel));
|
||||
}
|
||||
|
||||
throw new Exception($"User not in list: {msg.Sender}");
|
||||
}
|
||||
|
||||
|
||||
DateTime cur = DateTime.UnixEpoch.AddMilliseconds(msg.Origin);
|
||||
if (msg.Context.Type is null)
|
||||
continue;
|
||||
Luski.Snowflake sf = Luski.Snowflake.GenerateSnowflake(epoch, cur);
|
||||
LuskiFunctions.Snowflake sf = LuskiFunctions.Snowflake.GenerateSnowflake(epoch, cur);
|
||||
long reply = sf.ID;
|
||||
string body = msg.Context.Body;
|
||||
|
||||
Events.Add(msg.Event, sf.ID);
|
||||
cur = cur.ToLocalTime();
|
||||
bool chanp;
|
||||
long id;
|
||||
if (ChannelProfilesIdList.ContainsKey(msg.Sender))
|
||||
{
|
||||
chanp = true;
|
||||
checkFakeUser(msg.Sender);
|
||||
id = IdConverter[ChannelProfilesIdList[msg.Sender]];
|
||||
}
|
||||
else
|
||||
{
|
||||
chanp = false;
|
||||
id = UserMap[msg.Sender];
|
||||
}
|
||||
|
||||
if (msg.Context.Relations is not null)
|
||||
{
|
||||
if (Events.TryGetValue(msg.Context.Relations.Reply.ID, out long greply)) reply = greply;
|
||||
//Console.WriteLine("Body: {0}", msg.Context.Body);
|
||||
//Console.WriteLine("Fancy Body: {0}", msg.Context.FormattedBody);
|
||||
// string[] ars = msg.Context.FormattedBody.Split('\n');
|
||||
if (msg.Context.FormattedBody is null) body = msg.Context.Body;
|
||||
else body = msg.Context.FormattedBody.Split("</mx-reply>")[^1]
|
||||
.Replace("<br/>", "\n")
|
||||
.Replace("<br>", "\n")
|
||||
.Replace("'", "'")
|
||||
.Replace("'", "'")
|
||||
.Replace("\\", "\\\\")
|
||||
.Replace("[", "\\[");
|
||||
if (body.Contains("could build a better dropdown than Discord"))
|
||||
{
|
||||
Console.WriteLine("break");
|
||||
}
|
||||
|
||||
if (msg.Context.Mentions is not null && msg.Context.Mentions.IDs is not null && msg.Context.Mentions.IDs.Length > 0)
|
||||
{
|
||||
foreach (var i in msg.Context.Mentions.IDs)
|
||||
{
|
||||
string test = "[";
|
||||
if (UserMap.ContainsKey(i))
|
||||
{
|
||||
test += $"@{UserMap[i]}]";
|
||||
}
|
||||
else
|
||||
{
|
||||
checkFakeUser(i);
|
||||
test += $"%{cps[i]}>";
|
||||
}
|
||||
body = body.Replace($"<a href=\"https://matrix.to/#/{i}\"",test);
|
||||
int index = -1;
|
||||
while (true)
|
||||
{
|
||||
index = body.IndexOf(test, index + 1, StringComparison.Ordinal);
|
||||
if (index == -1) break;
|
||||
int index2 = body.IndexOf("</a>", index + 1, StringComparison.Ordinal);
|
||||
body = body.Remove(index + test.Length, index2 + 4 - test.Length - index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body = body.Replace("<p>", "").Replace("</p>", "\n");
|
||||
if (body.EndsWith("\n")) body = body.Remove(body.Length - 1, 1);
|
||||
//body = msg.Context.FormattedBody;
|
||||
Console.WriteLine(body);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (msg.Context.Mentions is not null && msg.Context.Mentions.IDs is not null && msg.Context.Mentions.IDs.Length > 0)
|
||||
{
|
||||
body = msg.Context.FormattedBody!;
|
||||
foreach (var i in msg.Context.Mentions.IDs)
|
||||
{
|
||||
string test = "[";
|
||||
if (UserMap.ContainsKey(i))
|
||||
{
|
||||
test += $"@{UserMap[i]}>";
|
||||
}
|
||||
else
|
||||
{
|
||||
checkFakeUser(i);
|
||||
test += $"%{cps[i]}]";
|
||||
}
|
||||
body = body!.Replace($"<a href=\"https://matrix.to/#/{i}\"",test);
|
||||
int index = -1;
|
||||
while (true)
|
||||
{
|
||||
index = body.IndexOf(test, index + 1, StringComparison.Ordinal);
|
||||
if (index == -1) break;
|
||||
int index2 = body.IndexOf("</a>", index + 1, StringComparison.Ordinal);
|
||||
body = body.Remove(index + test.Length, index2 + 4 - test.Length - index);
|
||||
}
|
||||
}
|
||||
body = body!.Replace("<p>", "").Replace("</p>", "\n");
|
||||
if (body.EndsWith("\n")) body = body.Remove(body.Length - 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
switch (msg.Context.Type)
|
||||
{
|
||||
default:
|
||||
|
||||
Tables.Messages.Insert(
|
||||
Messages.ID.CreateParameter(sf.ID),
|
||||
Messages.Context.CreateParameter(msg.Context.Body.ToDB(Encoder, Encryption)),
|
||||
Messages.Context.CreateParameter(body.ToDB(Encoder, Encryption)),
|
||||
Messages.ChannelID.CreateParameter(Channel),
|
||||
Messages.EncoderType.CreateParameter(Encoder),
|
||||
Messages.Files.CreateParameter(Array.Empty<long>()),
|
||||
Messages.EncryptionKey.CreateParameter(Encryption),
|
||||
Messages.TimeStamp.CreateParameter(sf.Timestamp),
|
||||
Messages.AuthorID.CreateParameter(UserMap[msg.Sender]));
|
||||
Messages.AuthorID.CreateParameter(id),
|
||||
Messages.IsChannelProfile.CreateParameter(chanp),
|
||||
Messages.ReplyTo.CreateParameter(reply));
|
||||
break;
|
||||
case "m.image" or "m.video" or "m.audio" or "m.file":
|
||||
int h = cur.Hour;
|
||||
@ -126,7 +254,7 @@ public static class Matrix
|
||||
Files.EncoderType.CreateParameter(Encoder),
|
||||
Files.EncryptionKey.CreateParameter(Encryption),
|
||||
Files.Hash.CreateParameter(JacobTechEncryption.Encryption.Hashing.SHA256(d)),
|
||||
Files.Owner.CreateParameter(UserMap[msg.Sender]),
|
||||
Files.Owner.CreateParameter(id),
|
||||
Files.AllowedChannels.CreateParameter(new long[] { Channel }),
|
||||
Files.Public.CreateParameter(true),
|
||||
Files.Size.CreateParameter(d.LongLength),
|
||||
@ -139,12 +267,15 @@ public static class Matrix
|
||||
Messages.EncoderType.CreateParameter(Encoder),
|
||||
Messages.Files.CreateParameter(new[] { sf.ID }),
|
||||
Messages.EncryptionKey.CreateParameter(Encryption),
|
||||
Messages.TimeStamp.CreateParameter(sf.Timestamp),
|
||||
Messages.AuthorID.CreateParameter(UserMap[msg.Sender]));
|
||||
Messages.AuthorID.CreateParameter(id),
|
||||
Messages.IsChannelProfile.CreateParameter(chanp),
|
||||
Messages.ReplyTo.CreateParameter(reply));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Tables.Channels.Update(Channels.ID, Channel, Channels.Profiles.CreateParameter(IdConverter.Values.ToArray()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -152,7 +283,6 @@ public static class Matrix
|
||||
if (remove)
|
||||
{
|
||||
Tables.Messages.DeleteRow(Messages.ChannelID.CreateParameter(Channel));
|
||||
Tables.Files.DeleteRow(Files.Channel.CreateParameter(Channel));
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public class Message
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("unsigned")]
|
||||
public Unsigned Unsigned { get; set; } = default!;
|
||||
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(Message))]
|
||||
|
@ -7,7 +7,17 @@ public class MessageContext
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("body")]
|
||||
public string Body { get; set; } = default!;
|
||||
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("formatted_body")]
|
||||
public string? FormattedBody { get; set; } = default!;
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("msgtype")]
|
||||
public string Type { get; set; } = default!;
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("m.mentions")]
|
||||
public Metions? Mentions { get; set; } = default!;
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("m.relates_to")]
|
||||
public ReplyRelation? Relations { get; set; } = default!;
|
||||
}
|
10
LuskiServer/Converters/Matrix/Types/Metion.cs
Normal file
10
LuskiServer/Converters/Matrix/Types/Metion.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LuskiServer.Converters.Matrix.Types;
|
||||
|
||||
public class Metions
|
||||
{
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("user_ids")]
|
||||
public string[]? IDs { get; set; } = default!;
|
||||
}
|
10
LuskiServer/Converters/Matrix/Types/Relation.cs
Normal file
10
LuskiServer/Converters/Matrix/Types/Relation.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LuskiServer.Converters.Matrix.Types;
|
||||
|
||||
public class Relation
|
||||
{
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("event_id")]
|
||||
public string ID { get; set; } = default!;
|
||||
}
|
10
LuskiServer/Converters/Matrix/Types/Relations.cs
Normal file
10
LuskiServer/Converters/Matrix/Types/Relations.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LuskiServer.Converters.Matrix.Types;
|
||||
|
||||
public class Relations
|
||||
{
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("m.relates_to")]
|
||||
public string ID { get; set; } = default!;
|
||||
}
|
10
LuskiServer/Converters/Matrix/Types/ReplyRelation.cs
Normal file
10
LuskiServer/Converters/Matrix/Types/ReplyRelation.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LuskiServer.Converters.Matrix.Types;
|
||||
|
||||
public class ReplyRelation
|
||||
{
|
||||
[JsonInclude]
|
||||
[JsonPropertyName("m.in_reply_to")]
|
||||
public Relation Reply { get; set; } = default!;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace LuskiServer.Enums;
|
||||
|
||||
public enum ChannelType : short
|
||||
{
|
||||
TextAndVoice = 0
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
namespace LuskiServer.Enums;
|
||||
|
||||
public enum ErrorCode
|
||||
{
|
||||
MissingToken,
|
||||
InvalidToken,
|
||||
MissingPostData,
|
||||
InvalidPostData,
|
||||
Forbidden,
|
||||
ServerError,
|
||||
MissingHeader,
|
||||
InvalidHeader,
|
||||
InvalidURL
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
namespace LuskiServer.Enums;
|
||||
|
||||
public enum PictureType : short
|
||||
{
|
||||
none,
|
||||
png,
|
||||
jpeg,
|
||||
bmp,
|
||||
gif,
|
||||
ico,
|
||||
svg,
|
||||
tif,
|
||||
webp
|
||||
}
|
@ -8,7 +8,7 @@ public enum PluginPerms : long
|
||||
{
|
||||
CustomeServerRoleSet = 0b_0000_0001,
|
||||
AddCommands = 0b_0000_0010,
|
||||
[PluginWarning("This permission is considred dangerous. The plugin will have private keys to some channels.")]
|
||||
[PluginWarning("This permission is considered dangerous. The plugin will have private keys to some channels.")]
|
||||
ReadMessages = 0b_0000_0100,
|
||||
SendMessages = 0b_0000_1000,
|
||||
FalseUser = 0b_0001_0000
|
||||
|
@ -1,45 +0,0 @@
|
||||
namespace LuskiServer.Enums;
|
||||
|
||||
public enum ServerPermissions : long
|
||||
{
|
||||
/// <summary>
|
||||
/// Internal permission for quick permission lookup
|
||||
/// </summary>
|
||||
ViewThis,
|
||||
ViewChannels,
|
||||
MoveChannels,
|
||||
EditChannels,
|
||||
EditChannelPermissions,
|
||||
CreateChannels,
|
||||
DeleteChannels,
|
||||
ViewCategories,
|
||||
MoveCategories,
|
||||
EditCategories,
|
||||
EditCategoryPermissions,
|
||||
CreateCategories,
|
||||
DeleteCategories,
|
||||
DeleteKeys,
|
||||
ManageRoles,
|
||||
ViewLogs,
|
||||
ManageServer,
|
||||
AddServers,
|
||||
RemoveServers,
|
||||
Invite,
|
||||
Nickname,
|
||||
ManageNicknames,
|
||||
Kick,
|
||||
Ban,
|
||||
SendMessages,
|
||||
SendFiles,
|
||||
ChannelPings,
|
||||
ServerPings,
|
||||
PingSomeone,
|
||||
ManageMessages,
|
||||
ReadMessageHistory,
|
||||
UseServerCommands,
|
||||
JoinVoice,
|
||||
SpeakInVoice,
|
||||
MuteMembers,
|
||||
DeafenMembers,
|
||||
MoveMembers
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
namespace LuskiServer.Enums;
|
||||
|
||||
public enum Status : short
|
||||
{
|
||||
Offline,
|
||||
Online,
|
||||
Idle,
|
||||
DoNotDisturb,
|
||||
Invisible,
|
||||
MAX
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IncludeBuildOutput>true</IncludeBuildOutput>
|
||||
<FileVersion>1.0.08</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
@ -20,11 +21,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.0.0" />
|
||||
<PackageReference Include="JacobTechEncryption" Version="1.0.2" />
|
||||
<PackageReference Include="Luski.Shared" Version="1.1.0-alpha19" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
|
||||
<PackageReference Include="ServerDatabase" Version="2.8.9" />
|
||||
<PackageReference Include="ServerDatabase.SourceGenerator" Version="1.0.2-alpha09" />
|
||||
<PackageReference Include="ServerDatabase" Version="2.9.9" />
|
||||
<PackageReference Include="ServerDatabase.SourceGenerator" Version="1.0.2-alpha10" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
|
||||
<PackageReference Include="websocketsharp.core" Version="1.0.0" />
|
||||
|
@ -1,17 +1,14 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices.JavaScript;
|
||||
using System.Text;
|
||||
using Asp.Versioning;
|
||||
using Asp.Versioning.ApiExplorer;
|
||||
using JacobTechEncryption;
|
||||
using JacobTechEncryption.Enums;
|
||||
using Luski.Shared.PublicServers.V1.Enums;
|
||||
using Luski.Shared.PublicServers.V1.ServerToClient.HTTP;
|
||||
using LuskiServer;
|
||||
using LuskiServer.Classes;
|
||||
using LuskiServer.Classes.ServerComs;
|
||||
using LuskiServer.Classes.TableDef;
|
||||
using LuskiServer.Converters.Matrix;
|
||||
using LuskiServer.Converters.Matrix.Types;
|
||||
using LuskiServer.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ServerDatabase;
|
||||
@ -20,13 +17,25 @@ using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
[assembly: Microsoft.AspNetCore.Mvc.ApiController]
|
||||
|
||||
Luski.Config = Luski.GetSettings("/etc/luskiserver/app.json", AppConfigContext.Default.AppConfig, true);
|
||||
Console.WriteLine($"Server starting with starting epoch of {Luski.Config.ServerEpoch.ToLocalTime()} and current time of {DateTime.UtcNow.ToLocalTime()}");
|
||||
Luski.Database = new Database(Luski.Config.Address,
|
||||
Luski.Config.Database,
|
||||
Luski.Config.Username,
|
||||
Luski.Config.Password,
|
||||
Luski.Config.CustomeName);
|
||||
LuskiFunctions.Config = LuskiServer.Classes.LuskiFunctions.GetSettings("/etc/luskiserver/app.json", AppConfigContext.Default.AppConfig, true);
|
||||
List<string> tttt = args.ToList();
|
||||
if (tttt.Contains("--urls"))
|
||||
{
|
||||
tttt[tttt.IndexOf("--urls") + 1] = string.Join(";", LuskiFunctions.Config.Addresses);
|
||||
}
|
||||
else
|
||||
{
|
||||
tttt.Add("--urls");
|
||||
tttt.Add(string.Join(";", LuskiFunctions.Config.Addresses));
|
||||
}
|
||||
|
||||
args = tttt.ToArray();
|
||||
Console.WriteLine($"Server starting with starting epoch of {LuskiFunctions.Config.ServerEpoch.ToLocalTime()} and current time of {DateTime.UtcNow.ToLocalTime()}");
|
||||
LuskiFunctions.Database = new Database(LuskiFunctions.Config.Address,
|
||||
LuskiFunctions.Config.Database,
|
||||
LuskiFunctions.Config.Username,
|
||||
LuskiFunctions.Config.Password,
|
||||
LuskiFunctions.Config.CustomeName);
|
||||
|
||||
|
||||
Dictionary<string, List<Message>> fff = new();
|
||||
@ -34,7 +43,7 @@ Dictionary<string, List<Message>> fff = new();
|
||||
|
||||
try
|
||||
{
|
||||
Luski.Database.ExecuteNonQuery($"CREATE DATABASE {Luski.Config.Database} WITH OWNER = {Luski.Config.Username} ENCODING = 'UTF8' CONNECTION LIMIT = -1 IS_TEMPLATE = False;");
|
||||
LuskiFunctions.Database.ExecuteNonQuery($"CREATE DATABASE {LuskiFunctions.Config.Database} WITH OWNER = {LuskiFunctions.Config.Username} ENCODING = 'UTF8' CONNECTION LIMIT = -1 IS_TEMPLATE = False;");
|
||||
Console.WriteLine("Database Created");
|
||||
}
|
||||
catch
|
||||
@ -44,35 +53,73 @@ catch
|
||||
|
||||
foreach (PropertyInfo prop in typeof(Tables).GetProperties())
|
||||
{
|
||||
ITable table = (ITable)prop.GetValue(null)!;
|
||||
table.DatabaseHandler = Luski.Database;
|
||||
IBetterTable table = (IBetterTable)prop.GetValue(null)!;
|
||||
table.DatabaseHandler = LuskiFunctions.Database;
|
||||
Type t = Type.GetType($"LuskiServer.Classes.TableDef.{prop.Name}")!;
|
||||
foreach(PropertyInfo prop2 in t.GetProperties())
|
||||
{
|
||||
table.AddColumn((ITableColumn)prop2.GetValue(null)!, prop2.Name);
|
||||
}
|
||||
Luski.Database.Tables.Add(table);
|
||||
LuskiFunctions.Database.Tables.Add(table);
|
||||
}
|
||||
|
||||
Luski.Database.RegisterTables();
|
||||
LuskiFunctions.Database.RegisterTables();
|
||||
|
||||
bool d = Tables.Storage.TryReadRow(out StorageRow row, Storage.ID.CreateParameter(534144618594309));
|
||||
Console.WriteLine(d);
|
||||
//Tables.Channels.Update(Channels.ID, 0, Channels.PictureType.CreateParameter(PictureType.png), Channels.Picture.CreateParameter(File.ReadAllBytes("/home/jacob/Pictures/Logo.png")));
|
||||
/*
|
||||
Dictionary<string, long> AMap = new()
|
||||
{
|
||||
{"@jacobtech:matrix.org", 0},
|
||||
{"@rqndomnezz:matrix.org", 0},
|
||||
{"@ardillybar:matrix.org", 0},
|
||||
{"@themagicalcats:matrix.org", 0},
|
||||
{"@jobotnik:matrix.org", 0},
|
||||
{"@captainleader:matrix.org", 0},
|
||||
{"@kaizenash:matrix.org", 0},
|
||||
{"@bubs_cooper:matrix.org", 0},
|
||||
{"@quadro:matrix.org", 0},
|
||||
{"@tcll:matrix.org", 0},
|
||||
{"@eeetile:matrix.org", 0},
|
||||
{"@etile:matrix.org", 0},
|
||||
{"@tranquillity_:midov.pl", 0}
|
||||
{"@jacobtech:matrix.org", 0}
|
||||
};
|
||||
//Matrix.ZipJsonChatExpot(File.OpenRead("/home/jacob/Downloads/matrix - Luski Project Discussion - Chat Export - 2023-08-08T20-10-12.315Z.zip"), 0, AMap, new(), EncoderType.UTF16, 0);
|
||||
|
||||
Dictionary<string, int> BMap = new()
|
||||
{
|
||||
{"@rqndomnezz:matrix.org",0},
|
||||
{"@ardillybar:matrix.org", 1},
|
||||
{"@themagicalcats:matrix.org", 2},
|
||||
{"@c4tz:matrix.org", 2},
|
||||
{"@jobotnik:matrix.org", 3},
|
||||
{"@captainleader:matrix.org", 4},
|
||||
{"@kaizenash:matrix.org", 4},
|
||||
{"@bubs_cooper:matrix.org", 5},
|
||||
{"@quadro:matrix.org", 6},
|
||||
{"@tcll:matrix.org", 7},
|
||||
{"@eeetile:matrix.org", 8},
|
||||
{"@etile:matrix.org", 8},
|
||||
{"@tranquillity_:midov.pl", 9},
|
||||
{"@troler:asra.gr", 10},
|
||||
{"@xnq:matrix.org", 11},
|
||||
{"@jacobtech-bot:matrix.org", 12}
|
||||
};
|
||||
|
||||
List<Tuple<string, byte[], PictureType, byte[]>> BMapL = new()
|
||||
{
|
||||
new("Rqndomnezz", File.ReadAllBytes("/home/jacob/Downloads/2023-01-20_23-29.png"), PictureType.png, new byte[] { 161, 196, 248, 255 }),
|
||||
new("ardillybar", File.ReadAllBytes("/home/jacob/Downloads/a.jpeg"), PictureType.jpeg, new byte[] { 255, 168, 188, 255 }),
|
||||
new("Cats", File.ReadAllBytes("/home/jacob/Downloads/c.png"), PictureType.png, new byte[] { 114, 213, 174, 255 }),
|
||||
new("jobotnik", File.ReadAllBytes("/home/jacob/Downloads/j.png"), PictureType.png, new byte[] { 161, 196, 248, 255 }),
|
||||
new("Kyron Saif", File.ReadAllBytes("/home/jacob/Downloads/k.png"), PictureType.png, new byte[] { 114, 213, 174, 255 }),
|
||||
new("Lucky Black", File.ReadAllBytes("/home/jacob/Downloads/b.png"), PictureType.png, new byte[] { 161, 196, 248, 255 }),
|
||||
new("quadro", Array.Empty<byte>(), PictureType.none, new byte[] { 229, 177, 233, 255 }),
|
||||
new("DarkPikachu", File.ReadAllBytes("/home/jacob/Downloads/tc.png"), PictureType.png, new byte[] { 181, 132, 95, 255 }),
|
||||
new("etile", Array.Empty<byte>(), PictureType.none, new byte[] { 181, 132, 95, 255 }),
|
||||
new("tranquillity", Array.Empty<byte>(), PictureType.none, new byte[] { 161, 196, 248, 255 }),
|
||||
new("Troler", File.ReadAllBytes("/home/jacob/Downloads/tr.png"), PictureType.png, new byte[] { 161, 196, 248, 255 }),
|
||||
new("xnq", File.ReadAllBytes("/home/jacob/Downloads/x.png"), PictureType.png, new byte[] { 161, 196, 248, 255 }),
|
||||
new("JacobTech Bot", Array.Empty<byte>(), PictureType.none, new byte[] { 114, 213, 174, 255 })
|
||||
};
|
||||
*/
|
||||
|
||||
//
|
||||
//Matrix.ZipJsonChatExport(File.OpenRead("/run/media/jacob/F69D-7CBA/Matrix Keys/l.zip"), 0, AMap, BMap, BMapL, new(), EncoderType.UTF16, 0);
|
||||
//Matrix.ZipJsonChatExport(File.OpenRead("/home/jacob/Downloads/matrix - Luski Project Discussion - Chat Export - 2023-08-08T20-10-12.315Z.zip"), 0, AMap, BMap, BMapL, new(), EncoderType.UTF16, 0);
|
||||
//
|
||||
//Tables.Channels.Update(Channels.ID, 0, ">=", Channels.Color.CreateDefaultParameter());
|
||||
//Tables.Categories.Update(Categories.ID, 0, ">=", Categories.Color.CreateDefaultParameter());
|
||||
|
||||
//Console.WriteLine(Convert.ToHexString(Tables.Channels.Read(Channels.Color, Channels.ID.CreateParameter(3))));
|
||||
|
||||
if (!Tables.Server.TryRead(Server.ID, out _, Server.ID.CreateParameter(0)))
|
||||
{
|
||||
@ -149,45 +196,49 @@ Tables.Categories.Insert(
|
||||
Categories.RoleOverides.CreateParameter(Array.Empty<long>())
|
||||
);
|
||||
*/
|
||||
if (!Luski.Database.VersionsTable.TryRead(Luski.Database.VersionsTable.ID, out _,
|
||||
Luski.Database.VersionsTable.ID.CreateParameter(0)))
|
||||
if (!LuskiFunctions.Database.VersionsTable.TryRead(LuskiFunctions.Database.VersionsTable.ID, out _,
|
||||
LuskiFunctions.Database.VersionsTable.ID.CreateParameter(0)))
|
||||
{
|
||||
Luski.Database.VersionsTable.Insert(Luski.Database.VersionsTable.ID.CreateParameter(0));
|
||||
LuskiFunctions.Database.VersionsTable.Insert(LuskiFunctions.Database.VersionsTable.ID.CreateParameter(0));
|
||||
}
|
||||
|
||||
//Tables.Roles.Update(Roles.ID, 1, Roles.Color.CreateParameter(new byte[]{1,143,243,255}));
|
||||
|
||||
/*
|
||||
Tables.Roles.Insert(
|
||||
Roles.ID.CreateParameter(1),
|
||||
Roles.Name.CreateParameter("Mod"),
|
||||
Roles.DisplayName.CreateParameter("Moderators"),
|
||||
Roles.Color.CreateParameter("56,155,32,255"),
|
||||
Roles.Color.CreateDefaultParameter(),
|
||||
Roles.Description.CreateParameter("Mods for the server"),
|
||||
Roles.ServerPermissions.CreateParameter(new[]
|
||||
Roles.ServerPermission.CreateParameter(new[]
|
||||
{
|
||||
ServerPermissions.ViewChannels,
|
||||
ServerPermissions.ViewCategories,
|
||||
ServerPermissions.Nickname,
|
||||
ServerPermissions.SendMessages,
|
||||
ServerPermissions.SendFiles,
|
||||
ServerPermissions.ChannelAndServerPings,
|
||||
ServerPermissions.PingSomeone,
|
||||
ServerPermissions.ReadMessageHistory,
|
||||
ServerPermissions.UseServerCommands,
|
||||
ServerPermissions.JoinVoice,
|
||||
ServerPermissions.SpeakInVoice,
|
||||
ServerPermissions.ViewThis,
|
||||
ServerPermissions.Kick,
|
||||
ServerPermissions.CreateCategories,
|
||||
ServerPermissions.CreateChannels,
|
||||
ServerPermissions.DeleteCategories,
|
||||
ServerPermissions.DeleteChannels,
|
||||
ServerPermissions.EditCategories,
|
||||
ServerPermissions.EditChannels,
|
||||
ServerPermissions.EditCategoryPermissions,
|
||||
ServerPermissions.EditChannelPermissions,
|
||||
ServerPermissions.Invite,
|
||||
ServerPermissions.ManageMessages,
|
||||
ServerPermissions.ManageRoles,
|
||||
ServerPermissions.ViewLogs
|
||||
ServerPermission.ViewChannels,
|
||||
ServerPermission.ViewCategories,
|
||||
ServerPermission.Nickname,
|
||||
ServerPermission.SendMessages,
|
||||
ServerPermission.SendFiles,
|
||||
ServerPermission.ChannelPings,
|
||||
ServerPermission.ServerPings,
|
||||
ServerPermission.PingSomeone,
|
||||
ServerPermission.ReadMessageHistory,
|
||||
ServerPermission.UseServerCommands,
|
||||
ServerPermission.JoinVoice,
|
||||
ServerPermission.SpeakInVoice,
|
||||
ServerPermission.ViewThis,
|
||||
ServerPermission.Kick,
|
||||
ServerPermission.CreateCategories,
|
||||
ServerPermission.CreateChannels,
|
||||
ServerPermission.DeleteCategories,
|
||||
ServerPermission.DeleteChannels,
|
||||
ServerPermission.EditCategories,
|
||||
ServerPermission.EditChannels,
|
||||
ServerPermission.EditCategoryPermissions,
|
||||
ServerPermission.EditChannelPermissions,
|
||||
ServerPermission.Invite,
|
||||
ServerPermission.ManageMessages,
|
||||
ServerPermission.ManageRoles,
|
||||
ServerPermission.ViewLogs
|
||||
})
|
||||
);
|
||||
*/
|
||||
@ -198,24 +249,22 @@ if (!Tables.Roles.TryRead(Roles.ID, out _, Roles.ID.CreateParameter(0)))
|
||||
Roles.ID.CreateParameter(0),
|
||||
Roles.Name.CreateParameter("server"),
|
||||
Roles.DisplayName.CreateParameter("Members"),
|
||||
Roles.Color.CreateParameter("ÿÿÿÿ"),
|
||||
Roles.Color.CreateDefaultParameter(),
|
||||
Roles.Description.CreateParameter("The default role for the server. Everybody will have this role."),
|
||||
Roles.ServerPermissions.CreateParameter(new[]
|
||||
{
|
||||
ServerPermissions.ViewChannels,
|
||||
ServerPermissions.ViewCategories,
|
||||
ServerPermissions.Nickname,
|
||||
ServerPermissions.SendMessages,
|
||||
ServerPermissions.SendFiles,
|
||||
ServerPermissions.ChannelPings,
|
||||
ServerPermissions.ServerPings,
|
||||
ServerPermissions.PingSomeone,
|
||||
ServerPermissions.ReadMessageHistory,
|
||||
ServerPermissions.UseServerCommands,
|
||||
ServerPermissions.JoinVoice,
|
||||
ServerPermissions.SpeakInVoice,
|
||||
ServerPermissions.ViewThis
|
||||
})
|
||||
Roles.ServerPermissions.CreateParameter(
|
||||
ServerPermission.ViewChannels |
|
||||
ServerPermission.ViewCategories |
|
||||
ServerPermission.Nickname |
|
||||
ServerPermission.SendMessages |
|
||||
ServerPermission.SendFiles |
|
||||
ServerPermission.ChannelPings |
|
||||
ServerPermission.ServerPings |
|
||||
ServerPermission.PingSomeone |
|
||||
ServerPermission.ReadMessageHistory |
|
||||
ServerPermission.UseServerCommands |
|
||||
ServerPermission.JoinVoice |
|
||||
ServerPermission.SpeakInVoice |
|
||||
ServerPermission.ViewThis)
|
||||
);
|
||||
}
|
||||
|
||||
@ -233,17 +282,18 @@ if (!Tables.Categories.TryRead(Categories.ID, out _, Categories.ID.CreateParamet
|
||||
Categories.ID.CreateParameter(0),
|
||||
Categories.Name.CreateParameter(Encoding.UTF8.GetBytes("server")),
|
||||
Categories.Parent.CreateParameter(-1),
|
||||
Categories.Channels.CreateParameter(new long[]{0}),
|
||||
Categories.Description.CreateParameter(
|
||||
Encoding.UTF8.GetBytes("The default category for the server. Everybody will see this category.")),
|
||||
Categories.RoleOverides.CreateParameter(Array.Empty<long>())
|
||||
Categories.RoleOverrides.CreateParameter(Array.Empty<long>())
|
||||
);
|
||||
Tables.Channels.Insert(
|
||||
Channels.ID.CreateParameter(0),
|
||||
Channels.Type.CreateParameter(ChannelType.TextAndVoice),
|
||||
Channels.Description.CreateParameter(Encoding.UTF8.GetBytes("Default chat for you to use in your new server")),
|
||||
Channels.Name.CreateParameter(Encoding.UTF8.GetBytes("Default Channel")),
|
||||
Channels.RoleOverides.CreateParameter(Array.Empty<long>()),
|
||||
Channels.UserOverides.CreateParameter(Array.Empty<long>()),
|
||||
Channels.RoleOverrides.CreateParameter(Array.Empty<long>()),
|
||||
Channels.UserOverrides.CreateParameter(Array.Empty<long>()),
|
||||
Channels.Epoch.CreateParameter(DateTime.UtcNow.Date),
|
||||
Channels.TitleEncryptionKey.CreateParameter(0),
|
||||
Channels.Parent.CreateParameter(0),
|
||||
@ -256,6 +306,14 @@ if (!Tables.Categories.TryRead(Categories.ID, out _, Categories.ID.CreateParamet
|
||||
Channels.EncoderTypes.CreateParameter(new [] { EncoderType.UTF8 }));
|
||||
}
|
||||
|
||||
long[] keys = Tables.Sessions.ReadColumn(Sessions.SessionKey);
|
||||
foreach (long key in keys)
|
||||
{
|
||||
Tables.Keys.DeleteRow(Keys.ID.CreateParameter(key));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Tables.Sessions.DeleteRows();
|
||||
|
||||
|
||||
@ -264,7 +322,7 @@ foreach (AltServerRow Server in Tables.AltServers.ReadRows())
|
||||
//TODO add code to open a live WSS connection with all other servers on the network
|
||||
}
|
||||
|
||||
WSS.Init(Luski.Config.IPv4WSS, Luski.Config.IPv4PortWSS, Luski.Config.IPv4_URL_WSS!, Luski.Config.IPv4SecureWSS, Luski.Config.IPv6WSS, Luski.Config.IPv6_URL_WSS, Luski.Config.IPv6PortWSS, Luski.Config.IPv6SecureWSS);
|
||||
WSS.Init(LuskiFunctions.Config.IPv4WSS, LuskiFunctions.Config.IPv4PortWSS, LuskiFunctions.Config.IPv4_URL_WSS!, LuskiFunctions.Config.IPv4SecureWSS, LuskiFunctions.Config.IPv6WSS, LuskiFunctions.Config.IPv6_URL_WSS, LuskiFunctions.Config.IPv6PortWSS, LuskiFunctions.Config.IPv6SecureWSS);
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder( args );
|
||||
|
||||
@ -310,18 +368,18 @@ builder.Services.Configure<ApiBehaviorOptions>(options =>
|
||||
content = reader.ReadToEndAsync().Result;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(content)) return new ObjectResult(new HTTPResponse()
|
||||
if (string.IsNullOrEmpty(content)) return new ObjectResult(new STC()
|
||||
{
|
||||
error = ErrorCode.MissingPostData,
|
||||
error_message = "The post information was missing"
|
||||
Error = ErrorCode.MissingPostData,
|
||||
ErrorMessage = "The post information was missing"
|
||||
})
|
||||
{
|
||||
StatusCode = 403
|
||||
};
|
||||
return new ObjectResult(new HTTPResponse()
|
||||
return new ObjectResult(new STC()
|
||||
{
|
||||
error = ErrorCode.InvalidPostData,
|
||||
error_message = "The provided post information was invalid"
|
||||
Error = ErrorCode.InvalidPostData,
|
||||
ErrorMessage = "The provided post information was invalid"
|
||||
})
|
||||
{
|
||||
StatusCode = 403
|
||||
|
Loading…
Reference in New Issue
Block a user