mirror of
https://github.com/retspen/webvirtcloud
synced 2025-03-31 03:56:45 +00:00
make console password optional for users with permissions
This commit is contained in:
parent
74a4a1a3ef
commit
44aa746f4b
8 changed files with 57 additions and 5 deletions
accounts
console/templates
instances
|
@ -24,6 +24,19 @@ def apply_change_password(sender, **kwargs):
|
||||||
user.user_permissions.remove(permission)
|
user.user_permissions.remove(permission)
|
||||||
print('\033[1mDon`t forget to remove the option from settings.py\033[0m')
|
print('\033[1mDon`t forget to remove the option from settings.py\033[0m')
|
||||||
|
|
||||||
|
def apply_passwordless_console(sender, **kwargs):
|
||||||
|
'''
|
||||||
|
Apply new passwordless_console permission for all users
|
||||||
|
'''
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.models import User, Permission
|
||||||
|
|
||||||
|
print('\033[92mApplying permission passwordless_console for all users\033[0m')
|
||||||
|
users = User.objects.all()
|
||||||
|
permission = Permission.objects.get(codename='passwordless_console')
|
||||||
|
for user in users:
|
||||||
|
user.user_permissions.add(permission)
|
||||||
|
|
||||||
|
|
||||||
def create_admin(sender, **kwargs):
|
def create_admin(sender, **kwargs):
|
||||||
'''
|
'''
|
||||||
|
@ -49,3 +62,4 @@ class AccountsConfig(AppConfig):
|
||||||
def ready(self):
|
def ready(self):
|
||||||
post_migrate.connect(apply_change_password, sender=self)
|
post_migrate.connect(apply_change_password, sender=self)
|
||||||
post_migrate.connect(create_admin, sender=self)
|
post_migrate.connect(create_admin, sender=self)
|
||||||
|
post_migrate.connect(apply_passwordless_console, sender=self)
|
||||||
|
|
|
@ -6,6 +6,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from instances.models import Instance
|
from instances.models import Instance
|
||||||
|
|
||||||
|
|
||||||
class UserInstanceManager(models.Manager):
|
class UserInstanceManager(models.Manager):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return super().get_queryset().select_related('instance', 'user')
|
return super().get_queryset().select_related('instance', 'user')
|
||||||
|
|
|
@ -199,7 +199,11 @@
|
||||||
<label for="port">{% trans 'Port' %}:</label>
|
<label for="port">{% trans 'Port' %}:</label>
|
||||||
<input type='text' id='port' value='{{ ws_port }}'>
|
<input type='text' id='port' value='{{ ws_port }}'>
|
||||||
<label for="password">{% trans 'Password' %}:</label>
|
<label for="password">{% trans 'Password' %}:</label>
|
||||||
<input type='password' id='password'>
|
{% if perms.instances.passwordless_console %}
|
||||||
|
<input type='password' id='password' value='{{ console_passwd }}'>
|
||||||
|
{% else %}
|
||||||
|
<input type='password' id='password'>
|
||||||
|
{% endif %}
|
||||||
<label for="show_console">{% trans 'Show console' %}</label>
|
<label for="show_console">{% trans 'Show console' %}</label>
|
||||||
<input type="checkbox" id="show_console" value="1" onchange="toggle_console()" checked>
|
<input type="checkbox" id="show_console" value="1" onchange="toggle_console()" checked>
|
||||||
<button id="connectButton">{% trans 'Start' %}</button>
|
<button id="connectButton">{% trans 'Start' %}</button>
|
||||||
|
|
|
@ -93,7 +93,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (password === undefined) {
|
if (password === undefined) {
|
||||||
password = spice_query_var('password', '');
|
{% if perms.instances.passwordless_console %}
|
||||||
|
password = '{{ console_passwd }}';
|
||||||
|
{% else %}
|
||||||
|
password = prompt('{% trans "Password" %}');
|
||||||
|
{% endif %}
|
||||||
//password = '{{ console_passwd | safe }}';
|
//password = '{{ console_passwd | safe }}';
|
||||||
}
|
}
|
||||||
if (password === 'None') password = '';
|
if (password === 'None') password = '';
|
||||||
|
|
|
@ -297,7 +297,11 @@
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<label>Password:</label>
|
<label>Password:</label>
|
||||||
<input id="noVNC_password_input" type="password" />
|
{% if perms.instances.passwordless_console %}
|
||||||
|
<input id="noVNC_password_input" type="password" value='{{ console_passwd }}' />
|
||||||
|
{% else %}
|
||||||
|
<input id="noVNC_password_input" type="password" />
|
||||||
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input id="noVNC_password_button" type="submit" value="Send Password" class="noVNC_submit" />
|
<input id="noVNC_password_button" type="submit" value="Send Password" class="noVNC_submit" />
|
||||||
|
|
|
@ -167,7 +167,13 @@
|
||||||
// By default, use the host and port of server that served this file
|
// By default, use the host and port of server that served this file
|
||||||
const host = readQueryVariable('host', '{{ ws_host }}');
|
const host = readQueryVariable('host', '{{ ws_host }}');
|
||||||
let port = readQueryVariable('port', '{{ ws_port }}');
|
let port = readQueryVariable('port', '{{ ws_port }}');
|
||||||
const password = readQueryVariable('password');
|
|
||||||
|
{% if perms.instances.passwordless_console %}
|
||||||
|
const password = '{{ console_passwd }}';
|
||||||
|
{% else %}
|
||||||
|
const password = readQueryVariable('password');
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
//const path = readQueryVariable('path', 'websockify');
|
//const path = readQueryVariable('path', 'websockify');
|
||||||
const path = readQueryVariable('path', '{{ ws_path }}');
|
const path = readQueryVariable('path', '{{ ws_path }}');
|
||||||
|
|
||||||
|
|
17
instances/migrations/0009_auto_20200717_0524.py
Normal file
17
instances/migrations/0009_auto_20200717_0524.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 2.2.13 on 2020-07-17 05:24
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('instances', '0008_auto_20200708_0950'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='permissionset',
|
||||||
|
options={'default_permissions': (), 'managed': False, 'permissions': [('clone_instances', 'Can clone instances'), ('passwordless_console', 'Can access console without password')]},
|
||||||
|
),
|
||||||
|
]
|
|
@ -211,6 +211,8 @@ class PermissionSet(models.Model):
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
default_permissions = ()
|
default_permissions = ()
|
||||||
permissions = (('clone_instances', _('Can clone instances')), )
|
permissions = [('clone_instances', 'Can clone instances'),
|
||||||
|
('passwordless_console', _('Can access console without password')),
|
||||||
|
]
|
||||||
|
|
||||||
managed = False
|
managed = False
|
||||||
|
|
Loading…
Add table
Reference in a new issue