How to input a number in a web page and pass to a script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to input a number in a web page and pass to a script?
# 1  
Old 09-18-2010
How to input a number in a web page and pass to a script?

I am working on an embedded linux router and trying to make a webpage where the user can input a desired number of CPE and have a script update that number on the router. I have a CLI where I can log in and type the following to change that number

echo "20">/proc/net/dbrctl/maxcpe which then sets the MaxCPE at 20

Here is the code for the webpage that I am using to test this

Quote:
<B>Set Max CPE</B>
<form method="get" action="cpe.sh">
<select size="3" name=cpe>
<option>5</option>
<option>10</option>
<option>20</option>
<option>32</option>
<option>64</option>
</select>
<input type="submit">
</form>
</body>
</html>
And here is the script that it is calling
Quote:
#!/bin/sh
echo \"$cpe\">/proc/net/dbrctl/maxcpe
It does not work and I am confused as to why or what I need to change. I am trying to set the webpage up to either select a number from a list like I have setup there or to have an input box, and then have that number passed into the script and have it execute as if I had typed in the string in the command line interface

So if I put let's say 4 into the input box then click the button it would be as if I was in the console/command line and typed
echo "4">/proc/net/dbrctl/maxcpe

The number has to keep the quotes around it but how do I get the number I put in the webpage placed into a variable named something like cpe and then have that number in that variable echoed like above.

When I ran this in a webpage it would output cpe.sh?cpe=20 if I select 20 but ti would not update the actual number of CPE passed to /proc/net/dbrctl/maxcpe

Thanks for any help guys, I am new to this and feel lost.
# 2  
Old 09-18-2010
Sorry, I am on my mobile phone at McDonalds having some fast road trip food so maybe I missed something....

Are you sure your webserver can write to your /proc filesystem?

If so, is that really what you want to do, from a security perspective?
# 3  
Old 09-19-2010
I am just trying to get the webpage to call the script or pass the variable to the script and execute it just from inputting a number and clicking a button in the webpage.

Yes I am sure about the security aspect of this

Also I made a script right on the router called cpe.sh with one line:

echo "19">/proc/net/dbrctl/maxcpe

just to test it and then I ran it right on the router and it wrote 19 into the maxcpe just fine. The only problem I guess is how to properly read the input from a user and then have it passed to the script and executed properly like the above script but put the users input in place of the 19. Any suggestions?
# 4  
Old 09-19-2010
Did you try:
Code:
#!/bin/sh
echo "$cpe">/proc/net/dbrctl/maxcpe

# 5  
Old 09-19-2010
or

Code:
echo $cpe>/proc/net/dbrctl/maxcpe

What will you get, if you run:

Code:
echo $cpe

# 6  
Old 09-19-2010
Quote:
Originally Posted by BobTheBulldog
I am working on an embedded linux router and trying to make a webpage where the user can input a desired number of CPE and have a script update that number on the router. I have a CLI where I can log in and type the following to change that number

echo "20">/proc/net/dbrctl/maxcpe which then sets the MaxCPE at 20

Here is the code for the webpage that I am using to test this
Code:
<B>Set Max CPE</B>
<form method="get" action="cpe.sh">
<select size="3" name=cpe>
<option>5</option>
<option>10</option>
<option>20</option>
<option>32</option>
<option>64</option>
</select>
<input type="submit">
</form>

And here is the script that it is calling
Code:
#!/bin/sh
echo \"$cpe\">/proc/net/dbrctl/maxcpe

It does not work and I am confused as to why or what I need to change.

The information in the form is passed to the script in the variable $QUERY_STRING.

You need to parse that string to extract the variable names and values.

I use this function:
Code:
parse_query() ## probably requires bash
{
    local var val
    local IFS='&'
    unset $*
    vars="&$*&"
    [ "$REQUEST_METHOD" = "POST" ] && read QUERY_STRING
    set -f
    for item in $QUERY_STRING
    do
      var=${item%%=*}
      val=${item#*=}
      val=${val//+/ }
      case $vars in
	  *"&$var&"* )
              case $val in
                  *%[0-9a-fA-F][0-9a-fA-F]*)
                       val=$( printf "%b." "${val//\%/\\x}" )
                       val=${val%.}
              esac
              eval "$var=\$val"
              ;;
      esac
    done
    set +f
}

I call it with the names of the variables I want set, e.g.:

Code:
parse_query cpe

# 7  
Old 09-19-2010
Quote:
Originally Posted by BobTheBulldog
I am just trying to get the webpage to call the script or pass the variable to the script and execute it just from inputting a number and clicking a button in the webpage.

Yes I am sure about the security aspect of this

Also I made a script right on the router called cpe.sh with one line:

echo "19">/proc/net/dbrctl/maxcpe

just to test it and then I ran it right on the router and it wrote 19 into the maxcpe just fine. The only problem I guess is how to properly read the input from a user and then have it passed to the script and executed properly like the above script but put the users input in place of the 19. Any suggestions?
One obvious problem is that when you test the script from the command line, you are not running with the same userid as your web server is running. To write to the proc file system, you must be root (technically, UID 0).

It is highly unlikely your web server is running as root (it should not be, and never is); hence you cannot just pass a variable via your web server and write to the proc file system.

What is the userid you are using when you test from the command line?

Are you running Apache? What is the userid of the web server when it runs?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: Page number with total number of pages, EG Page 1 of 5

So I've worked how to add page numbers based on regex. It's using the footer text. How do we get the total amount added so we have page number with the total number of pages? Desired output: Page No:1 of 5 Thanks in advance. (15 Replies)
Discussion started by: tugar
15 Replies

2. Shell Programming and Scripting

Refresh web page in bash script

hello, I am trying to refresh my web page which is created in bash script. I have a HTML page which when press a button calls a bash script. this bash script created the same page with dynamic data. When pressing the button I am calling to a function that set time out of 7 seconds and and after... (1 Reply)
Discussion started by: SH78
1 Replies

3. Shell Programming and Scripting

Random web page download wget script

Hi, I've been attempting to create a script that downloads web pages at random intervals to mimic typical user usage. However I'm struggling to link $url to the URL list and thus wget complains of a missing URL. Any ideas? Thanks #!/bin/sh #URL List url1="http://www.bbc.co.uk"... (14 Replies)
Discussion started by: shadyuk
14 Replies

4. Shell Programming and Scripting

script for adding page number before page breaks

Hi, If there is an expert that can help: I have many txt files that are produced from pdftotext that include page breaks the page breaks seem to be unix style hex 0C. I want to add page numbers before each page break as in : Page XXXX Regards antman (9 Replies)
Discussion started by: antman
9 Replies

5. HP-UX

Help running a unix script from a web page

First, let me state that I am completely out of my realm with this. I have a server running HPUX. I'm not even sure if this can be considered a UNIX question and for that let me apologize in advance. I need to create a web page where a client can input 2 variables (i.e. date and phone number).... (0 Replies)
Discussion started by: grinds
0 Replies

6. Shell Programming and Scripting

How to pass data from server (CGI script) to client (html page)

Hi I know how to pass data from client side (html file) to server using CGI script (POST method). I also know how to re-create the html page from server side after receiving the data (using printf). However I want to write static pages on client side (only the structure), and only to pass... (0 Replies)
Discussion started by: naamabm
0 Replies

7. Shell Programming and Scripting

Perl script to copy contents of a web page

Hi All, Sorry to ask this question and i am not sure whether it is possible. please reply to my question. Thanks in advance. I need a perl script ( or any linux compatible scripts ) to copy the graphical contents of the webpage to a word pad. Say for example, i have a documentation site... (10 Replies)
Discussion started by: anand.linux1984
10 Replies

8. Shell Programming and Scripting

how to redirect to a web-page by shell script

Dear all, I am calling a korn shell script(CGI script) by a web-page. This shell script do some checking in a unix file and return true or false. Now within the same script, If it returns true then I want to redirect to another web-page stored in htdocs directory. Example: Login page sends a... (3 Replies)
Discussion started by: ravi18s
3 Replies

9. Shell Programming and Scripting

How to direct a script to a new web page after a script got completed?

Hi , I have a cgi code with shell script on it.I am submitting a form in the first.cgi.These values are posted to second.cgi.Second.cgi do some process with these values. After that i want to direct my page from second.cgi to first.cgi. What is the command i can use from cgi(shell) script? ... (2 Replies)
Discussion started by: rajbal
2 Replies

10. Shell Programming and Scripting

running shell script thru WEB page ....

....passing variable via list... here 's the HTML code extract : **************** <form method=post action=http://servername/cgi-bin/cgi-comptage_diff.ksh> <table border...........> .............. </table> <table bgcolor=#FFFFFF width="980"> ... (6 Replies)
Discussion started by: Nicol
6 Replies
Login or Register to Ask a Question