示例#1
0
def main():
	if os.environ['REQUEST_METHOD'] != 'POST': # Forbidden
		tools.redirect('/')
		exit()
		
	form = cgi.FieldStorage()
	r_url = form.getfirst("r_url")
	r_content = form.getfirst("r_content")
	r_type = form.getfirst("r_type")
	r_url = unicode(r_url, 'utf-8') if r_url else None
	r_content = r_content if r_content else None
	r_type = unicode(r_type, 'utf-8') if r_type else None
	
	if not r_url or r_url == 'http://': # url not passed
		tools.redirect('/')
		exit()
		
	if not r_url.startswith('http://') and not r_url.startswith('https://'):
		r_url = 'http://'+r_url
		
	try:
		if not r_content or not r_type:
			r_content, r_type, r_url = fetch(r_url)
	except DownloadFail, e:
		tools.printError('Download error', 'Sorry, we couldn\'t access to address you provided. Please try again in a few seconds.')
		tools.logException()
		exit()
示例#2
0
def main():
	try:
		if os.environ['REQUEST_METHOD'] != 'POST': # Forbidden
			raise Forbidden
		if users.get_current_user() == None:
			raise Forbidden
			
		form = cgi.FieldStorage()
		r_id = form.getfirst("id")
		r_token = form.getfirst("token")
		r_action = form.getfirst("action")
		
		if r_action != 'del':
			raise Forbidden
		page = models.Page.get_by_key_name('K'+r_id)
		if page is None or page.public < 0: raise NotFound
		
		if not users.is_current_user_admin() and page.owner != users.get_current_user():
			raise Forbidden
		if r_token != tools.token(page):
			raise Forbidden
			
		page.public = -1
		page.put()
		
		tools.redirect('/my')
	except Forbidden:
		tools.printError("Forbidden", "You've just tried to do some evil thing. We didn't expect that of you.")
	except NotFound:
		tools.printError("Not found", "We think you are playing unfair.")
示例#3
0
def main():
    try:
        if os.environ['REQUEST_METHOD'] != 'POST':  # Forbidden
            raise Forbidden
        user = users.get_current_user()
        if user == None:
            raise Forbidden

        form = cgi.FieldStorage()
        r_id = form.getfirst("id")
        r_token = form.getfirst("token")
        r_action = form.getfirst("action")

        if r_action != 'del':
            raise Forbidden
        page = models.Page.get_by_key_name('K' + r_id)
        if page is None or page.public < 0: raise NotFound

        if not users.is_current_user_admin() and page.owner != user:
            raise Forbidden
        if r_token != tools.token(page, user):
            raise Forbidden

        page.public = -1
        page.put()

        tools.redirect('/my')
    except Forbidden:
        tools.printError(
            "Forbidden",
            "You've just tried to do some evil thing. We didn't expect that of you."
        )
    except NotFound:
        tools.printError("Not found", "We think you are playing unfair.")
示例#4
0
def main():
    try:
        args = cgi.FieldStorage()
        r_id = args.getfirst("id")
        cookies = Cookie.SimpleCookie(os.environ['HTTP_COOKIE'])
        r_token = cookies['anonymous_token'].value

        user = users.get_current_user()
        if not user: raise Forbidden

        page = models.Page.get_by_key_name('K' + r_id)
        if page is None: raise NotFound(id)

        if page.public != 0: raise Forbidden
        if not isAnonymous(page.owner): raise Forbidden
        if r_token != tools.token(page, page.owner): raise Forbidden

        page.public = 1
        page.owner = user
        page.put()

        tools.redirect('/' + page.key().name()[1:])
    except Forbidden:
        tools.printError(
            "Forbidden",
            "You've just tried to do some evil thing. We didn't expect that of you."
        )
    except NotFound:
        tools.printError("Not found", "We think you are playing unfair.")
示例#5
0
def main():
	try:
		args = cgi.FieldStorage()
		r_id = args.getfirst("id")
		cookies = Cookie.SimpleCookie(os.environ['HTTP_COOKIE'])
		r_token = cookies['anonymous_token'].value

		user = users.get_current_user()
		if not user: raise Forbidden

		page = models.Page.get_by_key_name('K'+r_id)
		if page is None: raise NotFound(id)

		if page.public != 0: raise Forbidden
		if not isAnonymous(page.owner): raise Forbidden
		if r_token != tools.token(page, page.owner): raise Forbidden

		page.public = 1
		page.owner = user
		page.put()

		tools.redirect('/'+page.key().name()[1:])
	except Forbidden:
		tools.printError("Forbidden", "You've just tried to do some evil thing. We didn't expect that of you.")
	except NotFound:
		tools.printError("Not found", "We think you are playing unfair.")
示例#6
0
def main():
	user = users.get_current_user()
	if user is None: # do not show anonymous uploads with unworking del button
		tools.redirect('/')
		return
		
	pages = models.Page.all().filter('owner =', user).filter('public >', 0).order('-public').order('-date').fetch(2000)
	print MyTemplate(user=user, pages=pages).utf8()
示例#7
0
def main():
    user = users.get_current_user()
    if user is None:  # do not show anonymous uploads with unworking del button
        tools.redirect('/')
        return

    pages = models.Page.all().filter('owner =', user).filter(
        'public >', 0).order('-public').order('-date').fetch(2000)
    print MyTemplate(user=user, pages=pages).utf8()
示例#8
0
 async def delete(self):
     task = Task({
         'id': self.match_info['id'],
         'account_id': self.account.id
     })
     await db.delete_task(self.app.pool, task)
     raise redirect(self, 'index')
示例#9
0
文件: views.py 项目: rozumalex/notify
 async def update(self):
     data = await self.post()
     try:
         await self.account.update_personal_info(self.app.pool, data)
     except ValidationError as e:
         return {
             'session': self.session,
             'account': self.account,
             'error': e
         }
     raise redirect(self, 'profile')
示例#10
0
文件: views.py 项目: rozumalex/notify
 async def delete(self):
     data = await self.post()
     try:
         await self.account.delete(self.app.pool, data)
     except LoginError as e:
         return {
             'session': self.session,
             'account': self.account,
             'error': e
         }
     else:
         self.session.pop('account_id')
         raise redirect(self, 'login')
示例#11
0
文件: upload.py 项目: giteugen/peeep
def main():
	if os.environ['REQUEST_METHOD'] != 'POST': # Forbidden
		tools.redirect('/')
		exit()
		
	form = cgi.FieldStorage()
	r_url = form.getfirst("r_url")
	r_content = form.getfirst("r_content")
	r_type = form.getfirst("r_type")
	r_url = unicode(r_url, 'utf-8') if r_url else None
	r_content = r_content if r_content else None
	r_type = unicode(r_type, 'utf-8') if r_type else None
	verified = False
	
	if not r_url or r_url == 'http://': # url not passed
		tools.redirect('/')
		exit()
		
	if not r_url.startswith('http://') and not r_url.startswith('https://'):
		r_url = 'http://'+r_url

	user = users.get_current_user()
	public = 1 if user is not None else 0
	if user:
		owner = user
	else:
		owner = generateAnonymous()
		
	try:
		if not r_content or not r_type:
			r_content, r_type, r_url = fetch(r_url)
			verified = True
	except DownloadFail, e:
		tools.printError('Download error', 'Sorry, we couldn\'t access to address you provided. Please try again in a few seconds.')
		tools.logException()
		exit()
示例#12
0
文件: views.py 项目: rozumalex/notify
    async def post(self):
        data = await self.post()

        try:
            account = await db.get_account_by_email(self.app.pool,
                                                    data['email'])
        except LoginError as e:
            return {'session': self.session, 'error': e}

        try:
            account.check_password(data['password'])
        except LoginError as e:
            return {'session': self.session, 'error': e}

        self.session['account_id'] = account.id
        raise redirect(self, 'index')
示例#13
0
文件: views.py 项目: rozumalex/notify
    async def post(self):
        data = await self.post()

        try:
            account = Account(data)
        except ValidationError as e:
            return {'session': self.session, 'error': e}

        try:
            account_id = await account.create(self.app.pool)
        except Exception as e:
            return {'session': self.session, 'error': e}

        try:
            await create_tasks_table(self.app.pool, account_id)
        except Exception as e:
            return {'session': self.session, 'error': e}

        self.session['account_id'] = account_id
        raise redirect(self, 'index')
示例#14
0
    async def update(self):
        data = await self.post()
        try:
            task = Task(data)
        except ValidationError as e:
            return {
                'account': self.account,
                'session': self.session,
                'error': e
            }

        try:
            await task.update(self.app.pool)
        except asyncpg.exceptions.UniqueViolationError as e:
            return {
                'account': self.account,
                'session': self.session,
                'error': e
            }

        raise redirect(self, 'index')
示例#15
0
def play_video():
    from tools import header_ua, redirect, pipeURL

    try: name, icon, url, tmp = json.loads(args['data'][0])
    except: url = None
    
    if not url: return
    
    try: url = stalker.get_link(url, tmp)
    except: url = None
    
    if not url: return
    
    try:
        url = pipeURL(redirect(url, header_ua))
    
        li = xbmcgui.ListItem(name, iconImage=icon, thumbnailImage=icon)
        li.setInfo('video', {'Title': name})
    
        xbmc.Player().play(item=url, listitem=li)
    
    except Exception as e:
        alert('PLAY  ERROR:\n\n'+str(e))
示例#16
0
文件: views.py 项目: rozumalex/notify
 async def get(self):
     self.session.pop('account_id')
     raise redirect(self, 'login')
示例#17
0
 async def get(self):
     redis = self.request.app['redis']
     if not await redis.get('user'):
         redirect(self.request, 'login')
示例#18
0
 async def wrapped(request, *args, **kwargs):
     if request.account:
         raise redirect(request, 'index')
     return await func(request, *args, **kwargs)
示例#19
0
	
	if not r_url or r_url == 'http://': # url not passed
		tools.redirect('/')
		exit()
		
	if not r_url.startswith('http://') and not r_url.startswith('https://'):
		r_url = 'http://'+r_url
		
	try:
		if not r_content or not r_type:
			r_content, r_type, r_url = fetch(r_url)
	except DownloadFail, e:
		tools.printError('Download error', 'Sorry, we couldn\'t access to address you provided. Please try again in a few seconds.')
		tools.logException()
		exit()
	
	id = tools.md5(ID_SALT+r_url+unicode(time.time()))[:8]
	page = models.Page(key_name='K'+id, url=r_url)
	page.put()
	
	if tools.isHtml(r_type):
		r_content = preprocessHtml(r_content, r_url)
		
	content = bz2.compress(r_content)
	cache = models.Cache(page=page, url=tools.md5(unicode(page.url)), content=content, contentType=r_type)
	cache.put()
	
	tools.redirect('/'+id)
	
if __name__ == "__main__":
	main()
示例#20
0
 async def get(self):
     if self.account:
         raise redirect(self, 'tasks')
     result = {'account': self.account, 'session': self.session}
     return result
示例#21
0
 async def wrapped(request, *args, **kwargs):
     if not request.account:
         raise redirect(request, 'login')
     return await func(request, *args, **kwargs)
示例#22
0
文件: upload.py 项目: giteugen/peeep
	try:
		if not r_content or not r_type:
			r_content, r_type, r_url = fetch(r_url)
			verified = True
	except DownloadFail, e:
		tools.printError('Download error', 'Sorry, we couldn\'t access to address you provided. Please try again in a few seconds.')
		tools.logException()
		exit()
	
	id = tools.md5(ID_SALT+r_url+unicode(time.time()))[:8]
	page = models.Page(key_name='K'+id, url=r_url, owner=owner, public=public)
	page.put()
	
	if tools.isHtml(r_type):
		r_content = preprocessHtml(r_content, r_url)
		
	content = bz2.compress(r_content)
	cache = models.Cache(page=page, url=tools.md5(unicode(page.url)), content=content, contentType=r_type, verified=verified)
	cache.put()
	
	if user:
		tools.redirect('/'+id)
	else:
		cookies = {'anonymous_token': tools.token(page, owner)}
		headers = [
			tools.formatCookie(cookies, 60*60*24)
		]
		tools.redirect(users.create_login_url('/confirm.php?id=%s' % id), headers)
	
if __name__ == "__main__":
	main()