where to ask question about adding a web service?

Post new topic   Reply to topic    DD-WRT Forum Index -> Ralink SoC based Hardware
Goto page Previous  1, 2
Author Message
Specimen
DD-WRT User


Joined: 22 Mar 2013
Posts: 112

PostPosted: Thu Jul 14, 2016 20:46    Post subject: Reply with quote
rtayek wrote:
Specimen wrote:
...

I really don't think you are going about this the right way.
I don't know if you ended up using NCS or httpd, but if it's teh first you use the variables it provides in a script, if it's the second you set it up also in a script.
In Administration > Commands > Start up/Custom script.

And also use the scheduler in Administration > Management > Cron.

All this requires Bash knowledge.

On the other hand, modifying the code, which seems to be your method, might originate bugs, conflicts and makes it impossible to upgrade.


i may be going down the wrong track.

i want to see if i can use the existing httpd without any modifications to it. the routers admin pages save and restore state. httpd uses nvram to persist state. i am trying to find the code or program that does this for the state that gets posted to the admin pages.

i understand sh.

i would like to add my own web page that saves and restores one string variable. this is for some dedicated android tablets talking to a dedicated router.

there are dozens of .webconfig files in www/ that fool around with nvram and capture, so i assume that this is where that persistence gets done, but i don't know where capture is defined.

is there any docs on how the .webconfig filed get used or the capture function?

thanks


The only way to save this state is through a startup script, this script is saved in the NVRAM.

The startup script is just bash, meaning, it's a set of command line parameters for the Linux CLI. Somewhat similar to batch in Windows CLI.

So, to start an instance of httpd you would type: 'httpd <parameters>' on the console, this can be automated via a startup script that starts httpd with those parameters every time.

Let me give you an example of a startup script that I created that installs the program cURL on my router every time (this is necessary because I need cURL for other scripts and dd-wrt doesn't come with it, since this router, ASUS RT-N10+ B1, has no way to had any other persistent storage I use NVRAM for this).

Code:

if test -d /tmp/bin; then exit 0; fi

# Download and install curl
PATH2PKG="http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/rt305x/packages/base/"
sleep 30
until ping -c 1 openwrt.org &> /dev/null && ping -c 1 curl.haxx.se &> /dev/null; do sleep 30; done
mkdir /tmp/test
cd /tmp/test
until wget -qT 30 "$PATH2PKG"; do sleep 2; done
CURLP=$(cat index.html | grep curl | awk -F '"' '{print $2}' | head -n 1)
LIBCURLP=$(cat index.html | grep libcurl | awk -F '"' '{print $2}' | head -n 1)
LIBPOLARP=$(cat index.html | grep libpolarssl | awk -F '"' '{print $2}')
until wget -qT 30 "$PATH2PKG""$CURLP"; do sleep 2; done
until wget -qT 30 "$PATH2PKG""$LIBCURLP"; do sleep 2; done
until wget -qT 30 "$PATH2PKG""$LIBPOLARP"; do sleep 2; done
tar -zxf $CURLP
tar -zxf data.tar.gz
rm data.tar.gz
tar -zxf $LIBCURLP
tar -zxf data.tar.gz
rm data.tar.gz
tar -zxf $LIBPOLARP
tar -zxf data.tar.gz
mv usr/* /tmp
cd ..
rm -rf test
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/tmp/lib
export PATH=${PATH}:/tmp/bin
until curl -k -s -m 30 -o /tmp/cacert.pem https://curl.haxx.se/ca/cacert.pem; do sleep 2; done
sleep 2
exit
Sponsor
Specimen
DD-WRT User


Joined: 22 Mar 2013
Posts: 112

PostPosted: Thu Jul 14, 2016 20:48    Post subject: Reply with quote
You can create any file from the startup script stored in NVRAM, like an index.html, using the command echo on the startup script, like this:

Code:

# Create .profile
echo 'export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/tmp/lib
export PATH=${PATH}:/tmp/bin
export CURL_CA_BUNDLE=/tmp/cacert.pem' > /tmp/root/.profile


And then you point httpd to the file/folder via the start parameters.
rtayek
DD-WRT Novice


Joined: 02 Jul 2016
Posts: 23

PostPosted: Sun Jul 17, 2016 3:52    Post subject: Reply with quote
Specimen wrote:
...

The only way to save this state is through a startup script, this script is saved in the NVRAM. ...

So, to start an instance of httpd you would type: ...



i need to respond to a get or a post.

i don't see how a script run at startup is going to help me.

sorry for being so dense.

naict, the data i am after is sent like https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_and_retrieving_form_data. the query string from a get gets passed into do_file. which i suppose i can get from a script.

i can't see how the post data get used in the http://svn.dd-wrt.com/browser/src/router/httpd/httpd.c though.

i am looking for the code that the existing admin web pages use to process that data.


thanks
rtayek
DD-WRT Novice


Joined: 02 Jul 2016
Posts: 23

PostPosted: Sun Jul 17, 2016 6:50    Post subject: Reply with quote
perhaps you are suggesting an approach like http://www.dd-wrt.com/phpBB2/viewtopic.php?t=729&sid=a5104a89acdd8ef195cc5fe372827c6e?
Specimen
DD-WRT User


Joined: 22 Mar 2013
Posts: 112

PostPosted: Sun Jul 17, 2016 12:50    Post subject: Reply with quote
Quote:
i need to respond to a get or a post.


Do you really? Maybe you should think in 'first principle' terms, of, globally, think of what you want to achieve, you aren't looking for a solution to a problem, you think you already have a solution and you are looking for a problem. Wink

You should start with what you can do with the stock dd-wrt, namely, using something simple as nocatsplash, because you might have more flexibility on the Android side. And in that case sending a POST or a GET might not be the solution to your problem.

I would stop trying to look at the httpd code and how it controls the webui because you can't control or tap into that without modifying the code.

As for what exact approach I would suggest, to tell you truth I haven't really given much thought about your specific case (and I won't), I just got the general idea, and I know the way you started going about this is the wrong approach. Again, I'm not proposing a solution, I'm just suggesting you take a different approach that starts from what you can easily do in DD-WRT.

The script I posted is a example of how: 1) you can create any text file from a a script, 2) the potential of the startup script, in the specific case, used to install software on the router.
rtayek
DD-WRT Novice


Joined: 02 Jul 2016
Posts: 23

PostPosted: Mon Jul 18, 2016 5:51    Post subject: Reply with quote
Specimen wrote:
Quote:
i need to respond to a get or a post.


Do you really? Maybe you should think in 'first principle' terms, of, globally, think of what you want to achieve, you aren't looking for a solution to a problem, you think you already have a solution and you are looking for a problem. Wink


what i want to achieve is sending data that persists across http sessions (but not across router power cycles) and retrieving that data, so get and post https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_and_retrieving_form_data came to mind initaly.

Specimen wrote:


You should start with what you can do with the stock dd-wrt, namely, using something simple as nocatsplash, because you might have more flexibility on the Android side. And in that case sending a POST or a GET might not be the solution to your problem.


i was initially turned off by the hot spot stuff as it did all kinds of things that i do not need and i did not want to fire up another service.

also, what else would i do over http besides a get or a post?

Specimen wrote:

I would stop trying to look at the httpd code and how it controls the webui because you can't control or tap into that without modifying the code.



yes, it seems to be difficult to do much with that http://www.devttys0.com/2011/09/modifying-the-dd-wrt-gui/.

Specimen wrote:

As for what exact approach I would suggest, to tell you truth I haven't really given much thought about your specific case (and I won't), I just got the general idea, and I know the way you started going about this is the wrong approach. Again, I'm not proposing a solution, I'm just suggesting you take a different approach that starts from what you can easily do in DD-WRT.

The script I posted is a example of how: 1) you can create any text file from a a script, 2) the potential of the startup script, in the specific case, used to install software on the router.


ok, how about a mypage script https://search.yahoo.com/yhs/search;_ylt=AwrTcdNwaIxXM_oARxgnnIlQ;_ylc=X1MDMTM1MTE5NTY4NwRfcgMyBGZyA3locy1tb3ppbGxhLTAwMQRncHJpZANTTzNwZGhSclJKMk9kczdZenYxTXJBBG5fcnNsdAMwBG5fc3VnZwMwBG9yaWdpbgNzZWFyY2gueWFob28uY29tBHBvcwMwBHBxc3RyAwRwcXN0cmwDBHFzdHJsAzMwBHF1ZXJ5A2RkLXdydCUyMG15cGFnZSUyMGFkZCUyMHNjcmlwdAR0X3N0bXADMTQ2ODgxOTYwNg--?p=dd-wrt+mypage+add+script&fr2=sb-top-search&hspart=mozilla&hsimp=yhs-001?

can i get the post data in a script that i add to one of the hotspots? or is there some perl or php or javascript running with those?

thanks
Specimen
DD-WRT User


Joined: 22 Mar 2013
Posts: 112

PostPosted: Mon Jul 18, 2016 20:08    Post subject: Reply with quote
There other methods besides post or get, you can set a cookie strictly using HTML. And you can also use JScript, as that is all processed on the client side.

Code:
<meta http-equiv="set-cookie" content="___________">


Instead of asking me about mypage script, why don't you try it?
rtayek
DD-WRT Novice


Joined: 02 Jul 2016
Posts: 23

PostPosted: Thu Jul 21, 2016 15:10    Post subject: Reply with quote
Specimen wrote:
There other methods besides post or get, you can set a cookie strictly using HTML. And you can also use JScript, as that is all processed on the client side.

Code:
<meta http-equiv="set-cookie" content="___________">


Instead of asking me about mypage script, why don't you try it?


the cookie might work.

i will look at the mypage stuff.

thanks
rtayek
DD-WRT Novice


Joined: 02 Jul 2016
Posts: 23

PostPosted: Fri Jul 22, 2016 7:41    Post subject: Reply with quote
rtayek wrote:
... i will look at the mypage stuff. ...


mypage seems to need https://www.dd-wrt.com/wiki/index.php/JFFS.

i have DD-WRT v24SP2- (11/05/13) std (SVN revision 22750), but there is no mention of jffs on adminstration|management. there is a line: show_layer_ext(document.setup.enable_jffs2, 'idjffs2', 0 == 1); in the page source.

i did an nvram set enable_jffs2=1, and nvram show | grep jffs says: enable_jffs2=1. i restarted the browser, bit still no jffs support in the web page.

i did an nvram commit and cycled power on the router, still no joy Sad

thanks
Specimen
DD-WRT User


Joined: 22 Mar 2013
Posts: 112

PostPosted: Fri Jul 22, 2016 10:38    Post subject: Reply with quote
The instructions are for routers that have external storage. But I already showed you before how to use the NVRAM to write files to /tmp/ using the startup command and echo.

You can research by yourself what JFFS2 is for and how relates to external storage, don't expect me to explain it.

This project seems to be too ambitious for your understanding of DD-WRT and your willingness to research for yourself.
rtayek
DD-WRT Novice


Joined: 02 Jul 2016
Posts: 23

PostPosted: Sat Jul 23, 2016 11:45    Post subject: Reply with quote
Specimen wrote:
The instructions are for routers that have external storage. But I already showed you before how to use the NVRAM to write files to /tmp/ using the startup command and echo.

You can research by yourself what JFFS2 is for and how relates to external storage, don't expect me to explain it.

This project seems to be too ambitious for your understanding of DD-WRT and your willingness to research for yourself.


i did write a startup script that created a web page in /www/user/. the browser can retrieve this file.

but i still have no idea how to access the query or the form submit data from the html file or deal with a cookie.

thanks
Specimen
DD-WRT User


Joined: 22 Mar 2013
Posts: 112

PostPosted: Sat Jul 23, 2016 12:38    Post subject: Reply with quote
rtayek wrote:
Specimen wrote:
The instructions are for routers that have external storage. But I already showed you before how to use the NVRAM to write files to /tmp/ using the startup command and echo.

You can research by yourself what JFFS2 is for and how relates to external storage, don't expect me to explain it.

This project seems to be too ambitious for your understanding of DD-WRT and your willingness to research for yourself.


i did write a startup script that created a web page in /www/user/. the browser can retrieve this file.

but i still have no idea how to access the query or the form submit data from the html file or deal with a cookie.

thanks


You don't know enough HTML/JS to do this. This is not an HTML/JS forum.

And quite frankly I haven't seen any good reason as to why NoCatSplash is not suitable for you, you can also write the webpage clients access in NCS. And the concern about having another service running is ridiculous, how would that be different than running another instance of httpd.

You decided to pick the most difficult path and you are out of your depth.

PS
Besides you are using a +2 year old version of DD-WRT, which means you don't really know much about DD-WRT releases. DD-WRT wiki, documentation and site is outdated, releases work in a permanent beta state and can be found here ftp://ftp.dd-wrt.com/betas/2016/
The most updated information is found scattered in the forums.
You are using a poorly documented tool, for the first time. to achieve something that is non-standard and you refuse to try the standard tools it comes with.

Your best bet would be to find something similar someone had already implemented and documented.
Goto page Previous  1, 2 Display posts from previous:    Page 2 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Ralink SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum