Replace episode selection CGI with a PHP script
This commit is contained in:
parent
98d276c9b1
commit
447bce65b3
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$domains = array(
|
||||||
|
'.euro.net' => 'countries/nl/eplist.html',
|
||||||
|
'.pr.us' => 'countries/pr/eplist.html',
|
||||||
|
'.ar' => 'countries/wbtv/eplist.html',
|
||||||
|
'.at' => 'countries/at/eplist.html',
|
||||||
|
'.au' => 'countries/au/eplist.html',
|
||||||
|
'.au' => 'countries/au/eplist.html',
|
||||||
|
'.be' => 'countries/be/eplist.html',
|
||||||
|
'.br' => 'countries/wbtv/eplist.html',
|
||||||
|
'.ca' => 'countries/ca/eplist.html',
|
||||||
|
'.cl' => 'countries/cl/eplist.html',
|
||||||
|
'.co' => 'countries/co/eplist.html',
|
||||||
|
'.cr' => 'countries/cr/eplist.html',
|
||||||
|
'.cz' => 'countries/cz/eplist.html',
|
||||||
|
'.de' => 'countries/de/eplist.html',
|
||||||
|
'.es' => 'countries/es/eplist.html',
|
||||||
|
'.fi' => 'countries/fi/eplist.html',
|
||||||
|
'.fr' => 'countries/fr/eplist.html',
|
||||||
|
'.gb' => 'countries/uk/eplist.html',
|
||||||
|
'.gr' => 'countries/gr/eplist.html',
|
||||||
|
'.id' => 'countries/id/eplist.html',
|
||||||
|
'.ie' => 'countries/uk/eplist.html',
|
||||||
|
'.il' => 'countries/il/eplist.html',
|
||||||
|
'.it' => 'countries/it/eplist.html',
|
||||||
|
'.jo' => 'countries/jo/eplist.html',
|
||||||
|
'.my' => 'countries/id/eplist.html',
|
||||||
|
'.nl' => 'countries/nl/eplist.html',
|
||||||
|
'.no' => 'countries/no/eplist.html',
|
||||||
|
'.nz' => 'countries/nz/eplist.html',
|
||||||
|
'.pe' => 'countries/pe/eplist.html',
|
||||||
|
'.ph' => 'countries/ph/eplist.html',
|
||||||
|
'.pk' => 'countries/pk/eplist.html',
|
||||||
|
'.pl' => 'countries/pl/eplist.html',
|
||||||
|
'.pt' => 'countries/pt/eplist.html',
|
||||||
|
'.ru' => 'countries/ru/eplist.html',
|
||||||
|
'.se' => 'countries/se/eplist.html',
|
||||||
|
'.sg' => 'countries/sg/eplist.html',
|
||||||
|
'.si' => 'countries/si/eplist.html',
|
||||||
|
'.uk' => 'countries/uk/eplist.html',
|
||||||
|
'' => 'countries/us/eplist.html',
|
||||||
|
);
|
||||||
|
|
||||||
|
$remote_host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
|
||||||
|
$server_name = $_SERVER['SERVER_NAME'];
|
||||||
|
|
||||||
|
foreach ($domains as $suffix => $url) {
|
||||||
|
if (!$suffix || substr($remote_host, -strlen($suffix)) == $suffix) {
|
||||||
|
header("Location: http://$server_name/lurk/$url");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print file_get_contents('internal/dom-error.html');
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
DEFAULT countries/us/eplist.html
|
|
||||||
.ca countries/ca/eplist.html
|
|
||||||
.uk countries/uk/eplist.html
|
|
||||||
.ie countries/uk/eplist.html
|
|
||||||
.fi countries/fi/eplist.html
|
|
||||||
.se countries/se/eplist.html
|
|
||||||
.gb countries/uk/eplist.html
|
|
||||||
.fr countries/fr/eplist.html
|
|
||||||
.gr countries/gr/eplist.html
|
|
||||||
.id countries/id/eplist.html
|
|
||||||
.au countries/au/eplist.html
|
|
||||||
.be countries/be/eplist.html
|
|
||||||
.cl countries/cl/eplist.html
|
|
||||||
.pt countries/pt/eplist.html
|
|
||||||
.co countries/co/eplist.html
|
|
||||||
.cr countries/cr/eplist.html
|
|
||||||
.de countries/de/eplist.html
|
|
||||||
.my countries/id/eplist.html
|
|
||||||
.nl countries/nl/eplist.html
|
|
||||||
.euro.net countries/nl/eplist.html
|
|
||||||
.pr.us countries/pr/eplist.html
|
|
||||||
.il countries/il/eplist.html
|
|
||||||
.au countries/au/eplist.html
|
|
||||||
.sg countries/sg/eplist.html
|
|
||||||
.at countries/at/eplist.html
|
|
||||||
.pe countries/pe/eplist.html
|
|
||||||
.ph countries/ph/eplist.html
|
|
||||||
.pk countries/pk/eplist.html
|
|
||||||
.es countries/es/eplist.html
|
|
||||||
.ru countries/ru/eplist.html
|
|
||||||
.jo countries/jo/eplist.html
|
|
||||||
.no countries/no/eplist.html
|
|
||||||
.si countries/si/eplist.html
|
|
||||||
.nz countries/nz/eplist.html
|
|
||||||
.pl countries/pl/eplist.html
|
|
||||||
.br countries/wbtv/eplist.html
|
|
||||||
.ar countries/wbtv/eplist.html
|
|
||||||
.it countries/it/eplist.html
|
|
||||||
.cz countries/cz/eplist.html
|
|
||||||
|
|
@ -52,7 +52,7 @@ href="/lurk/universe/intro.html"><img
|
||||||
src="nav/title/universe.gif" width=162 height=114 border=0 align=middle
|
src="nav/title/universe.gif" width=162 height=114 border=0 align=middle
|
||||||
alt="[The Babylon 5 Universe]"></a><a
|
alt="[The Babylon 5 Universe]"></a><a
|
||||||
|
|
||||||
href="/cgi-bin/select-eplist"><img
|
href="/lurk/episodes.php"><img
|
||||||
src="nav/title/episodes.gif" width=162 height=114 border=0 align=middle
|
src="nav/title/episodes.gif" width=162 height=114 border=0 align=middle
|
||||||
alt="[The Episodes]"></a><a
|
alt="[The Episodes]"></a><a
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
* Select an episode list to show based on a control file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define LISTFILE "/home/koreth/lurk/internal/domainlist"
|
|
||||||
char * BASEDIR = "/home/koreth/lurk/";
|
|
||||||
#define ERRORFILE "/home/koreth/lurk/internal/dom-error.html"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
char *getenv();
|
|
||||||
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
char domain[100], filename[500], bestname[500];
|
|
||||||
char *hisdomain, *mapbuf;
|
|
||||||
int matchlen = 0, hislen, thislen, i, c, fd;
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
chdir(BASEDIR);
|
|
||||||
|
|
||||||
printf("Content-type: text/html\n");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the remote domain name and make it lower case.
|
|
||||||
*/
|
|
||||||
hisdomain = getenv("REMOTE_HOST");
|
|
||||||
if (hisdomain == NULL)
|
|
||||||
hisdomain = strdup("com");
|
|
||||||
hislen = strlen(hisdomain);
|
|
||||||
for (i = 0; i < hislen; i++)
|
|
||||||
hisdomain[i] = tolower(hisdomain[i]);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now read list entries and find the filename with the longest
|
|
||||||
* matching domain name.
|
|
||||||
*/
|
|
||||||
fp = fopen(LISTFILE, "r");
|
|
||||||
if (fp)
|
|
||||||
{
|
|
||||||
/* First entry is the default filename. */
|
|
||||||
fscanf(fp, "%s %s", domain, bestname);
|
|
||||||
|
|
||||||
while (fscanf(fp, "%s %s", domain, filename) > -1)
|
|
||||||
{
|
|
||||||
thislen = strlen(domain);
|
|
||||||
if (thislen > matchlen && thislen <= hislen)
|
|
||||||
{
|
|
||||||
if (! strcmp(domain, hisdomain+hislen-thislen))
|
|
||||||
{
|
|
||||||
strcpy(bestname, filename);
|
|
||||||
matchlen = thislen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strcpy(bestname, ERRORFILE);
|
|
||||||
|
|
||||||
printf("Location: http://%s/lurk/%s\n\n", getenv("SERVER_NAME"),
|
|
||||||
bestname);
|
|
||||||
}
|
|
||||||
|
|
@ -1,129 +0,0 @@
|
||||||
/*
|
|
||||||
* Select an episode list to show based on a control file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define LISTFILE "/home/koreth/lurk/internal/domainlist"
|
|
||||||
char * BASEDIR = "/home/koreth/lurk/";
|
|
||||||
#define ERRORFILE "/home/koreth/lurk/internal/dom-error.html"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
char *getenv();
|
|
||||||
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
char domain[100], filename[500], bestname[500];
|
|
||||||
char *hisdomain, *mapbuf;
|
|
||||||
int matchlen = 0, hislen, thislen, i, c, fd;
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
chdir(BASEDIR);
|
|
||||||
|
|
||||||
printf("Content-type: text/html\n");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the remote domain name and make it lower case.
|
|
||||||
*/
|
|
||||||
hisdomain = getenv("REMOTE_HOST");
|
|
||||||
if (hisdomain == NULL)
|
|
||||||
hisdomain = strdup("com");
|
|
||||||
hislen = strlen(hisdomain);
|
|
||||||
for (i = 0; i < hislen; i++)
|
|
||||||
hisdomain[i] = tolower(hisdomain[i]);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now read list entries and find the filename with the longest
|
|
||||||
* matching domain name.
|
|
||||||
*/
|
|
||||||
fp = fopen(LISTFILE, "r");
|
|
||||||
if (fp)
|
|
||||||
{
|
|
||||||
/* First entry is the default filename. */
|
|
||||||
fscanf(fp, "%s %s", domain, bestname);
|
|
||||||
|
|
||||||
while (fscanf(fp, "%s %s", domain, filename) > -1)
|
|
||||||
{
|
|
||||||
thislen = strlen(domain);
|
|
||||||
if (thislen > matchlen && thislen <= hislen)
|
|
||||||
{
|
|
||||||
if (! strcmp(domain, hisdomain+hislen-thislen))
|
|
||||||
{
|
|
||||||
strcpy(bestname, filename);
|
|
||||||
matchlen = thislen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strcpy(bestname, ERRORFILE);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Output the file in question.
|
|
||||||
*/
|
|
||||||
fd = open(bestname, 0);
|
|
||||||
if (fd < 0)
|
|
||||||
fd = open(ERRORFILE, 0);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
|
||||||
err:
|
|
||||||
printf("\n<html><body><h1>Fatal error!</h1>\n");
|
|
||||||
printf("Can't find an episode list.</body></html>\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fstat(fd, &st))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
#if defined(MAP_FAILED) && defined(MAP_SHARED) /* { */
|
|
||||||
mapbuf = mmap(NULL, (size_t) st.st_size, PROT_READ,
|
|
||||||
MAP_SHARED, fd, (off_t) 0);
|
|
||||||
if (mapbuf == MAP_FAILED)
|
|
||||||
{
|
|
||||||
perror("eplist: mmap");
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
printf("Content-length: %lu\n\n", (unsigned long)st.st_size);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
write(1, mapbuf, (unsigned long)st.st_size);
|
|
||||||
|
|
||||||
#else /* }{ */
|
|
||||||
printf("Content-length: %lu\n\n", (unsigned long)st.st_size);
|
|
||||||
|
|
||||||
fp = fdopen(fd, "r");
|
|
||||||
while ((c = getc(fp)) != EOF)
|
|
||||||
putchar(c);
|
|
||||||
fclose(fp);
|
|
||||||
fflush(stdout);
|
|
||||||
#endif /* } */
|
|
||||||
|
|
||||||
close(1);
|
|
||||||
|
|
||||||
{
|
|
||||||
char *c, *val;
|
|
||||||
|
|
||||||
val = getenv("HTTP_USER_AGENT");
|
|
||||||
for (c = val; *c; c++)
|
|
||||||
if (*c == '/')
|
|
||||||
*c = '#';
|
|
||||||
|
|
||||||
chdir("/home/woodstock/koreth/browsers");
|
|
||||||
fd = open(val, O_RDWR | O_APPEND | O_CREAT, 0644);
|
|
||||||
write(fd, val, 1);
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue