Приглашаем посетить
WebAdverts (Display All)
#!/usr/bin/perl
############################################
## ##
## WebAdverts (Display All) ##
## by Darryl Burgdorf ##
## (e-mail burgdorf@awsd.com) ##
## ##
## last modified: 5/27/97 ##
## copyright (c) 1997 ##
## ##
## latest version is available from ##
## http://awsd.com/scripts/ ##
## ##
############################################
require "/usr/www/users/dburgdor/scripts/ads/ads_configure.pl";
&ConfigureAdverts;
$UseLocking = 1;
print "Content-type: text/html\n\n";
open (COUNT, "<$advertcount");
$lockerror = &LockFile(COUNT);
if ($lockerror) {
print "[ File Lock Error ($advertcount)! ]";
exit;
}
@lines = <COUNT>;
if (@lines < 4) {
&UnlockFile(COUNT);
close (COUNT);
exit;
}
foreach $line (@lines) { chop ($line) if ($line =~ /\n$/); }
&UnlockFile(COUNT);
close (COUNT);
$lines = @lines-1;
foreach $key (3..$lines) {
$displayad = @lines[$key];
open (DISPLAY, "+<$adverts_dir/$displayad.txt");
$lockerror = &LockFile(DISPLAY);
if ($lockerror) {
print "[ File Lock Error ($displayad.txt)! ]";
exit;
}
@adlines = <DISPLAY>;
foreach $adline (@adlines) {
chop ($adline) if ($adline =~ /\n$/);
}
$text = "Please Visit Our Sponsor!";
($max,$shown,$visits,$url,$image,$height,$width,$alt,$pass,$text,$start,$weight) = @adlines;
unless ((($AdvertTracking < 2) && ($shown < $max)) ||
(($AdvertTracking == 2) && ($visits < $max))) {
&UnlockFile(DISPLAY);
close (DISPLAY);
next;
}
print "<P ALIGN=CENTER><A HREF=\"$gotoadvert?$displayad\">";
print "<IMG SRC=\"$image\" HEIGHT=$height WIDTH=$width ALT=\"$alt\">";
print "</A><BR><SMALL><A HREF=\"$gotoadvert?$displayad\">";
print "$text</A></SMALL></P>\n";
$shown += 1;
truncate (DISPLAY,0);
seek(DISPLAY, 0, 0);
print DISPLAY "$max\n";
print DISPLAY "$shown\n";
print DISPLAY "$visits\n";
print DISPLAY "$url\n";
print DISPLAY "$image\n";
print DISPLAY "$height\n";
print DISPLAY "$width\n";
print DISPLAY "$alt\n";
print DISPLAY "$pass\n";
print DISPLAY "$text\n";
print DISPLAY "$start\n";
print DISPLAY "$weight\n";
&UnlockFile(DISPLAY);
close (DISPLAY);
next;
}
exit;
sub LockFile {
local(*FILE) = @_;
local($TrysLeft) = 10;
if ($UseLocking) {
while ($TrysLeft--) {
$lockresult = eval("flock(FILE,6)");
if ($@) {
$UseLocking = 0;
last;
}
if (!$lockresult) {
select(undef,undef,undef,0.1);
}
else {
last;
}
}
}
if ($TrysLeft >= 0) {
return 0;
}
else {
return -1;
}
}
sub UnlockFile {
local(*FILE) = @_;
if ($UseLocking) {
flock(FILE,8);
}
}