Ejemplo n.º 1
0
class Server(BaseModel):
    name = pw.TextField(primary_key=True)
    ip = pw.IPField()

    class Meta:
        table_name = 'servers'

    @property
    def serialize(self):
        data = {'name': self.name, 'ip': self.ip}
        return data

    @classmethod
    def get_server(cls, server_name):
        try:
            server = (Server.select().where(Server.name == server_name).get())
            return server.serialize
        except DoesNotExist:
            return None

    @classmethod
    def add_server(cls, server_props):
        cls.insert(server_props).execute()
        return server_props

    @classmethod
    def update_server(cls, server_update):
        server_name = server_update.get('name')
        try:
            (Server.update(ip=server_update.get('ip')).where(
                Server.name == server_name).execute())
            return True
        except DoesNotExist:
            return False

    @classmethod
    def delete_server(cls, server_name):
        try:
            (Server.delete().where(Server.name == server_name).execute())
            return True
        except DoesNotExist:
            return False
Ejemplo n.º 2
0
    class Server(pw.Model):
        name = pw.TextField(primary_key=True)
        ip = pw.IPField()

        class Meta:
            table_name = "servers"
Ejemplo n.º 3
0
class ListItem(BaseModel):
    ip = peewee.IPField(unique=True)
Ejemplo n.º 4
0
class User(peewee.Model):
    class Meta:
        database = portal_db

    # ident-related fields
    hw_addr = peewee.CharField(primary_key=True)
    ip_addr = peewee.IPField()

    # metadata
    platform = peewee.CharField(null=True)
    system = peewee.CharField(null=True)
    system_version = peewee.FloatField(null=True)
    browser = peewee.CharField(null=True)
    browser_version = peewee.FloatField(null=True)
    language = peewee.CharField(null=True)

    # registration-related fields
    last_seen_on = peewee.DateTimeField(default=datetime.datetime.now)
    registered_on = peewee.DateTimeField(null=True)

    @property
    def is_registered(self):
        """ """
        if not self.registered_on:
            return False
        now = datetime.datetime.now()
        return (
            now > self.registered_on and
            (now - self.registered_on).total_seconds() < REGISTRATION_TIMEOUT)

    @property
    def is_being_registered(self):
        """ has started but not completed registration process """
        if not self.registered_on:
            return False
        now = datetime.datetime.now()
        return self.registered_on > now

    @property
    def is_active(self):
        return is_active(self.ip_addr)

    @property
    def is_apple(self):
        return self.platform in ("macos", "iphone", "ipad")

    @property
    def is_recent_android(self):
        if self.system == "Android" and self.system_version >= 7:
            return True
        if self.platform == "linux" and self.browser == "chrome":
            return True
        return False

    def register(self, delay=0):
        self.registered_on = datetime.datetime.now() + datetime.timedelta(
            seconds=delay)
        self.save()

    @classmethod
    def create_or_update(cls, hw_addr, ip_addr, extras):
        now = datetime.datetime.now()
        data = {"ip_addr": ip_addr, "last_seen_on": now}
        user, created = cls.get_or_create(hw_addr=hw_addr, defaults=data)
        extras.update(data)
        for key, value in extras.items():
            if hasattr(user, key):
                setattr(user, key, value)
        user.save()
        return user
Ejemplo n.º 5
0
class IP_Location(pw.Model):
    ip = pw.IPField(primary_key=True)
    location = pw.TextField()

    class Meta:
        database = ip_cache
Ejemplo n.º 6
0
class AccessRequests(BaseModel):
    timestamp = pw.DateTimeField(null=False)
    srcip = pw.IPField(null=False)
    token = pw.ForeignKeyField(Tokens, backref='accessrequests')