122 lines
3.4 KiB
Perl
Executable File
122 lines
3.4 KiB
Perl
Executable File
#! /usr/bin/perl -w
|
|
# Woman's Voice
|
|
# 1-subs_counter.cgi: The subscriber counter.
|
|
|
|
# Copyright (c) 2003-2021 imacat.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
# Author: imacat <imacat@mail.imacat.idv.tw>
|
|
# First written: 2003-05-17
|
|
|
|
use 5.008;
|
|
use strict;
|
|
use warnings;
|
|
use lib $ENV{"DOCUMENT_ROOT"} . qw(/magicat/lib/perl5);
|
|
use Selima::wov;
|
|
local $SIG{"__DIE__"} = \&http_500;
|
|
my $d = new Selima::Destroy;
|
|
# Prototype declaration
|
|
sub main();
|
|
sub get_counter();
|
|
sub html_image($);
|
|
|
|
use Fcntl qw(:flock :seek);
|
|
use GD;
|
|
use IO::NestedCapture qw(CAPTURE_STDOUT);
|
|
|
|
use constant DATA_FILE => "/var/lib/mailman/lists/wov/config.pck";
|
|
use constant COUNTER_PROG => "/usr/libexec/total_members";
|
|
use constant LISTNAME => "wov";
|
|
use vars qw(@FGCOLOR @BGCOLOR $FONT);
|
|
@FGCOLOR = (0, 0, 0); # #000000 Black
|
|
@BGCOLOR = (255, 255, 255); # #FFFFFF White
|
|
$FONT = gdLargeFont;
|
|
use constant TRANSPARENT => 1;
|
|
initenv( -allowed => [qw(GET HEAD)],
|
|
-session => 0,
|
|
-dbi => DBI_NONE,
|
|
-lastmod => 1,
|
|
-lmfiles => [DATA_FILE],
|
|
-multilang => 0);
|
|
|
|
use vars qw($COUNTER $MTIME);
|
|
|
|
main;
|
|
exit 0;
|
|
|
|
sub main() {
|
|
local ($_, %_);
|
|
|
|
get_counter();
|
|
html_image($COUNTER);
|
|
|
|
return;
|
|
}
|
|
|
|
# get_counter: Get the subscriber counter
|
|
sub get_counter() {
|
|
local ($_, %_);
|
|
my $OUT;
|
|
|
|
# Obtain the mtime of the subscriber database file
|
|
$_ = (stat DATA_FILE)[9];
|
|
# We should update the counter
|
|
if (!defined $MTIME || $MTIME != $_) {
|
|
# Update the timestamp
|
|
$MTIME = $_;
|
|
@_ = (COUNTER_PROG, LISTNAME);
|
|
open $OUT, "-|", @_ or http_500 COUNTER_PROG . ": $!";
|
|
defined($COUNTER = <$OUT>) or http_500 COUNTER_PROG . ": $!";
|
|
close $OUT or http_500 COUNTER_PROG . ": $!";
|
|
chomp $COUNTER;
|
|
}
|
|
|
|
return $COUNTER;
|
|
}
|
|
|
|
# html_image: Make the image from the counter value
|
|
sub html_image($) {
|
|
local $_;
|
|
my ($counter, $image, $width, $height, $fgcolor, $bgcolor);
|
|
$counter = $_[0];
|
|
|
|
# Group the counter with commas at thousand digits.
|
|
$counter = fmtno($counter);
|
|
|
|
# Initialize the image object
|
|
# Get the width and height
|
|
$width = $FONT->width * (length $counter);
|
|
$height = $FONT->height;
|
|
# Create an image object
|
|
$image = GD::Image->new($width, $height);
|
|
# Create the forground/background color objects
|
|
$fgcolor = $image->colorAllocate(@FGCOLOR);
|
|
$bgcolor = $image->colorAllocate(@BGCOLOR);
|
|
|
|
# Draw the image
|
|
# Set the transparent background
|
|
$image->transparent($bgcolor) if TRANSPARENT;
|
|
# Paint the background
|
|
$image->filledRectangle(0, 0, $width, $height, $bgcolor);
|
|
# Write the text
|
|
$image->string($FONT, 0, 0, $counter, $fgcolor);
|
|
|
|
# Output
|
|
$CONTENT_TYPE = "image/png";
|
|
binmode IO::NestedCapture->instance->{"STDOUT_current"}[-1], ":raw";
|
|
print $image->png;
|
|
|
|
return;
|
|
}
|