| Line 12... |
Line 12... |
| 12 |
$SIG{__WARN__} = sub { warn sprintf("[%s] ", scalar localtime), @_ };
|
12 |
$SIG{__WARN__} = sub { warn sprintf("[%s] ", scalar localtime), @_ };
|
| 13 |
$SIG{__DIE__} = sub { die sprintf("[%s] ", scalar localtime), @_ };
|
13 |
$SIG{__DIE__} = sub { die sprintf("[%s] ", scalar localtime), @_ };
|
| Line 14... |
Line 14... |
| 14 |
|
14 |
|
| Line 15... |
Line 15... |
| 15 |
our @EXPORT = qw( $ORCUSER $SYSTEM_EMAIL getRCDBH getAccessLevels authDB max authenticate canView getShiftDepartment getClassID getDepartments convertDepartments convertTime getSchedule getRCid getSetting getUser getUserEmail getUserDerbyName getYears printRCHeader changeShift modShiftTime signUpCount signUpEligible findConflict changeLeadShift sendNewUserEMail logit validate_emt);
|
15 |
our @EXPORT = qw( $ORCUSER $SYSTEM_EMAIL getRCDBH getAccessLevels authDB max authenticate canView getShiftDepartment getClassID getDepartments convertDepartments convertTime getSchedule getRCid getSetting getUser getUserEmail getUserDerbyName getYears printRCHeader changeShift modShiftTime signUpCount signUpEligible findConflict changeLeadShift sendNewUserEMail logit validate_emt);
|
| Line 16... |
Line 16... |
| 16 |
|
16 |
|
| 17 |
checkQueue (); # without a number here, the queue functionality is disabled / bypassed
|
17 |
checkQueue (100); # without a number here, the queue functionality is disabled / bypassed
|
| 18 |
|
18 |
|
| 19 |
my $dbh = WebDB::connect ("vorc");
|
19 |
my $dbh = WebDB::connect ("vorc");
|
| Line 140... |
Line 140... |
| 140 |
$RCDBIDHASH->{department} = convertDepartments ($RCDBIDHASH->{department});
|
140 |
$RCDBIDHASH->{department} = convertDepartments ($RCDBIDHASH->{department});
|
| 141 |
$RCDBIDHASH->{'access'} = max ($RCDBIDHASH->{'access'}, values %{$RCDBIDHASH->{department}});
|
141 |
$RCDBIDHASH->{'access'} = max ($RCDBIDHASH->{'access'}, values %{$RCDBIDHASH->{department}});
|
| 142 |
$result->{cookie_string} = "${id}&${encpass}&$RCDBIDHASH->{'access'}";
|
142 |
$result->{cookie_string} = "${id}&${encpass}&$RCDBIDHASH->{'access'}";
|
| 143 |
$result->{RCid} = $RCDBIDHASH->{'RCid'};
|
143 |
$result->{RCid} = $RCDBIDHASH->{'RCid'};
|
| 144 |
logit($RCDBIDHASH->{'RCid'}, "Logged In") if $src eq "form";
|
144 |
logit($RCDBIDHASH->{'RCid'}, "Logged In") if $src eq "form";
|
| 145 |
# $dbh->do ("update official set last_login = CONVERT_TZ(now(), 'America/Chicago', 'America/Los_Angeles') where RCid = ?", undef, $RCDBIDHASH->{'RCid'}) if $src eq "form";
|
- |
|
| 146 |
$dbh->do ("update official set last_login = now() where RCid = ?", undef, $RCDBIDHASH->{'RCid'}) if $src eq "form";
|
145 |
$dbh->do ("update official set last_login = now() where RCid = ?", undef, $RCDBIDHASH->{'RCid'}) if $src eq "form";
|
| 147 |
$result->{authenticated} = 'true';
|
146 |
$result->{authenticated} = 'true';
|
| 148 |
# my @depts = map { s/-\d// } split /:/, $RCDBIDHASH->{department};
|
- |
|
| 149 |
# my @depts = split /:/, $RCDBIDHASH->{department};
|
- |
|
| Line 150... |
Line 147... |
| 150 |
|
147 |
|
| 151 |
$ORCUSER = $RCDBIDHASH;
|
148 |
$ORCUSER = $RCDBIDHASH;
|
| 152 |
$ORCUSER->{MVPid} = getUser($ORCUSER->{RCid})->{MVPid};
|
149 |
$ORCUSER->{MVPid} = getUser($ORCUSER->{RCid})->{MVPid};
|
| 153 |
$ORCUSER->{emt_verified} = getUser($ORCUSER->{RCid})->{emt_verified};
|
150 |
$ORCUSER->{emt_verified} = getUser($ORCUSER->{RCid})->{emt_verified};
|
| Line 191... |
Line 188... |
| 191 |
$FORM{'PASS'} = WebDB::trim $query->param('pass') || '';
|
188 |
$FORM{'PASS'} = WebDB::trim $query->param('pass') || '';
|
| 192 |
$FORM{'SUB'} = $query->param('login') || '';
|
189 |
$FORM{'SUB'} = $query->param('login') || '';
|
| 193 |
$FORM{'activate'} = WebDB::trim $query->param('activate') // '';
|
190 |
$FORM{'activate'} = WebDB::trim $query->param('activate') // '';
|
| Line 194... |
Line 191... |
| 194 |
|
191 |
|
| 195 |
if ($RCAUTH) {
|
192 |
if ($RCAUTH) {
|
| 196 |
#We have an authenication cookie. Double-check it
|
193 |
# We have an authenication cookie. Double-check it
|
| 197 |
my ($RCID, $RCPASS, $RCLVL) = split /&/, $RCAUTH;
|
194 |
my ($RCID, $RCPASS, $RCLVL) = split /&/, $RCAUTH;
|
| 198 |
$authenticated = authDB('cookie', $RCID, $RCPASS, $MINLEVEL, $FORM{'activate'});
|
195 |
$authenticated = authDB('cookie', $RCID, $RCPASS, $MINLEVEL, $FORM{'activate'});
|
| 199 |
} elsif ($FORM{'SUB'}) {
|
196 |
} elsif ($FORM{'SUB'}) {
|
| 200 |
#a log in form was submited
|
197 |
# a log in form was submited
|
| 201 |
if ($FORM{'SUB'} eq "Submit") {
|
198 |
if ($FORM{'SUB'} eq "Submit") {
|
| 202 |
$authenticated = authDB('form', $FORM{'ID'}, $FORM{'PASS'}, $MINLEVEL, $FORM{'activate'});
|
199 |
$authenticated = authDB('form', $FORM{'ID'}, $FORM{'PASS'}, $MINLEVEL, $FORM{'activate'});
|
| 203 |
} elsif ($FORM{'SUB'} eq "New User") {
|
200 |
} elsif ($FORM{'SUB'} eq "New User") {
|
| 204 |
# Print the new user form and exit
|
201 |
# Print the new user form and exit
|
| Line 225... |
Line 222... |
| 225 |
$authenticated->{cookie_string} = "";
|
222 |
$authenticated->{cookie_string} = "";
|
| 226 |
$authenticated->{authenticated} = 'false';
|
223 |
$authenticated->{authenticated} = 'false';
|
| 227 |
$ENV{REQUEST_URI} =~ s/LOGOUT//;
|
224 |
$ENV{REQUEST_URI} =~ s/LOGOUT//;
|
| 228 |
logit ($ORCUSER->{RCid}, "Logged Out");
|
225 |
logit ($ORCUSER->{RCid}, "Logged Out");
|
| 229 |
$dbh->do ("update official set last_active = ? where RCid = ?", undef, undef, $ORCUSER->{RCid});
|
226 |
$dbh->do ("update official set last_active = ? where RCid = ?", undef, undef, $ORCUSER->{RCid});
|
| 230 |
# `/bin/rm $SESSIONS_ACTIVE/$sessionid`;
|
- |
|
| 231 |
$qdbh->do ("delete from session where sessionid = ?", undef, $sessionid);
|
227 |
$qdbh->do ("delete from session where sessionid = ?", undef, $sessionid);
|
| 232 |
$ORCUSER = "";
|
228 |
$ORCUSER = "";
|
| 233 |
} else {
|
229 |
} else {
|
| 234 |
$dbh->do ("update official set last_active = now() where RCid = ?", undef, $ORCUSER->{RCid});
|
230 |
$dbh->do ("update official set last_active = now() where RCid = ?", undef, $ORCUSER->{RCid});
|
| 235 |
# `/bin/touch $SESSIONS_ACTIVE/$sessionid`;
|
- |
|
| 236 |
$qdbh->do ("replace into session (RCid, sessionid, timestamp) values (?, ?, now())", undef, $ORCUSER->{RCid}, $sessionid);
|
231 |
$qdbh->do ("replace into session (RCid, sessionid, timestamp, email) values (?, ?, now(), ?)", undef, $ORCUSER->{RCid}, $sessionid, $ORCUSER->{email});
|
| 237 |
# `/bin/rm $SESSIONS_QUEUE/$RCqueueID` if ($RCqueueID and -e $SESSIONS_QUEUE."/".$RCqueueID);
|
- |
|
| 238 |
$qdbh->do ("delete from queue where queueid = ?", undef, $RCqueueID) if $RCqueueID;
|
232 |
$qdbh->do ("delete from queue where queueid = ?", undef, $RCqueueID) if $RCqueueID;
|
| 239 |
return $authenticated->{cookie_string};
|
233 |
return $authenticated->{cookie_string};
|
| 240 |
}
|
234 |
}
|
| 241 |
$qdbh->disconnect;
|
235 |
$qdbh->disconnect;
|
| 242 |
}
|
236 |
}
|
| Line 252... |
Line 246... |
| 252 |
} else {
|
246 |
} else {
|
| 253 |
$authenticated->{ERRMSG} = "";
|
247 |
$authenticated->{ERRMSG} = "";
|
| 254 |
# Since there was no ERRMSG, no need to log anything.
|
248 |
# Since there was no ERRMSG, no need to log anything.
|
| 255 |
}
|
249 |
}
|
| Line 256... |
Line -... |
| 256 |
|
- |
|
| 257 |
# print header(-cookie=>$RCAUTH_cookie);
|
- |
|
| 258 |
|
- |
|
| 259 |
|
250 |
|
| 260 |
if ($RCqueueID) {
|
251 |
if ($RCqueueID) {
|
| 261 |
my $RCQUEUE_cookie = CGI::Cookie->new(-name=>'RCQUEUEID',-value=>"",-expires=>"+0m");
|
252 |
my $RCQUEUE_cookie = CGI::Cookie->new(-name=>'RCQUEUEID',-value=>"",-expires=>"+0m");
|
| 262 |
print header(-cookie=>[$RCAUTH_cookie,$RCQUEUE_cookie]);
|
253 |
print header(-cookie=>[$RCAUTH_cookie,$RCQUEUE_cookie]);
|
| 263 |
} else {
|
254 |
} else {
|
| 264 |
print header(-cookie=>$RCAUTH_cookie);
|
255 |
print header(-cookie=>$RCAUTH_cookie);
|
| - |
|
256 |
}
|
| 265 |
}
|
257 |
|
| 266 |
printRCHeader("Please Sign In");
|
258 |
printRCHeader("Please Sign In");
|
| 267 |
print<<authpage;
|
259 |
print<<authpage;
|
| 268 |
<form action="$ENV{REQUEST_URI}" method=POST name=Req id=Req>
|
260 |
<form action="$ENV{REQUEST_URI}" method=POST name=Req id=Req>
|
| 269 |
<input type=hidden name=RCqueueID value=$RCqueueID>
|
261 |
<input type=hidden name=RCqueueID value=$RCqueueID>
|
| Line 332... |
Line 324... |
| 332 |
exit;
|
324 |
exit;
|
| 333 |
}
|
325 |
}
|
| Line 334... |
Line 326... |
| 334 |
|
326 |
|
| 335 |
sub checkQueue {
|
327 |
sub checkQueue {
|
| - |
|
328 |
my $max_users = shift;
|
| 336 |
my $max_users = shift;
|
329 |
|
| Line 337... |
Line 330... |
| 337 |
return unless $max_users =~ /^\d+$/;
|
330 |
return unless $max_users =~ /^\d+$/;
|
| Line 338... |
Line 331... |
| 338 |
|
331 |
|
| 339 |
return if $ENV{'QUERY_STRING'} eq "SKIPQUEUE";
|
332 |
return if $ENV{'QUERY_STRING'} eq "SKIPQUEUE";
|
| 340 |
|
333 |
|
| Line 341... |
Line 334... |
| 341 |
my $RCAUTH = CGI::cookie('RCAUTH') // "";
|
334 |
my $RCAUTH = CGI::cookie('RCAUTH') // "";
|
| 342 |
|
335 |
|
| 343 |
my $qdbh = WebDB::connect ("session");
|
- |
|
| 344 |
|
336 |
my $qdbh = WebDB::connect ("session");
|
| 345 |
if ($RCAUTH) {
|
- |
|
| 346 |
# If the user is already logged in, bypass the queue check.
|
- |
|
| 347 |
use Digest::MD5 qw/md5_hex/;
|
337 |
|
| 348 |
my ($RCID, $RCPASS, $RCLVL) = split /&/, $RCAUTH;
|
- |
|
| 349 |
# my $sessionid = md5_hex ($RCID);
|
- |
|
| 350 |
|
338 |
if ($RCAUTH) {
|
| 351 |
my ($active) = $qdbh->selectrow_array ("select count(*) from session where RCid = ? and last_active > (now() - interval 30 minute)", undef, $RCID);
|
339 |
# If the user is already logged in, bypass the queue check.
|
| Line 352... |
Line -... |
| 352 |
|
- |
|
| 353 |
# return if -e $SESSIONS_ACTIVE."/".$sessionid;
|
340 |
my ($email, $RCPASS, $RCLVL) = split /&/, $RCAUTH;
|
| 354 |
return if $active;
|
341 |
my ($active) = $qdbh->selectrow_array ("select count(*) from session where email = ? and timestamp > (now() - interval 30 minute)", undef, $email);
|
| 355 |
}
|
342 |
return if $active;
|
| 356 |
|
343 |
}
|
| Line 357... |
Line 344... |
| 357 |
# my $active_users = `/bin/ls -1 $SESSIONS_ACTIVE | /usr/bin/wc -l`; chomp $active_users;
|
344 |
|
| - |
|
345 |
my ($active_users) = $qdbh->selectrow_array ("select count(*) from session where timestamp > (now() - interval 30 minute)");
|
| Line 358... |
Line 346... |
| 358 |
my ($active_users) = $qdbh->selectrow_array ("select count(*) from session where timestamp > (now() - interval 30 minute)");
|
346 |
my ($current_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where last_seen > now() - interval 7 minute limit 1");
|
| 359 |
# my @queued_users = `/bin/ls -1 $SESSIONS_QUEUE`; foreach (@queued_users) { chomp; }
|
347 |
my @queued_users;
|
| 360 |
my @queued_users;
|
348 |
push @queued_users, map { @{$_} } @{ $qdbh->selectall_arrayref ("select queueid from queue where last_seen > (now() - interval 7 minute) and (timestamp <> last_seen or timestampdiff(minute, last_seen, now()) <= 1) order by timestamp") };
|
| 361 |
push @queued_users, map { @{$_} } @{ $qdbh->selectall_arrayref ("select queueid from queue where timestamp > (now() - interval 7 minute) order by timestamp") };
|
349 |
|
| 362 |
|
350 |
my $RCqueueID = CGI::cookie('RCQUEUEID') // WebDB::trim CGI::param('RCqueueID') // "";
|
| 363 |
my $RCqueueID = CGI::cookie('RCQUEUEID') // WebDB::trim CGI::param('RCqueueID') // "";
|
351 |
$RCqueueID = "" unless inQueue ($RCqueueID, \@queued_users);
|
| 364 |
|
352 |
|
| - |
|
353 |
if ($active_users >= $max_users) {
|
| - |
|
354 |
# We are at max users. People have to wait.
|
| 365 |
if ($active_users >= $max_users) {
|
355 |
if (!$RCqueueID) {
|
| 366 |
# We are at max users. People have to wait.
|
- |
|
| Line 367... |
Line 356... |
| 367 |
if (!$RCqueueID) {
|
356 |
use Digest::MD5 qw/md5_hex/;
|
| 368 |
use Digest::MD5 qw/md5_hex/;
|
357 |
$RCqueueID = time () ."-". md5_hex (rand ());
|
| Line 369... |
Line 358... |
| 369 |
$RCqueueID = time () ."-". md5_hex (rand ());
|
358 |
push @queued_users, $RCqueueID;
|
| 370 |
push @queued_users, $RCqueueID;
|
359 |
$qdbh->do ("replace into queue (queueid, timestamp, last_seen) values (?, now(), now())", undef, $RCqueueID);
|
| 371 |
$qdbh->do ("replace into queue (queueid, timestamp) values (?, now())", undef, $RCqueueID);
|
360 |
} else {
|
| 372 |
}
|
361 |
$qdbh->do ("update queue set last_seen = now() where queueid = ?", undef, $RCqueueID);
|
| 373 |
# `/bin/touch $SESSIONS_QUEUE/$RCqueueID`;
|
362 |
}
|
| 374 |
|
363 |
|
| 375 |
printQueuePage ($RCqueueID, "(".inQueue ($RCqueueID, \@queued_users)." of ".scalar @queued_users." users)");
|
364 |
printQueuePage ($RCqueueID, "(".inQueue ($RCqueueID, \@queued_users)." of ".scalar @queued_users." users)", $current_wait);
|
| 376 |
exit;
|
365 |
exit;
|
| - |
|
366 |
|
| - |
|
367 |
} elsif (scalar @queued_users) {
|
| 377 |
|
368 |
# There are users in queue...
|
| Line 378... |
Line 369... |
| 378 |
} elsif (scalar @queued_users) {
|
369 |
if (!$RCqueueID) {
|
| 379 |
# There are users in queue...
|
370 |
# If you're not already in queue, get in line.
|
| 380 |
if (!$RCqueueID) {
|
371 |
use Digest::MD5 qw/md5_hex/;
|
| 381 |
# If you're not already in queue, get in line.
|
372 |
$RCqueueID = time () ."-". md5_hex (rand ());
|
| 382 |
use Digest::MD5 qw/md5_hex/;
|
373 |
push @queued_users, $RCqueueID;
|
| 383 |
$RCqueueID = time () ."-". md5_hex (rand ());
|
374 |
$qdbh->do ("replace into queue (queueid, timestamp, last_seen) values (?, now(), now())", undef, $RCqueueID);
|
| 384 |
push @queued_users, $RCqueueID;
|
375 |
} else {
|
| Line 385... |
Line 376... |
| 385 |
$qdbh->do ("replace into queue (queueid, timestamp) values (?, now())", undef, $RCqueueID);
|
376 |
$qdbh->do ("update queue set last_seen = now() where queueid = ?", undef, $RCqueueID);
|
| 386 |
}
|
377 |
}
|
| Line 387... |
Line 378... |
| 387 |
|
378 |
|
| 388 |
my $queue_position = inQueue ($RCqueueID, \@queued_users);
|
379 |
my $queue_position = inQueue ($RCqueueID, \@queued_users);
|
| 389 |
if ($queue_position > ($max_users - $active_users)) {
|
380 |
if ($queue_position > ($max_users - $active_users)) {
|
| - |
|
381 |
# If you're not at the head of the line, continue to wait.
|
| Line 390... |
Line 382... |
| 390 |
# If you're not at the head of the line, continue to wait.
|
382 |
printQueuePage ($RCqueueID, "($queue_position of ".scalar @queued_users." users)", $current_wait);
|
| 391 |
printQueuePage ($RCqueueID, "($queue_position of ".scalar @queued_users." users)");
|
383 |
exit;
|
| 392 |
exit;
|
384 |
}
|
| 393 |
}
|
385 |
}
|
| 394 |
}
|
386 |
|
| 395 |
|
387 |
return;
|
| - |
|
388 |
}
|
| 396 |
return;
|
389 |
|
| 397 |
}
|
390 |
sub printQueuePage {
|
| 398 |
|
391 |
my $RCqueueID = shift;
|
| 399 |
sub printQueuePage {
|
392 |
my $queue_position = shift;
|
| 400 |
my $RCqueueID = shift;
|
393 |
my $wait_time = shift;
|