summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-09-30 23:05:11 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-09-30 23:05:11 (GMT)
commit6f1943313a0e503189dd9685483a9ecd1bd7cc6e (patch)
tree7461bd743125feb61a7f977a06e7698bb184d333 /utils
parent88ba274e7841fedffe9ef98b0933c0610ac6997c (diff)
introduced rhrd context
Diffstat (limited to 'utils')
-rwxr-xr-xutils/get-rd-token8
-rwxr-xr-xutils/rd-group80
-rwxr-xr-xutils/rd-show46
-rwxr-xr-xutils/rd-user32
-rwxr-xr-xutils/rhrd-ws-login8
-rwxr-xr-xutils/update-rd-tokens10
6 files changed, 92 insertions, 92 deletions
diff --git a/utils/get-rd-token b/utils/get-rd-token
index b2b4dce..2c54ea2 100755
--- a/utils/get-rd-token
+++ b/utils/get-rd-token
@@ -46,14 +46,14 @@ if($num_args == 1) {
my $token='';
my $ret = 0;
-my ($dbh, undef, $errorstring) = RHRD::rddb::opendb();
-if(defined $dbh) {
- ($token, undef, $errorstring) = RHRD::rddb::get_token($dbh, $requsername);
+my ($ctx, undef, $errorstring) = RHRD::rddb::init();
+if(defined $ctx) {
+ ($token, undef, $errorstring) = RHRD::rddb::get_token($ctx, $requsername);
unless($token) {
print STDERR "$errorstring\n";
$ret = 1;
}
- RHRD::rddb::closedb($dbh);
+ RHRD::rddb::destroy($ctx);
} else {
print STDERR "$errorstring\n";
$ret = 1;
diff --git a/utils/rd-group b/utils/rd-group
index ecf10cb..3898b5e 100755
--- a/utils/rd-group
+++ b/utils/rd-group
@@ -41,9 +41,9 @@ sub print_usage
sub list
{
- my ($dbh) = @_;
+ my ($ctx) = @_;
- my @groups = RHRD::rddb::list_groups($dbh);
+ my @groups = RHRD::rddb::list_groups($ctx);
if(!defined $groups[0] && defined $groups[1]) {
print STDERR "$groups[1]: $groups[2]";
return 1;
@@ -56,18 +56,18 @@ sub list
sub check
{
- my ($dbh, $groupname) = @_;
+ my ($ctx, $groupname) = @_;
- my ($result, $status, $errorstring) = RHRD::rddb::check_group($dbh, $groupname);
+ my ($result, $status, $errorstring) = RHRD::rddb::check_group($ctx, $groupname);
print STDERR "$result, $status: $errorstring\n";
return $result;
}
sub add
{
- my ($dbh, $groupname, $description) = @_;
+ my ($ctx, $groupname, $description) = @_;
- my ($cnt, $status, $errorstring) = RHRD::rddb::add_group($dbh, $groupname, $description);
+ my ($cnt, $status, $errorstring) = RHRD::rddb::add_group($ctx, $groupname, $description);
unless(defined $cnt) {
print STDERR "$errorstring\n";
return 1;
@@ -78,9 +78,9 @@ sub add
sub remove
{
- my ($dbh, $groupname) = @_;
+ my ($ctx, $groupname) = @_;
- my @results = RHRD::rddb::remove_group($dbh, $groupname);
+ my @results = RHRD::rddb::remove_group($ctx, $groupname);
if(!defined $results[0] && defined $results[2]) {
print STDERR "$results[2]\n";
return 1;
@@ -93,9 +93,9 @@ sub remove
sub get_members
{
- my ($dbh, $groupname) = @_;
+ my ($ctx, $groupname) = @_;
- my @users = RHRD::rddb::get_group_members($dbh, $groupname);
+ my @users = RHRD::rddb::get_group_members($ctx, $groupname);
if(!defined $users[0] && defined $users[1]) {
print STDERR "$users[2]\n";
return 1;
@@ -108,9 +108,9 @@ sub get_members
sub add_member
{
- my ($dbh, $groupname, $username) = @_;
+ my ($ctx, $groupname, $username) = @_;
- my ($cnt, undef, $errorstring) = RHRD::rddb::add_group_member($dbh, $groupname, $username);
+ my ($cnt, undef, $errorstring) = RHRD::rddb::add_group_member($ctx, $groupname, $username);
unless(defined $cnt) {
print STDERR "$errorstring\n";
return 1;
@@ -121,9 +121,9 @@ sub add_member
sub remove_member
{
- my ($dbh, $groupname, $username) = @_;
+ my ($ctx, $groupname, $username) = @_;
- my ($cnt, undef, $errorstring) = RHRD::rddb::remove_group_member($dbh, $groupname, $username);
+ my ($cnt, undef, $errorstring) = RHRD::rddb::remove_group_member($ctx, $groupname, $username);
unless(defined $cnt) {
print STDERR "$errorstring\n";
return 1;
@@ -134,9 +134,9 @@ sub remove_member
sub is_member
{
- my ($dbh, $groupname, $username) = @_;
+ my ($ctx, $groupname, $username) = @_;
- my ($cnt, undef, $errorstring) = RHRD::rddb::is_group_member($dbh, $groupname, $username);
+ my ($cnt, undef, $errorstring) = RHRD::rddb::is_group_member($ctx, $groupname, $username);
unless(defined $cnt) {
print STDERR "$errorstring\n";
return 1;
@@ -147,9 +147,9 @@ sub is_member
sub get_carts
{
- my ($dbh, $groupname) = @_;
+ my ($ctx, $groupname) = @_;
- my ($low, $high, $type, $enforce_range) = RHRD::rddb::get_group_carts($dbh, $groupname);
+ my ($low, $high, $type, $enforce_range) = RHRD::rddb::get_group_carts($ctx, $groupname);
unless(defined $low) {
print STDERR "$type\n";
return 1;
@@ -160,9 +160,9 @@ sub get_carts
sub set_carts
{
- my ($dbh, $groupname, $low_cart, $high_cart, $cart_type, $enforce_cart_range) = @_;
+ my ($ctx, $groupname, $low_cart, $high_cart, $cart_type, $enforce_cart_range) = @_;
- my ($cnt, undef, $errorstring) = RHRD::rddb::set_group_carts($dbh, $groupname, $low_cart, $high_cart, $cart_type, $enforce_cart_range);
+ my ($cnt, undef, $errorstring) = RHRD::rddb::set_group_carts($ctx, $groupname, $low_cart, $high_cart, $cart_type, $enforce_cart_range);
unless(defined $cnt) {
print STDERR "$errorstring\n";
return 1;
@@ -173,9 +173,9 @@ sub set_carts
sub get_reports
{
- my ($dbh, $groupname) = @_;
+ my ($ctx, $groupname) = @_;
- my ($nownext, $traffic, $music) = RHRD::rddb::get_group_reports($dbh, $groupname);
+ my ($nownext, $traffic, $music) = RHRD::rddb::get_group_reports($ctx, $groupname);
unless(defined $nownext) {
print STDERR "$music\n";
return 1;
@@ -186,9 +186,9 @@ sub get_reports
sub set_reports
{
- my ($dbh, $groupname, $now_next, $traffic, $music) = @_;
+ my ($ctx, $groupname, $now_next, $traffic, $music) = @_;
- my ($cnt, undef, $errorstring) = RHRD::rddb::set_group_reports($dbh, $groupname, $now_next, $traffic, $music);
+ my ($cnt, undef, $errorstring) = RHRD::rddb::set_group_reports($ctx, $groupname, $now_next, $traffic, $music);
unless(defined $cnt) {
print STDERR "$errorstring\n";
return 1;
@@ -208,14 +208,14 @@ my $cmd = $ARGV[0];
my $groupname = $ARGV[1];
my $ret = 0;
-my ($dbh, $status, $errorstring) = RHRD::rddb::opendb();
-if(defined $dbh) {
+my ($ctx, $status, $errorstring) = RHRD::rddb::init();
+if(defined $ctx) {
if($cmd eq "list") {
if($num_args != 1) {
print_usage();
$ret = 1;
} else {
- $ret = list($dbh);
+ $ret = list($ctx);
}
}
elsif($cmd eq "check") {
@@ -223,7 +223,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = check($dbh, $groupname);
+ $ret = check($ctx, $groupname);
}
}
elsif($cmd eq "add") {
@@ -231,7 +231,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = add($dbh, $groupname, $ARGV[2]);
+ $ret = add($ctx, $groupname, $ARGV[2]);
}
}
elsif($cmd eq "remove") {
@@ -239,7 +239,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = remove($dbh, $groupname);
+ $ret = remove($ctx, $groupname);
}
}
elsif($cmd eq "get-members") {
@@ -247,7 +247,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = get_members($dbh, $groupname);
+ $ret = get_members($ctx, $groupname);
}
}
elsif($cmd eq "add-member") {
@@ -255,7 +255,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = add_member($dbh, $groupname, $ARGV[2]);
+ $ret = add_member($ctx, $groupname, $ARGV[2]);
}
}
elsif($cmd eq "remove-member") {
@@ -263,7 +263,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = remove_member($dbh, $groupname, $ARGV[2]);
+ $ret = remove_member($ctx, $groupname, $ARGV[2]);
}
}
elsif($cmd eq "is-member") {
@@ -271,7 +271,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = is_member($dbh, $groupname, $ARGV[2]);
+ $ret = is_member($ctx, $groupname, $ARGV[2]);
}
}
elsif($cmd eq "get-carts") {
@@ -279,7 +279,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = get_carts($dbh, $groupname);
+ $ret = get_carts($ctx, $groupname);
}
}
elsif($cmd eq "set-carts") {
@@ -287,7 +287,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = set_carts($dbh, $groupname, $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5]);
+ $ret = set_carts($ctx, $groupname, $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5]);
}
}
elsif($cmd eq "get-reports") {
@@ -295,7 +295,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = get_reports($dbh, $groupname);
+ $ret = get_reports($ctx, $groupname);
}
}
elsif($cmd eq "set-reports") {
@@ -303,15 +303,15 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = set_reports($dbh, $groupname, $ARGV[2], $ARGV[3], $ARGV[4]);
+ $ret = set_reports($ctx, $groupname, $ARGV[2], $ARGV[3], $ARGV[4]);
}
}
else {
- print STDERR "unknown command\n";
+ print_usage();
$ret = 1;
}
- RHRD::rddb::closedb($dbh);
+ RHRD::rddb::destroy($ctx);
} else {
print STDERR "$errorstring\n";
$ret = 1;
diff --git a/utils/rd-show b/utils/rd-show
index 17286e9..0e53e05 100755
--- a/utils/rd-show
+++ b/utils/rd-show
@@ -39,9 +39,9 @@ sub print_usage
sub list
{
- my ($dbh) = @_;
+ my ($ctx) = @_;
- my @shows = RHRD::rddb::list_shows($dbh);
+ my @shows = RHRD::rddb::list_shows($ctx);
if(!defined $shows[0] && defined $shows[1]) {
print STDERR "$shows[1]: $shows[2]";
return 1;
@@ -54,14 +54,14 @@ sub list
sub show
{
- my ($dbh, $show_id) = @_;
+ my ($ctx, $show_id) = @_;
- my @carts = RHRD::rddb::get_show_carts($dbh, $show_id);
+ my @carts = RHRD::rddb::get_show_carts($ctx, $show_id);
if(!defined $carts[0] && defined $carts[1]) {
print STDERR "$carts[1]: $carts[2]\n";
return 1;
}
- my ($title, undef, $status, $errorstring) = RHRD::rddb::get_show_title_and_log($dbh, $show_id);
+ my ($title, undef, $status, $errorstring) = RHRD::rddb::get_show_title_and_log($ctx, $show_id);
unless (defined $title) {
print STDERR "$errorstring\n";
return 1;
@@ -77,24 +77,24 @@ sub show
sub add__create_group
{
- my ($dbh, $groupname) = @_;
+ my ($ctx, $groupname) = @_;
print " > '" . $groupname . "' does not exist - creating it .. ";
- my ($cnt, $status, $errorstring) = RHRD::rddb::add_group($dbh, $groupname);
+ my ($cnt, $status, $errorstring) = RHRD::rddb::add_group($ctx, $groupname);
unless(defined $cnt) {
print STDERR $status . ": " . $errorstring . "\n";
return undef;
}
print int($cnt) . " rows affected\n";
- (my $low_cart, my $high_cart, $errorstring) = RHRD::rddb::get_shows_next_free_slot($dbh);
+ (my $low_cart, my $high_cart, $errorstring) = RHRD::rddb::get_shows_next_free_slot($ctx);
if(!$low_cart) {
print $high_cart . ": " . $errorstring . "\n";
return undef;
}
print " using carts " . $low_cart . " - " . $high_cart . " for new group .. ";
- ($cnt, $status, $errorstring) = RHRD::rddb::set_group_carts($dbh, $groupname, $low_cart, $high_cart, 1, 'Y');
+ ($cnt, $status, $errorstring) = RHRD::rddb::set_group_carts($ctx, $groupname, $low_cart, $high_cart, 1, 'Y');
unless(defined $cnt) {
print STDERR $status . ": " . $errorstring . "\n";
return undef;
@@ -102,7 +102,7 @@ sub add__create_group
print int($cnt) . " rows affected\n";
print " enabling reports .. ";
- ($cnt, $status, $errorstring) = RHRD::rddb::set_group_reports($dbh, $groupname, 'Y', 'Y', 'Y');
+ ($cnt, $status, $errorstring) = RHRD::rddb::set_group_reports($ctx, $groupname, 'Y', 'Y', 'Y');
unless(defined $cnt) {
print STDERR $status . ": " . $errorstring . "\n";
return undef;
@@ -114,9 +114,9 @@ sub add__create_group
sub add__get_group_carts
{
- my ($dbh, $groupname, $num_carts) = @_;
+ my ($ctx, $groupname, $num_carts) = @_;
- my ($result, $status, $errorstring) = RHRD::rddb::check_group($dbh, $groupname);
+ my ($result, $status, $errorstring) = RHRD::rddb::check_group($ctx, $groupname);
unless(defined $result) {
print STDERR $status . ": " . $errorstring . "\n";
return undef;
@@ -129,7 +129,7 @@ sub add__get_group_carts
# find free range in group which is big enough for $num_carts carts
} else {
- $low_cart = add__create_group($dbh, $groupname);
+ $low_cart = add__create_group($ctx, $groupname);
}
return $low_cart;
@@ -137,11 +137,11 @@ sub add__get_group_carts
sub add
{
- my ($dbh, $groupname, $name, $title, $num_carts, $rhythm, $dow, $starttime, $len) = @_;
+ my ($ctx, $groupname, $name, $title, $num_carts, $rhythm, $dow, $starttime, $len) = @_;
print " * creating show: " . $title . " (" . $name . ") for group '" . $groupname . "'\n";
- my $low_cart = add__get_group_carts($dbh, $groupname, $num_carts);
+ my $low_cart = add__get_group_carts($ctx, $groupname, $num_carts);
return 1 unless defined($low_cart);
my $high_cart = $low_cart + $num_carts - 1;
print " * will be using carts: " . $low_cart . " - " . $high_cart . "\n";
@@ -158,7 +158,7 @@ sub add
sub remove
{
- my ($dbh, $show_id) = @_;
+ my ($ctx, $show_id) = @_;
print "removing show " . $show_id . ", not yet implemented!\n";
return 0;
@@ -172,14 +172,14 @@ if($num_args < 1) {
my $cmd = $ARGV[0];
my $ret = 0;
-my ($dbh, $status, $errorstring) = RHRD::rddb::opendb();
-if(defined $dbh) {
+my ($ctx, $status, $errorstring) = RHRD::rddb::init();
+if(defined $ctx) {
if($cmd eq "list") {
if($num_args != 1) {
print_usage();
$ret = 1;
} else {
- $ret = list($dbh)
+ $ret = list($ctx)
}
}
elsif($cmd eq "show") {
@@ -187,7 +187,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = show($dbh, $ARGV[1])
+ $ret = show($ctx, $ARGV[1])
}
}
elsif($cmd eq "remove") {
@@ -195,7 +195,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = remove($dbh, $ARGV[1]);
+ $ret = remove($ctx, $ARGV[1]);
}
}
elsif($cmd eq "add") {
@@ -203,14 +203,14 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = add($dbh, $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5], $ARGV[6], $ARGV[7], $ARGV[8]);
+ $ret = add($ctx, $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5], $ARGV[6], $ARGV[7], $ARGV[8]);
}
}
else {
print_usage();
$ret = 1;
}
- RHRD::rddb::closedb($dbh);
+ RHRD::rddb::destroy($ctx);
} else {
print STDERR "$errorstring\n";
$ret = 1;
diff --git a/utils/rd-user b/utils/rd-user
index 2a032dd..8689cb4 100755
--- a/utils/rd-user
+++ b/utils/rd-user
@@ -39,9 +39,9 @@ sub print_usage
sub list
{
- my ($dbh) = @_;
+ my ($ctx) = @_;
- my @users = RHRD::rddb::list_users($dbh);
+ my @users = RHRD::rddb::list_users($ctx);
if(!defined $users[0] && defined $users[1]) {
print STDERR "$users[1]: $users[2]";
return 1;
@@ -54,19 +54,19 @@ sub list
sub check
{
- my ($dbh, $username) = @_;
+ my ($ctx, $username) = @_;
- my ($result, $status, $errorstring) = RHRD::rddb::check_user($dbh, $username);
+ my ($result, $status, $errorstring) = RHRD::rddb::check_user($ctx, $username);
print STDERR "$result, $status: $errorstring\n";
return $result;
}
sub add
{
- my ($dbh, $username, $fullname) = @_;
+ my ($ctx, $username, $fullname) = @_;
my $token = mkpasswd(-length => 16, -minnum => 3, -minupper => 3, -minspecial => 0);
- my ($cnt, undef, $errorstring) = RHRD::rddb::add_user($dbh, $username, $token, $fullname);
+ my ($cnt, undef, $errorstring) = RHRD::rddb::add_user($ctx, $username, $token, $fullname);
unless(defined $cnt) {
print STDERR "$errorstring\n";
return 1;
@@ -77,9 +77,9 @@ sub add
sub remove
{
- my ($dbh, $username) = @_;
+ my ($ctx, $username) = @_;
- my @results = RHRD::rddb::remove_user($dbh, $username);
+ my @results = RHRD::rddb::remove_user($ctx, $username);
if(!defined $results[0] && defined $results[2]) {
print STDERR "$results[2]\n";
return 1;
@@ -100,14 +100,14 @@ my $cmd = $ARGV[0];
my $username = $ARGV[1];
my $ret = 0;
-my ($dbh, undef, $errorstring) = RHRD::rddb::opendb();
-if(defined $dbh) {
+my ($ctx, undef, $errorstring) = RHRD::rddb::init();
+if(defined $ctx) {
if($cmd eq "list") {
if($num_args != 1) {
print_usage();
$ret = 1;
} else {
- $ret = list($dbh);
+ $ret = list($ctx);
}
}
elsif($cmd eq "check") {
@@ -115,28 +115,28 @@ if(defined $dbh) {
print_usage();
$ret = 1;
} else {
- $ret = check($dbh, $username);
+ $ret = check($ctx, $username);
}
} elsif($cmd eq "add") {
if($num_args < 2 || $num_args > 3) {
print_usage();
$ret = 1;
} else {
- $ret = add($dbh, $username, $ARGV[2]);
+ $ret = add($ctx, $username, $ARGV[2]);
}
} elsif($cmd eq "remove") {
if($num_args != 2) {
print_usage();
$ret = 1;
} else {
- $ret = remove($dbh, $username);
+ $ret = remove($ctx, $username);
}
} else {
- print STDERR "unknown command\n";
+ print_usage();
$ret = 1;
}
- RHRD::rddb::closedb($dbh);
+ RHRD::rddb::destroy($ctx);
} else {
print STDERR "$errorstring\n";
$ret = 1;
diff --git a/utils/rhrd-ws-login b/utils/rhrd-ws-login
index a3cee53..79eeac5 100755
--- a/utils/rhrd-ws-login
+++ b/utils/rhrd-ws-login
@@ -38,14 +38,14 @@ my $username = $ENV{'USER'};
my $ret = 0;
-my ($dbh, undef, $errorstring) = RHRD::rddb::opendb();
-if(defined $dbh) {
+my ($ctx, undef, $errorstring) = RHRD::rddb::init();
+if(defined $ctx) {
my $macro = '';
if($cmd eq "logout") {
$macro = "LO!";
}
elsif($cmd eq "login") {
- (my $token, undef, $errorstring) = RHRD::rddb::get_token($dbh, $username);
+ (my $token, undef, $errorstring) = RHRD::rddb::get_token($ctx, $username);
if($token) {
$token =~ s/([ !'"\\])/\\$1/g;
$macro = "LO $username $token!";
@@ -58,7 +58,7 @@ if(defined $dbh) {
print_usage();
$ret = 1;
}
- RHRD::rddb::closedb($dbh);
+ RHRD::rddb::destroy($ctx);
unless ($macro eq '') {
system('/usr/bin/rmlsend', $macro) == 0 or die "system(/usr/bin/rmlsend, $macro) failed: $?";
}
diff --git a/utils/update-rd-tokens b/utils/update-rd-tokens
index 8983b17..4004e5d 100755
--- a/utils/update-rd-tokens
+++ b/utils/update-rd-tokens
@@ -39,9 +39,9 @@ my %EXCLUDED_USERS = map { $_ => 1 } @ARGV;
$EXCLUDED_USERS{'admin'} = 1;
my $ret = 0;
-my ($dbh, undef, $errorstring) = RHRD::rddb::opendb();
-if(defined $dbh) {
- my @users = RHRD::rddb::list_users($dbh);
+my ($ctx, undef, $errorstring) = RHRD::rddb::init();
+if(defined $ctx) {
+ my @users = RHRD::rddb::list_users($ctx);
if(!defined $users[0] && defined $users[2]) {
print STDERR "$users[2]\n";
$ret = 1;
@@ -49,12 +49,12 @@ if(defined $dbh) {
foreach my $user (@users) {
next if(exists($EXCLUDED_USERS{$user}));
my $token = mkpasswd(-length => 16, -minnum => 3, -minupper => 3, -minspecial => 0);
- RHRD::rddb::set_token($dbh, $user, $token);
+ RHRD::rddb::set_token($ctx, $user, $token);
print "$user -> $token\n";
}
}
- RHRD::rddb::closedb($dbh);
+ RHRD::rddb::destroy($ctx);
} else {
print STDERR "$errorstring\n";
$ret = 1;