summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-07-26 05:05:43 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-07-26 05:05:43 (GMT)
commit93a958c9f5cd178adc07a2c91a333b283a7fe872 (patch)
tree3c2d152111fb233b39b50ab3e700a787c2e93dcf /lib
parent530c0398afb0a90322d4436e93b378e22651fa5b (diff)
added script to handle rivenell users
Diffstat (limited to 'lib')
-rwxr-xr-xlib/RHRD/rddb.pm87
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index ee49444..b887c66 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -110,6 +110,93 @@ sub check_token
return (0, 'ERROR', "wrong password");
}
+sub add_user
+{
+ my ($dbh, $username, $token) = @_;
+
+ my $sql = qq{insert into USERS (LOGIN_NAME, FULL_NAME, PHONE_NUMBER, DESCRIPTION, PASSWORD, ENABLE_WEB, ADMIN_USERS_PRIV, ADMIN_CONFIG_PRIV, CREATE_CARTS_PRIV, DELETE_CARTS_PRIV, MODIFY_CARTS_PRIV, EDIT_AUDIO_PRIV, ASSIGN_CART_PRIV, CREATE_LOG_PRIV, DELETE_LOG_PRIV, DELETE_REC_PRIV, PLAYOUT_LOG_PRIV, ARRANGE_LOG_PRIV, MODIFY_TEMPLATE_PRIV, ADDTO_LOG_PRIV, REMOVEFROM_LOG_PRIV, CONFIG_PANELS_PRIV, VOICETRACK_LOG_PRIV, EDIT_CATCHES_PRIV, ADD_PODCAST_PRIV, EDIT_PODCAST_PRIV, DELETE_PODCAST_PRIV) values ( ?, "", "", "", ? , "N", "N", "N", "Y", "Y", "N", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N");};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ my $cnt = $sth->execute($username, $token)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ $sth->finish();
+ return ($cnt, 'OK', "success");
+}
+
+sub remove_user
+{
+ my ($dbh, $username) = @_;
+
+ my @actions = ({
+ # Delete RSS Feed Perms
+ sql => qq{delete from FEED_PERMS where USER_NAME = ?;},
+ name => 'podcast feed assignments',
+ cnt => 0
+ }, {
+ # Delete Member User Perms
+ sql => qq{delete from USER_PERMS where USER_NAME = ?;},
+ name => 'group assignments',
+ cnt => 0
+ }, {
+ # Delete from User List
+ sql => qq{delete from USERS where LOGIN_NAME = ?;},
+ name => 'user entries',
+ cnt => 0
+ }, {
+ # Delete from Cached Web Connections
+ sql => qq{delete from WEB_CONNECTIONS where LOGIN_NAME = ?;},
+ name => 'cached web connections',
+ 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($username)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ $sth->finish();
+ }
+
+ return @actions;
+}
+
+sub check_user
+{
+ my ($dbh, $username) = @_;
+
+ my $sql = qq{select count(*) from USERS where LOGIN_NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute($username)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my ($cnt) = $sth->fetchrow_array();
+ $sth->finish();
+
+ if ($cnt != 0) {
+ $sql = qq{select count(*) from STATIONS where DEFAULT_NAME = ?;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute($username)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ ($cnt) = $sth->fetchrow_array();
+ $sth->finish();
+
+ if($cnt) { return (2, 'OK', "user '" . $username . "' is known by rivendell and is the default user of at least one station"); }
+ else { return (1, 'OK', "user '" . $username . "' is known by rivendell and isn't the default user of any station"); }
+ }
+
+ return (0, 'OK', "user '" . $username . "' not known by rivendell");
+}
+
sub get_users
{
my ($dbh) = @_;