-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
45 lines (40 loc) · 1.56 KB
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import os
from sqlalchemy import Column, Integer, String, PrimaryKeyConstraint, null
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
import random
import configparser
if os.environ.get('DEV'):
engine = create_engine('sqlite:///test.db', echo=True)
Base = declarative_base()
else:
Config = configparser.ConfigParser()
Config.read("config.ini")
user = Config.get("connection", "user")
password = Config.get("connection", "password")
host = Config.get("connection", "host")
db = Config.get("connection", "db")
engine = create_engine('mysql+pymysql://%s:%s@%s/%s' % (user, password, host, db))
Base = declarative_base()
class User(Base):
__tablename__ = 'vpnusers'
vpn_id = Column(Integer, primary_key=True)
vpn_username = Column(String(255), nullable=False, unique=True, default = 'pass')
pass_hash = Column(String(20), nullable=False, default = 0)
pin = Column(String(255), nullable=True, default=null())
skip_2fa = Column(Integer, nullable=False, default=0)
one_time_code = Column(String(21), nullable=True, default = 0)
primary = PrimaryKeyConstraint('vpn_id', name = "id_idx")
def __repr__(self):
return "<User(name='%s', pin='%s')>" % (self.vpn_username, self.pin)
def generateNewReserveCodes():
res = list()
for r in range(0,3):
code = ""
c = list()
for n in range(0,6):
c.append(random.randint(0,9))
code = ''.join([str(elem) for elem in c])
res.append(code)
return res