You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
changedetection.io/changedetection.py

111 lines
3.6 KiB

#!/usr/bin/python3
# Launch as a eventlet.wsgi server instance.
import getopt
import os
import sys
import eventlet
import eventlet.wsgi
import changedetectionio
from changedetectionio import store
def main():
ssl_mode = False
UI improvements (#412) * Update CONTRIBUTING.md * Add option for tags on import (#377) * Add option for tags on import and backup * .add_watch() can accept empty tag Use https://changedetection.io/CHANGELOG.txt as a nice default page to watch * plaintext mime type fix - Don't attempt to extract HTML content from plaintext, this will remove lines and break changedetection (#391) * #323 Adding note about discord:// 2000 char limit (#392) * Adding note about discord:// 2000 char limit * Ability to use a generated salted password in deployments as env var SALTED_PASS (#397) * Ability to use a generated salted password in deployments as env var SALTED_PASS * Offer instance on Lemonade Tidy README * Update README - Tidy up sections * Update README - Fix docker section * Update README.md * /preview format doesnt need <pre> - fixing too many returnlines in content on diff/preview page * fixed the reference to wiki for rpi section (#402) * Add notification note - tgram:// bots cant send messages to other bots, so you should specify chat ID of non-bot user. * Notification error log handler (#403) * Add a notifications debug/error log interface (Link available under the notification URLs list) * Refactor tests for notification error log handler (#404) * Introduce -h option to allow listening not on 0.0.0.0. (#406) * Fix typo in the startup create-directory command suggestion (#405) * Use flask url_for() for webdriver chrome icon instead of relative path * merging latest upstream changes Co-authored-by: dgtlmoon <dgtlmoon@gmail.com> Co-authored-by: Tim Loderhose <timlod@users.noreply.github.com> Co-authored-by: Radu Ursache <3800336+rursache@users.noreply.github.com> Co-authored-by: Alexander Aleksandrovič Klimov <al2klimov@gmail.com>
3 years ago
host = ''
port = os.environ.get('PORT') or 5000
do_cleanup = False
# Must be absolute so that send_from_directory doesnt try to make it relative to backend/
datastore_path = os.path.join(os.getcwd(), "datastore")
try:
UI improvements (#412) * Update CONTRIBUTING.md * Add option for tags on import (#377) * Add option for tags on import and backup * .add_watch() can accept empty tag Use https://changedetection.io/CHANGELOG.txt as a nice default page to watch * plaintext mime type fix - Don't attempt to extract HTML content from plaintext, this will remove lines and break changedetection (#391) * #323 Adding note about discord:// 2000 char limit (#392) * Adding note about discord:// 2000 char limit * Ability to use a generated salted password in deployments as env var SALTED_PASS (#397) * Ability to use a generated salted password in deployments as env var SALTED_PASS * Offer instance on Lemonade Tidy README * Update README - Tidy up sections * Update README - Fix docker section * Update README.md * /preview format doesnt need <pre> - fixing too many returnlines in content on diff/preview page * fixed the reference to wiki for rpi section (#402) * Add notification note - tgram:// bots cant send messages to other bots, so you should specify chat ID of non-bot user. * Notification error log handler (#403) * Add a notifications debug/error log interface (Link available under the notification URLs list) * Refactor tests for notification error log handler (#404) * Introduce -h option to allow listening not on 0.0.0.0. (#406) * Fix typo in the startup create-directory command suggestion (#405) * Use flask url_for() for webdriver chrome icon instead of relative path * merging latest upstream changes Co-authored-by: dgtlmoon <dgtlmoon@gmail.com> Co-authored-by: Tim Loderhose <timlod@users.noreply.github.com> Co-authored-by: Radu Ursache <3800336+rursache@users.noreply.github.com> Co-authored-by: Alexander Aleksandrovič Klimov <al2klimov@gmail.com>
3 years ago
opts, args = getopt.getopt(sys.argv[1:], "Ccsd:h:p:", "port")
except getopt.GetoptError:
UI improvements (#412) * Update CONTRIBUTING.md * Add option for tags on import (#377) * Add option for tags on import and backup * .add_watch() can accept empty tag Use https://changedetection.io/CHANGELOG.txt as a nice default page to watch * plaintext mime type fix - Don't attempt to extract HTML content from plaintext, this will remove lines and break changedetection (#391) * #323 Adding note about discord:// 2000 char limit (#392) * Adding note about discord:// 2000 char limit * Ability to use a generated salted password in deployments as env var SALTED_PASS (#397) * Ability to use a generated salted password in deployments as env var SALTED_PASS * Offer instance on Lemonade Tidy README * Update README - Tidy up sections * Update README - Fix docker section * Update README.md * /preview format doesnt need <pre> - fixing too many returnlines in content on diff/preview page * fixed the reference to wiki for rpi section (#402) * Add notification note - tgram:// bots cant send messages to other bots, so you should specify chat ID of non-bot user. * Notification error log handler (#403) * Add a notifications debug/error log interface (Link available under the notification URLs list) * Refactor tests for notification error log handler (#404) * Introduce -h option to allow listening not on 0.0.0.0. (#406) * Fix typo in the startup create-directory command suggestion (#405) * Use flask url_for() for webdriver chrome icon instead of relative path * merging latest upstream changes Co-authored-by: dgtlmoon <dgtlmoon@gmail.com> Co-authored-by: Tim Loderhose <timlod@users.noreply.github.com> Co-authored-by: Radu Ursache <3800336+rursache@users.noreply.github.com> Co-authored-by: Alexander Aleksandrovič Klimov <al2klimov@gmail.com>
3 years ago
print('backend.py -s SSL enable -h [host] -p [port] -d [datastore path]')
sys.exit(2)
create_datastore_dir = False
for opt, arg in opts:
# if opt == '--purge':
# Remove history, the actual files you need to delete manually.
# for uuid, watch in datastore.data['watching'].items():
# watch.update({'history': {}, 'last_checked': 0, 'last_changed': 0, 'previous_md5': None})
if opt == '-s':
ssl_mode = True
UI improvements (#412) * Update CONTRIBUTING.md * Add option for tags on import (#377) * Add option for tags on import and backup * .add_watch() can accept empty tag Use https://changedetection.io/CHANGELOG.txt as a nice default page to watch * plaintext mime type fix - Don't attempt to extract HTML content from plaintext, this will remove lines and break changedetection (#391) * #323 Adding note about discord:// 2000 char limit (#392) * Adding note about discord:// 2000 char limit * Ability to use a generated salted password in deployments as env var SALTED_PASS (#397) * Ability to use a generated salted password in deployments as env var SALTED_PASS * Offer instance on Lemonade Tidy README * Update README - Tidy up sections * Update README - Fix docker section * Update README.md * /preview format doesnt need <pre> - fixing too many returnlines in content on diff/preview page * fixed the reference to wiki for rpi section (#402) * Add notification note - tgram:// bots cant send messages to other bots, so you should specify chat ID of non-bot user. * Notification error log handler (#403) * Add a notifications debug/error log interface (Link available under the notification URLs list) * Refactor tests for notification error log handler (#404) * Introduce -h option to allow listening not on 0.0.0.0. (#406) * Fix typo in the startup create-directory command suggestion (#405) * Use flask url_for() for webdriver chrome icon instead of relative path * merging latest upstream changes Co-authored-by: dgtlmoon <dgtlmoon@gmail.com> Co-authored-by: Tim Loderhose <timlod@users.noreply.github.com> Co-authored-by: Radu Ursache <3800336+rursache@users.noreply.github.com> Co-authored-by: Alexander Aleksandrovič Klimov <al2klimov@gmail.com>
3 years ago
if opt == '-h':
host = arg
if opt == '-p':
port = int(arg)
if opt == '-d':
datastore_path = arg
# Cleanup (remove text files that arent in the index)
if opt == '-c':
do_cleanup = True
# Create the datadir if it doesnt exist
if opt == '-C':
create_datastore_dir = True
# isnt there some @thingy to attach to each route to tell it, that this route needs a datastore
app_config = {'datastore_path': datastore_path}
if not os.path.isdir(app_config['datastore_path']):
if create_datastore_dir:
os.mkdir(app_config['datastore_path'])
else:
print ("ERROR: Directory path for the datastore '{}' does not exist, cannot start, please make sure the directory exists.\n"
UI improvements (#412) * Update CONTRIBUTING.md * Add option for tags on import (#377) * Add option for tags on import and backup * .add_watch() can accept empty tag Use https://changedetection.io/CHANGELOG.txt as a nice default page to watch * plaintext mime type fix - Don't attempt to extract HTML content from plaintext, this will remove lines and break changedetection (#391) * #323 Adding note about discord:// 2000 char limit (#392) * Adding note about discord:// 2000 char limit * Ability to use a generated salted password in deployments as env var SALTED_PASS (#397) * Ability to use a generated salted password in deployments as env var SALTED_PASS * Offer instance on Lemonade Tidy README * Update README - Tidy up sections * Update README - Fix docker section * Update README.md * /preview format doesnt need <pre> - fixing too many returnlines in content on diff/preview page * fixed the reference to wiki for rpi section (#402) * Add notification note - tgram:// bots cant send messages to other bots, so you should specify chat ID of non-bot user. * Notification error log handler (#403) * Add a notifications debug/error log interface (Link available under the notification URLs list) * Refactor tests for notification error log handler (#404) * Introduce -h option to allow listening not on 0.0.0.0. (#406) * Fix typo in the startup create-directory command suggestion (#405) * Use flask url_for() for webdriver chrome icon instead of relative path * merging latest upstream changes Co-authored-by: dgtlmoon <dgtlmoon@gmail.com> Co-authored-by: Tim Loderhose <timlod@users.noreply.github.com> Co-authored-by: Radu Ursache <3800336+rursache@users.noreply.github.com> Co-authored-by: Alexander Aleksandrovič Klimov <al2klimov@gmail.com>
3 years ago
"Alternatively, use the -C parameter.".format(app_config['datastore_path']),file=sys.stderr)
sys.exit(2)
datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], version_tag=changedetectionio.__version__)
app = changedetectionio.changedetection_app(app_config, datastore)
# Go into cleanup mode
if do_cleanup:
datastore.remove_unused_snapshots()
app.config['datastore_path'] = datastore_path
@app.context_processor
def inject_version():
return dict(right_sticky="v{}".format(datastore.data['version_tag']),
new_version_available=app.config['NEW_VERSION_AVAILABLE'],
has_password=datastore.data['settings']['application']['password'] != False
)
# Proxy sub-directory support
# Set environment var USE_X_SETTINGS=1 on this script
# And then in your proxy_pass settings
#
# proxy_set_header Host "localhost";
# proxy_set_header X-Forwarded-Prefix /app;
if os.getenv('USE_X_SETTINGS'):
print ("USE_X_SETTINGS is ENABLED\n")
from werkzeug.middleware.proxy_fix import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app, x_prefix=1, x_host=1)
if ssl_mode:
# @todo finalise SSL config, but this should get you in the right direction if you need it.
UI improvements (#412) * Update CONTRIBUTING.md * Add option for tags on import (#377) * Add option for tags on import and backup * .add_watch() can accept empty tag Use https://changedetection.io/CHANGELOG.txt as a nice default page to watch * plaintext mime type fix - Don't attempt to extract HTML content from plaintext, this will remove lines and break changedetection (#391) * #323 Adding note about discord:// 2000 char limit (#392) * Adding note about discord:// 2000 char limit * Ability to use a generated salted password in deployments as env var SALTED_PASS (#397) * Ability to use a generated salted password in deployments as env var SALTED_PASS * Offer instance on Lemonade Tidy README * Update README - Tidy up sections * Update README - Fix docker section * Update README.md * /preview format doesnt need <pre> - fixing too many returnlines in content on diff/preview page * fixed the reference to wiki for rpi section (#402) * Add notification note - tgram:// bots cant send messages to other bots, so you should specify chat ID of non-bot user. * Notification error log handler (#403) * Add a notifications debug/error log interface (Link available under the notification URLs list) * Refactor tests for notification error log handler (#404) * Introduce -h option to allow listening not on 0.0.0.0. (#406) * Fix typo in the startup create-directory command suggestion (#405) * Use flask url_for() for webdriver chrome icon instead of relative path * merging latest upstream changes Co-authored-by: dgtlmoon <dgtlmoon@gmail.com> Co-authored-by: Tim Loderhose <timlod@users.noreply.github.com> Co-authored-by: Radu Ursache <3800336+rursache@users.noreply.github.com> Co-authored-by: Alexander Aleksandrovič Klimov <al2klimov@gmail.com>
3 years ago
eventlet.wsgi.server(eventlet.wrap_ssl(eventlet.listen((host, port)),
certfile='cert.pem',
keyfile='privkey.pem',
server_side=True), app)
else:
UI improvements (#412) * Update CONTRIBUTING.md * Add option for tags on import (#377) * Add option for tags on import and backup * .add_watch() can accept empty tag Use https://changedetection.io/CHANGELOG.txt as a nice default page to watch * plaintext mime type fix - Don't attempt to extract HTML content from plaintext, this will remove lines and break changedetection (#391) * #323 Adding note about discord:// 2000 char limit (#392) * Adding note about discord:// 2000 char limit * Ability to use a generated salted password in deployments as env var SALTED_PASS (#397) * Ability to use a generated salted password in deployments as env var SALTED_PASS * Offer instance on Lemonade Tidy README * Update README - Tidy up sections * Update README - Fix docker section * Update README.md * /preview format doesnt need <pre> - fixing too many returnlines in content on diff/preview page * fixed the reference to wiki for rpi section (#402) * Add notification note - tgram:// bots cant send messages to other bots, so you should specify chat ID of non-bot user. * Notification error log handler (#403) * Add a notifications debug/error log interface (Link available under the notification URLs list) * Refactor tests for notification error log handler (#404) * Introduce -h option to allow listening not on 0.0.0.0. (#406) * Fix typo in the startup create-directory command suggestion (#405) * Use flask url_for() for webdriver chrome icon instead of relative path * merging latest upstream changes Co-authored-by: dgtlmoon <dgtlmoon@gmail.com> Co-authored-by: Tim Loderhose <timlod@users.noreply.github.com> Co-authored-by: Radu Ursache <3800336+rursache@users.noreply.github.com> Co-authored-by: Alexander Aleksandrovič Klimov <al2klimov@gmail.com>
3 years ago
eventlet.wsgi.server(eventlet.listen((host, int(port))), app)
if __name__ == '__main__':
main()