HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/web/secure/itpplates/test - Copy (2).asp
<%Option Explicit%>
<!--#include file="dbfunctions.asp"-->
<!--#include file="jsonObject.class.asp" -->
<%

Dim NL
NL = Chr(13) + Chr(10)

Dim oJSONResponse ' used to hold the return JSONobject 
Dim oJSONRequest ' used to hold the request JSON


' gets rid of "The specified LCID is not available." error in jsonObject.class.asp line 624
' *** perhaps we need to set Response.LCID instead of Session.LCID
Session.LCID = 1033 

DebugOn
SetDebugLogTypeToFile
WebDebugLog


Const API_KEY = "ab363c05-4a96-48dc-8764-6d2a5d975158"

Response.ContentType = "application/json"

API_Run


Sub API_Run
  Dim LResult

  ' instantiate the class
  Set oJSONResponse = New JSONobject
  Set oJSONRequest = New JSONobject
  
  'oJSONRequest.debug = True
  'oJSONResponse.debug = True

  ' add default properties
  oJSONResponse.Add "status", 400
  oJSONResponse.Add "message", "Unknown error"
 
  On Error Resume Next ' start the error handling
  
  
  API_Log "Debug:", "1"
  
  LResult = API_ReadRequest ' read request into object  
  
  API_Log "Debug:", "2"
  
  If Err.Number <> 0 Then LResult = Err.Description
  
  API_Log "Debug:", "3"
  
  If LResult = "" Then ' if no error then continue
  
    API_Log "Debug:", "4"
  
    LResult = API_Authenticate ' check API key etc
    
    API_Log "Debug:", "5"
    
    If Err.Number <> 0 Then LResult = Err.Description
    
    API_Log "Debug:", "6"
    
    If LResult = "" Then
    
      API_Log "Debug:", "7"
    
      LResult = API_ProcessRequest ' process the request
      
      API_Log "Debug:", "8"
      
      If Err.Number <> 0 Then LResult = Err.Description
      
      API_Log "Debug:", "9"
      
    End If
  End If
  
  On Error GoTo 0 ' cancel the error handling   
  
  ' if no error then change status code to 200
  If LResult = "" Then
    oJSONResponse.Change "status", 200      
  End If
  oJSONResponse.Change "message", LResult
  
  ' (SS,23/4/20) replaced above with following to pass back test
  'oJSONResponse.Change "message", "Hello world, just testing, " & Now
  
  ' write the response
  oJSONResponse.Write()
  
  ' log the response
  API_Log "Response", oJSONResponse.Serialize
  
  ' free the object created earlier, might not be necessary
  Set oJSONResponse = Nothing
  Set oJSONRequest = Nothing
End Sub

' check the API key, returns "" if okay, error message otherwise
Function API_Authenticate
  Dim LResult, LValue
  LResult = ""

  'LValue = oJSONRequest.Value("apikey")
  LValue = oJSONRequest.Value("APIKey")
  If IsNull(LValue) Then
    LResult = "API Key (APIKey) is missing"
  ElseIf LValue <> API_KEY Then
    LResult = "API Key is invalid"
  End If
  
  API_Authenticate = LResult
End Function


' reads the request from JSON, returns "" if okay, error message otherwise
Function API_ReadRequest
  Dim LResult, LByteCount, LBytes, LStream, LJSONString 

  LResult = ""
  LJSONString = ""
  
  LByteCount = Request.TotalBytes
  LBytes = Request.BinaryRead(LByteCount)
  
  If LByteCount = 0 Then
    LResult = "No request specified"
  Else
    ' with help from https://stackoverflow.com/questions/2682280/get-classic-asp-variable-from-posted-json
    ' gets request into a string
    Set LStream = Server.CreateObject("ADODB.Stream")
    LStream.Type = 1 ' adTypeBinary              
    LStream.Open()                                   
    LStream.Write(LBytes)
    LStream.Position = 0                             
    LStream.Type = 2 ' adTypeText                
    LStream.Charset = "utf-8"                      
    LJSONString = LStream.ReadText() ' json request as a string                
    LStream.Close()
    Set LStream = Nothing
    
    If LJSONString = "" Then
      LResult = "Empty request"
    Else
      oJSONRequest.Parse(LJSONString)
    End If        
  End If
  
  API_Log "Request", LJSONString
  API_ReadRequest = LResult
End Function

' process the request
Function API_ProcessRequest
  Dim LResult, LCompany, LLicenceKey
  LResult = ""
  
  
  API_Log "API_ProcessRequest: ", "1"
  
  LCompany = oJSONRequest.Value("company")
  
  API_Log "Company", LCompany
  
  API_Log "API_ProcessRequest: ", "2"
  
  
  LLicenceKey = oJSONRequest.Value("licenceKey")
  
  API_Log "API_ProcessRequest: ", "3"  
  
  API_Log "Licence Key", LLicenceKey
  
  API_Log "API_ProcessRequest: ", "4"
  
  
  API_Log "Licence Key", oJSONRequest.Value("createDate") & ""
  
  API_ProcessRequest = LResult  
End Function


Sub API_Log(AType, ALog)
  DebugLog 0, NL & AType & ": " & ALog

'  Dim LSQL
'  LSQL = "INSERT INTO api_log SET LogDateTime = NOW(), IPAddress = '" & CleanSQLStr(Request.ServerVariables("REMOTE_ADDR")) & "', SessionID = '" & Session.SessionID & "', Type = '" & AType & "', Log = '" & CleanSQLStr(ALog) & "'"
'  ExecuteQuery LSQL
End Sub

%>