def get_ldap_connection(): uri = settings.get('ldap', 'uri') conn = ldap.initialize(uri) # LDAP/SSL setup if uri.startswith('ldaps'): conn.protocol_version = ldap.VERSION3 # Force cert validation conn.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND) if settings.has_option('ldap', 'cacert'): cacert = settings.get('ldap', 'cacert') # Set path name of file containing all trusted CA certificates conn.set_option(ldap.OPT_X_TLS_CACERTFILE, cacert) # Force libldap to create a new SSL context conn.set_option(ldap.OPT_X_TLS_NEWCTX, 0) return conn
def get_ldap_connection(): uri = settings.get('ldap', 'uri') conn = ldap.initialize(uri) # LDAP/SSL setup if uri.startswith('ldaps'): conn.protocol_version = ldap.VERSION3 # Force libldap to create a new SSL context conn.set_option(ldap.OPT_X_TLS_NEWCTX, ldap.OPT_X_TLS_DEMAND) # Force cert validation conn.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND) if settings.has_option('ldap', 'cacert'): cacert = settings.get('ldap', 'cacert') # Set path name of file containing all trusted CA certificates conn.set_option(ldap.OPT_X_TLS_CACERTFILE, cacert) return conn
except ModuleNotFoundError: from configparser import NoSectionError, NoOptionError import os import platform import pwd guests_allowed = False trusted_sources_allowed = False all_enabled = True auth_enabled = settings.get('config', 'authentication') == 'enable' uids = {} # cache of user login/names to avoid duplicate NSS resolutions if auth_enabled: if settings.has_option('config', 'secret_key'): secret_key_file = settings.get('config', 'secret_key') else: secret_key_file = '/etc/slurm-web/secret.key' # check secret key file exist or print error otherwise if not os.path.exists(secret_key_file): print("Secret key file %s does not exists" % (secret_key_file)) try: secret_key = open(secret_key_file, 'rb').read() except IOError: print("IO error with secret key file %s" % (secret_key_file)) # fallback to bad secret key secret_key = b"badsecretkey"
def main(): log.info("------------------------------------------------------------") session = Session() (options, args) = parser.parse_args() if options.filename is not None: feeds = [options.filename] else: feeds = settings.get('main', 'feeds').split() preferred_quality = settings.get('main', 'preferred_quality') if settings.has_option('main', 'global_exclude_regex'): exclude_regex = re.compile(settings.get('main', 'global_exclude_regex')) else: exclude_regex = None for feed_url in feeds: feed = parse(feed_url) log.info("Checking %s" % feed['feed']['subtitle']) for entry in feed.entries: if (exclude_regex is not None and exclude_regex.search(entry.description.lower()) is not None): log.info("SKIP %s" % entry.description) continue data = extract_metadata(entry.description) try: data['torrent_url'] = entry.enclosures[0]['href'] except (IndexError, KeyError): log.warning("No torrent found for %(name)s" % data) show = TVShow(**data) existing_qualities = session.query(TVShow).filter(TVShow.name==show.name).\ filter(TVShow.season==show.season).\ filter(TVShow.episode==show.episode) preferred_qualities = existing_qualities.\ filter(TVShow.quality==preferred_quality) # nothing yet? then add unconditionally if existing_qualities.count()==0: session.add(show) log.info("ADDED %(name)s %(season)s %(episode)s in %(quality)s" % show.__dict__) # already in preferred quality? elif preferred_qualities.count() > 0: log.info("HAVE %(name)s %(season)s %(episode)s to %(quality)s" % show.__dict__) continue # update existing quality with this one: else: existing_quality = existing_qualities.one() if show.quality != existing_quality.quality: session.delete(existing_quality) session.add(show) log.info("UPDATED %(name)s %(season)s %(episode)s to %(quality)s" % show.__dict__) torrent_download_dir = path.expanduser(settings.get('main', 'torrent_download_dir')) shows = session.query(TVShow).filter(TVShow.status==u'new') if shows.count() > 0: log.info("downloading torrents to %s" % torrent_download_dir) for show in session.query(TVShow).filter(TVShow.status==u'new'): torrent_path, result = urlretrieve(show.torrent_url, path.join(torrent_download_dir, "%s.torrent" % show.filename)) if result.type == 'application/x-bittorrent': show.status = u'torrent_downloaded' log.info("DOWNLOAD %(name)s %(season)s %(episode)s in %(quality)s" % show.__dict__) else: log.error("Couldn't download %s" % show.torrent_url) else: log.info("no shows to download") session.commit()
from functools import wraps from werkzeug.exceptions import Forbidden from itsdangerous import (TimedJSONWebSignatureSerializer as Serializer, BadSignature, SignatureExpired) from ConfigParser import NoSectionError, NoOptionError import os import platform guests_allowed = False all_enabled = True auth_enabled = settings.get('config', 'authentication') == 'enable' if auth_enabled: if settings.has_option('config', 'secret_key'): secret_key_file = settings.get('config', 'secret_key') else: secret_key_file = '/etc/slurm-web/secret.key' # check secret key file exist or print error otherwise if not os.path.exists(secret_key_file): print "Secret key file %s does not exists" % (secret_key_file) try: secret_key = open(secret_key_file, 'rb').read() except IOError: print "IO error with secret key file %s" % (secret_key_file) # fallback to bad secret key secret_key = b"badsecretkey"
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, BadSignature, SignatureExpired from ConfigParser import NoSectionError, NoOptionError import os import platform import pwd guests_allowed = False all_enabled = True auth_enabled = settings.get("config", "authentication") == "enable" uids = {} # cache of user login/names to avoid duplicate NSS resolutions if auth_enabled: if settings.has_option("config", "secret_key"): secret_key_file = settings.get("config", "secret_key") else: secret_key_file = "/etc/slurm-web/secret.key" # check secret key file exist or print error otherwise if not os.path.exists(secret_key_file): print "Secret key file %s does not exists" % (secret_key_file) try: secret_key = open(secret_key_file, "rb").read() except IOError: print "IO error with secret key file %s" % (secret_key_file) # fallback to bad secret key secret_key = b"badsecretkey"