Gossamer Forum
Home : Products : Links 2.0 : Installation -- Unix :

Add.cgi submission giving me an invalid date format error

Quote Reply
Add.cgi submission giving me an invalid date format error
Hi guys,

I have a Links 2.0 installation that I moved over from another domain and everything is working now except for my add.cgi page. Whenever I try to add a site I get a "Date (Invalid date format)" error. I've checked the links.cfg file and it's already in the dd-mmm-yyyy. This installation has the templates and recip link mods already added if that makes a difference.

Here is the code from my files:

Links.cfg

# -------------
# Links
# -------------
# Links Manager
#
# File: links.cfg
# Description: Contains all the setup variables.
# 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.
# =====================================================================
# Paths and URL's to Important Stuff
# --------------------------------------------------------
# PATH and URL of Admin CGI directory. No Trailing Slash.
# $db_script_path = "/htdocs/sites/pornhats.com/cgi-bin/links/admin";
$db_script_path = "/home/nclark/pornhats.com/cgi-bin/links/admin";
$db_dir_url = "http://www.pornhats.com/cgi-bin/links/admin";
# Link to check for on other sites
$site_check = "www.pornhats.com";
#full path to report
$report_url = "http://www.pornhats.com/cgi-bin/links/admin/recip.html";
#full path to recip script place in the same dir as your admin.cgi
$report_cgi = "/home/nclark/pornhats.com/cgi-bin/links/admin/recip.cgi";

# URL of User CGI directory. No Trailing Slash.
$db_cgi_url = "http://www.pornhats.com/cgi-bin/links/admin";

# PATH and URL of Pages to be built. No Trailing Slash.
$build_root_path = "/home/nclark/pornhats.com/html/clothingresources";
$build_root_url = "http://www.pornhats.com/clothingresources";

# PATH and URL of What's New page. No Trailing slash.
$build_new_path = "$build_root_path/New";
$build_new_url = "$build_root_url/New";
# PATH and URL of What's Cool page. No Trailing slash.
$build_cool_path = "$build_root_path/Cool";
$build_cool_url = "$build_root_url/Cool";
# PATH and URL of What's Rating page. No Trailing slash.
$build_ratings_path = "$build_root_path/Ratings";
$build_ratings_url = "$build_root_url/Ratings";
# Database Options
# --------------------------------------------------------
# You really need to use flock(). However if your system doesn't support it (Win95),
# then turn this off at your own risk!
$db_use_flock = 1;
# Use Pragma: no-cache to stop browsers from caching output? (0 = cache, 1 = nocache)
$db_nocache = 0;
# Use IIS headers? Set this to 1 if your web server needs the full headers (HTTP/1.0 etc.)
$db_iis = 0;
# Field number of category in category.db
$db_main_category = 1;
# Referers -- which hosts are allowed to add to your database.
@db_referers = ();
# Email Options
# --------------------------------------------------------
# NOTE: Be sure to edit the text of the message. It can be found
# in the templates directory: email-add.txt, email-del.txt and
# email-mod.txt respectively.
# Set only ONE of either $db_mail_path which should go to a
# mail program like sendmail, or $db_smtp_server which will use
# a SMTP server. Do not set both at once!
# PATH of sendmail. # SMTP Server
$db_mail_path = '/usr/sbin/sendmail'; $db_smtp_server = '';

# Email address of the administrator. BE SURE TO SET!
$db_admin_email = 'webmaster@pornhats.com';
# Notify visitors automatically when their links are validated?
$db_email_add = 0;
# Notify visitors automatically when their links are modified?
$db_email_modify = 0;

# Log all outgoing messages? Put the full path to a logfile and make sure it
# exists and is writeable (chmod 666 -rw-rw-rw-). This logfile can get pretty
# big!
$db_mailer_log = '';
# Build Options
# --------------------------------------------------------
# Setting for popular cutoff, can either be a percent (i.e. top 3%), or
# a fixed value (i.e. top 10). Enter 0.03 or 10 respectively.
$db_popular_cutoff = 0.03; # Top 3%
# Number of days a link is considered New.
$db_new_cutoff = 14; # 14 days old.
# Return search results bolded (1 = yes, 0 = no).
$search_bold = 1;
# The name of an index file.
$build_index = "index.html";
# The extension to use for non index files:
$build_extension = ".html";

# Should your add.cgi automatically select what category the user
# is adding his link into?
$db_single_category = 1;
# Directory Permissions. Do NOT put quotes around it. Set to 0777
# for world writeable. If you put this at 0755, you might need a
# script to remove any directories created as they will be owned
# by the web server or user nobody. Better solution might be to
# run the nph-build routine from the command shell.
$build_dir_per = 0755;
# The script can now break up category pages that have more then x
# number of links in it. It will also create next and previous links
# to help navigate. Set this to 1 if you want to break up pages or 0 if
# you want to have only one page per category.
# Setting this to one, will also break up the What's New pages into
# per day sections (not affected by number of links per page).
$build_span_pages = 1;
# Number of links per page.
$build_links_per_page = 20;
# Detailed View: The script can build a single html page per link. This is
# great if you have a review in your database. To enable, you must set
# the directory where all the pages will be stored, the url to that directory
# and set the enable option.
$build_detailed = 0;
$build_detail_path = "$build_root_path/Detailed";
$build_detail_url = "$build_root_url/Detailed";
# Use Templates: instead of editing site_html.pl, you can edit regular html pages
# encoded with special <%links_tags%>. It's not as flexible as site_html.pl, but it
# may be easier.
$build_use_templates = 1;

# Site Title, the default title to use. You should really spend some time customizing
# the directory though!
$build_site_title = 'Hussy Clothing Network';
# Date Routines
# --------------------------------------------------------
# Your date format can be whatever you like, as long as the following
# two functions are defined &date_to_unix and &unix_to_date:
# The default is dd-mmm-yyyy.
sub date_to_unix {
# --------------------------------------------------------
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# timelocal does not like to be in array context, don't do my($time) = timelocal (..)
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my $date = shift; my $i;
my %months = map { $_ => $i++ } qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
my ($day, $mon, $year) = split(/-/, $date);

exists $months{$mon} or return undef;
$day = int($day); $year = $year - 1900;

require Time::Local;
my $time = 0;
eval {
$time = &Time::Local::timelocal(0,0,0, $day, $months{$mon}, $year);
};
if ($@) { die "invalid date format: $date - parsed as (day: $day, month: $months{$mon}, year: $year). Reason: $@"; }
return $time;
}
sub unix_to_date {
# --------------------------------------------------------
# This routine must take a unix time and return your date format
# A much simpler routine, just make sure your format isn't so complex that
# you can't get it back into unix time.
#
my $time = shift;
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $tz) = localtime $time;
my @months = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}
sub long_date {
# --------------------------------------------------------
# This routine is for printing a nicer date format on the what's new page. It should
# take in a date in your current format and return a new one.
my $time = shift;
$time = &date_to_unix ($time);
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $tz) = localtime $time;
my @months = qw!January February March April May June July August September October November December!;
my @days = qw!Sunday Monday Tuesday Wednesday Thursday Friday Saturday!;
$year = $year + 1900;
return "$days[$dweek], $months[$mon] $day $year";
}
# -------------------------------------------------------------
# Extra Paths -- unless you feel the need to rename files, you
# can leave this as is.
# -------------------------------------------------------------
$db_script_url = $db_dir_url . "/admin.cgi"; # Admin script.
$db_header_path = $db_script_path . "/header"; # Place to store header and footers.
$db_footer_path = $db_script_path . "/footer";
$build_search_url = $db_cgi_url . "/search.cgi"; # URL of search script.
$build_add_url = $db_cgi_url . "/add.cgi"; # URL of add script.
$build_modify_url = $db_cgi_url . "/modify.cgi"; # URL of modify script.
$build_jump_url = $db_cgi_url . "/jump.cgi"; # URL of jump script.
$build_email_url = $db_cgi_url . "/subscribe.cgi"; # URL of email update script.
$build_rate_url = $db_cgi_url . "/rate.cgi"; # URL of rate script.

$db_mail_url = $db_dir_url . "/nph-email.cgi"; # URL of admin mass mail script.
$build_css_url = $build_root_url . "/links.css"; # URL to your CSS file.

$db_lib_path = $db_script_path; # PATH of library files.
$db_links_name = "$db_script_path/data/links.db"; # PATH to links database.
$db_category_name = "$db_script_path/data/categories.db"; # PATH to category database.
$db_valid_name = "$db_script_path/data/validate.db"; # PATH to validation database.
$db_modified_name = "$db_script_path/data/modified.db"; # PATH to modification database.
$db_url_name = "$db_script_path/data/url.db"; # PATH to URL lookup database.
$db_email_name = "$db_script_path/data/email.db"; # PATH to email database.
$db_links_id_file_name = "$db_script_path/data/linksid.txt"; # PATH to links counter file.
$db_category_id_file_name = "$db_script_path/data/categoryid.txt"; # PATH to category counter file.
$db_hits_path = "$db_script_path/data/hits"; # PATH to hits directory.
$db_template_path = "$db_script_path/templates"; # PATH to templates.
$db_rates_path = "$db_script_path/data/rates"; # PATH to ratings.
$recip_report = "$db_script_path/recip.html"; # PATH to recip report.
1;


Add.cgi

#!/usr/bin/perl
# -------------
# Links
# -------------
# Links Manager
#
# File: add.cgi
# Description: Adds a record marked unvalidated to the database and
# optionally emails someone.
# 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.
# =====================================================================
#
# Setup Notes:
# Make sure the require statement below points to the config file.
# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \

require "links.cfg"; # Change this to full path to links.cfg if you have problems.
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[/url]";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}
# ========================================================
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 {
# --------------------------------------------------------
local (%in) = &parse_form;
# We are processing the form.
if (keys %in != 0) {
&process_form;
}
# Otherwise we are displaying the form (in site_html.pl).
else {
if ($db_single_category) {
my %is_valid = map { $_ => 1 } &category_list;
$ENV{'HTTP_REFERER'} =~ s,/[^/]+\.[^/]+$,,;
$ENV{'HTTP_REFERER'} =~ m,$build_root_url/(.+?)/?$,;
$is_valid{$1} ? &site_html_add_form ($1) : &site_html_add_form ();
}
else {
&site_html_add_form ();
}
}
}
sub process_form {
# --------------------------------------------------------
my ($key, $status, $line, $output);
# Check the referer.
if (@db_referers and $ENV{'HTTP_REFERER'}) {
$found = 0;
foreach (@db_referers) {
$ENV{'HTTP_REFERER'} =~ /$_/i and $found++ and last;
}
if (!$found) {
&site_html_add_failure ("Auto submission is not allowed in this directory. Please visit the site to add your entry.");
return;
}
}
# This will set system fields like Validated to their proper values.
foreach $key (keys %add_system_fields) {
$in{$key} = $add_system_fields{$key};
}

# Set date variable to today's date.
# $in{$db_cols[$db_modified]} = e"t_date;
$in{$db_cols[$db_modified]} = et_date;

open (ID, "<$db_links_id_file_name") or &cgierr("error in process_form. unable to open id file: $db_links_id_file_name. Reason: $!");
$in{$db_key} = <ID> + 1; # Get next ID number
close ID;
# Validate the form input..
$status = &validate_record(%in);
if ($status eq "ok") {
# Update the counter.
open (ID, ">$db_links_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_links_id_file_name. Reason: $!");
flock(ID, 2) unless (!$db_use_flock);
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
# Print out the validate input to a "validation database" where it is stored until
# the admin decides to add it into the real database.
open (VAL, ">>$db_valid_name") or &cgierr("error in add_record. unable to open validate file: $db_valid_name. Reason: $!");
flock(VAL, 2) unless (!$db_use_flock);
print VAL &join_encode(%in);
close VAL; # automatically removes file lock
# Send the admin an email message notifying of new addition.
&send_email;
# Send the visitor to the success page.
&site_html_add_success;
}
else {
&site_html_add_failure($status);
}
}
sub send_email {
# --------------------------------------------------------
# Sends an email to the admin, letting him know that there is
# a new link waiting to be validated. No error checking as we don't
# want users to see the informative &cgierr output.
# Check to make sure that there is an admin email address defined.
$db_admin_email or &cgierr("Admin Email Address Not Defined in config file!");
my $to = $db_admin_email;
my $from = $in{$db_cols[$db_contact_email]};
my $subject = "Addition to Database: $in{'Title'}\n";
my $msg = qq|
The following link is awaiting validation:
Title: $in{'Title'}
URL: $in{'URL'}\
Recip URL: $in{'recip'}
Category: $in{'Category'}
Description: $in{'Description'}
Contact Name: $in{'Contact Name'}
Contact Email: $in{'Contact Email'}

Remote Host: $ENV{'REMOTE_HOST'}
Referer: $ENV{'HTTP_REFERER'}

To validate, please go to:
$db_script_url

Sincerely,
Links Manager.
|;
# Then mail it away!
require "$db_lib_path/Mailer.pm";
my $mailer = new Mailer ( { smtp => $db_smtp_server,
sendmail => $db_mail_path,
from => $from,
subject => $subject,
to => $to,
msg => $msg,
log => $db_mailer_log
} ) or return;
$mailer->send or return;
}


Recip.cgi

#!/usr/bin/perl
## Program Name: recip.cgi
require "/htdocs/sites/pornhats.com/cgi-bin/links/admin/links.cfg";
require "/htdocs/sites/pornhats.com/cgi-bin/links/admin/db_utils.pl";
$perpage=0;
if ($ENV{'QUERY_STRING'}){
$perpage=$ENV{'QUERY_STRING'};}
open (REPORT, ">$recip_report");
$date = e"t_date;
$time = e"t_time;
$long_date = &long_date ($date);
$finalnum=$perpage+5;
#print "<html><title>Checking Links - ID #'s ($perpage-$finalpage)</title>";
print "Content-type: text/html\n\n";
print "<meta http-equiv=\"Refresh\" content=\"0; URL=",$report_url,"\">";
print REPORT "<html><head><title>Links Checked - ($long_date)</title></head>";
print REPORT "<body bgcolor=\"#c0c0c0\" text=\"#000000\">";
print REPORT "<form action=$db_script_url METHOD=POST><input type=hidden name=db value=links>";
print REPORT "<center><table border=\"0\" callpadding=\"0\" cellspacing=\"0\"><tr><td bgcolor=\"navy\" colspan=\"4\">";
print REPORT "<center><h2><font color=\"\#ffffff\">Reciprical Link Report</font></h2></center><p>";
print REPORT "<center><h4><font color=\"\#ffffff\">",$long_date, " - ", $time,"</font></h4></center><p>";
print REPORT "</td></tr>";
&main;
sub main {
open (LINK, "$db_links_name") or print("unable to open url index $db_links_name. Reason: $!");
seek (LINK, 0, 0); # rewind to beginning.
# Go through the Links database and find the link we want to go to.
LINE: while (<LINK> ) {
next LINE if (/^#/); # Skip comment lines.
next LINE if (/^\s*$/); # Skip blank lines.
@links=split (/\|/);
#if (($links[0] < $perpage+5) and ($links[0] >= $perpage)) {
e"tcontent("$links[14]");
#}
#elsif ($links[0] > $perpage+5) {
#$perpage=$perpage+5;
#print "<a href=>Next 5</a>";
#exit;
#}
} #end of while
close (LINK);
}
sub getcontent{
use LWP::Simple;
$counter=0;
local ($url) = @_;
$page = get($url);
if ($page) {
if ($page =~ /$site_check/i){
}
else {
if ($links[14] =~ "http.*") {
$body = "Hello $links[6], I am the webmaster of http://$site_check. I was verifying the reciprical links and was unable to find a link on your site ($links[2]). You submitted $links[14] as the reciprical link location. I am unable to find it there. I don't want to remove your link by mistake please let me know where it is currently located. You are listed in the $links[4] Category of http://$site_check. I hope to continue sending traffic to your website. --Thanks-- Webmaster...http://$site_check";
print REPORT "<tr><td bgcolor=\"#ffffff\">";
print REPORT "ID $links[0] <input TYPE=CHECKBOX NAME=$links[0] VALUE=\"delete\">";
print REPORT "</td><td bgcolor=\"#ffffff\">";
print REPORT "<a href=\"$url\" target=\"_new\">$url</a></td><td bgcolor=\"#ffffff\"> - is not linking back ";
print REPORT "</td><td bgcolor=\"#ffffff\">";
print REPORT "<a href=\"mailto\:$links[7]?subject=Unable to verify reciprical link&body=$body\">$links[7]</a><br>";
print REPORT "</td></tr>";
#&send_email;
}
}
}
else {
if ($links[14] =~ "http.*") {
$body2 = "Hello $links[6], I am the webmaster of http://$site_check. I was verifying the reciprical links and was unable to connect to your site ($links[2]) to verify the link. I don't know if your site was temporarily down or you moved to a new location. You submitted $links[14] as the reciprical link location. I don't want to remove your link by mistake please let me know if your site is still up and the current location of my reciprical link. You are listed in the $links[4] Category of http://$site_check. I hope to continue sending traffic to your website. --Thanks-- Webmaster...http://$site_check";
print REPORT "<tr><td bgcolor=\"#ffffff\">";
print REPORT "ID $links[0] <input TYPE=CHECKBOX NAME=$links[0] VALUE=\"delete\">";
print REPORT "</td><td bgcolor=\"#ffffff\">";
print REPORT "<a href=\"$url\" target=\"_new\">$url</a></td><td bgcolor=\"#ffffff\"> - <font color=\"\#ff0000\">Could not connect!</font> ";
print REPORT "</td><td bgcolor=\"#ffffff\">";
print REPORT "<a href=\"mailto\:$links[7]?subject=Unable to verify reciprical link&body=$body2\">$links[7]</a><br>";
print REPORT "</td></tr>";
}
}
}
print REPORT "</table>";
&del_button;
print REPORT "</body></html>";
close (REPORT);
print "Done. <a href=\"$report_url\">Click Here to View Report.</a>";
sub del_button{
print REPORT "<INPUT TYPE=SUBMIT name=delete_records VALUE=Delete Checked Link(s)> <INPUT TYPE=RESET VALUE=Reset>\n";
}
sub send_email {
# --------------------------------------------------------
# Sends an email to the admin, letting him know that there is
# a new link waiting to be validated. No error checking as we don't
# want users to see the informative &cgierr output.
# Check to make sure that there is an admin email address defined.
$db_admin_email or &cgierr("Admin Email Address Not Defined in config file!");
my $to = $links[7];
my $from = $db_admin_email;
my $subject = "Unable to find Reciprical Link\n";
my $msg = qq|Hello $links[6],
I am the webmaster of http://$site_check.
I was verifying the reciprical links for my site and was
unable to find a link on your site ($links[2]).
You submitted $links[14]
as the location of where I could find my return link.
I have searched this page and am unable to find it.
I don't want to remove your link by mistake so please let
me know where the return link for my site is currently located.
As you know you are listed on my site in the $links[4] Category.
I hope to continue sending traffic to your website.
Best Regards,
-Webmaster http://$site_check

|;
# Then mail it away!
require "$db_lib_path/Mailer.pm";
my $mailer = new Mailer ( { smtp => $db_smtp_server,
sendmail => $db_mail_path,
from => $from,
subject => $subject,
to => $to,
msg => $msg,
log => $db_mailer_log
} ) or return;
$mailer->send or return;
}



Thanks for any help - I've tried what little I could think of.
Gieckboy



Webmaster
Hussy Clothing Company
Trucker Hats | Vintage Clothing
Quote Reply
Re: [Gieckboy] Add.cgi submission giving me an invalid date format error In reply to
Any takers guys? I could really use some guidance on this as I've already tried everything I can think of.

Thanks!
Webmaster
Hussy Clothing Company
Trucker Hats | Vintage Clothing
Quote Reply
Re: [Gieckboy] Add.cgi submission giving me an invalid date format error In reply to
I have to use dd-mm-yyyy to make mine work..if this helps, I do occasionaly have the problem as I import in from excel and sometimes forget to fill the date field