mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 15:45:23 +00:00
Added function for public key to gstfsd
This commit is contained in:
parent
2d1f72a7e1
commit
0408e1d9cd
4 changed files with 73 additions and 10 deletions
|
@ -29,13 +29,21 @@ class MyTCPServerHandler(SocketServer.BaseRequestHandler):
|
|||
try:
|
||||
gfs.mount(part, '/')
|
||||
if gfs.is_file('/etc/shadow'):
|
||||
file_shadow = gfs.cat('/etc/shadow')
|
||||
new_root_hash = "root:" + data['passwd'] + ":"
|
||||
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'}))
|
||||
if data['action'] == 'password':
|
||||
file_shadow = gfs.cat('/etc/shadow')
|
||||
new_root_hash = "root:" + data['passwd'] + ":"
|
||||
file_shadow_new = re.sub('^root:.*?:', new_root_hash, file_shadow)
|
||||
gfs.write('/etc/shadow', file_shadow_new)
|
||||
gfs.chmod(640, '/etc/shadow')
|
||||
self.request.sendall(json.dumps({'return': 'success'}))
|
||||
if data['action'] == 'publickey':
|
||||
if not gfs.is_dir('/root/.ssh'):
|
||||
gfs.mkdir ('/root/.ssh')
|
||||
gfs.chmod(0700, "/root/.ssh")
|
||||
gfs.write('/root/.ssh/authorized_keys', data['key'])
|
||||
gfs.chmod(0600, '/root/.ssh/authorized_keys')
|
||||
self.request.sendall(json.dumps({'return': 'success'}))
|
||||
gfs.umount(part)
|
||||
except RuntimeError:
|
||||
pass
|
||||
gfs.shutdown()
|
||||
|
|
|
@ -222,6 +222,11 @@
|
|||
{% trans "Root Password" %}
|
||||
</a>
|
||||
</li>
|
||||
<li role="presentation">
|
||||
<a href="#sshkeys" aria-controls="sshkeys" role="tab" data-toggle="tab">
|
||||
{% trans "SSH Keys" %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
|
@ -250,6 +255,30 @@
|
|||
</form>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="sshkeys">
|
||||
<p>{% trans "You need shut down your instance and choose your public key." %}</p>
|
||||
<form class="form-inline" method="post" role="form">{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
<select name="sshkeyid" class="form-control keyselect">
|
||||
{% if publickeys %}
|
||||
{% for key in publickeys %}
|
||||
<option value="{{ key.id }}">{{ key.keyname }}</option>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<option value="None">{% trans "None" %}</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{% ifequal status 5 %}
|
||||
<input type="submit" class="btn btn-lg btn-success pull-right" name="addpublickey" value="{% trans "Add Public Key" %}">
|
||||
{% else %}
|
||||
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Add Public Key" %}</button>
|
||||
{% endifequal %}
|
||||
</form>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -11,7 +11,7 @@ from django.shortcuts import render, get_object_or_404
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
from computes.models import Compute
|
||||
from instances.models import Instance
|
||||
from accounts.models import UserInstance
|
||||
from accounts.models import UserInstance, UserSSHKey
|
||||
from vrtManager.hostdetails import wvmHostDetails
|
||||
from vrtManager.instance import wvmInstance, wvmInstances
|
||||
from vrtManager.connection import connection_manager
|
||||
|
@ -139,6 +139,7 @@ def instance(request, compute_id, vname):
|
|||
compute = get_object_or_404(Compute, pk=compute_id)
|
||||
computes = Compute.objects.all()
|
||||
computes_count = len(computes)
|
||||
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
|
||||
keymaps = QEMU_KEYMAPS
|
||||
console_types = QEMU_CONSOLE_TYPES
|
||||
try:
|
||||
|
@ -265,9 +266,8 @@ def instance(request, compute_id, vname):
|
|||
|
||||
if 'rootpasswd' in request.POST:
|
||||
passwd = request.POST.get('passwd', '')
|
||||
|
||||
passwd_hash = crypt.crypt(passwd, '$6$kgPoiREy')
|
||||
data = {'passwd': passwd_hash, 'vname': vname}
|
||||
data = {'action': 'password', 'passwd': passwd_hash, 'vname': vname}
|
||||
|
||||
if conn.get_status() == 5:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
@ -286,6 +286,28 @@ def instance(request, compute_id, vname):
|
|||
msg = _("Please shutdow down your instance and then try again")
|
||||
error_messages.append(msg)
|
||||
|
||||
if 'addpublickey' in request.POST:
|
||||
sshkeyid = request.POST.get('sshkeyid', '')
|
||||
publickey = UserSSHKey.objects.get(id=sshkeyid)
|
||||
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 result['return'] == 'success':
|
||||
messages.append(msg)
|
||||
else:
|
||||
error_messages.append(msg)
|
||||
else:
|
||||
msg = _("Please shutdow down your instance and then try again")
|
||||
error_messages.append(msg)
|
||||
|
||||
if 'resize' in request.POST:
|
||||
vcpu = request.POST.get('vcpu', '')
|
||||
cur_vcpu = request.POST.get('cur_vcpu', '')
|
||||
|
|
|
@ -129,3 +129,7 @@ p {
|
|||
border-width: 0 0 0 1em;
|
||||
padding: 0 0.3em;
|
||||
}
|
||||
.keyselect {
|
||||
display: inline;
|
||||
min-width: 250px;
|
||||
}
|
Loading…
Reference in a new issue