There is a local area network, machines are in same address space.
I have one manager node which controls other machines. Is there a way to execute a script on any of these machines? (Note: SSH is not enabled and we cannot install any code on these machines except manager machine)
Currently, its done by opening a http session in browser, and then providing username and password, followed by the buttons on the page for each script. I need to automate this in Go
. Is this possible?
Eg of one such button:
`<form ACTION="enableSsh.cgi" method="get">
<b>
<input type="SUBMIT" VALUE="Enable SSH Service">
<input type=hidden name=stamp value="########">
<input type=hidden name=token value="********">
<input type=hidden name=frame value="$%$%$%$%">
</b>
</form>`
Currently, its done by opening a http session in browser, and then providing username and password, followed by the buttons on the page for each script. I need to automate this.
I think you don't need to care about interface at all, until you find a way to execute scripts in backend. From my point of view, it's impossible to execute scripts on the machine without setting up at least SSHD on them. To have your script executed, you need to have some kind of server working on remote machine to handle your requests.
Also, have a look at Configuration Management Systems, such as: Ansible, SaltStack, and so on, because even SSH seems to be a too low-level tool for your use-case.
Yes, it's possible to do solely with the Go standard library.
The things to study, in this order:
How HTML forms are encoded and sent to HTTP servers by the Internet browsers.
The things to get familiar with:
GET
and POST
request methods.When a HTML form is submitted, the data sent to the HTTP server is typically encoded in one of two forms:
application/x-www-form-urlencoded
encoding is used to make GET
requests andmultipart/form-data
encoding is used to make POST
requests.In your example, the form has the method="get"
attribute which indicates the form submission uses GET
and hence the application/x-www-form-urlencoded
encoding for its data.
The net/http
package in the Go standard library which can be used to make HTTP requests.
With all this things in place, you need to make a HTTP GET
request to a proper server and URL, with a proper set of parameters.
The server is the same from which you get that HTML page. The URL will be /enableSsh.cgi
.
Now you just need to make up the request and to it.
Here is one example but really googling for golang+get+query+with+parameters
will bring you myriads of similar examples. The query parameters are those form fields—stamp
, token
and frame
, and their values are, well, what is about to be submitted.
In the case you'll need to POST
a form with the multipart/form-data
encoding, you'd use the mime/multipart
package in the Go standard library, whose Writer
type can be used to build a stream of data encoded according to the multipart/form-data
rules.