-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendpage-db
109 lines (95 loc) · 2.37 KB
/
sendpage-db
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
#!/usr/bin/perl
#
# dbi is the tool that will assist in loading data into a database
#
# $Id$
#
# Copyright (C) 2004 Todd T. Fries
# [email protected], http://FreeDaemonConsulting.com/
#
# 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.
# http://www.gnu.org/copyleft/gpl.html
use Getopt::Std;
use Sendpage::Db;
getopts('hpadvtc:U:P:');
if ($opt_c) {
$dbtype = $opt_c;
} else {
$dbtype = "dbi:mysql:database=test;host=localhost;port=3306";
}
if ($opt_U) {
$dbuser = $opt_U;
}
if ($opt_P) {
$dbpass = $opt_P;
}
my $db = Sendpage::Db->new($dbtype,$dbuser,$dbpass);
sub HELP_MESSAGE {
printf STDERR "Usage: \n";
printf STDERR "-v verbose\n";
printf STDERR "-p show table entries\n";
printf STDERR "-a add an entry\n";
printf STDERR "-d remove an entry\n";
printf STDERR "-c <dbtype> database connection type, e.g. dbi:mysql:\n";
printf STDERR "-U <dbuser> database user (optional)\n";
printf STDERR "-P <dbpass> database password (optional)\n";
exit(0);
}
if ($opt_h) {
HELP_MESSAGE;
exit(0);
}
if ($opt_v) {
# verbose
$debug = 1;
} else {
$debug = 0;
}
if ($opt_p) {
$db->show;
exit(0);
}
if ($opt_a) {
while(<stdin>) {
($recip,$var,$value) = split(/ /,$_);
chomp($value);
if ($var eq "email-cc" or $var eq "dest") {
if($debug) {
print "adding $recip with $var = $value\n";
}
$db->update("$recip:$var",$value);
} else {
print "invalid synatx, parsed: ";
print "recip = $recip, var = $var, val = $value\n";
}
}
if($debug) {
$db->show;
}
exit(0);
}
if ($opt_d) {
while(<stdin>) {
chomp($recip = $_);
if($debug) {
print "deleting $recip info\n";
}
$db->delete("$recip:dest");
$db->delete("$recip:email-cc");
}
exit(0);
}
HELP_MESSAGE;
0;