It is currently September 8th, 2024, 12:20 am

Weird behaivour with WebParser HTTP Authentication

Get help with creating, editing & fixing problems with skins
User avatar
Jeff
Posts: 346
Joined: September 3rd, 2018, 11:18 am

Weird behaivour with WebParser HTTP Authentication

Post by Jeff »

Very strange behaivour, I'm posting here since I couldn't find anything for my Error Code and not understanding why it isn't working

To cut a long story short, I'm making a skin for VLC where you don't need the libcad plugin!
I have the following measure

Code: Select all

[VLCRoot]
Measure=WebParser
URL=http://#UserName#:#Password#@#IpAdress#:#Port#/requests/status.xml
RegExp=.*
For some reason, this is not working, when I run the skin, I get and then the error
  • (Fetch error) The parameter is incorrect. (ErrorCode=87) (VLCMeter\VLCMeter.ini - [VLCRoot])
I have genuinley looked at everything I wrote, up and down, left and right, diagonally, through my monitor (I'm a ghost and I can phase throught it) and it dosen't make sense.
I tried to fix this in a bit of a convoluted way, I looked at the packets in the Developer Tools menu, looked at the headers and decided to move the Auth part from the URL to the Headers stolen from there

Code: Select all

[VLCRoot]
Measure=WebParser
URL=http://#IpAdress#:#Port#/requests/status.xml
Header=Authorization: Basic OjEyMzQ=
; find a way to encode to b64 #UserName#:#Password#
RegExp=.*
This works with the only caveat that I need to base64 that field, which should not be hard, but I don't know if I would want to use Lua.
Is there a way to do HTTP Auth in Rainmeter on local ips without a .TDL ending or did I miss something?

Actually, this entire post was a ruse, should I use status.xml or status.json to parse VLC's data? πŸ€”
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Weird behaivour with WebParser HTTP Authentication

Post by Yincognito »

I don't have VLC installed and I don't quite get why an username and a password would be needed in this case, but maybe the username in your original attempt must not be blank, from Rainmeter's point of view (it wouldn't be the first case, as it doesn't like empty regex captures either)? :???:

As for base64 encoding and decoding, Javascript has the btoa() and atob() functions to do it and you can fetch stuff from an address there too, via XMLHttpRequest() or fetch(), but of course you're not using WebView to be able to use these. For Lua, this might be a reasonable solution:
http://lua-users.org/wiki/BaseSixtyFour

Unfortunately, I don't have an answer to your last question, since I didn't work with HTTP Auth in WebParser yet, given that I didn't need it for any email skin. :(
Profiles: Rainmeter Profile β—‡ DeviantArt Profile β—† Suites: MYiniMeter β—† Skins: Earth
User avatar
Jeff
Posts: 346
Joined: September 3rd, 2018, 11:18 am

Re: Weird behaivour with WebParser HTTP Authentication

Post by Jeff »

Yincognito wrote: ↑July 23rd, 2024, 9:12 am I don't have VLC installed and I don't quite get why an username and a password would be needed in this case, but maybe the username in your original attempt must not be blank, from Rainmeter's point of view (it wouldn't be the first case, as it doesn't like empty regex captures either)? :???:
Supposedly, it's to prevent vandalism from people who would connect to the online interface... why you would use the online interface in a public setting is another question lol
Yincognito wrote: ↑July 23rd, 2024, 9:12 am As for base64 encoding and decoding, Javascript has the btoa() and atob() functions to do it and you can fetch stuff from an address there too, via XMLHttpRequest() or fetch(), but of course you're not using WebView to be able to use these. For Lua, this might be a reasonable solution:
http://lua-users.org/wiki/BaseSixtyFour
If I don't find out the reason why it's not working, I guess I'll eventually use this, I'll just tell users to copy both the .inc with the measures and the .lua file (day 11 of wishing for a LineN option for Script measures without some loadstring hack)
Yincognito wrote: ↑July 23rd, 2024, 9:12 am Unfortunately, I don't have an answer to your last question, since I didn't work with HTTP Auth in WebParser yet, given that I didn't need it for any email skin. :(
For email skins, both field will always have to be filled, in this case, username can be left alone, while I could just add a username and call it a day, this will probably prop up in other places in the future again

The thing is, it works in CMD's curl but it dosen't work in Powershell's Invoke-WebRequest?????????????????
Image
I'm too lazy to look in the code, but I'm pretty sure it's not working in Rainmeter because the library WebParser (and by extension Powershell) uses (System.Web.Whatev) also has this incorrectly, so technology older than me beats newer (supposedly better) technology again.
User avatar
balala
Rainmeter Sage
Posts: 16499
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Weird behaivour with WebParser HTTP Authentication

Post by balala »

Jeff wrote: ↑July 22nd, 2024, 8:00 pm For some reason, this is not working, when I run the skin, I get
I don't have VLC installed either, but same way as Yincognito, this error leads me thinking there is something wrong with the username. Check it. Unfortunately no more ideas, but this definitely looks weird for me, at this point.
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Weird behaivour with WebParser HTTP Authentication

Post by Yincognito »

Jeff wrote: ↑July 23rd, 2024, 9:56 am The thing is, it works in CMD's curl but it dosen't work in Powershell's Invoke-WebRequest?????????????????
Hmm... it works for me for a plain non authentication local webpage (e.g. (Invoke-WebRequest -URI "http://localhost:8080/Index.js").Content), so this might require the usage of some other parameters of Invoke-WebRequest e.g. -Authentication and possibly -Body in order to be successful in the attempt (see example 2 below too):
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.4
Jeff wrote: ↑July 23rd, 2024, 9:56 amwishing for a LineN option for Script measures without some loadstring hack
Not sure why you'd need the slower loadstring() hacks to compile additional chunks of code, since besides using Lua functions directly / inline, you could !CommandMeasure any kind of global code separated by ; to do the same thing. Not to mention you can add any number of custom options to a Script measure and refer them in Lua using the SELF object. Or, you can use 'template' structures if by any chance you want to have those 'factory' measures that mass create the contents in your .inc files at load / refresh time.
Profiles: Rainmeter Profile β—‡ DeviantArt Profile β—† Suites: MYiniMeter β—† Skins: Earth
User avatar
Jeff
Posts: 346
Joined: September 3rd, 2018, 11:18 am

Re: Weird behaivour with WebParser HTTP Authentication

Post by Jeff »

balala wrote: ↑July 23rd, 2024, 10:24 am I don't have VLC installed either, but same way as Yincognito, this error leads me thinking there is something wrong with the username.
Yincognito wrote: ↑July 23rd, 2024, 6:46 pm Hmm... it works for me for a plain non authentication local webpage (e.g. (Invoke-WebRequest -URI "http://localhost:8080/Index.js").Content), so this might require the usage of some other parameters of Invoke-WebRequest e.g. -Authentication and possibly -Body in order to be successful in the attempt (see example 2 below too):
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.4
Both of you were correct, the problem in both Rainmeter and Powershell were the fact that the username is missing.
In Powershell's case, I tried to use both -Body to input a $NULL username and then -Credentials which also didn't allow me to continue without a valid username
In Rainmeter's case, I wasn't able to find what is exactly used, looking at the MeasureWebParser.h file though I see the class HINTERNET, which is my only hint, searching it on Google got me to this page about HINTERNET Handlers, then on the side there is the page explaining this problem, Handling Authentication, which specifically says both User name and password have to be valid.

The problem is, you can't set a username in VLC, the URL can not be in any other form than http://:<Password>@localhost:<Port>/, which sucks. In essence this is a Windows design choice exasperated by a VLC design choice.
Yincognito wrote: ↑July 23rd, 2024, 6:46 pm Not sure why you'd need the slower loadstring() hacks to compile additional chunks of code, since besides using Lua functions directly / inline, you could !CommandMeasure any kind of global code separated by ; to do the same thing. Not to mention you can add any number of custom options to a Script measure and refer them in Lua using the SELF object. Or, you can use 'template' structures if by any chance you want to have those 'factory' measures that mass create the contents in your .inc files at load / refresh time.
From my testing like 4 years ago, Rainmeter requires a ScriptFile to be loaded in order for any !CommandMeasure to work, the file could be empty, it just has to open a file to ever initialize the environment.
I wanted other skin authors to just copy paste the MAIN .ini and be done, nothing else, if they wanna implement what I'm writing into their own suites.
My idea is just to... brace yourself... do !CommandMeasure "MyScriptMeasure" "local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';function enc(data);return ((data:gsub('.', function(x) ;local r,b='',x:byte();for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end;return r;end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x);if (#x < 6) then return '' end;local c=0;for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end;return b:sub(c+1,c+1);end)..({ '', '==', '=' })[#data%3+1]);end;function Initialize();local VLCPassword = SKIN:GetVariable("Password", "");SKIN:Bang("!SetOption", "VLCRoot", "Header", "Authorization: Basic "..enc(":"..tostring(VLCPassword)))" in order for the user, who ever modifies this, to not have to copy/use the .lua file.
For the better of humanity, I ditched this idea, if a user wants to modify this skin, just do it like a normal person, duplicate the folder and rename it lol
User avatar
Jeff
Posts: 346
Joined: September 3rd, 2018, 11:18 am

Re: Weird behaivour with WebParser

Post by Jeff »

I still have a weird behavior with WebParser though, because it's pooling every second, it reports stuff in the log every second.
The problem appears if you refresh the skin during a period where WebParser writes to the log. If you refresh during that, congrats, you broke the Rainmeter Log, now nothing is getting reported anymore and the WebParser measure eventually fails.
https://imgur.com/a/gnxYiev
I made a video showing the problem. I don't really think there is a way around this, WebParser wasn't made for stuff like this.
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Weird behaivour with WebParser HTTP Authentication

Post by Yincognito »

Jeff wrote: ↑August 2nd, 2024, 8:37 pm The problem is, you can't set a username in VLC, the URL can not be in any other form than http://:<Password>@localhost:<Port>/, which sucks.
This is really strange, if you're right. I mean, why would VLC even use such authentication if you can't input a non empty username along the password in the first place? But then, googling "VLC empty username" reveals that in the past users were unhappy that they could NOT use an empty username at the time, so the opposite of what you need. Take a look at those results, they might help you one way or another. Also, you could post on the VLC forum about the need to use a non empty username (if that's even the root issue, of course) and see what they respond. If the approach is still tricky, then obviously authentication using a base64 header like you mentioned would be preferable.
Jeff wrote: ↑August 2nd, 2024, 8:37 pm I wanted other skin authors to just copy paste the MAIN .ini and be done, nothing else, if they wanna implement what I'm writing into their own suites.
Oh, I see - you wanted to do things exclusively from the .ini and without having to copy any .lua file ... while still using Lua, lol. Yeah, I think duplicating the skin folder is the sane thing to do in this case indeed.
Jeff wrote: ↑August 2nd, 2024, 8:41 pm I still have a weird behavior with WebParser though, because it's pooling every second, it reports stuff in the log every second.
The problem appears if you refresh the skin during a period where WebParser writes to the log. If you refresh during that, congrats, you broke the Rainmeter Log, now nothing is getting reported anymore and the WebParser measure eventually fails.
https://imgur.com/a/gnxYiev
I made a video showing the problem. I don't really think there is a way around this, WebParser wasn't made for stuff like this.
Yeah, frequent overlapping of WebParser requests do indeed make it "hang", this is a known issue. I do think that there are some ways to avoid this though.

While you can't control when the user refreshes the skin, you can in fact control after how much time after the skin load / refresh does the WebParser begins to request data, via starting with its measure disabled and enabling it only after a "safe period" (say, 1+ seconds) has passed. All you need is a Calc measure counting time since refresh and some IfCondition.

Or, you can even use Formula=Counter in that Calc measure, to detect if it's the load time or refresh time and act accordingly (e.g. request data right away if the former, wait a bit until doing that if the latter), given how that function works.
Profiles: Rainmeter Profile β—‡ DeviantArt Profile β—† Suites: MYiniMeter β—† Skins: Earth