PHP - Php Does Not Execute Bash Command
Hello, 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 ? Similar TutorialsHi 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? 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? Hi, I have a strange problem using the exec command. I have the following php code : <?php error_reporting(E_ALL); ini_set('display_errors','On'); $accountBase = "HORAIREMOBILE"; $primaryUser = "DUM"; $secondaryUser = "DUM"; $result = exec(escapeshellcmd("/home/evidian/utils/getAccount ".escapeshellarg($accountBase)." ".escapeshellarg($primaryUser)." ".escapeshellarg($secondaryUser)),$output,$return_val); echo $result; ?> When I execute the command from the CLI, with any user, it just works fine, and shows my the result (basically a JSON formated output). However, when I call the code frome the apache server, it simply returns nothing. Could anybody help me with this issue ? Hi guys, I am new here, and I am a bit stuck with doing something unusual. I want to create a script that can turn on a program (dynamips and dynagen). So far, I have tried 'exec' and 'shell_exec'. Soon I realized that apache runs the commands as 'www-data' user (apache2 in ubuntu) and it's very limited on what you can execute. Is there any way to do that at all? What would be the best practice? I am not concerned about security as this is not a production environment... Thanks 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
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/
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! 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 maxxdI need to execute a program in the command prompt in windows using php, which php functions would be best to do this? and would i need to set any type of permissions to be able to use them? Hello, I've been assigned the task of creating an internal site for our office that has links to all the websites we use as well as the applications we use. I'm very comfortable using php with mysql for handling forms and displaying database information but I'm not sure how to go about this. So my question is, is there anyway I can use php to open an exe file? Hi, I am trying to create a PHP script ("repair-correct.php") in order to run some CLI commands without using PuTTy - The CLI commands are needed to repair/correct the execution of a web application named Mautic. Shared web host account with PHP 7.0 URL: https://www.myserver.com Mautic directory: https://www.myserver.com/mautic
What I want to do is:
Step1: Change ownership of files and folders To find out which user Apache is running as, I want to execute the following command and take note of the first entry in the line which is returned: ps aux | grep apache2 I want to use this information to find the groups with the following command groups apache_user (where apache_user is the user I identified from the first step above) To reset the ownership of files and folders, I want to use the following command (ensuring that I replace apache_user and apache_group with the values identified in the steps above): sudo chown -R apache_user:apache_group With this command I want to change ownership, using the -R flag which means recursively - including all files/folders within that location.
Step 2: Reset the file and folder permissions
find . -type f -not -perm 644 -exec chmod 644 {} +
Thanks so much for your help in solving this problem!
Best, Tony
Hi, Below i have some sample code and am confused over execute(), i have the code below in a try and catch block, in the catch block i call a function i created to log any error that is caught in catch block to a .txt file. I then looked online and it seems that i should do an if statement check on execute to ensure it executed the query, the part that confuses me if the execute failed i thought it would be caught in the catch block but it seems that is not the case. To explain better i have commented the code in depth on the area that i am confused about. Any help in making me understand would be great. I have not included all code above try and catch to keep things simple Code: [Select] <?php try { // connect to database $dbh = sql_con(); // checke if username exists on users table or users banlist table $stmt = $dbh->prepare(" SELECT users.user_login FROM users WHERE users.user_login = ? UNION ALL SELECT users_banlist.user_banlist FROM users_banlist WHERE users_banlist.user_banlist = ?"); // this is the part i am confused with, why is it i would use an if statement on execute() ? // i thought using a try and catch block any errors would be caught in the catch block. // using an if statement to check if execute() worked, i thought if execute failed it would // be handled by the catch block, i mean in my exmaple code here, what could cause the execute to fail ? // and why if execute failed it would not be caught by catch block ? // i am looing at exmaple online and i am reading different things and its all confusing me // execute query if(!$stmt->execute(array($username, $username))){ echo 'something went wrong .. '; } else { // execute worked } } // if any errors found log them in my ExceptionErrorHandler() function and display friendly message catch (PDOException $e) { // this function catches an error and logs them to file ExceptionErrorHandler($e); require_once($footer_inc); exit; } } ?> Thanks or any help! I have written a Validation class that checks to see if a file being uploaded to the server meets certain conditions. That works a treat. The next step is to actually upload it to the server and I have an Upload class that can do that. Again, that works perfectly fine. Once the file uploads, I am passing the $location of that of that file to my DB class. The DB class is full of methods that prepare and then execute strings that are SQL queries that are required in other areas of my application. Nothing I have at the moment is suitable for just running an SQL file so I don't know what to do now.. My procedural code, that works, looks like this; $dbh2 = new PDO("mysql:host=localhost;dbname=DB360transfer", $login_user, $login_password); $sql = file_get_contents($path.$new_file_name); $qr = $dbh2->exec($sql);I'm not sure how to replicate this up in a PDO/OOP application. My DB Class script is attached. The run_from_file code starts on line 98. I've left in the other stuff as I suspect the answer has something to do with using the $this or the self:: - but really I have no idea. So my question is, what is the correct syntax for executing a file in OOP? Attached Files DB.php 2.92KB 6 downloads hi, I am having problems setting a session from a SQL query, please help... here is my code: Code: [Select] $query1 = "SELECT * FROM members_copy WHERE rsUser = '$username' AND rsPass = '$password'"; $result1 = mysql_query($query1); echo "<br>".$result1['USERID']; $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['USERID']=$result1['USERID']; $_SESSION['RSTOWN']=$result1['RSTOWN']; $_SESSION['RSEMAIL']=$result1['RSEMAIL']; $_SESSION['RSUSER']=$result1['RSUSER']; no sessions are currently being set?! Hi,
I have a cron job that executes this script every 2 minutes:
<?php // LOAD WP-LOAD.PHP require('/opt/bitnami/apps/wordpress/htdocs/wp-load.php'); // INCLUDE AND EXECUTE SCHEDULER.PHP include('/opt/bitnami/apps/wordpress/htdocs/wp-content/themes/yeelloe/scheduler.php'); ?>When I try to include; /opt/bitnami/apps/wordpress/htdocs/wp-content/themes/yeelloe/scheduler.php: <?php // EXPLODE AND PARSE WP-CONTENT; FUNCTIONS.PHP $parse_uri = explode( '/opt/bitnami/apps/wordpress/htdocs/wp-content', $_SERVER['SCRIPT_FILENAME'] ); // LOAD WP-LOAD.PHP require_once( $parse_uri[0] . '/opt/bitnami/apps/wordpress/htdocs/wp-load.php' ); // LOAD TEMPLATE FUNCTION CheckFunction(); ?> Not sure if this is possible I am trying to do a multi delete: Code: [Select] <form name="form1" method="post" action=""> <table> while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td> </tr> <?php } ?> // Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } <tr><td> <select name="dropdown"> <option value="option1">Choose an action...</option> <option value="edit">Edit</option> <option value="delete">Delete</option> </select> <a class="button" href="#">Apply to selected</a> if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=nameslist.php\">"; } } mysql_close(); |