-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallocatenumber.py
More file actions
executable file
·36 lines (30 loc) · 1.43 KB
/
allocatenumber.py
File metadata and controls
executable file
·36 lines (30 loc) · 1.43 KB
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
#!/usr/bin/env python
import cgi
import cgitb; cgitb.enable() # for troubleshooting
import subprocess
import random
import string
print "Content-type: application/json"
print
prefix_saycel = "999100"
prefix_saycel2 = "999200"
prefix_rhizo = "505051"
form = cgi.FieldStorage()
prefix = cgi.escape(form.getvalue("prefix", prefix_saycel))
email_address = cgi.escape(form.getvalue("email_address", ""))
if ";" in email_address:
print """{ "status" : "err", "msg" : "email address contains semicolon, not supported, sorry" }"""
exit()
if prefix != prefix_saycel and prefix != prefix_rhizo and prefix != prefix_saycel2:
print """{ "status" : "err", "msg" : "wrong prefix, must be 999100, 999200 or 505051" }"""
else:
for i in range(5):
suffix = ''.join(random.choice(string.digits) for _ in range(5))
username = prefix + suffix
pwd = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(8))
if subprocess.call(["/usr/sbin/kamctl", "add", username, pwd], stderr=subprocess.PIPE, stdout=subprocess.PIPE) == 0:
if email_address != "":
subprocess.call(["/usr/sbin/kamctl", "sets", username, "email_address", email_address], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
print """{ "status" : "ok", "msg" : "created user", "user" : "%s", "pwd" : "%s", "email_address" : "%s" }""" % (username, pwd, email_address)
exit()
print """{ "status" : "err", "msg" : "could not create user, sorry" }"""