Esempio n. 1
0
def login_form():
    if request.method == 'POST':
        if request.form.get('sec-password'):
            return render_template('login.html',
                                   error='wrongpassword',
                                   what=[True, False])
        else:
            username = request.form.get('username')
            password = request.form.get('password')
            info = F.login(username, password)
            if info == 'usernotexist':
                return render_template('login.html',
                                       error='usernotexist',
                                       what=[True, False])
            elif info == 'wrongpassword':
                return render_template('login.html',
                                       error='wrongpassword',
                                       what=[True, False])
            else:
                user_id = F.get_id(username)[0]
                if F.get_2auth(user_id)[0] == "None":
                    res = make_response(redirect('/'))
                    res.set_cookie('WOWPOW',
                                   E.encrypt(str(F.get_id(username))))
                    return res
                else:
                    return render_template('2auth.html',
                                           info=[username, password],
                                           what=[True, False])
    else:
        return render_template("login.html", what=[True, False])
Esempio n. 2
0
def signup_form():
    if request.method == 'POST':
        name = request.form.get('name')
        username = request.form.get('username')
        password = request.form.get('password')
        rpassword = request.form.get('rpassword')
        email = request.form.get('email')
        nallowed = [' ', '/']
        for i in nallowed:
            if i in username:
                return render_template('signup.html',
                                       error='forbidchar',
                                       what=[True, False])
        jeff = F.signup(username, password, rpassword, name, email)
        if jeff == 'userexists':
            return render_template('signup.html',
                                   error='userexists',
                                   what=[True, False])
        elif jeff == 'passwordmatch':
            return render_template('signup.html',
                                   error='passwordnotmatch',
                                   what=[True, False])
        else:
            user_id = F.get_id(username)[0]
            F.init_folder(user_id)
            res = make_response(redirect('/'))
            res.set_cookie('WOWPOW', E.encrypt(str(F.get_id(username))))
            return res
    else:
        return render_template("signup.html", what=[True, False])
Esempio n. 3
0
def unlock_applet(neo, password):

    install_id = functions.get_id(neo)  #get id
    challenge = functions.get_challenge(neo)  #get challenge
    password_utf8 = password.encode('utf-8').strip()

    key = PBKDF2(password_utf8, install_id).read(16)
    response = hmac.new(key, challenge, hashlib.sha1).digest()
    cmd = commands['unlock']
    payload = functions.unlock_payload(response)

    try:
        data, status = neo._cmd(cmd['cl'], cmd['ins'], cmd['p1'], cmd['p2'],
                                payload)
        if status == 0x6a80:
            password_8bit = ""
            for x in range(0, len(password)):
                char = ord(password[x]) & 0xff
                password_8bit += chr(char)
            if password_8bit != password_utf8:
                key = PBKDF2(password_8bit, install_id).read(16)
                response = hmac.new(key, challenge, hashlib.sha1).digest()
                payload = functions.unlock_payload(response)
                data, status = neo._cmd(cmd['cl'], cmd['ins'], cmd['p1'],
                                        cmd['p2'], payload)
        if status != 0x9000:
            raise Exception('APDU eror: 0x%04x' % status)

        neo.password_protected = False
        return True
    except Exception, e:
        #set the NEO to none as we will need to check for password again
        neo = None
        print e
        return False
Esempio n. 4
0
def set_task_message(message):
    if func.check_set_message(message.text) != 0:
        data = func.check_set_message(message.text)
        string = data[1].split(':')
        if len(string) == 5:
            if 0 <= int(string[0]) <= 23:
                tz = pytz.timezone('Europe/Moscow')
                deadline = func.fetch_deadline(data[1])
                if deadline > datetime.now(tz):
                    if func.check_group(message):
                        if func.check_person(message, data[0]):
                            conn = psycopg2.connect(dbname='',
                                                    user='',
                                                    password='',
                                                    host='')
                            cursor = conn.cursor()
                            string = 'INSERT INTO ' + (
                                data[0])[1:] + ' VALUES (%s, %s, %s, %s)'
                            cursor.execute(
                                string, (str(data[2]), str(message.chat.title),
                                         str(func.idtoname(
                                             message.chat.id)), str(data[1])))
                            conn.commit()
                            cursor.close()
                            conn.close()
                            bot.send_message(
                                message.chat.id, 'Задание для ' + "@" +
                                (data[0])[1:] + ' успешно созданно')
                            answer = '@' + str(
                                message.from_user.username
                            ) + ' установил вам задачу: "' + str(
                                data[2]) + '" до ' + str(data[1])
                            bot.send_message(func.get_id(message, data[0]),
                                             answer)
                        else:
                            bot.send_message(
                                message.chat.id, "Похоже " + data[0] +
                                ' еще не присоединилась к данной группе')
                    else:
                        bot.send_message(
                            message.chat.id,
                            "Похоже данная группа еще не зарегистрированна, для регистрации введите /reg"
                        )
                else:
                    bot.send_message(
                        message.chat.id,
                        "К сожалению, у меня нет машины времени =(")
            else:
                bot.send_message(message.chat.id, "Ошибка, неверный формат")
        else:
            bot.send_message(message.chat.id, "Ошибка, неверный формат")
    else:
        bot.send_message(
            message.chat.id,
            "Похоже вы ввели команду в неправильном формате, для подробной информации введите /help"
        )
Esempio n. 5
0
def login2_form():
    if request.method == 'POST':
        if request.form.get('sec-password'):
            username = request.form.get('username')
            password = request.form.get('password')
            sec_password = request.form.get('sec-password')
            info = F.login(username, password)
            if info == 'usernotexist':
                return render_template('login.html',
                                       error='usernotexist',
                                       what=[True, False])
            elif info == 'wrongpassword':
                return render_template('login.html',
                                       error='wrongpassword',
                                       what=[True, False])
            else:
                user_id = F.get_id(username)[0]
                if F.get_2auth(user_id)[0] == "None":
                    res = make_response(redirect('/'))
                    res.set_cookie('WOWPOW',
                                   E.encrypt(str(F.get_id(username))))
                    return res
                else:
                    id = F.get_id(username)
                    pass2_encrypt = hashlib.sha224(
                        sec_password.encode()).hexdigest()
                    if F.get_2auth(user_id)[0] == pass2_encrypt:
                        res = make_response(redirect('/'))
                        res.set_cookie('WOWPOW',
                                       E.encrypt(str(F.get_id(username))))
                        return res
                    else:
                        return redirect('/')
        else:
            return redirect('/')
    else:
        return redirect('/')
def unlock_applet(neo, password):
    install_id = functions.get_id(neo) #get id
    challenge = functions.get_challenge(neo) #get challenge

    key = PBKDF2(password, install_id).read(16)
    response = hmac.new(key, challenge, hashlib.sha1).digest()
    cmd = commands['unlock']
    payload = functions.unlock_payload(response)

    try:
        result = neo._cmd_ok(cmd['cl'], cmd['ins'], cmd['p1'], cmd['p2'], payload)
        return True
    except Exception, e:
        #set the NEO to none as we will need to check for password again
        neo = None
        print e
        return False
def unlock_applet(neo, password):
    install_id = functions.get_id(neo)  #get id
    challenge = functions.get_challenge(neo)  #get challenge

    key = PBKDF2(password, install_id).read(16)
    response = hmac.new(key, challenge, hashlib.sha1).digest()
    cmd = commands['unlock']
    payload = functions.unlock_payload(response)

    try:
        result = neo._cmd_ok(cmd['cl'], cmd['ins'], cmd['p1'], cmd['p2'],
                             payload)
        return True
    except Exception, e:
        #set the NEO to none as we will need to check for password again
        neo = None
        print e
        return False
Esempio n. 8
0
def display_login():
    username = raw_input("username:\t")
    if username and len(username) > 0:
        password = raw_input("password:\t")
        if password and len(password) > 0:
            password = encrypt_string(password)

            if login(username, password):
                user_id = get_id(username, password)
                return user_id
            else:
                print "username, password is incorrect"
                return -1
        else:
            print "password is empty!!"
            return -1
    else:
        print "username is emtpy!!"
        return -1
		elif command_name == "calculate":
			payload = functions.calculate_payload(param)

			try:
				resp = neo._cmd_ok(cmd['cl'], cmd['ins'], cmd['p1'], cmd['p2'], payload)
				hotp = functions.parse_hotp_response(resp)
				return hotp	
			except Exception, e:
				#neo = None
				print e
				return None

		elif command_name == 'set_code':

			install_id = functions.get_id(neo) #get id
			challenge = '\x1f\x2f\x3f\x4f\x5f\x6f\x7f\x8f'

			#1000 round of pbkdf2
			key = PBKDF2(param, install_id).read(16)
			response = hmac.new(key, challenge, hashlib.sha1).digest()
			#build payload
			payload = functions.set_code_payload(key, response, challenge)

			try: 
				resp = neo._cmd_ok(cmd['cl'], cmd['ins'], cmd['p1'], cmd['p2'], payload)
				return 
				
			except Exception, e:
				print e
				return None
Esempio n. 10
0
    elif command_name == "calculate":
        payload = functions.calculate_payload(param)

        try:
            resp = neo._cmd_ok(cmd['cl'], cmd['ins'], cmd['p1'], cmd['p2'],
                               payload)
            hotp = functions.parse_hotp_response(resp)
            return hotp
        except Exception, e:
            #neo = None
            print e
            return None

    elif command_name == 'set_code':

        install_id = functions.get_id(neo)  #get id
        challenge = '\x1f\x2f\x3f\x4f\x5f\x6f\x7f\x8f'

        #1000 round of pbkdf2
        key = PBKDF2(param, install_id).read(16)
        response = hmac.new(key, challenge, hashlib.sha1).digest()
        #build payload
        payload = functions.set_code_payload(key, response, challenge)

        try:
            resp = neo._cmd_ok(cmd['cl'], cmd['ins'], cmd['p1'], cmd['p2'],
                               payload)
            return

        except Exception, e:
            print e
Esempio n. 11
0
	def generate_forest(self,exits=[]):
		self.exits = exits
		self.entrances = [] #ALife needs this
		
		for x in xrange(self.size[0]):
			for y in xrange(self.size[1]):
				self.map[x][y] = random.choice(var.GRASS)
				self.walking_space.append((x,y))
		
		#Lakes
		self.walk(walkers=7,where=self.walking_space,types=[10],intensity=(50,75),distance=(6,8))	
		self.decompose_ext(6,find=10,to=10,breakon=[15])
		self.decompose_ext(1,find=10,to=8,count=1)
		self.decompose_ext(1,find=8,to=36,count=2,breakon=[10])
		self.decompose_ext(1,find=36,to=37,count=1,breakon=[10])

		self.walking_space = []
		
		#Faster to do this here.
		#We'll randomize some features of the landscape and build an array
		#of open spaces.
		for x in xrange(self.size[0]):
			for y in xrange(self.size[1]):
				#Randomize water
				if self.map[x][y] == 10:
					self.map[x][y] = random.choice(var.WATER)
				
				#Building list of open spaces
				if not self.map[x][y] in var.solid and not self.map[x][y] in var.blocking:
					self.walking_space.append((x,y))
		
		_town = town()
		_town.generate()
		_room_size = (12,12)
		
		for _room_type in ['home','home','home','home','home','home','home','home','home',
			'store','store','bar','store','store','store','forge']:
			_room = []
			_zone = _town.get_random_zone()
			_pos = (50+(_zone['pos'][0])*_room_size[0],50+(_zone['pos'][1])*_room_size[1])
			
			__pos = list(_pos)
			if _zone['open'][0]==1:
				__pos[0]+=((_zone['open'][0]*_room_size[0])-1)
				__pos[1]+=((_zone['open'][1]*_room_size[1])+random.randint(2,_room_size[1]-1))
				_bridge_dir = 'right'
			elif _zone['open'][0]==-1:
				__pos[1]+=((_zone['open'][1]*_room_size[1])+random.randint(2,_room_size[1]-1))
				_bridge_dir = 'left'
			if _zone['open'][1]==1:
				__pos[1]+=((_zone['open'][1]*_room_size[1])-1)
				__pos[0]+=((_zone['open'][0]*_room_size[0])+random.randint(2,_room_size[0]-1))
				_bridge_dir = 'down'
			elif _zone['open'][1]==-1:
				__pos[0]+=((_zone['open'][0]*_room_size[0])+random.randint(2,_room_size[0]-1))
				_bridge_dir = 'up'
			
			_touches_land = True
			for ___pos in [(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]:
				____pos = (__pos[0]+___pos[0],__pos[1]+___pos[1])
				if not ____pos in self.real_estate:
					self.real_estate.append(____pos)
					if self.map[____pos[0]][____pos[1]] in var.WATER:
						_touches_land = False
			
			#Build a bridge
			if not _touches_land:
				_bpos = list(__pos)
				
				while 1:					
					if _bridge_dir in ['down','up']:
						for spot in [-1,2]:
							if _bpos[1]%2:
								self.map[_bpos[0]+spot][_bpos[1]] = 15
						
						self.map[_bpos[0]][_bpos[1]] = 16
						self.map[_bpos[0]+1][_bpos[1]] = 16
					else:
						for spot in [-1,2]:
							if _bpos[0]%2:
								self.map[_bpos[0]][_bpos[1]+spot] = 15
					
						self.map[_bpos[0]][_bpos[1]] = 16
						self.map[_bpos[0]][_bpos[1]+1] = 16
					
					if _bridge_dir == 'down':
						_bpos[1]+=1
					elif _bridge_dir == 'up':
						_bpos[1]-=1
					elif _bridge_dir == 'left':
						_bpos[0]-=1
					elif _bridge_dir == 'right':
						_bpos[0]+=1
					
					if not self.map[_bpos[0]][_bpos[1]] in var.blocking:
						break
				
			_door = (__pos[0]-_pos[0],__pos[1]-_pos[1])
			_building = self.generate_building(_door)
			
			_room_walls = []
			_room_floor = []
			for x in range(_building.size[0]):
				for y in range(_building.size[1]):
					_x = _pos[0]+y
					_y = _pos[1]+x
					self.real_estate.append((_x,_y))
					
					if not _building.house[y,x]:
						self.map[_x][_y] = 15
						_room_walls.append((_x,_y))
					else:
						self.map[_x][_y] = 16
						_room_floor.append((_x,_y))
			
			_walking = []
			for entry in _building.walking_space:
				_walking.append((_pos[0]+entry[0],_pos[1]+entry[1]))
			
			__room = {'name':_room_type,'walls':_room_walls,'walking_space':_walking,
				'door':__pos,'type':_room_type,'owner':None}
			
			__room['name'] += str(functions.get_id())
			
			#_room_walls.remove(tuple(__pos))
			if __room['type'] == 'home':
				_needs = [26,24,18]
			elif __room['type'] == 'store':
				_needs = [18,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21]
			elif __room['type'] == 'bar':
				_needs = [28,18,27,27,27]
			elif __room['type'] == 'forge':
				_needs = [30,18,31]
				__room['orders'] = ['23']
			
			self.map[__pos[0]][__pos[1]] = 16
			self.rooms.append(__room)
			#self.landmarks.append(random.choice(_room))
			
			for need in _needs:
				_pos = random.choice(__room['walking_space'])
				_stored = False
				for _storage in self.get_all_items_in_building_of_type(__room['name'],'storage'):
					_storage['items'].append(self.add_item(need,_pos,no_place=True))
					_stored = True
					break
				
				if not _stored:
					_i = self.add_item(need,_pos)
					
					if need == 28:
						_i['contains'] = 'ale'
		
		#for road in _town.get_all_zones_of_type('road'):
		#	_pos = (1+(road['pos'][0])*_room_size[0],1+(road['pos'][1])*_room_size[1])
		#	for x in xrange(0,_room_size[0]):
		#		_x = _pos[0]+x
		#		for y in xrange(0,_room_size[1]):
		#			_y = _pos[1]+y
		#			try:
		#				#if road['orientation']=='hor':
		#				#	if y==0 or y==_room_size[1]-1: continue
		#				#else:
		#				#	if x==0 or x==_room_size[0]-1: continue
		#				self.map[_x][_y]=29
		#			except:
		#				pass
		
		#Trees
		for t in xrange(140):
			_pos = (random.randint(10,self.size[0]-10),
				random.randint(10,self.size[1]-10))
			if self.map[_pos[0]][_pos[1]] in var.GRASS and not _pos in self.real_estate:
				_tree = self.add_item(32,_pos)
				_tree['limbs'] = self.generate_tree()
				self.claim_real_estate(_pos,(1,1))
		
		for pos in exits:
			self.map[pos[0]][pos[1]] = 4
			self.claim_real_estate(pos,(1,1))
Esempio n. 12
0
 def play(self, item, history = True, play = True):
  """
  Plays the track given in item.
  
  If history is True, add any current track to the history.
  If play is True, play the track immediately.
  """
  logger.debug('Playing item: %s.', item)
  id = functions.get_id(item)
  track = None # The object to store the track in until it's ready for playing.
  error = None # Any error that occured.
  if id in library.downloaded: # The file has already been downloaded.
   try:
    track = FileStream(file = library.get_path(item))
    if self.current_library and item in self.current_library:
     new_item = copy(item)
     if 'playCount' in new_item:
      new_item['playCount'] += 1
     self.current_library[self.current_library.index(item)] = new_item # Save it with the modified play count so the poll thread doesn't screw anything up.
   except BassError as e:
    del library.downloaded[id]
    return self.play(item, history = history, play = play) # Try again... File's probably not there or something...
  else:
   if id in library.downloading:
    if time() - library.downloading[id] <= config.config.get('library', 'download_timeout'):
     return wx.MessageBox('This song is still downloading, please wait.', 'Download In Progress')
    else:
     del library.downloading[id]
   try:
    url = application.mobile_api.get_stream_url(id)
   except gmusicapi.exceptions.CallFailure as e:
    application.device_id = None
    return wx.MessageBox('Cannot play with that device: %s.' % e, 'Invalid Device')
   except functions.RE as e:
    if self.current_track:
     self.current_track.set_position(self.current_track.get_length() - 1)
     self.play_pause.SetLabel(config.config.get('windows', 'play_label'))
    return wx.MessageBox(*functions.format_requests_error(e))
   try:
    track = URLStream(url = url)
   except BassError as e:
    error = e # Just store it for later alerting.
   if config.config.get('library', 'cache'): # The user wants their tracks downloaded.
    Thread(target = functions.download_file, args = [url, id, item]).start()
  if error:
   return wx.MessageBox(str(e), 'Error')
  if self.current_track:
   self.current_track.stop()
   if history:
    self.add_history(self.get_current_track())
  self._current_track = item
  if application.lyrics_frame:
   Thread(target = application.lyrics_frame.populate_lyrics, args = [item.get('artist'), item.get('title')]).start()
  self.current_track = track
  self.SetTitle()
  self.duration = columns.parse_durationMillis(self.get_current_track().get('durationMillis'))
  self.update_hotkey_area()
  self.set_volume()
  self.set_pan()
  self.set_frequency()
  if play:
   self.current_track.play()
   self.play_pause.SetLabel(config.config.get('windows', 'pause_label'))
  else:
   self.play_pause.SetLabel(config.config.get('windows', 'play_label'))
  filename = os.path.join(application.artwork_directory, item['albumId'] + '.jpg')
  if filename != self.album_art_filename:
   if filename in os.listdir(application.artwork_directory):
    logger.debug('Loading album art from cache.')
   else:
    url = item['albumArtRef'][0]['url']
    logger.debug('Downloading album art from %s.', url)
    art = requests.get(url)
    with open(filename, 'wb') as f:
     f.write(art.content)
   self.album_art_filename = filename
   i = wx.Image(filename)
   self.album_art.SetBitmap(i.ConvertToBitmap())
   i.Destroy()
   logger.info('Loaded album art from %s.', filename)
  try:
   Thread(target = application.mobile_api.increment_song_playcount, args = [id]).start()
   self.artist_info = application.mobile_api.get_artist_info(item['artistId'][0])
   try:
    self.set_artist_bio(self.artist_info.get('artistBio', 'No information available.'))
   except wx.PyDeadObjectError:
    pass # The frame has been deleted.
  except functions.RE:
   pass # We are not connected to the internet, but we can still play stuff.
Esempio n. 13
0
def home():
    if 'WOWPOW' in request.cookies:
        if request.cookies['WOWPOW'] == '':
            return render_template("index.html", what=[False, True, False])
        else:
            id = int(E.decrypt(request.cookies['WOWPOW'])[1])
            setting = F.get_settings(id)[2:]
            dirpath = 'root'
            if request.method == 'POST':
                if request.form.get('delete_file'):
                    delete = request.form.get('delete_file')
                    path = dirpath
                    if '/' in delete:
                        d2 = delete.split('/')[::-1][1:][::-1]
                        fin = ''
                        for i in d2:
                            fin += '/' + i
                        path = fin[1:]
                    if F.del_file(delete, id) == True:
                        return render_template(
                            "welcome.html",
                            error='Folder Deleted',
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, path),
                            path=path,
                            files=F.get_files(id, path),
                            settings=setting)
                    else:
                        return render_template(
                            "welcome.html",
                            error="Folder didn't delete",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                if request.form.get('add-file-path'):
                    path = request.form.get('add-file-path')
                    add_file = request.files['add-file']
                    seeif = F.add_file(id, path, add_file)
                    if seeif == True:
                        return render_template(
                            "welcome.html",
                            what=[True, True, F.get_userinfo(id)],
                            error="Success!",
                            folders=F.get_folders(id, path),
                            path=path,
                            files=F.get_files(id, path),
                            settings=setting)
                    elif seeif == False:
                        return render_template(
                            "welcome.html",
                            what=[True, True, F.get_userinfo(id)],
                            error="No file was selected!",
                            folders=F.get_folders(id, path),
                            path=path,
                            files=F.get_files(id, path),
                            settings=setting)
                elif request.form.get('file-menu'):
                    file_menu = request.form.get('file-menu')
                    file_menu_path = request.form.get('file-menu-path')
                    return render_template(
                        "welcome.html",
                        what=[True, True, F.get_userinfo(id)],
                        folders=F.get_folders(id, file_menu_path),
                        path=file_menu_path,
                        files=F.get_files(id, file_menu_path),
                        showfilemenu=file_menu,
                        settings=setting)
                elif request.form.get('cdir'):
                    cdir = request.form.get('cdir')[::-1][1:][::-1]
                    cdirpath = request.form.get('cdirpath')
                    newpath = ''
                    j = False
                    if '/' in cdirpath:
                        for i in cdirpath.split('/'):
                            if i == cdir:
                                newpath += i + '/'
                                j = True
                            else:
                                if j == False:
                                    newpath += i + '/'
                        newpath = newpath[::-1][1:][::-1]
                    else:
                        return render_template(
                            "welcome.html",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, cdirpath),
                            path=cdirpath,
                            files=F.get_files(id, cdirpath),
                            settings=setting)
                    return render_template(
                        "welcome.html",
                        what=[True, True, F.get_userinfo(id)],
                        folders=F.get_folders(id, newpath),
                        path=newpath,
                        files=F.get_files(id, newpath),
                        settings=setting)
                elif request.form.get('createfolderpath'):
                    path = request.form.get('createfolderpath')
                    fname = request.form.get('foldername')
                    create_folder = F.create_folder(id, path, fname)
                    if create_folder == True:
                        return render_template(
                            "welcome.html",
                            error="Success!",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, path),
                            path=path,
                            files=F.get_files(id, path),
                            settings=setting)
                    elif create_folder == 'folder_exist':
                        return render_template(
                            "welcome.html",
                            error="That folder already exists!",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, path),
                            path=path,
                            files=F.get_files(id, path),
                            settings=setting)
                    else:
                        return render_template(
                            "welcome.html",
                            error="ERROR",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, path),
                            path=path,
                            files=F.get_files(id, path),
                            settings=setting)
                elif request.form.get('goback'):
                    npath = request.form.get('goback').split(
                        '/')[::-1][1:][::-1]
                    path = ''
                    for i in npath:
                        path += '/' + i
                    path = path[1:] if path != '' else 'root'
                    return render_template(
                        "welcome.html",
                        what=[True, True, F.get_userinfo(id)],
                        folders=F.get_folders(id, path),
                        path=path,
                        files=F.get_files(id, path),
                        settings=setting)
                elif request.form.get("moveto"):
                    moveto = request.form.get('moveto')
                    movewhat = request.form.get('movepath')
                    moveit = F.move_dir(id, movewhat, moveto)
                    if moveit == 'cant_move_past_root':
                        return render_template(
                            "welcome.html",
                            error=
                            "You can't move directory past your root folder.",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    elif moveit == 'move_place_none':
                        return render_template(
                            "welcome.html",
                            error=
                            "The place you're moving the folder to doesn't exist.",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    elif moveit == 'error_3':
                        return render_template(
                            "welcome.html",
                            error="error_3",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    elif moveit == 'error_4':
                        return render_template(
                            "welcome.html",
                            error="error_4",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    else:
                        return render_template(
                            "welcome.html",
                            error="Success!",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                elif request.form.get('cancel'):
                    return render_template(
                        "welcome.html",
                        what=[True, True, F.get_userinfo(id)],
                        folders=F.get_folders(id, dirpath),
                        path=dirpath,
                        files=F.get_files(id, dirpath),
                        settings=setting)
                elif request.form.get('movefolder'):
                    what = request.form.get('movefolder')
                    if '/' in what:
                        what2 = what.split('/')
                        return render_template(
                            "welcome.html",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            movefolder=[what, what2[::-1][0]],
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    else:
                        return render_template(
                            "welcome.html",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            movefolder=[False, what],
                            files=F.get_files(id, dirpath),
                            settings=setting)
                elif request.form.get('trashwhat'):
                    what = request.form.get('trashwhat')
                    trash_it = F.trash_folder(id, what)
                    if trash_it == True:
                        return render_template(
                            "welcome.html",
                            error='Success',
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    elif trash_it == 'user_not_exists':
                        return render_template(
                            "welcome.html",
                            error='error_2',
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                elif request.form.get('dirpath'):
                    nowpath = request.form.get('dirpath')
                    newpath = request.form.get('chdir')
                    if nowpath == 'root':
                        dirpath = ''
                        dirpath += newpath
                        return render_template(
                            "welcome.html",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    else:
                        nowpath += '/' + newpath
                        dirpath = nowpath
                        return render_template(
                            "welcome.html",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                elif request.form.get('sharewhat'):
                    what = request.form.get('sharewhat')
                    towho = request.form.get('sendto')
                    if F.user_exists(towho) == True:
                        what = F.share_folder(id, what, F.get_id(towho))
                        if what == 'user_has_dir':
                            return render_template(
                                "welcome.html",
                                error=
                                'That user has a folder named the same as the one your sharing',
                                what=[True, True,
                                      F.get_userinfo(id)],
                                folders=F.get_folders(id, dirpath),
                                path=dirpath,
                                files=F.get_files(id, dirpath),
                                settings=setting)
                        elif what == True:
                            return render_template(
                                "welcome.html",
                                error='Success',
                                what=[True, True,
                                      F.get_userinfo(id)],
                                folders=F.get_folders(id, dirpath),
                                path=dirpath,
                                files=F.get_files(id, dirpath),
                                settings=setting)
                        elif what == 'share_user_not_exists':
                            return render_template(
                                "welcome.html",
                                error="User doesn't exist.",
                                what=[True, True,
                                      F.get_userinfo(id)],
                                folders=F.get_folders(id, dirpath),
                                path=dirpath,
                                files=F.get_files(id, dirpath),
                                settings=setting)
                        else:
                            return render_template(
                                "welcome.html",
                                error='error_1',
                                what=[True, True,
                                      F.get_userinfo(id)],
                                folders=F.get_folders(id, dirpath),
                                path=dirpath,
                                files=F.get_files(id, dirpath),
                                settings=setting)
                    else:
                        return render_template(
                            "welcome.html",
                            error="User doesn't exist!",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                elif request.form.get('rename'):
                    renamewhat = request.form.get('rename')
                    path = request.form.get('renamepath')
                    rename_result = F.rename_folder(path, renamewhat, id)
                    if rename_result == False:
                        return render_template(
                            "welcome.html",
                            error='folder_rename_error',
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    elif rename_result == 'rndirexists':
                        return render_template(
                            "welcome.html",
                            error='folder_rename_exists',
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    elif rename_result == 'spacebar':
                        return render_template(
                            "welcome.html",
                            error='folder_rename_spacebar',
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    else:
                        return render_template(
                            "welcome.html",
                            error='Success',
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                elif request.form.get('delete_folder'):
                    delete = request.form.get('delete_folder')
                    if F.del_folder(delete, id) == True:
                        return render_template(
                            "welcome.html",
                            error='Folder Deleted',
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
                    else:
                        return render_template(
                            "welcome.html",
                            error="Folder didn't delete",
                            what=[True, True, F.get_userinfo(id)],
                            folders=F.get_folders(id, dirpath),
                            path=dirpath,
                            files=F.get_files(id, dirpath),
                            settings=setting)
            return render_template("welcome.html",
                                   what=[True, True,
                                         F.get_userinfo(id)],
                                   folders=F.get_folders(id, dirpath),
                                   path=dirpath,
                                   files=F.get_files(id, dirpath),
                                   settings=setting)
    else:
        return render_template("index.html", what=[False, True, False])