Code Monkey home page Code Monkey logo

Comments (9)

jow- avatar jow- commented on August 26, 2024

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.

from luci-ng.

jow- avatar jow- commented on August 26, 2024

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 [email protected]

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:~#

from luci-ng.

jow- avatar jow- commented on August 26, 2024

Example for a backup download

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

from luci-ng.

feckert avatar feckert commented on August 26, 2024

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" <
[email protected]>:

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

from luci-ng.

feckert avatar feckert commented on August 26, 2024

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

from luci-ng.

feckert avatar feckert commented on August 26, 2024

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

from luci-ng.

jow- avatar jow- commented on August 26, 2024

@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!

from luci-ng.

feckert avatar feckert commented on August 26, 2024

Hello @jow- ,

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

Regards

Flo

from luci-ng.

jow- avatar jow- commented on August 26, 2024

#11 got merged now.

from luci-ng.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.