ClassicASP-FirePHP icon indicating copy to clipboard operation
ClassicASP-FirePHP copied to clipboard

Type mismatch: 'toJson' in firedebug.inc, line 72

Open strider72 opened this issue 7 years ago • 14 comments

I would love for this to work, but I get an error as soon as I try to call "log":

Type mismatch: 'toJson'
/path/to/firedebug.inc, line 72

The Console itself returns:

The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.

Does this still work at all in the post-Firebug world? Does it work in the standard Firefox/Chrome Console?

strider72 avatar Jan 31 '18 17:01 strider72

Sorry I've no idea what the error is or whether this still works with current versions of firePHP. We used it extensively with our old codebase but that was replaces years ago so it's not been updated since.

dmeagor avatar Jan 31 '18 17:01 dmeagor

Ah. Too bad. Thanks.

strider72 avatar Jan 31 '18 17:01 strider72

Someone on stack overflow stated that they had to add the line below to example page. Did you try this? Let me know if it works and I'll update the repo.

<!--#include file="JSON.asp" -->

dmeagor avatar Feb 01 '18 13:02 dmeagor

Actually I've just updated the firephp.inc file to include it. Not sure how that got left off. Please pull down and try the example again. If it's still compatible with firephp then it should just work (no need to add the include again to the example.)

dmeagor avatar Feb 01 '18 13:02 dmeagor

UPDATE: point 1 is false. I mistakenly put the JSON include inside the VBScript area; but includes don't work that way. Moved it to the very top of the file, before the <% , and it works fine.

A couple notes:

  1. I had added the JSON file from within firedebug.inc -- similar to what you did. Got the error. I have gotten rid of the error by including the JSON file within the file I'm using for testing. I have a feeling the include within firedebug didn't work the same because perhaps the SSI isn't being processed inside a .inc file...?
<!--#include virtual="/lib/asp/ClassicASP-FirePHP/1.2/json/JSON.asp" -->
<!--#include virtual="/lib/asp/ClassicASP-FirePHP/1.2/firedebug.inc" -->
  1. Probably the reason you didn't include it directly before was the understanding that somebody might already have it loaded. It's probably best as a load it if you need it kind of thing. Instead of including it directly as you have, I would just make a clearer note in the Readme.

  2. Your link is wrong. You have to account for the json folder.

Having said all that, I no longer get the error on page load, but still nothing is sent to the Console. Hmmm...

strider72 avatar Feb 02 '18 16:02 strider72

It appears you write to the Console by sending an HTTP header starting with X-Wf-1-1-....

I don't know if Firefox can still use these headers. The only thing I've found anywhere about writing to console says use JavaScript (which I can't in my use case). Wish FF still had a "console-via-headers" method. :-(

strider72 avatar Feb 02 '18 17:02 strider72

Previously you needed to install the firePHP addon for firebug. It's firephp that processes the header and then passes on the data to the console in a formatted way.

Assuming that you have verified that the headers are present in the example.asp request now. And your sure the firephp extension is installed and enabled (it used to need explicit enabling and browser restart)
then you might consider installing an old version of firefox just for debugging classic asp.

I suggest trying

Firefox 3.6+ & Firebug 1.7 with FirePHP Extension 0.5.0 http://firephp.org/

No reason it shouldn't work then.

dmeagor avatar Feb 02 '18 18:02 dmeagor

Yea, verily, you are awesome. Installed firePHP beta and it works. Thank you so much for the help!

For anyone else looking for it:

  1. There a link on this page: https://github.com/firephp/firephp-for-firefox-devtools
  2. You may have to first go to about:config and set xpinstall.signatures.required to false

Edit for clarification: It's working fine in the current version of Firefox (58.x as I write), using a beta version of FirePHP. This ROCKS.

strider72 avatar Feb 02 '18 19:02 strider72

That's great. Surprised this still works TBH.

Probably the most useful thing we did with this was to add a "log group" for all SQL queries. It would show the query times, a successful/fail for each and the full SQL (un-paramaterising the query so we could test it easily.)

If you already have a sql helper function you can tie into then I highly recommend setting this up if you've got to support this classic asp app in the future.

If you don't then unfortunately it would mean creating a some kind of SQL helper function.

I have an old implementation which takes care of sql injection/paramaterisation and returns either a recordset, disconnected recordset or a simple value and of course logs to firedebug. I think there was a version that could log a table as well if needed. Example below

Set rs = safeSQL("Update poll theme with updated info",_
	"UPDATE tblTemplate SET json=? WHERE templateId=? AND id=?",_
	array(jsonString, pollThemeID, userid))

dmeagor avatar Feb 02 '18 19:02 dmeagor

I have a custom function called pquery that takes two parameters -- a string of the SQL query, and an array of data to be passed in (or NULL if query is static). Maybe I could work the logging in to that function

strider72 avatar Feb 02 '18 23:02 strider72

FYI: https://stackoverflow.com/questions/48588158/write-to-firefox-console-from-a-page-no-javascript/

strider72 avatar Feb 02 '18 23:02 strider72

The other version looks like the one to use moving forwards but the lack of grouping would be annoying.

Here's the version of the script we were using with the sql logging.

<%

'Functions
'-----------
' log value
' log_type type,label,value
' log_group_start label,collapsed (true/false)
' log_group_end
' log_table array (requires 2 dimensional array)
'----------------------------------------------------------------------

	if Request.ServerVariables("REMOTE_ADDR") = "127.0.0.1" or Request.ServerVariables("REMOTE_ADDR")= "82.68.196.158" or Request.ServerVariables("REMOTE_ADDR")="123.123.123" or  instr(Request.ServerVariables("REMOTE_ADDR"), "192.168.1.") then
		FireDebugLoaded=true
		Set console = new FireDebug		
	end if


	Class FireDebug
		
		'Private variables 
		Private headerPrefix
		Private headerCounter
		Private protocolHeaderKeys(3)
		Private protocolHeaderVals(3)
		Private pageStartTime
		Private arrLog_sql
		Private arrLog_sql_count
		
		Private Sub Class_Initialize()
			pageStartTime = timer

			redim arrLog_sql(1,0)
			arrLog_sql_count=0


			'Set the header prefix
			headerPrefix = "X-Wf-"
			
			headerCounter = 0
			
			protocolHeaderKeys(0) = "Protocol-1"
			protocolHeaderKeys(1) = "1-Plugin-1"
			protocolHeaderKeys(2) = "1-Structure-1"
			
			protocolHeaderVals(0) = "http://meta.wildfirehq.org/Protocol/JsonStream/0.2"
			protocolHeaderVals(1) = "http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3"
			protocolHeaderVals(2) = "http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1"
			
			'Turn on Page buffering
			Response.Buffer = True
			
			For i = 0 to 2				
				Response.addHeader headerPrefix & protocolHeaderKeys(i), protocolHeaderVals(i) 				
			next

		End Sub

		Private Sub Class_Terminate()
			firebugDump()

		end sub
		

		Public Function log_sql_time(timems)
			arrLog_sql(1,arrLog_sql_count-1) = timems
		End Function
		
		Public Function log_sql(strSQL)						
			redim preserve arrLog_sql(1,arrLog_sql_count)
		
			arrLog_sql(0,arrLog_sql_count) = strSQL
			arrLog_sql(1,arrLog_sql_count) = -1

			arrLog_sql_count=arrLog_sql_count+1
		End Function

		Public Function log( ByRef obj )
			dim str
			
			headerCounter= headerCounter + 1
			if vartype(obj)<>14 then 
				if TypeName(obj)="Dictionary" then
					'Dictionary object
					Set member = jsObject()
					for each str in obj
						member(str) = obj(str)
					next
					set obj=member				
				end if
			end if
			
			str= "|[{""Type"":""LOG""},"&toJson(obj)&"]|"
			msgLength = len(str) - 2
			str=msgLength&str						
			Response.addHeader headerPrefix & "1-1-1-" & headerCounter , str
		End Function

		Public Function log_type( logtype,label,ByRef obj )
			dim str
			
			headerCounter= headerCounter + 1
			
			if TypeName(obj)="Dictionary" then
				'Dictionary object
				Set member = jsObject()
				for each str in obj
					member(str) = obj(str)
				next
				set obj=member				
			end if
				      
			str= "|[{""Type"":"""&logtype&""",""Label"":"""&label&"""},"&toJson(obj)&"]|"
			msgLength = len(str) - 2
			str=msgLength&str
			Response.addHeader headerPrefix & "1-1-1-" & headerCounter , str
		End Function

		Public Function log_group_start( label,Collapsed )
			dim str
			
			if Collapsed=true then Collapsed="true" else Collapsed="false"

			headerCounter= headerCounter + 1
				      
			str= "|[{""Type"":""GROUP_START"",""Label"":"""&label&""",""Collapsed"":"""&Collapsed&"""},"&toJson(obj)&"]|"
			msgLength = len(str) - 2
			str=msgLength&str						
			Response.addHeader headerPrefix & "1-1-1-" & headerCounter , str
		End Function

		Public Function log_group_end()
			dim str
			
			headerCounter= headerCounter + 1
				      
			str= "|[{""Type"":""GROUP_END""}]|"
			msgLength = len(str) - 2
			str=msgLength&str						
			Response.addHeader headerPrefix & "1-1-1-" & headerCounter , str
		End Function

		Public function firebugDump()

			dim str,lasterr
			
			
				if typename(cn) = "Connection" then				
					for each objErr in cn.Errors 
					  log_type "ERROR","Description",objErr.Description
					  log_type "ERROR","HelpContext",objErr.HelpContext
					  log_type "ERROR","HelpFile",objErr.HelpFile
					  log_type "ERROR","NativeError",objErr.NativeError
					  log_type "ERROR","Number",objErr.Number
					  log_type "ERROR","Source",objErr.Source
					  log_type "ERROR","SQLState",objErr.SQLState
					next					
				end if
			
			
			set objErr=Server.GetLastError()
			if objErr.Number<>0 then 
				
				log_type "ERROR","","objErr.Number: "&objErr.Number
				log_type "ERROR","","err.Number: "&err.Number
				log_type "ERROR","","ERROR ON PAGE: "&objErr.file										
				log_type "ERROR","",err.Source
				log_type "ERROR","","Error: "&objErr.Description &" on line: "&objErr.line
				if objErr.column>1 then log_type "ERROR","","Column: "&objErr.column					
				if objErr.ASPDescription<>"" then log_type "ERROR","","Description: "&objErr.ASPDescription
			else
				log_type "INFO","SUCCESS","(Time taken: "&formatnumber((timer-pageStartTime)*1000,2)&"ms)"

			end if



			'SQL Log
			if arrLog_sql_count>0 then
				log_group_start "SQL Queries ("&arrLog_sql_count&")",true
				for a=0 to arrLog_sql_count-1
					if arrLog_sql(1,a)=-1 then 
						log_type "ERROR","",arrLog_sql(0,a)
					else 
						log_type "INFO","",arrLog_sql(0,a) & " ["&formatnumber(arrLog_sql(1,a)*1000)&"ms]"
					end if
				next
				log_group_end			
			end if


			log_group_start "ASP System Collections",true


			'SESSION
			Set member = jsObject()
			for each str in session.contents
				if vartype(session.contents(str))=14 then 
					mytype="Decimal subtype - CAUTION"
				else
					mytype = typename(Session.Contents(str))
				end if
				member(str) = Session.Contents(str) &" ["&mytype&"]"
			next
			log_type "INFO","SESSION",member

			'POST
			Set member = jsObject()	
			for each str in request.form
				member(str) = request.form(str)
			next
			log_type "INFO","POST",member


			'GET
			Set member = jsObject()
			for each str in request.querystring
				member(str) = request.querystring(str)
			next
			log_type "INFO","GET",member

			'Application
'			Set member = jsObject()	
'			for each str in Application.Contents
'				'response.write(vartype(application(str))&",")
'				if left(application(str),3)<>"lan" then 
'					if vartype(application(str))<>8204 then
'						member(str) = application.contents(str)
'					else		
'						member(str) = "Not shown"
'					end if
'				end if
'			next
'			log_type "INFO","APPLICATION",member

			'SERVER
			Set member = jsObject()
			for each str in Request.ServerVariables
				member(str) = request.ServerVariables(str)
			next
			log_type "INFO","SERVER",member

			log_group_end()


		end function
		
		
	End Class


'Shortcut functions to save typing.

	'Multi-purpose log function.  Log's variables or json (see json.asp) objects
	sub log( ByRef msg )
		if FireDebugLoaded=true then		
			call console.log(msg)
		end if
	end sub

	'log info
	sub logi( byref title, ByRef msg )
		if FireDebugLoaded=true then		
			call console.log_type("INFO",title,msg)
		end if
	end sub

	'log warn
	sub logw( byref title, ByRef msg )
		if FireDebugLoaded=true then		
			call console.log_type("WARN",title,msg)
		end if
	end sub

	'log error
	sub loge( byref title, ByRef msg )
		if FireDebugLoaded=true then		
			call console.log_type("ERROR",title,msg)
		end if
	end sub

	'log with INFO, WARN, or ERROR icon/styling and heading
	sub log_type( logtype,label,ByRef obj )		
		if FireDebugLoaded=true then		
			call console.log_type(logtype,label,obj)
		end if
	end sub

	'start and end expandable group
	sub log_group_start( label,collapsed )
		if FireDebugLoaded=true then		
			call console.log_group_start(label,collapsed)
		end if
	end sub

	sub log_group_end()
		if FireDebugLoaded=true then
			call console.log_group_end()
		end if
	end sub

	'log 2D array
	sub log_table(ByRef obj)
		if FireDebugLoaded=true then		
			call console.log_type("TABLE","Array",obj)
		end if
	end sub

	'log sql query, also use log_sql_time after
	sub log_sql(label, ByVal strSQL,parameters)
		if FireDebugLoaded=true then		

			if isarray(parameters) then		
			    no=0
			    for each value in parameters        
			        strSQL = replace(strSQL,"?","'"&value&"'",1,1)
			        no=no+1
			    next 
			end if

	    	call console.log_sql(label &": " & strSQL)
		end if
	end sub

	'call after log_sql to update query with outcome and time
	sub log_sql_time(t)
		if FireDebugLoaded=true then	
	    	console.log_sql_time t
	    end if
	end sub

%>

dmeagor avatar Feb 02 '18 23:02 dmeagor

And the sql function with the timing, success/fail etc.

' USAGE:   set rs = safeSQL( "Get login data", "SELECT * FROM tblUser WHERE userName=? AND password=?", array("[email protected]","password") )
function safeSQL(label, strSQL,parameters)
    Dim cmd,no,t,rs
    if FireDebugLoaded=true then 
        log_sql label, strSQL, parameters
        if strCount(strSQL,"?")<ubound(parameters)+1 then 
   			log_type "ERROR","ADO paramater error","not enough ?'s"
	    	response.end
   		elseif strCount(strSQL,"?")>ubound(parameters)+1 then 
   			log_type "ERROR","ADO paramater error","not enough paramaters supplied"
	    	response.end
   		end if
    end if
    Set rs = server.createobject("ADODB.Recordset")
    Set cmd = Server.CreateObject("ADODB.Command")    
    cmd.ActiveConnection = cn
    cmd.CommandText = strSQL
    cmd.CommandType = adCmdText
    no=0
    for each value in parameters
    	'on error resume next
  ''   	if isempty(value) then
  ''  		value=""
  '' 	end if
    	if isnumeric(value) or vartype(value)=14 or isnull(value) then   ' vartype 14 is decimal subtype - not documented
			
			Set newParameter = cmd.CreateParameter("?", adDouble,adParamInput,,value)
			cmd.Parameters.Append newParameter		
		else
			value = replace(value,"%_str%","")			
			Set newParameter = cmd.CreateParameter("?", adVarWChar,adParamInput,len(value)+1,value)
			cmd.Parameters.Append newParameter
		end if
    	
    	'cmd.Parameters(no) = value
   	    
   	    if err.number<>0 then 
   	    	if FireDebugLoaded=true then	    	
	    		log_type "ERROR","ADO paramater error","("&no+1&")="&value
	    		log_type "ERROR","Description",err.description
	    	end if	    	
	    	out("ADO ERROR - CHECK LOG")
	    	response.end
	    end if
		on error goto 0
		    	
    	no=no+1
    next 
    
    t=timer
    rs.Open cmd, , adOpenForwardOnly, adLockReadOnly
    Set safeSQL = rs
    'Set safeSQL = cmd.Execute()
    t = timer-t
	
	Set cmd = Nothing
    log_sql_time t
end function

dmeagor avatar Feb 02 '18 23:02 dmeagor

And the function for outputting sql results table to JSON / firephp.

I think this one requires the json2.asp script be included like this.

<script language="javascript" runat="server" src="/app/json/json2.asp"></script>

can be downloaded here if you don't already have it.

https://github.com/nagaozen/asp-xtreme-evolution/blob/master/lib/axe/classes/Parsers/json2.asp

Function safeSQL_JSON(label, sql, parameters)
        Dim rs, jsa
        Set rs = safeSQL (label,sql,parameters)
        Set jsa = jsArray()
        While Not (rs.EOF Or rs.BOF)
                Set jsa(Null) = jsObject()
                For Each col In rs.Fields
                        jsa(Null)(col.Name) = col.Value
                Next
        rs.MoveNext
        Wend
        rs.close
        Set safeSQL_JSON = jsa
End Function

dmeagor avatar Feb 02 '18 23:02 dmeagor