diff --git a/dev/gstfsd b/dev/gstfsd new file mode 100755 index 0000000..008223c --- /dev/null +++ b/dev/gstfsd @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +import SocketServer +import json +import guestfs +import re + + +PORT = 16510 +ADDRESS = "0.0.0.0" + + +class MyTCPServer(SocketServer.ThreadingTCPServer): + allow_reuse_address = True + + +class MyTCPServerHandler(SocketServer.BaseRequestHandler): + def handle(self): + try: + # recive data + data = json.loads(self.request.recv(1024).strip()) + dom_name = data['vname'] + passwd_hash = data['passwd'] + + # GuestFS + gfs = guestfs.GuestFS (python_return_dict=True) + try: + gfs.add_domain(dom_name) + gfs.launch() + parts = gfs.list_partitions() + for part in parts: + try: + gfs.mount(part, '/') + if gfs.is_file('/etc/shadow'): + file_shadow = gfs.cat('/etc/shadow') + new_root_hash = "root:" + passwd_hash + ":" + file_shadow_new = re.sub('^root:.*?:', new_root_hash, file_shadow) + gfs.write("/etc/shadow", file_shadow_new) + gfs.chmod('640', '/etc/shadow') + gfs.umount(part) + self.request.sendall(json.dumps({'return':'success'})) + except RuntimeError: + pass + gfs.shutdown() + gfs.close() + except RuntimeError, err: + self.request.sendall(json.dumps({'return': 'error', 'message': err.message})) + + except Exception, e: + print "Exception wile receiving message: ", e + +server = MyTCPServer((ADDRESS, PORT), MyTCPServerHandler) +server.serve_forever() diff --git a/instances/templates/instance.html b/instances/templates/instance.html index c9811b1..6c82eb5 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -39,6 +39,8 @@ {% include 'errors_block.html' %} + {% include 'messages_block.html' %} +
{% trans "You need shut down your instance and enter a new root password." %}
+ + +