LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Invoking UNIX shell commands from HTML webpage (https://www.linuxquestions.org/questions/programming-9/invoking-unix-shell-commands-from-html-webpage-807205/)

ixcel87 05-11-2010 02:25 PM

Invoking UNIX shell commands from HTML webpage
 
Hello all,

I have a few questions regarding HTML, UNIX and Javascript. I've been tasked with creating a fairly simple webpage that takes a few inputs. Each input must correspond to an argument in a UNIX command running on a server.

Here's the background. On a UNIX server we have a script (.ksh) that takes 3 arguments. The result of the script is a data file which is FTP'ed to an external server. Let's forget about the FTP portion for now. I would like to know where I should begin.

What I know so far:
1) I will need HTML to create the webpage. Skill level is high
2) I will need Javascript to make my webpage more interactive. Skill level is high.
3) I will need to understand the UNIX environment. Skill level is high.

What else will I need to complete this task?

Thanks in advance!

AlucardZero 05-11-2010 02:45 PM

You'll need to unsderstand the glue between the "HTML" page and the Unix environment and how to set up your Web server to execute the script. I say "HTML" because straight HTML can't do this. You'll need a script written in Perl, PHP, Python, Ruby, ... to call the Unix commands. These scripting languages can make generating the HTML require less typing, too.

You'll also need to understand security, input validation, and the like. Having a web-accessible page call Unix commands should be setting off alarm klaxons in your head.

ixcel87 05-11-2010 03:53 PM

So Javascript won't work?

I see that you mentioned a 'web server', must I set up an Apache server?

AlucardZero 05-11-2010 04:02 PM

I don't think JavaScript can call external programs, no, but I don't use it much.

You don't have to use Apache.. you can use Lighttpd, nginx, IIS.. whatever Web server you want. But you generally need a Web server to serve up Web pages.

paulsm4 05-11-2010 04:22 PM

Quote:

I've been tasked with creating a fairly simple webpage that takes a few inputs. Each input must correspond to an argument in a UNIX command running on a server.
The answer is "CGI".

Perl and PHP are two great choices.

Scan through this tutorial (or Google for any of a million others):

http://www.lies.com/begperl/

Quote:

On a UNIX server we have a script (.ksh) that takes 3 arguments. The result of the script is a data file which is FTP'ed to an external server. Let's forget about the FTP portion for now.
Again, the answer is "CGI". For example, in Perl and PHP you could use the "system()" function to execute your script:
http://www.perlmonks.org/?node_id=78523

WARNING:
Executing *any* user commands on the server is a *huge* potential security risk. No matter *how* you do it. Be careful!

Here's another good link:
http://perldoc.perl.org/perlsec.html

Sergei Steshenko 05-11-2010 04:26 PM

Quote:

Originally Posted by ixcel87 (Post 3964858)
...
I would like to know where I should begin.
...

Well, you should begin (if you haven't yet) from understanding:
  1. what creates WEB pages;
  2. what displays WEB pages;
  3. how the entity that displays WEB pages passes back to the entity that creates WEB pages user input;
  4. which of the two entities is the originator from human user point of view.

The originator in the same terms as WRT phone conversation.

ixcel87 05-12-2010 10:35 AM

Thanks guys!

The websites you guys provided are all very helpful. I will try the following:

1) upgrade my ubuntu machine
2) install apache 2.2 on ubuntu
3) create simple webpage
4) create a simple unix script (to be invoked by the webpage)
5) read up on PHP and Perl (not sure with one i will use)

can someone please touch upon the security aspect of this implementation?

from a security perspective, all of my development will be localized to my unix server. all webpages, scripts, etc... will be created and run from one machine; and i will be the only person with access. Of course when i look to implement a bigger solution i will have to think about the security risks.

HasC 05-12-2010 10:45 AM

Quote:

Originally Posted by ixcel87 (Post 3964951)
So Javascript won't work?

I see that you mentioned a 'web server', must I set up an Apache server?

JavaScript won't do, because it's _client-side_ scripting

What the OP needs is _server-side_ scripting: PHP, Perl, Ruby, and the like

Sergei Steshenko 05-12-2010 03:22 PM

Quote:

Originally Posted by ixcel87 (Post 3965856)
Thanks guys!

The websites you guys provided are all very helpful. I will try the following:

1) upgrade my ubuntu machine
2) install apache 2.2 on ubuntu
3) create simple webpage
4) create a simple unix script (to be invoked by the webpage)
5) read up on PHP and Perl (not sure with one i will use)

can someone please touch upon the security aspect of this implementation?

from a security perspective, all of my development will be localized to my unix server. all webpages, scripts, etc... will be created and run from one machine; and i will be the only person with access. Of course when i look to implement a bigger solution i will have to think about the security risks.

The item in red is not quite precisely formulated. Because of the page the user sees he/she will enter some data and/or click on something, and those actions will produce a request to server to do something, e.g. to run a script with the data provided by user.


All times are GMT -5. The time now is 03:56 AM.