6 changed files with 152 additions and 2 deletions
@ -0,0 +1,32 @@ |
|||||
|
# Generated by Django 2.0.1 on 2018-01-14 18:04 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
import django.db.models.deletion |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
initial = True |
||||
|
|
||||
|
dependencies = [ |
||||
|
('auth', '0009_alter_user_last_name_max_length'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.CreateModel( |
||||
|
name='Category', |
||||
|
fields=[ |
||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
|
('Nom de la catégorie', models.CharField(max_length=255)), |
||||
|
], |
||||
|
), |
||||
|
migrations.CreateModel( |
||||
|
name='Content', |
||||
|
fields=[ |
||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
|
('Nom du contenu', models.CharField(max_length=255)), |
||||
|
('URL du contenu', models.URLField(editable=False)), |
||||
|
('group_owner', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, to='auth.Group')), |
||||
|
], |
||||
|
), |
||||
|
] |
||||
@ -1,3 +1,25 @@ |
|||||
from django.db import models |
from django.db import models |
||||
|
from django.contrib.auth.models import Group |
||||
|
|
||||
# Create your models here. |
|
||||
|
class Category(models.Model): |
||||
|
name = models.CharField( |
||||
|
max_length=255, |
||||
|
name="Nom de la catégorie" |
||||
|
) |
||||
|
|
||||
|
|
||||
|
class Content(models.Model): |
||||
|
name = models.CharField( |
||||
|
max_length=255, |
||||
|
name="Nom du contenu" |
||||
|
) |
||||
|
group_owner = models.ForeignKey( |
||||
|
Group, |
||||
|
on_delete=models.CASCADE, |
||||
|
editable=False, |
||||
|
) |
||||
|
content_url = models.URLField( |
||||
|
name='URL du contenu', |
||||
|
editable=False, |
||||
|
) |
||||
|
|||||
@ -0,0 +1,32 @@ |
|||||
|
# Generated by Django 2.0.1 on 2018-01-14 18:04 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
import settings.models |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
initial = True |
||||
|
|
||||
|
dependencies = [ |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.CreateModel( |
||||
|
name='ContentSettings', |
||||
|
fields=[ |
||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
|
('URL du FTP', models.URLField(max_length=255)), |
||||
|
('Identifiant sur le FTP', models.CharField(max_length=255)), |
||||
|
('Mot de passe', settings.models.AESEncryptedField(max_length=255)), |
||||
|
], |
||||
|
), |
||||
|
migrations.CreateModel( |
||||
|
name='SiteSettings', |
||||
|
fields=[ |
||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
|
('allow_upload', models.BooleanField(help_text="Autoriser l'upload de vidéos.")), |
||||
|
('site_name', models.CharField(help_text='Nom du site', max_length=255)), |
||||
|
], |
||||
|
), |
||||
|
] |
||||
@ -1,3 +1,39 @@ |
|||||
from django.db import models |
from django.db import models |
||||
|
import binascii |
||||
|
import site_tps.qaes |
||||
|
from django.conf import settings |
||||
|
|
||||
# Create your models here. |
|
||||
|
class AESEncryptedField(models.CharField): |
||||
|
def save_form_data(self, instance, data): |
||||
|
setattr(instance, self.name, |
||||
|
binascii.b2a_base64(qaes.encrypt(settings.AES_KEY, data))) |
||||
|
|
||||
|
def value_from_object(self, obj): |
||||
|
return qaes.decrypt(settings.AES_KEY, |
||||
|
binascii.a2b_base64(getattr(obj, self.attname))) |
||||
|
|
||||
|
|
||||
|
class ContentSettings(models.Model): |
||||
|
ftp_url = models.URLField( |
||||
|
max_length=255, |
||||
|
name="URL du FTP", |
||||
|
) |
||||
|
ftp_id = models.CharField( |
||||
|
max_length=255, |
||||
|
name="Identifiant sur le FTP", |
||||
|
) |
||||
|
ftp_pass = AESEncryptedField( |
||||
|
max_length=255, |
||||
|
name="Mot de passe" |
||||
|
) |
||||
|
|
||||
|
|
||||
|
class SiteSettings(models.Model): |
||||
|
allow_upload = models.BooleanField( |
||||
|
help_text="Autoriser l'upload de vidéos." |
||||
|
) |
||||
|
site_name = models.CharField( |
||||
|
max_length=255, |
||||
|
help_text="Nom du site", |
||||
|
) |
||||
|
|||||
@ -0,0 +1,26 @@ |
|||||
|
import string |
||||
|
from random import choice |
||||
|
from Crypto.Cipher import AES |
||||
|
|
||||
|
EOD = '`%EofD%`' # This should be something that will not occur in strings |
||||
|
|
||||
|
|
||||
|
def genstring(length=16, chars=string.printable): |
||||
|
return ''.join([choice(chars) for i in range(length)]) |
||||
|
|
||||
|
|
||||
|
def encrypt(key, s): |
||||
|
obj = AES.new(key) |
||||
|
datalength = len(s) + len(EOD) |
||||
|
if datalength < 16: |
||||
|
saltlength = 16 - datalength |
||||
|
else: |
||||
|
saltlength = 16 - datalength % 16 |
||||
|
ss = ''.join([s, EOD, genstring(saltlength)]) |
||||
|
return obj.encrypt(ss) |
||||
|
|
||||
|
|
||||
|
def decrypt(key, s): |
||||
|
obj = AES.new(key) |
||||
|
ss = obj.decrypt(s) |
||||
|
return ss.split(EOD)[0] |
||||
Loading…
Reference in new issue