Exemplo n.º 1
0
def poll():
	# global curr_time
	# ipdb.set_trace()
	global curr_time
	# curr = session['curr']
	while os.path.isfile('/mnt/lock'):
		pass
	a = soldier.run('sudo touch /mnt/lock', sudo=syspass)
	resp = []
	f = open('/mnt/chat.txt', 'r')
	lines = f.readlines()
	print lines
	for line in lines:
		tm = line.split("$$$")[0]
		print str(curr_time) + "   $$$   " + str(tm) 
		print int(tm) > int(curr_time)
		if int(tm) > int(curr_time):
			tt = datetime.datetime.fromtimestamp(int(tm)/1000).strftime('%Y-%m-%d %H:%M:%S')
			try:
				resp.append(tt + ' : ' + line.split("$$$")[1] + ' : ' + line.split("$$$")[2] )
				curr_time = int(tm)
			except:
				pass
			try:
				curr_time = int(tm)
			except:
				pass
	f.close()
	a = soldier.run('sudo rm /mnt/lock', sudo=syspass)
	# session['curr'] = curr
	return resp
Exemplo n.º 2
0
def create_repo(remote_ssh, description, name, is_private):
    if not name:
        dir_name = soldier.run('pwd').output
        repo_name = dir_name.strip().split('/')[-1]
    else:
        repo_name = name

    body = {
        'name': repo_name,
        'description': description,
        'private': is_private,
    }
    if py2:
        username = raw_input('Username: '******'Username: '******'Password: '******'ssh_url']
    https_url = req.json()['clone_url']
    
    remote_url = ssh_url if remote_ssh else https_url
    
    soldier.run('git init')
    soldier.run('git remote add origin {}'.format(remote_url))
    return req.status_code
Exemplo n.º 3
0
def run_script(data=[],tt=0,email=0):
    while os.path.isfile('script/lock'):
        continue
    if len(data) == 0:
        f = open("script/Input.csv","rb")
        r = csv.reader(f)
        for row in r:
            x.append( ', '.join(row))
        data = x
        # x = f.readlines()
        # x = x[1:]
        # data = x
    # ipdb.set_trace()
    try:
        a=soldier.run('touch script/lock')
        header  =   "Application Number,Type,Alias".split(",")
        fb      =   open('script/ready_nums.csv','w')
        w       =   csv.writer(fb,dialect='excel')
        w.writerow(header)
        fb.close()
        cnt = 1
        print 'len ==== ' + str(len(data))
        while cnt<len(data):
            try:
                os.remove(os.path.join(os.path.join(os.path.join(BASE_DIR,"script"),"Output"),"data.xlsx"))
            except:
                pass
            fb      =   open('script/Input.csv','w')
            w       =   csv.writer(fb,dialect='excel')
            w.writerow(header)
            for i in range(cnt,min(cnt+10,len(data))):
                w.writerow(data[i])
            cnt+=10
            fb.close()
            out = soldier.run('cat script/Input.csv')
            print out.output

            job     =   soldier.run('python3 script/patent.py')
            print job.output
            print job.is_alive()
            print "here"
            try:
                if email == 1:
                    print "run add data"
                    add_data()
                else:
                    diff_data()
            except:
                pass
            time.sleep(tt)
        a=soldier.run('rm script/lock')
    except:
        a=soldier.run('rm script/lock')
    if email == 1:
        send_emails("send")

    add_failed_nums()

    return
Exemplo n.º 4
0
def send_emails(r):
    To  = Email.objects.all()
    from_email = Email_USER
    job = soldier.run('cp script/update/data.xlsx script/update/data.xls')
    print job.output
    job = soldier.run('cp script/Total/data.xlsx script/Total/data.xls')
    print job.output
    job = soldier.run('cp script/Output/data.xlsx script/Output/data.xls')
    print job.output
    # for email,name in to:
    if r == 'add':
        # print to[0].name
        try:
            for to in To:
                send_mail("check","Hello "+to.name+" you are registered for email update.",from_email,[to.email])
            print "Mail sent"
        except BadHeaderError:
            return "Invalide Header Found"
    elif r == 'add':
        # print to[0].name
        try:
            for to in To:
                send_mail("check","Hello "+to.name+" you are unsubscribed for email update.",from_email,[to.email])
            print "Mail sent"
        except BadHeaderError:
            return "Invalide Header Found"
    elif r == 'update':
        # print to[0].name
        try:
            for to in To:
                email   =   EmailMessage("Difference in data.xls","Hello, "+to.name+".This is the data.xls file contain difference",from_email,[to.email])
                # send_mail("check","Hello "+to.name,from_email,[to.email])
                email.attach_file('script/update/data.xls')
                email.attach_file('script/Output/data.xls')
                try:
                    email.send()
                    print "Mail sent"
                except:
                    print "Mail not sent"
        except BadHeaderError:
            return "Invalide Header Found"

    else:
        try:
            for to in To:
                email   =   EmailMessage("data.xls","Hello, "+to.name+".This is the data.xls file",from_email,[to.email])
                # send_mail("check","Hello "+to.name,from_email,[to.email])
                email.attach_file('script/Total/data.xls')
                email.attach_file('script/failed_nums.csv')
                try:
                    email.send()
                    print "Mail sent"
                except:
                    print "Mail not sent"
        except BadHeaderError:
            return "Invalide Header Found"
Exemplo n.º 5
0
    def file_checker(self, path):
        #binary = file_as_bytes(open("..{}tmp{}{}".format(seperator,seperator, path), 'rb'))

        #binary = file_as_bytes(open(path, 'rb'))
        self.file_name = path.split(seperator)[-1]
        self.sample = {
            "binary": file_as_bytes(open(path, 'rb')),
            "name": self.file_name
        }
        self.file_md5 = hashlib.md5(self.sample["binary"]).hexdigest()
        self.file_sha1 = hashlib.sha1(self.sample["binary"]).hexdigest()
        self.file_sha256 = hashlib.sha256(self.sample["binary"]).hexdigest()
        self.file_date = datetime.now()

        self.counter = 0
        dp = DBProcessor()
        dp.select_samples_by_md5(self.file_md5)
        #self.dp.select_samples_by_md5(self.file_md5)

        if len(dp.rows) == 0:
            #self.ei.ask_bin({'file': ('sample', binary)})
            self.ei.ask_bin(self.sample)
            try:
                self.vt_url = self.ei.result["virustotal"]["permalink"]
                self.hybrid_url = "https://www.hybrid-analysis.com/sample/{}?environmentId=120".format(
                    self.ei.result["hybrid"]["sha256"])
            except:
                pass
            print(self.vt_url)
            print(self.hybrid_url)
            sample_info = (self.file_name, self.counter, self.file_md5,
                           self.file_sha1, self.file_sha256, self.vt_url,
                           self.hybrid_url, self.file_date)

            print(sample_info)
            with dp.conn:
                dp.insert_samples(sample_info)
            soldier.run('cp tmp{}{} samples{}{}'.format(
                seperator, self.file_name, seperator, self.file_name))
        else:
            self.counter = dp.rows[0][1] + 1
            sample_info = (self.counter, self.file_md5)
            print(self.counter)
            with dp.conn:
                dp.update_samples(sample_info)

            self.vt_url = dp.rows[0][5]
            self.hybrid_url = dp.rows[0][6]
        soldier.run('rm tmp{}{}'.format(seperator, self.file_name))
        """curl --request GET \
        --url 'https://www.virustotal.com/vtapi/v2/file/report?apikey=01ce6059fc6b30c8a999648cc664baac122761517d310ab1a8865dcd5e244332&resource=67c326feeb47e17a48aae78fe367b8db'
        {"response_code": 0, "resource": "67c326feeb47e17a48aae78fe367b8db", "verbose_msg": "The requested resource is not among the finished, queued or pending scans"}
        """
        print(self.file_md5)
Exemplo n.º 6
0
def send(msg,tm):
	# ipdb.set_trace()
	curr = tm
	while os.path.isfile('/mnt/lock'):
		pass
	a = soldier.run('sudo touch /mnt/lock', sudo=syspass)
	resp = []
	f = open('/mnt/chat.txt', 'a')
	f.write(str(curr) + '$$$' + str(session['name']) + '$$$' + msg + '\n')
	f.close()
	a = soldier.run('sudo rm /mnt/lock', sudo=syspass)
	return "success"
Exemplo n.º 7
0
def reduce_images(noi):
    tokeep = []
    i = 0
    cnt = 1
    os.chdir(
        "/home/akash/PycharmProjects/Djangoproject/Major_Project/Major/main_app"
    )
    # print soldier.run('cp ').output

    while (i <= noi - 1):
        tokeep.append(i)
        soldier.run('cp ' + str(i + 1) + '.jpg Final_Frames').output
        if cnt > 200:
            break

        for j in range(i + 1, noi):

            file1 = str(i) + ".jpg"
            file2 = str(j) + ".jpg"
            cnt = cnt + 1
            if cnt > 200:
                break
            i1 = Image.open(file1)
            i2 = Image.open(file2)
            size = 400, 400
            im_resized = i1.resize(size, Image.ANTIALIAS)
            im_resized.save(file1, "JPEG")
            im_resized2 = i2.resize(size, Image.ANTIALIAS)
            im_resized2.save(file2, "JPEG")
            # assert i1.mode == i2.mode, "Different kinds of images."
            # assert i1.size == i2.size, "Different sizes."
            pairs = zip(im_resized.getdata(), im_resized2.getdata())
            if len(i1.getbands()) == 1:
                # for gray-scale jpegs
                dif = sum(abs(p1 - p2) for p1, p2 in pairs)
            else:
                dif = sum(
                    abs(c1 - c2) for p1, p2 in pairs for c1, c2 in zip(p1, p2))

            ncomponents = i1.size[0] * i1.size[1] * 3
            perc = (dif / 255.0) * 100 / ncomponents
            print(perc)
            if (perc >= 20):  # not similar frames!
                i = j
                break
            if j == noi:
                fl = 1
                # print "Difference (percentage):", (dif / 255.0 * 100) / ncomponents
    for i in range(0, len(tokeep)):
        print(tokeep[i])
Exemplo n.º 8
0
def deploy():
    screen_name = "osdc_bot"
    screen_kill_comm = "screen -S {} -X quit".format(screen_name)
    screen_start_comm = 'screen -S "{}" -d -m'.format(screen_name)
    update_local_comm = "git pull origin master"
    start_bot_comm = ('screen -r "{0}" -X stuff "{1}"'.format(
        screen_name, "DEPLOY=1 nodejs chatbot.js\n"))
    try:
        soldier.run(screen_kill_comm)
    except:
        pass

    print(soldier.run(update_local_comm).status_code)
    print(soldier.run(screen_start_comm).status_code)
    print(soldier.run(start_bot_comm).status_code)
    return 'Deployed'
Exemplo n.º 9
0
def create_repo(remote_ssh, description):
    dir_name = soldier.run("pwd").output
    repo_name = dir_name.strip().split("/")[-1]

    body = {"name": repo_name}
    if py2:
        username = raw_input("Username: "******"Username: "******"Password: "******"ssh_url"]
    https_url = req.json()["clone_url"]

    remote_url = ssh_url if remote_ssh else https_url

    soldier.run("git init")
    soldier.run("git remote add origin {}".format(remote_url))
    return req.status_code
Exemplo n.º 10
0
def index():
	global curr_time
	global syspass
	if request.method == 'GET':
		return render_template('index.html')
	elif request.method == 'POST':
		# ipdb.set_trace()
		enroll = request.form['enroll']
		passwd = request.form['pass']
		syspass = request.form['syspass']
		name = request.form['name']
		session['name'] = name
		a = soldier.run('sudo mount -t cifs //fileserver2/' + enroll + ' /mnt -o user='******',password='******',workgroup=workgroup,ip=172.16.68.30', sudo=syspass)
		# a = soldier.run()
		if os.path.isfile('/mnt/chat.txt') == False:
			a = soldier.run('sudo touch /mnt/chat.txt', sudo=syspass)
		curr_time = time.time()
		session['user']=1
		# print session['curr']
		return redirect('/chat')
Exemplo n.º 11
0
def index():
	if request.method == 'GET':
		return render_template('index.html')

	elif request.method == 'POST':
		# ipdb.set_trace()
		filename = request.form['filename']
		passwd = request.form['pass']
		# ipdb.set_trace()
		try:
			# check if file already exists
			# if doesnt exists then create a new file and enter details in redis
			if not r.exists(filename) or r.exists == None:
				r.hmset(filename,{request.remote_addr:filename})
				r.set(filename+'pass',passwd)
				a=soldier.run('touch app/files/' + filename)
				# start queue for sending data to clients 
				start_queue(filename)
			# if exists check for password
			else:
				if r.exists(filename+'pass'):
					if r.get(filename+'pass')!=passwd:
						return redirect('/')
		except:
			# exception will be if file is not present hence create the file
			r.hmset(filename,{request.remote_addr:filename})
			r.set(filename+'pass',passwd)
			a=soldier.run('touch app/files/' + filename)
			# start queue for sending data to clients 
			start_queue(filename)
			if r.get(filename+'pass')!=passwd:
				return redirect('/')

		# add filename to curr ip and vice versa in redis
		ip_file_map = r.hgetall(filename)
		ip_file_map[request.remote_addr] = filename
		r.hmset(filename,ip_file_map)
		r.set(request.remote_addr, filename)
		# store that user is logged in 
		session['logged_in'] = filename
		return redirect('/edit/' + filename)
Exemplo n.º 12
0
def serve(path):
    if not os.path.exists(path):
        raise Exception("Wrong path provided")

    current_dir = os.getcwd()
    os.chdir(path)
    proc = soldier.run(f'python3 -m http.server {MEDIA_PORT}', background=True)
    os.chdir(current_dir)
    if not proc.is_alive():
        raise Exception(proc.error)

    return proc
Exemplo n.º 13
0
 def test_pipe(self):
     ls_output = soldier.run('ls | grep {}'.format(self.testdir)).\
                     output.strip()
     assert ls_output == self.testdir
Exemplo n.º 14
0
def send_emails(r):
    To = Email.objects.all()
    from_email = Email_USER
    job = soldier.run('cp script/update/data.xlsx script/update/data.xls')
    print job.output
    job = soldier.run('cp script/Total/data.xlsx script/Total/data.xls')
    print job.output
    job = soldier.run('cp script/Output/data.xlsx script/Output/data.xls')
    print job.output
    # for email,name in to:
    if r == 'add':
        # print to[0].name
        try:
            for to in To:
                send_mail(
                    "check", "Hello " + to.name +
                    " you are registered for email update.", from_email,
                    [to.email])
            print "Mail sent"
        except BadHeaderError:
            return "Invalide Header Found"
    elif r == 'add':
        # print to[0].name
        try:
            for to in To:
                send_mail(
                    "check", "Hello " + to.name +
                    " you are unsubscribed for email update.", from_email,
                    [to.email])
            print "Mail sent"
        except BadHeaderError:
            return "Invalide Header Found"
    elif r == 'update':
        # print to[0].name
        try:
            for to in To:
                email = EmailMessage(
                    "Difference in data.xls", "Hello, " + to.name +
                    ".This is the data.xls file contain difference",
                    from_email, [to.email])
                # send_mail("check","Hello "+to.name,from_email,[to.email])
                email.attach_file('script/update/data.xls')
                email.attach_file('script/Output/data.xls')
                try:
                    email.send()
                    print "Mail sent"
                except:
                    print "Mail not sent"
        except BadHeaderError:
            return "Invalide Header Found"

    else:
        try:
            for to in To:
                email = EmailMessage(
                    "data.xls",
                    "Hello, " + to.name + ".This is the data.xls file",
                    from_email, [to.email])
                # send_mail("check","Hello "+to.name,from_email,[to.email])
                email.attach_file('script/Total/data.xls')
                email.attach_file('script/failed_nums.csv')
                try:
                    email.send()
                    print "Mail sent"
                except:
                    print "Mail not sent"
        except BadHeaderError:
            return "Invalide Header Found"
Exemplo n.º 15
0
def init_folders():
    soldier.run("mkdir samples")
    soldier.run("mkdir tmp")
Exemplo n.º 16
0
    commands = [
        'sudo -i apt-get install rabbitmq-server -y',
        'sudo rabbitmq-plugins enable rabbitmq_management',
        'sudo -i rabbitmq-server -detached',
        'sudo -i rabbitmqctl stop_app',
        'sudo -i rabbitmqctl reset',
        'sudo -i rabbitmqctl start_app',
        'sudo -i rabbitmqctl cluster_status',
    ]
    single_command = "\n".join(commands)
    shell_lines = ssh_session(host, single_command)
    for s in shell_lines:
        print s

    # To transfer SSL files to AWS instance
    soldier.run("scp -i " + path_key + " -r " + path_ssl_keys + " ubuntu@" +
                host + ":~/").output
    # To transfer rabbitmq.config
    soldier.run("scp -i " + path_key + " -r " + path_config_file + " ubuntu@" +
                host + ":~/").output
    print "Soldier Done!!"
    commands = [
        "sudo -i mv /home/ubuntu/rabbitmq.config /etc/rabbitmq",
        "sudo -i mv /etc/rabbitmq/rabbitmq-env.conf /etc/rabbitmq/rabbitmq-env.conf.old",
        "sudo -i /etc/init.d/rabbitmq-server stop",
        "sudo -i /etc/init.d/rabbitmq-server start",
        # Above 2 commands to restart RMQ server
    ]
    single_command = "\n".join(commands)
    shell_lines = ssh_session(host, single_command)
    for s in shell_lines:
        print s
Exemplo n.º 17
0
def select_dir():  #TODO
    soldier.run("python /home/" + user + "/File-Server-Sync-System-/main.py",
                sudo=def_syspass)
Exemplo n.º 18
0
def howdoi():
    command = soldier.run('howdoi {}'.format(request.args['query']))
    print(command.status_code)
    return '```\n{}\n```'.format(command.output)
Exemplo n.º 19
0
import soldier

soldier.run(
    "sudo RABBITMQ_NODE_PORT=5673 RABBITMQ_NODENAME=rb1 rabbitmq-server -detached"
).output
soldier.run(
    "sudo RABBITMQ_NODE_PORT=5674 RABBITMQ_NODENAME=rb2 rabbitmq-server -detached"
).output

soldier.run("sudo rabbitmqctl -n rb1 stop_app").output
soldier.run("sudo rabbitmqctl -n rb1 reset").output
soldier.run("sudo rabbitmqctl -n rb1 start_app").output

soldier.run("sudo rabbitmqctl -n rb2 stop_app").output
soldier.run("sudo rabbitmqctl -n rb2 reset").output
soldier.run("sudo rabbitmqctl -n rb2 start_app").output

soldier.run("sudo rabbitmqctl -n rb2 stop_app").output
soldier.run("sudo rabbitmqctl -n rb2 join_cluster rb1@ANIKET").output
soldier.run("sudo rabbitmqctl -n rb2 start_app").output

soldier.run(
    " sudo rabbitmqctl -n rb1 set_policy ha-all \"\" \'{\"ha-mode\":\"all\",\"ha-sync-mode\":\"automatic\"}\'"
).output

## Some notes:
##Cluster of rabbitMQ nodes set
##HA policy set
## Erlang cookie will as it is be same if we follow AWS guide to form nodes
## HAProxy if used can be configured here
def select_dir():#TODO
	soldier.run("python /home/"+user+"/File-Server-Sync-System-/main.py", sudo=def_syspass)
Exemplo n.º 21
0
#Video compression code on the basis of difference in consecutive frames

import soldier
from itertools import izip
import Image

noi = 200
tokeep = []
i = 0
cnt = 1

#print soldier.run('cp ').output

while (i <= noi - 1):
    tokeep.append(i)
    soldier.run('cp ' + str(i + 1) + '.jpg Final_Frames').output
    if cnt > 200:
        break

    for j in range(i + 1, noi):

        file1 = str(i) + ".jpg"
        file2 = str(j) + ".jpg"
        cnt = cnt + 1
        if cnt > 200:
            break
        i1 = Image.open(file1)
        i2 = Image.open(file2)
        size = 400, 400
        im_resized = i1.resize(size, Image.ANTIALIAS)
        im_resized.save(file1, "JPEG")
Exemplo n.º 22
0
def sync():  #TODO
    soldier.run("python /home/" + user + "/File-Server-Sync-System-/samba.py",
                sudo=def_syspass)
Exemplo n.º 23
0
 def test_rmdir(self):
     soldier.run('rmdir {}'.format(self.testdir))
     assert not os.path.exists(os.getcwd() + '/' + self.testdir)
Exemplo n.º 24
0
 def test_pwd(self):
     pwd_output = soldier.run('pwd').output.strip()
     assert pwd_output == os.getcwd()
Exemplo n.º 25
0
def run_script(data=[], tt=0, email=0):
    while os.path.isfile('script/lock'):
        continue
    if len(data) == 0:
        f = open("script/Input.csv", "rb")
        r = csv.reader(f)
        for row in r:
            x.append(', '.join(row))
        data = x
        # x = f.readlines()
        # x = x[1:]
        # data = x
    # ipdb.set_trace()
    try:
        a = soldier.run('touch script/lock')
        header = "Application Number,Type,Alias".split(",")
        fb = open('script/ready_nums.csv', 'w')
        w = csv.writer(fb, dialect='excel')
        w.writerow(header)
        fb.close()
        cnt = 1
        print 'len ==== ' + str(len(data))
        while cnt < len(data):
            try:
                os.remove(
                    os.path.join(
                        os.path.join(os.path.join(BASE_DIR, "script"),
                                     "Output"), "data.xlsx"))
            except:
                pass
            fb = open('script/Input.csv', 'w')
            w = csv.writer(fb, dialect='excel')
            w.writerow(header)
            for i in range(cnt, min(cnt + 10, len(data))):
                w.writerow(data[i])
            cnt += 10
            fb.close()
            out = soldier.run('cat script/Input.csv')
            print out.output

            job = soldier.run('python3 script/patent.py')
            print job.output
            print job.is_alive()
            print "here"
            try:
                if email == 1:
                    print "run add data"
                    add_data()
                else:
                    diff_data()
            except:
                pass
            time.sleep(tt)
        a = soldier.run('rm script/lock')
    except:
        a = soldier.run('rm script/lock')
    if email == 1:
        send_emails("send")

    add_failed_nums()

    return
def sync(): #TODO
	soldier.run("python /home/"+user+"/File-Server-Sync-System-/samba.py", sudo=def_syspass)
Exemplo n.º 27
0
 def hybrid_submit_file(self, input):
     self.hybrid_sh_writer(input)
     self.result["hybrid"] = json.loads(
         soldier.run('sh lib{}hybrid.sh'.format(seperator)).output)