Home > Forum > Controllers SlimLine e Netsyst (LogicLab) > Using cURL to access web pages of SlimLine
- This topic has 7 replies, 2 participants and was last updated 1 year, 3 months ago da Sergio Bertana.
-
AuthorPost
-
January 10, 2023 at 5: 03 pm #69174ChiaraParticipant
Given any program on a system SlimLine, called mapped variables:
VAR_GLOBAL Var1 AT %MW100.10 : UINT; Var2 AT %MW100.12 : UINT; Var3 AT %MW100.2200 : UINT; END_VAR
Added a custom page e.g. Values.htm (whose content points to VAR3 ) I can change the values of VAR2200 and VAR1 with:
curl -v -X GET "http://IPPLC/webpages/user/Values.htm?USINT+10=8&USINT+12=7"
I would expect the value of Var3 in the output, instead it returns me:
* Trying IPPLC:80... * Connected to IPPLC (IPPLC) port 80 (#0) * Server auth using Digest with user 'Admin' > GET /webpages/user/Values.htm HTTP/1.1 > Host: 10.7.208.158 > User-Agent: curl/7.85.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 302 Found < Server: Elsist CPU module < Location: /Login.html < Transfer-Encoding: chunked < Connection: close * Closing connection 0
January 10, 2023 at 5: 33 pm #69179Sergio BertanaAdministrator ForumThe concept is correct but probably the page you request in cURL is in a folder accessible only by a logged in user. When you access from the browser you are first asked for authentication and then access the page. If you notice the response contains a 302 code which is a redirect to the login page. I made the sample program cURLExample (Download) where in the LogicLab program I declared 3 global variables:
VAR_GLOBAL Var1 AT %MW100.10 : UINT; Var2 AT %MW100.12 : UINT; Var3 AT %MW100.2048 : UINT; END_VAR
And a web page defined as follows:
<head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>SlimLine - Simple page</title> <style type="text/css"> body {font-family: Arial, Helvetica, sans-serif; font-size: 18px; font-style: normal;} </style> </head> <body> This page is served by the <b>SlimLine</b><br> Var3:<!--["%d", UINT, 2048]--> </body> </html>
I loaded the page with the name Values.htm in C:\Web, the C:\Web folder as you see from screenshot it can also be read by an anonymous user, so with the cURL command:
curl "http://192.168.0.181/Values.htm?UINT+10=8&UINT+12=20"
I value Var1=8 e Var2=20 and the page with the value of is returned to me Var3 which being allocated in DB100.2048 has the value kept in backup when the system is turned off.
C:\Windows\system32>curl "http://192.168.0.181/Values.htm?UINT+10=8&UINT+12=20" <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>SlimLine - Simple page</title> <style type="text/css"> body {font-family: Arial, Helvetica, sans-serif; font-size: 18px; font-style: normal;} </style> </head> <body> This page is served by the <b>SlimLine</b><br> Var3:208 </body> </html>
January 11, 2023 at 3: 25 pm #69228Sergio BertanaAdministrator ForumI add an example to use cURL with authentication so that you can also access pages stored in folders accessible only by logged in users.
The login mechanism uses cookies to recognize the user, therefore the first operation is to log into the system by enabling saving of the returned cookies in a file. The command:
curl -c "C:\Cookie" "http://192.168.0.181/SysCgi/Login.cgi?Username=Admin&Password=Admin&Action=Login"
Log in to the system with credentials Admin:Admin, saving the returned cookies in the file C:\Cookie. Now if we supply the cookie file to the cURL commands, the system will recognize the user and enable access. So assuming that our page Values.htm is now moved to the folder C:\Web\webpages of the system, here we could access it with the command:
curl -b "C:\Cookie" "http://192.168.0.181/webpages/Values.htm?UINT+10=8&UINT+12=20"
In the various commands we can add the parameter -v if we wish to have a return verbose of the operation performed.
Authentication has a lifetime on the system, therefore if you continue to log in, life is automatically refreshed, if there are no logins after about 1 minute the session expires and you need to log in again.
January 12, 2023 at 9: 02 am #69236ChiaraParticipantThanks for the example and the clarifications, so the authentication only takes effect on reading, wouldn't it be more correct to also ignore the requests to perform the value change if you are not authenticated?
January 12, 2023 at 4: 00 pm #69245ChiaraParticipantCan I ask for the correct syntax to use in the htm files to read the OUTPUT status?
"DO1": <!--["%d", BOOL, QX0.1]-->
The DO1 tag with type: BOOL and address %QX0.1 in the plc program shows the status correctly, while on html the value is empty.
January 12, 2023 at 6: 22 pm #69250Sergio BertanaAdministrator ForumFrom web page you cannot access the system I/O you can only access variables allocated in DB100.
So if you want to read the inputs or set the outputs you have to allocate BOOL variables in DB100 and then with a ladder or ST program copy the state of the physical I/Os on the allocated variables.
January 13, 2023 at 8: 43 am #69264ChiaraParticipantThanks for the answer, but the status can be read with:
"PLC_DO" : [<!--[OSID_PLC_DO_ALL]-->] "PLC_DI" : [<!--[OSID_PLC_DI_ALL]-->]
January 13, 2023 at 11: 04 am #69285Sergio BertanaAdministrator ForumThe “OSID_xxxx” TAGs are TAGs that we use to manage our system web pages.
They are not documented as they work we advise against its use because this allows us to modify its functionality at our discretion without impacting any use by customers.
-
AuthorPost
- You must be logged in to reply to this topic.