86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
import configparser
|
|
from modules.track.logging import log
|
|
|
|
path = "data/config.ini"
|
|
|
|
def create():
|
|
try:
|
|
file = open(path, 'r')
|
|
log("INFO", "Config already exists")
|
|
return
|
|
except FileNotFoundError as e:
|
|
log("INFO", "Creating config file")
|
|
pass
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.add_section('authorisation')
|
|
# change this to a randomly generated string
|
|
config.set('authorisation', 'AdminKey', 'secret')
|
|
config.set('authorisation', 'RegistrationKey', 'secret')
|
|
config.set('authorisation', 'UsernameMaxLength', '20')
|
|
config.set('authorisation', 'UsernameMinLength', '5')
|
|
config.set('authorisation', 'PasswordMaxLength', '30')
|
|
config.set('authorisation', 'PasswordMinLength', '5')
|
|
config.set('authorisation', 'TokenExpiryTime', '2592000')
|
|
|
|
config.add_section('database')
|
|
config.set('database', 'Path', 'data/database.db')
|
|
config.set('database', 'Encrypt', 'false')
|
|
config.set('database', 'ShamirSecretSharing', 'false')
|
|
config.set('database', 'NumberOfShares', '5')
|
|
config.set('database', 'MinimumShares', '3')
|
|
config.set('database', 'KeyPath', 'data/key.txt')
|
|
config.set('database', 'EncryptedPath', 'data/.cryptdatabase.db')
|
|
config.set('database', 'EncryptionConfigPath', 'data/encryptconfig.txt')
|
|
config.set('database', 'SaltPath', 'data/.salt.txt')
|
|
config.set('database', 'SharesPath', 'data/shares/')
|
|
|
|
config.add_section('user')
|
|
config.set('user', 'DefaultLevel', 'member')
|
|
config.set('user', 'DefaultOccupationID', 'Null')
|
|
|
|
config.add_section('posts')
|
|
config.set('posts', 'PostTimeLimit', '5') # miniutes
|
|
config.set('posts', 'DayStart', '9') #24 hour time
|
|
config.set('posts', 'DayEnd', '17') #24 hour time
|
|
|
|
config.add_section('notifications')
|
|
config.set('notifications', 'DefaultExpireTime', '604800')
|
|
config.set('notifications', 'ntfyUrl', 'https://ntfy.example.com')
|
|
|
|
config.add_section('networking')
|
|
config.set('networking', 'Port', '9999')
|
|
|
|
config.add_section('miscellaneous')
|
|
config.set('miscellaneous', 'ServerCode', '12345')
|
|
|
|
with open(path, 'w') as configfile:
|
|
config.write(configfile)
|
|
log("INFO", "Created config file")
|
|
|
|
def read(section, key, *args, **kwargs):
|
|
config = configparser.ConfigParser()
|
|
config.read(path)
|
|
|
|
if section not in config:
|
|
return None
|
|
if key not in config[section]:
|
|
return None
|
|
|
|
info = config[section][key]
|
|
if info == "false":
|
|
info = False
|
|
if info == "true":
|
|
info = True
|
|
|
|
return info
|
|
|
|
def main():
|
|
create()
|
|
info = read("users", "DefaultOccupation")
|
|
print(info)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|