summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rwxr-xr-xutils/update-rd-tokens56
1 files changed, 56 insertions, 0 deletions
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