changed how template apps are handled, no more database table, also separate files for each app. Unfortunately the idea of displaying a list here is not going to work. As we add data sources for template apps, there's going to be too much data to send at one time, so we'll need to keep the autocomplete.

This commit is contained in:
Ross Mountjoy 2020-02-13 11:22:40 -05:00
parent 331027894a
commit 445ca85808
36 changed files with 281 additions and 236 deletions

View File

@ -1,177 +0,0 @@
[Nextcloud]
prefix = https://
url = your-website.com
icon = static/images/apps/nextcloud.png
description = A safe home for all your data community-driven, free & open source
open_in = this_tab
[Home Assistant]
prefix = https://
url = your-website.com
icon = static/images/apps/home-assistant.png
description = Open source home automation that puts local control and privacy first
open_in = this_tab
[Emby]
prefix = https://
url = your-website.com
icon = static/images/apps/emby.png
description = Emby Server is a personal media server with apps on just about every device
open_in = this_tab
[Bitwarden]
prefix = https://
url = your-website.com
icon = static/images/apps/bitwarden.png
description = A free and open-source password management service
open_in = this_tab
[Deluge]
prefix = https://
url = your-website.com
icon = static/images/apps/deluge.png
description = Deluge is a lightweight, Free Software, cross-platform BitTorrent client
open_in = this_tab
[Gitea]
prefix = https://
url = your-website.com
icon = static/images/apps/gitea.png
description = A painless self-hosted Git service
open_in = this_tab
[SSH]
prefix = https://
url = your-website.com
icon = static/images/apps/terminal.png
description = SSH, terminal, shell, shellinabox
open_in = this_tab
[Portainer]
prefix = https://
url = your-website.com
icon = static/images/apps/portainer.png
description = Making Docker management easy
open_in = this_tab
[Nginx Proxy Manager]
prefix = https://
url = your-website.com
icon = static/images/apps/nginxproxymanager.png
description = Docker container for managing Nginx proxy hosts with a simple, powerful interface
open_in = this_tab
[Sonarr]
prefix = https://
url = your-website.com
icon = static/images/apps/sonarr.png
description = Smart PVR for newsgroup and bittorrent users
open_in = this_tab
[Radarr]
prefix = https://
url = your-website.com
icon = static/images/apps/radarr.png
description = A fork of Sonarr to work with movies à la Couchpotato
open_in = this_tab
[Jackett]
prefix = http://
url = 192.168.39.175:9117
icon = static/images/apps/jackett.png
description = API Support for your favorite torrent trackers
open_in = this_tab
[Riot]
prefix = https://
url = your-website.com
icon = static/images/apps/riot.png
description = A glossy Matrix collaboration client for the web
open_in = this_tab
[Jellyfin]
prefix = https://
url = your-website.com
icon = static/images/apps/jellyfin.png
description = The Free Software Media System
open_in = this_tab
[Lidarr]
prefix = http://
url = 192.168.39.175:8686
icon = static/images/apps/lidarr.png
description = Looks and smells like Sonarr but made for music
open_in = this_tab
[Airsonic]
prefix = http://
url = 192.168.39.175:4040
icon = static/images/apps/airsonic.png
description = A Free and Open Source community driven media server
open_in = this_tab
[Tautulli]
prefix = http://
url = 192.168.39.175:8181
icon = static/images/apps/tautulli.png
description = A Python based monitoring and tracking tool for Plex Media Server
open_in = this_tab
[Bazarr]
prefix = http://
url = 192.168.39.175:6767
icon = static/images/apps/bazarr.png
description = A companion application to Sonarr and Radarr
open_in = this_tab
[Ombi]
prefix = http://
url = 192.168.39.175:3579
icon = static/images/apps/ombi.png
description = Want a Movie or TV Show on Plex or Emby? Use Ombi!
open_in = this_tab
[Syncthing]
prefix = http://
url = 192.168.39.175:8384
icon = static/images/apps/Syncthing.png
description = Open Source Continuous File Synchronization
open_in = this_tab
[The Lounge]
prefix = http://
url = 192.168.39.175:9000
icon = static/images/apps/thelounge.png
description = Modern, responsive, cross-platform, self-hosted web IRC client
open_in = this_tab
[Traefik]
prefix = http://
url = 192.168.39.175:8080
icon = static/images/apps/traefik.png
description = The Cloud Native Edge Router
open_in = this_tab
[HandBrake]
prefix = https://
url = 192.168.39.175:7803
icon = static/images/apps/handbrake.png
sidebar_icon = static/images/icons/handbrake.png
description = HandBrake is an open-source, GPL-licensed, multiplatform, multithreaded video transcoder
open_in = this_tab
[OPNsense]
prefix = https://
url = 192.168.39.1
icon = static/images/apps/opnsense.png
sidebar_icon = static/images/apps/opnsense.png
description = Secure Your Network with ease. From Virtual Private Networking to Intrusion Detection, Best in class, FREE Open Source Project
open_in = new_tab
[BookStack]
prefix = http://
url = 192.168.39.175:8197
icon = static/images/apps/bookstack.png
sidebar_icon = static/images/apps/bookstack.png
description = BookStack is a simple, self-hosted, easy-to-use platform for organising and storing information
open_in = new_tab

View File

@ -30,17 +30,6 @@ class Apps(db.Model):
tags = db.Column(db.String()) tags = db.Column(db.String())
class TemplateApps(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String())
prefix = db.Column(db.String())
url = db.Column(db.String())
icon = db.Column(db.String())
sidebar_icon = db.Column(db.String())
description = db.Column(db.String())
open_in = db.Column(db.String())
class DataSources(db.Model): class DataSources(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String()) name = db.Column(db.String())

View File

@ -1,11 +1,8 @@
import os import os
import subprocess
import importlib import importlib
from shutil import copyfile from shutil import copyfile
from requests import get
from configparser import ConfigParser
from dashmachine.paths import dashmachine_folder, images_folder, root_folder from dashmachine.paths import dashmachine_folder, images_folder, root_folder
from dashmachine.main.models import TemplateApps, Groups from dashmachine.main.models import Groups
from dashmachine.main.read_config import read_config from dashmachine.main.read_config import read_config
from dashmachine.settings_system.models import Settings from dashmachine.settings_system.models import Settings
from dashmachine.user_system.models import User from dashmachine.user_system.models import User
@ -21,31 +18,6 @@ def row2dict(row):
return d return d
def read_template_apps():
config = ConfigParser()
try:
config.read("app_templates.ini")
except Exception as e:
return {"msg": f"Invalid Config: {e}."}
TemplateApps.query.delete()
for section in config.sections():
template_app = TemplateApps()
template_app.name = section
template_app.prefix = config[section]["prefix"]
template_app.url = config[section]["url"]
template_app.icon = config[section]["icon"]
if "sidebar_icon" in config[section]:
template_app.sidebar_icon = config[section]["sidebar_icon"]
else:
template_app.sidebar_icon = template_app.icon
template_app.description = config[section]["description"]
template_app.open_in = config[section]["open_in"]
db.session.add(template_app)
db.session.commit()
# establishes routes decorated w/ @public_route as accessible while not signed # establishes routes decorated w/ @public_route as accessible while not signed
# in. See login and register routes for usage # in. See login and register routes for usage
def public_route(decorated_function): def public_route(decorated_function):
@ -57,7 +29,6 @@ def dashmachine_init():
db.create_all() db.create_all()
db.session.commit() db.session.commit()
read_template_apps()
user_data_folder = os.path.join(dashmachine_folder, "user_data") user_data_folder = os.path.join(dashmachine_folder, "user_data")
# create the user_data subdirectories, link them to static # create the user_data subdirectories, link them to static

View File

@ -13,6 +13,8 @@ root_folder = get_root_folder()
dashmachine_folder = os.path.join(root_folder, "dashmachine") dashmachine_folder = os.path.join(root_folder, "dashmachine")
template_apps_folder = os.path.join(root_folder, "template_apps")
platform_folder = os.path.join(dashmachine_folder, "platform") platform_folder = os.path.join(dashmachine_folder, "platform")
user_data_folder = os.path.join(dashmachine_folder, "user_data") user_data_folder = os.path.join(dashmachine_folder, "user_data")

View File

@ -1,3 +1,44 @@
"""
##### deluge
Display information from Deluge web ui.
```ini
[variable_name]
platform = deluge
resource = https://deluge.example.com:8112/json
value_template = {{download_rate|filesizeformat}}/s {{upload_rate|filesizeformat}}/s
password = MySecretPassword
```
> **Returns:** `value_template` as rendered string
| Variable | Required | Description | Options |
|-----------------|----------|-----------------------------------------------------------------|-------------------|
| [variable_name] | Yes | Name for the data source. | [variable_name] |
| plaform | Yes | Name of the platform. | rest |
| resource | Yes | Url of your deluge instance + '/json' | url |
| value_template | Yes | Jinja template for how the returned data from api is displayed. | jinja template |
| password | No | Password to use for auth. | string |
> **Working example:**
>```
>[deluge]
>platform = deluge
>resource = https://deluge.example.com:8112/json
>value_template = {{download_rate|filesizeformat}}/s {{upload_rate|filesizeformat}}/s
>password = MySecretPassword
>
>[Deluge]
>prefix = https://
>url = https://deluge.example.com:8112
>icon = static/images/apps/deluge.png
>sidebar_icon = static/images/apps/deluge.png
>description = Deluge is a lightweight, Free Software, cross-platform BitTorrent client
>open_in = iframe
>data_sources = deluge
>```
"""
from flask import render_template_string from flask import render_template_string
import requests import requests
@ -19,11 +60,7 @@ class Platform:
self.password = None # Discard password, no longer needed. self.password = None # Discard password, no longer needed.
def _api_call(self, method, params=[]): def _api_call(self, method, params=[]):
json = { json = {"id": self.id, "method": method, "params": params}
"id": self.id,
"method": method,
"params": params
}
return self.session.post(self.resource, json=json) return self.session.post(self.resource, json=json)
def process(self): def process(self):

View File

@ -1,13 +1,14 @@
import os import os
from shutil import move from shutil import move
from configparser import ConfigParser
from flask_login import current_user from flask_login import current_user
from flask import render_template, request, Blueprint, jsonify, redirect, url_for from flask import render_template, request, Blueprint, jsonify, redirect, url_for
from dashmachine.user_system.forms import UserForm from dashmachine.user_system.forms import UserForm
from dashmachine.user_system.utils import add_edit_user from dashmachine.user_system.utils import add_edit_user
from dashmachine.user_system.models import User from dashmachine.user_system.models import User
from dashmachine.main.utils import row2dict, public_route, check_groups from dashmachine.main.utils import public_route, check_groups
from dashmachine.main.read_config import read_config from dashmachine.main.read_config import read_config
from dashmachine.main.models import Files, TemplateApps from dashmachine.main.models import Files
from dashmachine.settings_system.forms import ConfigForm from dashmachine.settings_system.forms import ConfigForm
from dashmachine.settings_system.utils import load_files_html, get_config_html from dashmachine.settings_system.utils import load_files_html, get_config_html
from dashmachine.settings_system.models import Settings from dashmachine.settings_system.models import Settings
@ -15,6 +16,7 @@ from dashmachine.paths import (
backgrounds_images_folder, backgrounds_images_folder,
icons_images_folder, icons_images_folder,
user_data_folder, user_data_folder,
template_apps_folder,
) )
from dashmachine.version import version from dashmachine.version import version
from dashmachine import db from dashmachine import db
@ -35,10 +37,13 @@ def settings():
with open(os.path.join(user_data_folder, "config.ini"), "r") as config_file: with open(os.path.join(user_data_folder, "config.ini"), "r") as config_file:
config_form.config.data = config_file.read() config_form.config.data = config_file.read()
files_html = load_files_html() files_html = load_files_html()
template_apps = [] template_apps = []
t_apps = TemplateApps.query.all() config = ConfigParser()
for t_app in t_apps: for template_app_ini in os.listdir(template_apps_folder):
template_apps.append(f"{t_app.name}&&{t_app.icon}") config.read(os.path.join(template_apps_folder, template_app_ini))
entry = config[template_app_ini.replace(".ini", "")]
template_apps.append(f"{template_app_ini.replace('.ini', '')}&&{entry['icon']}")
users = User.query.all() users = User.query.all()
config_readme = get_config_html() config_readme = get_config_html()
@ -87,11 +92,15 @@ def delete_file():
@settings_system.route("/settings/get_app_template", methods=["GET"]) @settings_system.route("/settings/get_app_template", methods=["GET"])
def get_app_template(): def get_app_template():
template_app = TemplateApps.query.filter_by(name=request.args.get("name")).first() # template_app = TemplateApps.query.filter_by(name=request.args.get("name")).first()
template = f"[{template_app.name}]<br>" # template = f"[{template_app.name}]<br>"
for key, value in row2dict(template_app).items(): # for key, value in row2dict(template_app).items():
if key not in ["id", "name"]: # if key not in ["id", "name"]:
template += f"{key} = {value}<br>" # template += f"{key} = {value}<br>"
fn = os.path.join(template_apps_folder, f"{request.args.get('name')}.ini")
with open(fn, "r") as template_app_ini:
template = template_app_ini.read().replace("\n", "<br>")
return template return template

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

View File

@ -102,7 +102,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col s12 scrollbar settings-page-card-right"> <div class="col s12 scrollbar settings-page-card-right">
<div id="template-div" class="selectable-all code"></div> <div id="template-div" class="selectable code"></div>
</div> </div>
</div> </div>

View File

@ -1 +1 @@
version = "v0.33" version = "v0.34"

View File

@ -0,0 +1,39 @@
"""empty message
Revision ID: a36cddc6266e
Revises: ff5eb645bfe4
Create Date: 2020-02-13 10:44:25.619089
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "a36cddc6266e"
down_revision = "ff5eb645bfe4"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("template_apps")
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"template_apps",
sa.Column("id", sa.INTEGER(), nullable=False),
sa.Column("name", sa.VARCHAR(), nullable=True),
sa.Column("prefix", sa.VARCHAR(), nullable=True),
sa.Column("url", sa.VARCHAR(), nullable=True),
sa.Column("icon", sa.VARCHAR(), nullable=True),
sa.Column("sidebar_icon", sa.VARCHAR(), nullable=True),
sa.Column("description", sa.VARCHAR(), nullable=True),
sa.Column("open_in", sa.VARCHAR(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
# ### end Alembic commands ###

View File

@ -0,0 +1,6 @@
[Airsonic]
prefix = https://
url = your-website.com
icon = static/images/apps/airsonic.png
description = A Free and Open Source community driven media server
open_in = this_tab

6
template_apps/Bazarr.ini Normal file
View File

@ -0,0 +1,6 @@
[Bazarr]
prefix = https://
url = your-website.com
icon = static/images/apps/bazarr.png
description = A companion application to Sonarr and Radarr
open_in = this_tab

View File

@ -0,0 +1,6 @@
[Bitwarden]
prefix = https://
url = your-website.com
icon = static/images/apps/bitwarden.png
description = A free and open-source password management service
open_in = this_tab

View File

@ -0,0 +1,7 @@
[BookStack]
prefix = https://
url = your-website.com
icon = static/images/apps/bookstack.png
sidebar_icon = static/images/apps/bookstack.png
description = BookStack is a simple, self-hosted, easy-to-use platform for organising and storing information
open_in = this_tab

21
template_apps/Deluge.ini Normal file
View File

@ -0,0 +1,21 @@
# -----------------
# App config entry
# -----------------
[Deluge]
prefix = https://
url = your-website.com
icon = static/images/apps/deluge.png
description = Deluge is a lightweight, Free Software, cross-platform BitTorrent client
open_in = this_tab
# -----------------------------------------------------------
# Data Source (place this above the app entry in config.ini)
# -----------------------------------------------------------
[variable_name]
platform = deluge
resource = https://deluge.example.com:8112/json
value_template = ↓{{download_rate|filesizeformat}}/s ↑{{upload_rate|filesizeformat}}/s
password = MySecretPassword
# then add to the app config entry:
data_sources = variable name

6
template_apps/Emby.ini Normal file
View File

@ -0,0 +1,6 @@
[Emby]
prefix = https://
url = your-website.com
icon = static/images/apps/emby.png
description = Emby Server is a personal media server with apps on just about every device
open_in = this_tab

6
template_apps/Gitea.ini Normal file
View File

@ -0,0 +1,6 @@
[Gitea]
prefix = https://
url = your-website.com
icon = static/images/apps/gitea.png
description = A painless self-hosted Git service
open_in = this_tab

View File

@ -0,0 +1,7 @@
[HandBrake]
prefix = https://
url = your-website.com
icon = static/images/apps/handbrake.png
sidebar_icon = static/images/icons/handbrake.png
description = HandBrake is an open-source, GPL-licensed, multiplatform, multithreaded video transcoder
open_in = this_tab

View File

@ -0,0 +1,6 @@
[Home Assistant]
prefix = https://
url = your-website.com
icon = static/images/apps/home-assistant.png
description = Open source home automation that puts local control and privacy first
open_in = this_tab

View File

@ -0,0 +1,6 @@
[Jackett]
prefix = https://
url = your-website.com
icon = static/images/apps/jackett.png
description = API Support for your favorite torrent trackers
open_in = this_tab

View File

@ -0,0 +1,6 @@
[Jellyfin]
prefix = https://
url = your-website.com
icon = static/images/apps/jellyfin.png
description = The Free Software Media System
open_in = this_tab

6
template_apps/Lidarr.ini Normal file
View File

@ -0,0 +1,6 @@
[Lidarr]
prefix = https://
url = your-website.com
icon = static/images/apps/lidarr.png
description = Looks and smells like Sonarr but made for music
open_in = this_tab

View File

@ -0,0 +1,6 @@
[Nextcloud]
prefix = https://
url = your-website.com
icon = static/images/apps/nextcloud.png
description = A safe home for all your data community-driven, free & open source
open_in = this_tab

View File

@ -0,0 +1,6 @@
[Nginx Proxy Manager]
prefix = https://
url = your-website.com
icon = static/images/apps/nginxproxymanager.png
description = Docker container for managing Nginx proxy hosts with a simple, powerful interface
open_in = this_tab

View File

@ -0,0 +1,7 @@
[OPNsense]
prefix = https://
url = your-website.com
icon = static/images/apps/opnsense.png
sidebar_icon = static/images/apps/opnsense.png
description = Secure Your Network with ease. From Virtual Private Networking to Intrusion Detection, Best in class, FREE Open Source Project
open_in = this_tab

6
template_apps/Ombi.ini Normal file
View File

@ -0,0 +1,6 @@
[Ombi]
prefix = https://
url = your-website.com
icon = static/images/apps/ombi.png
description = Want a Movie or TV Show on Plex or Emby? Use Ombi!
open_in = this_tab

View File

@ -0,0 +1,7 @@
[Pi-hole]
prefix = https://
url = your-website.com
icon = static/images/apps/pihole.png
sidebar_icon = static/images/apps/pihole.png
description = A black hole for Internet advertisements
open_in = this_tab

View File

@ -0,0 +1,6 @@
[Portainer]
prefix = https://
url = your-website.com
icon = static/images/apps/portainer.png
description = Making Docker management easy
open_in = this_tab

6
template_apps/Radarr.ini Normal file
View File

@ -0,0 +1,6 @@
[Radarr]
prefix = https://
url = your-website.com
icon = static/images/apps/radarr.png
description = A fork of Sonarr to work with movies à la Couchpotato
open_in = this_tab

6
template_apps/Riot.ini Normal file
View File

@ -0,0 +1,6 @@
[Riot]
prefix = https://
url = your-website.com
icon = static/images/apps/riot.png
description = A glossy Matrix collaboration client for the web
open_in = this_tab

6
template_apps/SSH.ini Normal file
View File

@ -0,0 +1,6 @@
[SSH]
prefix = https://
url = your-website.com
icon = static/images/apps/terminal.png
description = SSH, terminal, shell, shellinabox
open_in = this_tab

6
template_apps/Sonarr.ini Normal file
View File

@ -0,0 +1,6 @@
[Sonarr]
prefix = https://
url = your-website.com
icon = static/images/apps/sonarr.png
description = Smart PVR for newsgroup and bittorrent users
open_in = this_tab

View File

@ -0,0 +1,6 @@
[Syncthing]
prefix = https://
url = your-website.com
icon = static/images/apps/Syncthing.png
description = Open Source Continuous File Synchronization
open_in = this_tab

View File

@ -0,0 +1,6 @@
[Tautulli]
prefix = https://
url = your-website.com
icon = static/images/apps/tautulli.png
description = A Python based monitoring and tracking tool for Plex Media Server
open_in = this_tab

View File

@ -0,0 +1,6 @@
[The Lounge]
prefix = https://
url = your-website.com
icon = static/images/apps/thelounge.png
description = Modern, responsive, cross-platform, self-hosted web IRC client
open_in = this_tab

View File

@ -0,0 +1,6 @@
[Traefik]
prefix = https://
url = your-website.com
icon = static/images/apps/traefik.png
description = The Cloud Native Edge Router
open_in = this_tab