205 lines
5.3 KiB
Plaintext
205 lines
5.3 KiB
Plaintext
<!-- #include virtual = "lib/config.asp" -->
|
|
<%
|
|
Response.Buffer = True
|
|
Response.ContentType = "application/json"
|
|
Response.Charset = "utf-8"
|
|
|
|
Response.AddHeader "Access-Control-Allow-Origin", "*"
|
|
Response.AddHeader "Access-Control-Allow-Methods", "GET, POST, OPTIONS"
|
|
Response.AddHeader "Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With"
|
|
Response.AddHeader "Access-Control-Max-Age", "86400"
|
|
|
|
If Request.ServerVariables("REQUEST_METHOD") = "OPTIONS" Then
|
|
Response.Status = "200 OK"
|
|
Response.End
|
|
End If
|
|
|
|
|
|
Dim remoteIp
|
|
Dim clientId
|
|
Dim requestMethod
|
|
Dim cmd
|
|
Dim rs
|
|
Dim returnString
|
|
|
|
remoteIp = Trim(Request.ServerVariables("REMOTE_ADDR"))
|
|
clientId = Trim(Request("clientId"))
|
|
requestMethod = UCase(Request.ServerVariables("REQUEST_METHOD"))
|
|
|
|
|
|
' ============================================================
|
|
' POST : clientId에 현재 접속 IP 할당(위험성이 있어 제외)
|
|
' ============================================================
|
|
'If requestMethod = "POST" Then
|
|
'
|
|
' If clientId = "" Then
|
|
' Response.Status = "400 Bad Request"
|
|
' Response.Write "{""success"":false,""message"":""clientId가 필요합니다.""}"
|
|
' Response.End
|
|
' End If
|
|
'
|
|
'
|
|
' On Error Resume Next
|
|
'
|
|
' adoconn.BeginTrans
|
|
'
|
|
'
|
|
' ' --------------------------------------------------------
|
|
' ' 1. 현재 IP가 이미 다른 client에 할당되어 있다면 해제
|
|
' ' --------------------------------------------------------
|
|
' Set cmd = Server.CreateObject("ADODB.Command")
|
|
'
|
|
' With cmd
|
|
' .ActiveConnection = adoconn
|
|
' .CommandType = 1 ' adCmdText
|
|
'
|
|
' .CommandText = _
|
|
' "UPDATE [new_cati].[dbo].[client] " & _
|
|
' "SET [client_ip] = NULL " & _
|
|
' "WHERE [client_ip] = ? " & _
|
|
' "AND [client_id] <> ?"
|
|
'
|
|
' .Parameters.Append .CreateParameter("@clientIp", 200, 1, 50, remoteIp)
|
|
' .Parameters.Append .CreateParameter("@clientId", 200, 1, 50, clientId)
|
|
'
|
|
' .Execute
|
|
' End With
|
|
'
|
|
' Set cmd = Nothing
|
|
'
|
|
'
|
|
' If Err.Number <> 0 Then
|
|
' adoconn.RollbackTrans
|
|
'
|
|
' Response.Status = "500 Internal Server Error"
|
|
' Response.Write _
|
|
' "{""success"":false,""message"":""기존 IP 해제 중 오류가 발생했습니다.""}"
|
|
'
|
|
' Response.End
|
|
' End If
|
|
'
|
|
'
|
|
' ' --------------------------------------------------------
|
|
' ' 2. 전달받은 clientId에 현재 IP 할당
|
|
' ' --------------------------------------------------------
|
|
' Set cmd = Server.CreateObject("ADODB.Command")
|
|
'
|
|
' With cmd
|
|
' .ActiveConnection = adoconn
|
|
' .CommandType = 1
|
|
'
|
|
' .CommandText = _
|
|
' "UPDATE [new_cati].[dbo].[client] " & _
|
|
' "SET [client_ip] = ? " & _
|
|
' "WHERE [client_id] = ?"
|
|
'
|
|
' .Parameters.Append .CreateParameter("@clientIp", 200, 1, 50, remoteIp)
|
|
' .Parameters.Append .CreateParameter("@clientId", 200, 1, 50, clientId)
|
|
'
|
|
' .Execute
|
|
' End With
|
|
'
|
|
' Set cmd = Nothing
|
|
'
|
|
'
|
|
' If Err.Number <> 0 Then
|
|
' adoconn.RollbackTrans
|
|
'
|
|
' Response.Status = "500 Internal Server Error"
|
|
' Response.Write _
|
|
' "{""success"":false,""message"":""IP 할당 중 오류가 발생했습니다.""}"
|
|
'
|
|
' Response.End
|
|
' End If
|
|
'
|
|
'
|
|
' adoconn.CommitTrans
|
|
'
|
|
' On Error GoTo 0
|
|
'
|
|
'End If
|
|
|
|
|
|
' ============================================================
|
|
' GET / POST 공통
|
|
' 현재 IP에 연결된 client 조회
|
|
' ============================================================
|
|
|
|
Set cmd = Server.CreateObject("ADODB.Command")
|
|
|
|
With cmd
|
|
.ActiveConnection = adoconn
|
|
.CommandType = 1
|
|
|
|
.CommandText = _
|
|
"SELECT " & _
|
|
" [client_id], " & _
|
|
" [internal_no], " & _
|
|
" [external_no], " & _
|
|
" [client_ip] " & _
|
|
"FROM [new_cati].[dbo].[client] WITH(NOLOCK) " & _
|
|
"WHERE [client_ip] = ?"
|
|
|
|
.Parameters.Append .CreateParameter("@clientIp", 200, 1, 50, remoteIp)
|
|
|
|
Set rs = .Execute
|
|
End With
|
|
|
|
|
|
If Not rs.EOF Then
|
|
|
|
returnString = "{"
|
|
returnString = returnString & """success"":true,"
|
|
returnString = returnString & """clientId"":""" & JsonEscape(rs("client_id")) & ""","
|
|
returnString = returnString & """internalNo"":""" & JsonEscape(rs("internal_no")) & ""","
|
|
returnString = returnString & """externalNo"":""" & JsonEscape(rs("external_no")) & ""","
|
|
returnString = returnString & """clientIp"":""" & JsonEscape(rs("client_ip")) & """"
|
|
returnString = returnString & "}"
|
|
|
|
Else
|
|
|
|
returnString = "{"
|
|
returnString = returnString & """success"":true,"
|
|
returnString = returnString & """clientId"":"""","
|
|
returnString = returnString & """internalNo"":"""","
|
|
returnString = returnString & """externalNo"":"""","
|
|
returnString = returnString & """clientIp"":""" & remoteIp & """"
|
|
returnString = returnString & "}"
|
|
|
|
End If
|
|
|
|
|
|
rs.Close
|
|
Set rs = Nothing
|
|
Set cmd = Nothing
|
|
|
|
Response.Write returnString
|
|
Response.End
|
|
|
|
|
|
|
|
' ============================================================
|
|
' JSON 문자열 Escape
|
|
' ============================================================
|
|
Function JsonEscape(value)
|
|
|
|
Dim str
|
|
|
|
If IsNull(value) Then
|
|
JsonEscape = ""
|
|
Exit Function
|
|
End If
|
|
|
|
str = CStr(value)
|
|
|
|
str = Replace(str, "\", "\\")
|
|
str = Replace(str, """", "\""")
|
|
str = Replace(str, vbCrLf, "\n")
|
|
str = Replace(str, vbCr, "\n")
|
|
str = Replace(str, vbLf, "\n")
|
|
str = Replace(str, vbTab, "\t")
|
|
|
|
JsonEscape = str
|
|
|
|
End Function
|
|
%> |