summaryrefslogtreecommitdiff
path: root/utils/rd-user
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 /utils/rd-user
parent530c0398afb0a90322d4436e93b378e22651fa5b (diff)
added script to handle rivenell users
Diffstat (limited to 'utils/rd-user')
-rwxr-xr-xutils/rd-user73
1 files changed, 73 insertions, 0 deletions
diff --git a/utils/rd-user b/utils/rd-user
new file mode 100755
index 0000000..22a41ec
--- /dev/null
+++ b/utils/rd-user
@@ -0,0 +1,73 @@
+#!/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 create/remove users...
+if ($> != 0 ) {
+ print STDERR "this must be run as root!\n";
+ exit 1;
+}
+
+my $num_args = $#ARGV + 1;
+if ($num_args != 2) {
+ print STDERR "Usage: rd-user (check|add|remove) <username>\n";
+ exit 1;
+}
+
+my $cmd = $ARGV[0];
+my $username = $ARGV[1];
+
+my ($dbh, undef, $errorstring) = RHRD::rddb::opendb();
+if(defined $dbh) {
+ if($cmd eq "check") {
+ (my $result, my $status, $errorstring) = RHRD::rddb::check_user($dbh, $username);
+ print "$result, $status: $errorstring\n";
+ } elsif($cmd eq "add") {
+ my $token = mkpasswd(-length => 16, -minnum => 3, -minupper => 3, -minspecial => 2);
+ (my $cnt, undef, $errorstring) = RHRD::rddb::add_user($dbh, $username, $token);
+ unless(defined $cnt) {
+ print "$errorstring\n";
+ RHRD::rddb::closedb($dbh);
+ exit 1;
+ }
+ print int($cnt) . " rows affected\n";
+ } elsif($cmd eq "remove") {
+ my @results = RHRD::rddb::remove_user($dbh, $username);
+ if(!defined $results[0] && defined $results[2]) {
+ print "$results[2]\n";
+ } else {
+ for my $href (@results) {
+ print int($href->{cnt}) . " " . $href->{name} . " deleted\n";
+ }
+ }
+ }
+
+ RHRD::rddb::closedb($dbh);
+} else {
+ print STDERR "$errorstring\n";
+ exit 1;
+}
+
+exit 0