def theirpassword(request, username=""): print "this is called" if not request.user.is_authenticated: return render(request, "login.html", {'login_failed': False, 'is_authenticated': False}) if not request.user.is_superuser: return HttpResponseRedirect('/password/') if request.method == 'POST': if request.POST['password'] == request.POST['confirmpw']: user = User.objects.get(username=request.POST['username']) user.set_password(request.POST['password']) user.save() user = request.user return render(request, "profile.html", { 'is_admin': isAdmin(user.id), 'files': getFiles(user.id), 'username': user.username, 'history': getHistory(user.id) }) else: return render(request, "password.html", { 'failed': True, 'username': user.username, 'is_admin': isAdmin(user.id), 'username2': username, 'viewing': True, }) if request.method == 'GET': user = request.user return render(request, "password.html", { 'username2': username, 'viewing': True, 'username': user.username, 'is_admin': isAdmin(user.id), })
def mypassword(request): if not request.user.is_authenticated: return render(request, "login.html", {'login_failed': False, 'is_authenticated': False}) if request.method == 'POST': user = request.user if request.POST['password'] == request.POST['confirmpw']: user.set_password(request.POST['password']) user.save() return render(request, "profile.html", { 'is_admin': isAdmin(user.id), 'files': getFiles(user.id), 'username': user.username, 'history': getHistory(user.id) }) else: return render(request, "password.html", { 'failed': True, 'username': user.username, 'is_admin': isAdmin(user.id), }) if request.method == 'GET': user = request.user return render(request, "password.html", { 'username': user.username, 'is_admin': isAdmin(user.id), })
def systemlist(request): if not request.user.is_authenticated: return render(request, "login.html", {'login_failed': False, 'is_authenticated': False}) if not request.user.is_superuser: return HttpResponseRedirect('/myprofile/') system_size = getFileSize("") system_files = getFiles("") user = request.user return render(request, "system.html", { 'username': user.username, 'is_admin': isAdmin(user.id), 'files': system_files, 'size': system_size })
def userlist(request): if not request.user.is_authenticated: return render(request, "login.html", {'login_failed': False, 'is_authenticated': False}) if not request.user.is_superuser: return HttpResponseRedirect('/myprofile/') userlist = [] for user in User.objects.all(): userinfo = [] userinfo.append(user.username) userinfo.append(getFileSize(user.id)) userlist.append(userinfo) user = request.user return render(request, "userlist.html", { 'username': user.username, 'is_admin': isAdmin(user.id), 'users': userlist, })
def share(request): if not request.user.is_authenticated: return HttpResponseRedirect('/') else: if request.method == 'POST': username = request.POST['username'] user = User.objects.get(username=username) path = '../uploads/' + str(request.user.id) + "/" copy_path = '../uploads/' + str(user.id) + "/" #Create a new log element for the designated user for every file in requesting user's filesystem for root, folder, filename in os.walk(path): key_counter = 0 for f in filename: #Get relative path of current file newpath = "/" + os.path.relpath(os.path.join(root, f), path) print newpath key = str(datetime.now()) + str(key_counter) action = UserAction( user=user, action="add", path=newpath, key=key, timestamp=getDateTime(key), ip=getClientIp(request) ) action.save() key_counter + 1 #Copy files from requesting user to designated user's filesystem copyTree(path, copy_path) return HttpResponseRedirect('/myprofile/') if request.method == 'GET': return render(request, 'share.html', { 'username': request.user.username, 'is_admin': isAdmin(request.user.id) })
def command( bot, line, socket ): #This is run if the bot's command symbol, by default '!' is found command, commandstring = helpers.getCmdAndCmdString( line ) command = command.lower() if command == '': return if command in [ 'say', 'echo' ]: bot.privmsg( commandstring ) if command in [ 'topic' ]: msg = helpers.prependNick( commandstring ) bot.privmsg( msg + "Topic is: " + bot.channeltopic ) if command in [ 'yourcode' ]: msg = helpers.prependNick( commandstring ) msg += 'https://github.com/vinaysrao/ircbot.git' bot.privmsg( msg ) if command in [ 'god' ]: msg = helpers.prependNick( commandstring ) msg += 'http://www.youtube.com/watch?v=8nAos1M-_Ts' bot.privmsg( msg ) if command in [ 'addnick' ]: nick = helpers.getnick( line ) if commandstring == '' or len( commandstring.split() ) > 1: return if helpers.isAdmin( bot, nick ): if bot.addKnownNick( commandstring ): bot.privmsg( commandstring + ' added to known nicks' ) if command in [ 'kick' ]: msg = chr( 1 ) + "ACTION kicks " + commandstring + chr( 1 ) bot.privmsg( msg ) if command in [ 'lmgtfy' ]: if commandstring == '': return query = commandstring.split( ' ', 1 ) if helpers.isNewNick( query[ 0 ], bot.activeNickList ): msg = '' query = '+'.join( query ) else: msg = query[ 0 ] + ': ' query = '+'.join( query[ 1: ] ) query = '+'.join( query.split() ) url = 'http://www.lmgtfy.com/?q=' + query msg += url bot.privmsg( msg ) if command in [ 'define' ]: s = wordnet.synsets( commandstring ) try: msg = s[ 0 ].definition.capitalize() except: msg = 'Definition not found' if commandstring == 'god': msg = "\' \'" bot.privmsg( msg ) if command in [ 'quit' ]: if( helpers.isAdmin( bot, helpers.getnick( line ) ) ): bot.serializeNicks() __import__( 'sys' ).exit( 0 ) if command in [ 'restart' ]: if( helpers.isAdmin( bot, helpers.getnick( line ) ) ): bot.serializeNicks() __import__( 'sys' ).exit( 1 ) if command in [ 'list' ]: msg = helpers.prependNick( commandstring ) msg += ', '.join( helpers.commandList() ) bot.privmsg( msg ) if command in 'togglewelcome': if( helpers.isAdmin( bot, helpers.getnick( line ) ) ): bot.welcome_new = not bot.welcome_new msg = 'Bot\'s welcome mode: %s' % bot.welcome_new bot.privmsg( msg )
def command(bot, line, socket): #This is run if the bot's command symbol, by default '!' is found command, commandstring = helpers.getCmdAndCmdString(line) command = command.lower() if command == '': return if command in ['say', 'echo']: bot.privmsg(commandstring) if command in ['topic']: msg = helpers.prependNick(commandstring) bot.privmsg(msg + "Topic is: " + bot.channeltopic) if command in ['yourcode']: msg = helpers.prependNick(commandstring) msg += 'https://github.com/vinaysrao/ircbot.git' bot.privmsg(msg) if command in ['god']: msg = helpers.prependNick(commandstring) msg += 'http://www.youtube.com/watch?v=8nAos1M-_Ts' bot.privmsg(msg) if command in ['addnick']: nick = helpers.getnick(line) if commandstring == '' or len(commandstring.split()) > 1: return if helpers.isAdmin(bot, nick): if bot.addKnownNick(commandstring): bot.privmsg(commandstring + ' added to known nicks') if command in ['kick']: msg = chr(1) + "ACTION kicks " + commandstring + chr(1) bot.privmsg(msg) if command in ['lmgtfy']: if commandstring == '': return query = commandstring.split(' ', 1) if helpers.isNewNick(query[0], bot.activeNickList): msg = '' query = '+'.join(query) else: msg = query[0] + ': ' query = '+'.join(query[1:]) query = '+'.join(query.split()) url = 'http://www.lmgtfy.com/?q=' + query msg += url bot.privmsg(msg) if command in ['google']: if commandstring == '': return query = commandstring.split(' ', 1) if helpers.isNewNick(query[0], bot.activeNickList): msg = '' query = '+'.join(query) else: msg = query[0] + ': ' query = '+'.join(query[1:]) query = '+'.join(query.split()) url = 'https://www.google.com/search?q=' + query msg += url bot.privmsg(msg) if command in ['define']: try: from nltk.corpus import wordnet except ImportError: bot.privmsg('NLTK Not found!') return s = wordnet.synsets(commandstring) try: msg = s[0].definition.capitalize() except: msg = 'Definition not found' if commandstring == 'god': msg = "\' \'" bot.privmsg(msg) if command in ['ud']: meaning = urbandict.define(commandstring) if meaning is not None: msg = meaning else: msg = "Definition not found" msg = ' '.join(msg.splitlines()) bot.privmsg(msg) if command in ['quit']: if (helpers.isAdmin(bot, helpers.getnick(line))): bot.serializeNicks() __import__('sys').exit(0) if command in ['restart']: if (helpers.isAdmin(bot, helpers.getnick(line))): bot.serializeNicks() __import__('sys').exit(1) if command in ['list']: msg = helpers.prependNick(commandstring) msg += ', '.join(helpers.commandList()) bot.privmsg(msg) if command in 'togglewelcome': if (helpers.isAdmin(bot, helpers.getnick(line))): bot.welcome_new = not bot.welcome_new msg = 'Bot\'s welcome mode: %s' % bot.welcome_new bot.privmsg(msg) if command in 'quiet': if (helpers.isAdmin(bot, helpers.getnick(line))): bot.quiet = not bot.quiet