-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.py
executable file
·47 lines (40 loc) · 1.23 KB
/
service.py
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
#!/usr/bin/env python3
from bottle import route, error, run, template, request, response, abort
import simplepam, getent, os, sys
@route('/user/<name>/authenticate', method='POST')
def authenticate(name):
print("Authenticating",name, end=" ")
data = request.json
if not data:
print("FAIL (no password)")
abort(401, "Unable to authenticate: no password given.")
elif simplepam.authenticate(name, request.json['password']):
print("OK")
return None
print("FAIL (wrong password)")
abort(401, "Unable to authenticate.")
@route('/user/<name>', method='GET')
def user_info(name):
print("Getting User details for",name )
user = getent.passwd(name);
if user:
print(dict(user))
return dict(user)
print("User not found")
abort(404, "User not found.");
@error(404)
def error404(error):
return ""
@error(401)
def error404(error):
return ""
if __name__ == "__main__":
open('reg-service.pid','w').write(str(os.getpid()))
if len(sys.argv) == 3:
address = sys.argv[1]
port = int(sys.argv[2])
else:
address = "localhost"
port=3023
run(host=address, port=port, reloader=False, server='cherrypy')
os.remove('reg-service.pid')