PHP + Bash script

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

PHP + Bash script

Postby mudasir » Fri Jun 27, 2008 4:14 pm

AOA,

Dear LP members,

I am writing a PHP script, which will take input from users. As soon as the users press enter, the input from the script should become a variable of a bash script that will run some commands.

like if a user enter "bla bla"

a variable should be created and this "bla bla" should be stored in that varialbe, which can be used in a bash script.

As the bash script will be completed, it should be redirected to a HTML or a PHP page with the output of the BASH script.

Looking forward for your help.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
mudasir
Captain
 
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Website: http://www.crystalnetworks.org
Location: Dubai

Re:

Postby LinuxFreaK » Mon Jun 30, 2008 7:54 am

Dear mudasir,
Salam,

What are difficulties you are facing in that ?

Best Regards.
Farrukh Ahmed
LinuxFreaK
Site Admin
 
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
ICQ: 82075802
Website: http://www.linuxpakistan.net/wiki/index.php?pagename=LinuxFreak
WLM: f4fahmed@hotmail.com
Yahoo Messenger: f4fahmed@yahoo.com
AOL: linuxpakistan@aol.com
Location: Karachi

Postby mudasir » Mon Jun 30, 2008 7:57 am

AOA,

Dear Farrukh bhai,

THe PHP script that will take the inpu from user is complete, no i dont know how to convert that input in a bash variable, and start the bash script as the php script starts to work.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
mudasir
Captain
 
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Website: http://www.crystalnetworks.org
Location: Dubai

Re:

Postby LinuxFreaK » Mon Jun 30, 2008 8:10 am

Dear mudasir,
Salam,

mudasir wrote:THe PHP script that will take the inpu from user is complete, no i dont know how to convert that input in a bash variable, and start the bash script as the php script starts to work.


Can you post your php script ?

Best Regards.
Farrukh Ahmed
LinuxFreaK
Site Admin
 
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
ICQ: 82075802
Website: http://www.linuxpakistan.net/wiki/index.php?pagename=LinuxFreak
WLM: f4fahmed@hotmail.com
Yahoo Messenger: f4fahmed@yahoo.com
AOL: linuxpakistan@aol.com
Location: Karachi

Postby mudasir » Mon Jun 30, 2008 8:16 am

Dear Farrukh bhai,

<html><head><title>Directory Search</title></head>
<body><form action="index.php" method="post" name="form1">
Search: <input type="text" name="user">
<BR><input type="submit" value="submit">
</form></body></html>

this is the simple php script that i am trying to write.

Now what ever the user will input, must be processed by a bash script. thats what i want.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
mudasir
Captain
 
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Website: http://www.crystalnetworks.org
Location: Dubai

Postby lambda » Mon Jun 30, 2008 12:57 pm

that's the web page (all html), not the php code.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Postby compucated » Tue Oct 21, 2008 6:30 pm

Don't know either you are not going at right way with PHP coding (as you posted just html code), or don't want to post your php code.

Anyway, you don't need to send your variables toward bash script to execute, you can also execute your php variable directly.

i.e.

Code: Select all

exec("echo $php-variable");


moreover, what I guess you are trying to write front end for MT. isn't it?
if yes, see below this will give you some clues:

Code: Select all

$output = "/ip hotspot user add name=".$values["Login"]." "."password=".$values["Password"]." "."mac-address=".$values["MAC"]." "."profile=".$values["Package"]." "."disabled=".$values["Status"];
exec("/usr/bin/ssh $user@$mt-ip $output 'comment=\"$comments\"'");


Although I finished PHP/MySql based front end for MT database year ago, but I can not post those as they includes some blocks of copyright material.

Best of luck
compucated
Naik
 
Posts: 75
Joined: Mon Oct 13, 2003 5:06 am
WLM: compucated(at)msn(dot)com
Yahoo Messenger: activatedpower(at)yahoo(dot)com
Location: Karachi, Pakistan

Postby lambda » Tue Oct 21, 2008 9:19 pm

what if i wrote "blah; rm /etc/passwd" in the text field?
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Postby compucated » Tue Oct 21, 2008 11:28 pm

lambda wrote:what if i wrote "blah; rm /etc/passwd" in the text field?


I love your witty reply :lol:
httpd.log > Permission Denied

Nothing happen, with default http configuration, as none of http server running as root by default, and in case http server is running with root permissions (not recommended in any way), its gone!

TIP: There is backup of passwd file with "passwd-" or "opasswd".

Although lambda made a fun, but I like to clarify for beginners that PHP permissions laid under http server, all execution's through PHP also execute as a user, with which your httpd is running.
compucated
Naik
 
Posts: 75
Joined: Mon Oct 13, 2003 5:06 am
WLM: compucated(at)msn(dot)com
Yahoo Messenger: activatedpower(at)yahoo(dot)com
Location: Karachi, Pakistan


Return to “%s” Programming

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron