#!/usr/bin/perl ######################################### # invite ######################################### # id hash state attest created expired username password realname email grass keywords use localbucky; use invite; use Digest::MD5 qw (md5_hex); $dbh = DBI->connect ($dsn); our ($USER, $lastlog) = checkin(); our $loggedin = ($USER != -1); our ($command, $hash, $id) = invite_init(); invite_run($command, $hash, $id); sub invite_init { my $command = exists($input->{c}) ? scrub($input->{c}) : -1; my $hash = -1; if (defined($input->{object_from_uri})) { $hash = scrub($input->{object_from_uri}); } elsif (exists($input->{hash})) { $hash = scrub($input->{hash}); } elsif (exists($input->{invite})) { $hash = scrub($input->{invite}); } elsif (exists($input->{i})) { $hash = scrub($input->{i}); } my $id = exists($input->{id}) ? scrub($input->{id}) : -1; return ($command, $hash, $id); } sub invite_run { my ($command, $hash, $id) = @_; if ($loggedin) { invite_process_user($command, $hash, $id); } else { invite_process_outsider($command, $hash); } } sub invite_process_outsider { my ($command, $hash) = @_; # validate invite if ($command eq "validate") { validate_invite($hash); } # add request elsif ($command eq "request") { request_invite(); } # redeem invite elsif ($hash != -1) { my $invite = get_invite_from_hash($hash); unless (invite_is_active($invite)) { error("Bad invite key!"); } registration_form($invite); } # registration form else { registration_form(); } } sub invite_process_user { my ($command, $hash, $id) = @_; my $result = -1; my $invite = -1; if ($hash != -1) { $invite = get_invite_from_hash($hash); } elsif ($id) { $invite = get_invite_from_id($id); } # new invite if ($command eq "new") { $hash = generate_invite(); $result = ($hash != -1) ? 1 : 0; } # approve/delete/extend invites elsif ($command eq "approve" && $USER->{ulevel} == 3) { $result = validate_approve($invite); } elsif ($command eq "reject" && $USER->{ulevel} == 3) { $result = set_invite_state($invite, $BUCKY_INVITE_REJECTED); } elsif ($command eq "cancel" && $invite->{attest} eq $USER->{username}) { $result = set_invite_state($invite, $BUCKY_INVITE_EXPIRED); } elsif ($command eq "renew" && $invite->{attest} eq $USER->{username}) { $result = set_invite_expired($invite, ($invite->{expired} + 86400*7)); } header("invite manager"); menu(); print qq(); print qq(\n
\n); display_personal_invites($user_invites); print "

"; display_approve_list() if ($USER->{ulevel} == 3); print qq(

\n); invite_result_box($command, $hash, $result) if ($command != -1); invite_create_box(); print qq(
\n\n); footer(); } $dbh->disconnect ();