Virtual Hosting: Portable PAC issues

From The Uniform Server Wiki
Jump to navigation Jump to search

MPG UniCenter

Virtual Hosting: Home | Name based | PAC | Browsers and PAC | Making it portable | Issues

PAC Portable Issues
Uniform Server 3.5-Apollo

A few days after publishing a portable solution using PAC and Firefox I was a little surprised to be informed that my proposed solution does not work.

These are a few examples of the problems reported:

  • An instance of so and so browser is running! The answer to this one is close all browsers down before running the portable one.
  • UniServer insists on running a PCs default browser when run, not a real problem close that browser down; start the portable one, type in appropriate URL and all will be OK.
  • Several users hacked UniServer’s start batch file to run both browser and UniServer with varying degrees of success, Fire fox cannot be found, Opera runs and does not find the redirect page.
  • One user even wanted to run the entire set-up when the USB is plugged in.

The following attempts to address these issues.

What I Use

I use XP-Home SP2 and as a matter of course just close internal browsers down. I have no problem with Uniform Server firing up the local browser just an irritation; close that down as well. With both browsers I had no problem with the DNS simulator.

I do have a problem when both my favorite browsers come under the spotlight but try as I may I could not get Opera Portable to start-up with an external web page. Hence the following solution addresses the above problems using my preferred browser Firefox.

Top

Firefox the only portable solution

Cannot find Firefox

This is not a problem with Firefox but with batch files. In general most books state that a batch file will pick up its environment from the location from where it is run (i.e. drive letter and current folder). Now take a step back and read what I have written more importantly what is assumed.

Take an extreme example I have a batch file named test.bat on G: drive this batch file contains the instruction set newdrive=%~dp0. I run test.bat, as expected will pick up the correct environment (i.e. drive letter and current folder).

I have a second batch file test2.bat on drive Z: this contains a single instruction to run file test.bat. What will be the drive letter picked up by set newdrive=%~dp0 in test.batch? Confused!

Good you are in keeping with XP, batch file test.bat is not run from drive G in reality its run from drive Z. Its all semantics but the bottom line it does not pick up drive G as expected but Z. Hence if you set a variable to the current drive expecting it to be set to G any reference to a file located on G will produce a not found error.

OK! I lied XP is not confused, hidden is a very powerful concept; drive Z (or any other drive) can be located anywhere on a network. To run a program or batch file it is pulled into the current location hence an external file is referenced to this location. Knowing this you will understand why I call the following a magic bullet.

Magic bullet

To fix a reference points (where the file is physically located) for any batch file use the commands pushd and popd at the start and end of a batch respectively.

pushd: Saves to memory where you have come from and then force the new location to be that of the current file.

popd: This is the reverse of pushd, reads from memory where you came from and reinstates it.

To pick up the current drive letter (where the batch file resides) use this:

How to obtain batch file drive letter
pushd %~dp0
set current_drive=%~dp0
....
batch file code
....
popd

Top

An instance of Firefox is already running

Use pskill.exe in batch files to stop any currently running versions of Firefox. We want to use the portable version on our memory stick which uses the PAC file.

New batch files

Create two new batch files (use existing ones as templates)to start and stop the servers, integrate the above two solutions.

Files look like this additions are highlighted in bold:

Fire_fox_Server_Start.bat
: Name: Start Server File
: Created By: The Uniform Server Development Team
: Edited Last By: Olajide Olaolorun (empirex)
: Comment: After start, go to apanel directly.
: To Developers: Implemented %www%, and %apanel% :)
: MPG Firefox portable mods 25-4-07
@echo off

rem use: start mysql console - to start mysql at server start and display console
rem use: start mysql - to start mysql at server start
rem use: start nomysql console - to display console

rem============ FIREFOX INFO =========================================
rem Add these six lines. Change the paths as needed
pushd %~dp0
diskw\home\admin\program\pskill.exe firefox.exe c
diskw\home\admin\program\pskill.exe FirefoxPortable.exe c
set drive=%~d0
set startfile=file:///%drive%\UniformServer\diskw\home\admin\www\redirect.html
set browser=%drive%\portableapps\FirefoxPortable\FirefoxPortable.exe

diskw\home\admin\program\pskill.exe Apache.exe
IF NOT ERRORLEVEL 1 goto started
set Disk=%1
IF "%Disk%"=="" set Disk=w
rem create the disk
subst %Disk%: "diskw"
IF ERRORLEVEL 1 goto hint
set apachepath=\usr\local\apache2\
set apacheit=%Disk%:%apachepath%bin\Apache.exe -f %apachepath%conf\httpd.conf -d %apachepath%.
set programit=%Disk%:\home\admin\program\
set closeit=%programit%close.bat %Disk%

%Disk%:
cd \usr\local\php
IF "%2"=="mysql" start \usr\local\mysql\bin\mysqld-opt.exe --defaults-file=/usr/local/mysql/bin/my-small.cnf
CLS
echo The server is working on the disk %Disk%:\ [http/127.0.0.1/apanel/]
set www=\www\
set apanel=\home\admin\www\

rem======= FIREFOX INFO =================================
rem 1) Comment out line add new line to start Firefox
rem 2) Starts FF with file specified
:start %apanel%\redirect.html
start %browser% %startfile%

IF "%3"=="console" goto console
start %programit%uniserv.exe "%apacheit%" "%closeit%"
goto end
:console
%apacheit%
%closeit%
goto end
:hint
CLS
echo The disk %Disk% is busy. Use 'Disk Start.vbs' [disk letter]
goto pause
:started
CLS
echo ERROR!!!
echo One of the instances of Apache server is started. Use Stop.bat
:pause
echo .
pause
:end

rem============ FIREFOX INFO ==========================
popd

The first line in bold may not be required!

Fire_fox_Stop.bat
: Name: Stop Server File
: Created By: The Uniform Server Development Team
: Edited Last By: Olajide Olaolorun (empirex)
: Comment: Tara's new syetm of shutting down the server
: To Developers: Implemented a new system of server shutdown
: MPG Firefox portable mods 25-4-07

@echo off
diskw\home\admin\program\pskill.exe Apache.exe c

diskw\home\admin\program\pskill.exe firefox.exe c
diskw\home\admin\program\pskill.exe FirefoxPortable.exe c

if errorlevel 2 goto :PAUSE

:PAUSE
echo .
pause

:END

Save the fies in folder Uniform Server

Top

Auto Run

Check you can start and stop the server using the above batch file. Auto run uses the start batch file. You need to create a file named autorun.inf in the root folder of you memory stick. The one I used for testing is shown below:

autorun.inf
[autorun]
open=UniformServer\Fire_fox_Server_Start.bat
action=Launch UniformServer\Fire_fox_Server_Start.bat
label=MPG

When your memory stick is plugged in you will receive the following message just click OK:

Launch UniformServer\Fire_fox_Server_Start.bat using the program provided on the device

Conclusion

The above is not a definitive guide however it will allow you to experiment. The paths will need changing to meet your file structure.

Top


Ric