Domain management (activated, booleans)

This commit is contained in:
Cyrille L 2023-09-23 18:32:06 +02:00
parent 5f45caebe4
commit f5a7e6efaf
8 changed files with 42 additions and 20 deletions

View File

@ -33,11 +33,13 @@
#-------------------------- #--------------------------
import sys import sys
import domain, langs import domain, langs, debug
def manage(action, target): def manage(action, target):
# Load domain configuration, update if needed, check if valid # Load domain configuration, update if needed, check if valid
domain.valid_conf() if not domain.valid_conf():
debug.out(105, domain.conf_name, domain.dcf_uri, True, 1, True)
langs.load_website_lang() langs.load_website_lang()
print("check:", action, target, domain.dcf.get("DOMAIN", "name")) print("check:", action, target)

View File

@ -89,6 +89,7 @@ def out(nbr, var, val, show, color, stop):
102 : langs.logs.reset_dom, 102 : langs.logs.reset_dom,
103 : langs.logs.website_lang, 103 : langs.logs.website_lang,
104 : langs.logs.domains_no, 104 : langs.logs.domains_no,
105 : langs.logs.domain_off,
# Great (200-255) # Great (200-255)
200 : langs.logs.load_file, 200 : langs.logs.load_file,
201 : langs.logs.lang_logs_sys, 201 : langs.logs.lang_logs_sys,

View File

@ -184,14 +184,27 @@ def dcf_update_values(srv):
srv_wip = os.path.join(srv_dom, "wip/") srv_wip = os.path.join(srv_dom, "wip/")
srv_www = os.path.join(srv_dom, "www/") srv_www = os.path.join(srv_dom, "www/")
# Set booleans if invalid values
try: dcf.getboolean("DOMAIN", "activated")
except: dcf.set("DOMAIN", "activated", "no")
try: dcf.getboolean("WEBSITE", "article_code")
except: dcf.set("WEBSITE", "article_code", "yes")
try: dcf.getboolean("WEBSITE", "static")
except: dcf.set("WEBSITE", "static", "no")
try: dcf.getboolean("WEBSITE_MODULES", "sitemaps")
except: dcf.set("WEBSITE_MODULES", "sitemaps", "yes")
# Set template filenames to default if none
favicon = dcf.get("TEMPLATE_FILENAMES", "favicon") or "favicon.png" favicon = dcf.get("TEMPLATE_FILENAMES", "favicon") or "favicon.png"
logo = dcf.get("TEMPLATE_FILENAMES", "logo") or "logo.png" logo = dcf.get("TEMPLATE_FILENAMES", "logo") or "logo.png"
styles = dcf.get("TEMPLATE_FILENAMES", "styles") or "styles.css" styles = dcf.get("TEMPLATE_FILENAMES", "styles") or "styles.css"
rss = dcf.get("TEMPLATE_FILENAMES", "rss") or "rss.xml" rss = dcf.get("TEMPLATE_FILENAMES", "rss") or "rss.xml"
stats = dcf.get("TEMPLATE_FILENAMES", "stats") or "stats.ini" stats = dcf.get("TEMPLATE_FILENAMES", "stats") or "stats.ini"
www_url = dcf.get("WEBSITE", "www_url") dcf.get("WEBSITE", "www_url") or \
wip_url = dcf.get("WEBSITE", "wip_url") dcf.set("WEBSITE", "www_url", "https://%s/"%conf_name)
dcf.get("WEBSITE", "wip_url") or \
dcf.set("WEBSITE", "wip_url", create_wip_url())
usr_mods = os.path.join(dcf_dir + "modules/") usr_mods = os.path.join(dcf_dir + "modules/")
usr_tpl = os.path.join(dcf_dir, "template/") usr_tpl = os.path.join(dcf_dir, "template/")
@ -242,8 +255,6 @@ def dcf_update_values(srv):
# WEBSITE # WEBSITE
dcf.set("WEBSITE", "lang", langs.site_lang) 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.get("WEBSITE_MODULES", "sidebar_title") or \
dcf.set("WEBSITE_MODULES", "sidebar_title", langs.site.sidebar_title) dcf.set("WEBSITE_MODULES", "sidebar_title", langs.site.sidebar_title)
dcf.get("WEBSITE_MODULES", "sidebar_items").isdigit() or \ dcf.get("WEBSITE_MODULES", "sidebar_items").isdigit() or \
@ -324,24 +335,18 @@ def dcf_update_values(srv):
# Ensure domain is valid and ready to be used # # Ensure domain is valid and ready to be used #
#---------------------------------------------# #---------------------------------------------#
def valid_conf(): def valid_conf():
dcf_load() global active
# Most importants dcf_load()
# - dcf name must be config_name # - dcf name must be config_name
# - root server must exists try: dcf_name = dcf.get("DOMAIN", "name")
try: except: debug.out(100, conf_name, dcf_uri, True, 2, True)
dcf_name = dcf.get("DOMAIN", "name")
if dcf_name != conf_name: if dcf_name != conf_name:
debug.out(100, conf_name, dcf_uri, True, 2, True) debug.out(100, conf_name, dcf_uri, True, 2, True)
except:
debug.out(100, conf_name, dcf_uri, True, 2, True)
# - root server must exists
# Server root
try: dcf_srv = dcf.get("SERVER", "root") try: dcf_srv = dcf.get("SERVER", "root")
except: debug.out(100, "SERVER root", "?", True, 2, True) except: debug.out(100, "SERVER root", "?", True, 2, True)
if not dcf_srv or not tools.dir_exists(dcf_srv, True): if not dcf_srv or not tools.dir_exists(dcf_srv, True):
debug.out(100, "SERVER root", "? %s"%dcf_srv, True, 2, True) debug.out(100, "SERVER root", "? %s"%dcf_srv, True, 2, True)
@ -366,6 +371,19 @@ def valid_conf():
if now_dcf_hash != ult_dcf_hash: if now_dcf_hash != ult_dcf_hash:
dcf_update_values("") dcf_update_values("")
return is_active()
#==============================#
# Check if domain is activated #
# Return True or False
#------------------------------#
def is_active():
dcf_load()
# Domain activated ?
try: return dcf.getboolean("DOMAIN", "activated")
except: return False
#======#======================================================================= #======#=======================================================================
# MAIN # # MAIN #

View File

@ -59,6 +59,7 @@ err_cr_file = "Fichier non créé"
# Warnings # Warnings
warn_no_dom = "Domaine non configuré" warn_no_dom = "Domaine non configuré"
domain_off = "Domaine désactivé"
reset_dom = "RÉINITIALISE le domaine" reset_dom = "RÉINITIALISE le domaine"
# infos # infos