Does PHP has access to the parallel ? I'm trying to write data to the LPT1 port using PHP, but not having luck finding anything.
Writing to the parallel port is as simple as:
file_put_contents("/dev/lp0", "See that was easy.");
Your real problem however sounds to be:
Does PHP has access to the parallel ?
Since PHP usually runs under Apache, the permissions for this device file are insufficient. On Debian systems you would add the www-data user to the lp group to make it work.
Related
We have a PHP application which automates script commands. Many of these are through web interfaces. I want this php application user to be running lots of cli and ssh commands, so I dont really want www-data doing it, as it would involve changing lots of script files to www-data executable permissions, and we want scripts to be entered into web interfaces.
This application is cross-operating system. Ideally on anything that php runs on, but win, mac,
The important things that we need to be able to do are (I think) ...
1) Have a Web Server (It's currently Apache, and that's working cross os so that would be great), that is running under normal settings, normal user, reverse proxied to the below application on te same server.
2) Have a PHP application on a different port, running as its own user that can do whatever it wants.
The ability to just run
php -S localhost:8000
As is available in the built in php web server seems ideal for this. So...
1) Is it safe to use the PHP built in Web Server if it's behind an apache proxy? I'm assuming the fact we are proxying over the entire request anyway means no, since it says not to.
2) Is there another Web Server/PHP Server that can easily do this?
3) Is there a way of running two apache processes to do this?
4) Am i doing this the wrong way entirely? There's another app I know that does it like that, but a Java app and the whole process is started and owned by a non apache user.
Thanks in advance
Apache 2.4 + php-fpm + mod_proxy_fcgi will suit you just fine.
(to elaborate for the downvote -- php-fpm allows the PHP process to run as a separate daemon under its own userid which is exactly the privilege separation requested here)
i want to statically assign the ip address of my arch linux using php. i want to change the ip by using netmask,interface,broadcast,address & gateway.the user puts up the values into a html page.the html page posts the data to the php page.i want to change the ip using this data. HOW TO DO THIS!!
Files also can be used!! right?
..i was thinking of writing directly into the rc.conf using files!!...will this work and how??..i have my arch linux up with apache & php..any of the help is appreciated!!...thanku..:)
You should write yourself a shell-script and launch that via PHP, instead of trying to accomplish such a task with PHP itself.
If you don't know how to do that, you should ask a related question https://unix.stackexchange.com/.
Why would you use PHP to attempt to configure a server?? You should configure the server using pre-existing tools and commands that are designed for that purpose.
$su
# ifconfig <interface, tpyically eth0> down
# ifconfig eth0 192.168.1.105 netmask 255.255.255.0 up
# ifconfig eth0
You COULD wrap those commands in an exec() statement, but I don't see a PHP script having the necessary system permissions to complete them successfully.
In normal condition, you may be not able to do it from web server directly due to security.
There are several problems like permission on /etc files, security context of user in which apache run etc.
One secure way is to create cron task which will run under root account and regularly check for existence of some file which can be generated by apache (php).
Once file will appear you can reconfigure whatever using ifconfig within cron task with appropriate privileges based on content o this file.
Don't forget that your apache should be configured to use all interfaces and not realy on IP based VirtualHosts or you will immediately lose connection to it.
I am looking into a way to reboot a remote dedicated server using php. While doing research on Google I read about Python shell client. Is there is something similar in php?
Can I use php to reboot a remote server using shell commands? and what is needed to do so?
I assume that you want a web based shell implemented in php.
In that case you can look at this http://ajaxshell.sourceforge.net/
and this http://sourceforge.net/projects/ajaxshell/
Using these scripts you can run arbitrary shell commands.
But remember 2 things.
1. password protect the web shell app
2. The shell will run commands as the apache user. If you want to reboot the server, apache may need root privileges. Running apache as root is usually considered as not a good practice.
You probably can, by using exec(), passthru() etc. Is it a good idea, I'm not sure : you'll have to give reboot privileges (I don't know exactly, but it's almost root...) to your php user.
Just to be sure, what you want to do is to call a web page that will reboot your server, or it's more complicated that that?
There is a shell equivilent for PHP. I recently published a project that allows PHP to obtain and interact with a real Bash shell, you can even easily get a shell with root. Get it here: https://github.com/merlinthemagic/MTS
After downloading you would simply use the following code:
//if PHP is running on the server you want to reboot:
$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
//if PHP needs to SSH to the server first
$shell = \MTS\Factories::getDevices()->getRemoteHost('ip_address')->getShellBySsh('username', 'password');
$strCmd = "reboot";
$return1 = $shell->exeCmd($strCmd);
I need to access COM port (console) via script to access our DSL modem.
It should access in such a way that I can read all the messages printed on the console and i should also send commands to the console via script .
Please let me know if it is possible in TCL or php .
Platform : Windows XP.
Also is there any way I can access the com port through script and console software such as teraterm simultaneously ?
Regards,
Mithun
It is possible to use TCL to access a serial (COM) port using the standard TCL input and output commands. The main ones that you need to look at are the open and fconfigure commands. A google search for 'tcl open com1' will bring back lots of examples.
One thing worth noting is that the open and fconfigure commands changed in recent versions of TCL, TCL 8.5 I think, so depending on the version of TCL and age of the example some rework might be needed.
You just need to open the com1: device and fconfigure it to use the communications settings that the other side expects. For example:
set fd [open "com1:" r+]
fconfigure $fd -mode 9600,n,8,1
Be aware that it can be messy to use event-driven IO with serial ports on all platforms.
Sounds like a job for Expect.
I was wondering, whether knockd http://www.zeroflux.org/cgi-bin/cvstrac.cgi/knock/wiki would be a good was to be able to restart apache without logging into ssh. But my programming question was whether there is a way to send tcp/udp packages via PHP so I can knock via a webclient.
I am aware that this is not the safest way of doing it, but I will only want to do things like update the svn, restart apache without having any passwords in it like with using ssh to do that.
You may use fsockopen() functions... but what you are doing(and the way you are doing it) is very risky from a security standpoit.. as it had been said, ssh is the way:)
If you really want to restart the apache server by using remote access (non-ssh) you can create a small php-daemon, that just watches for a specific file,(ex: /tmp/restart.apache) and when that file appears run exec("/etc/init.d/apache restart") (or whatever the command is for your distribution). This daemon should run as root... and the thing is that the whole security thing is up to you this way, you have to make sure this cannot get arbitrarly executed...
Your portknock ideea... a simple port scanner may restart your apache by mistake:) portknock is recommented to be used in conjunction with a ssh auth , not directly with apache:)
Seriously, you do not want to do what your trying to do.
You should look into calling your remote server through some sort of secure protocol, like SSH. And on the client side, have a small PHP utility application/script that executes remote SSH commands (preferably with a keyfile only based authentication mechanism).
Why not have a PHP script that calls "svn update"? As long as the files are writeable by the user Apache runs as, it works great. Just hit that URL to update the website
For SVN you have whole PHP api, try search SVN on php.net