Better domain control and validation
This commit is contained in:
parent
6a17add248
commit
5f45caebe4
26 changed files with 100 additions and 71 deletions
|
@ -7,7 +7,10 @@ Tyto - Littérateur
|
|||
- License:
|
||||
- Documentation:
|
||||
|
||||
## [1.9.0]
|
||||
## [1.9.1]
|
||||
- Auto update configuration domain
|
||||
- Better managing configuration domain values
|
||||
- Better checking if valid domain
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -12,3 +12,5 @@ tyto
|
|||
- - needs more checks to be validated
|
||||
- english logs translation file (French only, for now)
|
||||
|
||||
# Next
|
||||
- Create all directories for valid domain
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
# Version: 1.9.0
|
||||
# Version: 1.9.1
|
||||
# Updated: 2023-09-23 1695429475
|
||||
# Tyto - Littérateur
|
||||
|
||||
# Copyright (C) 2023 Cyrille Louarn <echolib+tyto@a-lec.org>
|
||||
|
@ -40,9 +41,9 @@
|
|||
# file program :
|
||||
#--------------------------
|
||||
|
||||
#======#
|
||||
# MAIN #
|
||||
#======#=======================================================================
|
||||
# MAIN #
|
||||
#======#
|
||||
import sys
|
||||
if not __name__ == "__main__":
|
||||
print("! Error: '%s' not '%s'"%(__name__, "__main__"))
|
||||
|
|
BIN
src/var/lib/tyto/program/__pycache__/args.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/args.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/check.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/debug.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/debug.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/domain.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/forms.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/forms.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/help.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/help.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/langs.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/langs.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/new.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/new.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/show.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/show.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/tools.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/tyto.cpython-311.pyc
Normal file
Binary file not shown.
BIN
src/var/lib/tyto/program/__pycache__/userset.cpython-311.pyc
Normal file
BIN
src/var/lib/tyto/program/__pycache__/userset.cpython-311.pyc
Normal file
Binary file not shown.
|
@ -45,7 +45,6 @@ def get_action():
|
|||
except: action = ""
|
||||
|
||||
|
||||
|
||||
#==================#
|
||||
# Target arguments #
|
||||
#------------------#
|
||||
|
@ -63,9 +62,9 @@ def get_options():
|
|||
|
||||
dlogs = force = erron = False
|
||||
for arg in range(1, len(sys.argv)):
|
||||
if sys.argv[arg] in tyto.debug_options: dlogs = True
|
||||
if sys.argv[arg] in tyto.force_options: force = True
|
||||
if sys.argv[arg] in tyto.debug_errors: erron = True
|
||||
dlogs = sys.argv[arg] in tyto.debug_options
|
||||
force = sys.argv[arg] in tyto.force_options
|
||||
erron = sys.argv[arg] in tyto.debug_errors
|
||||
|
||||
|
||||
#===========#
|
||||
|
@ -74,7 +73,7 @@ def get_options():
|
|||
def valid_action():
|
||||
global action
|
||||
if not action in tyto.actions:
|
||||
debug.out(1, "[action]", action, dlogs,2, False)
|
||||
debug.out(1, "[action]", action, False, 2, False)
|
||||
action = "help"
|
||||
|
||||
|
||||
|
|
|
@ -33,11 +33,11 @@
|
|||
#--------------------------
|
||||
|
||||
import sys
|
||||
import domain
|
||||
import domain, langs
|
||||
|
||||
|
||||
def manage(action, target):
|
||||
# Load domain configuration, update if needed, check if valid
|
||||
domain.valid_conf()
|
||||
|
||||
langs.load_website_lang()
|
||||
print("check:", action, target, domain.dcf.get("DOMAIN", "name"))
|
||||
|
|
|
@ -37,8 +37,8 @@ import langs, args
|
|||
|
||||
|
||||
#===================================#
|
||||
# Show logs if "show" is True #
|
||||
# -D argument for specific ones #
|
||||
# Show all logs if "show" is True #
|
||||
# or with -D argument #
|
||||
# color is for "*" in message #
|
||||
# - 3 colors levels: #
|
||||
# - - 0 = Green #
|
||||
|
@ -48,8 +48,11 @@ import langs, args
|
|||
#-----------------------------------#
|
||||
def out(nbr, var, val, show, color, stop):
|
||||
args.get_options()
|
||||
if not show and not args.dlogs: return # Show Very less logs
|
||||
if args.erron and color == 0: return # Show only warn and error logs
|
||||
if not show:
|
||||
show = args.dlogs or args.erron and color > 0 # Show only warn and error logs
|
||||
|
||||
if not show:
|
||||
return
|
||||
|
||||
# COlors
|
||||
CS = '\033[0;0m' # Unset
|
||||
|
|
|
@ -100,43 +100,12 @@ def dcf_exists():
|
|||
return True
|
||||
else:
|
||||
try: shown_no
|
||||
except: debug.out(100, "False", dcf_uri, True, 1, False)
|
||||
except: debug.out(104, "False", dcf_uri, True, 1, False)
|
||||
shown_no = True
|
||||
compatible_name()
|
||||
return False
|
||||
|
||||
|
||||
#=============================================#
|
||||
# Ensure domain is valid and ready to be used #
|
||||
#---------------------------------------------#
|
||||
def valid_conf():
|
||||
dcf_load()
|
||||
try:
|
||||
dcf_name = dcf.get("DOMAIN", "name")
|
||||
except:
|
||||
debug.out(100, conf_name, dcf_uri, True, 1, True)
|
||||
|
||||
# Check some values in ult_dcf
|
||||
ult_dcf_load()
|
||||
try:
|
||||
ult_dcf_name = ult_dcf.get("DOMAIN", "name")
|
||||
ult_dcf_hash = ult_dcf.get("DOMAIN", "hash")
|
||||
ult_dcf_conf = ult_dcf.get("DOMAIN", "conf")
|
||||
ult_dcf_root = ult_dcf.get("DOMAIN", "root")
|
||||
except:
|
||||
debug.out(100, conf_name, ult_dcf_uri, True, 1, True)
|
||||
|
||||
# Compare values (exit if mismatch)
|
||||
if ult_dcf_name != conf_name or \
|
||||
ult_dcf_conf != dcf_uri or \
|
||||
dcf_name != ult_dcf_name:
|
||||
debug.out(100, conf_name, "?", True, 1, True)
|
||||
|
||||
# Check if dcf need to be updated
|
||||
now_dcf_hash = tools.get_filesum(dcf_uri, True)
|
||||
if now_dcf_hash != ult_dcf_hash:
|
||||
dcf_update_values("")
|
||||
|
||||
|
||||
#=========================================#
|
||||
# Guess and return wip_url from conf_name #
|
||||
#-----------------------------------------#
|
||||
|
@ -204,28 +173,26 @@ def dcf_update_values(srv):
|
|||
dcf_load()
|
||||
|
||||
# Test server directory, and exit if not exists
|
||||
if not srv: srv = dcf.get("SERVER", "root") # Set from db if unknown
|
||||
if srv: tools.dir_exists(srv, True)
|
||||
srv = srv or dcf.get("SERVER", "root") # Set from db if unknown
|
||||
|
||||
# Test registred website lang
|
||||
# change to default lang sys, or "en" if no translation file
|
||||
# Load website lang file
|
||||
langs.load_website_lang()
|
||||
|
||||
srv_dom = os.path.join(srv, conf_name + "/")
|
||||
srv_wip = os.path.join(srv_dom, "wip/")
|
||||
srv_www = os.path.join(srv_dom, "www/")
|
||||
|
||||
favicon = dcf.get("TEMPLATE_FILENAMES", "favicon")
|
||||
logo = dcf.get("TEMPLATE_FILENAMES", "logo")
|
||||
styles = dcf.get("TEMPLATE_FILENAMES", "styles")
|
||||
rss = dcf.get("TEMPLATE_FILENAMES", "rss")
|
||||
stats = dcf.get("TEMPLATE_FILENAMES", "stats")
|
||||
favicon = dcf.get("TEMPLATE_FILENAMES", "favicon") or "favicon.png"
|
||||
logo = dcf.get("TEMPLATE_FILENAMES", "logo") or "logo.png"
|
||||
styles = dcf.get("TEMPLATE_FILENAMES", "styles") or "styles.css"
|
||||
rss = dcf.get("TEMPLATE_FILENAMES", "rss") or "rss.xml"
|
||||
stats = dcf.get("TEMPLATE_FILENAMES", "stats") or "stats.ini"
|
||||
|
||||
www_url = dcf.get("WEBSITE", "www_url")
|
||||
wip_url = dcf.get("WEBSITE", "wip_url")
|
||||
|
||||
sdb_title = dcf.get("WEBSITE_MODULES", "sidebar_title")
|
||||
|
||||
usr_mods = os.path.join(dcf_dir + "modules/")
|
||||
usr_tpl = os.path.join(dcf_dir, "template/")
|
||||
usr_favicon = os.path.join(usr_tpl, favicon)
|
||||
|
@ -262,11 +229,13 @@ def dcf_update_values(srv):
|
|||
dcf.set("USER_DIRS", "modules", usr_mods)
|
||||
dcf.set("USER_DIRS", "database", dcf_dir + ".db/")
|
||||
dcf.set("USER_DIRS", "template", usr_tpl)
|
||||
|
||||
dcf.set("USER_MODULES_FILES", "metas", usr_mods + "tyto_metas.raw")
|
||||
dcf.set("USER_MODULES_FILES", "header", usr_mods + "tyto_header.raw")
|
||||
dcf.set("USER_MODULES_FILES", "navbar", usr_mods + "tyto_navbar.raw")
|
||||
dcf.set("USER_MODULES_FILES", "sidebar", usr_mods + "tyto_sidebar.raw")
|
||||
dcf.set("USER_MODULES_FILES", "footer", usr_mods + "tyto_footer.raw")
|
||||
|
||||
dcf.set("USER_TEMPLATE_FILES", "favicon", usr_favicon)
|
||||
dcf.set("USER_TEMPLATE_FILES", "logo", usr_logo)
|
||||
dcf.set("USER_TEMPLATE_FILES", "styles", usr_styles)
|
||||
|
@ -275,8 +244,18 @@ def dcf_update_values(srv):
|
|||
dcf.set("WEBSITE", "lang", langs.site_lang)
|
||||
www_url or dcf.set("WEBSITE", "www_url", "https://%s/"%conf_name)
|
||||
wip_url or dcf.set("WEBSITE", "wip_url", create_wip_url())
|
||||
dcf.get("WEBSITE_MODULES", "sidebar_title") or \
|
||||
dcf.set("WEBSITE_MODULES", "sidebar_title", langs.site.sidebar_title)
|
||||
dcf.get("WEBSITE_MODULES", "sidebar_items").isdigit() or \
|
||||
dcf.set("WEBSITE_MODULES", "sidebar_items", "0")
|
||||
dcf.get("WEBSITE_MODULES", "rss_items").isdigit() or \
|
||||
dcf.set("WEBSITE_MODULES", "rss_items", "0")
|
||||
|
||||
sdb_title or dcf.set("WEBSITE_MODULES", "sidebar_title", langs.site.sidebar_title)
|
||||
dcf.set("TEMPLATE_FILENAMES", "favicon", favicon)
|
||||
dcf.set("TEMPLATE_FILENAMES", "logo", logo)
|
||||
dcf.set("TEMPLATE_FILENAMES", "styles", styles)
|
||||
dcf.set("TEMPLATE_FILENAMES", "rss", rss)
|
||||
dcf.set("TEMPLATE_FILENAMES", "stats", stats)
|
||||
|
||||
# SERVER
|
||||
dcf.set("SERVER", "root", srv)
|
||||
|
@ -341,6 +320,53 @@ def dcf_update_values(srv):
|
|||
debug.out(204, "True", dcf_uri, True, 0, False)
|
||||
|
||||
|
||||
#=============================================#
|
||||
# Ensure domain is valid and ready to be used #
|
||||
#---------------------------------------------#
|
||||
def valid_conf():
|
||||
dcf_load()
|
||||
|
||||
# Most importants
|
||||
# - dcf name must be config_name
|
||||
# - root server must exists
|
||||
try:
|
||||
dcf_name = dcf.get("DOMAIN", "name")
|
||||
if dcf_name != conf_name:
|
||||
debug.out(100, conf_name, dcf_uri, True, 2, True)
|
||||
except:
|
||||
debug.out(100, conf_name, dcf_uri, True, 2, True)
|
||||
|
||||
|
||||
|
||||
# Server root
|
||||
try: dcf_srv = dcf.get("SERVER", "root")
|
||||
except: debug.out(100, "SERVER root", "?", True, 2, True)
|
||||
|
||||
if not dcf_srv or not tools.dir_exists(dcf_srv, True):
|
||||
debug.out(100, "SERVER root", "? %s"%dcf_srv, True, 2, True)
|
||||
|
||||
# Check some values in ult_dcf
|
||||
ult_dcf_load()
|
||||
try:
|
||||
ult_dcf_name = ult_dcf.get("DOMAIN", "name")
|
||||
ult_dcf_hash = ult_dcf.get("DOMAIN", "hash")
|
||||
ult_dcf_conf = ult_dcf.get("DOMAIN", "conf")
|
||||
ult_dcf_root = ult_dcf.get("DOMAIN", "root")
|
||||
except:
|
||||
debug.out(100, conf_name, ult_dcf_uri, True, 1, True)
|
||||
|
||||
# Compare values (exit if mismatch)
|
||||
if ult_dcf_name != conf_name or \
|
||||
ult_dcf_conf != dcf_uri or \
|
||||
dcf_name != ult_dcf_name:
|
||||
debug.out(100, conf_name, "?", True, 1, True)
|
||||
|
||||
# Check if dcf need to be updated
|
||||
now_dcf_hash = tools.get_filesum(dcf_uri, True)
|
||||
if now_dcf_hash != ult_dcf_hash:
|
||||
dcf_update_values("")
|
||||
|
||||
|
||||
#======#=======================================================================
|
||||
# MAIN #
|
||||
#------#
|
||||
|
|
|
@ -225,10 +225,8 @@ def ask_domain_server():
|
|||
domain.dcf_load()
|
||||
srv = domain.dcf.get("SERVER", "root")
|
||||
|
||||
if srv:
|
||||
if not tools.dir_exists(srv, False):
|
||||
tested = True
|
||||
srv = ""
|
||||
if srv and not not tools.dir_exists(srv, False):
|
||||
srv = ""
|
||||
|
||||
q = "> %s (%s)%s "%(langs.logs.domain_srv, srv, langs.logs.q)
|
||||
answer = ask(q, False, srv)
|
||||
|
|
|
@ -114,7 +114,7 @@ def get_website_lang():
|
|||
site_lang = domain.dcf.get("WEBSITE", "lang")
|
||||
|
||||
if not translation_exists("website", site_lang, False):
|
||||
site_lang = get_sys_lang()
|
||||
site_lang = get_sys_lang() # or default "en"
|
||||
|
||||
tr_website_uri = tr_website_uri%(trfs, site_lang)
|
||||
|
||||
|
|
|
@ -56,11 +56,8 @@ def get_filesum(path, src):
|
|||
# Mainly used to check domain server dir #
|
||||
#----------------------------------------#
|
||||
def dir_exists(dir_path, out):
|
||||
exists = bool(os.path.exists(dir_path))
|
||||
|
||||
if not exists:
|
||||
if out: debug.out(6, "False", dir_path, True, 2, True)
|
||||
else: debug.out(6, "False", dir_path, True, 2, False)
|
||||
if not bool(os.path.exists(dir_path)):
|
||||
debug.out(6, "False", dir_path, out, 2, out)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -60,5 +60,5 @@ tyto [action] [target] [options]
|
|||
[options] ; multi-set
|
||||
--force, -F : force doing things...
|
||||
--debug, -D : show more logs
|
||||
--errors, -E : Show only warn and error logs
|
||||
--errors, -E : Show mainly warnings and errors logs
|
||||
"""
|
||||
|
|
|
@ -73,7 +73,7 @@ domain_new = "Domaine créé"
|
|||
created_dir = "Dossier créé"
|
||||
created_file = "Fichier créé"
|
||||
updated_file = "Fichier mis à jour"
|
||||
later = "Peut-être plus targ..."
|
||||
later = "Peut-être plus tard..."
|
||||
|
||||
|
||||
|
||||
|
@ -104,5 +104,5 @@ tyto [action] [target] [options]
|
|||
[options] ; multiples
|
||||
--force, -F : forcer à faire quelque chose...
|
||||
--debug, -D : montrer plus de logs
|
||||
--errors, -E : montrer uniquement les avertissement et erreurs
|
||||
--errors, -E : montrer surtout les avertissements et erreurs
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue