diff --git a/new-contact-api.asp b/new-contact-api.asp new file mode 100644 index 0000000..d38cae8 --- /dev/null +++ b/new-contact-api.asp @@ -0,0 +1,205 @@ + +<% +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 +%> \ No newline at end of file diff --git a/new-contact-get-info.asp b/new-contact-get-info.asp deleted file mode 100644 index 1781c12..0000000 --- a/new-contact-get-info.asp +++ /dev/null @@ -1,49 +0,0 @@ - -<% -Response.Buffer = True - -Response.AddHeader "Access-Control-Allow-Origin", "*" -Response.AddHeader "Access-Control-Allow-Methods", "*" -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.Write "" - Response.End -End If -%> -<% - ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''20260428 박준성''''''''''''''''''''''''''''''''''''''''''''''''''''''''' - '''''''''''''''''''''''''''New Contact에서 인트라넷을 통해 내부 IP를 통해 사용할 내선번호를 들고오기 위한 Page''''''''''''''''''''''''''' - dim remoteIp : remoteIp = Request.ServerVariables("REMOTE_ADDR") - dim query : query = "" - dim returnString : returnString = "" - - query = query & " SELECT [client_id], [internal_no], [external_no], [client_ip] " & VbCrlf - query = query & " FROM [new_cati].[dbo].[client] WITH(NOLOCK) " & VbCrlf - query = query & " WHERE client_ip = '" & remoteIp & "' " & VbCrlf - - adoRs.open query, adoconn, 1,1 - IF Not adoRs.EOF Then - returnString = "{" - returnString = returnString & """clientId"":""" & adoRs("client_id") & """," - returnString = returnString & """internalNo"":""" & adoRs("internal_no") & """," - returnString = returnString & """externalNo"":""" & adoRs("external_no") & """," - returnString = returnString & """clientIp"":""" & adoRs("client_ip") & """" - returnString = returnString & "}" - ELSE - returnString = "{" - returnString = returnString & """clientId"":""""," - returnString = returnString & """internalNo"":""""," - returnString = returnString & """externalNo"":""""," - returnString = returnString & """clientIp"":""""" - returnString = returnString & "}" - END IF - - Response.ContentType = "application/json" - Response.Charset = "utf-8" - Response.write returnString - '''''''''''''''''''''''''''New Contact에서 인트라넷을 통해 내부 IP를 통해 사용할 내선번호를 들고오기 위한 Page''''''''''''''''''''''''''' - ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''20260428 박준성''''''''''''''''''''''''''''''''''''''''''''''''''''''''' -%> \ No newline at end of file