コード例 #1
0
ファイル: UserClass.py プロジェクト: pvraj/OneDir
def timer():
    threading.Timer(10, timer).start();
    r = requests.post(SERVER_ADDRESS+"/pullChanges")

    # Connect to server
    response = requests.get(r.url)

    # Gets changes and stores them in pull_changes
    with open('pull_changes', 'w') as outfile:
        outfile.write(response.content)

    outfile.close()

    changes = open('pull_changes')
    for line in changes:
        commands = line.split(':')

        if commands[0] == 'CREATED FILE':
            FileWatch.pull_file(commands[1].strip())
        if commands[0] == 'DELETED FILE':
            FileWatch.remove_file(commands[1].strip())
        if commands[0] == 'MOVED FILE':
            FileWatch.move_file(commands[1].strip(), commands[2].rstrip())
        if commands[0] == 'MODIFIED FILE':
            FileWatch.modify_file(commands[1].strip())
        if commands[0] == 'CREATED DIR':
            FileWatch.create_dir(commands[1].strip())
        if commands[0] == 'DELETED DIR':
            FileWatch.remove_dir(commands[1].strip())
        if commands[0] == 'MOVED DIR':
            FileWatch.move_dir(commands[1].strip(), commands[2].rstrip())
コード例 #2
0
ファイル: run.py プロジェクト: pvraj/OneDir
		sys.exit()

# try:
# 	print "asdfasdf"
# 	from app import app
# 	app.run(debug = True)
# 	print "my name is dog"
# 	#test = raw_input("input")
# 	clean()
# except KeyboardInterrupt:
# 	print "hello this is dog"
# 	sys.exit()


#print "asdfasdf"
from app import app
UPLOAD_FOLDER = app.root_path + '/OneDir/'
ALLOWED_EXTENSIONS = set(['txt'])
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

# Watch upload folder
observer = FileWatch.watch_server(app.config['UPLOAD_FOLDER'])
observer.start()

app.run(host='0.0.0.0', debug = True)
print app.config['UPLOAD_FOLDER']
print "my name is dog"
#test = raw_input("input")
clean()
print "goodbye"
コード例 #3
0
ファイル: UserClass.py プロジェクト: pvraj/OneDir
def login(curs,con):
    logged_in = False
    current_username = None
    login = raw_input('Login (enter yes or no or admin): ')
    tries = 0
    if('y' in login.lower()):
        while(logged_in == False and tries < 3):
            tries +=1
            if(tries == 3):
                print 'Too many wrong attempts, system exiting'
                sys.exit()
            Username_Entered = raw_input('Please enter your username: '******'Please enter your password: '******'logged in'
            #    logged_in = True
            test = existsInServer(Username_Entered, Password_Entered)
            if (test):
                print "The username " + Username_Entered + "exists in the DB: " + str(test)
                # check password
                if (passwordInServer(Username_Entered, Password_Entered)):
                    print "The password seems to be CORRECT. logged-in to server SUCCESS."
                    logged_in = True
                else:
                    print "The password seems to be INCORRECT or you're already logged in. FAILURE."
                    logged_in = False

            else:
                print "The username " + Username_Entered + "exists in the DB: " + str(test)
                logged_in = False

        #start local file watch
        OBSERVER_LOCAL = FileWatch.watch_local(LOCAL_ROOT_DIR)
        OBSERVER_LOCAL.start()

        timer()


        delete = raw_input("Do you want delete account (d), change your settings (c), logout (L), or quit (q)?")
        if ('d' in delete.lower()):
            o =delete_User_DB(curs,con,Username_Entered)
            print o
            print "^ this should be the user name"
            o = generateNameObj(o)
            json_string = json.dumps(o)
            print "JSON: " + json_string
            headers = {'Content-type': 'application/json'}
            r = requests.post(SERVER_ADDRESS+"/deleteUser", data=json.dumps(o), headers=headers)
            print(r.url)
            print r.text
            return True
        elif ('c' in delete.lower()):
            change = raw_input('What setting would you like to change: password (P) or name(N)?')
            if('n' in change.lower()):
                newChange = raw_input('Please enter your new name: ')
                o = {"new_name" : newChange, "current_username": current_username}
                json_string = json.dumps(o)
                print "JSON: " + json_string
                headers = {'Content-type': 'application/json'}
                r = requests.post(SERVER_ADDRESS+"/changeName", data=json.dumps(o), headers=headers)
                print(r.url)
                statusStr = r.status_code
                statusStr = str(statusStr)
                if (str(statusStr[0]) != '2'):
                    print "the status code is bad"
                    print statusStr
                    sys.exit()
                else:
                    print "the status code is good"
                    if (r.text == '1'):
                        print "SERVER: Successfully changed name to " + newChange
                        return True
                    else:
                        print "SERVER: FAILED to change name."
                        sys.exit()
            #elif('p' in change.lower()):
                # asdfasdf
                #newChange = raw_input("Please enter your new password?")

                #p = {"username": current_username, "password": newChange}
                #json_string = json.dumps(p)
                #print "JSON: " + json_string
                #headers = {'Content-type': 'application/json'}
                #r = requests.post(SERVER_ADDRESS+"/changePassword", data=json.dumps(p), headers=headers)
            elif('n' in change.lower()):
                # do shit
                print "hello"
            else:
                print "Not sure what you meant there. Exiting...."
                sys.exit()
        elif ('l' in delete.lower()):
            print "Initating logout process..."
            obj = generateNameObj(current_username)
            json_string = json.dumps(obj)
            print "JSON: " + json_string
            headers = {'Content-type': 'application/json'}
            r = requests.post(SERVER_ADDRESS+"/userLogout", data=json.dumps(obj), headers=headers)
            print(r.url)
            statusStr = r.status_code
            statusStr = str(statusStr)
            if (str(statusStr[0]) != '2'):
                print "the status code is bad"
                print statusStr
                sys.exit()
            #existsInDB = False
            #return existsInDB
            #exit
            else:
                print "the status code is good"
                if (r.text == '1'):
                    print "SERVER: Successfully logged out..."
                    logged_in = False
                    return False
                else:
                    print "SERVER: Failed to log out..."
                    #logged_in = True
                    sys.exit()
        elif ('q' in delete.lower()):
            #print "asdfasd"
            return True
        else:
            print "Didn't catch that. Try typing it again."
            return True
    if('a' in login.lower()):
        while(logged_in == False):
            Username_Entered = raw_input('Please enter your username: '******'Please enter your password: '******'logged in'
            #    logged_in = True
            # needs to be changed to amdmin exits in server
            test = existsInServer(Username_Entered, Password_Entered)
            if (test):
                print "The username " + Username_Entered + "exists in the DB: " + str(test)
                # check password
                if (passwordInServer(Username_Entered, Password_Entered)):
                    print "The password seems to be CORRECT. logged-in to server SUCCESS."
                    logged_in = True
                else:
                    print "The password seems to be INCORRECT or you're already logged in. FAILURE."
                    logged_in = False
            else:
                print "The username " + Username_Entered + "exists in the DB: " + str(test)
                logged_in = False
            #start local file watch
        OBSERVER_LOCAL = FileWatch.watch_local(LOCAL_ROOT_DIR)
        OBSERVER_LOCAL.start()

        #start server file watch
        #OBSERVER_SERVER = FileWatch.watch_server(SERVER_ROOT_DIR)
        #OBSERVER_SERVER.start()

        delete = raw_input('Do you want delete account or change your settings (d for account deletion and c for settings change: ')
        if ('d' in delete.lower()):
            o =delete_User_DB(curs,con,Username_Entered)
            print o
            print "^ this should be the user name"
            o = generateNameObj(o)
            json_string = json.dumps(o)
            print "JSON: " + json_string
            headers = {'Content-type': 'application/json'}
            r = requests.post(SERVER_ADDRESS+"/deleteUser", data=json.dumps(o), headers=headers)
            print(r.url)
            print r.text
        elif ('c' in delete.lower()):
            change = raw_input('What setting would you like to change: password (P) or name(N)?')
            if('n' in change.lower()):
                newChange = raw_input('Please enter your new name: ')
                o = {"new_name" : newChange, "current_username": current_username}
                json_string = json.dumps(o)
                print "JSON: " + json_string
                headers = {'Content-type': 'application/json'}
                r = requests.post(SERVER_ADDRESS+"/changeName", data=json.dumps(o), headers=headers)
                print(r.url)
                statusStr = r.status_code
                statusStr = str(statusStr)
                if (str(statusStr[0]) != '2'):
                    print "the status code is bad"
                    print statusStr
                    sys.exit()
                else:
                    print "the status code is good"
                    if (r.text == '1'):
                        print "SERVER: Successfully changed name to " + newChange
                        return True
                    else:
                        print "SERVER: FAILED to change name."
                        sys.exit()
            #elif('p' in change.lower()):
                # asdfasdf
                #newChange = raw_input("Please enter your new password?")
                #p = {"username": Username_Entered, "password": newChange}
                #json_string = json.dumps(p)
                #print "JSON: " + json_string
                #headers = {'Content-type': 'application/json'}
                #r = requests.post(SERVER_ADDRESS+"/changePassword", data=json.dumps(p), headers=headers)
                #print r.text
                #print r.status_code
            elif('n' in change.lower()):
                # do shit
                print "hello"
            else:
                print "Not sure what you meant there. Exiting...."
                sys.exit()
        elif ('l' in delete.lower()):
            print "Initating logout process..."
            obj = generateNameObj(current_username)
            json_string = json.dumps(obj)
            print "JSON: " + json_string
            headers = {'Content-type': 'application/json'}
            r = requests.post(SERVER_ADDRESS+"/userLogout", data=json.dumps(obj), headers=headers)
            print(r.url)
            statusStr = r.status_code
            statusStr = str(statusStr)
            if (str(statusStr[0]) != '2'):
                print "the status code is bad"
                print statusStr
                sys.exit()
            #existsInDB = False
            #return existsInDB
            #exit
            else:
                print "the status code is good"
                if (r.text == '1'):
                    print "SERVER: Successfully logged out..."
                    logged_in = False
                    return False
                else:
                    print "SERVER: Failed to log out..."
                    #logged_in = True
                    sys.exit()
        elif ('q' in delete.lower()):
            #print "asdfasd"
            return True
        elif('z' in delete.lower()):
            admin_log = open('/Users/Rachel/PycharmProjects/OneDir/app/admin_backlog', 'r')
            for line in admin_log:
                print line
        else:
            print "Didn't catch that. Try typing it again."
            return True
    else:
       # sign_up(curs,con)
        print "Goodbye. Have a nice day!"
        return False