Author Topic: set cgi_web and album_web automatically  (Read 3224 times)

0 Members and 1 Guest are viewing this topic.

Offline EmTeedee

  • album.pl User
  • *
  • Posts: 2
  • Karma: +1/-0
  • I forgot to change the default text
set cgi_web and album_web automatically
« on: February 28, 2005, 15:33:45 »
My Photo Album was hosted on a PC in our Intranet. The same PC was also reachable from the internet through our firewall (port forwarding).
So local users could reach the album with http://foo.bar.local/PhotoAlbum
users from the internet had to use http://foo.dyndns.org:8080/PhotoAlbum
Thus it was impossible to set album_web and cgi_web for both. :'(

Luckily the Apache Web-Server provides some environment variables. ;D

To use this patch, you have to edit your album.cfg:
  • add GetPathsFromEnv=1
  • adjust album_web (it should be relative to your server root e.g. /PhotoAlbum )
(Just for your information: cgi_web is totally ignored, deal with it as you please)

Of course you have to edit your album.pl too:

replace

Code: [Select]
# Full (local) path to album.pl - don't change this
$::albumprog=$0;

debug("\$0: $0",2,__LINE__);

# Change all \'s to /'s
$::albumprog=~s/\\/\//g;

# Drop the preceeding path
$::albumprog=~s/.*\/(.*)/$1/;

$::albumprog=$::cgi_web."/".$::albumprog;

with

Code: [Select]
if (!$::GetPathsFromEnv || $::GetPathsFromEnv=='0') {
 
# Full (local) path to album.pl - don't change this
$::albumprog=$0;

debug("\$0: $0",2,__LINE__);

# Change all \'s to /'s
$::albumprog=~s/\\/\//g;

# Drop the preceeding path
$::albumprog=~s/.*\/(.*)/$1/;

$::albumprog=$::cgi_web."/".$::albumprog;
}
else {
debug("Try to get Paths from Environment",2,__LINE__);

# Save to say that album.pl is the current script
$::albumprog=$ENV{SCRIPT_URI};

# And I figure that album.pl is in the cgi-bin directory
$::cgi_web=$ENV{SCRIPT_URI};
$::cgi_web=~s/(.*)\/.*/$1/;
debug("CGI Web Path : $::cgi_web",2,__LINE__);

# Unfortunately the local album directory could be anywhere
#  (see DIRECTORY directive in httpd.conf)
# I think I can handle this by requesting a relative path in album_web
# and an absolute path in album_dir (no need to touch this)
my $tempPath=$ENV{SCRIPT_URI};
$tempPath=~s/^(.*?\/\/.*?)\/.*/$1/;
$::album_web=$tempPath.$::album_web;
debug("Album Web Path : $::album_web",2,__LINE__);
}

If you feel the need, search for "# Numeric variables" and add "$::GetPathsFromEnv" in the line below. (Should read like this:
Code: [Select]
[..blabla..]$::shadow_background=$::GetPathsFromEnv=0; but this is just for cosmetics  ;))

Good Luck...

This patch is meant for album.pl V6.5

Offline Mike Bobbitt

  • album.pl Author
  • Administrator
  • I Spend Too Much Time Here
  • *****
  • Posts: 3381
  • Karma: +35/-2
    • Mike's Development Archive
Re: set cgi_web and album_web automatically
« Reply #1 on: March 01, 2005, 11:15:22 »
Very cool! Nice clean work, thanks for the update! :)

Offline kl

  • album.pl User
  • *
  • Posts: 7
  • Karma: +0/-0
  • I forgot to change the default text
Re: set cgi_web and album_web automatically
« Reply #2 on: July 09, 2005, 09:07:15 »
Yes, It worked perfectly. thanks for the code