#!/usr/bin/perl # ------------- # Links # ------------- # Links Manager # # File: admin.cgi # Description: This is the administrative interface for the links program. # Author: Alex Krohn # Email: alex@gossamer-threads.com # Web: http://www.gossamer-threads.com/ # Version: 2.01 # # (c) 1998 Gossamer Threads Inc. # # This script is not freeware! Please read the README for full details # on registration and terms of use. # ===================================================================== # # Required Librariers # -------------------------------------------------------- eval { ($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX / ($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \ require 5.001; # Make sure we have at least perl 5.001. require "/home/public_html/cgi-bin/links/admin/links.cfg"; # Change this to full path to links.cfg if you have problems. require "$db_lib_path/db.pl"; require "$db_lib_path/linksa.def"; require "$db_lib_path/db_utils.pl"; # Database Support utilities. require "$db_lib_path/site_html_templates.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; } $font = 'font color="red" face="verdana,arial,helvetica" size="2"'; $font_title = 'font face="verdana,arial,helvetica" size="4"'; # ======================================================== eval { &main; }; # Trap any fatal errors so the program hopefully if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page. exit; # There are only two exit calls in the script, here and in in &cgierr. # ======================================================== sub main { # -------------------------------------------------------- $| = 1; # Flush Output Right Away # Main Menu. Check to see what the user requested, then if he has permission for that # request, do it. Otherwise send the user off to an unauthorized request page. %in = &parse_formn; # Get form input so we know which database to load. # Load the database definition file and set the link url. # $in{'db'} ? # require "$db_lib_path/$in{'db'}.def" : # require "$db_lib_path/links.def"; # mod to change where links gets the cgi # left unchanged, $db_script_url points to admin.cgi # and you cannot access admin.cgi without a password # $build_search2_url is defined in links.cfg and points to this file. $db_script_url = $build_search2_url; # The functions beginning with &html_ can be found in admin_html.pl, while the other # functions can be found in db.pl if ($in{'view_search'}) { &site_html_search_form; } # Display form to search database. elsif ($in{'view_records'}) { &view_records; } # Search database and print results. else { &html_home; } # Display Frame Index page. # &cgierr("Done"); # Uncomment this line for Debugging... #Will tack on form variables and environment variables # to the end of every page. Quite Useful. } sub view_records { # -------------------------------------------------------- # This is called when a user is searching the database for # viewing. All the work is done in query() and the routines just # checks to see if the search was successful or not and returns # the user to the appropriate page. my ($status, @hits) = &query("view"); if ($status eq "ok") { &html_view_success(@hits); } else { &html_view_failure($status); } } # from the Links 2 site_html_templates.html file # just renamed sub html_home { #sub site_html_search_form { # -------------------------------------------------------- # This routine displays the search form. &html_print_headers; print &load_template ('searchdbm.html', { term => $term, error => $error, %in, %globals }); } # from the Links 2 site_html_templates.html file # and combined with the dbman templates file sub html_view_success { #sub html_view_success { from dbm_db_templates_html.pl my @hits = @_; my ($numhits) = ($#hits+1) / ($#db_cols+1); my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits); &html_print_headers(); if ($db_next_hits) { $link_results .= "
<$font>Pages: $db_next_hits"; } # Go through each hit and convert the array to hash and send to # html_record for printing. $cat_hits = 0; $link_hits = $numhits; $q_string = $ENV{'QUERY_STRING'}; for (0 .. $numhits - 1) { $link_results .= "

"; $link_results .= &site_html_link (&array_to_hash($_, @hits)); } if ($db_next_hits) { $link_results .= "
<$font>Pages: $db_next_hits"; } #sub site_html_search_results { # -------------------------------------------------------- # This routine displays the search results. # # my $term = &urlencode ($in{'query'}); # &html_print_headers; print &load_template ('search_results.html', { term => $term, q_string => $q_string, link_results => $link_results, category_results => $category_results, next => $next, cat_hits => $cat_hits, link_hits => $link_hits, %in, %globals }); #} } sub html_view_failure { #sub site_html_search_failure { # -------------------------------------------------------- # This routine displays a failed search page with error in $error. # my $error = shift; my $term = &urlencode ($in{'query'}); &html_print_headers; print &load_template ('search_error.html', { term => $term, error => $error, %in, %globals }); } sub parse_formn { # -------------------------------------------------------- # Parses the form input and returns a hash with all the name # value pairs. Removes SSI and any field with "---" as a value # (as this denotes an empty SELECT field. my (@pairs, %in); my ($buffer, $pair, $name, $value); if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { &cgierr ("This script must be called from the Web\nusing either GET or POST requests\n\n"); } PAIR: foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; # Remove SSI. if ($value eq "---") { next PAIR; } # This is used as a default choice for select lists and is ignored. (exists $in{$name}) ? ($in{$name} .= "~~$value") : # If we have multiple select, then we tack on ($in{$name} = $value); # using the ~~ as a seperator. } return %in; }