diff --git a/doorlockd-new/doorlockd.py b/doorlockd-new/doorlockd.py index aa09606..5f515e4 100755 --- a/doorlockd-new/doorlockd.py +++ b/doorlockd-new/doorlockd.py @@ -315,6 +315,42 @@ def home(): authentication_form = AuthenticationForm() response = None + # detect old API if the 'api' POST variable is set. + # NOTE: THESE BITS WILL BE REMOVED ONCE EVERYONE UPDATED THEIR APP + if request.method == 'POST' and request.form.get('api'): + log.info('Deprecated API usage detected') + user = request.form.get('user') + password = request.form.get('pass') + command = request.form.get('command') + + if any(v is None for v in [user, password, command]): + log.warning('Incomplete deprecated API request') + abort(400) + + desired_state = DoorState.Close + if command == 'unlock': + desired_state = DoorState.Open + credentials = AuthMethod.LDAP_USER_PW, user, password + + log.info('Incoming request from %s' % user.encode('utf-8')) + log.info(' desired state: %s' % desired_state) + log.info(' current state: %s' % logic.state) + log.info(' -> Knock knock, %s, please update your app!' % user) + + response = logic.request(desired_state, credentials) + if response == LogicResponse.Success: + return '0' + elif response == LogicResponse.Perm: + return '7' + elif response == LogicResponse.AlreadyLocked: + return '3' + elif response == LogicResponse.AlreadyOpen: + return '2' + elif response == LogicResponse.LDAP: + return '10' + else: + return '1' # Fail-mode + if request.method == 'POST' and authentication_form.validate(): user = authentication_form.username.data password = authentication_form.password.data @@ -327,8 +363,8 @@ def home(): response = logic.request(desired_state, credentials) log.info(' response: %s' % response) - # Don't trust python, zero credentials - user = password = credentials = None + # Don't trust python, zero credentials + user = password = credentials = None return render_template('index.html', authentication_form=authentication_form,