Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 252 lines (200 sloc) 7.259 kB
#!/usr/bin/perl -w
###############################################################################
# dailyStuff - this program runs various housekeeping tasks, sends out the
# the mailing list, and compiles site statistics report and sends the report
# to the site admin
#
# Copyright (C) 1997 Rob "CmdrTaco" Malda
# malda@slashdot.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# $Id$
###############################################################################
use strict;
use vars '%I';
use File::Basename;
use File::Path;
use Slash;
*I = getSlashConf();
my($total) = sqlSelect("count(*)", "accesslog",
"to_days(now()) - to_days(ts)=1");
my $c = sqlSelectMany("count(*)","accesslog",
"to_days(now()) - to_days(ts)=1 GROUP BY host_addr");
my($unique) = $c->rows;
$c->finish;
my($comments) = sqlSelect("count(*)","accesslog",
"to_days(now()) - to_days(ts)=1 AND op='comments'");
$c = sqlSelectMany("dat,count(*)","accesslog",
"to_days(now()) - to_days(ts)=1 AND
(op='index' OR dat='index')
GROUP BY dat");
my(%indexes, %articles, %commentviews);
while(my($sect, $cnt) = $c->fetchrow) {
$indexes{$sect} = $cnt;
}
$c->finish;
$c = sqlSelectMany("dat,count(*),op","accesslog",
"to_days(now()) - to_days(ts)=1 AND op='article'",
"GROUP BY dat");
while(my($sid, $cnt) = $c->fetchrow) {
$articles{$sid} = $cnt;
}
$c->finish;
# clean the key table
my $delete_time = time() - $I{formkey_timeframe};
$I{dbh}->do("DELETE FROM formkeys WHERE ts < $delete_time");
sub updateStamps {
my $columns = "uid";
my $tables = "accesslog";
my $where = "to_days(now())-to_days(ts)=1 AND uid > 0";
my $other = "GROUP BY uid";
my $E = sqlSelectAll($columns, $tables, $where, $other);
$I{dbh}->do("LOCK TABLES users_info WRITE");
for (@{$E}) {
my $uid=$_->[0];
# print "Update $uid\n";
sqlUpdate("users_info",{-lastaccess=>'now()'},"uid=$uid");
}
$I{dbh}->do("UNLOCK TABLES");
}
updateStamps();
$c = sqlSelectMany("dat,count(*)","accesslog",
"to_days(now()) - to_days(ts)=1 AND op='comments'",
"GROUP BY dat");
while(my($sid, $cnt) = $c->fetchrow) {
$commentviews{$sid} = $cnt;
}
$c->finish;
$I{dbh}->do("delete from accesslog where date_add(ts,interval 48 hour) < now()");
my($sdTotalHits) = getvars("totalhits");
$sdTotalHits = $sdTotalHits + $total;
setvar("totalhits", $sdTotalHits);
my $email = <<EOT;
$I{sitename} Stats for yesterday
total $total
unique $unique
total hits $sdTotalHits
homepage $indexes{'index'}
indexes
EOT
foreach (keys %indexes) {
$email .= "\t $_=$indexes{$_}\n"
}
$email .= "\n-----------------------\n";
foreach my $key (sort { $articles{$b} <=> $articles{$a} } keys %articles) {
my $value = $articles{$key};
my($title, $author) = sqlSelect("title,aid", "stories",
"sid=" . $I{dbh}->quote($key));
$email .= "$value\t$key " . substr($title, 0, 30) .
" by $author\n" if $value > 100;
}
$email .= "\n-----------------------\n";
$email .= `$I{datadir}/bin/tailslash today`;
$email .= "\n-----------------------\n";
$I{dbh}->do("DELETE from pollvoters");
$I{dbh}->do("DELETE from moderatorlog WHERE
to_days(now()) - to_days(ts) > $I{archive_delay} ");
$I{dbh}->do("DELETE from metamodlog WHERE
to_days(now()) - to_days(ts) > $I{archive_delay} ");
my($comlim) = sqlSelect("commentlimit", "users_comments", "uid=-1");
sqlUpdate("users_comments", { commentlimit => 50000 }, "uid=-1");
$email .= "Archiving Comments...\n";
# Find all stories over $I{archive_delay} days where writestatus != 5
my $columns = "sid,time,section,title";
my $tables = "stories";
my $where = "writestatus<5 AND writestatus >= 0 AND to_days(now()) - to_days(time) > $I{archive_delay}";
my $E = sqlSelectAll($columns, $tables, $where); #, $other);
for (@{$E}) {
my($sid, $date, $section, $title) = ($_->[0], $_->[1], $_->[2], $_->[3]);
$email.= "archiving: $sid $title \n";
prog2file("$I{basedir}/article.pl sid=$sid\\\&ssi=yes\\\&mode=archive",
"$I{basedir}/$section/$sid"."_F.shtml");
unlink("$I{basedir}/$section/$sid.shtml")
or warn "Can't unlink $I{basedir}/$section/$sid.shtml: $!";
symlink("$I{basedir}/$section/${sid}_F.shtml", "$I{basedir}/$section/$sid.shtml")
or die "Can't symlink $I{basedir}/$section/${sid}_F.shtml -> $sid.shtml";
$I{dbh}->do("DELETE FROM comments WHERE sid='$sid'");
$I{dbh}->do("UPDATE stories SET writestatus=10 WHERE sid='$sid'");
}
sqlUpdate("users_comments",{ commentlimit=>$comlim },"uid=-1");
my $delay1 = $I{archive_delay} * 2;
my $delay2 = $I{archive_delay} * 9;
$I{defaultsection} ||= 'articles';
$I{dbh}->do("delete from newstories WHERE
(section='$I{defaultsection}' and to_days(now()) - to_days(time) > $delay1)
or (to_days(now()) - to_days(time) > $delay2)");
$I{dbh}->do("delete from comments where to_days(now()) - to_days(date) > $I{archive_delay}");
sub generateDailyMail {
my $columns = "sid,title,section,aid,tid,date_format(time,\"\%W \%M \%d, \@h:\%i\%p\"),dept";
my $tables = "stories";
my $where = "to_days(now()) - to_days(time) = 1 AND displaystatus=0 AND time < now()";
my $other = " ORDER BY time DESC";
my $E = sqlSelectAll($columns,$tables,$where,$other);
my $r = "$I{sitename} Daily Headline Mailer\n\n";
$r .= getblock("emailsponsor");
# newlines after advert
$r .= "\n\n";
return unless @$E;
for (@{$E}) {
my($sid, $title, $section, $aid, $tid, $time, $dept) = @$_;
$dept = $I{use_dept} ? "\n from the $dept dept." : "";
$r .= <<EOT;
$title$dept
posted by $aid on $time ($tid)
$I{rootdir}/article.pl?sid=$sid
EOT
}
return $r;
}
sub mailingList {
my $p = generateDailyMail() or return;
my $columns ="realemail,mode,nickname";
my $tables = "users,users_comments,users_info";
my $where = "users.uid=users_comments.uid AND users.uid=users_info.uid AND maillist=1";
my $other = "order by realemail";
my $E = sqlSelectAll($columns,$tables,$where,$other);
for (@{$E}) {
sendEmail($_->[0], "24 Hours of $I{sitename} Headlines For $_->[2]", <<EOT);
$p
You are getting this message because you subscribed to it.
If you want to unsubscribe from this, go to $I{rootdir}/users.pl
You can login as $_->[2] and disable the mailing from there.
EOT
}
}
sub prog2file {
my($c, $f) = @_;
my $d = `$c`;
my $dir = dirname($f);
mkpath($dir, 0, 0755) unless -e $dir;
if (length($d) > 0) {
local *F;
open F, ">$f" or die "Can't open $f: $!";
print F $d;
close F;
return "1";
} else {
return "0";
}
}
# Send a message to the shite admin.
if ($I{send_mail} == 1) {
for (keys %{$I{stats_reports}}) {
sendEmail($_, $I{stats_reports}{$_}, $email);
}
mailingList();
}
Jump to Line
Something went wrong with that request. Please try again.