summaryrefslogtreecommitdiff
path: root/lib/RHRD/rddb.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/RHRD/rddb.pm')
-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) = @_;