Run R with no gui - php

I am trying to get a default installed CentOS7 R 3.2.3 running without GUI, just for the data processing. The following code runs fine on OSX with no gui output, but fails on CentOS. I start both as
Rscript script.r someMatrix.txt
theMatrix = as.matrix(read.table(args[1],header=TRUE,sep="\t",row.names = 1))
values = heatmap(theMatrix,keep.dendro=TRUE)
Error in dev.hold() : no active or default device
Calls: heatmap -> dev.hold
I am calling the R scirpt from a PHP script within Apache. So it maybe a bad environment setting for the Apache user, but I am using the system wide installed package, and running the script as another user without any special environment settings worked fine.

Related

nodejs command not executing through PHP on Linux

The problem is faced while running node command (which generates PDF file for given link) on Linux through PHP exec/passthru/system functions. Actually, I am trying to create PDF file through headless chrome using Puppeteer node module. Everything worked fine in Windows system but as soon as the same code was moved on production server (which uses Linux), the exec/passthru commands began to throw 127 return code errors. Please note that same node command works without any problem when run directly on terminal .
Also, Apache has write permissions in directory where file is being generated and command was also tried by giving the absolute paths but nothing seems to be working
The format of command is like this
"node script-generating-code.js http://www.url-of-page.com/"

Bottle web server - how to serve PHP file?

I am working on a webapp made by someone else which uses Bottle routing. I want to create a simple login page which requires some PHP. If I return the PHP page as a static_file, any HTML will be executed but PHP won't, for obvious reasons. How should I serve the PHP file so that it is dynamic?
Not working:
#route('/login')
def serve():
return static_file('login.php', root='.')
In order to server PHP files, you need to have PHP installed on the web server. Additionally, the webserver needs to be configured to detect PHP files and execute them.
Serving PHP files from Python is kinda useless and not recommended.
I'd recommend you to take the time to translate this script from PHP to Python.
I wanted to do the same thing yesterday, but the answers I got to my question made it clear it was either impossible or extremely difficult. I came up with writing a small python program to run the PHP built in server. NOTE: PHP needs to be able to run from the command line for this to work.
#Import the os package so that this code can run commands
import os
#Get the port that the user wants to host on
port = str(input("What port would you like to host on?"))
#Add wanted port to the command that hosts the php server
cmd = "php -S localhost:" + port
#Actually run the command to host php server
os.system(cmd)
#Now the PHP server will take over until you
#use ctrl + C to quit hosting
Just remember that the port needs to be 4 numbers. When you host this, you can return any file from the folder you ran this code in by simply typing it in the browser. Example:
localhost:8080/login.php
Returns login.php (if it is there) on the localhost port that you asked for.

DCOM permissions error when exec from PHP but when executed from cmd works properly (officetopdf.exe)

I want a php script to execute a command officetopdf.exe input.doc output.pdf where officetopdf.exe is an program that uses the installed Office to export office files to pdf.
When executed it throws the error:
‘Retrieving the COM class factory for component with CLSID
{000209FF-0000-0000-C000-000000000046} failed due to the following
error: 80070005 Access is denied.’
and does not execute properly.
The server has IIS and Plesk panel. The user that calls PHP has been created with Plesk.
When officetopdf.exe is executed directly with cmd.exe it works well as expected.
It seems to be a problem of permissions of DCOM.
On local environment on our office in another computer with Windows 8 changing DCOM permissions it worked well.
On first install of office in the server all DCOM applications do not appear in DCOM config panel. I don't remember how we added but it wasn't automatically added because the Office was 32 bit and the system is 64 bit. If office 32 bit is installed the error 'Retrieving the COM class factory' changes to something like it does not find the class.
Tested on 2 servers with Windows 2012

Selenium WebDriver Firefox

I'm running a LAMP configuration on Ubuntu Server 13.04. I setup XVFB and Selenium to load on startup as services (/etc/init.d). Firefox is working if I export DISPLAY before opening it in a terminal session, however I'm not attempting to test in a terminal session; I'm using PHPWebDriver to call an instance of WebDriver.
When attempting to open a session as so:
$driver_include = "/includes/user/webdriver/__init__.php";
require $driver_include;
$wd_host = 'http://localhost:4444/wd/hub';
$web_driver = new PHPWebDriver_WebDriver($wd_host);
$session = $web_driver->session('firefox');
I get the following error:
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.
I also have Xvfb set to DISPLAY :10. By exporting to this display I can open Firefox in a terminal.
My question is:
How do I tell WebDriver to use a certain DISPLAY by default without starting it manually from a terminal session?
I think you will be fine as long as you make sure that the Grid server is running in a shell WITHIN a windowed environment. It won't work if you start the grid outside of a windowed environment that is needed to start the Firefox profile. If you are trying to run headless, without a DISPLAY, then you should use GhostDriver/PhantomJS instead, or something similar.

Server side script for launching application

I have been trying unsuccessfully so far to write a php script that will run when a page is opened and that will launch metasploit!
I ve tried shell_exec and exec and all the other alternatives but although I can get it to do simple things (i.e. ls, cds etc) if I try msfconsole it doesnt do anything!
I have also tried a different script that launches firefox and again nothing happens!
Now i know that php runs on the server and I m not expecting to see a console or firefox opening in the clients machine! Instead in order to check if it works I am trying to echo out the output of the shell_exec!But anyway since im hosting the files on my machine (i.e. this is the server and a VM is the client) if it could actually launch firefox i should be able to see the app opening here in the same way as by just doing this from the command line!
What am I missing?
Is there any other way to do this?(i.e. Launch metasploit everytime a user opens up my page)
NOTE: I've tried specifying the full path for msfconsole but that didnt work either!
Heres what I have so far:
$output = shell_exec('/opt/local/libexec/metasploit3/msfconsole;show');
echo "<pre>$output</pre>";
The ";show" bit was used in order to actually make it run something and print some stuff but didnt make any difference!
When you run a gui application from the command prompt in a X window system, it will use the default display. When you run it using php which is embedded in apache webserver, the program may not know where to display the gui application.
there are 2 things to make this work.
The program that executes the gui application must have permission to use display
you need to tell the program which display to use.
I used the following in my php script
<?php
$cmd = `export DISPLAY=:0; gedit`;
shell_exec($cmd);
?>
and ran the script from terminal using php -f test.php
I got the gedit up and running.
You can test the same with the script in apache too.
Please add apache user with privileges to access display server
update: I just added the following in /etc/apache2/apache2.conf (I am using ubuntu)
User poomalai
Group poomalai
and restarted the web server
sudo service apache2 restart
now I accessed localhost/test.php
and Presto!! I got the gedit :)
Hope this helps

Categories