-
Notifications
You must be signed in to change notification settings - Fork 0
/
clearbucket.pl
executable file
·95 lines (74 loc) · 2.83 KB
/
clearbucket.pl
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
#!/usr/bin/perl
# ----------------------------------------------------------------------------
#
# clearbucket.pl --- Clears the data of a bucket
#
# Copyright (c) 2001-2011 John Graham-Cumming
#
# This file is part of POPFile
#
# POPFile is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# POPFile 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 POPFile; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------------
use strict;
use local::lib;
use lib defined($ENV{POPFILE_ROOT})?$ENV{POPFILE_ROOT}:'./';
use POPFile::Loader;
my $code = 0;
if ( $#ARGV == 0 ) {
# POPFile is actually loaded by the POPFile::Loader object which does all
# the work
my $POPFile = POPFile::Loader->new();
# Indicate that we should create not output on STDOUT (the POPFile
# load sequence)
$POPFile->debug(0);
$POPFile->CORE_loader_init();
$POPFile->CORE_signals();
$POPFile->CORE_load( 1 );
$POPFile->CORE_link_components();
$POPFile->CORE_initialize();
my $bucket = shift @ARGV;
@ARGV = ();
if ( $POPFile->CORE_config() ) {
# Prevent the tool from finding another copy of POPFile running
my $c = $POPFile->get_module( 'POPFile::Config' );
my $current_piddir = $c->config_( 'piddir' );
$c->config_( 'piddir', $c->config_( 'piddir' ) . 'insert.pl.' );
$POPFile->CORE_start();
my $b = $POPFile->get_module( 'Classifier::Bayes' );
my $session = $b->get_session_key( 'admin', '' );
if ( !$b->is_bucket( $session, $bucket ) ) {
print STDERR "Error: Bucket `$bucket' does not exist.\n";
$code = 1;
} else {
if ( !$b->clear_bucket( $session, $bucket ) ) {
print STDERR "Error: Bucket `$bucket' was not cleared.\n";
$code = 1;
} else {
print "Bucket `$bucket' was cleared.\n";
}
}
$c->config_( 'piddir', $current_piddir );
# Reload configuration file ( to avoid updating configurations )
$c->load_configuration();
$b->release_session_key( $session );
$POPFile->CORE_stop();
}
} else {
print "clearbucket.pl - clears the date of a bucket\n\n";
print "Usage: clearbucket.pl <bucket> <messages>\n";
print " <bucket> The name of the bucket\n";
$code = 1;
}
exit $code;