| USB self-contained server |
Introduction
With the release of Uniform Server V4.0-Mona thought I would revisit a self-contained server on a USB memory stick. This includes portable Firefox and a PAC file simulating a portable DNS server.
This really is intended as a teaching and development server. A PAC file avoids using the hosts file. On Vista this can be a pain before it can be edited requires administrator privileges.
The following components are required:
Install Uniform Server
Install Firefox Portable
Note: To run double click on FirefoxPortable.exe (located in folder *\fx3\FirefoxPortable)
The easiest way to create a virtual host is to use Apanel however this writes to the hosts file. To avoid this edit Apache's config file and add the virtual host(s) manually.
Edit file: L:\usr\local\apache2\conf\httpd.conf (Note your drive letter may be different)
Navigate to the end of this file and just under the default host (localhost:80) add the new host section:
NameVirtualHost * <VirtualHost *> ServerName localhost:80 DocumentRoot /www </VirtualHost> ##########VIRTUAL HOST SETUP########## # CENTER.UNIFORMSERVER.COM <VirtualHost *> ServerName center.uniformserver.com DocumentRoot /www/center </VirtualHost>
I am using ServerName center.uniformserver.com and DocumentRoot /www/center use your real domain and create the appropriate folder in L:\www (again your drive letter may be different)
Create the following file and save as test.pac to root folder L:\www
| test.pac File |
|---|
function FindProxyForURL(url, host)
{
if (shExpMatch(url,"http://center.uniformserver.com/*")) return "PROXY 127.0.0.1";
return "";
}
|
When the USB stick is plugged in we need to start Firefox and UniController.
It is possible that a version of Firefox is already running, this will prevent our portable version running hence first kill any running Firefox. Then start UniController, since there are several commands these are placed in a batch file which is run by autorun.
Create a new batch file ff_pac.bat and save to USB root
| ff_pac.bat |
|---|
TITLE UNIFORM SERVER - PAC COLOR B0 mode con:cols=60 lines=20 @echo off cls rem ################################################### rem # Name: ff_pac.bat rem # Location: root of USB stic rem # Edited Last By: MPG (ric) rem # V 1.0 7-2-2009 rem ################################################## echo. rem working directory current folder pushd %~dp0 rem ### kill running FF home\admin\program\pskill.exe firefox.exe c home\admin\program\pskill.exe FirefoxPortable.exe c rem ### start USB Firefox start fx3\FirefoxPortable\FirefoxPortable.exe rem ### Before starting UniController wait for FF to start rem ### Safety loop counter cnt give up after 60 seconds echo Starting FF ............... echo. set /a cnt=0 :next1 set /a cnt+=1 if "%cnt%"=="60" goto :TIMEDOUT home\admin\program\unidelay.exe home\admin\program\pskill.exe FirefoxPortable.exe > nul IF ERRORLEVEL 1 goto :next1 rem ### start UniController home\admin\program\unidelay.exe 4 start unicontroller.exe goto :END :TIMEDOUT echo Unable to start FF pause :END rem restore original working directory popd |
First check you can start Firefox and UniController using the batch file.
Now create a file named autorun.inf and save to USB root. The one I used for testing is shown below:
| autorun.inf |
|---|
[autorun] open=ff_pac.bat action=Run FF UniController icon=docs\SRC\uslogo.ico |
When your memory stick is plugged in you will receive the following message just click OK:
Launch FF UniformServer using the program provided on the device
The above was not intended to be a definitive guide it provides a working example that you can expand for your own applications.
Instead of using UniController you can use batch files. This is covered on the following pages Virtual Hosting, although written for 3.5 the material is transferable to 4.0-Mona.