PHP - How Do I Get Php To Invoke A Bash Command When Someone Browses The Page In A Web Browser?
I have a PHP file in /var/www/html/ called foobar.php with the following content: Quote
<?php
I set the permissions of the foobar.php file to different settings. I set the owner and group of foobar.php and /tmp/output to different values. I tried modifying the httpd.conf file. When I placed this stanza in the httpd.conf file QuoteLoadModule php7_module /usr/lib64/httpd/modules/libphp7.so I could not restart the httpd service. I tried using just QuoteLoadModule php7_module modules/libphp7.so But this failed too. I thought PHP would interpret the file regardless of how I access it (e.g., via a web page and with the php command from a Linux terminal). How do I get PHP to invoke a Bash command when someone visits a .php web page? Similar TutorialsHello, I am mounting google drive to my raspberry pi with this command from command line; sudo gdfs -o allow_other /var/www/html/gdfs.creds /media/pi/gdrives İt is working from command line, but it is not work when i execute it from web browser. Here php content; shell_exec("sudo gdfs -o allow_other /var/www/html/gdfs.creds /media/pi/gdrives"); and i changed my sudoers file giving permission www-data. here is my sudoers file content # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL www-data ALL=NOPASSWD: ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d Can anyone tell me what i am doing wrong ? Hi everyone, i'm trying to get it so when i visit my webpage called start.php it executes the command (/bigbrotherbot start) in the terminal which then should start the process on my linux machine. I'm currently using this code Code: [Select] <?php shell_exec('sudo /bigbrotherbot start'); ?> This script doesn't appear to do anything though. I'm very new to php and would really appreciate the help. P.S the file bigbrotherbot is the bash script which works if i actually go to the terminal myself and type /bigbrotherbot start yet when i try to make the php do it it doesnt do anything. any ideas? Hi guys I am putting together an array in PHP for encoding into JSON but how do I make it be like "date": [ and not "date": { ?? Not sure even what to call it or look into. Thanks Hello,
I need to create a variable that also has a function when invoked, much like the OOP __invoke magic method, but with a variable rather than a class object.
#1: Is this possible?
Consider the situation:
$parent->child->variable = "test";
I also want to run a SQL query using $parent->child->variable('= 2'); where this function would look like
function $this->variable($params) {
return mysql_query('SELECT FROM `parent`.`child` WHERE `variable`' . $params);
}
I already know about safety, etc., so I don't need help on that front. I just need to know if a variable can also be used as a function via its own __invoke magic method or something similar?
Hi , I am tring to call user define function of java which parse xsl & xml and executing it using php but it is giving me following error. Versions i am using JDK 1.5,Php 5.3,JavaBridge. Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[o:PhpJBridge]]->XMLXSL((o:String)[o:String], (o:String)[o:String]). Cause: javax.xml.transform.TransformerConfigurationExcep tion: Could not compile stylesheet VM: 1.5.0_18@http://java.sun.com/" at: #-12 com.sun.org.apache.xalan.internal.xsltc.trax.Tran sformerFactoryImpl.newTemplates(Unknown Source) #-11 com.sun.org.apache.xalan.internal.xsltc.trax.Tran sformerFactoryImpl.newTransformer(Unknown Source) #-10 PhpJBridge.XMLXSL(SaxonTest.java:88) #-9 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) #-8 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) #-7 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) #-6 java.lang.reflect.Method.invoke(Unknown Source) #-5 php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1049) #-4 php.java.bridge.Request.handleRequest(Request.java:415) #-3 php.java.bridge.Request.handleRequests(Request.java:491) #-2 php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) #-1 p in http://localhost:8080/EchoServer/java/Java.inc on line 117 hello everybody! This is just basic script, where i try to modify for the needs. I try to play with it. i want to parse some data. The whole script has three parts: 1. Fetching 2. parsing 3. storing i want to put all into one script: Two are allready put together - there all seems to be clear... So this thread is one that asks for the combining two parts of a script - how to invoke a variable between them What has happened untill now: 1st i need to have a connection to database lets say MySQL. I will suggest to use mysqli instead of mysql. Well - okay i safe this db.php $host="localhost"; //database hostname $username="******"; //database username $password="******"; //database password $database="******"; //database name ?> Now i am going to take a new script and save this config.php <?php require_once('db.php'); //call db.php $connect=mysqli_connect($host,$username,$password); //connect to mysql through mysqli if(!$connect){ die("Cannot connect to host, please try later."); //throw error if any problem } else { $select_db=mysqli_select_db($database); //select database if(!$select_db){ die("Site Database is down at the moment, Please check later. We will be back shortly."); // error if cannot connect to database or db does not exist } } ?> Now i have to take care for the script, that takes the files (note this is very basic - it is only a proof of concept. In the real situation i will take cURL since cURL is much much nicer and more elegant and faster etc. <?php require_once('config.php'); // call config.php for db connection $content = file_get_contents("<-here the path to the file goes in-> Position XY! an URL is here "); var_dump($content); $pattern = '/<td>(.*?)<\/td>/si'; preg_match_all($pattern,$content,$matches); foreach ($matches[1] as $match) { $match = strip_tags($match); $match = trim($match); var_dump($match); $sql = mysqli_query("insert into tablename(contents) values ('$match')"); } ?> Note: This is just basic script, where you can modify it for your taste and can play with it. Question: If i have stored the URLs that i want to parse in a local file - how do i "call" them in the script. How do i do the call to file where the URLs (there are more than 2500 URLs that have to be parsed) at the following position: $content = file_get_contents("<-here the path to the file goes in-> Position XY! an URL is here "); The folder with the URLs is stored in the same folder as the scripts reside! Many thanks for all hints and for a starting point! if i have to write more - or if you need more infos - or if i have to be more concrete, just let me know! i love to hear from you! db1 This is a simple permutation function that i was converting from php:
string_gen(){ declare -a chars=('a' 'b') max=4 let length=${#chars[@]}-1 n=0 combination=" " for i in `seq 0 $max`; do let n=($n*($length))+($length) done remainder=0 for i in `seq 0 $n`; do current=$i combination=" " while [[ $current > 0 ]] do remainder=($current%$length) echo remainder if [ $remainder -eq 0 ]; then combination="$combination"${chars[$length]} else combination="$combination"${chars[$remainder]} current = $current/$length fi done done echo $combination }What is wrong with the syntax? Link to PHP version: http://stackoverflow...o-certain-lengt I would like PHP to kick off the following command: Code: [Select] arp -a|sed 's/ /,/g'>arp.csv I also have an executable makeArpFile.sh: Code: [Select] #!/bin/bash arp -a|sed 's/ /,/g'>arp.csv And I have tried executing it in php with the following: $arp = exec("bash makeArpFile.sh", $output, $exit_code); echo("Last line: " . $arp . "\n"); echo("Output: " . $output . "\n"); echo("Exit Code: " . $exit_code . "\n"); /*returns: Last line: Output: Exit Code: 127 */ I also tried just plain old: $arp = exec("makeArpFile.sh", $output, $exit_code); echo("Last line: " . $arp . "\n"); echo("Output: " . $output . "\n"); echo("Exit Code: " . $exit_code . "\n"); /*returns: Last line: Output: Exit Code: 127 */ I can run plain old arp>arp.txt but I really need it formatted in BSD style (arp -a>arp.txt) in order to be able to parse it properly later. Any thoughts? EDIT: for fun I made a useBash.sh script that executed "bash makeArpFile.sh" still no luck.
First off I want to thank everyone that is involved here in passing on the knowledge. After all that is what its all about. Okay so I want to do a campaign on password awareness and try to capitalize a little off of it. I came across the Breached_Compilation which is 1.4 billion email and plain text passwords. It has bash scripting in it to search and parse out the info from plain text documents which are in folders then prints the results in terminal. The other thing is that it posts the passwords in clear text. How would I obfuscate a portion of the clear text passwords? What would be the best way to integrate this to PHP? I am new to coding in PHP so any help is very much appreciated. Thanks an advance. Here is the Bash script.#!/bin/bash dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) if [ "$1" != "" ]; then letter1=$(echo ${1,,}|cut -b1) if [[ $letter1 == [a-zA-Z0-9] ]]; then if [ -f "$dir/data/$letter1" ]; then grep -ai "^$1" "$dir/data/$letter1" else letter2=$(echo ${1,,}|cut -b2) if [[ $letter2 == [a-zA-Z0-9] ]]; then if [ -f "$dir/data/$letter1/$letter2" ]; then grep -ai "^$1" "$dir/data/$letter1/$letter2" else letter3=$(echo ${1,,}|cut -b3) if [[ $letter3 == [a-zA-Z0-9] ]]; then if [ -f "$dir/data/$letter1/$letter2/$letter3" ]; then grep -ai "^$1" "$dir/data/$letter1/$letter2/$letter3" fi else if [ -f "$dir/data/$letter1/$letter2/symbols" ]; then grep -ai "^$1" "$dir/data/$letter1/$letter2/symbols" fi fi fi else if [ -f "$dir/data/$letter1/symbols" ]; then grep -ai "^$1" "$dir/data/$letter1/symbols" fi fi fi else if [ -f "$dir/data/symbols" ]; then grep -ai "^$1" "$dir/data/symbols" fi fi else echo "[*] Example: ./query name@domain.com" fi
I'm trying to make colourized output of bash script in php. So far I have this: <?php $cmd = '/home/thebalk/FiveM/manage.sh restart'; while (@ ob_end_flush()); // end all output buffers if any $proc = popen($cmd, 'r'); echo '<pre>'; while (!feof($proc)) { echo fread($proc, 4096); @ flush(); } echo '</pre>'; // // Converts Bashoutput to colored HTML // function convertBash($cmd) { $dictionary = array( '[1;30m' => '<span style="color:black">', '[1;31m' => '<span style="color:red">', '[1;32m' => '<span style="color:green">', '[1;33m' => '<span style="color:yellow">', '[1;34m' => '<span style="color:blue">', '[1;35m' => '<span style="color:purple">', '[1;36m' => '<span style="color:cyan">', '[1;37m' => '<span style="color:white">', '[m' => '</span>' ); $htmlString = str_replace(array_keys($dictionary), $dictionary, $cmd); return $htmlString; } ?> and my output looks like this: [1;36m BOT:[0;39m THE [1;32m TheBalkanRP-SRV01-test SERVER [0;39m WAS RUNNING [1;36m BOT:[0;39m STOPPING THE [1;32m TheBalkanRP-SRV01-test SERVER [1;36m BOT:[0;39m GTA V SERVER HAS STOPPED [1;36m BOT:[0;39m REMOVING CACHE FOLDER [1;36m BOT:[1;31m CACHE FOLDER HAS BEEN REMOVED [0;39m [1;36m BOT:[0;39m STARTING THE [1;32m TheBalkanRP-SRV01-test [0;39m SERVER [1;36m BOT:[1;32m SERVER HAS STARTED [0;39m I know my function is not connected with the code above but what is the right way to do it? Thank you! For those not knowing about this, is a new security hole found in all linux/unix based operating systems that should be patched.
http://arstechnica.c...with-nix-in-it/
Does anyone already fix the bug. I found something interesting in the error_log file this morning
x.x.x.x - - [25/Sep/2014:01:12:34 -0500] "GET /cgi-bin/defaul_p.cgi HTTP/1.0" 404 312 "-" "() { :;}; /bin/ping -c 5 "209.126.230.74"
Hey y'all. Probably a dumb question here but I'm at a loss. I've got a PHP service script that has an include, written as so: $config = new Config('config/config.json'); The config directory is next to the PHP script and does contain the config.json file, so when I run this from the CLI everything works great. However, I've got about 17 PHP services I need to start and really don't feel like typing them all out, so I've written a shell script that does this: #!bin/bash cd /path/to/my/script /usr/local/bin/php ./my-script.php This does start the service, but it bombs out because it can't find the config.json file. If I change the PHP to $config = new Config('./config/config.json'); it works as expected from the shell script. Updating the files is technically possible, but fraught right now for reasons I can't really get into (sorry). Anybody know what the difference is, or have any ideas on how to get around this? Edited September 5, 2020 by maxxdHello! I am executing an external command from a PHP script, using the exec function. Since this program can take more than 1-2 minutes to run, I thought I should use a "Loading page...please wait". What I need is to be able to get the process id from the external program that is being run and, when this finishes, I'll start outputting the results. Is there a way to do this? Hi, I'm new. I have been searching for this, but couldn't find my answer ... I've got a form on page A, with its 'action' attribute set to page B.php. Page B does nothing but process the form data & put it in a database. At the bottom of B.php there's a header redirect to page C. My problem is that page B shows up briefly in the browser, looking all blank and weird. Is there a sensible way around this? I just want it to do its stuff in the background. I realise I should be Ajaxing it all but, apart from the fact that I struggle with Ajax operations longer than a couple of lines, it's important that the site should work without javascript. I HOPE this is a really easy one! Thanks Hi, suppose the user requests a page www.foo2.php. Now if it is a link embedded in another page, say www.foo1.php, then Javascript can send the server browser info before furnishing the page. But is it possible to let the server know which browser is being used when the user requests the page by just typing the url http://www.foo2.php and hitting enter? i am facing issue with DB connection with Oracle DB able to telnet and connect DB from [RHEL] OS command prompt also when i am executing php command with php filename, i am able to connect to the database. i am getting err 500 when trying to open php page from front end.
pls help...!!!! I have created a tar file with my site backup and I assume it is the full backup. Not sure becasue I can't "un"-tar the file. I have tried several ways to "unzip" or untar the file but can not come up with anything. here is how I had created the tar file: Code: [Select] $date = date("m-d-Y"); // repeat this command for multiple backups, changing the path - e.g. you can have a backup for email, another for files, etc. shell_exec("tar cvfz file_backup_$date.tar.gz mydir/ "); now how do extract it? I have a shoutbox my friend made, and I'm just adding onto it. I have command that are like @prune, @prunelogs, @logout, etc.. I am tying to make it so you can type @ban username, @unban username, etc.. Here is my command that my friend came up with. if($_POST['text'] == '@ban'.$username.'') { $unn=$idk['username']; mysql_query("UPDATE users SET banned = '1' WHERE usernane='$unn'") or die(mysql_error()); mysql_query("INSERT INTO chat (`log`, `date` ,`username` ,`text`) VALUES (1, NOW( ) , '".stripslashes($_SESSION['user'])."', 'has banned '$unn'.');") or die(mysql_error()); |