I'm trying to execute audit2allow using Symfony\Component\Process\Process.
When I run exec("audit2allow -a -M a2a"); in PHP, it works just fine, a2a.pp and a2a.te is produced.
$process = new Process(['audit2allow', '-a', '-M', 'a2a']);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
However, the above code produces the output below
Symfony\Component\Process\Exception\ProcessFailedException : The command "'audit2allow' '-a' '-M' 'a2a'" failed.
Exit Code: 1(General error)
Working directory: /var/www/html/example
Output:
================
compilation failed:
a2a.te:6:ERROR 'syntax error' at token '' on line 6:
/usr/bin/checkmodule: error(s) encountered while parsing configuration
/usr/bin/checkmodule: loading policy configuration from a2a.te
which is the typical output when there is a empty /var/log/audit/audit.log.
What do I need to change to make it work properly? Symfony claims it is not a bug.
https://github.com/symfony/symfony/issues/35862
Update
Using Symfony\Component\Process\Process (code above) actually produces the file a2a.te, but it has only 1 line.
module a2a 1.0;
Whereas using exec() produces the file a2a.te with many lines:
module a2a 1.0;
require {
type kernel_t;
type vmblock_t;
type container_t;
...
Why does running the same command on Symfony\Component\Process\Process and exec() gives different outcomes?
Related
I am attempting to run a R script from PHP. I have created a shelled out version of my code that produces the same error message. I am running in VSCode, PHP Version 7.3.9, and R-3.6.2. Below are shelled our versions of my code that demonstrate my issue.
index.php
<?php
$R = '"C:/Program Files/R/R-3.6.2/bin/Rscript.exe"';
$testScript = "C:/xampp/htdocs/rtest/testscript.r";
$command = "$R $testScript testingArguement 2>&1";
$result = shell_exec($command);
echo $result;
?>
testscript.r
## Define all libraries
suppressMessages(library(plyr))
suppressMessages(library(dplyr))
suppressMessages(library(tidyr))
suppressMessages(library(tidyselect))
suppressMessages(library(tidyverse))
suppressMessages(library(data.table))
## Suppress Warning Messages
options(warn=-1)
args = commandArgs(trailingOnly=TRUE)
testValue = args[1]
cat("The test value is",testValue)
When I run the command via PHP in VSCode, the result variable receives the following...
"Error in library(plyr) : there is no package called 'plyr'
Calls: suppressMessages -> withCallingHandlers -> library
Execution halted
"
However, if I run the command manually in Command Prompt it works.
C:\Users\Garrett>"C:/Program Files/R/R-3.6.2/bin/Rscript.exe" C:/xampp/htdocs/rtest/testscript.r testingArguement 2>&1
The test value is testingArguement
C:\Users\Garrett>
I am just super confused to why the packages aren't getting recognized when running from within VSCode/PHP
credit goes to Rscript: There is no package called ...?
but to summarize, I did the following
1) Start R.exe in command prompt, and type the following to get the location of where packages are installed Sys.getenv('R_LIBS_USER')
2) Paste the following line at the top of your R script so that Rscript.exe can reference
.libPaths(c(.libPaths(),pathFromStepOne))
I've installed mjml cli using the following command (as described in the mjml documentation):
npm install mjml --save
now if i did node_modules/.bin/mjml in the command line it will run successfully.
the problem is when i use the symfony process component in php i got the following error (even if it's the right path):
The command "/Users/qoraiche/Documents/my-app/node_modules/.bin/mjml" failed. Exit Code: 127(Command not found) Working directory: /Users/qoraicheOS/Documents/my-app/public Output: ================ Error Output: ================ env: node: No such file or directory
Symfony process code:
$process = new Process(base_path('node_modules/.bin/mjml'));
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
By the way i have installed mjml globally as well and try it with no luck.
Try providing the full path to node.js when calling the MJML binary from a Symfony Process().
$process = new Process('/your/path/to/node ' . base_path('node_modules/.bin/mjml'));
I use this method in my own apps. Of course, you will need to provide the input and output files to actually transpile anything.
When I try to run that phing command: bin/phing clear_cache_action from a console, everything works. Unfortunately, when I try to run the same command from the controller in the Symfony project I get an error.
That my code:
public function clearAction()
{
$process = new Process('bin/phing clear_cache_action');
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
}
Symfony returns me that error:
The command "bin/phing clear_cache_action" failed.
Exit Code: 127(Command not found)
Working directory: /var/www/caolin/web
Output:
================
Error Output:
================
sh: 1: bin/phing: not found
Linux commands e.g. 'ls' works properly.
How can I run phing command from code?
I guess you are trying to execute phing from a Controller. Thus Working directory: /var/www/caolin/web instead of /var/www/caolin causes resolving bin/phing to /var/www/caolin/web/bin/phing which does not exist. You should set your current working directory to %kernel.project_dir%:
$process = new Process(
['bin/phing', 'clear_cache_action'],
$this->getParameter('kernel.project_dir')
);
$process->run();
However, I would not recommend starting a process from a Controller unless you are really sure what you are doing.
Im using phpseclib which id included with the command:
composer require phpseclib/phpseclib ~2.0
The target machine (receiver) is running Windows Server 2012.
On the target machine, I can run the following command in the cmd prompt and it works perfectly:
c:/maestro/__main__.py --process-report hourly_visitor -test
However, if I send that same command to the machine via SSH2, I get a strange error namely __main__.py: error: unrecognized arguments: -testh
Note the h in -testh. That's NOT in the sent command. Also, that extra letter seems to change, in a previous log entry, I saw:
__main__.py: error: unrecognized arguments: -testt with an extra t on the end but always a single letter added to the end.
I don't get it, what the heck is happening here?
Here is my php function:
public function triggerReport($config,$command)
{
$host = array_get($config,'host');
$username = array_get($config,'username');
$password = array_get($config,'password');
$ssh = new SSH2($host);
if (!$ssh->login($username, $password)) {
Log::error('Login Failed while attempting to trigger report with command: '.$command);
}
else{
$output = $ssh->exec($command);
Log::info('Output from running report with command: '.$command);
Log::info($output);
}
}
1st log output
Output from running report with command: C:\Python27\python.exe c:/maestro/__main__.py --process-report hourly_visitor -test
2nd log output:
usage: __main__.py [-h] --process-report [REPORT_TRIGGER] [-test]
[--to TO [TO ...]]
__main__.py: error: unrecognized arguments: -testh
I am able to run it through the browser but not from command line
ie php test.php
$raw = Cassandra::cluster()
->withContactPoints('localhost')
//->withCredentials($this->username, $this->password)
->build();
var_dump($raw);
die;
from browser:
object(Cassandra\DefaultCluster)#2 (0) { }
command line:
PHP Fatal error: Class 'Cassandra' not found in /var/www/html/test.php on line 2
Is it possible to get same from command line as well?
The cli uses a different php.ini file (e.g. /etc/php/7.0/cli/php.ini & /etc/php/7.0/fpm/php.ini). You are probably not including the extension in the cli one.