Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #1

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CNU.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
austin:pr0ject.px
This is a triumph
10 changes: 10 additions & 0 deletions Modules/file_parse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


# Parsing Module

File Parsing
===========

This module helps us extract credential files from text files that are taken by the information center.

Inorder to run a testfile choose one of the files in the <b>testfiles</b> folder and run the python script with the filename and extension after it. This would be such as testing the extraction of credentials from the file <b>sample.txt</b> by running: `python __file_parse__.py sample.txt`
Empty file added Modules/file_parse/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import sys

#methods for obtaining credentials from a sample file.
#The paramemter passed is the file itself once opened.
#these methods are based on the sample of how the credentials will be sent remotely.
Expand All @@ -7,31 +9,31 @@ def obt_login(text):
first_line = text[0]
line_list = first_line.split(',')
#indentation can cause an error
return line_list[0].replace(" ", "")
return line_list[0].replace(" ", "")

def obt_pass(text):
first_line = text[0]
line_list = first_line.split(',')
return line_list[1].replace(" ", "")

def obt_message(text):
mess_line = text[2]
mess_line = text[1]
return mess_line


#file concatination:
file = open("sample.txt")
text = file.readlines()

#Printing the test file credentials

usr_login = obt_login(text)
print(usr_login)

usr_pass = obt_pass(text)
print(usr_pass)

usr_mess = obt_message(text)
print(usr_mess)


##file concatination:
#file = open('testfiles/'+sys.argv[1])
#text = file.readlines()
#
##Printing the test file credentials
#
#usr_login = obt_login(text)
#print(usr_login)
#
#usr_pass = obt_pass(text)
#print(usr_pass)
#
#usr_mess = obt_message(text)
#print(usr_mess)
#
#
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
login, pass

login, pass
This is a messsage
2 changes: 2 additions & 0 deletions Modules/file_parse/testfiles/sample1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr,1234
Hello World
Empty file added __init__.py
Empty file.
1 change: 1 addition & 0 deletions creds.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a triumph
39 changes: 39 additions & 0 deletions file_parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

import sys

#methods for obtaining credentials from a sample file.
#The paramemter passed is the file itself once opened.
#these methods are based on the sample of how the credentials will be sent remotely.

def obt_login(text):
first_line = text[0]
line_list = first_line.split(',')
#indentation can cause an error
return line_list[0].replace(" ", "")

def obt_pass(text):
first_line = text[0]
line_list = first_line.split(',')
return line_list[1].replace(" ", "")

def obt_message(text):
mess_line = text[1]
return mess_line


##file concatination:
#file = open('testfiles/'+sys.argv[1])
#text = file.readlines()
#
##Printing the test file credentials
#
#usr_login = obt_login(text)
#print(usr_login)
#
#usr_pass = obt_pass(text)
#print(usr_pass)
#
#usr_mess = obt_message(text)
#print(usr_mess)
#
#
Binary file added file_parse.pyc
Binary file not shown.
76 changes: 42 additions & 34 deletions sric_script.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,63 @@
import subprocess
from Modules.file_parse.__file_parse__ import obt_login
from Modules.file_parse.__file_parse__ import obt_pass
from Modules.file_parse.__file_parse__ import obt_message
from ftplib import FTP # I'd rather use ftputil, since it's a nice wrapper for ftplib, but it might make things slower?
from file_parse import obt_login
from file_parse import obt_pass
from file_parse import obt_message

# The IP of the server we're downloading/uploading things to/from
server = 192.168.1.1
ftp_addr = '192.168.1.200'

# The names of the files were dealing with
creds = 'credentials.txt'
upload = 'upload-package.txt'
download = 'team1.txt'
upload = open('upload_package.txt', 'r')
creds_file = open('credentials.txt', 'wb')

# Download creds
down_user = 'tmp'
down_pass = 'tmp'
# Where we want to put the file
upload_name = 'CNU/IMPRINT_upload_package.txt'
team_dir = '/home/austin'

# Upload Creds
up_user = 'tmp'
up_pass = 'tmp'
up_mess = 'tmp'
# Set up the FTP object
FTP.set_debuglevel(2)

# Loop forever!
while True:

# Verify connection
output = subprocess.check_output(['ping', '-n', '1', server])
# Verify connection before attempting to create FTP instance so we don't have to wait for 30 second timeout
# Does ftplib automatically check connections? If so we should remove this whole block and set ftplib's timeout to like, 1s
output = subprocess.check_output(['ping', '-n', '1', server]) # Need to fix this command to work on linux....
if output = 'tmp string for network down':
continue

try:
ftp = FTP(ftp_addr, timeout = 30)
except ftplib.all_errors, e:
print "FTP ERROR:", e
continue

# Connect to the FTP object and Login anonymously
ftp = FTP(ftp_addr)
ftp.login()

# Using SFPT because I'm not sure if we can use SCP
with pysftp.Connection('http://' + server, username = down_user, password = down_pass) as sftp:
# Get the download payload
sftp.get(creds, '/creds.txt')
# Open download file
cred_file = open(creds)
# Change directory if needed
if team_dir:
ftp.cwd(team_dir)

# Need to do more testing with this line, we might be able to just use storelines or retrlines...
# ftp.retrbinary('RETR', creds_file.write)
ftp.retrlines('RETR ' + download, lambda s, w = creds_file.write: w(s + '\n'))

# Parse it mytext reads all lines of the file contents
# up_usr and up_pass defined in file contents
text = cred_file.readlines()

up_user = obt_login(text)
up_pass = obt_pass(text)
up_mess = obt_message(text)
text = creds_file.readlines()

with pysftp.Connection(server, username = up_user, password = up_pass) as sftp:
# Put the upload payload
sftp.put(uplpad)
# Login with the new creds and put the file
ftp.quit()
ftp = FTP(ftp_addr, obt_login(text), obt_pass(text), timeout = 30)
ftp.storlines('STOR ', upload_name, upload)

# Close cred_file (After the put since we need to get that done as fast as possible)
cred_file.close()
# End this script to save resources for other things
ftp.quit()
cred_file.close()
upload.close()
break

# Not currently connected... Time to try again
# Not currently connected... Time to try again
1 change: 1 addition & 0 deletions upload_package.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CNU IMPRINT UAS - Upload Task SRIC