mirror of
https://github.com/retspen/webvirtcloud
synced 2026-03-23 11:04:49 +00:00
Merge 748c167def into aa2a996e3f
This commit is contained in:
commit
72d57ebc21
10 changed files with 245 additions and 33 deletions
|
|
@ -5,6 +5,7 @@ import crypt
|
|||
from string import letters, digits
|
||||
from random import choice
|
||||
from bisect import insort
|
||||
from jwcrypto import jws, jwk, jwe
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
|
|
@ -288,21 +289,34 @@ def instance(request, compute_id, vname):
|
|||
|
||||
if 'rootpasswd' in request.POST:
|
||||
passwd = request.POST.get('passwd', '')
|
||||
passwd_hash = crypt.crypt(passwd, '$6$kgPoiREy')
|
||||
if passwd:
|
||||
passwd_hash = crypt.crypt(passwd, '$6$%s' % ''.join([choice(letters + digits) for i in xrange(8)]))
|
||||
# if password is empty, disable the root password
|
||||
else:
|
||||
passwd_hash = "*"
|
||||
data = {'action': 'password', 'passwd': passwd_hash, 'vname': vname}
|
||||
|
||||
if conn.get_status() == 5:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((compute.hostname, 16510))
|
||||
s.send(json.dumps(data))
|
||||
result = json.loads(s.recv(1024))
|
||||
s.close()
|
||||
msg = _("Reset root password")
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
if compute.gstfsd_key:
|
||||
key = jwk.JWK(**json.loads(compute.gstfsd_key.strip()))
|
||||
data = jwe.JWE(json.dumps(data), algs=["A256KW", "A256CBC-HS512"])
|
||||
data.add_recipient(key, header='{"alg":"A256KW","enc":"A256CBC-HS512"}')
|
||||
data = jws.JWS(data.serialize())
|
||||
data.add_signature(key, alg="HS512")
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((compute.hostname, 16510))
|
||||
s.send(data.serialize())
|
||||
result = json.loads(s.recv(4096))
|
||||
s.close()
|
||||
msg = _("Reset root password")
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
|
||||
if result['return'] == 'success':
|
||||
messages.append(msg)
|
||||
if result['return'] == 'success':
|
||||
messages.append(msg)
|
||||
else:
|
||||
error_messages.append(result.get('message', msg))
|
||||
else:
|
||||
msg = _("Please import the gstfsd key into this compute. It is in /var/lib/gstfsd/SECRET on %s") % compute.name
|
||||
error_messages.append(msg)
|
||||
else:
|
||||
msg = _("Please shutdow down your instance and then try again")
|
||||
|
|
@ -314,17 +328,26 @@ def instance(request, compute_id, vname):
|
|||
data = {'action': 'publickey', 'key': publickey.keypublic, 'vname': vname}
|
||||
|
||||
if conn.get_status() == 5:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((compute.hostname, 16510))
|
||||
s.send(json.dumps(data))
|
||||
result = json.loads(s.recv(1024))
|
||||
s.close()
|
||||
msg = _("Installed new ssh public key %s" % publickey.keyname)
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
if compute.gstfsd_key:
|
||||
key = jwk.JWK(**json.loads(compute.gstfsd_key.strip()))
|
||||
data = jwe.JWE(json.dumps(data), algs=["A256KW", "A256CBC-HS512"])
|
||||
data.add_recipient(key, header='{"alg":"A256KW","enc":"A256CBC-HS512"}')
|
||||
data = jws.JWS(data.serialize())
|
||||
data.add_signature(key, alg="HS512")
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((compute.hostname, 16510))
|
||||
s.send(data.serialize())
|
||||
result = json.loads(s.recv(4096))
|
||||
s.close()
|
||||
msg = _("Installed new ssh public key %s" % publickey.keyname)
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
|
||||
if result['return'] == 'success':
|
||||
messages.append(msg)
|
||||
if result['return'] == 'success':
|
||||
messages.append(msg)
|
||||
else:
|
||||
error_messages.append(result.get('message', msg))
|
||||
else:
|
||||
msg = _("Please import the gstfsd key into this compute. It is in /var/lib/gstfsd/SECRET on %s") % compute.name
|
||||
error_messages.append(msg)
|
||||
else:
|
||||
msg = _("Please shutdow down your instance and then try again")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue