mirror of
https://github.com/wizarrrr/wizarr.git
synced 2025-12-23 23:59:23 -05:00
cleanup
This commit is contained in:
376
.gitignore
vendored
376
.gitignore
vendored
@@ -5,4 +5,378 @@ __pycache__/
|
||||
.DS_Store
|
||||
.buildHelper.txt
|
||||
data/
|
||||
database/
|
||||
database/
|
||||
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/pycharm,flask,python
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=pycharm,flask,python
|
||||
|
||||
### Flask ###
|
||||
instance/*
|
||||
!instance/.gitignore
|
||||
.webassets-cache
|
||||
.env
|
||||
|
||||
### Flask.Python Stack ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
.pdm.toml
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
### PyCharm ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### PyCharm Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
||||
.idea/**/sonarlint/
|
||||
|
||||
# SonarQube Plugin
|
||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
||||
.idea/**/sonarIssues.xml
|
||||
|
||||
# Markdown Navigator plugin
|
||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
||||
.idea/**/markdown-navigator.xml
|
||||
.idea/**/markdown-navigator-enh.xml
|
||||
.idea/**/markdown-navigator/
|
||||
|
||||
# Cache file creation bug
|
||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
||||
.idea/$CACHE_FILE$
|
||||
|
||||
# CodeStream plugin
|
||||
# https://plugins.jetbrains.com/plugin/12206-codestream
|
||||
.idea/codestream.xml
|
||||
|
||||
# Azure Toolkit for IntelliJ plugin
|
||||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
||||
.idea/**/azureSettings.xml
|
||||
|
||||
### Python ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
|
||||
# C extensions
|
||||
|
||||
# Distribution / packaging
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
|
||||
# Installer logs
|
||||
|
||||
# Unit test / coverage reports
|
||||
|
||||
# Translations
|
||||
|
||||
# Django stuff:
|
||||
|
||||
# Flask stuff:
|
||||
|
||||
# Scrapy stuff:
|
||||
|
||||
# Sphinx documentation
|
||||
|
||||
# PyBuilder
|
||||
|
||||
# Jupyter Notebook
|
||||
|
||||
# IPython
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
|
||||
# Celery stuff
|
||||
|
||||
# SageMath parsed files
|
||||
|
||||
# Environments
|
||||
|
||||
# Spyder project settings
|
||||
|
||||
# Rope project settings
|
||||
|
||||
# mkdocs documentation
|
||||
|
||||
# mypy
|
||||
|
||||
# Pyre type checker
|
||||
|
||||
# pytype static type analyzer
|
||||
|
||||
# Cython debug symbols
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
|
||||
### Python Patch ###
|
||||
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
||||
poetry.toml
|
||||
|
||||
# ruff
|
||||
.ruff_cache/
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/pycharm,flask,python
|
||||
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
4
.idea/misc.xml
generated
Normal file
4
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (wizarr)" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/wizarr.iml" filepath="$PROJECT_DIR$/.idea/wizarr.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
28
.idea/wizarr.iml
generated
Normal file
28
.idea/wizarr.iml
generated
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="Flask">
|
||||
<option name="enabled" value="true" />
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="format" value="PLAIN" />
|
||||
<option name="myDocStringFormat" value="Plain" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
|
||||
<option name="TEMPLATE_FOLDERS">
|
||||
<list>
|
||||
<option value="$MODULE_DIR$/app/templates" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="PROJECT_TEST_RUNNER" value="py.test" />
|
||||
</component>
|
||||
</module>
|
||||
56
app/admin.py
56
app/admin.py
@@ -54,7 +54,7 @@ def invite():
|
||||
code = request.form.get("code").upper()
|
||||
if len(code) != 6:
|
||||
return abort(401)
|
||||
except :
|
||||
except:
|
||||
code = ''.join(secrets.choice(
|
||||
string.ascii_uppercase + string.digits) for _ in range(6))
|
||||
if Invitations.get_or_none(code=code):
|
||||
@@ -105,14 +105,14 @@ def invite():
|
||||
)
|
||||
else:
|
||||
server_type = Settings.get(Settings.key == "server_type").value
|
||||
return render_template("admin/invite.html", needUpdate=needUpdate(), url=os.getenv("APP_URL"), server_type=server_type)
|
||||
return render_template("admin/invite.html", needUpdate=need_update(), url=os.getenv("APP_URL"),
|
||||
server_type=server_type)
|
||||
else:
|
||||
return redirect("/admin")
|
||||
|
||||
|
||||
@app.route('/settings', methods=["GET", "POST"])
|
||||
def preferences():
|
||||
|
||||
settings = {
|
||||
'server_type': None,
|
||||
'admin_username': None,
|
||||
@@ -156,6 +156,7 @@ def preferences():
|
||||
settings['admin_username'].save()
|
||||
settings['admin_password'].value = hash
|
||||
settings['admin_password'].save()
|
||||
|
||||
return redirect('/settings')
|
||||
|
||||
elif not settings['server_verified'].value:
|
||||
@@ -206,7 +207,6 @@ def preferences():
|
||||
@app.route('/settings/', methods=["GET", "POST"])
|
||||
@login_required
|
||||
def secure_settings():
|
||||
|
||||
if request.method == 'GET':
|
||||
if htmx:
|
||||
settings = {}
|
||||
@@ -228,7 +228,7 @@ def secure_settings():
|
||||
"api_key", Settings.get(Settings.key == "api_key").value)
|
||||
libraries = []
|
||||
library_count = int(request.form.get("library_count", 0))
|
||||
for library in range(library_count+1):
|
||||
for library in range(library_count + 1):
|
||||
library_value = request.form.get(f"library_{library}")
|
||||
if library_value:
|
||||
libraries.append(library_value)
|
||||
@@ -363,18 +363,19 @@ def table():
|
||||
if invite.expires and type(invite.expires) == str:
|
||||
invite.expires = datetime.datetime.strptime(
|
||||
invite.expires, "%Y-%m-%d %H:%M")
|
||||
if invite.expires and invite.expires.strftime("%Y-%m-%d %H:%M") < datetime.datetime.now().strftime("%Y-%m-%d %H:%M"):
|
||||
if invite.expires and invite.expires.strftime("%Y-%m-%d %H:%M") < datetime.datetime.now().strftime(
|
||||
"%Y-%m-%d %H:%M"):
|
||||
invite.expired = True
|
||||
else:
|
||||
invite.expired = False
|
||||
|
||||
return render_template("tables/invite_table.html", server_type=Settings.get(key="server_type").value, invitations=invitations, rightnow=datetime.datetime.now())
|
||||
return render_template("tables/invite_table.html", server_type=Settings.get(key="server_type").value,
|
||||
invitations=invitations, rightnow=datetime.datetime.now())
|
||||
|
||||
|
||||
@app.route('/users')
|
||||
@login_required
|
||||
def users():
|
||||
|
||||
return render_template("admin/users.html")
|
||||
|
||||
|
||||
@@ -393,14 +394,14 @@ def user(user):
|
||||
if not value:
|
||||
info["Policy"][key] = ""
|
||||
else:
|
||||
#Slip value into a string
|
||||
# Slip value into a string
|
||||
info["Policy"][key] = ", ".join(value)
|
||||
for key, value in info["Configuration"].items():
|
||||
if type(value) == list:
|
||||
if not value:
|
||||
info["Configuration"][key] = ""
|
||||
else:
|
||||
#Slip value into a string
|
||||
# Slip value into a string
|
||||
info["Configuration"][key] = ", ".join(value)
|
||||
|
||||
elif request.method == "POST":
|
||||
@@ -425,7 +426,7 @@ def user(user):
|
||||
value = value.split(", ")
|
||||
info["Policy"][field] = value
|
||||
for field in info["Configuration"]:
|
||||
|
||||
|
||||
if key == field:
|
||||
if type(info["Configuration"][field]) == bool:
|
||||
if value == "True":
|
||||
@@ -445,7 +446,7 @@ def user(user):
|
||||
return redirect("/users/table")
|
||||
|
||||
else:
|
||||
info = GetPlexUser(user)
|
||||
info = plex_get_user(user)
|
||||
if request.method == "POST":
|
||||
plex_token = Settings.get(Settings.key == "api_key").value
|
||||
plex_url = Settings.get(Settings.key == "server_url").value
|
||||
@@ -454,9 +455,9 @@ def user(user):
|
||||
username = info["Name"]
|
||||
for form in request.form.items():
|
||||
print(form)
|
||||
response = admin.updateFriend(username, server, allowSync=bool(request.form.get("allowSync")),
|
||||
allowCameraUpload=bool(request.form.get("allowCameraUpload")),
|
||||
allowChannels=bool(request.form.get("allowChannels")))
|
||||
response = admin.updateFriend(username, server, allowSync=bool(request.form.get("allowSync")),
|
||||
allowCameraUpload=bool(request.form.get("allowCameraUpload")),
|
||||
allowChannels=bool(request.form.get("allowChannels")))
|
||||
print(response)
|
||||
return redirect("/users/table")
|
||||
return render_template("admin/user.html", user=info, db_id=user)
|
||||
@@ -464,25 +465,24 @@ def user(user):
|
||||
else:
|
||||
return redirect("/admin")
|
||||
|
||||
@ app.route('/users/table')
|
||||
@ login_required
|
||||
def users_table():
|
||||
|
||||
@app.route('/users/table')
|
||||
@login_required
|
||||
def users_table():
|
||||
if request.args.get("delete"):
|
||||
print("Deleting user " + request.args.get("delete"))
|
||||
GlobalDeleteUser(request.args.get("delete"))
|
||||
|
||||
users=GlobalGetUsers()
|
||||
global_delete_user(request.args.get("delete"))
|
||||
|
||||
users = global_get_users()
|
||||
|
||||
return render_template('tables/global-users.html', users=users)
|
||||
|
||||
|
||||
def needUpdate():
|
||||
def need_update():
|
||||
try:
|
||||
r=requests.get(
|
||||
r = requests.get(
|
||||
url="https://raw.githubusercontent.com/Wizarrrr/wizarr/master/.github/latest")
|
||||
data=r.content.decode("utf-8")
|
||||
data = r.content.decode("utf-8")
|
||||
if version.parse(VERSION) < version.parse(data):
|
||||
return True
|
||||
elif version.parse(VERSION) >= version.parse(data):
|
||||
@@ -493,13 +493,13 @@ def needUpdate():
|
||||
return False
|
||||
|
||||
|
||||
@ scheduler.task('interval', id='checkExpiring', minutes=15, misfire_grace_time=900)
|
||||
def checkExpiring():
|
||||
@scheduler.task('interval', id='checkExpiring', minutes=15, misfire_grace_time=900)
|
||||
def check_expiring():
|
||||
logging.info('Checking for expiring users...')
|
||||
expiring=Users.select().where(
|
||||
expiring = Users.select().where(
|
||||
Users.expires < datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))
|
||||
for user in expiring:
|
||||
GlobalDeleteUser(user)
|
||||
global_delete_user(user)
|
||||
logging.info("Deleting user " + user.email +
|
||||
" due to expired invite.")
|
||||
return
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
from app import Invitations
|
||||
|
||||
|
||||
|
||||
def isInviteValid(code):
|
||||
invitation = Invitations.get_or_none(Invitations.code == code)
|
||||
if not invitation:
|
||||
return False, "Invalid code"
|
||||
if invitation.expires and invitation.expires <= datetime.datetime.now():
|
||||
return False, "Invitation has expired."
|
||||
if invitation.used == True and invitation.unlimited != True:
|
||||
return False, "Invitation has already been used."
|
||||
return True, "okay"
|
||||
def is_invite_valid(code):
|
||||
invitation = Invitations.get_or_none(Invitations.code == code)
|
||||
if not invitation:
|
||||
return False, "Invalid code"
|
||||
if invitation.expires and invitation.expires <= datetime.datetime.now():
|
||||
return False, "Invitation has expired."
|
||||
if invitation.used == True and invitation.unlimited != True:
|
||||
return False, "Invitation has already been used."
|
||||
return True, "okay"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import requests
|
||||
import datetime
|
||||
from app import *
|
||||
from app.helpers import isInviteValid
|
||||
from app.helpers import is_invite_valid
|
||||
from flask import abort, jsonify, render_template, redirect
|
||||
import logging
|
||||
import re
|
||||
@@ -32,7 +32,7 @@ def Get(path):
|
||||
f"{jellyfin_url}{path}", headers=headers)
|
||||
return response
|
||||
|
||||
def jf_inviteUser(username, password, code, email):
|
||||
def jf_invite_user(username, password, code, email):
|
||||
try:
|
||||
# Create user dictionary
|
||||
user = {"Name": username, "Password": password}
|
||||
@@ -159,23 +159,23 @@ def join_jellyfin():
|
||||
if password != confirm_password:
|
||||
return render_template("welcome-jellyfin.html", username=username, email=email, code=code, error="Passwords do not match")
|
||||
|
||||
valid, message = isInviteValid(code)
|
||||
valid, message = is_invite_valid(code)
|
||||
if not valid:
|
||||
return render_template("welcome-jellyfin.html", username=username, email=email, code=code, error=message)
|
||||
|
||||
jf_GetUsers()
|
||||
jf_get_users()
|
||||
if Users.select().where(Users.username == username).exists():
|
||||
return render_template("welcome-jellyfin.html", username=username, email=email, code=code, error="User already exists")
|
||||
if Users.select().where(Users.email == email).exists():
|
||||
return render_template("welcome-jellyfin.html", username=username, email=email, code=code, error="Email already exists")
|
||||
|
||||
if jf_inviteUser(username, password, code, email):
|
||||
if jf_invite_user(username, password, code, email):
|
||||
return redirect('/setup')
|
||||
else:
|
||||
return render_template("welcome-jellyfin.html", username=username, email=email, code=code, error="An error occured. Please contact an administrator.")
|
||||
|
||||
|
||||
def jf_GetUsers():
|
||||
def jf_get_users():
|
||||
response = Get("/Users")
|
||||
# Compare user to database
|
||||
for user in response.json():
|
||||
@@ -194,7 +194,7 @@ def jf_GetUsers():
|
||||
return Users.select()
|
||||
|
||||
|
||||
def jf_DeleteUser(user):
|
||||
def jf_delete_user(user):
|
||||
try:
|
||||
jf_id = Users.get_by_id(user).token
|
||||
jellyfin_url = Settings.get(Settings.key == "server_url").value
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
from flask import request, redirect, render_template
|
||||
from app import app, Invitations, Settings, session, Users
|
||||
from app.plex import *
|
||||
import secrets
|
||||
from app.jellyfin import *
|
||||
from app.helpers import *
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from plexapi.server import PlexServer
|
||||
import logging
|
||||
from functools import wraps
|
||||
import datetime
|
||||
from packaging import version
|
||||
import random
|
||||
import string
|
||||
import os
|
||||
from flask_babel import _
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
19
app/ombi.py
19
app/ombi.py
@@ -5,7 +5,8 @@ from flask import abort, jsonify, render_template, redirect
|
||||
import logging
|
||||
import re
|
||||
|
||||
def ombi_RunUserImporter(name):
|
||||
|
||||
def ombi_run_user_importer(name):
|
||||
try:
|
||||
if not Settings.get_or_none(Settings.key == "overseerr_url").value:
|
||||
return
|
||||
@@ -29,12 +30,14 @@ def ombi_RunUserImporter(name):
|
||||
logging.error("Error running ombi user importer: " + str(e))
|
||||
return
|
||||
|
||||
def ombi_RunAllUserImporters():
|
||||
#ombi_RunUserImporter('plex')
|
||||
#ombi_RunUserImporter('emby')
|
||||
return ombi_RunUserImporter('jellyfin')
|
||||
|
||||
def ombi_DeleteUser(internal_user_token):
|
||||
def ombi_run_all_user_importers():
|
||||
# ombi_RunUserImporter('plex')
|
||||
# ombi_RunUserImporter('emby')
|
||||
return ombi_run_user_importer('jellyfin')
|
||||
|
||||
|
||||
def ombi_delete_user(internal_user_token):
|
||||
try:
|
||||
if not Settings.get_or_none(Settings.key == "overseerr_url").value:
|
||||
return
|
||||
@@ -61,7 +64,7 @@ def ombi_DeleteUser(internal_user_token):
|
||||
# get the wizarr username from internal_user_token
|
||||
dbQuery = Users.select().where(Users.token == internal_user_token)
|
||||
for u in dbQuery:
|
||||
username=u.username
|
||||
username = u.username
|
||||
|
||||
# Match wizarr username with ombi username and get the ombi_user_id.
|
||||
ombi_user_id = None
|
||||
@@ -82,4 +85,4 @@ def ombi_DeleteUser(internal_user_token):
|
||||
logging.error("Error deleting ombi user: " + str(e))
|
||||
return
|
||||
else:
|
||||
return
|
||||
return
|
||||
|
||||
29
app/plex.py
29
app/plex.py
@@ -8,9 +8,9 @@ import logging
|
||||
from cachetools import cached, TTLCache
|
||||
|
||||
|
||||
def handleOauthToken(token, code):
|
||||
def plex_handle_oauth_token(token, code):
|
||||
email = MyPlexAccount(token).email
|
||||
inviteUser(email, code)
|
||||
plex_invite_user(email, code)
|
||||
if Users.select().where(Users.email == email).exists():
|
||||
Users.delete().where(Users.email == email).execute()
|
||||
expires = datetime.datetime.now() + datetime.timedelta(days=int(Invitations.get(code=code).duration)
|
||||
@@ -19,10 +19,10 @@ def handleOauthToken(token, code):
|
||||
username=MyPlexAccount(token).username, code=code, expires=expires)
|
||||
|
||||
user.save()
|
||||
threading.Thread(target=SetupUser, args=(token,)).start()
|
||||
threading.Thread(target=plex_setup_user, args=(token,)).start()
|
||||
|
||||
|
||||
def GetPlexUser(user):
|
||||
def plex_get_user(user):
|
||||
print("user is ", user)
|
||||
email = Users.get_by_id(user).email
|
||||
plex_token = Settings.get(Settings.key == "api_key").value
|
||||
@@ -46,7 +46,7 @@ def GetPlexUser(user):
|
||||
|
||||
|
||||
@cached(cache=TTLCache(maxsize=1024, ttl=600))
|
||||
def getUsers():
|
||||
def plex_get_users():
|
||||
token = Settings.get(Settings.key == "api_key").value
|
||||
admin = MyPlexAccount(token)
|
||||
plexusers = admin.users()
|
||||
@@ -76,17 +76,16 @@ def getUsers():
|
||||
return users
|
||||
|
||||
|
||||
def deleteUser(id):
|
||||
getUsers.cache_clear()
|
||||
def plex_delete_user(id):
|
||||
plex_get_users.cache_clear()
|
||||
email = Users.get(Users.id == id).email
|
||||
plex_token = Settings.get(Settings.key == "api_key").value
|
||||
admin = MyPlexAccount(plex_token)
|
||||
admin.removeFriend(email)
|
||||
|
||||
|
||||
|
||||
def inviteUser(email, code):
|
||||
getUsers.cache_clear()
|
||||
def plex_invite_user(email, code):
|
||||
plex_get_users.cache_clear()
|
||||
sections = list(
|
||||
(Settings.get(Settings.key == "libraries").value).split(", "))
|
||||
plex_url = Settings.get(Settings.key == "server_url").value
|
||||
@@ -111,9 +110,9 @@ def inviteUser(email, code):
|
||||
return
|
||||
|
||||
|
||||
def SetupUser(token):
|
||||
def plex_setup_user(token):
|
||||
try:
|
||||
getUsers.cache_clear()
|
||||
plex_get_users.cache_clear()
|
||||
plex_token = Settings.get(Settings.key == "api_key").value
|
||||
admin_email = MyPlexAccount(plex_token).email
|
||||
user = MyPlexAccount(token)
|
||||
@@ -123,7 +122,7 @@ def SetupUser(token):
|
||||
logging.error("Failed to setup user: " + str(e))
|
||||
|
||||
|
||||
def optOutOnlineSources(token):
|
||||
def plex_opt_out_online_sources(token):
|
||||
user = MyPlexAccount(token)
|
||||
for source in user.onlineMediaSources():
|
||||
source.optOut()
|
||||
@@ -131,7 +130,7 @@ def optOutOnlineSources(token):
|
||||
|
||||
|
||||
@app.route('/scan', methods=["POST"])
|
||||
def scan():
|
||||
def plex_scan():
|
||||
plex_url = request.args.get('plex_url')
|
||||
plex_token = request.args.get('plex_token')
|
||||
if not plex_url or not plex_token:
|
||||
@@ -148,7 +147,7 @@ def scan():
|
||||
|
||||
|
||||
@app.route('/scan-specific', methods=["POST"])
|
||||
def scan_specific():
|
||||
def plex_scan_specific():
|
||||
plex_url = Settings.get(Settings.key == "server_url").value
|
||||
plex_token = Settings.get(Settings.key == "api_key").value
|
||||
if not plex_url or not plex_token:
|
||||
|
||||
41
app/universal.py
Normal file
41
app/universal.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from app.plex import *
|
||||
from app.jellyfin import *
|
||||
from app.ombi import *
|
||||
|
||||
|
||||
def global_delete_user(user):
|
||||
server_type = Settings.get(Settings.key == "server_type").value
|
||||
if server_type == "plex":
|
||||
try:
|
||||
plex_delete_user(user)
|
||||
except Exception as e:
|
||||
if "429" in str(e):
|
||||
logging.error("Too many requests to Plex API")
|
||||
else:
|
||||
logging.error("Unable to delete user: " + str(e))
|
||||
elif server_type == "jellyfin":
|
||||
jf_delete_user(user)
|
||||
Users.delete().where(Users.id == user).execute()
|
||||
ombi_delete_user(user)
|
||||
|
||||
|
||||
def global_get_users():
|
||||
server_type = Settings.get(Settings.key == "server_type").value
|
||||
if server_type == "plex":
|
||||
try:
|
||||
users = plex_get_users()
|
||||
return users
|
||||
except Exception as e:
|
||||
if "429" in str(e):
|
||||
logging.error("Too many requests to Plex API")
|
||||
else:
|
||||
logging.error("Unable to get users: " + str(e))
|
||||
elif server_type == "jellyfin":
|
||||
try:
|
||||
users = jf_get_users()
|
||||
return users
|
||||
except Exception as e:
|
||||
if "429" in str(e):
|
||||
logging.error("Too many requests to Jellyfin API")
|
||||
else:
|
||||
logging.error("Unable to get users: " + str(e))
|
||||
@@ -48,13 +48,13 @@ def connect():
|
||||
code = request.form.get('code')
|
||||
token = request.form.get("token")
|
||||
|
||||
valid, message = isInviteValid(code)
|
||||
valid, message = is_invite_valid(code)
|
||||
|
||||
if not valid:
|
||||
return render_template("user-plex-login.html", name=Settings.get(Settings.key == "server_name").value, code=code, code_error=message)
|
||||
|
||||
if Settings.get(key="server_type").value == "plex":
|
||||
threading.Thread(target=handleOauthToken, args=(token, code)).start()
|
||||
threading.Thread(target=plex_handle_oauth_token, args=(token, code)).start()
|
||||
return redirect(os.getenv("APP_URL") + "/setup")
|
||||
|
||||
elif Settings.get(key="server_type").value == "jellyfin":
|
||||
@@ -62,7 +62,7 @@ def connect():
|
||||
|
||||
@app.route('/setup', methods=["GET"])
|
||||
def setup():
|
||||
ombi_RunAllUserImporters()
|
||||
ombi_run_all_user_importers()
|
||||
|
||||
resp = make_response(render_template(
|
||||
"wizard.html", server_type=Settings.get(Settings.key == "server_type").value))
|
||||
|
||||
Reference in New Issue
Block a user