luci84tm
luci84tm

Reputation: 3

Press javascript button on webpage using curl & bash

My first post here, so please if this topic is answered elsewhere let me know. I found similar posts but didn't manage to use them to solve my problem.

Background: I use a IPTV service provider which offers the possibility to watch TV Channels on my RPi running KODI. SO this provider promotes usage of a IPTV Simple Client together with some playlist urls. Making thinks shorter, this playlists are generated for my account only and are bound to my public IP address. Problem, I don't have and want to have a fix Public IP address, so everytime my ISP resets my DSL connection I have to login on the IPTV provider page and press on a so called "Update IP" button. That's annoying!! I want to automate that with a bash script which would be triggered by my dynamic dns service update which runs on a regular basis on my rpi.

What I managed so far: - use a bash command with CURL to login on the webpage and save the cookie into a text file. with this:

 curl -c cookie.txt -d "[email protected]" -d "pass=mypass" http://www.spicetvbox.ro/user/login

And then I tried several ways to press that "Update IP" button with:

 curl -b cookie.txt  -d "press=UPDATEIP" http://www.spicetvbox.ro/user/xbmc
 curl -b cookie.txt  -d "button=Upfate IP" http://www.spicetvbox.ro/user/xbmc
 curl -b cookie.txt -X POST   http://www.spicetvbox.ro/user/xbmc

And allot of other commands like this. I tried to use firebug to inspect the button element.. and this is the html from firebug:

<form id="formXBUpd89942" class="jqValidation" role="form" novalidate="novalidate" action="http://www.spicetvbox.ro/user/xbmc" method="post">
<input type="hidden" value="UPDATEIP" name="run">
<input type="hidden" value="89942" name="id">
<button class="btn btn-info btn-xs" type="submit">
<i class="fa fa-refresh"></i>
  Update IP
</button>

Please give me some advice on how to press that button from CURL.

Upvotes: 0

Views: 5378

Answers (1)

Tom Fenech
Tom Fenech

Reputation: 74685

You don't really need to click the button - you need to submit the form, or at least achieve the same effect.

Use cURL to do an HTTP POST to http://www.spicetvbox.ro/user/xbmc - something like this:

curl -b cookie.txt --data "run=UPDATEIP&id=89942" http://www.spicetvbox.ro/user/xbmc

This data is taken from the value of the form fields and the URL is taken from the action attribute of the form element. When --data (equivalent to -d) is specified, cURL performs a POST.

Upvotes: 1

Related Questions