summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.PL2
-rw-r--r--debian/control2
-rwxr-xr-xlib/RHRD/rddb.pm34
-rwxr-xr-xutils/update-rd-tokens56
4 files changed, 92 insertions, 2 deletions
diff --git a/Makefile.PL b/Makefile.PL
index 89beee4..de9de18 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,7 +1,7 @@
use ExtUtils::MakeMaker;
use 5.004;
-my @utils = qw(get-rd-token get-rd-week);
+my @utils = qw(get-rd-token get-rd-week update-rd-tokens);
WriteMakefile(
NAME => 'RHRD',
diff --git a/debian/control b/debian/control
index fb5f8cc..af8c55b 100644
--- a/debian/control
+++ b/debian/control
@@ -15,7 +15,7 @@ Description: Radio Helsinki Rivendell Perl Modules
Package: rhrd-utils
Architecture: all
-Depends: ${misc:Depends}, ${perl:Depends}, librhrd-perl
+Depends: ${misc:Depends}, ${perl:Depends}, librhrd-perl, libstring-mkpasswd-perl
Description: Radio Helsinki Rivendell Utilities
This package contains the following tools
* get-rd-token
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index 63a182c..ee49444 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -72,6 +72,20 @@ sub get_token
return ($token, 'OK', 'success');
}
+sub set_token
+{
+ my ($dbh, $username, $token) = @_;
+
+ my $sql = qq{update USERS set PASSWORD = ? where LOGIN_NAME = ?;};
+ my $rows = $dbh->do($sql, undef, $token, $username)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ unless($rows == 1) {
+ return (undef, 'ERROR', "user '" . $username . "' not known by rivendell")
+ }
+ return ($token, 'OK', 'success');
+}
+
sub check_token
{
my ($dbh, $username, $token) = @_;
@@ -96,6 +110,26 @@ sub check_token
return (0, 'ERROR', "wrong password");
}
+sub get_users
+{
+ my ($dbh) = @_;
+
+ my $sql = qq{select LOGIN_NAME from USERS order by LOGIN_NAME;};
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+
+ $sth->execute()
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my @users;
+ while(my ($user) = $sth->fetchrow_array()) {
+ push @users, $user;
+ }
+ $sth->finish();
+
+ return @users;
+}
+
sub get_showtitle_and_log
{
my ($dbh, $showid) = @_;
diff --git a/utils/update-rd-tokens b/utils/update-rd-tokens
new file mode 100755
index 0000000..1aee501
--- /dev/null
+++ b/utils/update-rd-tokens
@@ -0,0 +1,56 @@
+#!/usr/bin/perl -w
+#
+# rhrdlibs
+#
+# Copyright (C) 2015 Christian Pointner <equinox@helsinki.at>
+#
+# This file is part of rhrdlibs.
+#
+# rhrdlibs is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# any later version.
+#
+# rhrdlibs 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with rhrdlibs. If not, see <http://www.gnu.org/licenses/>.
+#
+
+use strict;
+use RHRD::rddb;
+use String::MkPasswd qw(mkpasswd);
+
+# this is ridiculous but makes it a little harder to find user passwords...
+if ($> != 0 ) {
+ print STDERR "this must be run as root!\n";
+ exit 1;
+}
+
+my %EXCLUDED_USERS = ('admin' => 1, 'importer' => 1, 'player' => 1);
+
+my ($dbh, undef, $errorstring) = RHRD::rddb::opendb();
+if(defined $dbh) {
+ my @users = RHRD::rddb::get_users($dbh);
+ if(!defined $users[0] && defined $users[2]) {
+ print STDERR "$users[2]\n";
+ exit 1;
+ }
+
+ foreach my $user (@users) {
+ next if(exists($EXCLUDED_USERS{$user}));
+ my $token = mkpasswd(-length => 16, -minnum => 3, -minupper => 3, -minspecial => 2);
+ RHRD::rddb::set_token($dbh, $user, $token);
+ print "$user -> $token\n";
+ }
+
+ RHRD::rddb::closedb($dbh);
+} else {
+ print STDERR "$errorstring\n";
+ exit 1;
+}
+
+exit 0