#!/usr/bin/perl # $Id: index.cgi,v 1.1 2005/10/11 07:46:17 toshi Exp $ # Copyright (C) 2005 kinotrope, Inc. All rights reserved. # # Apache requied. use strict; require './idx_lib.cgi'; $SIG{__DIE__} = sub { warn @_ if 0; go_redirect("/"); exit(0); }; sub get_lang_def { my $file = shift; local *IN, $/; my %def; open IN, $file; undef $/; my $buff = ; close IN; $buff =~ s/\r\n/\n/g; $buff =~ s/\r/\n/g; foreach (split /\n/, $buff) { s/#.*$//; s/\s+$//; next if /^#/; next if /^\s*$/; my($lang, $dir) = split /\s+/; $def{$lang} = $dir; } return %def; } # Here we go! my $uri = $ENV{REQUEST_URI} or die "error #1\n"; die "error #2\n" if $uri =~ /\.cgi/; # direct my $droot = $ENV{DOCUMENT_ROOT} or die "error #3\n"; die "error #5\n" unless -d $droot; my %fixed = get_lang_def('./language.txt'); my @lang = get_accept_lang(); foreach my $al (@lang) { go_redirect($fixed{$al}) if exists $fixed{$al}; my($l, $c) = split '-', $al, 2; next unless $c; go_redirect("/$c/$l/index.html") if -d $droot . "/$c/$l"; } go_redirect("/js.html"); # vi:set ts=4 sm sw=4 ai: