Beispiel #1
0
def login():
    try:
        with open(".virtualcloud", "w+") as json_data:
            try: 
                data = json.load(json_data)
            except ValueError:
                data = {}
    except IOError:
        print "Could not create new settings file"

    if not data:
        data = {'dropbox' : [], 'gdrive' : []}
        
    while True:
        cmd = raw_input("To add a service please enter 'dropbox' or 'gdrive'. When done, enter 'done': ").lower()
        if cmd == 'dropbox':
            db = db_ops.db(-1)
            data['dropbox'].append(db.AT)          
        if cmd == 'gdrive':
            gd = gd_ops.gd(-1)
            data['gdrive'].append(gd.credentials)        
        if cmd == 'done':
            break

    try:
        with open(".virtualcloud", "w+") as json_file:
            json.dump(data,json_file)
    except IOError:
        print "Sorry, failed to add accounts!"
        sys.exit()
Beispiel #2
0
def uploadNotChunked(fileName, service):
    userclouds = verifyLogin()

    if (service == 'dropbox'):
        #Create new instance of Dropbox Operations
        db = db_ops.db(userclouds['dropbox'][0])
        #Upload File
        db.db_upload(fileName)
        print "File uploaded!"
        
    elif (service == 'drive'):
        print "Choosing Drive"
        gd = gd_ops.gd()
        gd.gd_upload(fileName)
        print "File uploaded!"
Beispiel #3
0
def upload(fn, cs):
    inputfile = ''
    chunksize = 0
    buffer = 1024

    filename = fn
    chunksize = cs
    
    try:
        with open('.virtualcloud') as userjson:
            userclouds = json.load(userjson)
    except IOError:
        print "Please login first!"
        sys.exit()
    db_tokens = userclouds["dropbox"]
    dbclients = []
    for token in db_tokens:
        dbclients.append(db_ops.db(token))
        
    gd_tokens = userclouds["gdrive"]
    gdclients = []    
    for token in gd_tokens:
        gdclients.append(gd_ops.gd(token))

    prefix = hashlib.sha224(os.path.basename(filename)).hexdigest()
    
    with open (filename, 'r+b') as src:
        suffix = 0
        upload_completed = False
        while upload_completed is False:
            with tempfile.TemporaryFile() as target:
                data = src.read(chunksize)
                if data:
                    target.write(data)
                    #Iteration through clients TODO, temporarily only looks at first db client
                    outputfilepath = prefix + '.%s' % suffix
                    target.seek(0)
                    dbclients[0].db_upload(outputfilepath, target)
                    print "Uploaded piece: " + str(suffix)
                    suffix +=1
                else:
                    upload_completed = True
                    print "Upload Complete!"
Beispiel #4
0
def download (filename, targetdir=os.getcwd()):
    try:
        with open('.virtualcloud') as userjson:
            userclouds = json.load(userjson)
    except IOError:
        print "Please login first!"
        sys.exit()
    db_tokens = userclouds["dropbox"]
    dbclients = []
    for token in db_tokens:
        dbclients.append(db_ops.db(token))
        
    gd_tokens = userclouds["gdrive"]
    gdclients = []    
    for token in gd_tokens:
        gdclients.append(gd_ops.gd(token))

    prefix = hashlib.sha224(filename).hexdigest()

    #TODO: For now, only looking at dropbox client 0 
    dbfilelist = dbclients[0].client.metadata('/')['contents']
    infiles = []
    for file_data in dbfilelist:
        if file_data['is_dir']:
            continue
        if prefix in file_data['path']:
            infiles.append(file_data)

    infiles.sort(key = lambda k: int(k['path'].partition('.')[2]))       
    outfile = targetdir + '/' + filename
    
    with open(outfile, 'w+b') as target:
        for infile in infiles:
            with dbclients[0].db_download(infile['path']) as src:
                data = src.read()
                if data:
                    target.write(data)
                else:
                    break
Beispiel #5
0
def setup():
    try:
        with open(".virtualcloud", "w+") as json_data:
            try: 
                data = json.load(json_data)
            except ValueError:
                data = {}
    except IOError:
        print "Could not create new settings file"

    if not data:
        data = {'dropbox' : [], 'gdrive' : []}

    print "Welcome to VirtualCloud setup!\nHere you can add all your cloud services for easy one step access."
    print "To add a service please enter 'dropbox' or 'gdrive'. When done, enter 'done'.\n" \
              "If you want to remove all your accounts, enter 'clear'."
              
    while True:
        
        cmd = raw_input('(virtualcloud setup) ').lower()
        if cmd == 'dropbox':
            db = db_ops.db(-1)
            data['dropbox'].append(db.AT)          
        if cmd == 'gdrive':
            gd = gd_ops.gd(-1) 
        if cmd == 'clear':
            try:
                os.remove(".virtualcloud")
            except OSError:
                print 'No accounts found to be deleted.'
        if cmd == 'done':
            break

    try:
        with open(".virtualcloud", "w+") as json_file:
            json.dump(data,json_file)
    except IOError:
        print "Sorry, failed to add accounts!"
        sys.exit()
Beispiel #6
0
from flask import Flask, render_template, request
import hashlib
from db_ops import db

app = Flask(__name__)
database = db()

admin_status = False


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/form', methods=['POST', 'GET'])
def form():
    if request.method == 'GET':
        return render_template('form.html')
    elif request.method == 'POST':
        result = dict(request.form)
        result['password'] = hashlib.md5(
            result['password'].encode('utf-8')).hexdigest()
        database.store_data(result)
        return render_template("results.html", result=result)


@app.route('/data')
def data():
    data = database.retrieve_data()
    keys = data[0].keys()