dynamically generate default config on first run

This commit is contained in:
2020-06-29 23:06:58 +01:00
parent 4606415a38
commit 55d26b541a
8 changed files with 94 additions and 210 deletions

View File

@@ -49,10 +49,13 @@ first_run = False
if data_dir.exists() is False or (data_dir / "config.ini").exists() is False:
if not data_dir.exists():
Path.mkdir(data_dir)
print(f"Config dir not found, so created at {str(data_dir)}")
print(f"Config dir not found, so generating at {str(data_dir)}")
if args.config is None:
config_path = data_dir / "config.ini"
shutil.copy(str(local_dir / "config-default.ini"), str(config_path))
from jellyfin_accounts.generate_ini import generate_ini
default_path = local_dir / "config-default.ini"
generate_ini(local_dir / "config-base.json", default_path)
shutil.copy(str(default_path), str(config_path))
print("Setup through the web UI, or quit and edit the configuration manually.")
first_run = True
else:

View File

@@ -0,0 +1,486 @@
{
"jellyfin": {
"meta": {
"name": "Jellyfin",
"description": "Settings for connecting to Jellyfin"
},
"username": {
"name": "Jellyfin Username",
"required": true,
"requires_restart": true,
"type": "text",
"value": "username",
"description": "It is recommended to create a limited admin account for this program."
},
"password": {
"name": "Jellyfin Password",
"required": true,
"requires_restart": true,
"type": "password",
"value": "password"
},
"server": {
"name": "Server address",
"required": true,
"requires_restart": true,
"type": "text",
"value": "http://jellyfin.local:8096",
"description": "Jellyfin server address. Can be public, or local for security purposes."
},
"public_server": {
"name": "Public address",
"required": false,
"requires_restart": false,
"type": "text",
"value": "https://jellyf.in:443",
"description": "Publicly accessible Jellyfin address for invite form. Leave blank to reuse the above address."
},
"client": {
"name": "Client Name",
"required": true,
"requires_restart": true,
"type": "text",
"value": "jf-accounts",
"description": "This and below settings will show on the Jellyfin dashboard when the program connects. You may as well leave them alone."
},
"version": {
"name": "Version Number",
"required": true,
"requires_restart": true,
"type": "text",
"value": "0.2.4"
},
"device": {
"name": "Device Name",
"required": true,
"requires_restart": true,
"type": "text",
"value": "jf-accounts"
},
"device_id": {
"name": "Device ID",
"required": true,
"requires_restart": true,
"type": "text",
"value": "jf-accounts-0.2.4"
}
},
"ui": {
"meta": {
"name": "General",
"description": "Settings related to the UI and program functionality."
},
"host": {
"name": "Address",
"required": true,
"requires_restart": true,
"type": "text",
"value": "0.0.0.0",
"description": "Set 0.0.0.0 to run on localhost"
},
"port": {
"name": "Port",
"required": true,
"requires_restart": true,
"type": "int",
"value": 8056
},
"jellyfin_login": {
"name": "Use Jellyfin for authentication",
"required": true,
"requires_restart": true,
"type": "bool",
"value": true,
"description": "Enable this to use Jellyfin users instead of the below username and pw."
},
"admin_only": {
"name": "Allow admin users only",
"required": false,
"requires_restart": true,
"depends_true": "jellyfin_login",
"type": "bool",
"value": true,
"description": "Allows only admin users on Jellyfin to access the admin page."
},
"username": {
"name": "Web Username",
"required": true,
"requires_restart": true,
"depends_false": "jellyfin_login",
"type": "text",
"value": "your username",
"description": "Username for admin page (Leave blank if using jellyfin_login)"
},
"password": {
"name": "Web Password",
"required": true,
"requires_restart": true,
"depends_false": "jellyfin_login",
"type": "password",
"value": "your password",
"description": "Password for admin page (Leave blank if using jellyfin_login)"
},
"debug": {
"name": "Debug logging",
"required": true,
"requires_restart": true,
"type": "bool",
"value": false
},
"contact_message": {
"name": "Contact message",
"required": false,
"requires_restart": false,
"type": "text",
"value": "Need help? contact me.",
"description": "Displayed at bottom of all pages except admin"
},
"help_message": {
"name": "Help message",
"required": false,
"requires_restart": false,
"type": "text",
"value": "Enter your details to create an account.",
"description": "Display at top of invite form."
},
"success_message": {
"name": "Success message",
"required": false,
"requires_restart": false,
"type": "text",
"value": "Your account has been created. Click below to continue to Jellyfin.",
"description": "Displayed when a user creates an account"
}
},
"password_validation": {
"meta": {
"name": "Password Validation",
"description": "Password validation (minimum length, etc.)"
},
"enabled": {
"name": "Enabled",
"required": true,
"requires_restart": true,
"type": "bool",
"value": true
},
"min_length": {
"name": "Minimum Length",
"requires_restart": true,
"depends_true": "enabled",
"type": "text",
"value": "8"
},
"upper": {
"name": "Minimum uppercase characters",
"requires_restart": true,
"depends_true": "enabled",
"type": "text",
"value": "1"
},
"lower": {
"name": "Minimum lowercase characters",
"requires_restart": true,
"depends_true": "enabled",
"type": "text",
"value": "0"
},
"number": {
"name": "Minimum number count",
"requires_restart": true,
"depends_true": "enabled",
"type": "text",
"value": "1"
},
"special": {
"name": "Minimum number of special characters",
"requires_restart": true,
"type": "text",
"value": "0"
}
},
"email": {
"meta": {
"name": "Email",
"description": "General email settings. Ignore if not using email features."
},
"no_username": {
"name": "Use email addresses as username",
"required": false,
"requires_restart": false,
"depends_true": "method",
"type": "bool",
"value": false,
"description": "Use email address from invite form as username on Jellyfin."
},
"use_24h": {
"name": "Use 24h time",
"required": false,
"requires_restart": false,
"depends_true": "method",
"type": "bool",
"value": true
},
"date_format": {
"name": "Date format",
"required": false,
"requires_restart": false,
"depends_true": "method",
"type": "text",
"value": "%d/%m/%y",
"description": "Date format used in emails. Follows datetime.strftime format."
},
"message": {
"name": "Help message",
"required": false,
"requires_restart": false,
"depends_true": "method",
"type": "text",
"value": "Need help? contact me.",
"description": "Message displayed at bottom of emails."
},
"method": {
"name": "Email method",
"required": false,
"requires_restart": false,
"type": "select",
"options": [
"smtp",
"mailgun"
],
"value": "smtp",
"description": "Method of sending email to use."
},
"address": {
"name": "Sent from (address)",
"required": false,
"requires_restart": false,
"depends_true": "method",
"type": "email",
"value": "jellyfin@jellyf.in",
"description": "Address to send emails from"
},
"from": {
"Name": "Sent from (name)",
"required": false,
"requires_restart": false,
"depends_true": "method",
"type": "text",
"value": "Jellyfin",
"description": "The name of the sender"
}
},
"password_resets": {
"meta": {
"name": "Password Resets",
"description": "Settings for the password reset handler."
},
"enabled": {
"name": "Enabled",
"required": true,
"requires_restart": true,
"type": "bool",
"value": true,
"description": "Enable to store provided email addresses, monitor Jellyfin directory for pw-resets, and send reset pins"
},
"watch_directory": {
"name": "Jellyfin directory",
"required": true,
"requires_restart": true,
"depends_true": "enabled",
"type": "text",
"value": "/path/to/jellyfin",
"description": "Path to the folder Jellyfin puts password-reset files."
},
"email_html": {
"name": "Custom email (HTML)",
"required": false,
"requires_restart": false,
"depends_true": "enabled",
"type": "text",
"value": "",
"description": "Path to custom email html"
},
"email_text": {
"name": "Custom email (plaintext)",
"required": false,
"requires_restart": false,
"depends_true": "enabled",
"type": "text",
"value": "",
"description": "Path to custom email in plain text"
},
"subject": {
"name": "Email subject",
"required": true,
"requires_restart": false,
"depends_true": "enabled",
"type": "text",
"value": "Password Reset - Jellyfin",
"description": "Subject of password reset emails."
}
},
"invite_emails": {
"meta": {
"name": "Invite emails",
"description": "Settings for sending invites directly to users."
},
"enabled": {
"name": "Enabled",
"required": true,
"requires_restart": true,
"type": "bool",
"value": true
},
"email_html": {
"name": "Custom email (HTML)",
"required": false,
"requires_restart": false,
"depends_true": "enabled",
"type": "text",
"value": "",
"description": "Path to custom email HTML"
},
"email_text": {
"name": "Custom email (plaintext)",
"required": false,
"requires_restart": false,
"depends_true": "enabled",
"type": "text",
"value": "",
"description": "Path to custom email in plain text"
},
"subject": {
"name": "Email subject",
"required": true,
"requires_restart": false,
"depends_true": "enabled",
"type": "text",
"value": "Invite - Jellyfin",
"description": "Subject of invite emails."
},
"url_base": {
"name": "URL Base",
"required": true,
"requires_restart": false,
"depends_true": "enabled",
"type": "text",
"value": "http://accounts.jellyf.in:8056/invite",
"description": "Base URL for jf-accounts. This is necessary because using a reverse proxy means the program has no way of knowing the URL itself."
}
},
"mailgun": {
"meta": {
"name": "Mailgun (Email)",
"description": "Mailgun API connection settings"
},
"api_url": {
"name": "API URL",
"required": false,
"requires_restart": false,
"type": "text",
"value": "https://api.mailgun.net..."
},
"api_key": {
"name": "API Key",
"required": false,
"requires_restart": false,
"type": "text",
"value": "your api key"
}
},
"smtp": {
"meta": {
"name": "SMTP (Email)",
"description": "SMTP Server connection settings."
},
"encryption": {
"name": "Encryption Method",
"required": false,
"requires_restart": false,
"type": "select",
"options": [
"ssl_tls",
"starttls"
],
"value": "starttls",
"description": "Your email provider should provide different ports for each encryption method. Generally 465 for ssl_tls, 587 for starttls."
},
"server": {
"name": "Server address",
"required": false,
"requires_restart": false,
"type": "text",
"value": "smtp.jellyf.in",
"description": "SMTP Server address."
},
"port": {
"name": "Port",
"required": false,
"requires_restart": false,
"type": "int",
"value": 465
},
"password": {
"name": "Password",
"required": false,
"requires_restart": false,
"type": "password",
"value": "smtp password"
}
},
"files": {
"meta": {
"name": "File Storage",
"description": "Optional settings for changing storage locations."
},
"invites": {
"name": "Invite Storage",
"required": false,
"requires_restart": true,
"type": "text",
"value": "",
"description": "Location of stored invites (json)."
},
"emails": {
"name": "Email Addresses",
"required": false,
"requires_restart": true,
"type": "text",
"value": "",
"description": "Location of stored email addresses (json)."
},
"user_template": {
"name": "User Template",
"required": false,
"requires_restart": true,
"type": "text",
"value": "",
"description": "Location of stored user policy template (json)."
},
"user_configuration": {
"name": "userConfiguration",
"required": false,
"requires_restart": true,
"type": "text",
"value": "",
"description": "Location of stored user configuration template (used for setting homescreen layout) (json)"
},
"user_displayprefs": {
"name": "displayPreferences",
"required": false,
"requires_restart": true,
"type": "text",
"value": "",
"description": "Location of stored displayPreferences template (also used for homescreen layout) (json)"
},
"custom_css": {
"name": "Custom CSS",
"required": false,
"requires_restart": true,
"type": "text",
"value": "",
"description": "Location of custom bootstrap CSS."
}
}
}

View File

@@ -1,118 +1,115 @@
[jellyfin]
; It is reccommended to create a limited admin account for this program.
; settings for connecting to jellyfin
; it is recommended to create a limited admin account for this program.
username = username
password = password
; Jellyfin server address. Can be public, or local for security purposes.
; jellyfin server address. can be public, or local for security purposes.
server = http://jellyfin.local:8096
; Publicly accessible Jellyfin address, used on invite form.
; Leave blank to use the same address as above.
; publicly accessible jellyfin address for invite form. leave blank to reuse the above address.
public_server = https://jellyf.in:443
; this and below settings will show on the jellyfin dashboard when the program connects. you may as well leave them alone.
client = jf-accounts
version = 0.1
version = 0.2.4
device = jf-accounts
device_id = jf-accounts-0.1
device_id = jf-accounts-0.2.4
[ui]
; Set 0.0.0.0 to run localhost
; settings related to the ui and program functionality.
; set 0.0.0.0 to run on localhost
host = 0.0.0.0
port = 8056
; Enable this to use Jellyfin users instead of the below username and pw.
; enable this to use jellyfin users instead of the below username and pw.
jellyfin_login = true
; Allows only admin users on Jellyfin to access admin page.
; allows only admin users on jellyfin to access the admin page.
admin_only = true
; Username to use on admin page... (leave blank if using jellyfin_login)
; username for admin page (leave blank if using jellyfin_login)
username = your username
; ..and its corresponding password (leave blank if using jellyfin_login)
; password for admin page (leave blank if using jellyfin_login)
password = your password
debug = false
; Displayed at the bottom of all pages except admin
; displayed at bottom of all pages except admin
contact_message = Need help? contact me.
; Displayed at top of form page.
help_message = Enter your details to create an account.
; Displayed when an account is created.
; display at top of invite form.
help_message = Enter your details to create an account.
; displayed when a user creates an account
success_message = Your account has been created. Click below to continue to Jellyfin.
[password_validation]
; Enables password validation.
enabled = true
; Min. password length
; password validation (minimum length, etc.)
enabled = true
min_length = 8
; Min. number of uppercase characters
upper = 1
; Min. number of lowercase characters
lower = 0
; Min. number of numbers
number = 1
; Min. number of special characters
special = 0
[email]
; When true, disables username input on invite form and sets the Jellyfin username to the email address
; general email settings. ignore if not using email features.
; use email address from invite form as username on jellyfin.
no_username = false
; Leave the rest of this section if you aren't using any email-related features.
use_24h = true
; Date format follows datetime's strftime.
; date format used in emails. follows datetime.strftime format.
date_format = %d/%m/%y
; Displayed at bottom of emails
; message displayed at bottom of emails.
message = Need help? contact me.
; Mail methods: mailgun, smtp
; method of sending email to use.
method = smtp
; Address to send from
; address to send emails from
address = jellyfin@jellyf.in
; The name of the sender
; the name of the sender
from = Jellyfin
[password_resets]
; Enable to store provided email addresses, monitor jellyfin directory for pw-resets, and send pin
; settings for the password reset handler.
; enable to store provided email addresses, monitor jellyfin directory for pw-resets, and send reset pins
enabled = true
; Directory to monitor for passwordReset*.json files. Usually the jellyfin config directory
; path to the folder jellyfin puts password-reset files.
watch_directory = /path/to/jellyfin
; Path to custom email html. If blank, uses the internal template.
email_html =
; Path to alternate plaintext email. If blank, uses the internal template.
; path to custom email html
email_html =
; path to custom email in plain text
email_text =
; Subject of emails
; subject of password reset emails.
subject = Password Reset - Jellyfin
[invite_emails]
; If enabled, allows one to send an invite directly to an email address.
; settings for sending invites directly to users.
enabled = true
; Path to custom email html. If blank, uses the internal template.
email_html =
; Path to alternate plaintext email. If blank, uses the internal template.
; path to custom email html
email_html =
; path to custom email in plain text
email_text =
; subject of invite emails.
subject = Invite - Jellyfin
; Base url for jf-accounts. This necessary because most will use a reverse proxy, so the program has no other way of knowing what URL to send.
; base url for jf-accounts. this is necessary because using a reverse proxy means the program has no way of knowing the url itself.
url_base = http://accounts.jellyf.in:8056/invite
[mailgun]
; mailgun api connection settings
api_url = https://api.mailgun.net...
api_key = your api key
[smtp]
; Choose between ssl_tls and starttls. Your provider should tell you which to use, but generally SSL/TLS is 465, STARTTLS 587
; smtp server connection settings.
; your email provider should provide different ports for each encryption method. generally 465 for ssl_tls, 587 for starttls.
encryption = starttls
; smtp server address.
server = smtp.jellyf.in
; Uses SMTP_SSL, so make sure the port is for this, not starttls.
port = 465
password = smtp password
[files]
; When the below paths are left blank, files are stored in ~/.jf-accounts/.
; Path to store valid invites.
; optional settings for changing storage locations.
; location of stored invites (json).
invites =
; Path to store emails addresses in JSON
; location of stored email addresses (json).
emails =
; Path to the user policy template. Can be acquired with get-defaults (jf-accounts -g).
user_template =
; Path to the user configuration template (part of homescreen layout). Can be acquired with get-defaults (jf-accounts -g).
user_configuration =
; Path to the user display preferences template (part of homescreen layout). Can be acquired with get-defaults (jf-accounts -g).
user_displayprefs =
; Path to custom bootstrap.css
; location of stored user policy template (json).
user_template =
; location of stored user configuration template (used for setting homescreen layout) (json)
user_configuration =
; location of stored displaypreferences template (also used for homescreen layout) (json)
user_displayprefs =
; location of custom bootstrap css.
custom_css =

View File

@@ -0,0 +1,32 @@
import configparser
import json
from pathlib import Path
def generate_ini(base_file, ini_file):
"""
Generates .ini file from config-base file.
"""
with open(Path(base_file), 'r') as f:
config_base = json.load(f)
ini = configparser.RawConfigParser(allow_no_value=True)
for section in config_base:
ini.add_section(section)
for entry in config_base[section]:
if 'description' in config_base[section][entry]:
ini.set(section,
'; ' + config_base[section][entry]['description'])
if entry != 'meta':
value = config_base[section][entry]['value']
if isinstance(value, bool):
value = str(value).lower()
else:
value = str(value)
ini.set(section,
entry,
value)
with open(Path(ini_file), 'w') as config_file:
ini.write(config_file)
return True