-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacs-cp.py
executable file
·100 lines (71 loc) · 2.62 KB
/
acs-cp.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
import bottle
from bottle import get, post, static_file, request, route, template
from bottle import SimpleTemplate
from configparser import ConfigParser
import os
from os import path
import ssl
from SOAPpy import SOAPProxy
@get('/')
def get_index():
return index_tpl()
@post('/')
def post_index():
form = request.forms.getunicode
def error(msg):
return index_tpl(username=form('username'), alerts=[('error', msg)])
if form('new-password') != form('confirm-password'):
return error("Password doesn't match the confirmation!")
if len(form('new-password')) < 6:
return error("Password must be at least 6 characters long!")
try:
change_password(form('username'), form('old-password'), form('new-password'))
except Error as e:
print("Unsuccessful attempt to change password for %s: %s" % (form('username'), e))
return error(str(e))
print("Password successfully changed for: %s" % form('username'))
return index_tpl(alerts=[('success', "Password has been changed")])
@route('/static/<filename>', name='static')
def serve_static(filename):
return static_file(filename, root=path.join(BASE_DIR, 'static'))
def change_password(*args):
# Get the ACS host / IP
host = CONF['acs']['host']
targetUrl = 'https://' + host + '/PI/services/UCP/'
server = SOAPProxy(targetUrl, 'UCP')
# Call the changeUserPassword with given input
try:
ans = server.changeUserPass(args[0],args[1],args[2])
except:
raise Error('Problems connecting to: %s' % host)
else:
# Password changing failed
if ans.status == 'failure':
raise Error('Username or Password is incorrect!')
# Print all failure reasons
for err in ans.errors:
raise Error(err)
else:
# Password was changed successfully
return 'Success'
def index_tpl(**kwargs):
return template('index', **kwargs)
def read_config():
config = ConfigParser()
config.read([path.join(BASE_DIR, 'settings.ini'), os.getenv('CONF_FILE', '')])
return config
class Error(Exception):
pass
BASE_DIR = path.dirname(__file__)
CONF = read_config()
bottle.TEMPLATE_PATH = [ BASE_DIR ]
# Set default attributes to pass into templates.
SimpleTemplate.defaults = dict(CONF['html'])
SimpleTemplate.defaults['url'] = bottle.url
# Run bottle internal server when invoked directly (mainly for development).
if __name__ == '__main__':
bottle.run(**CONF['server'])
# Run bottle in application mode (in production under uWSGI server).
else:
application = bottle.default_app()