|
@@ -3,7 +3,7 @@
|
|
|
DIR = "/var/local/log/lcmlog-data"
|
|
|
FROM_DOMAIN = "lcm.mi.infn.it"
|
|
|
TO_ADDRESS = "working@lcm.mi.infn.it"
|
|
|
-REPLY_TO = True # Does this make sense?
|
|
|
+REPLY_TO = True
|
|
|
|
|
|
import os
|
|
|
import os.path
|
|
@@ -69,10 +69,20 @@ def main():
|
|
|
if kind != "150" and kind != "Admin": # We only have this two log types
|
|
|
raise KindError
|
|
|
if method == "POST":
|
|
|
- send_mail = input()
|
|
|
- auth(user_id, "POST", kind) # Check if the user can post for the requested kind
|
|
|
- log = sys.stdin.read() # Read the log content
|
|
|
- method_post(kind, user_name, date, tags, log, send_mail == "Yes")
|
|
|
+ optional_line = input()
|
|
|
+ auth(user_id, "POST", kind) # Check if the user can post for the requested kind
|
|
|
+ log = sys.stdin.read() # Read the log content
|
|
|
+ if optional_line == "MAIL":
|
|
|
+ send_mail = True
|
|
|
+ TO_ADDRESS = "working@lcm.mi.infn.it"
|
|
|
+ REPLY_TO = True
|
|
|
+ else:
|
|
|
+ send_mail = False
|
|
|
+ # optional_line consumes the input but it is not
|
|
|
+ # a recognized header, so it's
|
|
|
+ # the first line of the log
|
|
|
+ log = optional_line + log
|
|
|
+ method_post(kind, user_name, date, tags, log, send_mail)
|
|
|
elif method == "GET":
|
|
|
auth(user_id, "GET", kind) # Check if the user can get logs for the requested kind
|
|
|
user_to_find = input() # Read the user name of the log writer to search
|
|
@@ -228,12 +238,11 @@ def log_hash(name):
|
|
|
# True add the 'Reply-to: ' header to the email
|
|
|
def log_mail(kind, user_name, date, tags, log):
|
|
|
if REPLY_TO:
|
|
|
- subprocess.run("printf " + shlex.quote(log) + " | mail -s \"Log" + kind + " " + date + " " + tags +
|
|
|
- "\" -r " + user + FROM_DOMAIN + " -a \"Reply-to:" TO_ADDRESS + " \" -- "
|
|
|
- + TO_ADDRESS, shell=True)
|
|
|
+ subprocess.run('printf "%s\n" ' + f'{shlex.quote(log)} | mail -s "Log{kind} {date} {tags}" ' +
|
|
|
+ f'-r {user_name}@{FROM_DOMAIN} -S replyto="{TO_ADDRESS}" {TO_ADDRESS}', shell=True)
|
|
|
else:
|
|
|
- subprocess.run("printf \"%s\n\" " + shlex.quote(log) + " | mail -s \"Log" | kind + " " + date + " " + tags +
|
|
|
- "\" -r " + user + FROM_DOMAIN + " -- " + TO_ADDRESS, shell=True)
|
|
|
+ subprocess.run('printf "%s\n" ' + f'{shlex.quote(log)} | mail -s "Log{kind} {date} {tags}" ' +
|
|
|
+ f'-r {user_name}@{FROM_DOMAIN} {TO_ADDRESS}', shell=True)
|
|
|
return
|
|
|
|
|
|
|
|
@@ -256,10 +265,12 @@ def method_get(kind, user_to_find, date, tags):
|
|
|
|
|
|
# Write log
|
|
|
def method_post(kind, user_name, date, tags, log, send_mail):
|
|
|
- name = log_create(kind, user_name, date, tags, log)
|
|
|
- if send_mail:
|
|
|
- log_mail(kind, user_name, date, tags, log)
|
|
|
- logger.info("POST successful: hash " + name)
|
|
|
+ name = log_create(kind, user_name, date, tags, log)
|
|
|
+ logger.info("POST successful: hash " + name)
|
|
|
+ if send_mail:
|
|
|
+ log_mail(kind, user_name, date, tags, log)
|
|
|
+ logger.info("MAIL sent.")
|
|
|
+
|
|
|
|
|
|
|
|
|
# Generate .data file
|