You've already forked directdnsonly
Initial project commit
This commit is contained in:
0
src/lib/__init__.py
Normal file
0
src/lib/__init__.py
Normal file
18
src/lib/common/__init__.py
Normal file
18
src/lib/common/__init__.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import random
|
||||
import string
|
||||
import lib.db.models
|
||||
|
||||
|
||||
def check_if_super_user_exists(session):
|
||||
exists = session.query(session.query(lib.db.models.Key).filter_by(name='super').exists()).scalar()
|
||||
return exists
|
||||
|
||||
|
||||
def check_if_domain_exists(session):
|
||||
pass
|
||||
|
||||
|
||||
def get_random_string(length):
|
||||
letters_and_digits = string.ascii_letters + string.digits
|
||||
result_str = ''.join(random.choice(letters_and_digits) for i in range(length))
|
||||
return result_str
|
||||
15
src/lib/db/__init__.py
Normal file
15
src/lib/db/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
import datetime
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
def connect():
|
||||
# Start SQLite engine
|
||||
engine = create_engine('sqlite:///./config/keys.db', connect_args={'check_same_thread': False})
|
||||
Base.metadata.create_all(engine)
|
||||
Session = sessionmaker(bind=engine)
|
||||
session = Session()
|
||||
return session
|
||||
28
src/lib/db/models/__init__.py
Normal file
28
src/lib/db/models/__init__.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from lib.db import Base
|
||||
from sqlalchemy import Column, Integer, String, DateTime
|
||||
|
||||
|
||||
class Key(Base):
|
||||
__tablename__ = "keys"
|
||||
id = Column(Integer, primary_key=True)
|
||||
key = Column(String, unique=True)
|
||||
name = Column(String)
|
||||
expires = Column(DateTime)
|
||||
service = Column(String)
|
||||
|
||||
def __repr__(self):
|
||||
return "<Key(key='%s', name='%s', expires='%s', service='%s')>" % (
|
||||
self.key, self.name, self.expires, self.service)
|
||||
|
||||
|
||||
class Domain(Base):
|
||||
__tablename__ = "domains"
|
||||
id = Column(Integer, primary_key=True)
|
||||
domain = Column(String, unique=True)
|
||||
hostname = Column(String)
|
||||
username = Column(String)
|
||||
|
||||
def __repr__(self):
|
||||
return "<Domain(id='%s', domain='%s', hostname='%s', username='%s')>" % (
|
||||
self.id, self.domain, self.hostname, self.username
|
||||
)
|
||||
Reference in New Issue
Block a user