Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luci2-io-helper: use for config download #5

Closed
feckert opened this issue Mar 16, 2016 · 9 comments
Closed

luci2-io-helper: use for config download #5

feckert opened this issue Mar 16, 2016 · 9 comments

Comments

@feckert
Copy link
Contributor

feckert commented Mar 16, 2016

Hello jow,

i am working on a page to download/upload conifguration. I have now some problem to understand the luci2-io-helper to download/upload the sysupgrade.tar.gz. Can you explain what i have to do to dowload/uploade a sysupgrade.tar.gz?

Is it possible to test it with curl (using the l2-session)

Kind Regards

Flo

@jow-
Copy link
Owner

jow- commented Mar 18, 2016

First make sure there is an access scope defined for the rpcd session (http://git.openwrt.org/?p=project/luci2/ui.git;a=blob;f=luci2/share/acl.d/luci2.json#l168)

File Upload

Best take a look at the old prototype code here: http://git.openwrt.org/?p=project/luci2/ui.git;a=blob;f=luci2/htdocs/luci2/view/system.upgrade.js#l128 and here: http://git.openwrt.org/?p=project/luci2/ui.git;a=blob;f=luci2/htdocs/luci2/ui.js#l123

In order to upload an arbitrary file you need to issue a POST request to /cgi-bin/luci-upload and supply these parameters:

  1. sessionid - the l2-session id value
  2. filename - the intended destination filepath
  3. filemode - the intended destination permission in octal, e.g. 0600 - optional
  4. filedata - the actual file data

Fields 1-3 must precede field 4 for the upload request to get accepted and the encoding must be multipart/form-data.

Backup Download

A backup download is easy to trigger by simply issuing a POST request to /cgi-bin/luci-backup with the sessionid parameter set to the l2-session id.

@jow-
Copy link
Owner

jow- commented Mar 18, 2016

Example for a file upload

$ echo "Hello" > /tmp/test.txt
$ md5sum /tmp/test.txt 
09f7e02f1290be211da707a266f153b3  /tmp/test.txt
$ curl -k -F "sessionid=b7e17a670e5637668fa6a5c79c3f2c6e" -F "filename=/tmp/foo.txt" -F "filemode=0400" -F "filedata=@/tmp/test.txt" https://192.168.1.1/cgi-bin/luci-upload
{
    "size": 6,
    "checksum": "09f7e02f1290be211da707a266f153b3"
}

When you then check your router via SSH:

$ ssh root@jj.ggdns.de

BusyBox v1.24.1 (2016-01-24 13:30:56 CET) built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 DESIGNATED DRIVER (Bleeding Edge, r48476)
 -----------------------------------------------------
  * 2 oz. Orange Juice         Combine all juices in a
  * 2 oz. Pineapple Juice      tall glass filled with
  * 2 oz. Grapefruit Juice     ice, stir well.
  * 2 oz. Cranberry Juice
 -----------------------------------------------------
root@jj:~# ls -lh /tmp/foo.txt 
-r--------    1 root     root           6 Mar 18 16:09 /tmp/foo.txt
root@jj:~#

@jow-
Copy link
Owner

jow- commented Mar 18, 2016

Example for a backup download

$ curl -k -F "sessionid=b7e17a670e5637668fa6a5c79c3f2c6e" https://192.168.1.1/cgi-bin/luci-backup

@feckert
Copy link
Contributor Author

feckert commented Mar 18, 2016

Hello jow,

Thanks for help.
Will try this after easter holiday

Best regards

Flo
Am 18.03.2016 4:13 nachm. schrieb "Jo-Philipp Wich" <
notifications@github.com>:

Example for a backup download

$ curl -k -F "sessionid=b7e17a670e5637668fa6a5c79c3f2c6e" https://192.168.1.1/cgi-bin/luci-backup


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/jow-/luci-ng/issues/5#issuecomment-198403802

@feckert
Copy link
Contributor Author

feckert commented Mar 30, 2016

Hello Jow,

i have tested the backup as you suggest. With your curl line it is not working as expected. I always get "Backup permission denied". I think the reason is that the Content-Type was set twice first to "application/x-www-form-urlencodedand" and then "multipart/form-data" ( I have added a --verbose option to command)

My line is was to get the backup file as expected
"curl -k --data "sessionid=2dd09c999867dd6c7c9a206aec22a734" -H "Content−Type:application/x-www-form-urlencoded" https://192.168.0.50/cgi-bin/luci-backup > backup.tar.gz"

But something is already is strange because it takes a long time and after that i get "curl: (18) transfer closed with outstanding read data remaining". But the backup file is complete and not corrupted? I think curl does not recognize the end of the transmission.

Regards

Flo

@feckert
Copy link
Contributor Author

feckert commented Apr 8, 2016

Hello Jow,

I have made a backup page. To download and upload a backup. Additional it is possible to edit the file /etc/sysupgrade.conf for. I am not sure if this meets your needs. Do you want a patch or should i make a pull request?

Additionally the problem with luci-backup to download the backup file is still present i am unable to solve the issue that the download take a long time. The curl request stops with a "curl: (18) transfer closed with outstanding read data remaining". But the backup.tar.gz is not corrupted :-)

Regards

Flo

@jow-
Copy link
Owner

jow- commented Apr 8, 2016

@feckert Ignore the error 18 for now, I believe its an issue around content-length/chunked encoding/http 1.1

Please do a PR for this feature!

@feckert
Copy link
Contributor Author

feckert commented Jun 28, 2016

Hello @jow- ,

i did a PR #11 for this issue. if it is integrated we should close this issue.

Regards

Flo

@jow-
Copy link
Owner

jow- commented Jun 28, 2016

#11 got merged now.

@jow- jow- closed this as completed Jun 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants