import parsers from helpers import config, logreader, resource_path, get_version from helpers.settings import SettingsWindow config.load('nparse.config.json') # validate settings file config.verify_settings() os.environ['QT_SCALE_FACTOR'] = str( config.data['general']['qt_scale_factor'] / 100) CURRENT_VERSION = '0.5.1' if config.data['general']['update_check']: ONLINE_VERSION = get_version() else: ONLINE_VERSION = CURRENT_VERSION class NomnsParse(QApplication): """Application Control.""" def __init__(self, *args): super().__init__(*args) # Updates self._toggled = False self._log_reader = None
parser.add_argument('-s', '--cert', type=str, nargs=1, help='Client certificate') parser.add_argument('-k', '--key', type=str, nargs='?', help='Client Key') args = parser.parse_args() cert = args.cert[0] if args.key: key = args.key else: key = cert if args.version: tls_version = helpers.get_version(args.version[0]) elif args.version_name: tls_version = getattr(TLSVersion, args.version_name) else: tls_version = getattr(TLSVersion, 'TLS_1_2') extensions = [] if args.extensions: for e in args.extensions: tmp_ext = helpers.get_ext(e) extensions.append(TLSExtension()/tmp_ext()) elif args.extensions_name: for name in args.extensions_name: tmp_ext = getattr(scapy_ssl, name) extensions.append(TLSExtension()/tmp_ext())
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ import logging import coloredlogs from helpers import get_logo, get_version from helpers.configparser import get_configuration from mqttcontrol import MQTTControl # constants logo = get_logo() version = get_version() license_hint = """ This is free software. You are welcome to redistribute it under the conditions of the GNU Public License v2. For details, see https://www.gnu.org/licenses/gpl-2.0.html """ # configuration user_config = get_configuration() # logger logger = logging.getLogger('102shows.server') coloredlogs.install(level=user_config.log_level) # friendly greeting print(logo + " version: {}".format(version))
import os from flask import Flask, jsonify import database from components.authtoken.controller import authtoken_blueprint from components.system.model import System from components.todo.controller import todo_blueprint from components.todolist.controller import todolist_blueprint from components.user.controller import user_blueprint from db import db from helpers import get_version, init_database_url APP_DIR_PATH = os.path.dirname(__file__) __version__ = get_version(APP_DIR_PATH) database_url = os.environ.get("DATABASE_URL") if database_url is None: database_url = init_database_url(APP_DIR_PATH) app = Flask(__name__) app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config["SQLALCHEMY_DATABASE_URI"] = database_url database.init(db, app) @app.route("/") def index(): return jsonify({
def generate(filename, servers, types, sort_by=None, sort_links=None, minimun_uptime=0, compress=False): """Generate a html file with the servers information. Don't display times_offline, to avoid a database access. If sort_links is not None, it will be a dictionary with the following keys: 'directory' and 'filename_prefix'. They will be used to build the links in the header table.""" if minimun_uptime > 0: # Filter by uptime _servers = {} _servers.update([(k, v) for k, v in servers.iteritems() if float(v['times_queried_online']) / v['times_queried'] > minimun_uptime]) servers = _servers tmpfilename = "%s.tmp" % filename logging.info('Writing HTML file temporary "%s" ordered by %s', tmpfilename, sort_by) # Get the table rows in HTML (without <tr> element) rows = get_rows(servers, types) # Sort servers by columns server_keys = servers.keys() if sort_by is None: # Assume that the servers are sorted by name sort_by = 'server' server_keys.sort() elif sort_by is 'server': # If it's a explicit request, then sort server_keys.sort() elif sort_by is 'uptime': # None is earlier than any date, so use current date now = datetime.utcnow() offline_since = lambda key: servers[key]['offline_since'] if servers[ key]['offline_since'] is not None else now uptime = lambda key: servers[key]['uptime'] if 'uptime' in servers[ key] else 0 server_keys.sort() server_keys.sort(key=uptime, reverse=True) server_keys.sort(key=offline_since, reverse=True) elif sort_by is 'times_online': times = lambda key: float(servers[key]['times_queried_online'] ) / servers[key]['times_queried'] server_keys.sort() server_keys.sort(key=times, reverse=True) else: # Sort servers num_available_components = (lambda key: _count_components( servers[key], service_type=sort_by, availability='available')) num_unavailable_components = (lambda key: _count_components( servers[key], service_type=sort_by, availability='unavailable')) # Stable sort server_keys.sort() server_keys.sort(key=num_unavailable_components, reverse=True) server_keys.sort(key=num_available_components, reverse=True) f = open(tmpfilename, "w+") f.write( """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>Jabber/XMPP Server List</title> <style type="text/css"> body{ font-family: verdana, tahoma, sans-serif; font-size: 0.8em; background: #FFF; } div#header{ padding: 5px; margin:2px auto; } h1, h2, h3, h4, h5{ text-shadow: 0.1em 0.1em #AAA; font-weight: bold; } h1{ font-size: 3em; } h2{ font-size: 2.5em; } h3{ font-size: 2em; } h4{ font-size: 1.6em; } h5{ font-size: 1.4em; } h6{ font-size: 1.2em; } a[href]{ text-decoration: none; color: #0000AA; } a img{ border: 0px; } .note{ padding: 5px; margin:2px auto; background: #FFC; } .footer{ color: gray; font-size: 0.8em; text-align: center; margin: 5px; } table{ border-collapse: collapse; border-spacing: 0px; /*background: #C4DCFF;*/ background: #EEE; width: 100%; font-size: 0.85em; } td, th{ vertical-align: middle; text-align: center; padding: 2px 2px; } tr.table_header{ background: #DFDFDF; } tr.table_header th:hover{ background: #EFEFEF; } tr.table_header th a{ text-decoration: none; font-weight: normal; color: #0000AA; } tr.table_header th a:hover{ text-decoration: underline; } tr.odd{ background:#EBF4FF; } tr.even{ background:#FFF; } tr.offline{ font-style: italic; background:#FFD4D4; } th.server, td.server{ text-align: left; padding: 2px; } th.times_offline,td.times_offline{ /*display: none;*/ } td.feature{ /* font-size: 2em; */ } .no{ color: #E90900;/*firebrick;*/ } .yes, .available{ color: #0A0;/*green;*/ } .unavailable{ color: #808080;/*gray;*/ } """) # Apply a different style to sorted columns sort_class = sort_by if not isinstance(sort_by, tuple) else "%s_%s" % sort_by f.write(""" tr.table_header th.%s{ background: #CFCFCF; } tr.table_header th.%s a{ font-weight: bolder; font-size: 1em; /* background: #FAFAFA; */ color: #0000FF; } tr.odd td.%s{ background: #DCE5EF; } tr.even td.%s{ background: #EFEFEF; } tr.offline td.%s{ font-style: italic; background:#FFD4D4; }""" % (sort_class, sort_class, sort_class, sort_class, sort_class)) f.write(""" div.tooltip span{ display: block; /*font-size: 0.7em;*/ white-space: nowrap; } /*td div.tooltip{ display: none; } td:hover div.tooltip{ display: block; }*/ div.tooltip_container{ position: relative; display: inline; } div.tooltip{ display: none; background: #FFC; z-index: 1; } th:hover div.tooltip, td:hover div.tooltip{ display: block; margin: 0px auto; position: absolute; top: 15px; left: 15px; padding: 3px; } td.server div.tooltip{ padding: 5px 10px; width: 200px; text-align: center; } td.server div.tooltip span{ white-space: normal; } td.server div.tooltip ul{ list-style-type: none; margin-left: 0px; padding-left: 0px; } td.server div.tooltip p{ text-align: left; } </style> </head> <body> <div id='header'> <div id='title'><h2>Jabber/<abbr title="eXtensible Messaging and Presence Protocol">XMPP</abbr> Server List</h2></div> <h4>Notes:</h4> <div class='note'>If the service Jabber ID is from a different domain than the server, it will be ignored.</div> <div class='note'>Greyed icons mean that those services aren't accesible from external servers or that those gateways can't be used by users from another servers.</div> </div> <table> """) cols = "\t\t\t<col class='server' />" for service_type in types: cols += "<col class='%s_%s' />" % (service_type[0], service_type[1]) cols += "<col class='uptime' /><col class='times_online' />\n" f.write(cols) table_header = _get_table_header(types, sort_by, sort_links) row_number = 0 for row_number, server_key in enumerate(server_keys): if row_number % ROWS_BETWEEN_TITLES == 0: f.write(table_header) offline = servers[server_key]['offline_since'] is not None f.write((u"<tr class='%s%s'>%s</tr>\n" % ('offline ' if offline else '', 'odd' if row_number % 2 == 1 else 'even', rows[server_key])).encode('utf-8')) if row_number % ROWS_BETWEEN_TITLES != 1: f.write(table_header) f.write( u"""</table><div class='footer'>Page generated on %s by <a href='http://code.google.com/p/xmpp-server-scanner/'>XMPP Server Scanner</a><!-- %s --></div></body></html>\n""" % (datetime.utcnow().strftime('%d-%B-%Y %H:%M UTC'), get_version())) if compress: tmpgzfilename = "%s.gz.tmp" % filename logging.info('Creating a compressed version of file "%s"', tmpfilename) f.seek(0) gzf = gzip.open(tmpgzfilename, "wb") gzf.writelines(f.readlines()) gzf.close() shutil.move(tmpgzfilename, filename + '.gz') f.close() shutil.move(tmpfilename, filename) if compress: logging.info('%s generated and compresed as %s.gz', filename, filename) else: logging.info('%s generated', filename)
"""\ This module starts the 102shows server. The real magic does not happen here, though. """ import logging import coloredlogs from helpers import get_logo, get_version from helpers.configparser import get_configuration from mqttcontrol import MQTTControl # constants logo = get_logo() version = get_version() license_hint = """\ This is free software. You are welcome to redistribute it under the conditions of the GNU Public License v2. For details, see https://www.gnu.org/licenses/gpl-2.0.html """ # configuration user_config = get_configuration() # logger logger = logging.getLogger('102shows.server') coloredlogs.install(level=user_config.log_level) # friendly greeting print(logo + " version: {}".format(version))
def generate(filename, servers, types, sort_by=None, sort_links=None, minimun_uptime=0, compress=False): """Generate a html file with the servers information. Don't display times_offline, to avoid a database access. If sort_links is not None, it will be a dictionary with the following keys: 'directory' and 'filename_prefix'. They will be used to build the links in the header table.""" if minimun_uptime > 0: # Filter by uptime _servers = {} _servers.update( [ (k, v) for k, v in servers.iteritems() if float(v["times_queried_online"]) / v["times_queried"] > minimun_uptime ] ) servers = _servers tmpfilename = "%s.tmp" % filename logging.info('Writing HTML file temporary "%s" ordered by %s', tmpfilename, sort_by) # Get the table rows in HTML (without <tr> element) rows = get_rows(servers, types) # Sort servers by columns server_keys = servers.keys() if sort_by is None: # Assume that the servers are sorted by name sort_by = "server" server_keys.sort() elif sort_by is "server": # If it's a explicit request, then sort server_keys.sort() elif sort_by is "uptime": # None is earlier than any date, so use current date now = datetime.utcnow() offline_since = lambda key: servers[key]["offline_since"] if servers[key]["offline_since"] is not None else now uptime = lambda key: servers[key]["uptime"] if "uptime" in servers[key] else 0 server_keys.sort() server_keys.sort(key=uptime, reverse=True) server_keys.sort(key=offline_since, reverse=True) elif sort_by is "times_online": times = lambda key: float(servers[key]["times_queried_online"]) / servers[key]["times_queried"] server_keys.sort() server_keys.sort(key=times, reverse=True) else: # Sort servers num_available_components = lambda key: _count_components( servers[key], service_type=sort_by, availability="available" ) num_unavailable_components = lambda key: _count_components( servers[key], service_type=sort_by, availability="unavailable" ) # Stable sort server_keys.sort() server_keys.sort(key=num_unavailable_components, reverse=True) server_keys.sort(key=num_available_components, reverse=True) f = open(tmpfilename, "w+") f.write( """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>Jabber/XMPP Server List</title> <style type="text/css"> body{ font-family: verdana, tahoma, sans-serif; font-size: 0.8em; background: #FFF; } div#header{ padding: 5px; margin:2px auto; } h1, h2, h3, h4, h5{ text-shadow: 0.1em 0.1em #AAA; font-weight: bold; } h1{ font-size: 3em; } h2{ font-size: 2.5em; } h3{ font-size: 2em; } h4{ font-size: 1.6em; } h5{ font-size: 1.4em; } h6{ font-size: 1.2em; } a[href]{ text-decoration: none; color: #0000AA; } a img{ border: 0px; } .note{ padding: 5px; margin:2px auto; background: #FFC; } .footer{ color: gray; font-size: 0.8em; text-align: center; margin: 5px; } table{ border-collapse: collapse; border-spacing: 0px; /*background: #C4DCFF;*/ background: #EEE; width: 100%; font-size: 0.85em; } td, th{ vertical-align: middle; text-align: center; padding: 2px 2px; } tr.table_header{ background: #DFDFDF; } tr.table_header th:hover{ background: #EFEFEF; } tr.table_header th a{ text-decoration: none; font-weight: normal; color: #0000AA; } tr.table_header th a:hover{ text-decoration: underline; } tr.odd{ background:#EBF4FF; } tr.even{ background:#FFF; } tr.offline{ font-style: italic; background:#FFD4D4; } th.server, td.server{ text-align: left; padding: 2px; } th.times_offline,td.times_offline{ /*display: none;*/ } td.feature{ /* font-size: 2em; */ } .no{ color: #E90900;/*firebrick;*/ } .yes, .available{ color: #0A0;/*green;*/ } .unavailable{ color: #808080;/*gray;*/ } """ ) # Apply a different style to sorted columns sort_class = sort_by if not isinstance(sort_by, tuple) else "%s_%s" % sort_by f.write( """ tr.table_header th.%s{ background: #CFCFCF; } tr.table_header th.%s a{ font-weight: bolder; font-size: 1em; /* background: #FAFAFA; */ color: #0000FF; } tr.odd td.%s{ background: #DCE5EF; } tr.even td.%s{ background: #EFEFEF; } tr.offline td.%s{ font-style: italic; background:#FFD4D4; }""" % (sort_class, sort_class, sort_class, sort_class, sort_class) ) f.write( """ div.tooltip span{ display: block; /*font-size: 0.7em;*/ white-space: nowrap; } /*td div.tooltip{ display: none; } td:hover div.tooltip{ display: block; }*/ div.tooltip_container{ position: relative; display: inline; } div.tooltip{ display: none; background: #FFC; z-index: 1; } th:hover div.tooltip, td:hover div.tooltip{ display: block; margin: 0px auto; position: absolute; top: 15px; left: 15px; padding: 3px; } td.server div.tooltip{ padding: 5px 10px; width: 200px; text-align: center; } td.server div.tooltip span{ white-space: normal; } td.server div.tooltip ul{ list-style-type: none; margin-left: 0px; padding-left: 0px; } td.server div.tooltip p{ text-align: left; } </style> </head> <body> <div id='header'> <div id='title'><h2>Jabber/<abbr title="eXtensible Messaging and Presence Protocol">XMPP</abbr> Server List</h2></div> <h4>Notes:</h4> <div class='note'>If the service Jabber ID is from a different domain than the server, it will be ignored.</div> <div class='note'>Greyed icons mean that those services aren't accesible from external servers or that those gateways can't be used by users from another servers.</div> </div> <table> """ ) cols = "\t\t\t<col class='server' />" for service_type in types: cols += "<col class='%s_%s' />" % (service_type[0], service_type[1]) cols += "<col class='uptime' /><col class='times_online' />\n" f.write(cols) table_header = _get_table_header(types, sort_by, sort_links) row_number = 0 for row_number, server_key in enumerate(server_keys): if row_number % ROWS_BETWEEN_TITLES == 0: f.write(table_header) offline = servers[server_key]["offline_since"] is not None f.write( ( u"<tr class='%s%s'>%s</tr>\n" % ("offline " if offline else "", "odd" if row_number % 2 == 1 else "even", rows[server_key]) ).encode("utf-8") ) if row_number % ROWS_BETWEEN_TITLES != 1: f.write(table_header) f.write( u"""</table><div class='footer'>Page generated on %s by <a href='http://code.google.com/p/xmpp-server-scanner/'>XMPP Server Scanner</a><!-- %s --></div></body></html>\n""" % (datetime.utcnow().strftime("%d-%B-%Y %H:%M UTC"), get_version()) ) if compress: tmpgzfilename = "%s.gz.tmp" % filename logging.info('Creating a compressed version of file "%s"', tmpfilename) f.seek(0) gzf = gzip.open(tmpgzfilename, "wb") gzf.writelines(f.readlines()) gzf.close() shutil.move(tmpgzfilename, filename + ".gz") f.close() shutil.move(tmpfilename, filename) if compress: logging.info("%s generated and compresed as %s.gz", filename, filename) else: logging.info("%s generated", filename)