def createrootshell(address): jail_id = 'rsh' + generate_salt(4) ipv4 = host_ip ssh_ports = list() app_ports = list() hosts = get_bitbsd('rootshell') for host in hosts: ssh_ports.append(host['ssh_port']) app_ports.append(host['app_port']) plan = 'rootshell' ssh_port = random.randrange(62002, 63000) app_port = random.randrange(52002, 53000) while ssh_port in ssh_ports: ssh_port = random.randrange(62002, 63000) while app_port in app_ports: app_port = random.randrange(52002, 53000) #gen user pwd pwd = generate_salt(8) hname = address print(pwd) add_bitbsd_rs(address, jail_id, ipv4, ssh_port, app_port, plan, pwd) system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds/controller/playbooks/create_rootshell.yml --extra-vars="cname=' + str(jail_id) + ' hname=' + hname + ' sshport=' + str(ssh_port) + ' appport=' + str(app_port) + ' pwd=' + pwd + '"')
def post(self): parser = reqparse.RequestParser() parser.add_argument('host') args = parser.parse_args() dtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') hetz_hosts = get_hetzner() bit_hosts = get_bitbsd() try: addr = args['host'] result = {"status": "wrong host"} except KeyError as e: return {"error": "need a host (btc addr)"} for host in hetz_hosts: if host['address'] == addr: result = { "ip": host['ipv4'], "pwd": host['pwd'], "status": "subscribed" } for host in bit_hosts: if host['address'] == addr: result = { "ip": 'bitbsd.org', "ssh_pwd": host['pwd'], "ssh_usr": '******', "rpc_user": host['rpc_user'], "rpc_pwd": host['rpc_pwd'], "rpc_port": host['rpc_port'], "ssh_port": host['ssh_port'] } accs = find_hosts() for acc in accs: if acc['address'] == addr: balance = acc['balance'] image = acc['image'] if (image == 'freebsd') or (image == 'bitcoind') or ( image == 'lightningd'): result['login_username'] = "******" if balance > 0: result['hours_left'] = balance else: result = {"status": "pending payment"} return result
def del_server(address): hosts = find_hosts() for host in hosts: if address == host['address']: image = host['image'] bitbsd_servers = get_bitbsd(image) for serv in bitbsd_servers: if serv['address'] == address: delete_jail(address) hetzner_servers = getServers() for serv in hetzner_servers: if serv['name'] == address: deleteServer(serv['id'])
def createbitcoind(address): jail_id = 'btd' + generate_salt(4) ipv4 = host_ip ssh_ports = list() rpc_ports = list() hosts = get_bitbsd('bitcoind') for host in hosts: ssh_ports.append(host['ssh_port']) rpc_ports.append(host['rpc_port']) plan = 'bitcoind' ssh_port = random.randrange(60002, 61000) rpc_port = random.randrange(50002, 51000) while ssh_port in ssh_ports: ssh_port = random.randrange(60002, 61000) while rpc_port in rpc_ports: rpc_port = random.randrange(50002, 51000) rpc_password = generate_password() # Create 16 byte hex salt salt = generate_salt(16) password_hmac = password_to_hmac(salt, rpc_password) username = jail_id authline = 'rpcauth={0}:{1}${2}'.format(username, salt, password_hmac) #system("echo '" + authline + "' >> /usr/local/etc/bitcoin.conf") rpc_pass = rpc_password rpc_user = username #gen user pwd pwd = generate_salt(8) hname = address print(pwd) add_bitbsd(address, jail_id, ipv4, ssh_port, rpc_port, authline, rpc_user, rpc_pass, plan, pwd) system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds/controller/playbooks/create_btcnode.yml --extra-vars="cname=' + str(jail_id) + ' sshport=' + str(ssh_port) + ' hname=' + hname + ' rpcport=' + str(rpc_port) + ' rpcauthline=' + authline + ' rpcusr='******' rpcpwd=' + rpc_pass + ' pwd=' + pwd + '"')
def delete_jail(address): hosts = find_hosts() for host in hosts: if address == host['address']: image = host['image'] jails = get_bitbsd(image) for jail in jails: if jail['address'] == address: starname = jail['address'] jname = jail['id'] print('now removing from bitbsd ' + starname + "(" + jname + ")") system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds/controller/playbooks/remove_btcnode.yml --extra-vars="jname=' + str(jname) + '"')
def createbitcoind(address): id = 'bd'+generate_salt(4) ipv4 = '188.165.223.61' ssh_ports = list() rpc_ports = list() hosts = get_bitbsd() for host in hosts: ssh_ports.append(host['ssh_port']) rpc_ports.append(host['ssh_port']) plan = 'bitcoind' ssh_port = random.randrange(60002, 64998) rpc_port = random.randrange(50002, 54998) while ssh_port in ssh_ports: ssh_port = random.randrange(60002, 64998) while rpc_port in rpc_ports: rpc_port = random.randrange(50002, 54998) password = generate_password() # Create 16 byte hex salt salt = generate_salt(16) password_hmac = password_to_hmac(salt, password) username = id authline = 'rpcauth={0}:{1}${2}'.format(username, salt, password_hmac) #system("echo '" + authline + "' >> /usr/local/etc/bitcoin.conf") rpc_pass = password rpc_user = username pwd = 'kie6IZ4Doo' pwd_hash = sha512_crypt.encrypt(pwd) print(pwd) add_bitbsd(address, id, ipv4, ssh_port, rpc_port, authline, rpc_user, rpc_pass, plan, pwd) system('/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds/controller/playbooks/create_btcnode.yml --extra-vars="cname='+str(id)+' sshport='+str(ssh_port)+' rpcport='+str(rpc_port)+' rpcauthline='+authline+' pwd='+pwd+'"')
def status(host): hetz_hosts = get_hetzner() bit_hosts = get_bitbsd() cln_hosts = get_bitbsd('lightningd') rs_hosts = get_bitbsd('rootshell') p2e_hosts = get_bitbsd('pay2exec') result = dict() for hh in hetz_hosts: if hh['address'] == host: result = { "ip": hh['ipv4'], "pwd": hh['pwd'] } for bh in bit_hosts: if bh['address'] == host: result = { "ip": 'bitclouds.link', "ssh_pwd": bh['pwd'], "ssh_usr": '******', "rpc_user": bh['rpc_user'], "rpc_pwd": bh['rpc_pwd'], "rpc_port": bh['rpc_port'], "ssh_port": bh['ssh_port'] } for bh in cln_hosts: if bh['address'] == host: result = { "ip": 'bitclouds.link', "ssh_pwd": bh['pwd'], "ssh_usr": '******', "ssh_port": bh['ssh_port'], "app_port": bh['app_port'], "user_port": bh['user_port'], "sparko": 'https://bitclouds.link:' + str(bh['sparko_port'])+'/rpc', "ssh2onion": "you can ssh directly to your .onion (/home/lightning/onion.domain) on port 22" } for bh in p2e_hosts: if bh['address'] == host: result = { "ip": 'pay2exec.dev', "ssh_pwd": bh['pwd'], "ssh_usr": '******', "ssh_port": bh['ssh_port'], "app_port": bh['app_port'], "web_port": bh['user_port'], "sparko": 'https://pay2exec.dev:' + str(bh['sparko_port'])+'/rpc', "webapp": 'http://pay2exec.dev:'+str(bh['user_port'])+'/', "ssh2onion": "you can open web/ssh directly to your .onion (/home/lightning/onion.domain) on port 80/22" } for bh in rs_hosts: if bh['address'] == host: result = { "ip": 'bitclouds.link', "ssh_pwd": bh['pwd'], "ssh_usr": '******', "ssh_port": bh['ssh_port'], "app_port": bh['app_port'] } accs = find_hosts() for acc in accs: if acc['address'] == host: balance = acc['balance'] image = acc['image'] result['status'] = acc['status'] if balance > 0: result['hours_left'] = balance else: result = { "status": "awaiting payment! if you paid already wait until your instance is created." } return result
from ctrldbops import find_hosts, deduct_host, get_suspended, delete_host, get_bitbsd, hardclear from orchestrator import del_server hosts = find_hosts() if sys.argv[1] in ['new', 'subscribed', 'deleted', 'suspended']: for host in hosts: if host['status'] == sys.argv[1]: print(host) elif sys.argv[1] == 'housekeeper': for host in hosts: if host['status'] == 'deleted': del_server(host['address']) elif sys.argv[1] == 'bc': for host in get_bitbsd('rootshell'): print(host) for host in get_bitbsd('lightningd'): print(host) elif sys.argv[1] == 'del': host2del = sys.argv[2] for host in hosts: if host['address'] == host2del: delete_host(host['address']) del_server(host['address']) elif sys.argv[1] == 'hardclear': many = int(input('how many hosts to delete?: ')) while many > 1: print('hosts left to delete: ' + str(many)) many -= 1
def del_server(address): servers = get_bitbsd() for serv in servers: if serv['address'] == address: pass
def createlightningd(address): jail_id = 'cln' + generate_salt(4) ipv4 = host_ip ssh_ports = list() app_ports = list() sparko_ports = list() user_ports = list() hosts = get_bitbsd('lightningd') for host in hosts: try: ssh_ports.append(host['ssh_port']) app_ports.append(host['app_port']) sparko_ports.append(host['sparko_port']) user_ports.append(host['user_port']) except KeyError as e: print('ERROR: ignoring ' + host['address']) clearold(host['address']) plan = 'lightningd' ssh_port = random.randrange(61002, 62000) sparko_port = random.randrange(59002, 59999) app_port = random.randrange(51002, 52000) user_port = random.randrange(53002, 54000) while ssh_port in ssh_ports: ssh_port = random.randrange(61002, 62000) while app_port in app_ports: app_port = random.randrange(51002, 52000) while sparko_port in sparko_ports: sparko_port = random.randrange(59002, 59999) while user_port in user_ports: user_port = random.randrange(53002, 54000) sparko1 = 'M' + generate_salt(8) sparko2 = 'R' + generate_salt(8) sparko3 = 'RW' + generate_salt(8) creds = getrpc() rpc_user = creds['user'] rpc_pass = creds['password'] authline = 'None' alias = address + " [bitclouds.sh]" hname = address #gen user pwd pwd = generate_salt(8) ports = { 'ssh': ssh_port, 'app': app_port, 'sparko': sparko_port, 'userport': user_port } print(pwd) add_bitbsd_cln(address, jail_id, ipv4, ports, alias, rpc_user, rpc_pass, plan, pwd) system( '/usr/local/bin/ansible-playbook /home/bitclouds/bitclouds/controller/playbooks/create_lightningd.yml --extra-vars="cname=' + str(jail_id) + ' sshport=' + str(ssh_port) + ' appport=' + str(app_port) + ' sparko1=' + str(sparko1) + ' sparko2=' + str(sparko2) + ' sparko3=' + str(sparko3) + ' sparkoport=' + str(sparko_port) + ' userport=' + str(user_port) + ' hname=' + hname + ' alias=' + alias + ' rpcusr='******' rpcpwd=' + rpc_pass + ' pwd=' + pwd + '"')