Compare commits
5
Commits
9c5b6dce9c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
701da16aaf
|
||
|
|
57de8f47d0
|
||
|
|
671af52b15
|
||
|
|
ef9cc1aab3
|
||
|
|
0a3fc13f1e
|
@@ -5,11 +5,13 @@
|
|||||||
git:
|
git:
|
||||||
repo: https://src.mehl.mx/mxmehl/autoreply-editor.git
|
repo: https://src.mehl.mx/mxmehl/autoreply-editor.git
|
||||||
dest: autoreply-editor
|
dest: autoreply-editor
|
||||||
|
notify: restart supervisord
|
||||||
|
|
||||||
- name: Deploy config file
|
- name: Deploy config file
|
||||||
template:
|
template:
|
||||||
src: config.py.j2
|
src: config.py.j2
|
||||||
dest: autoreply-editor/config.py
|
dest: autoreply-editor/config.py
|
||||||
|
notify: restart supervisord
|
||||||
|
|
||||||
- name: Install specified python requirements
|
- name: Install specified python requirements
|
||||||
pip:
|
pip:
|
||||||
@@ -46,3 +48,5 @@
|
|||||||
- name: update supervisord
|
- name: update supervisord
|
||||||
command: supervisorctl update
|
command: supervisorctl update
|
||||||
listen: reload supervisord
|
listen: reload supervisord
|
||||||
|
- name: restart supervisord
|
||||||
|
command: supervisorctl restart autoreply-editor
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[program:autoreply-editor]
|
[program:autoreply-editor]
|
||||||
directory=/home/{{ ansible_user_id }}/autoreply-editor
|
directory=/home/{{ ansible_user_id }}/autoreply-editor
|
||||||
command=gunicorn --bind 0.0.0.0:{{ port }} wsgi:app
|
command=gunicorn --bind 0.0.0.0:{{ port }} wsgi:app
|
||||||
startsecs=60
|
startsecs=5
|
||||||
|
|||||||
+22
-12
@@ -51,7 +51,9 @@ def qmail_status(user):
|
|||||||
|
|
||||||
def check_user(user):
|
def check_user(user):
|
||||||
"""Check if user exists"""
|
"""Check if user exists"""
|
||||||
fulluser = [item for item in app.config.get("USERS") if item[1].split('@')[0] == user]
|
fulluser = [
|
||||||
|
item for item in app.config.get("USERS") if item[1].split("@")[0] == user
|
||||||
|
]
|
||||||
if not fulluser:
|
if not fulluser:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@@ -60,7 +62,13 @@ def check_user(user):
|
|||||||
|
|
||||||
def get_messagefile(user):
|
def get_messagefile(user):
|
||||||
"""Return message file of user, and create if necessary"""
|
"""Return message file of user, and create if necessary"""
|
||||||
filepath = f"message-{user}.txt"
|
# Path of the project
|
||||||
|
gitpath = str(Path(app.root_path).parent)
|
||||||
|
# File name of the message
|
||||||
|
filename = f"message-{user}.txt"
|
||||||
|
# Combine path
|
||||||
|
filepath = os.path.join(gitpath, filename)
|
||||||
|
|
||||||
if not os.path.isfile(filepath):
|
if not os.path.isfile(filepath):
|
||||||
Path(filepath).touch()
|
Path(filepath).touch()
|
||||||
|
|
||||||
@@ -95,6 +103,9 @@ def get_filterfile(user):
|
|||||||
with open(filepath, "w", encoding="utf-8") as filterfile:
|
with open(filepath, "w", encoding="utf-8") as filterfile:
|
||||||
filterfile.write(filterconfig)
|
filterfile.write(filterconfig)
|
||||||
|
|
||||||
|
# Change permissions to 0600
|
||||||
|
os.chmod(filepath, 0o600)
|
||||||
|
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
|
|
||||||
@@ -123,6 +134,7 @@ def index():
|
|||||||
users=app.config.get("USERS"),
|
users=app.config.get("USERS"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/user/<user>")
|
@app.route("/user/<user>")
|
||||||
def user_status(user):
|
def user_status(user):
|
||||||
"""Status for specific user"""
|
"""Status for specific user"""
|
||||||
@@ -130,9 +142,7 @@ def user_status(user):
|
|||||||
if not check_user(user):
|
if not check_user(user):
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
with open(
|
with open(get_messagefile(user), "r", encoding="utf-8") as messagefile:
|
||||||
get_messagefile(user), "r", encoding="utf-8"
|
|
||||||
) as messagefile:
|
|
||||||
message = messagefile.read()
|
message = messagefile.read()
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
@@ -151,9 +161,7 @@ def user_update(user):
|
|||||||
|
|
||||||
if request.form["action"] == "message":
|
if request.form["action"] == "message":
|
||||||
input_message = request.form["message"]
|
input_message = request.form["message"]
|
||||||
with open(
|
with open(get_messagefile(user), "w", encoding="utf-8") as messagefile:
|
||||||
get_messagefile(user), "w", encoding="utf-8"
|
|
||||||
) as messagefile:
|
|
||||||
messagefile.write(str(input_message))
|
messagefile.write(str(input_message))
|
||||||
result = "Success: The autoreply message has been updated!"
|
result = "Success: The autoreply message has been updated!"
|
||||||
|
|
||||||
@@ -169,7 +177,6 @@ def user_update(user):
|
|||||||
with fileinput.FileInput(
|
with fileinput.FileInput(
|
||||||
get_qmailfile(user),
|
get_qmailfile(user),
|
||||||
inplace=True,
|
inplace=True,
|
||||||
backup=".bak",
|
|
||||||
) as qmailfile:
|
) as qmailfile:
|
||||||
for line in qmailfile:
|
for line in qmailfile:
|
||||||
print(
|
print(
|
||||||
@@ -182,9 +189,12 @@ def user_update(user):
|
|||||||
try:
|
try:
|
||||||
return render_template("update.html", user=user, result=result)
|
return render_template("update.html", user=user, result=result)
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
return render_template("update.html", user=user, result="Something went terribly wrong!")
|
return render_template(
|
||||||
|
"update.html", user=user, result="Something went terribly wrong!"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def page_not_found(e):
|
def page_not_found(error):
|
||||||
return render_template('error.html', error=e), 404
|
"""Error for 404"""
|
||||||
|
return render_template("error.html", error=error), 404
|
||||||
|
|||||||
Reference in New Issue
Block a user