I'm working on making a website/web application that displays images every 5 or so minutes, kinda like a webcam. The images are uploaded to an SFTP server. How can I access those from the web? Does anyone have any recommendations for what to use as well? Right now I'm looking at PHP but have checked out javascript and ruby as well. Only the application needs to ssh to a predetermined place, not the users.
I was suggested by a friend to use rsync and setup passwordless ssh. Anyone ever do this? or is this a bad idea?
If the application is the only thing that needs to SSH then you can rule out javascript immediately. It's predominately a client-side language in these environments.
You may like at Net::SSH ruby library, or I'm sure there's a php equivalent. I have used Net:SSH and it's fairly straight forward.
You need to write a server-side script that connects to the SFTP server and forwards the image to the client.
cURL has SFTP support.
PHP supports SFTP. You need to install ssh2 extension,
http://www.php.net/manual/en/book.ssh2.php
Related
Looking for some suggestions on best way / possibility of implementing offsite backup of the data in my php app.
So we have an PHP app that runs on the clients local site, which dumps the MySQL data to a datefile.sql each night. what's the best way to get this moved to an external server.
We host a server that currently we manually FTP files to each morning. How best can we automate this, would we need to hard code in FTP credentials, what if we had multiple clients how could we separate out this so no hard coded credentials are needed.
The ideal situation would be to have a MySQL instance running on the external server that the local clients server replicates the data across to this on the fly and back if required. Not even sure that's possible?
Happy to try and explain further if needed.
Thanks,
Any ideas?
you could create a bash script running on your server, called by a cron at night, that uses rsync to fetch the sql file from the clients servers (if you have an ssh connection with them), and restore it on your own machine.
You can achieve this using cron. Just create a cronjob and schedule it to run when you need it to. For all the file-transfering hasle, you may use rsync (which also provides ways to transfer only different data etc).
Also, I think that MySQL has a build-in feature for replication and backups, but I'm not sure about this or how to configure it..
Basically I want to use some kind of sockets (web sockets or node.js?) but I don't really know much about them and I want to send low latency data between html pages with javascript enabled on them.
I have php installed on the shared server and socket_connect() is a function included so i'm guessing php_sockets.dll is installed. I could potentially use this, but the php script is on a remote server so I don't know if i would be able to run it?
Should I use some other language that would be installed on a normal shared server?
EDIT: I don't have shell access..
http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/ this should give you a pretty good start in talking to php using html5's websocket api. You don't need Node.js to implement this.
I want to write a PHP script that connects to a network PC's C drive: \MAINPC\C$ and then authenticates itself (I provide the username and password) and then iterate over the file in another folder. The iterating part is easy, but I am stuck as to what to use to actually connect to the Windows server or whether or not I would have to use some low-level socket connection?
There is this:
stream wrapper to access Windows shared files
It wraps the smbclient program.
Further discussion in this SO question.
You can mount network shares to device names in windows, or simply mount them to a directory (via smb) on linux.
Then to php it is a simple file operation. You will have to make sure that the share is up tho.
PHP cannot magically access data on another machine.
You need a server on that machine (here the windows PC) that serves the file system you are interested in. Then you can create a php script that accesses the content of the filesystem by using that server.
Actually there are ready-to-use components for that stuff.
Is the webserver on a linux/unix-box?
Are the machines on the same LAN?
http://www.samba.org/samba/docs/man/manpages-3/smbclient.1.html may help you.
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
Does anyone know of a JS-based terminal client? Either something that initiates an SSH connection with a remote host or even something that simply communicates with a remote PHP script to execute commands and retrieve output. Does such a thing exist?
Check Anyterm, it uses a XmlHttpRequest channel to communicate with a daemon that uses a pseudo-terminal to communicate with a shell or other application.
http://www.masswerk.at/termlib/ looks interesting as a base.
http://sourceforge.net/projects/jsterminal
but you'd have to write your own commands to connect with the host
Shell in a box could be used also with a small Asus EEE-PC:
http://code.google.com/p/shellinabox/
It works great also for virtual machines in a cloud.
So far JSDom Shell is the only thing I have found, which seems relatively barebones but practical. If there are any other more substantial options, feel free to share!