-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 修复了一些安全性的问题 2. 修复了初始化时fixed_properties表中无属性设定数据的bug
- Loading branch information
1 parent
d9de81b
commit e6b9dc6
Showing
25 changed files
with
225 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,46 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using MySql.Data.MySqlClient; | ||
using Team123it.Arcaea.MarveCube.Controllers; | ||
using Team123it.Arcaea.MarveCube.Core; | ||
using static Team123it.Arcaea.MarveCube.GlobalProperties; | ||
|
||
|
||
namespace Team123it.Arcaea.MarveCube.Bots | ||
{ | ||
public static class Background | ||
{ | ||
/// <summary> | ||
/// 检查Apikey的有效性。 | ||
/// </summary> | ||
/// <exception cref="BotAPIException" /> | ||
public static void CheckApiKey(string apikey) | ||
{ | ||
var conn = new MySqlConnection(DatabaseConnectURL); | ||
try | ||
{ | ||
conn.Open(); | ||
var cmd = conn.CreateCommand(); | ||
cmd.CommandText = "SELECT COUNT(*),is_banned FROM bots WHERE apikey=?apikey;"; | ||
cmd.Parameters.Add(new MySqlParameter("?apikey", apikey)); | ||
var rd = cmd.ExecuteReader(); | ||
rd.Read(); | ||
if (rd.GetInt32(0) == 1) | ||
{ | ||
if (rd.GetBoolean(1)) | ||
{ | ||
throw new BotAPIException(BotAPIException.APIExceptionType.BotIsBlocked,null); | ||
} | ||
} | ||
else | ||
{ | ||
throw new BotAPIException(BotAPIException.APIExceptionType.InvalidApiKey,null); | ||
} | ||
} | ||
catch (BotAPIException) | ||
{ | ||
throw; | ||
} | ||
finally | ||
{ | ||
conn.Close(); | ||
} | ||
} | ||
|
||
public static bool IsSafeArgument(this HttpRequest req) | ||
{ | ||
foreach (var queryStr in req.Query) | ||
{ | ||
if (!BotController.IsSafeArgument(queryStr.Key)) return false; | ||
if (!BotController.IsSafeArgument(queryStr.Value)) return false; | ||
continue; | ||
} | ||
return true; | ||
} | ||
} | ||
public static class Background | ||
{ | ||
/// <summary> | ||
/// 检查Apikey的有效性。 | ||
/// </summary> | ||
/// <exception cref="BotAPIException" /> | ||
public static void CheckApiKey(string apikey) | ||
{ | ||
var conn = new MySqlConnection(DatabaseConnectURL); | ||
try | ||
{ | ||
conn.Open(); | ||
var cmd = conn.CreateCommand(); | ||
cmd.CommandText = "SELECT COUNT(*),is_banned FROM bots WHERE apikey=?apikey;"; | ||
cmd.Parameters.Add(new MySqlParameter("?apikey", apikey)); | ||
var rd = cmd.ExecuteReader(); | ||
rd.Read(); | ||
if (rd.GetInt32(0) == 1) | ||
{ | ||
if (rd.GetBoolean(1)) | ||
{ | ||
throw new BotAPIException(BotAPIException.APIExceptionType.BotIsBlocked,null); | ||
} | ||
} | ||
else | ||
{ | ||
throw new BotAPIException(BotAPIException.APIExceptionType.InvalidApiKey,null); | ||
} | ||
} | ||
catch (BotAPIException) | ||
{ | ||
throw; | ||
} | ||
finally | ||
{ | ||
conn.Close(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.