Newbie: Fill/Interact html forms with the Yun

Hello friends. I'm new around here and I've been working with the Yun since 1 mounth. I used it to stream video and watch it outside the localhost password protected (Thanks to sonnyyu!) and I've also used it as a database server, although I still have a few questions about it's security, since I've never worked with databases before.

Now I'm trying to have the Yun sending/filling a forms of a webpage. Is this feasable? I've litle knowledge overall but I didn't find anything helpfull out there. I know it is possible to control the yun via web even the pins I/O's, but I'm wondering how it works the other way around.

Thanks for the help!

Install software:

opkg update
opkg install curl

Post 2 variables:

curl -v -F key1=value1 -F key2=value2 URL

Post one variable and one localfile (upload file) :

curl -v -F key1=value1 -F upload=@localfilename URL

Thanks!

I have 2 pages, webpage.com/a and webpage.com/b. I can only access webpage.com/b if and only if I login to webpage.com/a first. If accessing webpage.com/b without going through the other, I simply get access denied (no redirect to login) via the browser. Once I login at webpage.com/a, I can access the other.

My problem is doing this using the curl command. I can login successfully to webpage.com/a using curl, but then try webpage.com/b and I get access denied.

webpage.com/a has the following structure:

<form action="login.php" method="POST">
   <input type="text" name="user" size="30" maxlength="100" required>
   <input type="password" name="password" size="30" maxlength="100" required />
   <input type="submit" value="Submit" />
</form>

I've tryed using the following:

curl --cookie-jar cookie.txt -F user=someuser -F password=somepassword http://webpage.com/a

curl --cookie cookie.txt http://webpage.com/b
curl --cookie-jar cookie.txt --data "user=someuser&password=somepassword&Submit=OK" http://webpage.com/a

curl --cookie cookie.txt http://webpage.com/b

None seems to keep the session logged in, I assume I'm doing something wrong, I just don't know what and can't find it...

Any help?

Try this one:

curl --cookie-jar cookie.txt --data "user=someuser&password=somepassword&Submit=OK" http://webpage.com/login.php
curl --cookie cookie.txt http://webpage.com/b

OMG. You are a genius! Thanks a lot! I've learned a lot in the past month and you helped a big part on that :slight_smile:

One more thing... I'm assuming that if I want to make this an executable file, I can make a .php? Start with "#!/bin/ash"?

nano /mnt/sda1/curl.sh
#!/bin/ash
curl --cookie-jar cookie.txt --data "user=someuser&password=somepassword&Submit=OK" http://webpage.com/login.php
curl --cookie cookie.txt --cookie-jar cookie.txt http://webpage.com/b
curl --cookie cookie.txt --cookie-jar cookie.txt http://webpage.com/c
...

"--cookie-jar cookie.txt" at sequence curl for keep session.

chmod 755  /mnt/sda1/curl.sh
/mnt/sda1/curl.sh

Hasr:
One more thing... I'm assuming that if I want to make this an executable file, I can make a .php? Start with "#!/bin/ash"?

To make it an executable file, you not only have to give it executable permissions (chmod +x) but you need to make that initial comment (called a shebang) point to the interpreter that is to run the file. The line you give will make ash run the file. You probably want the path to your PHP interpreter instead.

Discussion about Unix shebang