def alive_job(): while True: try: send_nodeinfo(node, {'type': 'alive'}) except Exception as err: print(str(err)) time.sleep(30)
def process_output(): while True: line = openvpn.vpn_proc.stdout.readline().strip() line_len = len(line) if line_len > 0: print(line) if 'Peer Connection Initiated with' in line: node.set_vpn_status('busy') send_nodeinfo(node, 'vpn_status') elif 'client-instance exiting' in line: openvpn.stop() break
def tasks(): while True: try: vpn_status_file = path.exists('/etc/openvpn/openvpn-status.log') if vpn_status_file is True: _connections = openvpn.get_connections() connections_len = len(_connections) if connections_len > 0: send_connections_info(node.account['addr'], node.account['token'], _connections) send_nodeinfo(node, {'type': 'alive'}) except Exception as err: print(str(err)) time.sleep(5)
def process_output(): while True: line = openvpn.vpn_proc.stdout.readline().strip() line_len = len(line) if line_len > 0: print(line) if 'Peer Connection Initiated with' in line: node.set_vpn_status('busy') send_nodeinfo(node, 'vpn_status') elif 'client-instance exiting' in line: openvpn.stop() break if __name__ == "__main__": account_addr = os.environ['ACCOUNT_ADDR'] keys = Keys() node = Node(account_addr) openvpn = OpenVPN() register_node(node) while True: keys.generate() node.set_ovpn(keys.ovpn()) send_nodeinfo(node, 'ovpn') openvpn.start() node.set_vpn_status('up') send_nodeinfo(node, 'vpn_status') process_output() time.sleep(2)
exit(3) elif (len(config['account_addr']) == 42) and (len(sys.argv) == 1): pass else: print( 'Password is not provided OR `account_addr` in config is incorrect. \ Please try again after deleting config file.') exit(2) node = Node(config) # openvpn = OpenVPN() shadowsocks = ShadowSocks() if len(node.config['token']) == 0: register_node(node) shadowsocks.start() send_nodeinfo(node, {'type': 'vpn'}) start_new_thread(alive_job, ()) # start_new_thread(connections_job, ()) while True: line = shadowsocks.vpn_proc.stdout.readline().strip() line_len = len(line) if line_len > 0: print("Line..", line) # if 'Peer Connection Initiated with' in line: # client_name = line.split()[6][1:-1] # if 'client' in client_name: # print('*' * 128) # elif 'client-instance exiting' in line: # client_name = line.split()[5].split('/')[0] # if 'client' in client_name: # print('*' * 128)