def print_tabulate(res, noheader=False, short=False): config = read_config() c = conn(config) tbl = [] for i in res: if not i.__dict__.has_key('passwordenabled'): i.__setattr__('passwordenabled', 0) if not i.__dict__.has_key('created'): i.__setattr__('created', '') if i.passwordenabled == 1: passw = "Yes" else: passw = "No" if short: tbl.append(["%s/%s" % (i.account, i.name)]) else: tbl.append([ "%s/%s" % (i.account, i.name), i.zonename, i.ostypename, i.created, passw, ]) tbl = sorted(tbl, key=operator.itemgetter(0)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: tbl.insert(0, ['name', 'zone', 'ostype', 'created', 'passwordenabled']) print tabulate(tbl, headers="firstrow")
def print_tabulate(res, noheader=False, short=False): config = read_config() c = conn(config) tbl = [] for i in res: if not i.__dict__.has_key("associatednetworkname"): if i.__dict__.has_key("vpcid"): i.__setattr__("associatednetworkname", "%s (VPC)" % c.list_vpcs(id=i.vpcid)[0].name) if i.isstaticnat: vmname = i.virtualmachinename else: vmname = "" if i.issourcenat: snat = "Yes" else: snat = "No" if short: tbl.append([i.name]) else: tbl.append([i.ipaddress, i.zonename, i.associatednetworkname, vmname, snat, i.allocated]) tbl = sorted(tbl, key=operator.itemgetter(2)) if noheader or short: print tabulate(tbl, tablefmt="plain") else: tbl.insert(0, ["ip", "zone", "network", "staticnat", "sourcenat", "allocated"]) print tabulate(tbl, headers="firstrow")
def print_tabulate(res, noheader=False, short=False, t='list'): config = read_config() c = conn(config) tbl = [] for i in res: if t == 'list': if not i.__dict__.has_key('virtualmachinename'): i.__setattr__('virtualmachinename', 'None') if short: tbl.append([i.id]) else: tbl.append([ i.ipaddress, c.list_networks(id=i.networkid)[0].name, i.publicport, i.privateport, i.protocol, i.virtualmachinename, i.state, i.id, ]) tbl = sorted(tbl, key=operator.itemgetter(0)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: tbl.insert(0, ['ip', 'network', 'public port', 'private port', 'proto', 'vmname', 'state', 'uuid']) print tabulate(tbl, headers="firstrow")
def print_tabulate(res, offering_type="compute", noheader=False, short=False): config = read_config() c = conn(config) tbl = [] for i in res: if short: tbl.append([i.name]) else: if offering_type == "compute": tbl.append([ i.name, i.displaytext, i.storagetype, ]) elif offering_type == "network": tbl.append([ i.name, i.displaytext, "%s Mbit/s" % i.networkrate, ]) tbl = sorted(tbl, key=operator.itemgetter(0)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: if offering_type == 'compute': tbl.insert(0, ['name', 'description', 'storagetype']) else: tbl.insert(0, ['name', 'description', 'external networkrate']) print tabulate(tbl, headers="firstrow")
def print_tabulate(res, offering_type="compute", noheader=False, short=False): config = read_config() c = conn(config) tbl = [] for i in res: if short: tbl.append([i.name]) else: if offering_type == "compute": tbl.append([ i.name, i.displaytext, i.storagetype, ]) elif offering_type == "network": tbl.append([ i.name, i.displaytext, "%s Mbit/s"% i.networkrate, ]) tbl = sorted(tbl, key=operator.itemgetter(0)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: if offering_type == 'compute': tbl.insert(0, ['name', 'description', 'storagetype']) else: tbl.insert(0, ['name', 'description', 'external networkrate']) print tabulate(tbl, headers="firstrow")
def list_main(): config = read_config() c = conn(config) parser = ArgumentParser( description="View service offerings in RedBridge Cloud") parser.add_argument('-s', '--search', dest="search", action="store", help="Search for offering") parser.add_argument('-n', '--noheader', dest="noheader", action="store_true", default=False, help="Do not show the header") options = parser.parse_args() slist = [] slist.append(['name', 'id', 'description']) if options.search: offerings = get_offering(c, options.search) else: offerings = c.list_serviceofferings() for o in offerings: slist.append([o.name, o.id, o.displaytext]) print tabulate(slist, headers="firstrow")
def ItsTime(self): if self.subdomain == True: if type(self.target) != list: self.target = self.target.split("://") else: pass url_target = "%s://%s.%s/" % (self.target[0], self.path, self.target[1]) else: url_target = "%s/%s" % (self.target, self.path) conn = connection.conn(url_target, self.UserAgent) HTTPcode = conn.HTTPcode() if HTTPcode == 200: print("Found: %s >> (%s)" % (url_target, HTTPcode)) found.append(url_target) if HTTPcode == 301: print("Redirected %s >> (%a)" % (url_target, HTTPcode)) if HTTPcode == 404: if args.v != False: print(url_target + " >> " + str(HTTPcode)) else: pass
def print_tabulate(res, noheader=False, short=False, t='list'): config = read_config() c = conn(config) tbl = [] for i in res: if t == 'list': rules = get_firewall_rules(c, ipid=i.id) r = rule_list_to_string(rules) if not i.__dict__.has_key('associatednetworkname'): if i.__dict__.has_key('vpcid'): i.__setattr__('associatednetworkname', "%s (VPC)" % c.list_vpcs(id=i.vpcid)[0].name) if i.isstaticnat: vmname = i.virtualmachinename else: vmname = "" if i.issourcenat: snat = "Yes" else: snat = "No" if short: tbl.append([i.name]) else: tbl.append([ i.ipaddress, i.zonename, i.associatednetworkname, vmname, i.allocated, r ]) tbl = sorted(tbl, key=operator.itemgetter(2)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: tbl.insert( 0, ['ip', 'zone', 'network', 'staticnat', 'allocated', 'rules']) print tabulate(tbl, headers="firstrow")
def check_target(target, UserAgent, tor): if tor != False: connection.tor().connect() else: pass conn = connection.conn(target, UserAgent) HTTPcode = conn.HTTPcode() if HTTPcode == 200: print("Server status: Online (%s)" % HTTPcode) else: print("Server status: Offline (%s)" % HTTPcode) redirect = conn.redirect() if target != redirect: print("Redirected: %s" % redirect) answer = raw_input("Follow redirection? [y/N] ").lower() if answer == "n" or answer == "": return(target) elif answer != "" or answer != "n": print("\nNew target: %s" % redirect) return(redirect)
def print_tabulate(res, noheader=False, short=False, t="vpn"): config = read_config() c = conn(config) tbl = [] for i in res: if t == 'vpn': if short: tbl.append([i.publicip]) else: tbl.append([ get_network_for_ip(c, i.publicipid), i.publicip, i.presharedkey, i.state, ]) if t == 'vpnusers': if short: tbl.append([i.username]) else: tbl.append([ i.username, i.state, ]) tbl = sorted(tbl, key=operator.itemgetter(0)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: if t == 'vpn': tbl.insert(0, ['network', 'endpoint', 'preshared key', 'state']) elif t == 'vpnuser': tbl.insert(0, ['username', 'state']) print tabulate(tbl, headers="firstrow")
def insert_bookstall_map(booking_id, event_id, stall_id): con, cursor = connection.conn() query = f"INSERT INTO `bookstall_map` (`booking_id`,`event_id`,`stall_id`) VALUES ('{booking_id}',{event_id},{stall_id});" cursor.execute(query) con.commit() cursor.close() con.close()
def print_tabulate(res, noheader=False, short=False): config = read_config() c = conn(config) tbl = [] for i in res: if not i.__dict__.has_key('networkofferingname'): i.__setattr__('networkofferingname', 'VPC') if short: tbl.append([i.name]) else: tbl.append([ i.name, i.zonename, i.networkofferingname, i.cidr, i.networkdomain, get_snat(c, i.id), has_vpn(c, i.id), i.state ]) tbl = sorted(tbl, key=operator.itemgetter(0)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: tbl.insert(0, ['name', 'zone', 'offering', 'cidr', 'domain', 'snat', 'vpn', 'state']) print tabulate(tbl, headers="firstrow")
def insert_stall(stall_no, stall_price, stall_size, is_booked, event_id): con, cursor = connection.conn() query = f"INSERT INTO `stall` (`stall_no`,`stall_price`,`stall_size`,`is_booked`,`event_id`) VALUES ({stall_no},{stall_price},{stall_size},'{is_booked}',{event_id});" cursor.execute(query) con.commit() cursor.close() con.close()
def check_target(target, UserAgent, tor): if tor != False: connection.tor().connect() else: pass conn = connection.conn(target, UserAgent) HTTPcode = conn.HTTPcode() if HTTPcode == 200: print("Server status: Online (%s)" % HTTPcode) else: print("Server status: Offline (%s)" % HTTPcode) exit() redirect = conn.redirect() if target != redirect: print("Redirected: %s" % redirect) answer = raw_input("Follow redirection? [y/N] ").lower() if answer == "n" or answer == "": return (target) elif answer != "" or answer != "n": print("\nNew target: %s" % redirect) return (redirect)
def insert_industry(industry_name): con, cursor = connection.conn() query = f"INSERT INTO `industry` (`industry_name`) VALUES ('{industry_name}');" cursor.execute(query) con.commit() cursor.close() con.close()
def insert_booking(booking_date, total_amount, event_id, exhibitor_id): con, cursor = connection.conn() query = f"INSERT INTO `booking` (`booking_date`,`total_amount`,`event_id`,`exhibitor_id`) VALUES ('{datetime.datetime()}',{total_amount},{event_id},{exhibitor_id});" cursor.execute(query) con.commit() cursor.close() con.close()
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if args['list']: res = c.list_sshkeypairs() if args['generate']: try: res = c.create_sshkeypair(name=args['NAME']) print res.privatekey sys.exit(0) except molnctrl.csexceptions.ResponseError as e: print "Unable to create ssh key: %s" % e[1] sys.exit(1) if args['delete']: try: res = c.delete_sshkeypair(name=args['NAME']) print "deleted SSH key: %s" % args['NAME'] sys.exit(0) except Exception as e: print "Unable to delete SSK keypair: %s" % e[1] sys.exit(1) if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "Unable to execute command" sys.exit(1)
def print_tabulate(res, noheader=False, short=False): config = read_config() c = conn(config) tbl = [] for i in res: if not i.__dict__.has_key('networkofferingname'): i.__setattr__('networkofferingname', 'VPC') if short: tbl.append([i.name]) else: tbl.append([ i.name, i.zonename, i.networkofferingname, i.cidr, i.networkdomain, get_snat(c, i.id), has_vpn(c, i.id), i.state ]) tbl = sorted(tbl, key=operator.itemgetter(0)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: tbl.insert(0, [ 'name', 'zone', 'offering', 'cidr', 'domain', 'snat', 'vpn', 'state' ]) print tabulate(tbl, headers="firstrow")
def megaconsumercard(spend_amt, spend_date, payment_mode, event_id, booking_id, visitor_id): con, cursor = connection.conn() query = f"INSERT INTO `megaconsumercard` (`spend_amt`,`spend_date`,`payment_mode`,`event_id`,`booking_id`,`visitor_id`) VALUES ({spend_amt},'{spend_date}','{payment_mode}',{event_id},{booking_id},{visitor_id});" cursor.execute(query) con.commit() cursor.close() con.close()
def insert_eventt(event_name, booking_start_date, event_start_date, event_end_date, venue_id): con, cursor = connection.conn() query = f"INSERT INTO `eventt` (`event_name`,`booking_start_date`,`event_start_date`,`event_end_date`,`venue_id`) VALUES ('{event_name}',{booking_start_date},{event_start_date},{event_end_date},{venue_id});" cursor.execute(query) con.commit() cursor.close() con.close()
def insert_exhibitor(exhibitor_name, email_id, phone_no, company_name, company_description, company_addr, company_pin_code, industry_id, country_id, state_id): con, cursor = connection.conn() query = f"INSERT INTO `exhibitor` (`exhibitor_name`,`email_id`,`phone_no`,`company_name`,`company_description`,`company_addr`,`company_pin_code`,`industry_id`,`country_id`,`state_id`) VALUES ('{exhibitor_name}','{email_id}',{phone_no},'{company_name}',{company_description},{company_addr},{company_pin_code},{industry_id},{country_id},{state_id});" cursor.execute(query) con.commit() cursor.close() con.close()
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if args['create']: id = get_network(c, args['NETWORK'])[0].id res = c.create_egressfirewallrule(networkid=id, protocol="All", cidrlist="0.0.0.0/0") if res: print "egress rule created" sys.exit(0)
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if args['list']: if args['NETWORK']: res = c.list_publicipaddresses(networkid=get_network_from_name( c, args['NETWORK']).id, isstaticnat='true') else: res = c.list_publicipaddresses(isstaticnat='true') elif args['enable']: try: if c.enable_staticnat(ipaddressid=get_id_from_address( c, args['IPADDRESS']).id, virtualmachineid=get_instance_from_name( c, args['INSTANCE']).id): if args['--rules']: print args try: for rule in args['RULE']: src = rule.split(':') proto_port = src[1].split('/') c.create_firewallrule( ipaddressid=get_id_from_address( c, args['IPADDRESS']).id, startport=proto_port[1], protocol=proto_port[0], cidrlist=src[0]) except Exception as e: print "Unable create firewall rules: %s" % e print "Enabled static nat for %s on %s" % (args['INSTANCE'], args['IPADDRESS']) sys.exit(0) except Exception as e: print "Unable to enable static nat: %s" % e[1] sys.exit(1) elif args['disable']: try: res = c.disable_staticnat(ipaddressid=get_id_from_address( c, args['IPADDRESS']).id).get_result() if res == 'succeded': print "Disabled static nat on %s" % args['IPADDRESS'] sys.exit(0) except Exception as e: print "Unable to disable static nat: %s" % e[1] sys.exit(1) if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "Unable to execute command" sys.exit(1)
def main(): config = read_config() c = conn(config, timeout=5) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if args['list']: list_args = {'listall': 'true'} if args['--search']: list_args['keyword'] = args['--search'] res = c.list_networks(**list_args) try: res += c.list_vpcs(**list_args) except: pass if args['delete']: id = get_network(c, args['NETWORK'])[0].id if id: res = c.delete_network(id=id).get_result() if res: print "network deleted" sys.exit(0) else: print "failed to delete the network, check that there are no running instances deployed on the network." sys.exit(1) if args['create']: create_args = {'name': args['NETWORK'], 'displaytext': args['NETWORK']} if args['--offering']: create_args['networkofferingid'] = get_offering_id( c, args['--offering']) if args['--domain']: create_args['networkdomain'] = args['--domain'] if args['--zone']: zone = get_zone(c, args['--zone'])[0] create_args['zoneid'] = zone.id else: zone = get_zone(c)[0] create_args['zoneid'] = zone.id try: c.create_network(**create_args) res = c.list_networks(keyword=args['NETWORK']) except JSONDecodeError: res = c.list_networks(keyword=args['NETWORK']) except ResponseError as e: print "Error creating network: %s" % e[1] sys.exit(1) if not res: print "Error creating network" if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "Unable to execute command" sys.exit(1)
def main(): config = read_config() c = conn(config, timeout=5) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if args['list']: list_args ={'listall': 'true'} if args['--search']: list_args['keyword'] = args['--search'] res = c.list_networks(**list_args) try: res += c.list_vpcs(**list_args) except: pass if args['delete']: id = get_network(c, args['NETWORK'])[0].id if id: res = c.delete_network(id=id).get_result() if res: print "network deleted" sys.exit(0) else: print "failed to delete the network, check that there are no running instances deployed on the network." sys.exit(1) if args['create']: create_args = {'name': args['NETWORK'], 'displaytext': args['NETWORK']} if args['--offering']: create_args['networkofferingid'] = get_offering_id(c, args['--offering']) if args['--domain']: create_args['networkdomain'] = args['--domain'] if args['--zone']: zone = get_zone(c, args['--zone'])[0] create_args['zoneid'] = zone.id else: zone = get_zone(c)[0] create_args['zoneid'] = zone.id try: c.create_network(**create_args) res = c.list_networks(keyword=args['NETWORK']) except JSONDecodeError: res = c.list_networks(keyword=args['NETWORK']) except ResponseError as e: print "Error creating network: %s" % e[1] sys.exit(1) if not res: print "Error creating network" if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "Unable to execute command" sys.exit(1)
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if (args['list'] and not args['users']): res = c.list_remoteaccessvpns() t = "vpn" elif args['enable']: ip = get_publicip_for_network(c, args['NETWORK']) try: ret = c.create_remoteaccessvpn(publicipid=ip.id) except Exception as e: print "Unable to enable remote access VPN: %s" % e[1] sys.exit(1) elif args['disable']: ip = get_publicip_for_network(c, args['NETWORK']) try: ret = c.delete_remoteaccessvpn(publicipid=ip.id) except Exception as e: print "Unable to disable remote access VPN: %s" % e[1] sys.exit(1) elif args['users']: t = 'vpnusers' if args['list']: res = c.list_vpnusers() if args['add']: if not args['PASSWORD']: length = 8 chars = string.ascii_letters + string.digits + '@#+=.-_' random.seed = (os.urandom(1024)) passwd = ''.join(random.choice(chars) for i in range(length)) else: passwd = args['PASSWORD'] c.add_vpnuser(username=args['USERNAME'], password=passwd) print "VPN user %s added with password %s" % (args['USERNAME'], passwd) sys.exit(1) elif args['remove']: try: c.remove_vpnuser(username=args['USERNAME']) print "Removed user: %s" % args['USERNAME'] sys.exit(0) except Exception as e: print "Unable to remove VPN user: %s" % e[1] sys.exit(1) if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short'], t=t) else: print "Unable to execute command" sys.exit(1)
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if args['list']: if args['compute']: res = c.list_serviceofferings() t = 'compute' elif args['network']: res = c.list_networkofferings(state="Enabled") t = 'network' if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short'], offering_type=t) else: print "Unable to execute command" sys.exit(1)
def list_main(): config = read_config() c = conn(config) parser = ArgumentParser(description="View service offerings in RedBridge Cloud") parser.add_argument('-s', '--search', dest="search", action="store", help="Search for offering") parser.add_argument('-n', '--noheader', dest="noheader", action="store_true", default=False, help="Do not show the header") options = parser.parse_args() slist = [] slist.append(['name', 'id', 'description']) if options.search: offerings = get_offering(c, options.search) else: offerings = c.list_serviceofferings() for o in offerings: slist.append([o.name, o.id, o.displaytext]) print tabulate(slist, headers="firstrow")
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version="%s %s" % (__cli_name__, __version__)) if args["list"]: res = c.list_publicipaddresses() elif args["allocate"]: res = [c.associate_ipaddress(networkid=get_network_from_name(c, args["NETWORK"]).id).get_result()] elif args["release"]: res = [c.disassociate_ipaddress(id=get_id_from_address(c, args["IPADDRESS"]).id).get_result()] print "Released ip address: %s" % args["IPADDRESS"] sys.exit(0) if res: print_tabulate(res, noheader=args["--noheader"], short=args["--short"]) else: print "Unable to execute command" sys.exit(1)
def ItsTime(): url_target = "%s/%s" % (target, path) paths.remove(path) conn = connection.conn(url_target, UserAgent) HTTPcode = conn.HTTPcode() if HTTPcode == 200: print("Found: %s >> (%s)" % (url_target, HTTPcode)) found.append(url_target) if HTTPcode == 301: print("Redirected %s >> (%a)" % (url_target, HTTPcode)) if HTTPcode == 404: if args.v != False: print(url_target + " >> " + str(HTTPcode)) else: pass
def print_tabulate(res, noheader=False, short=False): config = read_config() c = conn(config) tbl = [] for i in res: if short: tbl.append([i.name]) else: tbl.append([ i.name, i.fingerprint, ]) tbl = sorted(tbl, key=operator.itemgetter(0)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: tbl.insert(0, ['name', 'fingerprint']) print tabulate(tbl, headers="firstrow")
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if not args['FILTER']: args['FILTER'] = 'executable' if not args['FILTER'] in ["featured", "self", "selfexecutable","sharedexecutable","executable", "community"]: print "%s is not a valid template filter" % rgs['FILTER'] sys.exit(1) if args['list']: res = list_templates(c, args) if args['delete']: res = delete_template(c, args) if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "Could not find any templates, try listing featured templates using `rbc-templates list featured`" sys.exit(1)
def main(): config = read_config() c = conn(config, method='post') args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if args['--refresh-cache']: clear_cache(args) if args['--list']: try: if is_cache_valid(args): print load_inventory_from_cache(args) else: update_cache(c, args) print load_inventory_from_cache(args) #print inventory(c, args) sys.exit(0) except Exception as e: print "error creating inventory: %s" % e sys.exit(1) if args['--host']: return {}
def print_tabulate(res, noheader=False, short=False): config = read_config() c = conn(config) tbl = [] template_cache = {} for i in res: if not i.__dict__.has_key('keypair'): i.__setattr__('keypair', 'None') if not i.__dict__.has_key('password'): i.__setattr__('password', 'None') if not i.__dict__.has_key('group'): i.__setattr__('group', 'None') # cache templates if not template_cache.has_key(i.templateid): # lookup t = get_template_from_id(c, i.templateid) if t: template_cache[i.templateid] = t else: template_cache[i.templateid] = type('Template', (object, ), {'account': 'DELETED'}) if short: tbl.append([i.name]) else: tbl.append([ i.name, i.zonename, i.state, i.serviceofferingname, i.group, i.nics[0].networkname, i.nics[0].ipaddress, i.keypair, i.password, "%s/%s" % (template_cache[i.templateid].account, i.templatename), i.created ]) tbl = sorted(tbl, key=operator.itemgetter(0)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: tbl.insert(0, [ 'name', 'zone', 'state', 'offering', 'group', 'network', 'ipaddress', 'sshkey', 'password', 'template', 'created' ]) print tabulate(tbl, headers="firstrow")
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if args['list']: if args['NETWORK']: res = c.list_publicipaddresses(networkid=get_network_from_name(c, args['NETWORK']).id, isstaticnat='true') else: res = c.list_publicipaddresses(isstaticnat='true') elif args['enable']: try: if c.enable_staticnat(ipaddressid=get_id_from_address(c, args['IPADDRESS']).id, virtualmachineid=get_instance_from_name(c, args['INSTANCE']).id): if args['--rules']: print args try: for rule in args['RULE']: src = rule.split(':') proto_port = src[1].split('/') c.create_firewallrule(ipaddressid=get_id_from_address(c, args['IPADDRESS']).id, startport=proto_port[1], protocol=proto_port[0], cidrlist=src[0]) except Exception as e: print "Unable create firewall rules: %s" % e print "Enabled static nat for %s on %s" % (args['INSTANCE'], args['IPADDRESS']) sys.exit(0) except Exception as e: print "Unable to enable static nat: %s" % e[1] sys.exit(1) elif args['disable']: try: res = c.disable_staticnat(ipaddressid=get_id_from_address(c, args['IPADDRESS']).id).get_result() if res == 'succeded': print "Disabled static nat on %s" % args['IPADDRESS'] sys.exit(0) except Exception as e: print "Unable to disable static nat: %s" % e[1] sys.exit(1) if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "Unable to execute command" sys.exit(1)
def print_tabulate(res, noheader=False, short=False): config = read_config() c = conn(config) tbl = [] template_cache = {} for i in res: if not i.__dict__.has_key('keypair'): i.__setattr__('keypair', 'None') if not i.__dict__.has_key('password'): i.__setattr__('password', 'None') if not i.__dict__.has_key('group'): i.__setattr__('group', 'None') # cache templates if not template_cache.has_key(i.templateid): # lookup t = get_template_from_id(c, i.templateid) if t: template_cache[i.templateid] = t else: template_cache[i.templateid] = type('Template', (object,), {'account': 'DELETED'}) if short: tbl.append([i.name]) else: tbl.append([i.name, i.zonename, i.state, i.serviceofferingname, i.group, i.nics[0].networkname, i.nics[0].ipaddress, i.keypair, i.password, "%s/%s" % (template_cache[i.templateid].account, i.templatename), i.created] ) tbl = sorted(tbl, key=operator.itemgetter(0)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: tbl.insert(0, ['name', 'zone', 'state', 'offering', 'group', 'network', 'ipaddress', 'sshkey', 'password', 'template', 'created']) print tabulate(tbl, headers="firstrow")
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if not args['FILTER']: args['FILTER'] = 'executable' if not args['FILTER'] in [ "featured", "self", "selfexecutable", "sharedexecutable", "executable", "community" ]: print "%s is not a valid template filter" % rgs['FILTER'] sys.exit(1) if args['list']: res = list_templates(c, args) if args['delete']: res = delete_template(c, args) if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "Could not find any templates, try listing featured templates using `rbc-templates list featured`" sys.exit(1)
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if args['list']: res = c.list_publicipaddresses() elif args['allocate']: res = [ c.associate_ipaddress(networkid=get_network_from_name( c, args['NETWORK']).id).get_result() ] elif args['release']: res = [ c.disassociate_ipaddress( id=get_id_from_address(c, args['IPADDRESS']).id).get_result() ] print "Released ip address: %s" % args['IPADDRESS'] sys.exit(0) if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "Unable to execute command" sys.exit(1)
def print_tabulate(res, noheader=False, short=False, t='list'): config = read_config() c = conn(config) tbl = [] for i in res: if t == 'list': rules = get_firewall_rules(c, ipid=i.id) r = rule_list_to_string(rules) if not i.__dict__.has_key('associatednetworkname'): if i.__dict__.has_key('vpcid'): i.__setattr__('associatednetworkname', "%s (VPC)" % c.list_vpcs(id=i.vpcid)[0].name) if i.isstaticnat: vmname = i.virtualmachinename else: vmname = "" if i.issourcenat: snat = "Yes" else: snat = "No" if short: tbl.append([i.name]) else: tbl.append([ i.ipaddress, i.zonename, i.associatednetworkname, vmname, i.allocated, r ]) tbl = sorted(tbl, key=operator.itemgetter(2)) if (noheader or short): print tabulate(tbl, tablefmt="plain") else: tbl.insert(0, ['ip', 'zone', 'network', 'staticnat', 'allocated', 'rules']) print tabulate(tbl, headers="firstrow")
s = scans.passive(target_result, args.dork) s.google() s.DuckDuckGo() if args.nmap != False: if args.nmap == None: n = scans.active(target_result.replace("http://", "")\ .replace("https://", "")) n.nmap("sudo nmap -v -sS -sC") elif args.nmap != None: n = scans.active(None) n.nmap(args.nmap) robots = target_result + "/robots.txt" rob_code = connection.conn(robots, args.UserAgent).HTTPcode() if rob_code == 200: print("Found: %s >> (%s)" % (robots, rob_code)) found.append(robots) else: if args.v != False: print(robots + " >> " + str(rob_code)) else: pass print("*" * 80) print("\t[RESULTS]") for k in found: print(k) elif active_count() > 1: loop = True
def main(): config = read_config() c = conn(config) args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) if args['list']: if args['--network']: res = c.list_portforwardingrules(networkid=get_network_from_name(c, args['--network']).id) elif args['--pubip']: res = c.list_portforwardingrules(ipaddressid=get_id_from_address(c, args['--pubip']).id) else: res = c.list_portforwardingrules() elif args['add']: try: if args['--pubip']: ipid = get_id_from_address(c, args['--pubip']).id network_id = get_id_from_address(c, args['--pubip']).networkid elif args['--network']: ipid = get_default_snat_id(c, get_network_from_name(c, args['--network']).id) network_id = get_network_from_name(c, args['--network']).id else: print "Either --network or --pubip must be specified" sys.exit(1) except Exception as e: print "Unable to determine network or ip: %s" % e sys.exit(1) try: vmid = get_instance_from_name(c, args['INSTANCE'], networkid=network_id).id except Exception as e: print "Unable to find specified instance: %s" % e sys.exit(1) try: for f in args['--forward']: proto_port = f.split('/') ports=proto_port[1].split(':') async = c.create_portforwardingrule( ipaddressid=ipid, virtualmachineid=vmid, publicport=ports[0], privateport=ports[1], protocol=proto_port[0]) res = [async.get_result()] if not res: raise Exception("An internal error occured.") except Exception as e: try: msg = e[1] except: msg = e print "Unable to create portforward rule: %s" % msg sys.exit(1) elif args['delete']: try: async = c.delete_portforwardingrule(id=args['UUID']) res = async.get_result() if not res: raise Exception("An internal error occured.") if res == 'succeded': sys.exit(0) else: raise Exception("Failure") except Exception as e: try: msg = e[1] except: msg = e print "Unable to delete portforward rule: %s" % msg sys.exit(1) if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "Unable to execute command" sys.exit(1)
def main(): config = read_config() c = conn(config, method='post') args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) res = False res_get = False if args['deploy']: try: res = deploy_vm(c, args) except Exception as e: print "error deploying instance: %s" % e sys.exit(1) elif args['destroy']: try: id = c.list_virtualmachines(name=args['INSTANCE']) if len(id) == 1: res = destroy_vm(c, id[0].id) else: # Multiple VMs returned if args['--network']: id = c.list_virtualmachines(name=args['INSTANCE'], networkid=get_network( c, args['--network'])[0].id) res = destroy_vm(c, id[0].id) else: print "Multiple instances with name: %s found, please supply a network name" % args[ 'INSTANCE'] except Exception as e: print "Error destroying instance: %s" % e elif args['stop']: try: id = c.list_virtualmachines(name=args['INSTANCE']) if len(id) == 1: res = stop_vm(c, id[0].id) else: # Multiple VMs returned if args['--network']: id = c.list_virtualmachines(name=args['INSTANCE'], networkid=get_network( c, args['--network'])[0].id) res = stop_vm(c, id[0].id) else: print "Multiple instances with name: %s found, please supply a network name" % args[ 'INSTANCE'] except Exception as e: print "Error stopping instance: %s" % e elif args['start']: try: id = c.list_virtualmachines(name=args['INSTANCE']) if len(id) == 1: res = start_vm(c, id[0].id) else: # Multiple VMs returned if args['--network']: id = c.list_virtualmachines(name=args['INSTANCE'], networkid=get_network( c, args['--network'])[0].id) res = start_vm(c, id[0].id) else: print "Multiple instances with name: %s found, please supply a network name" % args[ 'INSTANCE'] except Exception as e: print "Error starting instance: %s" % e elif args['list']: res = list_vms(c, args) elif args['get']: res = c.list_virtualmachines(name=args['INSTANCE']) else: print "Unable to execute command" sys.exit(1) if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "No virtual machines found, deploy new machines using `rbc-instances deploy`" sys.exit(1)
import discovery from flask import Flask, render_template, request, redirect, url_for, session from connection import conn from flask_cors import CORS import json import random import base64 app = Flask(__name__) CORS(app) app.config['SECRET_KEY'] = 'e5ac358c-f0bf-11e5-9e39-d3b532c10a28' cnx = conn() @app.route("/") def hello(): return "teste" @app.route('/manage/health') def manage_health(): return json.dumps({'status': 'UP'}) @app.route('/manage/info') def manage_info(): return json.dumps({'app': 'budget'}) @app.route("/basic/acquisition/<string:ano>")
"Mato Grosso": "Mato_Grosso", "Centro-Sul": "Centro_Sul", "Regiões do IMEA": "Periodo" }, inplace=True) # Renomeia as colunas para ficarem somente com letras minusculas df_final.columns = df_final.columns.str.lower() # Salva os registros lidos e tratados em CSV para ser usado no load.py # Caso já exista o arquivo, será apagado os registros e inseridos somente dessa leitura df_final.to_csv('transform_manual.csv', sep=';', mode='w', decimal='.') print("Transformação Finalizada!") engine = conn() if createTableSoja(engine): # Carrega os dados que já estão na tabela do BD query = "select * from soja as s order by s.ano asc, s.nrmes" df_existents = pd.read_sql(sql=query, con=engine) # Carrega os dados do arquivo 'transform.csv' que foi gerado na transformação (transform.py) df_newRegisters = pd.read_csv('transform_manual.csv', sep=";") # Cria um dataframe fazendo o join entre os dois DFs df_final = df_newRegisters.merge(df_existents, how='left', on=['periodo'])
def main(): config = read_config() c = conn(config, method='post') args = docopt(__doc__, version='%s %s' % (__cli_name__, __version__)) res = False res_get = False if args['deploy']: try: res = deploy_vm(c, args) except Exception as e: print "error deploying instance: %s" % e sys.exit(1) elif args['destroy']: try: id = c.list_virtualmachines(name=args['INSTANCE']) if len(id) == 1: res = destroy_vm(c, id[0].id) else: # Multiple VMs returned if args['--network']: id = c.list_virtualmachines(name=args['INSTANCE'], networkid=get_network(c, args['--network'])[0].id) res = destroy_vm(c, id[0].id) else: print "Multiple instances with name: %s found, please supply a network name" % args['INSTANCE'] except Exception as e: print "Error destroying instance: %s" % e elif args['stop']: try: id = c.list_virtualmachines(name=args['INSTANCE']) if len(id) == 1: res = stop_vm(c, id[0].id) else: # Multiple VMs returned if args['--network']: id = c.list_virtualmachines(name=args['INSTANCE'], networkid=get_network(c, args['--network'])[0].id) res = stop_vm(c, id[0].id) else: print "Multiple instances with name: %s found, please supply a network name" % args['INSTANCE'] except Exception as e: print "Error stopping instance: %s" % e elif args['start']: try: id = c.list_virtualmachines(name=args['INSTANCE']) if len(id) == 1: res = start_vm(c, id[0].id) else: # Multiple VMs returned if args['--network']: id = c.list_virtualmachines(name=args['INSTANCE'], networkid=get_network(c, args['--network'])[0].id) res = start_vm(c, id[0].id) else: print "Multiple instances with name: %s found, please supply a network name" % args['INSTANCE'] except Exception as e: print "Error starting instance: %s" % e elif args['list']: res = list_vms(c, args) elif args['get']: res = c.list_virtualmachines(name=args['INSTANCE']) else: print "Unable to execute command" sys.exit(1) if res: print_tabulate(res, noheader=args['--noheader'], short=args['--short']) else: print "No virtual machines found, deploy new machines using `rbc-instances deploy`" sys.exit(1)