diff --git a/.gitignore b/.gitignore index 9f97018..8300eb0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,5 @@ __pycache__ broken_link_output.txt # Application files -config.ini -/log/* \ No newline at end of file +/log/* +/conf/* \ No newline at end of file diff --git a/README.md b/README.md index 712dfa3..9d60785 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ To install the required packages use `pip`: ## Usage ### Command Line & Server side -Copy the contents of the `config.ini.example` file into `config.ini` in the same directory. +Copy the contents of the `conf/conf.ini.example` file into `conf/conf.ini` in the same directory. Modify your config file with the details for your site: @@ -37,7 +37,7 @@ LogfileDirectory| The directory where logs will be saved, ensure you have the co EmailOutput|yes / no (default) AdminEmailAddress|The address of that emails will be sent from AdminEmailPassword|The password of the Admins email account -> **PLAIN TEXT!** -RecipientEmailAddress|The recipient's email where the output gets sent to +RecipientEmailAddresses|The recipient(s) email where the output gets sent to. Separate multiple emails with ',' #### AUTH CONFIG @@ -52,11 +52,18 @@ SitePassword| The password for the protected site -> **Plain Text** To run the script, ensure you have python (min <2.7) installed and run: -`python linker.py` +`python3 linker.py` + +#### MULTI CONFIGS +You can pass the config file name as a Command line argument, this is useful for multiple sites with a config for each site. ie: + +`python3 linker.py mysite.ini` + +`python3 linker.py mysecondsite.ini` ### Graphical interface Enter the linker directory, and run: -`python main.py` +`python3 main.py` From here you can enter or browse for the filename of the XML sitemap, and click enter. diff --git a/config.ini.example b/conf/conf.ini.example similarity index 91% rename from config.ini.example rename to conf/conf.ini.example index a4d7b69..ef85df3 100644 --- a/config.ini.example +++ b/conf/conf.ini.example @@ -25,7 +25,8 @@ EmailOutput=yes AdminEmailAddress= AdminEmailPassword= -RecipientEmailAddress= +;Recipient addresses, separated by ',' +RecipientEmailAddresses= [AUTH] SiteUsername= diff --git a/linker.py b/linker.py index d6fd3a8..e39bf5d 100644 --- a/linker.py +++ b/linker.py @@ -146,10 +146,10 @@ def send_mail(config, subject, message): server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(config['AdminEmailAddress'], config['AdminEmailPassword']) - + recipients = config['RecipientEmailAddresses'] msg = MIMEMultipart() msg['From'] = config['AdminEmailAddress'] - msg['To'] = config['RecipientEmailAddress'] + msg['To'] = recipients msg['Subject'] = subject body = message @@ -157,19 +157,29 @@ def send_mail(config, subject, message): msg.attach(MIMEText(body, 'plain')) txt = msg.as_string() - server.sendmail(config['AdminEmailAddress'], config['RecipientEmailAddress'], txt) + server.sendmail(config['AdminEmailAddress'], recipients.split(','), txt) server.quit() # Allows command line running def run(): + if len(sys.argv) > 1: + config_file = "conf/" + sys.argv[1] + else: + config_file = 'conf/conf.ini' + config = configparser.ConfigParser() - config.read('config.ini') + config.read(config_file) - gen_conf = config['GENERAL'] - email_conf = config['EMAIL'] - auth_conf = config['AUTH'] - auth = (auth_conf['SiteUsername'],auth_conf['SitePassword']) + try: + gen_conf = config['GENERAL'] + email_conf = config['EMAIL'] + auth_conf = config['AUTH'] + auth = (auth_conf['SiteUsername'],auth_conf['SitePassword']) + except KeyError as e: + log = "Unable to find config setting" + logging.error(log + str(e)) + sys.exit(log) scan_date = datetime.datetime.now().strftime("%Y-%m-%d") @@ -201,7 +211,9 @@ def run(): broken_links = check_links(site_map_file) if broken_links == 401: - sys.exit("The site you are trying to check requires authenticating. Please add the auth details in the config.ini file and try again.") + log = "The site you are trying to check requires authenticating. Please add the auth details in the config.ini file and try again." + logging.error(log) + sys.exit(log) else: log = "The file at {} could not be found. Please check the config and ensure the filepath is correct.".format(site_map_file)