1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#!/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(<table width="100%" cellpadding=0 cellspacing=0 border=0>);
print qq(<tr><td align=center valign=top>\n);
display_personal_invites($user_invites);
print "<p>";
display_approve_list() if ($USER->{ulevel} == 3);
print qq(</td>\n<td width="200" align=right valign=top>\n);
invite_result_box($command, $hash, $result) if ($command != -1);
invite_create_box();
print qq(</td></tr></table>\n\n);
footer();
}
$dbh->disconnect ();
|