Gossamer Forum
Home : Products : Links 2.0 : Customization :

How to hack info.cgi = category.cgi ?

Quote Reply
How to hack info.cgi = category.cgi ?
Hello all,

Is it possible to hack the info.cgi mod to be like a category.cgi mod ? I just think logically here, as usual info.cgi is open ID base on links.def, but is it possible to open ID base on category.def? for example, /cgi-bin/info.cgi?ID=5 means it will open the directory /homepage/Computer/ and list down the links inside the directory, Please give me the hint for this.

Thanks.

Last edited by:

reenee: Oct 1, 2001, 11:58 AM
Quote Reply
Re: [reenee] How to hack info.cgi = category.cgi ? In reply to
Hi,

Glennu has a dynamic category mod at:

http://cgi-resource.co.uk/cgi-bin/gotomod.cgi?id=3

Hope this helps.

ATKOgirl


Quote Reply
Re: [reenee] How to hack info.cgi = category.cgi ? In reply to
Not really too hard. Here is some basic code; it is NOT guarenteed to work as I have not done any testing or proofreading. do NOT try to run it.

Code:
my $in = param('cat');
my $name_col = 1;
my $cat_col = 6;
my $cat = {};
my $subs = {};
my $links = [];
open (DB, "categories.db");
while (<DB>) {
chomp;
my $data = split /\|/;
if ($data->[$name_col] eq $in) {
my $i = 0;
foreach (sort { $a->[0] <=> $b->[0]} keys %db_def) {
$cat->[$_] = $data->[$i++]
}
}
elsif ($data->[$name_col] =~ m,$in/[^/]+$,) {
$subs{$data->[$name_col]} = 0;
}
else {
next;
}
}
close (DB);
($cat->{$in} eq $in) or die "Category $in not found";
open (DB, "links.db");
while (<DB>) {
chomp;
my $data = split /\|/;
if ($data->[$cat_col] eq $in) {
push @$links, [@$data];
} elsif ($data->[$cat_col] =~ m,$in/[^/]+$,) {
${$subs->{$data->[$cat_col]}}++;
}
else {
next;
}
}
close (DB);
print header();
print start_html();
if (scalar keys %$subs) {
print "Categories:";
print "<ul>";
foreach (sort keys %$subs) {
print qq|<li>$_ ($subs->{$_})|;
}
print "</ul>";
}
if (scalar @$links) {
require "admin/links.def";
print "Links:";
print "<ul>";
forach (sort { $a->[0] cmp $b->[0] } @$links ) {
my $link = {};
my $i = 0;
foreach (sort { $a->[0] <=> $b->[0]} keys %db_def) {
$link->[$_] = $_->[$i++]
}
print qq|<li><a href="$link->{'URL'}">$link->{'Title'}</a><br>$link->{'Description'}|;
}
}
print end_html();

--Philip
Links 2.0 moderator
Quote Reply
Re: [PerlFreak] How to hack info.cgi = category.cgi ? In reply to
Hi Drew,

Thanks for reply, i try the mod and get the header from info.cgi and rename it to test.cgi, and i test it /cgi-bin/test.cgi?=ID=5 but only appear is a blank page, can you modify it to work ? sorry to my english.

Quote:
#!/usr/bin/perl

eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1");
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1");
use CGI qw/:standard/;
require "admin/links.cfg";
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}

my $in = param('cat');
my $name_col = 1;
my $cat_col = 6;
my $cat = {};
my $subs = {};
my $links = [];
open (DB, "categories.db");
while (<DB>) {
chomp;
my $data = split /\|/;
if ($data->[$name_col] eq $in) {
my $i = 0;
foreach (sort { $a->[0] <=> $b->[0]} keys %db_def) {
$cat->[$_] = $data->[$i++]
}
}
elsif ($data->[$name_col] =~ m,$in/[^/]+$,) {
$subs{$data->[$name_col]} = 0;
}
else {
next;
}
}
close (DB);
($cat->{$in} eq $in) or die "Category $in not found";
open (DB, "links.db");
while (<DB>) {
chomp;
my $data = split /\|/;
if ($data->[$cat_col] eq $in) {
push @$links, [@$data];
} elsif ($data->[$cat_col] =~ m,$in/[^/]+$,) {
${$subs->{$data->[$cat_col]}}++;
}
else {
next;
}
}
close (DB);
print header();
print start_html();
if (scalar keys %$subs) {
print "Categories:";
print "<ul>";
foreach (sort keys %$subs) {
print qq|<li>$_ ($subs->{$_})|;
}
print "</ul>";
}
if (scalar @$links) {
require "admin/links.def";
print "Links:";
print "<ul>";
foreach (sort { $a->[0] cmp $b->[0] } @$links ) {
my $link = {};
my $i = 0;
foreach (sort { $a->[0] <=> $b->[0]} keys %db_def) {
$link->[$_] = $_->[$i++]
}
print qq|<li><a href="$link->{'URL'}">$link->{'Title'}</a><br>$link->{'Description'}|;
}
}
print end_html();

Thanks again.

Last edited by:

reenee: Oct 2, 2001, 2:31 AM
Quote Reply
Re: [reenee] How to hack info.cgi = category.cgi ? In reply to
There's a missing ; here:

$cat->[$_] = $data->[$i++]
Quote Reply
Re: [RedRum] How to hack info.cgi = category.cgi ? In reply to
I said do NOT try to run the script. It's NOT finished.
Quote:
it is NOT guarenteed to work as I have not done any testing or proofreading. do NOT try to run it.

--Philip
Links 2.0 moderator
Quote Reply
Re: [PerlFreak] How to hack info.cgi = category.cgi ? In reply to
In Reply To:
I said do NOT try to run the script. It's NOT finished.
I'm so sorry Drew, i just need to try as long i only have very limit cgi knowledge i get from this forum since i joined, by the way, can you finish the script ?

Please help and please forgive me Frown

Last edited by:

reenee: Oct 2, 2001, 10:18 AM
Quote Reply
Re: [reenee] How to hack info.cgi = category.cgi ? In reply to
Hi Drew,

Hope you will continue the code and make it complete to run.

Thank you.
Quote Reply
Re: [reenee] How to hack info.cgi = category.cgi ? In reply to
Hi Drew,

Can you do something how to make the info.cgi run as category.cgi ?

Please help and thank you so much.