Skip to content

Commit

Permalink
Add ability to switch displaying hostname with custom text
Browse files Browse the repository at this point in the history
  • Loading branch information
kizniche committed Jan 11, 2024
1 parent 53674dd commit cf238cb
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This release also changes the Desktop grid width from 20 to 24, enabling the use

### Features

- Add ability to switch displaying hostname with custom text
- Add Step Line Series Type to Graph (Synchronous) Widget

### Miscellaneous
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""add hostname override setting
Revision ID: c7942284b74e
Revises: 16b28ef31b5b
Create Date: 2024-01-11 17:51:39.799272
"""
import sys
import os

sys.path.append(os.path.abspath(os.path.join(__file__, "../../../..")))

from alembic_db.alembic_post_utils import write_revision_post_alembic

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'c7942284b74e'
down_revision = '16b28ef31b5b'
branch_labels = None
depends_on = None


def upgrade():
write_revision_post_alembic(revision)

with op.batch_alter_table("misc") as batch_op:
batch_op.add_column(sa.Column('hostname_override', sa.Boolean))

op.execute(
'''
UPDATE misc
SET hostname_override=""
'''
)


def downgrade():
with op.batch_alter_table("misc") as batch_op:
batch_op.drop_column('hostname_override')
2 changes: 1 addition & 1 deletion mycodo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from config_translations import TRANSLATIONS as T

MYCODO_VERSION = '8.15.13'
ALEMBIC_VERSION = '16b28ef31b5b'
ALEMBIC_VERSION = 'c7942284b74e'

# FORCE UPGRADE MASTER
# Set True to enable upgrading to the master branch of the Mycodo repository.
Expand Down
1 change: 1 addition & 0 deletions mycodo/databases/models/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Misc(CRUDMixin, db.Model):
net_test_port = db.Column(db.Integer, default=53)
net_test_timeout = db.Column(db.Integer, default=3)
default_login_page = db.Column(db.String, default='password')
hostname_override = db.Column(db.String, default='')

# Measurement database
db_name = 'influxdb' # Default
Expand Down
1 change: 1 addition & 0 deletions mycodo/mycodo_flask/forms/forms_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class SettingsGeneral(FlaskForm):
index_page = StringField(lazy_gettext('Index Page'))
language = StringField(lazy_gettext('Language'))
rpyc_timeout = StringField(lazy_gettext('Pyro Timeout'))
hostname_override = StringField(lazy_gettext('Hostname Override'))
daemon_debug_mode = BooleanField(lazy_gettext('Enable Daemon Debug Logging'))
force_https = BooleanField(lazy_gettext('Force HTTPS'))
hide_success = BooleanField(lazy_gettext('Hide success messages'))
Expand Down
38 changes: 33 additions & 5 deletions mycodo/mycodo_flask/routes_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def create_admin():

language = None

try:
host = Misc.query.first().hostname_override
except:
host = None
if not host:
host = socket.gethostname()

# Find user-selected language in Mycodo/.language
try:
lang_path = os.path.join(INSTALL_DIRECTORY, ".language")
Expand Down Expand Up @@ -100,7 +107,7 @@ def create_admin():
form_create_admin=form_create_admin,
form_language=form_language,
form_notice=form_notice,
host=socket.gethostname(),
host=host,
language=language,
languages=LANGUAGES)

Expand Down Expand Up @@ -147,7 +154,7 @@ def create_admin():
form_create_admin=form_create_admin,
form_language=form_language,
form_notice=form_notice,
host=socket.gethostname(),
host=host,
language=language,
languages=LANGUAGES)

Expand Down Expand Up @@ -185,6 +192,13 @@ def login_password():

language = None

try:
host = Misc.query.first().hostname_override
except:
host = None
if not host:
host = socket.gethostname()

# Find user-selected language in Mycodo/.language
try:
lang_path = os.path.join(INSTALL_DIRECTORY, ".language")
Expand Down Expand Up @@ -256,7 +270,7 @@ def login_password():
dict_translation=TRANSLATIONS,
form_language=form_language,
form_login=form_login,
host=socket.gethostname(),
host=host,
language=language,
languages=LANGUAGES)

Expand All @@ -272,6 +286,13 @@ def login_keypad():
"error")
return redirect(url_for('routes_general.home'))

try:
host = Misc.query.first().hostname_override
except:
host = None
if not host:
host = socket.gethostname()

# Check if the user is banned from logging in (too many incorrect attempts)
if banned_from_login():
flash(gettext(
Expand All @@ -282,7 +303,7 @@ def login_keypad():

return render_template('login_keypad.html',
dict_translation=TRANSLATIONS,
host=socket.gethostname())
host=host)


@blueprint.route('/login_keypad_code/', methods=('GET', 'POST'))
Expand All @@ -304,6 +325,13 @@ def login_keypad_code(code):
"error")
return redirect(url_for('routes_general.home'))

try:
host = Misc.query.first().hostname_override
except:
host = None
if not host:
host = socket.gethostname()

# Check if the user is banned from logging in (too many incorrect attempts)
if banned_from_login():
flash(gettext(
Expand Down Expand Up @@ -335,7 +363,7 @@ def login_keypad_code(code):

return render_template('login_keypad.html',
dict_translation=TRANSLATIONS,
host=socket.gethostname())
host=host)


@blueprint.route("/logout")
Expand Down
7 changes: 6 additions & 1 deletion mycodo/mycodo_flask/routes_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def inject_variables():
"{err}".format(err=e))
daemon_status = '0'

if misc.hostname_override:
host = misc.hostname_override
else:
host = socket.gethostname()

languages_sorted = sorted(LANGUAGES.items(), key=operator.itemgetter(1))

return dict(current_user=flask_login.current_user,
Expand All @@ -74,7 +79,7 @@ def inject_variables():
hide_alert_success=misc.hide_alert_success,
hide_alert_warning=misc.hide_alert_warning,
hide_tooltips=misc.hide_tooltips,
host=socket.gethostname(),
host=host,
languages=languages_sorted,
mycodo_version=MYCODO_VERSION,
permission_view_settings=user_has_permission('view_settings', silent=True),
Expand Down
6 changes: 6 additions & 0 deletions mycodo/mycodo_flask/templates/settings/general.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ <h3 style="text-align: right; padding-bottom: 1.3em;"><a href="https://kizniche.
</select>
</div>
</div>
<div class="form-group">
{{form_settings_general.hostname_override.label(class_='col-sm-12 control-label checkbox-nopad')}}
<div class="col-sm-12">
{{form_settings_general.hostname_override(class_='form-control', value=misc.hostname_override, **{'title':_("Override the hostname with this text. Leave blank to use hostname.")})}}
</div>
</div>
<div class="form-group">
{{form_settings_general.rpyc_timeout.label(class_='col-sm-12 control-label checkbox-nopad')}}
<div class="col-sm-12">
Expand Down
1 change: 1 addition & 0 deletions mycodo/mycodo_flask/utils/utils_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def settings_general_mod(form):
force_https = mod_misc.force_https
mod_misc.force_https = form.force_https.data
mod_misc.rpyc_timeout = form.rpyc_timeout.data
mod_misc.hostname_override = form.hostname_override.data
mod_misc.daemon_debug_mode = form.daemon_debug_mode.data
mod_misc.hide_alert_success = form.hide_success.data
mod_misc.hide_alert_info = form.hide_info.data
Expand Down

0 comments on commit cf238cb

Please sign in to comment.