23
main.py
23
main.py
@@ -1,8 +1,10 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
import secrets
|
import secrets
|
||||||
import smtplib
|
import smtplib
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
|
|
||||||
@@ -106,21 +108,24 @@ def create_user(
|
|||||||
mail_password,
|
mail_password,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Creates Yunohost user from a csv file and sends them an email with the password",
|
description="Creates Yunohost user from a csv file and sends them an email with the password",
|
||||||
)
|
)
|
||||||
parser.add_argument("filename", help="Input file name")
|
parser.add_argument("filename", help="Input file name")
|
||||||
parser.add_argument(
|
|
||||||
"mail_user", help="This user will be used to send the confirmation mail"
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"mail_password", help="This password will be used to send the confirmation mail"
|
|
||||||
)
|
|
||||||
parser.add_argument("--dry-run", action="store_true")
|
parser.add_argument("--dry-run", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
mail_password = os.environ.get("MAIL_PASSWORD", None)
|
||||||
|
mail_user = os.environ.get("MAIL_USER", None)
|
||||||
|
|
||||||
|
if mail_user is None:
|
||||||
|
print("Missing environment variable: MAIL_USER")
|
||||||
|
sys.exit(1)
|
||||||
|
if mail_password is None:
|
||||||
|
print("Missing environment variable: MAIL_PASSWORD")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
with open(args.filename, "r") as f:
|
with open(args.filename, "r") as f:
|
||||||
data = f.readlines()
|
data = f.readlines()
|
||||||
|
|
||||||
@@ -131,7 +136,7 @@ if __name__ == "__main__":
|
|||||||
create_user(
|
create_user(
|
||||||
*line.strip().split(","),
|
*line.strip().split(","),
|
||||||
mail_text=email_text,
|
mail_text=email_text,
|
||||||
mail_user=args.mail_user,
|
mail_user=mail_user,
|
||||||
mail_password=args.mail_password,
|
mail_password=mail_password,
|
||||||
dry_run=args.dry_run,
|
dry_run=args.dry_run,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user