Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
UCC
UCC Snack Machine Server Code
Commits
8861a669
Commit
8861a669
authored
Feb 19, 2017
by
John Hodge
Browse files
OpenDispense - Fix to actually work
parent
f519d00a
Changes
1
Hide whitespace changes
Inline
Side-by-side
VendServer/OpenDispense.py
View file @
8861a669
...
...
@@ -12,6 +12,8 @@ import os
import
logging
import
re
import
pwd
import
base64
import
socket
from
subprocess
import
Popen
,
PIPE
from
LDAPConnector
import
get_uid
,
get_uname
,
set_card_id
...
...
@@ -75,21 +77,24 @@ class OpenDispense(DispenseInterface):
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
,
0
)
sock
.
connect
(
DISPENSE_ENDPOINT
)
sock
.
write
(
"AUTHIDENT
\n
"
)
rsp
=
sock
.
readline
()
logging
.
debug
(
'connected to dispsrv'
)
sockf
=
sock
.
makefile
()
sockf
.
write
(
"AUTHIDENT
\n
"
);
sockf
.
flush
()
rsp
=
sockf
.
readline
()
assert
"200"
in
rsp
sock
.
write
(
"AUTHCARD %s
\n
"
%
(
card_base64
,))
rsp
=
sock
.
readline
()
logging
.
debug
(
'authenticated'
)
sockf
.
write
(
"AUTHCARD %s
\n
"
%
(
card_base64
,));
sockf
.
flush
()
rsp
=
sockf
.
readline
()
if
not
"200"
in
rsp
:
raise
ValueError
,
"no UID found for card ID"
username
=
rsp
.
split
(
'='
)[
1
]
username
=
rsp
.
split
(
'='
)[
1
]
.
strip
()
# Check for thier username
try
:
# Get info from the system (by username)
info
=
pwd
.
getpwnam
(
username
)
except
KeyError
:
logging
.
info
(
'getting
p
in for u
id %d
: user not in password file'
%
uid
)
logging
.
info
(
'getting in
fo
for u
ser
\'
%s
\'
: user not in password file'
%
(
username
,)
)
return
False
else
:
# Get the users ID
...
...
@@ -100,7 +105,7 @@ class OpenDispense(DispenseInterface):
# Get info from the system (by UID)
info
=
pwd
.
getpwuid
(
self
.
_userid
)
except
KeyError
:
logging
.
info
(
'getting
p
in for uid %d: user not in password file'
%
uid
)
logging
.
info
(
'getting in
fo
for uid %d: user not in password file'
%
(
self
.
_userid
,)
)
return
False
# If we get this far all is good
...
...
@@ -118,14 +123,15 @@ class OpenDispense(DispenseInterface):
logging
.
info
(
'Enrolling card %s to uid %s (%s)'
%
(
cardId
,
self
.
_userId
,
self
.
_username
))
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
,
0
)
sock
.
connect
(
DISPENSE_ENDPOINT
)
sock
.
write
(
"AUTHIDENT
\n
"
)
rsp
=
sock
.
readline
()
sockf
=
sock
.
makefile
()
sockf
.
write
(
"AUTHIDENT
\n
"
)
sockf
.
flush
();
rsp
=
sockf
.
readline
()
assert
"200"
in
rsp
sock
.
write
(
"SETEUSER %s
\n
"
,
self
.
_username
)
rsp
=
sock
.
readline
()
sock
f
.
write
(
"SETEUSER %s
\n
"
,
self
.
_username
)
sockf
.
flush
();
rsp
=
sock
f
.
readline
()
assert
"200"
in
rsp
sock
.
write
(
"CARD_ADD %s
\n
"
,
card_base64
)
rsp
=
sock
.
readline
()
sock
f
.
write
(
"CARD_ADD %s
\n
"
,
card_base64
)
sockf
.
flush
();
rsp
=
sock
f
.
readline
()
if
"200"
in
rsp
:
return
True
else
:
...
...
@@ -154,6 +160,7 @@ class OpenDispense(DispenseInterface):
return
balance
def
getItemInfo
(
self
,
itemId
):
logging
.
debug
(
"getItemInfo(%s)"
%
(
itemId
,))
itemId
=
OpenDispenseMapping
.
vendingMachineToOpenDispense
(
itemId
)
args
=
(
'dispense'
,
'iteminfo'
,
itemId
)
info
,
unused
=
Popen
(
args
,
close_fds
=
True
,
stdout
=
PIPE
).
communicate
()
...
...
@@ -190,8 +197,20 @@ class OpenDispenseMapping():
@
staticmethod
def
vendingMachineToOpenDispense
(
itemId
):
logging
.
debug
(
"vendingMachineToOpenDispense(%s)"
%
(
itemId
,))
_mappingFile
=
"OpenDispenseMappings.conf"
fh
=
open
(
_mappingFile
)
try
:
fh
=
open
(
_mappingFile
)
except
IOError
:
if
itemId
[
1
]
==
'8'
:
return
'coke:'
+
itemId
[
0
]
elif
itemId
[
1
]
==
'5'
:
if
itemId
[
0
]
==
'5'
:
return
'door'
else
:
return
None
else
:
return
'snack:'
+
itemId
map
=
""
for
line
in
fh
:
#line = line.strip()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment