from __future__ import unicode_literals

# Create your models here.
from django.db import models
#from httpserver.models import *

class FTPGroup(models.Model):
  id = models.IntegerField(db_column='id',primary_key=True)
  gid = models.IntegerField(db_column='gid')
  uid = models.IntegerField(db_column='uid')
  nomegruppo = models.CharField(db_column='nome',max_length=30)
  directory = models.CharField(db_column='directory',max_length=50)
  section = models.CharField(db_column='section',max_length=4)
  enabled = models.BooleanField(db_column='enabled')
  server = models.CharField(db_column='server',max_length=15)
  master = models.BooleanField(db_column='master') # usato per indicare dove scaricare le configurazioni
  
  l3 = models.BooleanField(db_column='l3')
  home = models.CharField(db_column='home',max_length=64)
  sub = models.CharField(db_column='sub',max_length=64)
  http_port = models.IntegerField(db_column='http_port')
  https_port = models.IntegerField(db_column='https_port')

  class Meta:
    db_table = 'ftp_home'
    managed = False

class FTPServer(models.Model):
  id = models.IntegerField(db_column='id',primary_key=True)
  nome = models.CharField(db_column='nome',max_length=20)
  ip = models.CharField(db_column='ip',max_length=15)
  enabled = models.BooleanField(db_column='enabled')

  class Meta:
    ordering = ['id']
    db_table = 'ftp_server'
    managed = False

class FTPUser(models.Model):
  id = models.IntegerField(db_column='id', primary_key=True)
  dominio = models.ForeignKey('domini.Domini',db_column='domain',on_delete=models.PROTECT)
  utente = models.CharField(db_column='user',max_length=64)
  nota = models.TextField(db_column='nota')
  crypt = models.CharField(db_column='crypt',max_length=50)
  clear = models.CharField(db_column='clear',max_length=50)
  homedir = models.CharField(db_column='homedir',max_length=255)
  ftpserver = models.ForeignKey('FTPServer',db_column='server',on_delete=models.PROTECT)
  access = models.DateField(db_column='access')
  modified = models.DateField(db_column='modified')
  enabled = models.BooleanField(db_column='enabled')
  password_update = models.DateField(db_column='password_update')
  password_change_enabled = models.BooleanField(db_column='password_change_enabled')
  account_expire = models.BooleanField(db_column='account_expire')
  account_creation = models.DateField(db_column='account_creation')
  tobedeleted = models.BooleanField(db_column='tobedeleted')
  quota = models.IntegerField(db_column='quota')
  ftpgroup = models.ForeignKey('FTPGroup',db_column='ftp_home',on_delete=models.PROTECT)
  last_ftp_checked = models.DateField(db_column='last_ftp_checked')
  mail = models.CharField(db_column='mail',max_length=128)
  #sezione relativa alle configurazioni di pubblicazione (proxy,http,spazio e cert.ssl) via mqtt
  #httpserver = models.ForeignKey('httpserver.HttpServer',db_column='httpserver',on_delete=models.PROTECT)
  spaziocfg = models.BooleanField(db_column='spaziocfg',default=False)
  proxycfg = models.BooleanField(db_column='proxycfg',default=False)
  httpcfg = models.BooleanField(db_column='httpcfg',default=False)
  sslcfg = models.BooleanField(db_column='sslcfg',default=False)
  proxysslcfg = models.BooleanField(db_column='proxysslcfg',default=False)
  httpsslcfg = models.BooleanField(db_column='httpsslcfg',default=False)
  edit = models.BooleanField(db_column='edit',default=False)
  class Meta:
    ordering = ['id']
    db_table = 'ftp_user'
    managed = False

