Minimal http server for testing cgi-bin - linux

I have developed and maintain a web application which acts as a front end for some scrips in cgi-bin which in turn call C programs on the server. The web server is Apache2, hosted both on my office Linux box for testing and on Amazon ECC for the real deployment.
My problem is that I'm off travelling, mostly without any internet connection and with only a small portable linux machine, yet I want to develop the next release of the web pages, scripts, data sets and programs. Testing static web pages is no issue but testing pages which call server-side cgi-bin scripts is always problematic, so my idea is to put a minimal http server on the portable linux box (ubuntu 14.04) which will allow the server and client to be on the same machine without any internet (and maybe with just a socket) in-between.
Of course I can and do test scripts and programs directly, but this does not exercise features such as handling top-bit set characters in $POST_DATA or setting and retrieving cookies so would inevitably result in some divergence of code-base.
So:
Is this way sensible or is there a better or simpler means to do what I want?
If it is sensible, what hppt server would you recommend? I thought of miniWeb but have no experience of it.
PS: I'm expert in the the (maths of the) server-side programs but have much less experience as an apache sysadmin.

For many things this is sufficient:
python3 -mhttp.server --cgi
Unfortunately, it's so minimal, that it doesn't support stuff like setting the HTTP Status: https://bugs.python.org/issue10487
I'm not using lighttpd because I don't want to have to write a configuration file. Another minimal server that can be used is mini-httpd:
sudo apt install mini-httpd
/usr/sbin/mini_httpd -D -p 8000 -c 'cgi-bin/*'
The -D option keeps the server in the foreground instead of daemonizing it. The -p option is the port and -c is a pattern for my cgi scripts.
I also found that the built-in webserver of busybox can handle cgi scripts just fine:
busybox httpd -p 8000 -f

Related

How can I use (Node) Livereload on a development server in my network

Background: My PHP projects (CakePHP, Wordpress) run on an Ubuntu server in my network, I access them through a development TLD (.dev for example) setup through a local DNS server and I edit the files through a Samba share.
I would like to utilize Livereload for my development, preferably have it running on the server itself. I have basic Node/Gulp knowledge, but haven't been able to get this running.
Livereload (or a middleware server) should proxy the 'real' URLs, making sure all websites run as they would normally and Livereload should be available over the network (so not just localhost, because that runs on the development server)
Desired result:
Livereload runs on my dev server (IP: 10.0.0.1), my project is called helloworld.dev, I browse to 10.0.0.1:3000 on my machine and see helloworld.dev proxied through Livereload. I now edit a CSS file over the Samba share and the CSS is reloaded without a refresh.
I've tried using a few NPM packages, gulp-livereload, livereload, node-livereload, with their provided examples that come with the packages, but haven't been able to get the desired result. They all expect you to run in locally, don't support access to the Livereload URL over the network, cannot proxy the 'real' URLs or require static content.
Can anyone provide an example or 'proof of concept' code of my wish, so I can see where to start?
I found the answer: http://nitoyon.github.io/livereloadx/
This does EXACTLY what I need.
I can run
livereloadx -y http://helloworld.dev -l
open
http://serverip:35729
and I'm ready to roll.
The -y option creates the proxy to the 'real' URL and the -l makes it serve files from local filesystem instead of through its proxy.

How to run server-side Javascript within a shared server service?

I know there is Node.js and Rhino, amongst other platforms to run server side JS. Though, we can only afford a shared server, since a VPS is much more expensive, and normally shared servers do not provide such tools. We need to run some cron jobs which by default are run by the server, and our core functions are purely JS without interaction with the browser/client.
Is there then a simple way of running server side JS, without the need for installing server side specific SW?
1) Go to Node.js download page and get the link for the Linux Binaries (.tar.gz) (right click-> copy link address).
2) Then (thanks to user niutech) create the following php file, namely install_node.php
<?php
//Download and extract the latest node
exec('curl http://the_URL_you_copied | tar xz');
//Rename the folder for simplicity, adapt accordingly
exec('mv node-v#bla_bla-linux node');
?>
3) run the php file from the unix terminal
$php -q install_node.php
4) you may then run the node executable file on ./node/bin/node

SVN pre-commit hooks from windows to linux

I have two PC in my network:
1) CentOs
2) Windows 7
I created repository on Linux machine and add some pre-commit hook scripts. Then, I checked out files to working copy directories on both machines. Now, when I make some changes and commit them from linux working copy then pre-commit hooks works as they should. But when I commit my changes from Windows (using Tortoise or command line) commit execute but without any results of working scripts.
I have read, that scripts are lunched on PC that holds repository (correct me if I'm wrong), so it shouldn't be matter of what kind of platform I'm making changes.
So, if any one can explain me why this doesn't work from windows then I would be grateful?
The pre-commit hook is run by the machine that's hosting the server. If you're using the repository with a file:// URL or using svnlook or svnadmin commands then that's always the local machine since there isn't actually a server and the repository is accessed directly.
From the what you're saying it sounds to me like you're putting the repository on a network volume (SMB, NFS, etc) and then using a file:// URL to access it. If you use one of the other access methods then you won't have this problem.
You have 3 options.
svnserve
svnserve is a simple daemon that provides the svn:// access method. It listens on its own network port and talks a protocol that's specific to Subversion.
svnserve over ssh
The svnserve protocol is tunneled over ssh and a svnserve process is started on demand.
Apache HTTP
The mod_dav_svn and mod_authz_svn modules provide access to Subversion via an Apache httpd server. This uses the DAV and DeltaV protocols over HTTP (optionally with SSL/TLS support).
The SVN Book has a whole section on server setup that covers choosing the server to how to configure it. You probably want to read this before you make a choise and then read the configuration steps for your chosen server.

Apache, Linux and Remote Commands Like 'Ping'

I need to contact a server (perhaps Apache) running on a Linux box and have it return the following results. I am new to networking, but can write code in Java, PHP and maybe a little C.
I need to remotely run diagnostic tests from the Linux box on the local area network. Ultimately these tests need to be delivered to a web page on the client side.
I am not sure where to begin on this project and appreciate any suggestions or general strategies. I am familiar with a command written in Java (i.e., Runtime.getRuntime().exec("ping -c 1 " + ip); ), but I don't know if it is necessary to involve Java and I don't know how to startup a Java program on a server and return it to a PHP file. Is it possible to do this without involving Java? Again any specific or high- level suggestions are appreciated.
Perhaps you are looking for the exec function in PHP?
You can use exec function
-for ping:
//ping.php
<?php
exec ("/bin/ping -c 5 www.google.com", $response);
echo "<pre>" . join("\r\n", $response)."</pre>";
?>
use the php command-line in terminal
$ php ping.php

Executing exe or bat file on remote windows machine from *nix

I am trying to execute a bat file on remote windows machine on cloud from my Linux. The bat files starts selenium server and then my selenium tests are run. I am not able to start selenium RC server on that machine. I tried with Telnet but the problem with it is when telnet session is closed the RC server port is also closed. As my code my code has to start the server so I tried with ANT telnet task and also executed shell script of telnet in both ways the port was closed.
I read about Open SSH, psexec for linux and cygwin. But i am not getting how to use these and will they will solve my problem.
I have tried to start a service which will start the server but in this method i am not getting browser visible all tests are running in background as my script takes screen shot browser visibility is must.
Now my Question is what to use and which will be preferable for my job.
and what ever i choose should be executed by code it may be by shell, ant or php.
Thanks in advance.
Let's go through the various options you mentioned:
psexec: This is pretty much a PC only thing. Plus, you must make sure that newer Windows machines can get through the UAC that are setup by default. UAC is the thing you see all the time on Vista and Windows 7 when you try to do something that requires administrator's privileges. You can try something called winexe which is a Linux program that can do the psexec protocol, but I've had problems getting it to work.
OpenSSH: There are two main flavors of SSH, and Open SSH is the one used by the vast majority of sites. SSH has several advantages over other methods:
SSH is secure: Your network traffic is encrypted.
SSH can be password independent: You can setup SSH to use private/public keys. This way, you don't even have to know the password on the remote server. This makes it more secure since you don't have passwords being stored on various systems. And, in many Windows sites, passwords have to be changed every month or so or the account is locked.
SSH can do more than just execute remote commands: There are two sub-protocols on SSH called SCP and SFTP. These allow you to transfer files between two machines. Since they work over SSH, you get all of the advantages of SSH including encrypted packets, and public/private key protection.
SSH is well implemented in the Unix World: You'll find SSH clients built into Ant, Maven, and other build tools. Programs like CVS, Subversion, and Git can work over SSH connections too. Unfortunately, the Windows World operates in a different space time dimension. To use SSH on a Windows system requires third party software like Cygwin.
Cygwin: Cygwin is sort of an odd beast. It's a layer on top of Windows that allows many of the Unix/GNU libraries to work over Windows. It was originally developed to allow Unix developers to run their software on Windows DOS systems. However, Cygwin now contains a complete Unix like system including tools such as Perl and Python, BASH shell, and many utilities such as an SSH server. Since Cygwin is open source, you can download it for free and run SSH server. Unfortunately, I've had problems with Cygwin's SSH server. Another issue: If you're running programs remotely, you probably want to run them in a Windows environment and not the Cygwin environment.
I recommend that you look at WinSSHD from Bitvise. It's an OpenSSH implementation of the SSH Server, but it's not open source. It's about $100 per license and you need a license on each server. However, it's a robust implementation and has all of the features SSH has to offer.
You can look at CoSSH which is a package of Cygwin utilities and OpenSSH server. This is free and all open source, but if you want an easy way of setting it up, you have to pay for the Advanced Administrator Console. You don't need the Advanced Administrator Console since you can use Cygwin to set everything up, and it comes with a basic console to help.
I prefer to use cygwin and use SSH to then log in to the windows machine to execute commands. Be aware that, by default, cygwin doesn't have OpenSSH installed.
Once you have SSH working on the windows machine you can run a command on it from the Linux machine like this:
ssh user#windowsmachine 'mycommand.exe'
You can also set up ssh authentication keys so that you don't need to enter a password each time.
I've succeeded to run remote command on W2K3 via EXPECT on Debian Buster. Here is the script of mine:
#!/usr/bin/expect
#
# execute the script in the following manner:
#
# <script> <vindoze> <user> <password> <command>
#
#
set timeout 200
set hostname [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set command [lindex $argv 3]
spawn telnet $hostname
expect "login:"
send "$username\r"
expect "password:"
send "$password\r"
expect "C:*"
send "dir c:\\tasks\\logs \r"
# send $command
expect "C:*"
send "exit\r\r\r"
Bear in mind that you need to enable TELNET service of the Win machine and also the user which you are authenticated with must be member of TelnetClients built-in Win group. Or as most of the Win LazyMins do - authenticate with Admin user ;)
I use similar "expect" script for automated collecting & backup configuration of CLI enabled network devices like Allied Telesyn, Cisco, Planet etc.
Cheers,
LAZA
Not a very secure way, but if you have a running webserver you can use PHP or ASP to trigger a system command. Just hide thgat script under www.myserver.com/02124309c9867a7616972f52a55db1b4.php or something. And make sure the command are fixed written in the code, not open via parameter ...

Resources