diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-07-25 22:26:23 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-07-25 22:27:26 (GMT) |
commit | 816e4193f4b9d5f40267ebc569afef471b7f5786 (patch) | |
tree | 43f42b4cc6b18dd83ce30b32aef19d68c016083e /utils/update-rd-tokens | |
parent | 5a7e793f8d3d559b519c6c5ab4a386028a0e1106 (diff) |
added update-rd-tokens util
Diffstat (limited to 'utils/update-rd-tokens')
-rwxr-xr-x | utils/update-rd-tokens | 56 |
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 |