mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-01-24 12:47:05 +00:00
Fixed PLC1901 (compare-to-empty-string)
This commit is contained in:
parent
385ac086e6
commit
1782b69405
@ -52,7 +52,7 @@ class AuthService:
|
|||||||
msg = "Authorization header invalid."
|
msg = "Authorization header invalid."
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
if username.strip() == "" and password.strip() == "":
|
if not username.strip() and not password.strip():
|
||||||
msg = "No email address, password, session key, or API key provided."
|
msg = "No email address, password, session key, or API key provided."
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ class AuthService:
|
|||||||
self.sessions[sessionid] = session
|
self.sessions[sessionid] = session
|
||||||
|
|
||||||
# If no password was given, but a username was given, we're missing some information.
|
# If no password was given, but a username was given, we're missing some information.
|
||||||
elif password.strip() == "":
|
elif not password.strip():
|
||||||
msg = "Enter a password."
|
msg = "Enter a password."
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ def list_target_files(config):
|
|||||||
if path == '/':
|
if path == '/':
|
||||||
path = ''
|
path = ''
|
||||||
|
|
||||||
if bucket == "":
|
if not bucket:
|
||||||
msg = "Enter an S3 bucket name."
|
msg = "Enter an S3 bucket name."
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ with contextlib.suppress(OSError):
|
|||||||
csr_country_codes = []
|
csr_country_codes = []
|
||||||
with open(os.path.join(os.path.dirname(me), "csr_country_codes.tsv"), encoding="utf-8") as f:
|
with open(os.path.join(os.path.dirname(me), "csr_country_codes.tsv"), encoding="utf-8") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if line.strip() == "" or line.startswith("#"): continue
|
if not line.strip() or line.startswith("#"): continue
|
||||||
code, name = line.strip().split("\t")[0:2]
|
code, name = line.strip().split("\t")[0:2]
|
||||||
csr_country_codes.append((code, name))
|
csr_country_codes.append((code, name))
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ def dns_get_secondary_nameserver():
|
|||||||
def dns_set_secondary_nameserver():
|
def dns_set_secondary_nameserver():
|
||||||
from dns_update import set_secondary_dns
|
from dns_update import set_secondary_dns
|
||||||
try:
|
try:
|
||||||
return set_secondary_dns([ns.strip() for ns in re.split(r"[, ]+", request.form.get('hostnames') or "") if ns.strip() != ""], env)
|
return set_secondary_dns([ns.strip() for ns in re.split(r"[, ]+", request.form.get('hostnames') or "") if ns.strip()], env)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return (str(e), 400)
|
return (str(e), 400)
|
||||||
|
|
||||||
@ -352,11 +352,11 @@ def dns_set_record(qname, rtype="A"):
|
|||||||
|
|
||||||
if request.method in {"POST", "PUT"}:
|
if request.method in {"POST", "PUT"}:
|
||||||
# There is a default value for A/AAAA records.
|
# There is a default value for A/AAAA records.
|
||||||
if rtype in {"A", "AAAA"} and value == "":
|
if rtype in {"A", "AAAA"} and not value:
|
||||||
value = request.environ.get("HTTP_X_FORWARDED_FOR") # normally REMOTE_ADDR but we're behind nginx as a reverse proxy
|
value = request.environ.get("HTTP_X_FORWARDED_FOR") # normally REMOTE_ADDR but we're behind nginx as a reverse proxy
|
||||||
|
|
||||||
# Cannot add empty records.
|
# Cannot add empty records.
|
||||||
if value == '':
|
if not value:
|
||||||
return ("No value for the record provided.", 400)
|
return ("No value for the record provided.", 400)
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
@ -370,7 +370,7 @@ def dns_set_record(qname, rtype="A"):
|
|||||||
action = "set"
|
action = "set"
|
||||||
|
|
||||||
elif request.method == "DELETE":
|
elif request.method == "DELETE":
|
||||||
if value == '':
|
if not value:
|
||||||
# Delete all records for this qname-type pair.
|
# Delete all records for this qname-type pair.
|
||||||
value = None
|
value = None
|
||||||
else:
|
else:
|
||||||
@ -678,7 +678,7 @@ def authorized_personnel_only_via_cookie(f):
|
|||||||
@authorized_personnel_only_via_cookie
|
@authorized_personnel_only_via_cookie
|
||||||
def munin_static_file(filename=""):
|
def munin_static_file(filename=""):
|
||||||
# Proxy the request to static files.
|
# Proxy the request to static files.
|
||||||
if filename == "": filename = "index.html"
|
if not filename: filename = "index.html"
|
||||||
return send_from_directory("/var/cache/munin/www", filename)
|
return send_from_directory("/var/cache/munin/www", filename)
|
||||||
|
|
||||||
@app.route('/munin/cgi-graph/<path:filename>')
|
@app.route('/munin/cgi-graph/<path:filename>')
|
||||||
@ -707,7 +707,7 @@ def munin_cgi(filename):
|
|||||||
# -c "/usr/lib/munin/cgi/munin-cgi-graph" passes the command to run as munin
|
# -c "/usr/lib/munin/cgi/munin-cgi-graph" passes the command to run as munin
|
||||||
# "%s" is a placeholder for where the request's querystring will be added
|
# "%s" is a placeholder for where the request's querystring will be added
|
||||||
|
|
||||||
if filename == "":
|
if not filename:
|
||||||
return ("a path must be specified", 404)
|
return ("a path must be specified", 404)
|
||||||
|
|
||||||
query_str = request.query_string.decode("utf-8", 'ignore')
|
query_str = request.query_string.decode("utf-8", 'ignore')
|
||||||
|
@ -264,7 +264,7 @@ def build_zone(domain, domain_properties, additional_records, env, is_zone=True)
|
|||||||
(None, "AAAA", env.get('PUBLIC_IPV6'), f"Optional. Sets the IPv6 address that {domain} resolves to, e.g. for web hosting. (It is not necessary for receiving mail on this domain.)"),
|
(None, "AAAA", env.get('PUBLIC_IPV6'), f"Optional. Sets the IPv6 address that {domain} resolves to, e.g. for web hosting. (It is not necessary for receiving mail on this domain.)"),
|
||||||
]
|
]
|
||||||
for qname, rtype, value, explanation in defaults:
|
for qname, rtype, value, explanation in defaults:
|
||||||
if value is None or value.strip() == "": continue # skip IPV6 if not set
|
if value is None or not value.strip(): continue # skip IPV6 if not set
|
||||||
if not is_zone and qname == "www": continue # don't create any default 'www' subdomains on what are themselves subdomains
|
if not is_zone and qname == "www": continue # don't create any default 'www' subdomains on what are themselves subdomains
|
||||||
# Set the default record, but not if:
|
# Set the default record, but not if:
|
||||||
# (1) there is not a user-set record of the same type already
|
# (1) there is not a user-set record of the same type already
|
||||||
@ -456,7 +456,7 @@ def build_sshfp_records():
|
|||||||
keys = sorted(keys.split("\n"))
|
keys = sorted(keys.split("\n"))
|
||||||
|
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key.strip() == "" or key[0] == "#": continue
|
if not key.strip() or key[0] == "#": continue
|
||||||
try:
|
try:
|
||||||
_host, keytype, pubkey = key.split(" ")
|
_host, keytype, pubkey = key.split(" ")
|
||||||
yield "%d %d ( %s )" % (
|
yield "%d %d ( %s )" % (
|
||||||
|
@ -28,7 +28,7 @@ admin_addr = "administrator@" + env['PRIMARY_HOSTNAME']
|
|||||||
content = sys.stdin.read().strip()
|
content = sys.stdin.read().strip()
|
||||||
|
|
||||||
# If there's nothing coming in, just exit.
|
# If there's nothing coming in, just exit.
|
||||||
if content == "":
|
if not content:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# create MIME message
|
# create MIME message
|
||||||
|
@ -268,7 +268,7 @@ def get_mail_domains(env, filter_aliases=lambda alias : True, users_only=False):
|
|||||||
|
|
||||||
def add_mail_user(email, pw, privs, env):
|
def add_mail_user(email, pw, privs, env):
|
||||||
# validate email
|
# validate email
|
||||||
if email.strip() == "":
|
if not email.strip():
|
||||||
return ("No email address provided.", 400)
|
return ("No email address provided.", 400)
|
||||||
if not validate_email(email):
|
if not validate_email(email):
|
||||||
return ("Invalid email address.", 400)
|
return ("Invalid email address.", 400)
|
||||||
@ -284,7 +284,7 @@ def add_mail_user(email, pw, privs, env):
|
|||||||
validate_password(pw)
|
validate_password(pw)
|
||||||
|
|
||||||
# validate privileges
|
# validate privileges
|
||||||
if privs is None or privs.strip() == "":
|
if privs is None or not privs.strip():
|
||||||
privs = []
|
privs = []
|
||||||
else:
|
else:
|
||||||
privs = privs.split("\n")
|
privs = privs.split("\n")
|
||||||
@ -357,7 +357,7 @@ def remove_mail_user(email, env):
|
|||||||
return kick(env, "mail user removed")
|
return kick(env, "mail user removed")
|
||||||
|
|
||||||
def parse_privs(value):
|
def parse_privs(value):
|
||||||
return [p for p in value.split("\n") if p.strip() != ""]
|
return [p for p in value.split("\n") if p.strip()]
|
||||||
|
|
||||||
def get_mail_user_privileges(email, env, empty_on_error=False):
|
def get_mail_user_privileges(email, env, empty_on_error=False):
|
||||||
# get privs
|
# get privs
|
||||||
@ -370,7 +370,7 @@ def get_mail_user_privileges(email, env, empty_on_error=False):
|
|||||||
return parse_privs(rows[0][0])
|
return parse_privs(rows[0][0])
|
||||||
|
|
||||||
def validate_privilege(priv):
|
def validate_privilege(priv):
|
||||||
if "\n" in priv or priv.strip() == "":
|
if "\n" in priv or not priv.strip():
|
||||||
return (f"That's not a valid privilege ({priv}).", 400)
|
return (f"That's not a valid privilege ({priv}).", 400)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -411,7 +411,7 @@ def add_mail_alias(address, forwards_to, permitted_senders, env, update_if_exist
|
|||||||
|
|
||||||
# validate address
|
# validate address
|
||||||
address = address.strip()
|
address = address.strip()
|
||||||
if address == "":
|
if not address:
|
||||||
return ("No email address provided.", 400)
|
return ("No email address provided.", 400)
|
||||||
if not validate_email(address, mode='alias'):
|
if not validate_email(address, mode='alias'):
|
||||||
return (f"Invalid email address ({address}).", 400)
|
return (f"Invalid email address ({address}).", 400)
|
||||||
@ -438,7 +438,7 @@ def add_mail_alias(address, forwards_to, permitted_senders, env, update_if_exist
|
|||||||
for line in forwards_to.split("\n"):
|
for line in forwards_to.split("\n"):
|
||||||
for email in line.split(","):
|
for email in line.split(","):
|
||||||
email = email.strip()
|
email = email.strip()
|
||||||
if email == "": continue
|
if not email: continue
|
||||||
email = sanitize_idn_email_address(email) # Unicode => IDNA
|
email = sanitize_idn_email_address(email) # Unicode => IDNA
|
||||||
# Strip any +tag from email alias and check privileges
|
# Strip any +tag from email alias and check privileges
|
||||||
privileged_email = re.sub(r"(?=\+)[^@]*(?=@)",'',email)
|
privileged_email = re.sub(r"(?=\+)[^@]*(?=@)",'',email)
|
||||||
@ -461,7 +461,7 @@ def add_mail_alias(address, forwards_to, permitted_senders, env, update_if_exist
|
|||||||
for line in permitted_senders.split("\n"):
|
for line in permitted_senders.split("\n"):
|
||||||
for login in line.split(","):
|
for login in line.split(","):
|
||||||
login = login.strip()
|
login = login.strip()
|
||||||
if login == "": continue
|
if not login: continue
|
||||||
if login not in valid_logins:
|
if login not in valid_logins:
|
||||||
return (f"Invalid permitted sender: {login} is not a user on this system.", 400)
|
return (f"Invalid permitted sender: {login} is not a user on this system.", 400)
|
||||||
validated_permitted_senders.append(login)
|
validated_permitted_senders.append(login)
|
||||||
@ -598,11 +598,11 @@ def kick(env, mail_result=None):
|
|||||||
from web_update import do_web_update
|
from web_update import do_web_update
|
||||||
results.append( do_web_update(env) )
|
results.append( do_web_update(env) )
|
||||||
|
|
||||||
return "".join(s for s in results if s != "")
|
return "".join(s for s in results if s)
|
||||||
|
|
||||||
def validate_password(pw):
|
def validate_password(pw):
|
||||||
# validate password
|
# validate password
|
||||||
if pw.strip() == "":
|
if not pw.strip():
|
||||||
msg = "No password provided."
|
msg = "No password provided."
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
if len(pw) < 8:
|
if len(pw) < 8:
|
||||||
|
@ -68,7 +68,7 @@ def disable_mfa(email, mfa_id, env):
|
|||||||
return c.rowcount > 0
|
return c.rowcount > 0
|
||||||
|
|
||||||
def validate_totp_secret(secret):
|
def validate_totp_secret(secret):
|
||||||
if not isinstance(secret, str) or secret.strip() == "":
|
if not isinstance(secret, str) or not secret.strip():
|
||||||
msg = "No secret provided."
|
msg = "No secret provided."
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
if len(secret) != 32:
|
if len(secret) != 32:
|
||||||
|
@ -918,7 +918,7 @@ def list_apt_updates(apt_update=True):
|
|||||||
simulated_install = shell("check_output", ["/usr/bin/apt-get", "-qq", "-s", "upgrade"])
|
simulated_install = shell("check_output", ["/usr/bin/apt-get", "-qq", "-s", "upgrade"])
|
||||||
pkgs = []
|
pkgs = []
|
||||||
for line in simulated_install.split('\n'):
|
for line in simulated_install.split('\n'):
|
||||||
if line.strip() == "":
|
if not line.strip():
|
||||||
continue
|
continue
|
||||||
if re.match(r'^Conf .*', line):
|
if re.match(r'^Conf .*', line):
|
||||||
# remove these lines, not informative
|
# remove these lines, not informative
|
||||||
@ -1082,7 +1082,7 @@ class FileOutput:
|
|||||||
print(file=self.buf)
|
print(file=self.buf)
|
||||||
print(" ", end="", file=self.buf)
|
print(" ", end="", file=self.buf)
|
||||||
linelen = 0
|
linelen = 0
|
||||||
if linelen == 0 and w.strip() == "": continue
|
if linelen == 0 and not w.strip(): continue
|
||||||
print(w, end="", file=self.buf)
|
print(w, end="", file=self.buf)
|
||||||
linelen += len(w)
|
linelen += len(w)
|
||||||
print(file=self.buf)
|
print(file=self.buf)
|
||||||
|
@ -171,7 +171,7 @@ def strip_indent(s):
|
|||||||
class Comment(Grammar):
|
class Comment(Grammar):
|
||||||
grammar = ONE_OR_MORE(ZERO_OR_MORE(SPACE), L('#'), REST_OF_LINE, EOL)
|
grammar = ONE_OR_MORE(ZERO_OR_MORE(SPACE), L('#'), REST_OF_LINE, EOL)
|
||||||
def value(self):
|
def value(self):
|
||||||
if self.string.replace("#", "").strip() == "":
|
if not self.string.replace("#", "").strip():
|
||||||
return "\n"
|
return "\n"
|
||||||
lines = [x[2].string for x in self[0]]
|
lines = [x[2].string for x in self[0]]
|
||||||
content = "\n".join(lines)
|
content = "\n".join(lines)
|
||||||
@ -273,7 +273,7 @@ class RestartService(Grammar):
|
|||||||
class OtherLine(Grammar):
|
class OtherLine(Grammar):
|
||||||
grammar = (REST_OF_LINE, EOL)
|
grammar = (REST_OF_LINE, EOL)
|
||||||
def value(self):
|
def value(self):
|
||||||
if self.string.strip() == "": return ""
|
if not self.string.strip(): return ""
|
||||||
if "source setup/functions.sh" in self.string: return ""
|
if "source setup/functions.sh" in self.string: return ""
|
||||||
if "source /etc/mailinabox.conf" in self.string: return ""
|
if "source /etc/mailinabox.conf" in self.string: return ""
|
||||||
return "<pre class='shell'><div>" + recode_bash(self.string.strip()) + "</div></pre>\n"
|
return "<pre class='shell'><div>" + recode_bash(self.string.strip()) + "</div></pre>\n"
|
||||||
@ -417,7 +417,7 @@ class BashScript(Grammar):
|
|||||||
|
|
||||||
mode = 0
|
mode = 0
|
||||||
for item in result.value():
|
for item in result.value():
|
||||||
if item.strip() == "":
|
if not item.strip():
|
||||||
pass
|
pass
|
||||||
elif item.startswith("<p") and not item.startswith("<pre"):
|
elif item.startswith("<p") and not item.startswith("<pre"):
|
||||||
clz = ""
|
clz = ""
|
||||||
@ -474,7 +474,7 @@ def wrap_lines(text, cols=60):
|
|||||||
ret += " \\\n"
|
ret += " \\\n"
|
||||||
ret += " "
|
ret += " "
|
||||||
linelen = 0
|
linelen = 0
|
||||||
if linelen == 0 and w.strip() == "": continue
|
if linelen == 0 and not w.strip(): continue
|
||||||
ret += w
|
ret += w
|
||||||
linelen += len(w)
|
linelen += len(w)
|
||||||
return ret
|
return ret
|
||||||
|
Loading…
Reference in New Issue
Block a user