diff --git a/.gitignore b/.gitignore index b3ebced..0772847 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,8 @@ venv .idea .DS_* *.pyc -db.sqlite3 -console/cert.pem +db.sqlite3* +console/cert.pem* tags dhcpd.* +webvirtcloud/settings.py diff --git a/README.md b/README.md index f1b3767..8ec15f5 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,23 @@ sudo service supervisor restart WebVirtCloud is a virtualization web interface for admins and users. It can delegate Virtual Machine's to users. A noVNC viewer presents a full graphical console to the guest domain. KVM is currently the only hypervisor supported. +### Generate secret key +You should generate SECRET_KEY after cloning repo. Then put it into webvirtcloud/settings.py. + +```python +import random, string +haystack = string.ascii_letters + string.digits + string.punctuation +print(''.join([random.SystemRandom().choice(haystack) for _ in range(50)])) +``` + ### Install WebVirtCloud panel (Ubuntu) ```bash sudo apt-get -y install git python-virtualenv python-dev libxml2-dev libvirt-dev zlib1g-dev nginx supervisor libsasl2-modules gcc pkg-config git clone https://github.com/retspen/webvirtcloud cd webvirtcloud +cp webvirtcloud/settings.py.template webvirtcloud/settings.py +# now put secret key to webvirtcloud/settings.py sudo cp conf/supervisor/webvirtcloud.conf /etc/supervisor/conf.d sudo cp conf/nginx/webvirtcloud.conf /etc/nginx/conf.d cd .. @@ -63,6 +74,8 @@ sudo yum -y install python-virtualenv python-devel libvirt-devel glibc gcc nginx ```bash sudo mkdir /srv && cd /srv sudo git clone https://github.com/retspen/webvirtcloud && cd webvirtcloud +cp webvirtcloud/settings.py.template webvirtcloud/settings.py +# now put secret key to webvirtcloud/settings.py ``` #### Start installation webvirtcloud diff --git a/accounts/backends.py b/accounts/backends.py index 77aa509..e66b94a 100644 --- a/accounts/backends.py +++ b/accounts/backends.py @@ -1,7 +1,13 @@ from django.contrib.auth.backends import RemoteUserBackend +from accounts.models import UserInstance, UserAttributes +from instances.models import Instance class MyRemoteUserBackend(RemoteUserBackend): + + #create_unknown_user = True + def configure_user(self, user): - user.is_superuser = True + #user.is_superuser = True + UserAttributes.configure_user(user) return user diff --git a/accounts/migrations/0009_auto_20171026_0805.py b/accounts/migrations/0009_auto_20171026_0805.py new file mode 100644 index 0000000..7d035c7 --- /dev/null +++ b/accounts/migrations/0009_auto_20171026_0805.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0008_merge'), + ] + + operations = [ + migrations.AlterField( + model_name='userattributes', + name='can_clone_instances', + field=models.BooleanField(default=True), + ), + ] diff --git a/accounts/models.py b/accounts/models.py index 06fefee..19e3a20 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -1,5 +1,6 @@ from django.db import models from django.contrib.auth.models import User +from django.conf import settings from instances.models import Instance @@ -24,11 +25,33 @@ class UserSSHKey(models.Model): class UserAttributes(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) - can_clone_instances = models.BooleanField(default=False) + can_clone_instances = models.BooleanField(default=True) max_instances = models.IntegerField(default=1) max_cpus = models.IntegerField(default=1) max_memory = models.IntegerField(default=2048) max_disk_size = models.IntegerField(default=20) + @staticmethod + def create_missing_userattributes(user): + try: + userattributes = user.userattributes + except UserAttributes.DoesNotExist: + userattributes = UserAttributes(user=user) + userattributes.save() + + @staticmethod + def add_default_instances(user): + existing_instances = UserInstance.objects.filter(user=user) + if not existing_instances: + for instance_name in settings.NEW_USER_DEFAULT_INSTANCES: + instance = Instance.objects.get(name=instance_name) + user_instance = UserInstance(user=user, instance=instance) + user_instance.save() + + @staticmethod + def configure_user(user): + UserAttributes.create_missing_userattributes(user) + UserAttributes.add_default_instances(user) + def __unicode__(self): return self.user.username diff --git a/accounts/templates/account.html b/accounts/templates/account.html index c8d8c19..0b39978 100644 --- a/accounts/templates/account.html +++ b/accounts/templates/account.html @@ -13,6 +13,31 @@ {% include 'errors_block.html' %} + {% if request.user.is_superuser and publickeys %} +
{% trans "Key name" %} | +{% trans "Public key" %} | +
---|---|
{{ publickey.keyname }} | +{{ publickey.keypublic|truncatechars:64 }} | +