diff options
Diffstat (limited to 'scripts/rosteredit.pl')
-rwxr-xr-x | scripts/rosteredit.pl | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/rosteredit.pl b/scripts/rosteredit.pl new file mode 100755 index 0000000..4c7132d --- /dev/null +++ b/scripts/rosteredit.pl | |||
@@ -0,0 +1,62 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use strict; | ||
4 | |||
5 | use DBI; | ||
6 | |||
7 | if ($#ARGV < 0) { | ||
8 | die ("must specify database then action (list, add, del, preview)\n"); | ||
9 | } | ||
10 | my $db = shift @ARGV; | ||
11 | my $dbh = DBI->connect_cached("dbi:SQLite:dbname=$db","","", { RaiseError => 1, PrintError => 0, AutoCommit => 1 }); | ||
12 | |||
13 | my $action; | ||
14 | my $param; | ||
15 | |||
16 | if ($#ARGV < 0) { | ||
17 | die ("must specify action (list, add, del, preview)\n"); | ||
18 | } else { | ||
19 | $action = shift @ARGV; | ||
20 | for ($action) { | ||
21 | if (/^preview$/) { | ||
22 | if ($#ARGV < 0) { | ||
23 | die ("Must specify jabber id"); | ||
24 | } | ||
25 | my $sql = "SELECT [Group], ContactID, Contact, Subscription FROM RosterPreview WHERE UserID = ?"; | ||
26 | my ($jid) = @ARGV; | ||
27 | my $roster = eval { | ||
28 | $dbh->selectall_arrayref($sql,{ Slite=> {} },$jid); | ||
29 | }; | ||
30 | foreach my $item ( @$roster ) { | ||
31 | print "Entry: $item->[3] $item->[2]<$item->[1]> in group $item->[0]\n"; | ||
32 | } | ||
33 | } elsif (/^list$/) { | ||
34 | my $sql = "SELECT jid, fullname, groupname FROM requiredusers ORDER BY groupname, fullname"; | ||
35 | my $roster = eval { | ||
36 | $dbh->selectall_arrayref($sql,{ Slite=> {} }); | ||
37 | }; | ||
38 | foreach my $item ( @$roster ) { | ||
39 | print "Entry: $item->[1]<$item->[0]> in group $item->[2]\n"; | ||
40 | } | ||
41 | } elsif (/^add$/) { | ||
42 | if ($#ARGV < 2) { | ||
43 | die ("Must specify jabber id, fullname and groupname"); | ||
44 | } | ||
45 | my $sql = "INSERT INTO requiredusers (jid, fullname, groupname) VALUES (?, ?, ?)"; | ||
46 | my ($jid, $fname, $gname) = @ARGV; | ||
47 | print "Adding: $fname<$jid> to group $gname\n"; | ||
48 | $dbh->do($sql,undef,$jid,$fname,$gname); | ||
49 | } elsif (/^del$/) { | ||
50 | if ($#ARGV < 0) { | ||
51 | die ("Must specify jabber id"); | ||
52 | } | ||
53 | my $sql = "DELETE FROM requiredusers WHERE jid = ?"; | ||
54 | my ($jid) = @ARGV; | ||
55 | print "Deleting: $jid\n"; | ||
56 | $dbh->do($sql,undef,$jid); | ||
57 | } else { | ||
58 | die ("Unknown action $action\n"); | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||