source: npl/mailserver/dspam/dspam-3.10.2/webui/cgi-bin/admingraph.cgi @ c5c522c

gcc484ntopperl-5.22
Last change on this file since c5c522c was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 5.6 KB
Line 
1#!/usr/bin/perl
2
3# $Id: admingraph.cgi,v 1.46 2011/06/28 00:13:48 sbajic Exp $
4# DSPAM
5# COPYRIGHT (C) 2002-2012 DSPAM PROJECT
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20use CGI ':standard';
21use GD::Graph::bars;
22use strict;
23use vars qw { %CONFIG %FORM %LANG $LANGUAGE @spam @nonspam @period @data @inoc @sm @fp @wh @corpus @virus @black @block };
24
25#
26# Read configuration parameters common to all CGI scripts
27#
28if (!(-e "configure.pl") || !(-r "configure.pl")) {
29  &htmlheader;
30  print "<html><head><title>Error!</title></head><body bgcolor='white' text='black'><center><h1>";
31  print "Missing file configure.pl";
32  print "</h1></center></body></html>\n";
33  exit;
34}
35require "configure.pl";
36
37#
38# Parse form
39#
40%FORM = &ReadParse();
41
42#
43# Configure languages
44#
45
46if ($FORM{'language'} ne "") {
47  $LANGUAGE = $FORM{'language'};
48} else {
49  $LANGUAGE = $CONFIG{'LANGUAGE_USED'};
50}
51if (! defined $CONFIG{'LANG'}->{$LANGUAGE}->{'NAME'}) {
52  $LANGUAGE = $CONFIG{'LANGUAGE_USED'};
53}
54
55GD::Graph::colour::read_rgb("rgb.txt");
56
57do {
58  my($spam, $nonspam, $sm, $fp, $inoc, $wh, $corpus, $virus, $black, $block, $period) = split(/\_/, $FORM{'data'});
59  @spam = split(/\,/, $spam);
60  @nonspam = split(/\,/, $nonspam);
61  @sm = split(/\,/, $sm);
62  @fp = split(/\,/, $fp);
63  @inoc = split(/\,/, $inoc);
64  @wh = split(/\,/, $wh);
65  @corpus = split(/\,/, $corpus);
66  @virus = split(/\,/, $virus);
67  @black = split(/\,/, $black);
68  @block = split(/\,/, $block);
69  @period = split(/\,/, $period);
70};
71
72@data = ([@period], [@inoc], [@corpus], [@virus], [@black], [@block], [@wh], [@spam], [@nonspam], [@sm], [@fp]);
73my $mygraph = GD::Graph::bars->new(500, 250);
74$mygraph->set(
75    x_label     => "$CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_x_label_'.$FORM{'x_label'}}",
76    y_label     => "$CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_nb_messages'}",
77    title       => "$FORM{'title'}",
78    legend_placement => 'RT',
79    legend_spacing => 2,
80    bar_width   => 4,
81    bar_spacing => 0,
82    long_ticks  => 1,
83    legend_marker_height => 4,
84    show_values => 0,
85    boxclr => 'gray90',
86    cumulate => 1,
87    x_labels_vertical => 1,
88    y_tick_number => 4,
89    fgclr => 'gray85',
90    boxclr => 'gray95',
91    textclr => 'black',
92    legendclr => 'black',
93    labelclr => 'gray60',
94    axislabelclr => 'gray40',
95    borderclrs => [ undef ],
96    dclrs => [ qw ( mediumblue orangered2 deeppink1 black darkturquoise purple red green yellow orange ) ]
97) or warn $mygraph->error;
98
99if ($CONFIG{'3D_GRAPHS'} == 1) {
100  $mygraph->set(
101      shadowclr => 'darkgray',
102      shadow_depth => 3,
103      bar_width   => 3,
104      bar_spacing => 2,
105      borderclrs => [ qw ( black ) ]
106  ) or warn $mygraph->error;
107}
108
109if (defined $CONFIG{'GRAPHS_X_LABEL_FONT'} && $CONFIG{'GRAPHS_X_LABEL_FONT'} ne "" && -r $CONFIG{'GRAPHS_X_LABEL_FONT'}) {
110  $mygraph->set_x_label_font([$CONFIG{'GRAPHS_X_LABEL_FONT'}, GD::gdMediumBoldFont, 'verdana', 'arial'], 8);
111} else {
112  $mygraph->set_x_label_font(GD::gdMediumBoldFont);
113}
114if (defined $CONFIG{'GRAPHS_Y_LABEL_FONT'} && $CONFIG{'GRAPHS_Y_LABEL_FONT'} ne "" && -r $CONFIG{'GRAPHS_Y_LABEL_FONT'}) {
115  $mygraph->set_y_label_font([$CONFIG{'GRAPHS_Y_LABEL_FONT'}, GD::gdMediumBoldFont, 'verdana', 'arial'], 8);
116} else {
117  $mygraph->set_y_label_font(GD::gdMediumBoldFont);
118}
119if (defined $CONFIG{'GRAPHS_LEGEND_FONT'} && $CONFIG{'GRAPHS_LEGEND_FONT'} ne "" && -r $CONFIG{'GRAPHS_LEGEND_FONT'}) {
120  $mygraph->set_legend_font([$CONFIG{'GRAPHS_LEGEND_FONT'}, GD::gdMediumBoldFont, 'verdana', 'arial'], 8);
121} else {
122  $mygraph->set_legend_font(GD::gdMediumBoldFont);
123}
124$mygraph->set_legend(" $CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_inoculations'}"," $CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_corpusfeds'}"," $CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_virus'}"," $CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_RBL'}"," $CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_blocklisted'}"," $CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_whitelisted'}"," $CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_spam'}"," $CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_nonspam'}"," $CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_spam_misses'}"," $CONFIG{'LANG'}->{$LANGUAGE}->{'graph_legend_falsepositives'}");
125my $myimage = $mygraph->plot(\@data) or die $mygraph->error;
126                                                                               
127print "Content-type: image/png\n\n";
128print $myimage->png;
129
130sub ReadParse {
131  my(@pairs, %FORM);
132  if ($ENV{'REQUEST_METHOD'} =~ /GET/i)
133    { @pairs = split(/&/, $ENV{'QUERY_STRING'}); }
134  else {
135    my($buffer);
136    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
137    @pairs = split(/\&/, $buffer);
138  }
139  foreach(@pairs) {
140    my($name, $value) = split(/\=/, $_);
141                                                                               
142    $name =~ tr/+/ /;
143    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
144    $value =~ tr/+/ /;
145    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
146    $value =~ s/<!--(.|\n)*-->//g;
147    $FORM{$name} = $value;
148  }
149  return %FORM;
150}
151
152sub htmlheader {
153  print "Expires: now\n";
154  print "Pragma: no-cache\n";
155  print "Cache-control: no-cache\n";
156  print "Content-type: text/html\n\n";
157}
Note: See TracBrowser for help on using the repository browser.