125 lines
4.3 KiB
C#
125 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Runtime.Serialization.Json;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Web.Services.Protocols;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Web.SessionState;
|
|
using System.Data;
|
|
using System.IO.Compression;
|
|
using System.Data.SqlClient;
|
|
using Dapper;
|
|
using Dapper.Contrib.Extensions;
|
|
|
|
namespace abbott_2024_event.BackEnd.api
|
|
{
|
|
/// <summary>
|
|
/// ipList 的摘要描述
|
|
/// </summary>
|
|
public class ipList : IHttpHandler, IReadOnlySessionState
|
|
{
|
|
SqlConnection conn = new SqlConnection(globalClass.appsettings("DBConnectionString"));
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
result objRet = new result();
|
|
DataContractJsonSerializer json = new DataContractJsonSerializer(objRet.GetType());
|
|
context.Response.ContentType = "application/json;charset=utf-8";
|
|
context.Response.AddHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
string acceptEncoding = context.Request.Headers["Accept-Encoding"].ToString().ToUpperInvariant();
|
|
if (!String.IsNullOrEmpty(acceptEncoding))
|
|
{
|
|
if (acceptEncoding.Contains("GZIP"))
|
|
{
|
|
//输出流头部GZIP压缩
|
|
context.Response.AppendHeader("Content-encoding", "gzip");
|
|
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
|
|
}
|
|
else if (acceptEncoding.Contains("DEFLATE"))
|
|
{
|
|
//输出流头部DEFLATE压缩
|
|
context.Response.AppendHeader("Content-encoding", "deflate");
|
|
context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress);
|
|
}
|
|
}
|
|
|
|
authToken objAuth = new authToken();
|
|
|
|
string allowAnyIP = (context.Request["allow"] == null) ? "" : context.Request["allow"].ToString();
|
|
string iplist = (context.Request["iplist"] == null) ? "[]" : context.Request["iplist"].ToString();
|
|
string method = (context.Request["method"] == null) ? "" : context.Request["method"].ToString();
|
|
|
|
if (!objAuth.user_isLogin)
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0001";
|
|
objRet.message = "尚未登入,請登入後使用";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
if (method == "")
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0003";
|
|
objRet.message = "無method";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
if (method == "get") {
|
|
List<ipTable> ipTables = conn.Query<ipTable>("select * from ipTable").ToList();
|
|
|
|
foreach (ipTable ipTable in ipTables) {
|
|
objRet.ipList.Add(ipTable.ipTable_address);
|
|
}
|
|
objRet.ret = "yes";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
if (method == "edit") {
|
|
dynamic ipJsonObj;
|
|
|
|
ipJsonObj = JValue.Parse(iplist);
|
|
|
|
conn.Execute("delete ipTable");
|
|
|
|
foreach (string item in ipJsonObj)
|
|
{
|
|
if (item != "") {
|
|
ipTable newIp = new ipTable();
|
|
newIp.ipTable_address = item;
|
|
newIp.ipTable_create_user_uid = "admin";
|
|
conn.Insert<ipTable>(newIp);
|
|
}
|
|
}
|
|
|
|
objRet.ret = "yes";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
}
|
|
|
|
public class result
|
|
{
|
|
public string ret = "no";
|
|
public string err_code = "0000";
|
|
public string message = "";
|
|
public string allowAnyIP = "N";
|
|
public List<string> ipList = new List<string>();
|
|
}
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |