summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-09-17 21:57:15 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-09-17 21:57:15 (GMT)
commit66557641d3fb28103df0a947552993e5827320aa (patch)
treedc2395a7ea5c358480e1abfccf6fcc7c19b6a4c1 /lib
parent08cfff490aec608049b031cc148ad89ee5543ea4 (diff)
added group handling support
Diffstat (limited to 'lib')
-rw-r--r--lib/RHRD.pm2
-rwxr-xr-xlib/RHRD/rddb.pm197
2 files changed, 198 insertions, 1 deletions
diff --git a/lib/RHRD.pm b/lib/RHRD.pm
index 859641f..ce8bb84 100644
--- a/lib/RHRD.pm
+++ b/lib/RHRD.pm
@@ -26,6 +26,6 @@ use strict;
use vars qw($VERSION);
use 5.004;
-$VERSION = "0.2"
+$VERSION = "0.6"
##########################################################################
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index ef7740d..b7d0698 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -26,6 +26,8 @@ use strict;
use Config::IniFiles;
use DBI;
+########################### connection handling ###########################
+
sub opendb
{
my $RD_CONF = "/etc/rd.conf"; # TODO: hardcoded value
@@ -52,6 +54,8 @@ sub closedb
$dbh->disconnect();
}
+########################### TOKEN handling ###########################
+
sub get_token
{
my ($dbh, $username) = @_;
@@ -116,6 +120,8 @@ sub check_token
return (0, 'ERROR', "wrong password");
}
+########################### USER handling ###########################
+
sub add_user
{
my ($dbh, $username, $token, $fullname) = @_;
@@ -249,6 +255,197 @@ sub get_users
return @users;
}
+########################### GROUP handling ###########################
+
+sub add_group
+{
+ my ($dbh, $groupname, $description) = @_;
+ if(!defined $description) {
+ $description = '';
+ }
+
+ my $sql = qq{insert into GROUPS (NAME, DESCRIPTION) values (?, ?);};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ my $cnt = $sth->execute($groupname, $description)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ $sth->finish();
+ return ($cnt, 'OK', "success");
+}
+
+sub remove_group
+{
+ my ($dbh, $groupname) = @_;
+
+ my @actions = ({
+ # Delete Member Carts
+ sql => qq{delete from CART where GROUP_NAME = ?;},
+ name => 'member carts',
+ cnt => 0
+ }, {
+ # Delete Dropboxes
+ sql => qq{delete from DROPBOXES where GROUP_NAME = ?;},
+ name => 'dropboxes',
+ cnt => 0
+ }, {
+ # Delete Audio Perms
+ sql => qq{delete from AUDIO_PERMS where GROUP_NAME = ?;},
+ name => 'service permissions',
+ cnt => 0
+ }, {
+ # Delete Member User Perms
+ sql => qq{delete from USER_PERMS where GROUP_NAME = ?;},
+ name => 'user assignments',
+ cnt => 0
+ }, {
+ # Delete Replicator Map Records
+ sql => qq{delete from REPLICATOR_MAP where GROUP_NAME = ?;},
+ name => 'replicator map records',
+ cnt => 0
+ }, {
+ # Delete from Group List
+ sql => qq{delete from GROUPS where NAME = ?;},
+ name => 'group entries',
+ cnt => 0
+ });
+
+ for my $href (@actions) {
+ my $sth = $dbh->prepare($href->{sql})
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+ delete($href->{sql});
+
+ $href->{cnt} = $sth->execute($groupname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ $sth->finish();
+ }
+
+ return @actions;
+}
+
+sub check_group
+{
+ my ($dbh, $groupname) = @_;
+
+ my $sql = qq{select count(*) from GROUPS where NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute($groupname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my ($cnt) = $sth->fetchrow_array();
+ $sth->finish();
+
+ if ($cnt != 0) {
+ $sql = qq{select count(*) from CART where GROUP_NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute($groupname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ ($cnt) = $sth->fetchrow_array();
+ $sth->finish();
+
+ if($cnt) { return (2, 'OK', "group '" . $groupname . "' exists and has carts assigned to it"); }
+ else { return (1, 'OK', "group '" . $groupname . "' exists but no cart is assigned to it"); }
+ }
+
+ return (0, 'OK', "group '" . $groupname . "' does not exist");
+}
+
+sub get_group_carts
+{
+ my ($dbh, $groupname) = @_;
+
+ my $sql = qq{select DEFAULT_LOW_CART, DEFAULT_HIGH_CART, DEFAULT_CART_TYPE, ENFORCE_CART_RANGE from GROUPS where NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute($groupname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my ($low_cart, $high_cart, $cart_type, $enforce_cart_range) = $sth->fetchrow_array;
+ $sth->finish();
+
+ return ($low_cart, $high_cart, $cart_type, $enforce_cart_range);
+}
+
+sub set_group_carts
+{
+ my ($dbh, $groupname, $low_cart, $high_cart, $cart_type, $enforce_cart_range) = @_;
+ if(!defined $low_cart) {
+ $low_cart = 0;
+ }
+ if(!defined $high_cart) {
+ $high_cart = 0;
+ }
+ if(!defined $cart_type) {
+ $cart_type = 1;
+ }
+ if(!defined $enforce_cart_range) {
+ $enforce_cart_range = 'N';
+ }
+
+ my $sql = qq{update GROUPS set DEFAULT_LOW_CART = ?, DEFAULT_HIGH_CART = ?, DEFAULT_CART_TYPE = ? , ENFORCE_CART_RANGE = ? where NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ my $cnt = $sth->execute($low_cart, $high_cart, $cart_type, $enforce_cart_range, $groupname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ $sth->finish();
+
+ return ($cnt, 'OK', "Success");
+}
+
+sub get_group_reports
+{
+ my ($dbh, $groupname) = @_;
+
+ my $sql = qq{select ENABLE_NOW_NEXT, REPORT_TFC, REPORT_MUS from GROUPS where NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute($groupname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my ($now_next, $traffic, $music) = $sth->fetchrow_array;
+ $sth->finish();
+
+ return ($now_next, $traffic, $music);
+}
+
+sub set_group_reports
+{
+ my ($dbh, $groupname, $now_next, $traffic, $music) = @_;
+ if(!defined $now_next) {
+ $now_next = 'N';
+ }
+ if(!defined $traffic) {
+ $traffic = 'Y';
+ }
+ if(!defined $music) {
+ $music = 'Y';
+ }
+
+ my $sql = qq{update GROUPS set ENABLE_NOW_NEXT = ?, REPORT_TFC = ?, REPORT_MUS = ? where NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ my $cnt = $sth->execute($now_next, $traffic, $music, $groupname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ $sth->finish();
+
+ return ($cnt, 'OK', "Success");
+}
+
+########################### SHOW handling ###########################
+
sub get_showtitle_and_log
{
my ($dbh, $showid) = @_;