119 lines
4.8 KiB
Plaintext
119 lines
4.8 KiB
Plaintext
<!-- #include Virtual="/Lib/Config.asp"-->
|
|
<%
|
|
Server.ScriptTimeOut = 60 * 5
|
|
Dim SQL,Rcset
|
|
Dim COMMAND : COMMAND = Request("COMMAND")
|
|
Dim CRUD : CRUD = Request("CRUD")
|
|
Dim PKEY : PKEY = Request("PKEY")
|
|
Dim PSIDX : PSIDX = Request("PSIDX")
|
|
Dim PSIDX_CHECK, PSIDX_DIGITS, PSIDX_LIMIT
|
|
|
|
Const KON_CONTACT_API_KEY = "4B726963-436F6E74616374-53657276696365-402531213230"
|
|
|
|
Set Rcset = Server.CreateObject("ADODB.RecordSet")
|
|
Dim ObjCmd : set ObjCmd = Server.CreateObject("ADODB.Command")
|
|
|
|
IF (CRUD = "INSERT" OR CRUD = "DELETE") AND COMMAND = "CONTACT_SURVEY" THEN
|
|
IF Request.ServerVariables("HTTP_X_API_KEY") <> KON_CONTACT_API_KEY THEN
|
|
Response.Status = "401 Unauthorized"
|
|
Response.AddHeader "Cache-Control", "no-store"
|
|
Response.ContentType = "application/json; charset=utf-8"
|
|
Response.Write "{""message"":""Authentication required""}"
|
|
Response.End
|
|
END IF
|
|
END IF
|
|
|
|
IF (CRUD = "INSERT" OR CRUD = "SELECT" OR CRUD = "DELETE") AND COMMAND = "CONTACT_SURVEY" THEN
|
|
IF Len(PKEY) = 0 OR Len(PKEY) > 20 THEN
|
|
Response.Status = "400 Bad Request"
|
|
Response.ContentType = "application/json; charset=utf-8"
|
|
Response.Write "{""message"":""Invalid PKEY""}"
|
|
Response.End
|
|
END IF
|
|
|
|
IF CRUD = "INSERT" OR CRUD = "DELETE" THEN
|
|
Set PSIDX_CHECK = Server.CreateObject("VBScript.RegExp")
|
|
PSIDX_CHECK.Pattern = "^-?[0-9]{1,19}$"
|
|
IF NOT PSIDX_CHECK.Test(PSIDX) THEN
|
|
Response.Status = "400 Bad Request"
|
|
Response.ContentType = "application/json; charset=utf-8"
|
|
Response.Write "{""message"":""Invalid PSIDX""}"
|
|
Response.End
|
|
END IF
|
|
END IF
|
|
END IF
|
|
|
|
Call DBConnect2()
|
|
|
|
SELECT CASE CRUD
|
|
'-- CREATE '
|
|
CASE "CREATE"
|
|
SELECT CASE COMMAND
|
|
|
|
END SELECT
|
|
'-- SELECT '
|
|
CASE "SELECT"
|
|
SELECT CASE COMMAND
|
|
CASE "CONTACT_SURVEY"
|
|
response.ContentType = "application/json"
|
|
SQL = ""
|
|
SQL = SQL & " SELECT IDX, PKEY, PSIDX, REG_DT FROM KON_CONTACT_MAPPING WHERE PKEY = ? ORDER BY IDX "
|
|
With ObjCmd
|
|
.ActiveConnection = DBConn
|
|
.CommandText = SQL
|
|
.CommandType = adCmdText
|
|
.Parameters.Append .CreateParameter("@PKEY", adVarChar, adParamInput, 20)
|
|
.Parameters("@PKEY") = PKEY
|
|
End With
|
|
Rcset.Open ObjCmd, , 3, 1
|
|
IF Rcset.eof or Rcset.bof THEN
|
|
response.write "[]"
|
|
ELSE
|
|
response.write RecordToJSON(Rcset)
|
|
END IF
|
|
Rcset.Close
|
|
Set Rcset = Nothing
|
|
Set ObjCmd = Nothing
|
|
Call DBClose()
|
|
response.end
|
|
END SELECT
|
|
'-- INSERT '
|
|
CASE "INSERT"
|
|
SELECT CASE COMMAND
|
|
CASE "CONTACT_SURVEY"
|
|
SQL = ""
|
|
SQL = SQL & " INSERT INTO KON_CONTACT_MAPPING (PKEY, PSIDX) VALUES (?, CAST(? AS BIGINT)) "
|
|
With ObjCmd
|
|
.ActiveConnection = DBConn
|
|
.CommandText = SQL
|
|
.CommandType = adCmdText
|
|
.Parameters.Append .CreateParameter("@PKEY", adVarChar, adParamInput, 20)
|
|
.Parameters.Append .CreateParameter("@PSIDX", adVarChar, adParamInput, 20)
|
|
.Parameters("@PKEY") = PKEY
|
|
.Parameters("@PSIDX") = PSIDX
|
|
.Execute , , adExecuteNoRecords
|
|
End With
|
|
END SELECT
|
|
'-- DELETE '
|
|
CASE "DELETE"
|
|
SELECT CASE COMMAND
|
|
CASE "CONTACT_SURVEY"
|
|
SQL = ""
|
|
SQL = SQL & " DELETE FROM KON_CONTACT_MAPPING WHERE PKEY = ? AND PSIDX = CAST(? AS BIGINT) "
|
|
With ObjCmd
|
|
.ActiveConnection = DBConn
|
|
.CommandText = SQL
|
|
.CommandType = adCmdText
|
|
.Parameters.Append .CreateParameter("@PKEY", adVarChar, adParamInput, 20)
|
|
.Parameters.Append .CreateParameter("@PSIDX", adVarChar, adParamInput, 20)
|
|
.Parameters("@PKEY") = PKEY
|
|
.Parameters("@PSIDX") = PSIDX
|
|
.Execute , , adExecuteNoRecords
|
|
End With
|
|
END SELECT
|
|
END SELECT
|
|
Set ObjCmd = Nothing
|
|
If Not Rcset Is Nothing Then Set Rcset = Nothing
|
|
call DBClose()
|
|
|
|
%> |