def run() -> None: if not cp_ui.has_section('authentication'): raise InitialisationException( 'You cannot change your UI password because UI authentication is ' 'not set up yet. Please set it up using the run_ui_setup.py script.' ) if not cp_ui.has_option('authentication', 'hashed_password'): raise InitialisationException( 'Missing key authentication.hashed_password in the ' 'config/user_config_ui.ini config file. Please set up UI ' 'authentication again using the run_ui_setup.py script as your ' 'config is invalid.') while True: new_pass = input('Please insert your new password.\n') # The salt is the first 64 characters salt = bytes.fromhex(cp_ui['authentication']['hashed_password'][:64]) hashed_new_pass = hashlib.pbkdf2_hmac('sha256', new_pass.encode('utf-8'), salt, 100000) # Ask user if he really wants to change the password if the new password # is the same as the old one. if hashed_new_pass == \ bytes.fromhex( cp_ui['authentication']['hashed_password'][64:128]): if not yn_prompt('The new password is exactly the same as the old ' 'password. Do you want to insert a different ' 'password instead? (Y/n)\n'): print("Password did not change.") return else: # Generate a new salt to avoid situations where the user is suddenly # logged in without authenticating himself. This can happen if the # stored password matches the new password and the user is currently # not authenticated. salt = os.urandom(32) # Generate another hash with the new salt hashed_new_pass = hashlib.pbkdf2_hmac('sha256', new_pass.encode('utf-8'), salt, 100000) # First 64 characters are the salt, and the remaining characters # are the hashed password. cp_ui['authentication']['hashed_password'] = \ (salt + hashed_new_pass).hex() break print("Password changed successfully")
def node_from_node_config(node_config: NodeConfig): # Test connection log_and_print('Trying to connect to {}/status' ''.format(node_config.node_rpc_url)) try: node_status = get_cosmos_json(node_config.node_rpc_url + '/status', logger_general) log_and_print('Success.') except Exception: raise InitialisationException('Failed to connect to {} at {}'.format( node_config.node_name, node_config.node_rpc_url)) # Get node type node_type = NodeType.VALIDATOR_FULL_NODE \ if node_config.node_is_validator \ else NodeType.NON_VALIDATOR_FULL_NODE # Get pubkey if validator if node_config.node_is_validator: pubkey = node_status['validator_info']['address'] else: pubkey = None # Get network network = node_status['node_info']['network'] # Initialise node and load any state node = Node(node_config.node_name, node_config.node_rpc_url, node_type, pubkey, network, REDIS) node.load_state(logger_general) # Return node return node
def run() -> None: # Check if Redis enabled if not UserConf.redis_enabled: raise InitialisationException('Redis is not set up. Run the setup ' 'script to configure Redis.') logger = create_logger(InternalConf.redis_log_file, 'redis', InternalConf.logging_level) print('Deleting all Redis keys.') # Redis database try: RedisApi( logger, InternalConf.redis_database, UserConf.redis_host, UserConf.redis_port, password=UserConf.redis_password, namespace=UserConf.unique_alerter_identifier ).delete_all_unsafe() except Exception as e: sys.exit(e) # Redis test database try: RedisApi( logger, InternalConf.redis_test_database, UserConf.redis_host, UserConf.redis_port, password=UserConf.redis_password, namespace=UserConf.unique_alerter_identifier ).delete_all_unsafe() except Exception as e: sys.exit(e) print('Done deleting all Redis keys.')
def test_connection_to_github_page(repo: RepoConfig): # Get releases page releases_page = InternalConf.github_releases_template.format( repo.repo_page) # Test connection log_and_print('Trying to connect to {}'.format(releases_page)) try: releases = get_json(releases_page, logger_general) if 'message' in releases and releases['message'] == 'Not Found': raise InitialisationException( 'Successfully reached {} but URL ' 'is not valid.'.format(releases_page)) else: log_and_print('Success.') except Exception: raise InitialisationException('Could not reach {}.' ''.format(releases_page))
def run_monitor_network(network_nodes_tuple: Tuple[str, List[Node]]): # Get network and nodes network = network_nodes_tuple[0] nodes = network_nodes_tuple[1] # Monitor name based on network monitor_name = 'Network monitor ({})'.format(network) # Initialisation try: # Logger initialisation logger_monitor_network = create_logger( InternalConf.network_monitor_general_log_file_template.format( network), network, InternalConf.logging_level, rotating=True) # Organize as validators and full nodes validators = [n for n in nodes if n.is_validator] full_nodes = [n for n in nodes if not n.is_validator] # Do not start if not enough nodes if 0 in [len(validators), len(full_nodes)]: log_and_print('!!! Could not start {}. It must have at least 1 ' 'validator and 1 full node!!!'.format(monitor_name)) return # Initialise monitor network_monitor = NetworkMonitor( monitor_name, full_channel_set, logger_monitor_network, InternalConf.network_monitor_max_catch_up_blocks, REDIS, full_nodes, validators) except Exception as e: msg = '!!! Error when initialising {}: {} !!!'.format(monitor_name, e) log_and_print(msg) raise InitialisationException(msg) while True: # Start log_and_print('{} started with {} validator(s) and {} full node(s).' ''.format(monitor_name, len(validators), len(full_nodes))) sys.stdout.flush() try: start_network_monitor(network_monitor, InternalConf.network_monitor_period_seconds, logger_monitor_network) except Exception as e: full_channel_set.alert_error( TerminatedDueToExceptionAlert(monitor_name, e)) log_and_print('{} stopped.'.format(monitor_name))
def run() -> None: # Check if Mongo enabled if not UserConf.mongo_enabled: raise InitialisationException('Mongo is not set up. Run the setup ' 'script to configure Mongo.') logger = create_logger(InternalConf.mongo_log_file, 'mongo', InternalConf.logging_level) db_name = UserConf.mongo_db_name print('Deleting "{}" database from MongoDB.'.format(db_name)) # Attempt to delete database try: MongoApi(logger, UserConf.mongo_db_name, UserConf.mongo_host, UserConf.mongo_port, UserConf.mongo_user, UserConf.mongo_pass).drop_db() except Exception as e: sys.exit(e) print('Done deleting "{}" database from MongoDB.'.format(db_name))
def run_monitor_github(repo_config: RepoConfig): # Monitor name based on repository monitor_name = 'GitHub monitor ({})'.format(repo_config.repo_name) # Initialisation try: # Logger initialisation logger_monitor_github = create_logger( InternalConf.github_monitor_general_log_file_template.format( repo_config.repo_page.replace('/', '_')), repo_config.repo_page, InternalConf.logging_level, rotating=True) # Get releases page releases_page = InternalConf.github_releases_template.format( repo_config.repo_page) # Initialise monitor github_monitor = GitHubMonitor( monitor_name, full_channel_set, logger_monitor_github, REDIS, repo_config.repo_name, releases_page, InternalConf.redis_github_releases_key_prefix) except Exception as e: msg = '!!! Error when initialising {}: {} !!!'.format(monitor_name, e) log_and_print(msg) raise InitialisationException(msg) while True: # Start log_and_print('{} started.'.format(monitor_name)) sys.stdout.flush() try: start_github_monitor(github_monitor, InternalConf.github_monitor_period_seconds, logger_monitor_github) except Exception as e: full_channel_set.alert_error( TerminatedDueToExceptionAlert(monitor_name, e)) log_and_print('{} stopped.'.format(monitor_name))