Skip to content

Commit

Permalink
Merge branch 'release/0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Merton committed Aug 29, 2018
2 parents 72a82aa + b765cf0 commit 82d732b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ __pycache__
broken_link_output.txt

# Application files
config.ini
/log/*
/log/*
/conf/*
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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

Expand All @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion config.ini.example → conf/conf.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ EmailOutput=yes
AdminEmailAddress=
AdminEmailPassword=

RecipientEmailAddress=
;Recipient addresses, separated by ','
RecipientEmailAddresses=

[AUTH]
SiteUsername=
Expand Down
30 changes: 21 additions & 9 deletions linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,30 +146,40 @@ 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

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")

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 82d732b

Please sign in to comment.