/usr/sbin/cbpadmin is in postfix-cluebringer 2.0.10-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | #!/usr/bin/perl
# Cluebringer administration tool
# Copyright (C) 2009, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# 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.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
use lib('/usr/local/lib/postfix-cluebringer','/usr/lib/postfix-cluebringer');
use Config::IniFiles;
use Getopt::Long;
use cbp::logging;
use cbp::version;
print("Policyd Admin Tool (ClueBringer) v".VERSION." - Copyright (c) 2007-2009 AllWorldIT\n");
# Fire up commandline processing...
my %opts;
GetOptions(
\%opts,
"help",
"config:s",
"cleanup",
"debug",
);
# Check for some args
if ($opts{'help'}) {
displayHelp();
exit 0;
}
# Set defaults
my $cfg;
$cfg->{'config_file'} = "/etc/cluebringer.conf";
# Check if we must override
if (defined($opts{'config'}) && $opts{'config'} ne "") {
$cfg->{'config_file'} = $opts{'config'};
}
# Check config file exists
if (! -f $cfg->{'config_file'}) {
print(STDERR "ERROR: No configuration file '".$cfg->{'config_file'}."' found!\n");
displayHelp();
exit 1;
}
# Use config file, ignore case
tie my %inifile, 'Config::IniFiles', (
-file => $cfg->{'config_file'},
-nocase => 1
) or die "Failed to open config file '".$cfg->{'config_file'}."': $!";
# Copy config
my %config = %inifile;
# FIXME: This now generates a warning as Config::Inifiles doesn't implement UNTIE
#untie(%inifile);
# Our fake server...
my $server;
#
# Check what to do
#
# We must cleanup
if ($opts{'cleanup'}) {
loadModules();
# Loop with modules
foreach my $module ( sort { $b->{'priority'} <=> $a->{'priority'} } @{$server->{'modules'}} ) {
$server->log(LOG_INFO,"Module: " . $module->{'name'});
# If we have a cleanup module, run it
if (defined($module->{'cleanup'})) {
$server->log(LOG_INFO," -> running cleanup...");
$module->{'cleanup'}($server);
}
}
# Huh, nothing todo...
} else {
print(STDERR "ERROR: Nothing to do!\n");
displayHelp();
exit 1;
}
#
# Misc functions
#
# Register plugin info
sub plugin_register {
my ($self,$module,$info) = @_;
# If no info, return
if (!defined($info)) {
$server->log(LOG_ERR,"Plugin info not found for module => $module");
return -1;
}
# Set real module name & save
$info->{'Module'} = $module;
push(@{$self->{'modules'}},$info);
# If we should, init the module
if (defined($info->{'init'})) {
$info->{'init'}($self);
}
return 0;
}
# Function to load our modules
sub loadModules
{
# Pull in module list
my $modules = $config{'server'}{'modules'};
my @modulelist;
if (ref($config{'server'}{'modules'}) eq "ARRAY") {
foreach my $module (@{$modules}) {
$module =~ s/\s+//g;
# Skip comments
next if ($module =~ /^#/);
$module = "modules/$module";
push(@modulelist,$module);
}
} else {
my @splitModules = split(/\s+/,$config{'server'}{'modules'});
foreach my $module (@splitModules) {
# Skip comments
next if ($module =~ /^#/);
$module = "modules/$module";
push(@modulelist,$module);
}
}
# Emulate server
$server = new cbpserver;
$server->{'inifile'} = \%config;
# Init everything
$server->init();
# Load modules
foreach my $module (@modulelist) {
# Split off dir and mod name
$module =~ /^(\w+)\/(\w+)$/;
my ($mod_dir,$mod_name) = ($1,$2);
# Load module
my $res = eval("
use cbp::${mod_dir}::${mod_name};
plugin_register(\$server,\"${mod_name}\",\$cbp::${mod_dir}::${mod_name}::pluginInfo);
");
if ($@ || (defined($res) && $res != 0)) {
$server->log(LOG_ERR,"WARNING: Error loading plugin $module ($@)");
}
}
}
# Display help
sub displayHelp {
print(<<EOF);
Usage: $0 [args]
--config=<file> Configuration file
--debug Put into debug mode
--cleanup Cleanup database records
EOF
}
# Server emulation
package cbpserver;
use strict;
use warnings;
use cbp::logging;
use cbp::config;
use cbp::dbilayer;
use cbp::dblayer;
# Return oursevles
sub new
{
my $class = shift;
my $self = {
};
bless $self, $class;
return $self;
};
sub init
{
my $self = shift;
# Init config
cbp::config::Init($self);
# Init system stuff
$self->{'client'}->{'dbh'} = cbp::dbilayer::Init($self);
if (!defined($self->{'client'}->{'dbh'})) {
$self->log(LOG_WARN,"Failed to Initialize: ".cbp::dbilayer::internalErr()." ($$)");
die;
}
if ($self->{'client'}->{'dbh'}->connect()) {
$self->log(LOG_WARN,"Failed to connect to database: ".$self->{'client'}->{'dbh'}->Error()." ($$)");
die;
}
# Setup database handle
cbp::dblayer::setHandle($self->{'client'}->{'dbh'});
}
sub log
{
my ($self,$level,@msg) = @_;
# FIXME: we shouldn't ignore $level
print(@msg, "\n");
}
# Load modules we need and run cleanup() function
# Cleanup session_tracking older than 24hr
# Cleanup quotas_tracking
# - check last update, if its older than now - period, remove
# CheckHelo
# - Remove checkhelo_tracking older than specified period, default to 1 month
# vim: ts=4
|