It is currently April 19th, 2024, 1:57 pm

WebParser Header issue

Get help with creating, editing & fixing problems with skins
DollarD
Posts: 16
Joined: March 2nd, 2013, 5:56 pm

WebParser Header issue

Post by DollarD »

Hi,

I've been attempting to fetch network traffic data from my router via uPnP for use in my skin, and thought I could now use the native WebParser plugin instead of an external command, now that it includes support for custom headers. But alas...

Here's the measure currently:

Code: Select all

[MeasureFritzBox]
Measure=Plugin
Plugin=WebParser
URL=http://192.168.10.1:49000/igdupnp/control/WANCommonIFC1
Header=X-Http-Method-Override:POST
Header2=HOST:192.168.10.1:49000
Header3=SOAPACTION:"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetAddonInfos"
Header4=Content-Type:text/xml; charset="utf-8"
Header5=Connection:Close
Header6=Content-Length: 300
Header7=Cache-Control:no-cache
Header8=Allow: */*
Header9=#CRLF#
Header10=#XMLData#
UserAgent=" "
ProxyServer=/none
ForceReload=1
DynamicVariables=1
UpdateRate=30
You'd think think would do the trick. But observe the actual packet generated (and sniffed):
GET /igdupnp/control/WANCommonIFC1 HTTP/1.1
X-Http-Method-Override: POST
HOST: 192.168.10.1:49000
SOAPACTION: "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetAddonInfos"
Content-Type: text/xml; charset="utf-8"
Content-Length: 300
Cache-Control: no-cache
Allow: */*
<?xml version="1.0" encoding="utf-8"?><s: Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetAddonInfos xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1" /></s:Body></s:Envelope>
Connection: Close
So the two issues are:
  • The Connection: Close header is always placed last, no matter which header option you use.
  • The Header option adamantly refuses to allow me to place an empty header line.
The UserAgent option gracefully allow me to disable it, otherwise it would be the last header line as well. I can fix the Connection:Close issue by simply removing it (though I imagine my network stack won't like it).

The only outstanding issue really is ignoring the #CRLF# header. Then it would match perfectly with my VBS script and I could cut out the middleman there.

Usually I just get the output via RunCommand from this:

Code: Select all

On Error Resume Next

host = "192.168.10.1"

If host <> False Then
 Set http = Nothing
 Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
 If http Is Nothing Then Set http = CreateObject("WinHttp.WinHttpRequest.5")
 If http Is Nothing Then Set http = CreateObject("WinHttp.WinHttpRequest")
 If http Is Nothing Then Set http = CreateObject("MSXML2.ServerXMLHTTP")
 If http Is Nothing Then Set http = CreateObject("Microsoft.XMLHTTP")
 If http Is Nothing Then
  MsgBox "No HTML Object",16,"Error"
 Else
  body = "<?xml version=""1.0"" encoding=""utf-8""?>" _
   & "<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"" s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">" _
   & "<s:Body><u:GetAddonInfos xmlns:u=""urn:schemas-upnp-org:service:WANIPConnection:1"" /></s:Body></s:Envelope>"
  url = "igdupnp/control/WANCommonIFC1"
   With http
    .Open "POST", "http://" & host & ":49000/" & url,false
    .setRequestHeader "Content-Type", "text/xml; charset=""utf-8"""
    .setRequestHeader "Connection", "close"
    .setRequestHeader "Content-Length", Len(body)
    .setRequestHeader "HOST", host & ":49000"
    .setRequestHeader "SOAPACTION", """urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetAddonInfos"""
    .Send body
   End With

  WScript.Echo http.responseText
    
  WScript.Quit

 End If
End If
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: WebParser Header issue

Post by FreeRaider »

I dont understand what you want.

Post the output from your router and tell us what information you want to capture.
DollarD
Posts: 16
Joined: March 2nd, 2013, 5:56 pm

Re: WebParser Header issue

Post by DollarD »

Ok,

I want WebParser to deliver this or an equivalent HTTP request:

Code: Select all

POST /igdupnp/control/WANCommonIFC1 HTTP/1.1
Connection: close
Content-Type: text/xml; charset="utf-8"
Accept: */*
Host: 192.168.10.1:49000
User-Agent: Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
SOAPACTION: "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetAddonInfos"
Content-Length: 268

<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetAddonInfos xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1" /></s:Body></s:Envelope>
I know it can't post, but I've tested, and the X-Http-Method-Override:POST fixes it.

Then I can receive the following:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetAddonInfosResponse xmlns:u="urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1">
<NewByteSendRate>2287</NewByteSendRate>
<NewByteReceiveRate>6262</NewByteReceiveRate>
<NewPacketSendRate>0</NewPacketSendRate>
<NewPacketReceiveRate>0</NewPacketReceiveRate>
<NewTotalBytesSent>418233113</NewTotalBytesSent>
<NewTotalBytesReceived>996190098</NewTotalBytesReceived>
<NewAutoDisconnectTime>0</NewAutoDisconnectTime>
<NewIdleDisconnectTime>0</NewIdleDisconnectTime>
<NewDNSServer1>196.44.128.146</NewDNSServer1>
<NewDNSServer2>41.205.142.132</NewDNSServer2>
<NewVoipDNSServer1>196.44.128.146</NewVoipDNSServer1>
<NewVoipDNSServer2>196.44.128.146</NewVoipDNSServer2>
<NewUpnpControlEnabled>1</NewUpnpControlEnabled>
<NewRoutedBridgedModeBoth>1</NewRoutedBridgedModeBoth>
</u:GetAddonInfosResponse>
</s:Body>
</s:Envelope>
Which I can then use as follows:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1

....................................................................................................................................................

[Variables]
@Include="#CURRENTPATH#..\D10Variables.inc"

MeterLength=100
MeterStart=25
MeterStartAngle=(#Tau#*0.25)
MeterSizeAngle=(#Tau#/16)

XPos=0
YPos=0
WSize=150
HSize=250

CurrTime=0

....................................................................................................................................................

[MeasureDownload]
Measure=NetIn
Interface=0
MaxValue=1840000
AverageSize=4

[MeasureUpload]
Measure=NetOut
Interface=0
MaxValue=720000
AverageSize=4

[MeasureUsage]
Measure=NetTotal
Interface=0
Cumulative=1

[MeasureTimer]
Measure=Uptime
OnUpdateAction=[!SetVariable LastTime #CurrTime#][!SetVariable CurrTime [MeasureTimer:]][!CommandMeasure MeasureFritzBox Run]
UpdateDivider=5
DynamicVariables=1

[MeasureFritzBox]
Measure=Plugin
Plugin=Plugin\RunCommand.dll
Parameter=C:\Windows\System32\cscript.exe /nologo C:\Root\fb_getinfo.vbs
OutputType=ANSI
FinishAction=[!UpdateMeasure "MeasureBytesReceived"][!UpdateMeasure "MeasureBytesSent"]
DynamicVariables=1
UpdateDivider=-1

[MeasureTimePassed]
Measure=Calc
Formula=(#CurrTime# - #LastTime#)
DynamicVariables=1

[MeasureBytesReceived]
Measure=String
String=[MeasureFritzBox]
DynamicVariables=1
RegExpSubstitute=1
Substitute="(?siU).*<NewTotalBytesReceived>(\d*)<\/NewTotalBytesReceived>.*$":"\1"
OnUpdateAction=[!SetVariable PrevRec #CurrRec#][!SetVariable CurrRec [MeasureBytesReceived]]
UpdateDivider=-1

[MeasureBytesSent]
Measure=String
String=[MeasureFritzBox]
DynamicVariables=1
RegExpSubstitute=1
Substitute="(?siU).*<NewTotalBytesSent>(\d*)<\/NewTotalBytesSent>.*$":"\1"
OnUpdateAction=[!SetVariable PrevSent #CurrSent#][!SetVariable CurrSent [MeasureBytesSent]]
UpdateDivider=-1

[MeasureFBRec]
Measure=Calc
Formula=(#CurrRec# - #PrevRec#) / [MeasureTimePassed]
MaxValue=230000
DynamicVariables=1

[MeasureFBSent]
Measure=Calc
Formula=(#CurrSent# - #PrevSent#) / [MeasureTimePassed]
MaxValue=88000
DynamicVariables=1
Only with WebParser instead of RunCommand.

Does that help explain the problem I'm having?