Created
December 11, 2017 15:06
-
-
Save bkram/ae31b9f8581ddbc335f9e7a49041735c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import subprocess | |
import cherrypy | |
config = { | |
'global': { | |
'server.socket_host': '0.0.0.0', | |
'server.socket_port': 8080, | |
'server.thread_pool': 8, | |
# 'server.ssl_module' : 'pyopenssl', | |
# 'server.ssl_certificate' : '/path/to/certs/domain.com.crt', | |
# 'server.ssl_certificate_chain' : '/path/to/certs/ssl123_ca_bundle.pem', | |
# 'server.ssl_private_key' : '/path/to/certs/domain.com.key', | |
} | |
} | |
def smbpass(username, password): | |
proc = subprocess.Popen( | |
['smbpasswd', '-a', '-s', username], stdin=subprocess.PIPE) | |
proc.communicate(input=password + '\n' + password + '\n') | |
class PassSyncer(object): | |
@cherrypy.expose | |
def index(self): | |
return """<html> | |
<head><link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body> | |
<center> | |
<h1>Samba Password Sync</h1> | |
Please enter your LDAP credentials to sync your password.<br><br> | |
<form class="pure-form-aligned" method="post" action="syncpassword"> | |
<div class="pure-control-group"> | |
<input id="username" name="username" type="text" placeholder="Username"> | |
</div> | |
<div class="pure-control-group"> | |
<input name="password" id="password" type="password" placeholder="Password"> | |
</div> | |
<div class="pure-controls-group"> | |
<button type="submit" class="pure-button pure-button-primary">Sync my password !</button> | |
</div> | |
</form> | |
</center> | |
</body> | |
</html>""" | |
@cherrypy.expose | |
def syncpassword(self, username=None, password=None): | |
if username and password: | |
smbpass(username, password) | |
return """<html> | |
<head><link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body> | |
<center> | |
<h1>Samba Password Sync</h1> | |
Your LDAP password has been synced to the local Samba password database. | |
<center> | |
</body> | |
</html>""" | |
else: | |
raise cherrypy.HTTPRedirect('/') | |
if __name__ == '__main__': | |
cherrypy.quickstart(PassSyncer(), '/', config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment