Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sucs-site
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Imran Hussain
sucs-site
Commits
785d74ad
Commit
785d74ad
authored
16 years ago
by
Justin Mitchell
Browse files
Options
Downloads
Patches
Plain Diff
handler for card registration codes
parent
5c093011
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
htdocs/doorknock.php
+132
-0
132 additions, 0 deletions
htdocs/doorknock.php
with
132 additions
and
0 deletions
htdocs/doorknock.php
0 → 100644
+
132
−
0
View file @
785d74ad
<?
function
msg_tx
(
$text
,
$time
,
$fg
,
$bg
)
{
$f
=
fopen
(
"http://door.sucs.org/sendstatus.py?text="
.
urlencode
(
$text
)
.
"&timeout=
$time
&fg=
$fg
&bg=
$bg
"
,
"r"
);
fclose
(
$f
);
}
function
msg_good
(
$text
,
$time
=
5
)
{
msg_tx
(
$text
,
$time
,
"0,0,0"
,
"128,255,128"
);
}
function
msg_bad
(
$text
,
$time
=
3
)
{
msg_tx
(
$text
,
$time
,
"0,0,0"
,
"255,64,64"
);
}
header
(
"Content-type: text/plain"
);
// Initialise the database
require
(
"/usr/share/adodb/adodb.inc.php"
);
$DB
=
NewADOConnection
(
'postgres8'
);
if
(
$DB
->
Connect
(
'dbname=sucs'
)
===
FALSE
)
{
echo
"DB fail
\n
"
;
exit
;
}
$DB
->
SetFetchMode
(
ADODB_FETCH_ASSOC
);
$f
=
fopen
(
"/tmp/doorlog"
,
"a"
);
if
(
isset
(
$_REQUEST
[
'code'
]))
{
// Expire old requests
$DB
->
Execute
(
"delete from doorknock where start < NOW() - 30 seconds:reltime"
);
// Parse out the string
$code
=
$_REQUEST
[
'code'
];
$codes
=
split
(
' '
,
$code
);
if
(
$codes
[
0
]
!=
"SUCS"
)
{
echo
"Unrecognised codeword '
{
$codes
[
0
]
}
'
\n
"
;
msg_bad
(
"Invalid slip"
);
exit
;
}
// look up the user
$user
=
$DB
->
GetAll
(
"select * from signup where id=?"
,
array
(
$codes
[
1
]));
if
(
!
is_array
(
$user
)
||
count
(
$user
)
<
1
)
{
echo
"Unrecognised signup id
\n
"
;
msg_bad
(
"Invalid slip"
);
exit
;
}
if
(
$codes
[
2
]
!=
$user
[
0
][
'password'
])
{
echo
"Password mismatch
\n
"
;
msg_bad
(
"Invalid slip"
);
exit
;
}
if
(
$user
[
0
][
'card'
]
!=
""
)
{
echo
"User already has a card
\n
"
;
msg_bad
(
"Slip already used"
);
exit
;
}
// all looks valid so far
// check we arent bouncing ourselves out
$exist
=
$DB
->
GetAll
(
"select * from doorknock"
);
if
(
is_array
(
$exist
)
&&
count
(
$exist
)
>
0
)
{
print_r
(
$exist
);
if
(
$exist
[
0
][
'suid'
]
==
$user
[
0
][
'id'
])
{
echo
"Already in progress, no action
\n
"
;
exit
;
}
$DB
->
Execute
(
"delete from doorknock"
);
echo
"Bouncing out signup id=
{
$exist
[
0
][
'suid'
]
}
\n
"
;
}
$DB
->
Execute
(
"insert into doorknock (suid,start) values(?,NOW())"
,
array
(
$user
[
0
][
'id'
]));
echo
"Start waiting for id=
{
$user
[
0
][
'id'
]
}
\n
"
;
msg_good
(
"Please swipe ID Card to complete registration"
,
10
);
exit
;
}
else
// a card was swiped at the door, try to match it
if
(
isset
(
$_REQUEST
[
'id'
]))
{
$card
=
$_REQUEST
[
'id'
];
$exist
=
$DB
->
GetAll
(
"select * from doorknock"
);
if
(
!
is_array
(
$exist
)
||
count
(
$exist
)
<
1
)
{
echo
"No registration in progress, ignoring.
\n
"
;
exit
;
}
$signup
=
$DB
->
GetAll
(
"select * from signup where id=?"
,
array
(
$exist
[
0
][
'suid'
]));
if
(
!
is_array
(
$signup
)
||
count
(
$signup
)
<
1
)
{
echo
"Unrecognised signup id
\n
"
;
msg_bad
(
"Invalid slip"
);
$DB
->
Execute
(
"delete from doorknock"
);
exit
;
}
// should really check the card isnt already registered first
$DB
->
Execute
(
"update signup set card=? where id=?"
,
array
(
$card
,
$signup
[
0
][
'id'
]));
echo
"Registering card '
$card
' to signup id
{
$signup
[
0
][
'id'
]
}
\n
"
;
$DB
->
Execute
(
"delete from doorknock"
);
// User is registered, stick it in the real doorcards list too
if
(
$signup
[
0
][
'username'
]
!=
""
)
{
$user
=
$DB
->
GetAll
(
"select * from members where username=?"
,
array
(
$signup
[
0
][
'username'
]));
if
(
!
is_array
(
$user
)
||
count
(
$user
)
<
1
)
{
echo
"Cant find username '
{
$signup
[
0
][
'username'
]
}
' to full reg the card
\n
"
;
}
else
{
$DB
->
Execute
(
"insert into doorcards (uid, cardnumber) values (?,?)"
,
array
(
$user
[
0
][
'uid'
],
$card
));
echo
"Registering card to uid=
{
$user
[
0
][
'uid'
]
}
username
{
$user
[
0
][
'username'
]
}
\n
"
;
}
}
unlink
(
"/tmp/cards"
);
system
(
"/usr/local/bin/db-to-cards.php"
);
system
(
"sudo /usr/local/bin/putcardsfile"
);
unlink
(
"/tmp/cards"
);
msg_good
(
"Card now registered, swipe again for access"
);
exit
;
}
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment