Пример #1
0
 def GET(self):
     #如果删除了内置书籍py文件,则在数据库中也清除,有最长一天的滞后问题不大
     for bk in Book.all().filter('builtin = ', True):
         found = False
         for book in BookClasses():
             if book.title == bk.title:
                 found = True
                 break
         if not found:
             for fd in bk.feeds:
                 fd.delete()
             bk.delete()
     
     # 停止过期用户的推送
     for user in KeUser.all():
         if user.expires and (user.expires < datetime.datetime.utcnow()):
             user.enable_send = False
             user.put()
     
     query = DeliverLog.all()
     query.filter('datetime < ', datetime.datetime.utcnow() - datetime.timedelta(days=25))
     logs = query.fetch(1000)
     c = len(logs)
     db.delete(logs)
     
     return "%s lines log removed.<br />" % c
Пример #2
0
def StoreBookToDb():
    for book in BookClasses():  #添加内置书籍
        if memcache.get(book.title): #使用memcache加速
            continue
        b = Book.all().filter("title = ", book.title).get()
        if not b:
            b = Book(title=book.title,description=book.description,builtin=True)
            b.put()
            memcache.add(book.title, book.description, 86400)
Пример #3
0
    def POST(self):
        name, passwd = web.input().get('u'), web.input().get('p')
        if name.strip() == '':
            tips = _("Username is empty!")
            return self.render('login.html', "Login", nickname='', tips=tips)
        elif len(name) > 25:
            tips = _("The len of username reached the limit of 25 chars!")
            return self.render('login.html',
                               "Login",
                               nickname='',
                               tips=tips,
                               username=name)
        elif '<' in name or '>' in name or '&' in name:
            tips = _("The username includes unsafe chars!")
            return self.render('login.html', "Login", nickname='', tips=tips)

        self.CheckAdminAccount()  #确认管理员账号是否存在

        try:
            pwdhash = hashlib.md5(passwd).hexdigest()
        except:
            u = None
        else:
            u = KeUser.all().filter("name = ",
                                    name).filter("passwd = ", pwdhash).get()
        if u:
            main.session.login = 1
            main.session.username = name
            if u.expires:  #用户登陆后自动续期
                u.expires = datetime.datetime.utcnow() + datetime.timedelta(
                    days=180)
                u.put()

            #修正从1.6.15之前的版本升级过来后自定义RSS丢失的问题
            for fd in Feed.all():
                if not fd.time:
                    fd.time = datetime.datetime.utcnow()
                    fd.put()

            #1.7新增各用户独立的白名单和URL过滤器,这些处理是为了兼容以前的版本
            if name == 'admin':
                for wl in WhiteList.all():
                    if not wl.user:
                        wl.user = u
                        wl.put()
                for uf in UrlFilter.all():
                    if not uf.user:
                        uf.user = u
                        uf.put()

            #如果删除了内置书籍py文件,则在数据库中也清除
            #放在同步数据库是为了推送任务的效率
            for bk in Book.all().filter('builtin = ', True):
                found = False
                for book in BookClasses():
                    if book.title == bk.title:
                        if bk.description != book.description:
                            bk.description = book.description
                            bk.put()
                        found = True
                        break

                if not found:
                    for fd in bk.feeds:
                        fd.delete()
                    bk.delete()

            raise web.seeother(r'/my')
        else:
            tips = _("The username not exist or password is wrong!")
            main.session.login = 0
            main.session.username = ''
            main.session.kill()
            return self.render('login.html',
                               "Login",
                               nickname='',
                               tips=tips,
                               username=name)
Пример #4
0
#from google.appengine.api import taskqueue
from google.appengine.api import memcache

from lib.memcachestore import MemcacheStore
from books import BookClasses

from apps.View import *

from apps.dbModels import Book
from apps.BaseHandler import BaseHandler
from apps.utils import fix_filesizeformat

#reload(sys)
#sys.setdefaultencoding('utf-8')

for book in BookClasses():  #添加内置书籍
    if memcache.get(book.title): #使用memcache加速
        continue
    b = Book.all().filter("title = ", book.title).get()
    if not b:
        b = Book(title=book.title,description=book.description,builtin=True)
        b.put()
        memcache.add(book.title, book.description, 86400)

class Test(BaseHandler):
    def GET(self):
        s = ''
        for d in os.environ:
            s += "<pre><p>" + str(d).rjust(28) + " | " + str(os.environ[d]) + "</p></pre>"
        return s
Пример #5
0
 def POST(self):
     name, passwd = web.input().get('u'), web.input().get('p')
     if name.strip() == '':
         tips = _("Username is empty!")
         return self.render('login.html',"Login",nickname='',tips=tips)
     elif len(name) > 25:
         tips = _("The len of username reached the limit of 25 chars!")
         return self.render('login.html',"Login",nickname='',tips=tips,username=name)
     elif '<' in name or '>' in name or '&' in name:
         tips = _("The username includes unsafe chars!")
         return self.render('login.html',"Login",nickname='',tips=tips)
     
     self.CheckAdminAccount() #确认管理员账号是否存在
     
     u = KeUser.all().filter("name = ", name).get()
     if u:
         secret_key = u.secret_key or ''
         pwdhash = hashlib.md5(passwd + secret_key).hexdigest()
         if u.passwd != pwdhash:
             u = None
             
     if u:
         main.session.login = 1
         main.session.username = name
         if u.expires: #用户登陆后自动续期
             u.expires = datetime.datetime.utcnow()+datetime.timedelta(days=180)
             u.put()
         
         #为了兼容性,对于新账号才一次性设置secret_key
         #老账号删除重建则可以享受加强的加密
         #if not u.secret_key:
         #    u.secret_key = new_secret_key()
         #    u.put()
             
         #修正从1.6.15之前的版本升级过来后自定义RSS丢失的问题
         for fd in Feed.all():
             if not fd.time:
                 fd.time = datetime.datetime.utcnow()
                 fd.put()
             
         #1.7新增各用户独立的白名单和URL过滤器,这些处理是为了兼容以前的版本
         if name == 'admin':
             for wl in WhiteList.all():
                 try:
                     if not wl.user:
                         wl.user = u
                         wl.put()
                 except:
                     pass
             for uf in UrlFilter.all():
                 try:
                     if not uf.user:
                         uf.user = u
                         uf.put()
                 except:
                     pass
         
         #同步书籍数据库
         for bk in Book.all().filter('builtin = ', True):
             found = False
             for book in BookClasses():
                 if book.title == bk.title:
                     if bk.description != book.description:
                         bk.description = book.description
                         bk.put()
                     if bk.needs_subscription != book.needs_subscription:
                         bk.needs_subscription = book.needs_subscription
                         bk.put()
                     found = True
                     break
             
             #如果删除了内置书籍py文件,则在数据库中也清除
             if not found:
                 subs = u.subscription_info(bk.title)
                 if subs:
                     subs.delete()
                 for fd in bk.feeds:
                     fd.delete()
                 bk.delete()
                 
         if u.kindle_email:
             raise web.seeother(r'/my')
         else:
             raise web.seeother(r'/setting')
     else:
         import time
         time.sleep(5)
         tips = _("The username not exist or password is wrong!")
         main.session.login = 0
         main.session.username = ''
         main.session.kill()
         return self.render('login.html',"Login",nickname='',tips=tips,username=name)
Пример #6
0
    def POST(self):
        name, passwd = web.input().get('u'), web.input().get('p')
        if name.strip() == '':
            tips = _("Username is empty!")
            return self.render('login.html', "Login", nickname='', tips=tips)
        elif len(name) > 25:
            tips = _("The len of username reached the limit of 25 chars!")
            return self.render('login.html',
                               "Login",
                               nickname='',
                               tips=tips,
                               username=name)
        elif '<' in name or '>' in name or '&' in name or '\\' in name or '/' in name:
            tips = _("The username includes unsafe chars!")
            return self.render('login.html', "Login", nickname='', tips=tips)

        self.CheckAdminAccount()  #确认管理员账号是否存在

        u = KeUser.all().filter("name = ", name).get()
        if u:
            secret_key = u.secret_key or ''
            pwdhash = hashlib.md5(passwd + secret_key).hexdigest()
            if u.passwd != pwdhash:
                u = None

        if u:
            main.session.login = 1
            main.session.username = name
            if u.expires and u.expiration_days != 0:  #用户登陆后自动续期
                days = 180 if u.expiration_days is None else u.expiration_days  #兼容老版本和老账号
                u.expires = datetime.datetime.utcnow() + datetime.timedelta(
                    days=days)
                u.put()

            #为了兼容性,对于新账号才一次性设置secret_key
            #老账号删除重建则可以享受加强的加密
            #if not u.secret_key:
            #    u.secret_key = new_secret_key()
            #    u.put()

            #修正从1.6.15之前的版本升级过来后自定义RSS丢失的问题
            for fd in Feed.all():
                if not fd.time:
                    fd.time = datetime.datetime.utcnow()
                    fd.put()

            #1.7新增各用户独立的白名单和URL过滤器,这些处理是为了兼容以前的版本
            if name == 'admin':
                for wl in WhiteList.all():
                    try:
                        if not wl.user:
                            wl.user = u
                            wl.put()
                    except:
                        pass
                for uf in UrlFilter.all():
                    try:
                        if not uf.user:
                            uf.user = u
                            uf.put()
                    except:
                        pass

            #1.25.3新增user.remove_hyperlinks
            if u.remove_hyperlinks is None:
                u.remove_hyperlinks = 'image'
                u.put()

            #同步书籍数据库
            bksToDelete = []
            for bk in Book.all().filter('builtin = ', True):
                found = False
                for book in BookClasses():
                    if book.title == bk.title:
                        if bk.description != book.description:
                            bk.description = book.description
                            bk.put()
                        if bk.needs_subscription != book.needs_subscription:
                            bk.needs_subscription = book.needs_subscription
                            bk.put()
                        found = True
                        break

                #如果删除了内置书籍py文件,则在数据库中也清除相关信息
                if not found:
                    subs = u.subscription_info(bk.title)
                    if subs:
                        subs.delete()
                    for fd in list(bk.feeds):
                        fd.delete()
                    bksToDelete.append(bk)

            #从数据库中删除书籍
            for bk in bksToDelete:
                bk.delete()

            if u.kindle_email:
                raise web.seeother(r'/my')
            else:
                raise web.seeother(r'/setting')
        else:
            import time
            time.sleep(5)
            tips = _("The username not exist or password is wrong!")
            lang = main.session.get('lang')
            if lang and lang.startswith('zh'):
                tips += '&nbsp;&nbsp;&nbsp;&nbsp;<a href="/static/faq.html#forgotpwd" target="_blank">' + _(
                    'Forgot password?') + '</a>'
            else:
                tips += '&nbsp;&nbsp;&nbsp;&nbsp;<a href="/static/faq_en.html#forgotpwd" target="_blank">' + _(
                    'Forgot password?') + '</a>'
            main.session.login = 0
            main.session.username = ''
            main.session.kill()
            return self.render('login.html',
                               "Login",
                               nickname='',
                               tips=tips,
                               username=name)